結果

問題 No.334 門松ゲーム
ユーザー 37zigen37zigen
提出日時 2016-05-05 23:12:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 194 ms / 2,000 ms
コード長 1,026 bytes
コンパイル時間 2,304 ms
コンパイル使用メモリ 84,056 KB
実行使用メモリ 55,304 KB
最終ジャッジ日時 2024-04-15 13:27:44
合計ジャッジ時間 5,985 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 168 ms
55,304 KB
testcase_01 AC 130 ms
54,224 KB
testcase_02 AC 176 ms
54,324 KB
testcase_03 AC 168 ms
55,076 KB
testcase_04 AC 169 ms
54,980 KB
testcase_05 AC 170 ms
54,792 KB
testcase_06 AC 181 ms
55,072 KB
testcase_07 AC 151 ms
54,420 KB
testcase_08 AC 187 ms
55,100 KB
testcase_09 AC 159 ms
53,892 KB
testcase_10 AC 172 ms
54,104 KB
testcase_11 AC 194 ms
54,960 KB
testcase_12 AC 179 ms
54,800 KB
testcase_13 AC 180 ms
55,092 KB
testcase_14 AC 152 ms
53,828 KB
testcase_15 AC 187 ms
55,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	public static void main(String[] args)throws Exception{
		new Main().solve();
	}
	void solve(){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] k=new int[n];
		for(int i=0;i<n;i++)k[i]=sc.nextInt();
		if(judge(k)){
			System.out.println(ans[0]+" "+ans[1]+" "+ans[2]);
		}else{
			System.out.println(-1);
		}
	}
	int[] ans=new int[3];
	boolean judge(int[] k){
		int n=k.length;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				for(int l=j+1;l<n;l++){
					if(isKadomatsu(k[i],k[j],k[l])){
						int[] d=Arrays.copyOf(k, k.length);
						d[i]=d[j]=d[l]=-1;
						if(!judge(d)){
							ans[0]=i;
							ans[1]=j;
							ans[2]=l;
							return true;
						}
					}
				}
			}
		}
		return false;
	}
	
	
	boolean isKadomatsu(int x,int y,int z){
		if(x==-1||y==-1||z==-1)return false;
		else if(x==y||y==z||z==x)return false;
		else if(x<y&&y>z)return true;
		else if(x>y&&z>y)return true;
		else return false;
	}
}
0