結果

問題 No.1328 alligachi-problem
ユーザー さかぽんさかぽん
提出日時 2020-12-25 01:53:41
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 393 ms / 2,000 ms
コード長 1,734 bytes
コンパイル時間 4,015 ms
コンパイル使用メモリ 112,032 KB
実行使用メモリ 51,316 KB
最終ジャッジ日時 2023-10-21 16:09:47
合計ジャッジ時間 13,069 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
25,792 KB
testcase_01 AC 38 ms
25,656 KB
testcase_02 AC 39 ms
25,808 KB
testcase_03 AC 38 ms
25,640 KB
testcase_04 AC 43 ms
25,804 KB
testcase_05 AC 44 ms
25,804 KB
testcase_06 AC 43 ms
25,676 KB
testcase_07 AC 44 ms
25,804 KB
testcase_08 AC 40 ms
25,676 KB
testcase_09 AC 393 ms
51,288 KB
testcase_10 AC 337 ms
43,500 KB
testcase_11 AC 387 ms
51,276 KB
testcase_12 AC 388 ms
51,292 KB
testcase_13 AC 390 ms
51,284 KB
testcase_14 AC 393 ms
51,292 KB
testcase_15 AC 346 ms
43,512 KB
testcase_16 AC 387 ms
51,312 KB
testcase_17 AC 389 ms
51,316 KB
testcase_18 AC 390 ms
51,296 KB
testcase_19 AC 389 ms
51,284 KB
testcase_20 AC 392 ms
51,284 KB
testcase_21 AC 387 ms
51,292 KB
testcase_22 AC 389 ms
51,272 KB
testcase_23 AC 345 ms
43,488 KB
testcase_24 AC 343 ms
43,508 KB
testcase_25 AC 340 ms
43,504 KB
testcase_26 AC 370 ms
51,292 KB
testcase_27 AC 368 ms
51,292 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] == "R" ? 0 : 1, x: v[1] == "R" ? 0 : 1, y: int.Parse(v[2]));
			})
			.ToArray();

		var qr = new Queue<(int i, int c, int x, int y)>(cxys.Where(v => v.x == 0).OrderBy(v => v.y).ThenBy(v => -v.c));
		var qb = new Queue<(int i, int c, int x, int y)>(cxys.Where(v => v.x == 1).OrderBy(v => v.y).ThenBy(v => v.c));

		var a = new List<int>();
		var d = new int[2];

		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