Submission #689464

#TimeUsernameProblemLanguageResultExecution timeMemory
689464XiaoyangGroup Photo (JOI21_ho_t3)C++17
5 / 100
5055 ms320 KiB
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pii pair<int,int> #define pll pair<long long,long long> #define pb push_back #define debug(x) cerr<<#x<<"="<<x<<endl #define pq priority_queue #define inf (1ll<<60) #define rep(i,a,b) for (int i=a;i<(b);i++) #define MP make_pair #define SZ(x) (int(x.size())) #define ll long long #define mod 1000000007 #define ALL(x) x.begin(),x.end() #define endl "\n" void inc(int &a,int b) {a=(a+b)%mod;} void dec(int &a,int b) {a=(a-b+mod)%mod;} int lowbit(int x) {return x&(-x);} ll expo(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;} ll st[10]; int main(){ ios::sync_with_stdio(0); cin.tie(0); ll n;cin>>n; vector<ll>alist,tmp; rep(i,0,n){ ll a;cin>>a;alist.pb(a); tmp.pb(i+1); } rep(i,1,n)st[i]=st[i-1]+2; //~ for(auto x:st)cout<<x<<" "; //~ cout<<endl; ll ans=inf; do{ bool ok=true; rep(i,0,n-1){ if(st[i]+tmp[i]>=st[i+1]+tmp[i+1])ok=false; } if(!ok)continue; ll cnt=0; vector<ll>tmpc; for(auto x:tmp)tmpc.pb(x); rep(i,0,n){ if(tmpc[i]==alist[i])continue; for(int j=n-1;j>i;j--){ if(tmpc[j]==alist[i]){ swap(tmpc[j],tmpc[j-1]); cnt++; } } } //~ for(auto x:tmp)cout<<x<<" "; //~ debug(cnt); ans=min(ans,cnt); }while(next_permutation(ALL(tmp))); cout<<ans; return 0; } /* */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...