Submission #363401

# Submission time Handle Problem Language Result Execution time Memory
363401 2021-02-05T19:42:49 Z mosiashvililuka Cat (info1cup19_cat) C++14
10 / 100
1000 ms 5720 KB
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,i,j,ii,jj,zx,xc,t,tes,f[200009],boo,pi,k[200009],qi,qqi,bo[200009],fx[200009];
pair <int, int> p[3000009],q[200009],qq[200009];
void swp(int q, int w){
	swap(f[q],f[w]);
	swap(f[a-q+1],f[a-w+1]);
}
int main(){
	//ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>tes;
	//scanf("%d\n",&tes);
	for(t=1; t<=tes; t++){
		/*if(t>1){
			cout<<"test";
			exit(0);
		}*/
		cin>>a;
		int ta=a;
		//if(t!=tes) scanf("%d\n",&a); else scanf("%d",&a);
		for(i=1; i<=a; i++){
			cin>>f[i];
			//if(i==a) scanf("%d",&f[i]); else scanf("%d ",&f[i]);
		}
		boo=0;
		for(i=1; i<=a/2; i++){
			if(f[i]>a/2){
				boo=1;
				break;
			}
		}
		if(boo==0){
			/*boo=0;
			for(i=1; i<=a/2; i++){
				if(f[a-i+1]-f[i]!=a/2){
					boo=1;
					break;
				}
			}
			if(boo==1){
				cout<<-1<<endl;
				continue;
			}*/
			pi=0;
			for(i=1; i<=a/2; i++){
				k[f[i]]=i;
			}
			for(i=1; i<=a/2; i++){
				if(k[i]==i) continue;
				pi++;
				p[pi].first=k[i];
				p[pi].second=i;
				c=k[i];d=i;
				swap(k[i],k[f[i]]);
				swap(f[c],f[d]);
			}
			for(i=1; i<=pi; i++){
				swap(f[a-p[i].first+1],f[a-p[i].second+1]);
			}
			boo=0;
			for(i=2; i<=a; i++){
				if(f[i]<f[i-1]){
					boo=1;
					break;
				}
			}
			if(boo==1){
//				cout<<-1<<endl;
				//printf("-1\n");
				cout<<-1<<endl;
				continue;
			}
			cout<<pi<<" "<<pi<<endl;
			//printf("%d %d\n",pi,pi);
			for(i=1; i<=pi; i++){
				cout<<p[i].first<<" "<<p[i].second<<endl;
				//printf("%d %d\n",p[i].first,p[i].second);
			}
			continue;
		}
		boo=0;
		for(i=1; i<=a/2; i++){
			j=a-i+1;
			if(f[i]+f[j]!=a+1){
				boo=1;
				break;
			}
		}
		if(boo==0){
			//printf("%d 0\n",a);
		}else{
			//printf("-1\n");
			cout<<-1<<endl;
			continue;
		}
		qi=0;qqi=0;
      /*cout<<"eeeeeeeeepppppp";
      exit(0);*/
		for(i=1; i<=a/2; i++){
			if(f[i]>f[a-i+1]){
				qi++;
				q[qi].first=a-i+1;
				q[qi].second=i;
				/*if(ta!=a){
					cout<<"ooopaaaa";
					exit(0);
				}*/
				if(i==9||a-i+1==9){
					cout<<"aiaiai";
					cout<<a;
					exit(0);
				}
			}else{
				/*qqi++;
				qq[qqi].first=a-i+1;
				qq[qqi].second=i;*/
			}
		}
		if(qi%2==1){
			//printf("-1\n");
			cout<<-1<<endl;
			continue;
		}else{
			//printf("%d 0\n",a);
		}
		if(1==1){
			//just solution
		for(i=1; i<qi; i+=2){
			//cout<<q[i].first<<" l "<<q[i+1].second<<endl;
			pi++;
			p[pi].first=q[i].first;
			p[pi].second=q[i+1].second;
			/*if(q[i].first==9||q[i+1].second==9){
				cout<<"zzzzz";
				exit(0);
			}*/
			swp(q[i].first,q[i+1].second);
		}
		boo=0;
		if(boo==0){
			/*boo=0;
			for(i=1; i<=a/2; i++){
				if(f[a-i+1]-f[i]!=a/2){
					boo=1;
					break;
				}
			}
			if(boo==1){
				cout<<-1<<endl;
				continue;
			}*/
			for(i=1; i<=a/2; i++){
				k[f[i]]=i;
			}
			for(i=1; i<=a/2; i++){
				if(k[i]==i) continue;
				pi++;
				p[pi].first=k[i];
				p[pi].second=i;
				/*if(k[i]==9||i==9){
					cout<<"tuirtuireutier";
					exit(0);
				}*/
				c=k[i];d=i;
				swap(k[i],k[f[i]]);
				swap(f[c],f[d]);
			}
			/*for(i=1; i<=pi; i++){
				swap(f[a-p[i].first+1],f[a-p[i].second+1]);
			}
			boo=0;
			for(i=2; i<=a; i++){
				if(f[i]<f[i-1]){
					boo=1;
					break;
				}
			}*/
			if(boo==1){
				cout<<-1<<endl;
				//printf("-1\n");
				continue;
			}
			cout<<pi<<" "<<pi<<endl;
			//printf("%d %d\n",pi,pi);
			for(i=1; i<=pi; i++){
				cout<<p[i].first<<" "<<p[i].second<<endl;
				//printf("%d %d\n",p[i].first,p[i].second);
			}
			continue;
		}
		}
	}
	return 0;
}

Compilation message

cat.cpp: In function 'int main()':
cat.cpp:19:7: warning: unused variable 'ta' [-Wunused-variable]
   19 |   int ta=a;
      |       ^~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Expected integer, but "aiaiai10" found
# Verdict Execution time Memory Grader output
1 Correct 141 ms 748 KB Output is correct
2 Correct 155 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Expected integer, but "aiaiai10" found
# Verdict Execution time Memory Grader output
1 Correct 141 ms 748 KB Output is correct
2 Correct 155 ms 620 KB Output is correct
3 Execution timed out 1079 ms 5720 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Expected integer, but "aiaiai10" found