結果

問題 No.1328 alligachi-problem
ユーザー さかぽんさかぽん
提出日時 2020-12-25 01:44:16
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,177 ms / 2,000 ms
コード長 1,776 bytes
コンパイル時間 4,713 ms
コンパイル使用メモリ 113,768 KB
実行使用メモリ 71,640 KB
最終ジャッジ日時 2023-10-21 16:08:44
合計ジャッジ時間 19,523 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
26,700 KB
testcase_01 AC 46 ms
26,644 KB
testcase_02 AC 46 ms
26,708 KB
testcase_03 AC 41 ms
25,872 KB
testcase_04 AC 52 ms
26,724 KB
testcase_05 AC 52 ms
26,908 KB
testcase_06 AC 51 ms
26,752 KB
testcase_07 AC 53 ms
26,936 KB
testcase_08 AC 48 ms
26,672 KB
testcase_09 AC 637 ms
71,596 KB
testcase_10 AC 471 ms
65,528 KB
testcase_11 AC 613 ms
71,548 KB
testcase_12 AC 618 ms
70,392 KB
testcase_13 AC 621 ms
70,380 KB
testcase_14 AC 616 ms
71,612 KB
testcase_15 AC 471 ms
65,528 KB
testcase_16 AC 616 ms
71,640 KB
testcase_17 AC 620 ms
71,292 KB
testcase_18 AC 619 ms
71,608 KB
testcase_19 AC 619 ms
71,592 KB
testcase_20 AC 620 ms
65,680 KB
testcase_21 AC 623 ms
69,784 KB
testcase_22 AC 620 ms
69,740 KB
testcase_23 AC 473 ms
58,928 KB
testcase_24 AC 504 ms
57,944 KB
testcase_25 AC 520 ms
58,996 KB
testcase_26 AC 1,174 ms
64,588 KB
testcase_27 AC 1,177 ms
70,468 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Collections.Generic;
using System.Linq;

class Y
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var cxys = new bool[n]
			.Select((_, i) =>
			{
				var v = Console.ReadLine().Split();
				return (i: i + 1, c: v[0], x: v[1], y: int.Parse(v[2]));
			})
			.ToArray();

		var qr = new Queue<(int i, string c, string x, int y)>(cxys.Where(v => v.x == "R").OrderBy(v => v.y).ThenBy(v => v.c));
		var qb = new Queue<(int i, string c, string x, int y)>(cxys.Where(v => v.x == "B").OrderBy(v => v.y).ThenByDescending(v => v.c));

		var a = new List<int>();
		var d = new Dictionary<string, int>();
		d["R"] = 0;
		d["B"] = 0;

		while (qr.Count > 0 || qb.Count > 0)
		{
			if (qr.Count == 0)
			{
				var v = qb.Dequeue();
				if (d[v.x] != v.y) { Console.WriteLine("No"); return; }
				a.Add(v.i);
				d[v.c]++;
			}
			else if (qb.Count == 0)
			{
				var v = qr.Dequeue();
				if (d[v.x] != v.y) { Console.WriteLine("No"); return; }
				a.Add(v.i);
				d[v.c]++;
			}
			else
			{
				var vr = qr.Peek();
				var vb = qb.Peek();
				if (d[vr.x] != vr.y && d[vb.x] != vb.y) { Console.WriteLine("No"); return; }
				if (d[vr.x] != vr.y)
				{
					qb.Dequeue();
					a.Add(vb.i);
					d[vb.c]++;
				}
				else if (d[vb.x] != vb.y)
				{
					qr.Dequeue();
					a.Add(vr.i);
					d[vr.c]++;
				}
				else
				{
					if (vr.c == vr.x && vb.c == vb.x || vr.c != vr.x && vb.c != vb.x)
					{
						qr.Dequeue();
						a.Add(vr.i);
						d[vr.c]++;
					}
					else
					{
						if (vr.c == vr.x)
						{
							qr.Dequeue();
							a.Add(vr.i);
							d[vr.c]++;
						}
						else
						{
							qb.Dequeue();
							a.Add(vb.i);
							d[vb.c]++;
						}
					}
				}
			}
		}
		Console.WriteLine("Yes\n" + string.Join(" ", a));
	}
}
0