Submission #689464

# Submission time Handle Problem Language Result Execution time Memory
689464 2023-01-28T14:12:01 Z Xiaoyang Group Photo (JOI21_ho_t3) C++17
5 / 100
5000 ms 320 KB
#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 time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 5 ms 212 KB Output is correct
8 Correct 4 ms 316 KB Output is correct
9 Correct 5 ms 212 KB Output is correct
10 Correct 4 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 5 ms 212 KB Output is correct
8 Correct 4 ms 316 KB Output is correct
9 Correct 5 ms 212 KB Output is correct
10 Correct 4 ms 212 KB Output is correct
11 Execution timed out 5055 ms 212 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 5 ms 212 KB Output is correct
8 Correct 4 ms 316 KB Output is correct
9 Correct 5 ms 212 KB Output is correct
10 Correct 4 ms 212 KB Output is correct
11 Execution timed out 5055 ms 212 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 5 ms 212 KB Output is correct
8 Correct 4 ms 316 KB Output is correct
9 Correct 5 ms 212 KB Output is correct
10 Correct 4 ms 212 KB Output is correct
11 Execution timed out 5055 ms 212 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 5 ms 212 KB Output is correct
8 Correct 4 ms 316 KB Output is correct
9 Correct 5 ms 212 KB Output is correct
10 Correct 4 ms 212 KB Output is correct
11 Execution timed out 5055 ms 212 KB Time limit exceeded
12 Halted 0 ms 0 KB -