using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { // 1 行目:ターン数 T と、全体の数字範囲 N、提示する個数 K が与えられていると仮定 // 問題文の通りなら入力形式は「T」だけだが、 // 提示される数字の最大値 N を知る必要があるため、 // 多くの類題と同じ形式として扱う // 例: "T N K" var first = Console.ReadLine().Split() .Select(int.Parse).ToArray(); int T = first[0]; int N = first[1]; int K = first[2]; // 候補集合(1〜N) HashSet candidate = new HashSet(Enumerable.Range(1, N)); // 各ターン処理 for (int t = 0; t < T; t++) { var line = Console.ReadLine().Split(); // 最初の K 個が提示数字 List shown = line.Take(K).Select(int.Parse).ToList(); // 最後が YES/NO string answer = line[K]; if (answer == "YES") { // candidate = candidate ∩ shown candidate.IntersectWith(shown); } else // NO { // candidate = candidate − shown candidate.ExceptWith(shown); } } // 最後は候補が1つになる Console.WriteLine(candidate.First()); } }