Submission #600135

#TimeUsernameProblemLanguageResultExecution timeMemory
600135PiejanVDCSorting (IOI15_sorting)C++17
0 / 100
1077 ms356 KiB
#include "sorting.h" #include <bits/stdc++.h> using namespace std; int findSwapPairs(int n, int s[], int m, int X[], int Y[], int P[], int Q[]) { auto sorted = [&] (vector<int>&v) -> bool { for(int i = 0 ; i < n ; i++) if(v[i] != i) return 0; return 1; }; for(int T = 1 ; T <= m ; T++) { //cout << "T : " << T << '\n'; vector<int>c(n); for(int i = 0 ; i < n ; i++) c[i]= i; for(int i = 0 ; i < T ; i++) swap(c[X[i]], c[Y[i]]); vector<int>go(n, -1); for(int i = 0 ; i < n ; i++) { //assert(go[c[i]] == -1); go[c[i]] = i; } vector<int>v(n); auto S = [&] (int W) { for(int i = 0 ; i < n ; i++) if(v[i] == W) return i; //assert(0); }; for(int i = 0 ; i < n ; i++) v[i] = s[i]; int cnt = 0; for(int i = 0 ; i < T ; i++) { if(sorted(v)) return cnt; cnt++; swap(v[X[i]], v[Y[i]]); swap(go[X[i]], go[Y[i]]); int j; for(j = 0 ; j < n ; j++) { if(go[j] != v[j]) { int p = S(go[j]); P[cnt-1] = p; Q[cnt-1] = i; swap(v[p], v[j]); break; } } /*cout << " " << i << '\n'; cout << " "; for(auto z : v) cout << z << ' '; cout << '\n';*/ if(j == n) P[cnt] = 0, Q[cnt] = 0; // do the swappings // look for first element not correct in go } if(sorted(v)) return cnt; } return 0; }

Compilation message (stderr)

sorting.cpp: In lambda function:
sorting.cpp:29:9: warning: control reaches end of non-void function [-Wreturn-type]
   29 |         };
      |         ^
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...