結果

問題 No.1370 置換門松列
ユーザー さかぽん
提出日時 2021-02-18 13:21:41
言語 C#(csc)
(csc 3.9.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 953 bytes
コンパイル時間 2,216 ms
コンパイル使用メモリ 112,420 KB
実行使用メモリ 44,060 KB
最終ジャッジ日時 2024-09-14 19:25:52
合計ジャッジ時間 5,112 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 24 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Linq;

class E
{
	static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
	static (int, int) Read2() { var a = Read(); return (a[0], a[1]); }
	static void Main() => Console.WriteLine(Solve());
	static object Solve()
	{
		var (n, m) = Read2();
		var a = Read();
		Array.Reverse(a);

		var x = new int[m + 1];
		int c = 1 << 20, t = 1;

		if (a[0] == a[1]) return "No";
		x[a[0]] = c;
		x[a[1]] = c + t++;

		for (int i = 2; i < n; i++)
		{
			if (x[a[i]] == 0)
			{
				if (x[a[i - 2]] < x[a[i - 1]])
					x[a[i]] = c - t++;
				else
					x[a[i]] = c + t++;
			}
			else
			{
				if (!IsKadomatsu(x, a, i - 2)) return "No";
			}
		}

		return "Yes\n" + string.Join(" ", x.Skip(1).Select(v => v == 0 ? 1 : v));
	}

	static bool IsKadomatsu(int[] x, int[] a, int i) => x[a[i]] != x[a[i + 2]] && (x[a[i]] < x[a[i + 1]] && x[a[i + 1]] > x[a[i + 2]] || x[a[i]] > x[a[i + 1]] && x[a[i + 1]] < x[a[i + 2]]);
}
0