Submission #1083800

#TimeUsernameProblemLanguageResultExecution timeMemory
1083800ZeroCoolSorting (IOI15_sorting)C++14
Compilation error
0 ms0 KiB
#include "sorting.h" #include<bits/stdc++.h> using namespace std; #define ar array #define ll long long #define ld long double vector<ar<int, int>> ans, xy, swaps; bool check(vector<int> p, int m, int n) { int s = 0; vector<int> e = p; vector<int> co(n, 0); for (int i = 0; i < n; i++) co[p[i]] = i; for (int i = 0; i < m; i++) swap(p[xy[i][0]], p[xy[i][1]]); for (int i = 0; i < n; i++) { if (p[i] == i) continue; while(p[i] != i) { int j = p[i]; swaps.push_back({p[i], p[j]}); swap(p[i], p[j]); s++; } } if (swaps.size() > m)return 0; while(swaps.size() < m) swaps.push_back({0, 0}); for (int i = 0; i < m; i++) { swap(co[e[xy[i][0]]], co[e[xy[i][1]]]); swap(e[xy[i][0]], e[xy[i][1]]); auto [x, y] = swaps[i]; swaps[i] = {co[x], co[y]}; swap(e[co[x]], e[co[y]]); swap(co[x], co[y]); } return s <= m; } int findSwapPairs(int n, int A[], int m, int X[], int Y[], int P[], int Q[]) { vector<int> p(n); for (int i = 0; i < n; i++) p[i] = A[i]; for (int i = 0; i < m; i++) xy.push_back({X[i], Y[i]}); int l = 0, r = m - 1; while(l <= r) { int m = (l + r)/2; swaps.clear(); if(check(p, m, n)){ r = m - 1; ans = swaps; }else l = m + 1; } for (int i = 0; i < ans.size(); i++) { P[i] = ans[i][0]; Q[i] = ans[i][1]; } return ans.size(); }

Compilation message (stderr)

sorting.cpp:9:16: error: type/value mismatch at argument 2 in template parameter list for 'template<class _Tp, long unsigned int _Nm> struct std::array'
    9 | vector<ar<int, int>> ans, xy, swaps;
      |                ^~~
sorting.cpp:9:16: note:   expected a constant of type 'long unsigned int', got 'int'
sorting.cpp:9:19: error: template argument 1 is invalid
    9 | vector<ar<int, int>> ans, xy, swaps;
      |                   ^~
sorting.cpp:9:19: error: template argument 2 is invalid
sorting.cpp: In function 'bool check(std::vector<int>, int, int)':
sorting.cpp:16:42: error: invalid types 'int[int]' for array subscript
   16 |     for (int i = 0; i < m; i++) swap(p[xy[i][0]], p[xy[i][1]]);
      |                                          ^
sorting.cpp:16:55: error: invalid types 'int[int]' for array subscript
   16 |     for (int i = 0; i < m; i++) swap(p[xy[i][0]], p[xy[i][1]]);
      |                                                       ^
sorting.cpp:23:19: error: request for member 'push_back' in 'swaps', which is of non-class type 'int'
   23 |             swaps.push_back({p[i], p[j]});
      |                   ^~~~~~~~~
sorting.cpp:28:15: error: request for member 'size' in 'swaps', which is of non-class type 'int'
   28 |     if (swaps.size() > m)return 0;
      |               ^~~~
sorting.cpp:30:17: error: request for member 'size' in 'swaps', which is of non-class type 'int'
   30 |     while(swaps.size() < m) swaps.push_back({0, 0});
      |                 ^~~~
sorting.cpp:30:35: error: request for member 'push_back' in 'swaps', which is of non-class type 'int'
   30 |     while(swaps.size() < m) swaps.push_back({0, 0});
      |                                   ^~~~~~~~~
sorting.cpp:33:21: error: invalid types 'int[int]' for array subscript
   33 |         swap(co[e[xy[i][0]]], co[e[xy[i][1]]]);
      |                     ^
sorting.cpp:33:38: error: invalid types 'int[int]' for array subscript
   33 |         swap(co[e[xy[i][0]]], co[e[xy[i][1]]]);
      |                                      ^
sorting.cpp:34:18: error: invalid types 'int[int]' for array subscript
   34 |         swap(e[xy[i][0]], e[xy[i][1]]);
      |                  ^
sorting.cpp:34:31: error: invalid types 'int[int]' for array subscript
   34 |         swap(e[xy[i][0]], e[xy[i][1]]);
      |                               ^
sorting.cpp:35:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   35 |         auto [x, y] = swaps[i];
      |              ^
sorting.cpp:35:28: error: invalid types 'int[int]' for array subscript
   35 |         auto [x, y] = swaps[i];
      |                            ^
sorting.cpp:36:14: error: invalid types 'int[int]' for array subscript
   36 |         swaps[i] = {co[x], co[y]};
      |              ^
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:46:36: error: request for member 'push_back' in 'xy', which is of non-class type 'int'
   46 |     for (int i = 0; i < m; i++) xy.push_back({X[i], Y[i]});
      |                                    ^~~~~~~~~
sorting.cpp:49:13: warning: declaration of 'int m' shadows a parameter [-Wshadow]
   49 |         int m = (l + r)/2;
      |             ^
sorting.cpp:42:39: note: shadowed declaration is here
   42 | int findSwapPairs(int n, int A[], int m, int X[], int Y[], int P[], int Q[]) {
      |                                   ~~~~^
sorting.cpp:50:15: error: request for member 'clear' in 'swaps', which is of non-class type 'int'
   50 |         swaps.clear();
      |               ^~~~~
sorting.cpp:57:29: error: request for member 'size' in 'ans', which is of non-class type 'int'
   57 |     for (int i = 0; i < ans.size(); i++) {
      |                             ^~~~
sorting.cpp:58:19: error: invalid types 'int[int]' for array subscript
   58 |         P[i] = ans[i][0];
      |                   ^
sorting.cpp:59:19: error: invalid types 'int[int]' for array subscript
   59 |         Q[i] = ans[i][1];
      |                   ^
sorting.cpp:61:16: error: request for member 'size' in 'ans', which is of non-class type 'int'
   61 |     return ans.size();
      |                ^~~~