結果

問題 No.360 増加門松列
ユーザー nCk_cv
提出日時 2016-04-20 18:53:17
言語 Java
(openjdk 23)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 1,062 bytes
コンパイル時間 2,338 ms
コンパイル使用メモリ 77,580 KB
実行使用メモリ 50,400 KB
最終ジャッジ日時 2024-12-24 04:33:33
合計ジャッジ時間 5,690 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;
 
class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int[] in = new int[7];
		for(int i = 0; i < 7; i++) {
			in[i] = sc.nextInt();
		}
		boolean ans = dfs(0,new int[7],new boolean[7],in);
		
		if(ans) System.out.println("YES");
		else System.out.println("NO");
	}
	static boolean check(int a, int b, int c) {
		return a != b && b != c && a != c &&  ((a < b && c < b) || (a > b && c > b));
	}
	static boolean check2(int a, int b, int c) {
		return check(a,b,c) && a < c;	
	}
	static boolean check3(int[] a) {
		for(int i = 0; i < 5; i++) {
			if(!check2(a[i],a[i+1],a[i+2])) return false;
		}
		return true;
	}
	static boolean dfs(int id, int[] a, boolean [] b, int[] c) {
		if(id == 7) return check3(a);
		for(int i = 0; i < 7; i++) {
			if(b[i]) continue;
			b[i] = true;
			a[id] = c[i];
			if(dfs(id+1,a,b,c)) return true;
			a[id] = 0;
			b[i] = false;
		}
		return false;
	}
 
	
}
0