結果

問題 No.1370 置換門松列
ユーザー HaaHaa
提出日時 2021-01-29 22:41:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,297 bytes
コンパイル時間 1,639 ms
コンパイル使用メモリ 176,076 KB
実行使用メモリ 10,504 KB
最終ジャッジ日時 2023-10-12 21:03:22
合計ジャッジ時間 3,641 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 1 ms
4,352 KB
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 1 ms
4,352 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 48 ms
10,436 KB
testcase_22 AC 35 ms
9,484 KB
testcase_23 AC 43 ms
10,464 KB
testcase_24 AC 17 ms
5,072 KB
testcase_25 AC 53 ms
10,328 KB
testcase_26 AC 52 ms
10,504 KB
testcase_27 AC 26 ms
9,692 KB
testcase_28 AC 26 ms
9,592 KB
testcase_29 AC 23 ms
5,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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