結果
問題 | No.334 門松ゲーム |
ユーザー | kou6839 |
提出日時 | 2016-01-16 02:14:32 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 204 ms / 2,000 ms |
コード長 | 1,422 bytes |
コンパイル時間 | 2,632 ms |
コンパイル使用メモリ | 86,036 KB |
実行使用メモリ | 58,720 KB |
最終ジャッジ日時 | 2023-10-19 23:54:04 |
合計ジャッジ時間 | 6,357 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 177 ms
58,424 KB |
testcase_01 | AC | 143 ms
55,512 KB |
testcase_02 | AC | 177 ms
57,476 KB |
testcase_03 | AC | 183 ms
58,420 KB |
testcase_04 | AC | 176 ms
58,376 KB |
testcase_05 | AC | 179 ms
58,556 KB |
testcase_06 | AC | 200 ms
58,720 KB |
testcase_07 | AC | 167 ms
57,476 KB |
testcase_08 | AC | 181 ms
58,408 KB |
testcase_09 | AC | 163 ms
57,680 KB |
testcase_10 | AC | 168 ms
57,540 KB |
testcase_11 | AC | 201 ms
58,628 KB |
testcase_12 | AC | 183 ms
58,460 KB |
testcase_13 | AC | 187 ms
58,468 KB |
testcase_14 | AC | 170 ms
57,512 KB |
testcase_15 | AC | 204 ms
58,692 KB |
ソースコード
import java.awt.Frame; import java.net.NetworkInterface; import java.util.*; public class Main { static long gcd(long a,long b){ return b == 0 ? a : gcd(b, a%b); } static long lcm(long a, long b){ return a*b/gcd(a, b); } static int[] dx = {0,1,0,-1};//→↓←↑ static int[] dy = {1,0,-1,0}; static class Pair{ long weight,value; public Pair(long weight,long value) { // TODO Auto-generated constructor stub this.weight = weight; this.value = value; } } static boolean is_kadomatsu(int a,int b, int c){ if(a==b || b==c || a==c) return false; if( (a<b && b<c) || (a>b && b>c) )return false; return true; } static boolean dfs(int used,int now){ //勝ちでtrue if( (n-Integer.bitCount(used))<3) return false; boolean win = false; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ for(int k=j+1;k<n;k++){ if( ((used>>i)&1)==0 && ((used>>j)&1)==0 && ((used>>k)&1)==0 ){ if(is_kadomatsu(kado[i], kado[j], kado[k])){ if(dfs(used+(1<<i)+(1<<j)+(1<<k),now+1)){ continue; } if(now==0)System.out.println(i+" "+j+" "+k); return true; } } } } } return win; } static int n; static int[] kado; public static void main(String[] args) { Scanner sc = new Scanner(System.in); n = sc.nextInt(); kado = new int[n]; for(int i=0;i<n;i++) kado[i] = sc.nextInt(); if(!dfs(0,0)) System.out.println(-1); } }