結果

問題 No.334 門松ゲーム
ユーザー 14番14番
提出日時 2016-05-23 00:16:17
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 4,165 bytes
コンパイル時間 1,045 ms
コンパイル使用メモリ 114,344 KB
実行使用メモリ 27,836 KB
最終ジャッジ日時 2024-04-16 08:31:01
合計ジャッジ時間 2,342 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
27,704 KB
testcase_01 AC 32 ms
23,348 KB
testcase_02 AC 35 ms
25,668 KB
testcase_03 AC 34 ms
23,348 KB
testcase_04 AC 35 ms
25,528 KB
testcase_05 AC 36 ms
27,704 KB
testcase_06 AC 37 ms
27,456 KB
testcase_07 AC 36 ms
25,536 KB
testcase_08 WA -
testcase_09 AC 35 ms
25,416 KB
testcase_10 AC 36 ms
27,600 KB
testcase_11 AC 36 ms
25,536 KB
testcase_12 AC 35 ms
25,668 KB
testcase_13 WA -
testcase_14 AC 34 ms
25,516 KB
testcase_15 AC 37 ms
27,836 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.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int numCount = int.Parse(Reader.ReadLine());
        List<int> numList = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToList();
        
        bool ans = this.GetAns(numList, true);
        
        if(ans) {
            int[] idxList = this.lastMatched.Select(a=>numList.IndexOf(a)).ToArray();
            Console.WriteLine(string.Join(" ", idxList));
        } else
        {
            Console.WriteLine("-1");
        }

    }

    private Dictionary<string, bool> winDic = new Dictionary<string, bool>();

    int[] lastMatched = new int[3];
    
    private bool GetAns(List<int> target, bool isFirst) {
        
        string key = string.Join("#", target);
        if(winDic.ContainsKey(key)) {
            return winDic[key];
        }
        if(target.Count <= 0) {
            return false;
        }
        bool ans = false;
        
        for(int i=0; i<target.Count - 2; i++) {
            bool mustBreak = false;
            for(int j=i+1; j<target.Count -1; j++) {
                for(int k=j+1; k<target.Count; k++) {
                    if(target[i] < target[j] && target[j] < target[k]) {
                        continue;
                    }
                    if(target[i] > target[j] && target[j] > target[k]) {
                        continue;
                    }
                    if(target[i] == target[j] || target[j] == target[k] || target[i] == target[k]) {
                        continue;
                    }
                    List<int> subList = new List<int>(target);
                    subList.RemoveAt(k);
                    subList.RemoveAt(j);
                    subList.RemoveAt(i);
                    if(!this.GetAns(subList, false)) {
                        ans = true;
                        mustBreak = true;
                        if(isFirst) {
                            this.lastMatched = new int[] {target[i], target[j], target[k]};
                        }
                        break;
                    }
                }
                if(mustBreak) {
                    break;
                }
            }
            if(mustBreak) {
                break;
            }
        }
        winDic.Add(key, ans);
        return ans;
    }

    private void BaseSetup(List<int> target) {
        for(int i=0; i<target.Count; i++) {
            winDic.Add(target[i].ToString(), false);
            for(int j=i+1; j<target.Count; j++) {
                winDic.Add(target[i].ToString() + "#" + target[j].ToString(), false);
                for(int k=j+1; k<target.Count; k++) {
                    string key = target[i] + "#" + target[j] + "#" + target[k];
                    if(target[i] == target[j] || target[j] == target[k] || target[i] == target[k]) {
                        winDic.Add(key, false);
                    }
                    else if(Math.Max(target[i], Math.Max(target[j], target[k])) == target[j]) {
                        winDic.Add(key, true);
                    } else if(Math.Min(target[i], Math.Min(target[j], target[k])) == target[j]) {
                        winDic.Add(key, true);
                    } else
                    {
                        winDic.Add(key, false);
                    }
                }
            }
        }
        
        
    } 

    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


12
5 1 13 10 12 12 12 3 9 13 17 18


 
";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0