結果

問題 No.1370 置換門松列
ユーザー auauaauaua
提出日時 2021-01-30 15:23:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,587 bytes
コンパイル時間 1,599 ms
コンパイル使用メモリ 174,548 KB
実行使用メモリ 10,016 KB
最終ジャッジ日時 2023-10-12 21:05:23
合計ジャッジ時間 3,558 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,356 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 1 ms
4,352 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 43 ms
9,664 KB
testcase_22 AC 34 ms
9,632 KB
testcase_23 AC 41 ms
10,016 KB
testcase_24 AC 18 ms
5,160 KB
testcase_25 AC 48 ms
9,644 KB
testcase_26 AC 48 ms
9,592 KB
testcase_27 AC 28 ms
9,852 KB
testcase_28 AC 27 ms
9,856 KB
testcase_29 AC 23 ms
5,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    }
}
0