結果
| 問題 |
No.1370 置換門松列
|
| コンテスト | |
| ユーザー |
auaua
|
| 提出日時 | 2021-01-30 15:23:50 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 52 ms / 2,000 ms |
| コード長 | 1,587 bytes |
| コンパイル時間 | 1,779 ms |
| コンパイル使用メモリ | 176,320 KB |
| 実行使用メモリ | 10,112 KB |
| 最終ジャッジ日時 | 2024-09-14 19:24:22 |
| 合計ジャッジ時間 | 3,460 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 25 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> Complex;
const ll INF=1e9+7;
const ll inf=INF*INF;
const ll mod=998244353;
const ll MAX=100010;
signed main(){
ll n,m;cin>>n>>m;
vector<ll>a(n);
rep(i,n){
cin>>a[i];
a[i]--;
}
bool f=1;
rep(i,n){
if(i+1<n)if(a[i+1]==a[i])f=0;
if(i+2<n)if(a[i+2]==a[i])f=0;
}
vector<vector<ll> >G(m);
vector<ll>d(m);
rep(i,n){
if(i%2==0){
if(i+1<n){
G[a[i]].pb(a[i+1]);
d[a[i+1]]++;
}
if(i-1>=0){
G[a[i]].pb(a[i-1]);
d[a[i-1]]++;
}
}
}
queue<ll>q;
rep(i,m){
if(d[i]==0)q.push(i);
}
vector<ll>ans(m);
ll now=1;
while(!q.empty()){
ll k=q.front();
q.pop();
ans[k]=now;now++;
for(auto e:G[k]){
d[e]--;
if(d[e]==0)q.push(e);
}
}
if(now!=m+1)f=0;
if(!f){
cout<<"No"<<endl;
}else{
cout<<"Yes"<<endl;
rep(i,m){
cout<<ans[i]<<' ';
}
cout<<endl;
}
}
auaua