Submission #18597218


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
int A[101],P[101];
vector<int> R;

void go(int x) {
	R.push_back(x);
	int y=(x+A[x])%N;
	swap(A[x],A[y]);
	P[A[x]]=x;
	P[A[y]]=y;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	
	cin>>N;
	FOR(i,N) {
		cin>>A[i];
		P[A[i]]=i;
	}
	for(i=N-2;i>0;i--) {
		while(1) {
			x=P[N-1];
			if(P[i]==(x+1)%N) break;
			while((P[1]+1)%N!=P[i+1]) go(P[1]);
			if(i==1) break;
			for(j=N-1;j>i;j--) go(P[j]);
		}
		if(i==1) break;
		go(P[i]);
	}
	
	
	while(1) {
		FOR(i,N) if(A[i]!=i) break;
		if(i==N) break;
		FOR(i,N-1) go(P[1]);
	}
	
	FOR(i,N) assert(A[i]==i);
	
	cout<<R.size()<<endl;
	FORR(c,R) cout<<c<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

Submission Info

Submission Time
Task F - Esoswap
User kmjp
Language C++ (GCC 9.2.1)
Score 0
Code Size 1486 Byte
Status TLE
Exec Time 2222 ms
Memory 527660 KB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:29:10: warning: unused variable ‘k’ [-Wunused-variable]
   29 |  int i,j,k,l,r,x,y; string s;
      |          ^
./Main.cpp:29:12: warning: unused variable ‘l’ [-Wunused-variable]
   29 |  int i,j,k,l,r,x,y; string s;
      |            ^
./Main.cpp:29:14: warning: unused variable ‘r’ [-Wunused-variable]
   29 |  int i,j,k,l,r,x,y; string s;
      |              ^
./Main.cpp:29:18: warning: unused variable ‘y’ [-Wunused-variable]
   29 |  int i,j,k,l,r,x,y; string s;
      |                  ^
./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:6:28: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
    6 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                            ^
./Main.cpp:67:38: note: in expansion of macro ‘FOR’
   67 |  FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
      |                                      ^~~

Judge Result

Set Name All Sample
Score / Max Score 0 / 900 0 / 0
Status
AC × 2
TLE × 51
TLE × 1
Set Name Test Cases
All sample_01.txt, testcase_1.txt, testcase_10.txt, testcase_11.txt, testcase_12.txt, testcase_13.txt, testcase_14.txt, testcase_15.txt, testcase_16.txt, testcase_17.txt, testcase_18.txt, testcase_19.txt, testcase_2.txt, testcase_20.txt, testcase_21.txt, testcase_22.txt, testcase_23.txt, testcase_24.txt, testcase_25.txt, testcase_26.txt, testcase_27.txt, testcase_28.txt, testcase_29.txt, testcase_3.txt, testcase_30.txt, testcase_31.txt, testcase_32.txt, testcase_33.txt, testcase_34.txt, testcase_35.txt, testcase_36.txt, testcase_37.txt, testcase_38.txt, testcase_39.txt, testcase_4.txt, testcase_40.txt, testcase_41.txt, testcase_42.txt, testcase_43.txt, testcase_44.txt, testcase_45.txt, testcase_46.txt, testcase_47.txt, testcase_48.txt, testcase_49.txt, testcase_5.txt, testcase_50.txt, testcase_51.txt, testcase_52.txt, testcase_6.txt, testcase_7.txt, testcase_8.txt, testcase_9.txt
Sample sample_01.txt
Case Name Status Exec Time Memory
sample_01.txt TLE 2222 ms 527484 KB
testcase_1.txt AC 8 ms 3508 KB
testcase_10.txt TLE 2221 ms 527588 KB
testcase_11.txt TLE 2221 ms 527484 KB
testcase_12.txt TLE 2221 ms 527480 KB
testcase_13.txt TLE 2222 ms 527656 KB
testcase_14.txt TLE 2221 ms 527592 KB
testcase_15.txt TLE 2221 ms 527496 KB
testcase_16.txt TLE 2221 ms 527556 KB
testcase_17.txt TLE 2221 ms 527656 KB
testcase_18.txt TLE 2222 ms 527496 KB
testcase_19.txt TLE 2221 ms 527604 KB
testcase_2.txt AC 9 ms 3504 KB
testcase_20.txt TLE 2221 ms 527660 KB
testcase_21.txt TLE 2221 ms 527488 KB
testcase_22.txt TLE 2221 ms 527488 KB
testcase_23.txt TLE 2221 ms 527612 KB
testcase_24.txt TLE 2221 ms 527592 KB
testcase_25.txt TLE 2221 ms 527660 KB
testcase_26.txt TLE 2221 ms 527596 KB
testcase_27.txt TLE 2221 ms 527656 KB
testcase_28.txt TLE 2221 ms 527596 KB
testcase_29.txt TLE 2221 ms 527500 KB
testcase_3.txt TLE 2221 ms 527552 KB
testcase_30.txt TLE 2221 ms 527480 KB
testcase_31.txt TLE 2221 ms 527552 KB
testcase_32.txt TLE 2221 ms 527660 KB
testcase_33.txt TLE 2221 ms 527428 KB
testcase_34.txt TLE 2221 ms 527596 KB
testcase_35.txt TLE 2221 ms 527600 KB
testcase_36.txt TLE 2221 ms 527656 KB
testcase_37.txt TLE 2221 ms 527612 KB
testcase_38.txt TLE 2221 ms 527592 KB
testcase_39.txt TLE 2221 ms 527484 KB
testcase_4.txt TLE 2221 ms 527484 KB
testcase_40.txt TLE 2221 ms 527552 KB
testcase_41.txt TLE 2221 ms 527488 KB
testcase_42.txt TLE 2221 ms 527488 KB
testcase_43.txt TLE 2221 ms 527508 KB
testcase_44.txt TLE 2221 ms 527592 KB
testcase_45.txt TLE 2221 ms 527588 KB
testcase_46.txt TLE 2221 ms 527616 KB
testcase_47.txt TLE 2221 ms 527600 KB
testcase_48.txt TLE 2221 ms 527476 KB
testcase_49.txt TLE 2221 ms 527492 KB
testcase_5.txt TLE 2222 ms 527656 KB
testcase_50.txt TLE 2221 ms 527660 KB
testcase_51.txt TLE 2221 ms 527660 KB
testcase_52.txt TLE 2221 ms 527592 KB
testcase_6.txt TLE 2221 ms 527588 KB
testcase_7.txt TLE 2221 ms 527512 KB
testcase_8.txt TLE 2221 ms 527512 KB
testcase_9.txt TLE 2221 ms 527500 KB