結果
問題 | No.1370 置換門松列 |
ユーザー |
![]() |
提出日時 | 2021-01-29 22:41:28 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 57 ms / 2,000 ms |
コード長 | 1,297 bytes |
コンパイル時間 | 2,002 ms |
コンパイル使用メモリ | 180,172 KB |
実行使用メモリ | 10,760 KB |
最終ジャッジ日時 | 2024-09-14 19:22:05 |
合計ジャッジ時間 | 3,691 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll,ll> P; typedef vector<ll> VI; typedef vector<VI> VVI; #define REP(i,n) for(int i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() constexpr ll MOD=1000000007; constexpr ll INF=1e18; int main(){ int n, m; cin >> n >> m; VI a(n); REP(i,n) cin >> a[i], a[i]--; REP(i,n-2){ if(a[i]==a[i+2]){ cout << "No" << endl; return 0; } } VVI edge(m,VI(0)); VI h(m,0); REP(i,n-1){ if(i%2==0){ edge[a[i]].push_back(a[i+1]); h[a[i+1]]++; } else{ edge[a[i+1]].push_back(a[i]); h[a[i]]++; } } queue<int> q; REP(i,m){ if(h[i]==0) q.push(i); } VI tp; while(!q.empty()){ int v=q.front(); tp.push_back(v); q.pop(); for(auto to:edge[v]){ if(--h[to]==0) q.push(to); } } if(tp.size()!=m){ cout << "No" << endl; } else{ cout << "Yes" << endl; VI ans(m,0); REP(i,m){ ans[tp[i]]=i+1; } REP(i,m){ if(i) cout << " "; cout << ans[i]; } cout << endl; } return 0; }