結果
問題 | No.1370 置換門松列 |
ユーザー |
|
提出日時 | 2021-01-29 22:13:13 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 52 ms / 2,000 ms |
コード長 | 826 bytes |
コンパイル時間 | 960 ms |
コンパイル使用メモリ | 78,656 KB |
実行使用メモリ | 8,576 KB |
最終ジャッジ日時 | 2024-09-14 19:20:45 |
合計ジャッジ時間 | 2,705 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 25 |
コンパイルメッセージ
main.cpp:36:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 36 | main() | ^~~~
ソースコード
#include<iostream> #include<vector> #include<queue> using namespace std; int N,M; int A[1<<17]; int X[1<<17]; bool ok(bool f) { vector<int>indeg(M,0); vector<vector<int> >G(M); for(int i=0;i+1<N;i++) { if(f==(i%2==0)) { G[A[i]].push_back(A[i+1]); indeg[A[i+1]]++; } else { G[A[i+1]].push_back(A[i]); indeg[A[i]]++; } } queue<int>P; for(int i=0;i<M;i++)if(indeg[i]==0)P.push(i); int sz=0; while(!P.empty()) { int u=P.front();P.pop(); X[u]=++sz; for(int v:G[u])if(!--indeg[v])P.push(v); } return sz==M; } main() { cin>>N>>M; for(int i=0;i<N;i++) { cin>>A[i]; A[i]--; } for(int i=0;i+2<N;i++)if(A[i]==A[i+2]) { cout<<"No"<<endl; return 0; } if(ok(false)||ok(true)) { cout<<"Yes"<<endl; for(int i=0;i<M;i++)cout<<X[i]<<(i+1==N?"\n":" "); } else cout<<"No"<<endl; }