結果
問題 |
No.2148 ひとりUNO
|
ユーザー |
|
提出日時 | 2023-01-15 20:46:25 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 85 ms / 2,000 ms |
コード長 | 2,335 bytes |
コンパイル時間 | 1,178 ms |
コンパイル使用メモリ | 113,748 KB |
実行使用メモリ | 32,688 KB |
最終ジャッジ日時 | 2024-12-29 12:32:45 |
合計ジャッジ時間 | 5,076 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 39 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static string[] SList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => ReadLine()).ToArray(); public static void Main() { Solve(); } static void Solve() { var t = int.Parse(ReadLine()); var ans = new bool[t]; for (var u = 0; u < t; ++u) { var n = int.Parse(ReadLine()); var map = SList(n); ans[u] = Uno(n, map); } WriteLine(string.Join("\n", ans.Select(f => f ? "YES" : "NO"))); } static bool Uno(int n, string[] map) { var b = new HashSet<int>(); var g = new HashSet<int>(); var r = new HashSet<int>(); foreach (var card in map) { var d = int.Parse(card.Substring(2)); if (card[0] == 'B') b.Add(d); else if (card[0] == 'G') g.Add(d); else r.Add(d); } return Check(b, g, r) || Check(b, r, g) || Check(r, b, g) || Check(r, g, b) || Check(g, b, r) || Check(g, r, b); } static bool Check(HashSet<int> list1, HashSet<int> list2, HashSet<int> list3) { if (list2.Count == 1) { if (list3.Count == 0) { foreach (var li in list2) if (list1.Contains(li)) return true; } else { foreach (var li in list2) if (list1.Contains(li) && list3.Contains(li)) return true; } } else if (list2.Count == 0) { if (list3.Count == 0) return true; } else { var f12 = new HashSet<int>(); var f23 = new HashSet<int>(); foreach (var li in list2) { if (list1.Contains(li)) f12.Add(li); if (list3.Contains(li)) f23.Add(li); } if (list3.Count == 0 && f12.Count > 0) return true; if (list3.Count > 0) { foreach (var f2 in f12) if (f23.Count - (f23.Contains(f2) ? 1 : 0) > 0) return true; } } return false; } }