Submission #315088

#TimeUsernameProblemLanguageResultExecution timeMemory
315088SeanliuCat (info1cup19_cat)C++14
24 / 100
1082 ms7512 KiB
#include <iostream> #include <vector> #include <utility> #define pii pair<int,int> #define F first #define S second #define ericxiao ios_base::sync_with_stdio(0);cin.tie(0); #define endl '\n' using namespace std; const int maxN = 3e6 + 326; int N, arr[maxN], T; bool vis[maxN]; inline void makeMove(int i, int j){ swap(arr[i], arr[j]); swap(arr[N - i + 1], arr[N - j + 1]); } inline void disp(){ for(int i = 1; i <= N; i++) cout << arr[i] << " \n"[i == N]; } inline void solve(){ cin >> N; for(int i = 1; i <= N; i++) cin >> arr[i]; for(int i = 1; i <= N / 2; i++) if(arr[i] + arr[N - i + 1] != N + 1){ cout << -1 << endl; return; } vector<int> pos = vector<int>(); vector<pii> ans = vector<pii>(); for(int i = 1; i <= N / 2; i++) if(arr[i] > arr[N - i + 1]) pos.push_back(i); if(pos.size() & 1){ //not sure about this cout << -1 << endl; return; } /* cout << "have: "; for(int x : pos) cout << x << " "; cout << endl; */ for(int i = 0; i < (int)pos.size(); i += 2){ makeMove(pos[i], N - pos[i + 1] + 1); ans.emplace_back(pos[i], N - pos[i + 1] + 1); } //disp(); fill(vis, vis + N + 1, false); for(int i = 1; i <= N / 2; i++){ while(i != arr[i]){ int nxt = arr[i]; makeMove(i, arr[i]); ans.emplace_back(i, nxt); //disp(); } } cout << ans.size() << " " << ans.size() << endl; for(auto [a, b] : ans) cout << a << " " << b << endl; } int main(){ //ericxiao cin >> T; while(T--){ solve(); } }

Compilation message (stderr)

cat.cpp: In function 'void solve()':
cat.cpp:59:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   59 |  for(auto [a, b] : ans) cout << a << " " << b << endl;
      |           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...