結果
問題 | No.1051 PQ Permutation |
ユーザー | kotatsugame |
提出日時 | 2020-05-08 22:43:26 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 959 bytes |
コンパイル時間 | 724 ms |
コンパイル使用メモリ | 71,296 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 19:52:12 |
合計ジャッジ時間 | 4,056 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 WA * 3 |
コンパイルメッセージ
main.cpp:15:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 15 | main() | ^~~~ main.cpp: In function 'int index(int)': main.cpp:9:1: warning: control reaches end of non-void function [-Wreturn-type] 9 | } | ^
ソースコード
#include<iostream> #include<algorithm> using namespace std; int N,P,Q; int A[2<<17]; int index(int X) { for(int i=0;i<N;i++)if(A[i]==X)return i; } void output() { for(int i=0;i<N;i++)cout<<A[i]<<(i+1==N?"":" "); cout<<endl; } main() { cin>>N>>P>>Q; for(int i=0;i<N;i++)cin>>A[i]; if(!next_permutation(A,A+N)) { cout<<-1<<endl; return 0; } if(index(P)<index(Q)); else { int inv=index(Q); int cummax=0; for(int i=N-1;i>inv;i--)cummax=max(cummax,A[i]); for(int i=inv;;i--) { if(i<0) { cout<<-1<<endl; return 0; } cummax=max(cummax,A[i]); if(cummax>A[i]) { sort(A+i+1,A+N); reverse(A+i+1,A+N); next_permutation(A+i,A+N); int ip=index(P),iq=index(Q); if(iq==i) { sort(A+i+1,A+N); reverse(A+i+1,A+N); next_permutation(A+i,A+N); ip=index(P),iq=index(Q); } if(ip<iq)break; else { rotate(A+iq,A+iq+1,A+ip+1); break; } } } } output(); }