Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define nl "\n"
- #define fi first
- #define se second
- #define pb push_back
- #define ll long long
- #define RV return void
- #define sz(x) int(x.size())
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define fixed(n) fixed << setprecision(n)
- #define cin(v) for(auto&x:v) cin >> x;
- #define cout(v) for(auto&x:v) cout << x << " ";
- void files(){
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- }
- void solve(){
- int n ;
- cin >> n ;
- vector < int > v(n) ;
- vector < pair < int , int > > idx(11 , {-1,-1});
- vector < vector < int > > pref(n, vector<int>(10,0));
- for(int i=0 ;i < n ; i++){
- cin >> v[i];
- if(idx[v[i]].fi ==-1)
- idx[v[i]].fi = i;
- idx[v[i]].se=i;
- for(int j =0 ; j < 10 ; j++){
- pref[i][j] += (v[i] == j);
- if(i)
- pref[i][j] += pref[i-1][j];
- }
- }
- vector < int > temp;
- for(int i =0 ; i < 10 ; i++){
- if(idx[i].fi!=-1) temp.pb(i);
- }
- int m = sz(temp);
- vector < vector < int > > to_try;
- for(int k =0 ; k < (1 << m ) ; k++){
- vector<int> temp2;
- for(int j =0 ; j < m ; j++){
- if(k & (1 << j)){
- temp2.pb(temp[j]) ;
- }
- }
- to_try.pb(temp2);
- }
- auto comp=[&](auto a , auto b){
- if(sz(a) == sz(b)) return a > b ;
- return sz(a) < sz(b);
- };
- sort(rall(to_try) , comp);
- // for(auto& x: to_try) {cout(x) ; cout << nl;}
- for(int i =0 ; i < n -1; i++){
- int d = i+1;
- for(auto& temp2 : to_try){
- int cnt=sz(temp2);
- vector < bool > vis(10,0);
- for(auto& j : temp2) vis[j]=1;
- bool flag=1;
- for(auto& x : temp2){
- int cnt2=0;
- for(auto& q : temp)
- if(!vis[q])
- cnt2 += pref[idx[x].se][q] - pref[idx[x].fi][q];
- if((idx[x].se - idx[x].fi - cnt2) > d) {
- flag=0;
- break;
- }
- }
- if(flag){
- cout << m-cnt <<" ";
- break;
- }
- }
- }
- }
- int main(){
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- // files();
- int testCase=1;
- // cin >> testCase ;
- for(int i=1 ; i <= testCase ; i++){
- // cout << "Case "<< i <<": " << nl;
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement