Submission #315145

#TimeUsernameProblemLanguageResultExecution timeMemory
315145Kevin_Zhang_TWCat (info1cup19_cat)C++17
Compilation error
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 debug(auto L, auto R) { while (L < R) cerr << *L << " \n"[L+1==R], ++L; } void kout(){ cerr << endl; } template<class T1, class ...T2> void kout(T1 a, T2 ...e) { cerr << a << ' ', kout(e...); } #else #define DE(...) 0 #define deubg(...) 0 #endif const int MAX_N = 3000010; int per[MAX_N], n, pos[MAX_N]; void fail() { puts("-1"), exit(0); } void sw(int a, int b) { DE(a, b, per[a], per[b]); swap(per[a], per[b]); swap(pos[per[a]], pos[per[b]]); } void solve() { cin >> n; for (int i = 1;i <= n;++i) cin >> per[i], pos[per[i]] = i; for (int i = 1;i <= n/2;++i) if (per[i] > n/2) fail(); vector< pair<int,int> > res; res.reserve(n); int m = n / 2; DE(m); for (int i = 1;i <= m;++i) { while (i != per[i]) { int x = per[i]; res.pb(i, pos[i]); int a = i, b = pos[i], c = n-a+1, d = n-b+1; sw(a, b); sw(c, d); } } debug(per+1, per+1+n); for (int i = 1;i <= n;++i) if (i != per[i]) { cout << -1 << '\n'; return; } cout << res.size() << '\n'; for (auto [a, b] : res) cout << a << ' ' << b << '\n'; } signed main(){ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int T; cin >> T; while (T--) solve(); }

Compilation message (stderr)

cat.cpp: In function 'void sw(int, int)':
cat.cpp:12:17: warning: statement has no effect [-Wunused-value]
   12 | #define DE(...) 0
      |                 ^
cat.cpp:21:2: note: in expansion of macro 'DE'
   21 |  DE(a, b, per[a], per[b]);
      |  ^~
cat.cpp: In function 'void solve()':
cat.cpp:12:17: warning: statement has no effect [-Wunused-value]
   12 | #define DE(...) 0
      |                 ^
cat.cpp:35:2: note: in expansion of macro 'DE'
   35 |  DE(m);
      |  ^~
cat.cpp:38:8: warning: unused variable 'x' [-Wunused-variable]
   38 |    int x = per[i];
      |        ^
cat.cpp:46:2: error: 'debug' was not declared in this scope; did you mean 'deubg'?
   46 |  debug(per+1, per+1+n);
      |  ^~~~~
      |  deubg