結果

問題 No.24 数当てゲーム
ユーザー TaK7907TaK7907
提出日時 2017-10-22 12:10:39
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 67 ms / 5,000 ms
コード長 2,266 bytes
コンパイル時間 2,902 ms
コンパイル使用メモリ 104,396 KB
実行使用メモリ 23,632 KB
最終ジャッジ日時 2023-08-13 17:31:02
合計ジャッジ時間 4,242 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
21,696 KB
testcase_01 AC 64 ms
21,540 KB
testcase_02 AC 66 ms
21,552 KB
testcase_03 AC 65 ms
21,528 KB
testcase_04 AC 65 ms
19,592 KB
testcase_05 AC 66 ms
23,564 KB
testcase_06 AC 67 ms
21,556 KB
testcase_07 AC 64 ms
19,592 KB
testcase_08 AC 64 ms
23,596 KB
testcase_09 AC 65 ms
23,632 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;

namespace yukicode {
    public class Program {
        public static void GetFirstPrediction(ref List<uint> nums, ref string answer, ref List<uint> prediction) {
            if (answer == "YES") prediction = nums;
            else {
                for (uint i = 0; i <= 9; ++i) {
                    if (nums.IndexOf( i ) == -1) prediction.Add( i );
                }
            }
        }

        public static void Predict(ref List<uint> nums, ref string answer, ref List<uint> prediction) {
            if (answer == "YES") {
                prediction = prediction.Intersect( nums ).ToList();
            } else {
                prediction = prediction.Except( nums ).ToList();
            }
        }

        public static uint Solver(System.IO.TextReader reader) {
            uint n = uint.Parse( reader.ReadLine() );
            var possibleNumbers = new List<uint>();
            for (var i = 0; i != n; ++i) {
                var buf = reader.ReadLine().Split();
                var nums = buf.Take( 4 ).ToList().ConvertAll( uint.Parse );
                if (i == 0) {
                    GetFirstPrediction( ref nums, ref buf[ 4 ], ref possibleNumbers );
                } else { 
                    Predict( ref nums, ref buf[ 4 ], ref possibleNumbers );
                }
            }
            return possibleNumbers[0];
        }

        private static void Main() {
            Console.WriteLine( Solver( Console.In ) );
        }
    }

    //--- MyLib ---
    public class MyLib {
        public static string Ordinalization(int num) {
            string surfix = "stndrdth";
            return string.Format( "{0}{1}", num,
                ( 0 < num % 10 && num % 10 <= 4 ) && ( ( num % 100 ) / 10 != 1 ) ?
                surfix.Substring( ( num % 10 - 1 ) * 2, 2 ) : surfix.Substring( 6 ) );
        }
        public static List<int> GetIntList(string input, char delimitor) {
            return input.Split( delimitor ).ToList<string>().ConvertAll<int>( int.Parse );
        }
        public static List<int> GetIntList(string input, char[] delimitors) {
            return input.Split( delimitors ).ToList<string>().ConvertAll<int>( int.Parse );
        }
    }
}
0