結果

問題 No.1370 置換門松列
ユーザー hongrockhongrock
提出日時 2021-01-29 22:04:41
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,538 bytes
コンパイル時間 1,789 ms
コンパイル使用メモリ 169,984 KB
実行使用メモリ 8,828 KB
最終ジャッジ日時 2023-10-12 21:01:35
合計ジャッジ時間 3,674 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,928 KB
testcase_01 AC 3 ms
5,788 KB
testcase_02 AC 3 ms
5,780 KB
testcase_03 AC 3 ms
5,820 KB
testcase_04 AC 3 ms
5,744 KB
testcase_05 AC 3 ms
5,852 KB
testcase_06 AC 3 ms
5,820 KB
testcase_07 AC 3 ms
5,868 KB
testcase_08 AC 4 ms
5,872 KB
testcase_09 AC 3 ms
5,748 KB
testcase_10 AC 3 ms
5,876 KB
testcase_11 AC 4 ms
5,768 KB
testcase_12 AC 3 ms
5,740 KB
testcase_13 AC 3 ms
5,796 KB
testcase_14 AC 3 ms
5,956 KB
testcase_15 AC 3 ms
5,860 KB
testcase_16 AC 3 ms
5,956 KB
testcase_17 AC 3 ms
5,716 KB
testcase_18 AC 3 ms
5,820 KB
testcase_19 AC 4 ms
5,888 KB
testcase_20 AC 3 ms
5,796 KB
testcase_21 AC 30 ms
8,828 KB
testcase_22 AC 19 ms
7,884 KB
testcase_23 AC 27 ms
8,060 KB
testcase_24 AC 12 ms
6,448 KB
testcase_25 AC 35 ms
8,784 KB
testcase_26 AC 34 ms
8,828 KB
testcase_27 AC 16 ms
7,836 KB
testcase_28 AC 16 ms
7,692 KB
testcase_29 AC 14 ms
6,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define rep(i, a, n) for(int i=(a); i<(n); ++i)
#define per(i, a, n) for(int i=(a); i>(n); --i)
#define pb emplace_back
#define mp make_pair
#define clr(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(),(x).end()
#define lowbit(x) (x & -x)
#define fi first
#define se second
#define lson o<<1
#define rson o<<1|1
#define gmid l[o]+r[o]>>1

using LL = long long;
using ULL = unsigned long long;
using pii = pair<int,int>;
using PLL = pair<LL, LL>;
using UI = unsigned int;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1.0);

const int N = 1e5 + 10;

int n, m, a[N], x[N], deg[N];
vector<int> V[N];

bool ok(bool f){
	rep(i, 3, n+1){
		if(a[i] == a[i-2])	return 0;
	}
	rep(i, 1, m+1){
		V[i].clear();
		deg[i] = 0;
	}
	rep(i, 1, n){
		if(f){
			V[a[i]].pb(a[i+1]);
			++deg[a[i+1]];
		} else {
			V[a[i+1]].pb(a[i]);
			++deg[a[i]];
		}
		f ^= 1;
	}
	int v, cnt = 0;
	int val = 0;
	queue<int> Q;
	rep(i, 1, m+1){
		if(deg[i] == 0){
			Q.emplace(i);
		} else {
			x[i] = 0;
		}
	}
	while(!Q.empty()){
		v = Q.front(); Q.pop();
		++cnt;
		x[v] = ++val;

		for(int j : V[v]){
			if(--deg[j] == 0){
				Q.emplace(j);
			}
		}
	}

	return cnt == m;
}

int main(){
	scanf("%d %d", &n, &m);
	rep(i, 1, n+1)	scanf("%d", a+i);
	
	if(ok(0)){
		puts("Yes");
		rep(i, 1, m+1)	printf("%d%c", x[i], i==m?'\n':' ');
	} else if(ok(1)){
		puts("Yes");
		rep(i, 1, m+1)	printf("%d%c", x[i], i==m?'\n':' ');
	} else {
		puts("No");
	}

	return 0;
}
0