제출 #315326

#제출 시각아이디문제언어결과실행 시간메모리
315326Kevin_Zhang_TWCat (info1cup19_cat)C++17
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h> #define pb emplace_back #define AI(i) begin(i), end(i) using namespace std; using ll = long long; #ifdef KEV #define DE(args...) kout("[ " + string(#args) + " ] = ", args) void kout() {cerr << endl;} template<class T1, class ...T2> void kout (T1 v, T2 ...e) { cerr << v << ' ', kout(e...); } template<class T> void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; } #else #define DE(...) 0 #define debug(...) 0 #endif const int MAX_N = 300010; int n; vector<pair<int,int>> op; // just the front half void swap_sort(vector<int> p) { } bool valid(vector<int> p) { int cnt = 0, m = n / 2; for (int l = 0, r = n-1;l < r;++l, --r) { if ((p[l]>m) ^ (p[r]<=m)) return false; if (p[l] > m) ++cnt; } if (cnt & 1) return false; vector<int> pos(n); for (int i = 0;i < n;++i) pos[ p[i] ] = i; auto sw = [&](int x, int y) { swap(p[x], p[y]), swap(pos[ p[x] ], pos[ p[y] ]); }; auto do_op = [&](int x, int y) { int a = x, b = y, c = n - x - 1, d = n - y - 1; sw(a, b), sw(c, d); }; for (int i = 0;i < m;++i) { while (i+1 != p[i]) do_op(i, p[i]); } for (int i = 0;i < n;++i) if (p[i] != i+1) return false; return true; } // make p good enough so that I can do swap sort on it void pair_good(vector<int> &p) { } bool solve() { cin >> n; vector<int> p(n); for (int &i : p) cin >> i; if (!valid(p)) return false; pair_good(p); swap_sort(p); return true; } signed main() { ios_base::sync_with_stdio(0), cin.tie(0); int T; cin >> T; while (T--) { op.clear(); if (!solve()) cout << -1 << '\n'; else { cout << op.size() << ' ' << op.size() << '\n'; for (auto [a, b] : op) cout << a+1 << ' ' << b+1 << '\n'; } } } #include<bits/stdc++.h> #define pb emplace_back #define AI(i) begin(i), end(i) using namespace std; using ll = long long; #ifdef KEV #define DE(args...) kout("[ " + string(#args) + " ] = ", args) void kout() {cerr << endl;} template<class T1, class ...T2> void kout (T1 v, T2 ...e) { cerr << v << ' ', kout(e...); } template<class T> void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; } #else #define DE(...) 0 #define debug(...) 0 #endif const int MAX_N = 300010; int n; vector<pair<int,int>> op; // just the front half void swap_sort(vector<int> p) { } bool valid(vector<int> p) { int cnt = 0, m = n / 2; for (int l = 0, r = n-1;l < r;++l, --r) { if ((p[l]>m) ^ (p[r]<=m)) return false; if (p[l] > m) ++cnt; } if (cnt & 1) return false; vector<int> pos(n); for (int i = 0;i < n;++i) pos[ p[i] ] = i; auto sw = [&](int x, int y) { swap(p[x], p[y]), swap(pos[ p[x] ], pos[ p[y] ]); }; auto do_op = [&](int x, int y) { int a = x, b = y, c = n - x - 1, d = n - y - 1; sw(a, b), sw(c, d); }; for (int i = 0;i < m;++i) { while (i+1 != p[i]) do_op(i, p[i]); } for (int i = 0;i < n;++i) if (p[i] != i+1) return false; return true; } // make p good enough so that I can do swap sort on it void pair_good(vector<int> &p) { } bool solve() { cin >> n; vector<int> p(n); for (int &i : p) cin >> i; if (!valid(p)) return false; pair_good(p); swap_sort(p); return true; } signed main() { ios_base::sync_with_stdio(0), cin.tie(0); int T; cin >> T; while (T--) { op.clear(); if (!solve()) cout << -1 << '\n'; else { cout << op.size() << ' ' << op.size() << '\n'; for (auto [a, b] : op) cout << a+1 << ' ' << b+1 << '\n'; } } }

컴파일 시 표준 에러 (stderr) 메시지

cat.cpp:97:11: error: redefinition of 'const int MAX_N'
   97 | const int MAX_N = 300010;
      |           ^~~~~
cat.cpp:17:11: note: 'const int MAX_N' previously defined here
   17 | const int MAX_N = 300010;
      |           ^~~~~
cat.cpp:98:5: error: redefinition of 'int n'
   98 | int n;
      |     ^
cat.cpp:18:5: note: 'int n' previously declared here
   18 | int n;
      |     ^
cat.cpp:99:23: error: redefinition of 'std::vector<std::pair<int, int> > op'
   99 | vector<pair<int,int>> op;
      |                       ^~
cat.cpp:19:23: note: 'std::vector<std::pair<int, int> > op' previously declared here
   19 | vector<pair<int,int>> op;
      |                       ^~
cat.cpp:101:6: error: redefinition of 'void swap_sort(std::vector<int>)'
  101 | void swap_sort(vector<int> p) {
      |      ^~~~~~~~~
cat.cpp:21:6: note: 'void swap_sort(std::vector<int>)' previously defined here
   21 | void swap_sort(vector<int> p) {
      |      ^~~~~~~~~
cat.cpp:103:6: error: redefinition of 'bool valid(std::vector<int>)'
  103 | bool valid(vector<int> p) {
      |      ^~~~~
cat.cpp:23:6: note: 'bool valid(std::vector<int>)' previously defined here
   23 | bool valid(vector<int> p) {
      |      ^~~~~
cat.cpp:133:6: error: redefinition of 'void pair_good(std::vector<int>&)'
  133 | void pair_good(vector<int> &p) {
      |      ^~~~~~~~~
cat.cpp:53:6: note: 'void pair_good(std::vector<int>&)' previously defined here
   53 | void pair_good(vector<int> &p) {
      |      ^~~~~~~~~
cat.cpp:135:6: error: redefinition of 'bool solve()'
  135 | bool solve() {
      |      ^~~~~
cat.cpp:55:6: note: 'bool solve()' previously defined here
   55 | bool solve() {
      |      ^~~~~
cat.cpp:146:8: error: redefinition of 'int main()'
  146 | signed main() {
      |        ^~~~
cat.cpp:66:8: note: 'int main()' previously defined here
   66 | signed main() {
      |        ^~~~