結果

問題 No.360 増加門松列
ユーザー nCk_cvnCk_cv
提出日時 2016-04-20 18:53:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 1,062 bytes
コンパイル時間 2,059 ms
コンパイル使用メモリ 75,000 KB
実行使用メモリ 56,628 KB
最終ジャッジ日時 2023-08-25 18:38:00
合計ジャッジ時間 5,885 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
56,084 KB
testcase_01 AC 131 ms
56,236 KB
testcase_02 AC 117 ms
56,112 KB
testcase_03 AC 112 ms
55,844 KB
testcase_04 AC 127 ms
56,488 KB
testcase_05 AC 136 ms
56,628 KB
testcase_06 AC 127 ms
56,236 KB
testcase_07 AC 123 ms
56,532 KB
testcase_08 AC 121 ms
56,384 KB
testcase_09 AC 121 ms
56,064 KB
testcase_10 AC 122 ms
56,388 KB
testcase_11 AC 115 ms
55,884 KB
testcase_12 AC 128 ms
56,296 KB
testcase_13 AC 122 ms
55,900 KB
testcase_14 AC 120 ms
53,868 KB
testcase_15 AC 131 ms
55,892 KB
testcase_16 AC 124 ms
55,704 KB
testcase_17 AC 120 ms
55,992 KB
testcase_18 AC 130 ms
56,556 KB
testcase_19 AC 129 ms
56,160 KB
testcase_20 AC 142 ms
56,396 KB
testcase_21 AC 129 ms
56,088 KB
権限があれば一括ダウンロードができます

ソースコード

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