結果

問題 No.1370 置換門松列
ユーザー QCFiumQCFium
提出日時 2019-10-06 17:28:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 959 bytes
コンパイル時間 1,961 ms
コンパイル使用メモリ 176,388 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2024-04-25 17:03:40
合計ジャッジ時間 3,700 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 WA -
testcase_05 AC 1 ms
6,944 KB
testcase_06 WA -
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 29 ms
8,064 KB
testcase_22 AC 20 ms
8,320 KB
testcase_23 AC 27 ms
7,424 KB
testcase_24 AC 10 ms
6,940 KB
testcase_25 AC 34 ms
8,064 KB
testcase_26 AC 34 ms
8,320 KB
testcase_27 AC 16 ms
7,296 KB
testcase_28 AC 16 ms
7,040 KB
testcase_29 AC 13 ms
6,944 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;
}

int main() {
	int n = ri();
	int m = ri();
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri() - 1;
	
	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);
	bool res = true;
	for (int i = 0; i < m; i++) {
		for (auto j : hen[i]) if (ord[j] <= ord[i]) {
			res = false;
			break;
		}
		if (!res) break;
	}
	
	if (!res) puts("No");
	else {
		puts("Yes");
		for (int i = 0; i < m; i++) {
			if (i) printf(" ");
			printf("%d", ord[i] + 1);
		}
		puts("");
	}
	return 0;
}
0