結果

問題 No.305 鍵(2)
ユーザー uma-pinehilluma-pinehill
提出日時 2018-05-22 16:10:57
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 2,236 bytes
コンパイル時間 1,986 ms
コンパイル使用メモリ 104,272 KB
実行使用メモリ 39,496 KB
平均クエリ数 87.08
最終ジャッジ日時 2023-09-24 01:46:28
合計ジャッジ時間 4,105 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
37,032 KB
testcase_01 AC 84 ms
36,944 KB
testcase_02 AC 84 ms
37,620 KB
testcase_03 AC 81 ms
35,204 KB
testcase_04 AC 84 ms
37,580 KB
testcase_05 AC 81 ms
38,968 KB
testcase_06 AC 82 ms
36,500 KB
testcase_07 AC 85 ms
37,028 KB
testcase_08 AC 82 ms
35,124 KB
testcase_09 AC 85 ms
35,576 KB
testcase_10 AC 82 ms
35,004 KB
testcase_11 AC 83 ms
39,132 KB
testcase_12 AC 83 ms
39,496 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.Text;

public class Program
{
    static void Main()
    {
        long Key = 0;
        int[] NumPat = new int[10];
        int[] Kotae = new int[10];
        int Count =0;
        int ZeroNum = -1;
        
        // 未使用数字を取得
        for(long i = 0; i<=9; i++){
            int Hit = GetHit(i * 1111111111);
            if(Hit == 10){
                return;
            }else if(Hit == 0){
                ZeroNum = (int)i;
            }
        }
        
        int HitCount = 0;
        
        for(int j =0; j<=9;j++){
            if(j==ZeroNum){
                continue;
            }
            
            if(ZeroNum == -1){
                ResetArray(NumPat,9-j);
            }else{
                ResetArray(NumPat,ZeroNum);
            }
            
            NumPat[0]=j;
            
            for(int k =0;k<=9;k++){
                HitCount = GetHit(JointArray(NumPat));
                if(HitCount == 10){
                    return;
                }else if((HitCount == 1 && ZeroNum != -1) || (HitCount == 2 && ZeroNum == -1)){
                    Kotae[k] = j;
                }
                ShiftArray(NumPat);
            }
        }
        if(GetHit(JointArray(Kotae))!=10){
            Exception hand = new Exception("お手上げ");
            throw hand;
        }
    }
    
    
    static int GetHit(long Input){
        Console.WriteLine("{0:D10}",Input);
        return int.Parse(Console.ReadLine().Split(' ')[0]);
    }
    
    static long JointArray(int[] Arr){
        long Len = Arr.Length;
        long Poww = (long)Math.Pow(10, Len-1);
        long Result = 0;
        for(var i = 0;i < Len;i++){
            Result = Result + Arr[i]*Poww;
            Poww = Poww / 10;
        }
        return Result;
    }
    
    static int[] ResetArray(int[] Arr, int ResetValue){
        var tmp = Arr.Length;
        for(var i = 0;i<tmp;i++){
            Arr[i]=ResetValue;
        }
        return Arr;
    }
    
    static int[] ShiftArray(int[] Arr){
        int Len = Arr.Length;
        int Tmp = Arr[Len-1];
        for(var i = Len - 1;i > 0;i--){
            Arr[i] = Arr[i-1];
        }
        Arr[0] = Tmp;
        return Arr;
    }
}
0