Submission #257869

#TimeUsernameProblemLanguageResultExecution timeMemory
257869shrek12357정렬하기 (IOI15_sorting)C++14
Compilation error
0 ms0 KiB
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <map> #include <set> #include <climits> #include <cmath> #include <fstream> #include <queue> using namespace std; vector<pair<int, int>> toChange; vector<int> xAns, yAns; bool check(int t, int nums[], int n, int x[], int y[]) { int in[n + 11], out[n + 11]; for(int i = 0; i < n; i++){ in[i] = out[i] = nums[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--){ toChange[k++] = {cur[0], cur[j]}; } for(auto it : cur)viz[it] = 1; } if(k > t)return 0; } void getAns(int mid, int nums[], int n, int x[], int y[]) { map<int, int> pos; for (int i = 0; i < n; i++) { pos[nums[i]] = i; } for (int i = 0; i < toChange.size(); i++) { int a = x[i], b = y[i]; swap(nums[a], nums[b]); pos[nums[a]] = a; pos[nums[b]] = b; int c = toChange[i].first, d = toChange[i].second; nums[pos[c]] = d; nums[pos[d]] = c; xAns.push_back(pos[c]); yAns.push_back(pos[d]); int tmp = pos[d]; pos[d] = pos[c]; pos[c] = tmp; } for (int i = 0; i < mid - toChange.size(); i++) { xAns.push_back(0); yAns.push_back(0); } } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { int lo = -1; int hi = M; while (lo + 1 < hi) { int mid = (lo + hi) / 2; if (check(mid,S,N,X,Y)) { 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 'bool check(int, int*, int, int*, int*)':
sorting.cpp:25:18: error: 'query' was not declared in this scope
         swap(out[query[i].ff], out[query[i].ss]);
                  ^~~~~
sorting.cpp:29:5: error: 'memset' was not declared in this scope
     memset(viz, 0, sizeof(viz));
     ^~~~~~
sorting.cpp:29:5: note: suggested alternative: 'wmemset'
     memset(viz, 0, sizeof(viz));
     ^~~~~~
     wmemset
sorting.cpp:45:21: error: 'sz' was not declared in this scope
         for(int j = sz(cur) - 1; j > 0; j--){
                     ^~
sorting.cpp:17:44: warning: unused parameter 'x' [-Wunused-parameter]
 bool check(int t, int nums[], int n, int x[], int y[]) {
                                            ^
sorting.cpp:17:53: warning: unused parameter 'y' [-Wunused-parameter]
 bool check(int t, int nums[], int n, int x[], int y[]) {
                                                     ^
sorting.cpp: In function 'void getAns(int, int*, int, int*, int*)':
sorting.cpp:62:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < toChange.size(); i++) {
                  ~~^~~~~~~~~~~~~~~~~
sorting.cpp:77:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < mid - toChange.size(); i++) {
                  ~~^~~~~~~~~~~~~~~~~~~~~~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:98:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < xAns.size(); i++) {
                  ~~^~~~~~~~~~~~~
sorting.cpp: In function 'bool check(int, int*, int, int*, int*)':
sorting.cpp:53:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^