結果
| 問題 |
No.334 門松ゲーム
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-05-23 00:16:17 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,165 bytes |
| コンパイル時間 | 943 ms |
| コンパイル使用メモリ | 119,300 KB |
| 実行使用メモリ | 27,832 KB |
| 最終ジャッジ日時 | 2024-10-06 23:50:48 |
| 合計ジャッジ時間 | 2,253 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 WA * 2 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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();
}
}
14番