Submission #257847

#TimeUsernameProblemLanguageResultExecution timeMemory
257847shrek12357Sorting (IOI15_sorting)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> //:3 using namespace std; typedef long long ll; #define all(a) (a).begin(), (a).end() #define ff first #define ss second #define pb push_back #define mp make_pair #define rc(s) return cout<<s,0 #define pi pair <int, int> #define sz(x) (int)((x).size()) #include "sorting.h" const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; const ll H = 1e6 + 11; //ifstream in(".in"); //ofstream out(".out"); int pos[H], n, m; pi query[H], ans[H], a[H]; bool check(int t, int S[]){ int in[n + 11], out[n + 11]; for(int i = 0; i < n; i++){ in[i] = out[i] = S[i]; } for(int i = 0; i < t; i++){ swap(out[query[i].ff], out[query[i].ss]); } bool viz[n + 11]; memset(viz, 0, sizeof(viz)); int k = 0; for(int i = 0; i < n; i++){ if(viz[i])continue; vector<int>cur; int v = out[i]; while(v != i){ cur.push_back(v); v = out[v]; } cur.push_back(v); for(int j = sz(cur) - 1; j > 0; j--){ a[k++] = {cur[0], cur[j]}; } for(auto it : cur)viz[it] = 1; } if(k > t)return 0; for (int i = 0; i < n; ++i){ pos[in[i]] = i; } for(int i = 0; i < k; i++){ //His move int x = query[i].ff, y = query[i].ss; swap(in[x], in[y]); pos[in[x]] = x; pos[in[y]] = y; //My move x = pos[a[i].ff], y = pos[a[i].ss]; swap(in[x], in[y]); pos[in[x]] = x; pos[in[y]] = y; ans[i] = {x, y}; } while(k < t)ans[k++] = {0, 0}; return 1; } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { n = N; m = M; for(int i = 0; i < m; i++){ query[i].first = x[i]; query[i].second = y[i]; } int lo = -1; int hi = M; while (lo + 1 < hi) { int mid = (lo + hi) / 2; if (check(mid, S)) { hi = mid; } else { lo = mid; } toChange.clear(); } check(hi, S, N, X, Y); getAns(hi, S, N, X, Y); for (int i = 0; i < xAns.size(); i++) { P[i] = xAns[i]; Q[i] = yAns[i]; } return hi; }

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:92:24: error: 'x' was not declared in this scope
       query[i].first = x[i];
                        ^
sorting.cpp:93:25: error: 'y' was not declared in this scope
       query[i].second = y[i];
                         ^
sorting.cpp:105:3: error: 'toChange' was not declared in this scope
   toChange.clear();
   ^~~~~~~~
sorting.cpp:107:22: error: too many arguments to function 'bool check(int, int*)'
  check(hi, S, N, X, Y);
                      ^
sorting.cpp:25:6: note: declared here
 bool check(int t, int S[]){
      ^~~~~
sorting.cpp:108:2: error: 'getAns' was not declared in this scope
  getAns(hi, S, N, X, Y);
  ^~~~~~
sorting.cpp:108:2: note: suggested alternative: 'setns'
  getAns(hi, S, N, X, Y);
  ^~~~~~
  setns
sorting.cpp:109:22: error: 'xAns' was not declared in this scope
  for (int i = 0; i < xAns.size(); i++) {
                      ^~~~
sorting.cpp:109:22: note: suggested alternative: 'ans'
  for (int i = 0; i < xAns.size(); i++) {
                      ^~~~
                      ans
sorting.cpp:111:10: error: 'yAns' was not declared in this scope
   Q[i] = yAns[i];
          ^~~~
sorting.cpp:111:10: note: suggested alternative: 'ans'
   Q[i] = yAns[i];
          ^~~~
          ans