제출 #687057

#제출 시각아이디문제언어결과실행 시간메모리
687057Alihan_8Cat (info1cup19_cat)C++17
0 / 100
21 ms596 KiB
#include <bits/stdc++.h> // include <ext/pb_ds/assoc_container.hpp> // include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define all(x) x.begin(), x.end() #define pb push_back // define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> #define mpr make_pair #define ln '\n' void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);} #define int long long void solve(){ int n; cin >> n; vector <int> p(n), pos(n); for ( auto &i: p ) cin >> i, i--; vector <pair<int,int>> res; auto inv = [&](int i){ return n-1-i; }; auto answer = [&](int i, int j){ int _i = inv(i), _j = inv(j); swap(p[i], p[j]), swap(pos[p[i]], pos[p[j]]); swap(p[_i], p[_j]), swap(pos[p[_i]], pos[p[_j]]); res.pb({i, j}); }; auto print = [&](){ cout << (int)res.size() << ' ' << (int)res.size() << ln; for ( auto [l, r]: res ) cout << ++l << ' ' << ++r << ln; }; for ( int i = 0; i < n; i++ ) pos[p[i]] = i; vector <int> rem; for ( int i = 0; i < n/2; i++ ){ if ( pos[i] == i ) continue; if ( inv(pos[i]) < i ){ cout << "-1\n"; return; } if ( inv(i) == pos[i] ){ rem.pb(i); continue; } answer(i, pos[i]); } if ( (int)rem.size() & 1 ){ cout << "-1\n"; return; } for ( int i = 1; i < (int)rem.size(); i += 2 ){ answer(rem[i], pos[rem[i-1]]); answer(rem[i], rem[i-1]); } print(); } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int T; cin >> T; while ( T-- ){ solve(); } cout << '\n'; }

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

cat.cpp: In function 'void IO(std::string)':
cat.cpp:11:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cat.cpp:11:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...