結果
問題 |
No.1051 PQ Permutation
|
ユーザー |
|
提出日時 | 2020-05-08 23:14:51 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,683 bytes |
コンパイル時間 | 1,681 ms |
コンパイル使用メモリ | 173,340 KB |
実行使用メモリ | 16,000 KB |
最終ジャッジ日時 | 2024-07-05 20:00:37 |
合計ジャッジ時間 | 4,274 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 3 |
other | AC * 18 WA * 2 RE * 26 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:32:13: warning: 'pos' may be used uninitialized [-Wmaybe-uninitialized] 32 | if(pos[P] < pos[Q]){ | ~~~~~^ main.cpp:24:8: note: 'pos' declared here 24 | ll pos[200010]; | ^~~ main.cpp:32:22: warning: 'pos' may be used uninitialized [-Wmaybe-uninitialized] 32 | if(pos[P] < pos[Q]){ | ~~~~~^ main.cpp:24:8: note: 'pos' declared here 24 | ll pos[200010]; | ^~~ main.cpp:32:13: warning: 'pos' may be used uninitialized [-Wmaybe-uninitialized] 32 | if(pos[P] < pos[Q]){ | ~~~~~^ main.cpp:24:8: note: 'pos' declared here 24 | ll pos[200010]; | ^~~ main.cpp:32:22: warning: 'pos' may be used uninitialized [-Wmaybe-uninitialized] 32 | if(pos[P] < pos[Q]){ | ~~~~~^ main.cpp:24:8: note: 'pos' declared here 24 | ll pos[200010]; | ^~~
ソースコード
/*** author: yuji9511 ***/ #include <bits/stdc++.h> using namespace std; using ll = long long; using lpair = pair<ll, ll>; const ll MOD = 1e9+7; const ll INF = 1e18; #define rep(i,m,n) for(ll i=(m);i<(n);i++) #define rrep(i,m,n) for(ll i=(m);i>=(n);i--) #define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];}; void print() {} template <class H,class... T> void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);} int main(){ cin.tie(0); ios::sync_with_stdio(false); ll N,P,Q; cin >> N >> P >> Q; ll A[200010]; rep(i,0,N) cin >> A[i]; bool ok = false; ll p = -1, q = -1; ll pos[200010]; rep(i,0,N) pos[A[i]] = i; // ll r = next_permutation(A, A+N); // if(r == 0){ // print(-1); // return 0; // } set<ll> st; if(pos[P] < pos[Q]){ rrep(i,N-1,0){ ll cur = A[i]; if(cur == P) st.erase(Q); auto itr = st.lower_bound(cur); if(itr != st.end()){ ok = true; // print(i); ll v = *itr; st.erase(v); st.insert(A[i]); if(A[i] == P) st.erase(Q); A[i] = v; ll idx = i+1; // print(idx); while(st.size()){ auto it = st.begin(); ll val = *it; // print(val); if(val == P) st.insert(Q); A[idx] = val; idx++; st.erase(it); } break; }else{ st.insert(A[i]); if(A[i] == P){ st.erase(Q); } } } }else{ exit(1); rrep(i,N-1,0){ ll cur = A[i]; if(i > pos[Q]){ st.insert(A[i]); }else{ auto itr = st.lower_bound(A[i]); if(itr == st.end()){ st.insert(A[i]); }else{ ok = true; ll v = *itr; A[i] = v; st.erase(itr); ll idx = i+1; while(st.size()){ auto itr = st.begin(); ll val = *itr; if(val == P) st.insert(Q); A[idx] = val; idx++; st.erase(val); } } } } } if(not ok){ print(-1); }else{ printa(A, N); } }