結果

問題 No.1370 置換門松列
ユーザー 👑 NachiaNachia
提出日時 2021-01-29 22:33:35
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 851 bytes
コンパイル時間 2,110 ms
コンパイル使用メモリ 204,320 KB
実行使用メモリ 9,040 KB
最終ジャッジ日時 2023-10-12 21:03:07
合計ジャッジ時間 4,156 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,932 KB
testcase_01 AC 3 ms
5,784 KB
testcase_02 AC 3 ms
5,716 KB
testcase_03 AC 3 ms
5,876 KB
testcase_04 AC 4 ms
5,712 KB
testcase_05 AC 3 ms
5,872 KB
testcase_06 AC 3 ms
5,860 KB
testcase_07 AC 3 ms
5,844 KB
testcase_08 AC 4 ms
5,932 KB
testcase_09 AC 3 ms
5,776 KB
testcase_10 AC 3 ms
5,892 KB
testcase_11 AC 3 ms
5,936 KB
testcase_12 AC 3 ms
5,796 KB
testcase_13 AC 3 ms
5,756 KB
testcase_14 AC 3 ms
5,800 KB
testcase_15 AC 4 ms
5,920 KB
testcase_16 AC 4 ms
5,752 KB
testcase_17 AC 4 ms
5,800 KB
testcase_18 AC 3 ms
5,940 KB
testcase_19 AC 4 ms
5,808 KB
testcase_20 AC 4 ms
5,784 KB
testcase_21 AC 30 ms
8,928 KB
testcase_22 AC 19 ms
7,948 KB
testcase_23 AC 27 ms
8,308 KB
testcase_24 AC 12 ms
6,488 KB
testcase_25 AC 37 ms
8,980 KB
testcase_26 AC 37 ms
9,040 KB
testcase_27 AC 16 ms
8,016 KB
testcase_28 AC 16 ms
7,964 KB
testcase_29 AC 14 ms
6,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int N,M;
int A[100001];

vector<int> E[100000];
int I[100000];
vector<int> V;
int ans[100000];

int main(){
  scanf("%d%d",&N,&M);
  rep(i,N){ scanf("%d",&A[i]); A[i]--; }
  rep(i,N-2) if(A[i]==A[i+2]){ printf("No\n"); return 0; }
  rep(i,M) I[i]=0;
  rep(i,N-1){
    if(i%2){ E[A[i+1]].push_back(A[i]); I[A[i]]++; }
    else{ E[A[i]].push_back(A[i+1]); I[A[i+1]]++; }
  }
  queue<int> Q; rep(i,M) if(I[i]==0) Q.push(i);
  while(Q.size()){
    int p=Q.front(); Q.pop();
    V.push_back(p);
    for(int e:E[p]) if(0==--I[e]) Q.push(e);
  }
  if(V.size()!=M){ printf("No\n"); return 0; }
  printf("Yes\n");
  rep(i,M) ans[V[i]]=i+1;
  rep(i,M){ if(i) printf(" "); printf("%d",ans[i]); } printf("\n");
  return 0;
}
0