結果

問題 No.1370 置換門松列
ユーザー QCFiumQCFium
提出日時 2019-10-06 17:48:19
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 1,037 bytes
コンパイル時間 1,715 ms
コンパイル使用メモリ 176,732 KB
実行使用メモリ 8,184 KB
最終ジャッジ日時 2023-10-12 21:00:17
合計ジャッジ時間 4,305 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,352 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 28 ms
7,876 KB
testcase_22 AC 19 ms
8,184 KB
testcase_23 AC 25 ms
7,060 KB
testcase_24 AC 10 ms
4,348 KB
testcase_25 AC 32 ms
7,916 KB
testcase_26 AC 34 ms
7,824 KB
testcase_27 AC 15 ms
7,092 KB
testcase_28 AC 14 ms
7,024 KB
testcase_29 AC 12 ms
4,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

std::vector<std::vector<int> > hen;
std::vector<int> ord;
std::vector<bool> visited;
int cnt;
void dfs(int i) {
	visited[i] = true;
	for (auto j : hen[i]) {
		if (visited[j]) continue;
		dfs(j);
	}
	ord[i] = --cnt;
}

bool solve(int n, int m, const int *a) {
	for (int i = 0; i + 2 < n; i++) if (a[i] == a[i + 2]) return false;
	hen.resize(m);
	for (int i = 0; i + 1 < n; i++) {
		if (i & 1) hen[a[i]].push_back(a[i + 1]);
		else hen[a[i + 1]].push_back(a[i]);
	}
	ord.resize(m, -1);
	visited.resize(m, false);
	cnt = m;
	for (int i = 0; i < m; i++)
		if (!visited[i]) dfs(i);
	for (int i = 0; i < m; i++)
		for (auto j : hen[i]) if (ord[j] <= ord[i]) return false;
	return true;
}

int main() {
	int n = ri();
	int m = ri();
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri() - 1;
	
	
	if (!solve(n, m, a)) puts("No");
	else {
		puts("Yes");
		for (int i = 0; i < m; i++) {
			if (i) printf(" ");
			printf("%d", ord[i] + 1);
		}
		puts("");
	}
	return 0;
}
0