結果
| 問題 |
No.334 門松ゲーム
|
| コンテスト | |
| ユーザー |
kou6839
|
| 提出日時 | 2016-01-16 02:14:32 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 168 ms / 2,000 ms |
| コード長 | 1,422 bytes |
| コンパイル時間 | 2,059 ms |
| コンパイル使用メモリ | 81,196 KB |
| 実行使用メモリ | 55,216 KB |
| 最終ジャッジ日時 | 2024-09-19 19:49:06 |
| 合計ジャッジ時間 | 5,147 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 |
ソースコード
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);
}
}
kou6839