結果

問題 No.1370 置換門松列
ユーザー Example0911Example0911
提出日時 2021-01-31 12:40:59
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,207 bytes
コンパイル時間 2,068 ms
コンパイル使用メモリ 208,236 KB
実行使用メモリ 8,372 KB
最終ジャッジ日時 2023-10-12 21:06:01
合計ジャッジ時間 4,036 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 1 ms
4,352 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 25 ms
8,372 KB
testcase_22 AC 16 ms
7,728 KB
testcase_23 AC 22 ms
7,840 KB
testcase_24 AC 8 ms
4,352 KB
testcase_25 AC 28 ms
8,240 KB
testcase_26 AC 30 ms
8,168 KB
testcase_27 AC 13 ms
7,528 KB
testcase_28 AC 14 ms
7,476 KB
testcase_29 AC 10 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;
using P = pair<ll, ll>;
const ll INF = (1LL << 61);
ll mod = 998244353;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N, M; cin >> N >> M;
	bool ok = true;
	vector<int>a(N); for (int i = 0; i < N; i++)cin >> a[i];
	for (int i = 0; i < N; i++)a[i]--;
	for (int i = 0; i < N - 2; i++) {
		if (a[i] == a[i + 2]) {
			ok = false;
		}
	}
	vector<vector<int>>G(M);
	for (int i = 0; i < N - 1; i++) {
		if (i % 2 == 0) {
			G[a[i]].push_back(a[i + 1]);
		}
		else {
			G[a[i + 1]].push_back(a[i]);
		}
	}	
	vector<int>ind(M);
	for (int i = 0; i < M; i++) {
		for (auto j : G[i])ind[j]++;
	}
	queue<int>q;
	for (int i = 0; i < M; i++) {
		if (ind[i] == 0)q.push(i);
	}
	int cnt = 0;
	vector<int>ans(M, -1);
	while (!q.empty()) {
		int now = q.front(); q.pop();
		cnt++;
		ans[now] = cnt;
		for (auto nv : G[now]) {
			ind[nv]--;
			if (ind[nv] == 0)q.push(nv);
		}
	}
	for (int i = 0; i < M; i++) {
		if (ans[i] == -1)ok = false;
	}
	if (ok) {
		cout << "Yes" << endl;
		for (int i = 0; i < M; i++) {
			cout << ans[i];
			if (i == M - 1)cout << endl;
			else cout << " ";
		}
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}
0