結果
問題 | No.360 増加門松列 |
ユーザー | crazybbb3 |
提出日時 | 2016-11-28 00:03:23 |
言語 | Java19 (openjdk 21) |
結果 |
AC
|
実行時間 | 48 ms / 2,000 ms |
コード長 | 2,315 bytes |
コンパイル時間 | 2,208 ms |
コンパイル使用メモリ | 74,288 KB |
実行使用メモリ | 50,008 KB |
最終ジャッジ日時 | 2023-08-25 18:41:10 |
合計ジャッジ時間 | 4,173 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
49,428 KB |
testcase_01 | AC | 46 ms
49,492 KB |
testcase_02 | AC | 42 ms
49,344 KB |
testcase_03 | AC | 43 ms
49,432 KB |
testcase_04 | AC | 46 ms
47,596 KB |
testcase_05 | AC | 46 ms
49,540 KB |
testcase_06 | AC | 46 ms
49,492 KB |
testcase_07 | AC | 45 ms
49,664 KB |
testcase_08 | AC | 46 ms
49,516 KB |
testcase_09 | AC | 46 ms
49,464 KB |
testcase_10 | AC | 44 ms
49,684 KB |
testcase_11 | AC | 43 ms
49,516 KB |
testcase_12 | AC | 46 ms
49,624 KB |
testcase_13 | AC | 43 ms
49,460 KB |
testcase_14 | AC | 44 ms
49,776 KB |
testcase_15 | AC | 48 ms
49,400 KB |
testcase_16 | AC | 42 ms
49,524 KB |
testcase_17 | AC | 44 ms
49,524 KB |
testcase_18 | AC | 46 ms
50,008 KB |
testcase_19 | AC | 46 ms
49,760 KB |
testcase_20 | AC | 46 ms
49,776 KB |
testcase_21 | AC | 46 ms
49,600 KB |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Main { static BufferedReader in; static PrintWriter out; static StringTokenizer tok; void solve() throws IOException { int[] d = nia(7); boolean can = dfs(d, new int[7], 0); out.println(can ? "YES" : "NO"); } boolean dfs(int[] d, int[] a, int used) { int n = Integer.bitCount(used); if (n == 7) { for (int i = 0; i < 5; i++) { if (a[i] <= a[i + 1] && a[i + 1] <= a[i + 2] || a[i] >= a[i + 1] && a[i + 1] >= a[i + 2] || a[i] >= a[i + 2]) { return false; } } return true; } for (int i = 0; i < 7; i++) { if ((used >> i & 1) == 0) { a[n] = d[i]; if (dfs(d, a, used | 1 << i)) { return true; } } } return false; } String ns() throws IOException { while (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine(), " "); } return tok.nextToken(); } int ni() throws IOException { return Integer.parseInt(ns()); } long nl() throws IOException { return Long.parseLong(ns()); } double nd() throws IOException { return Double.parseDouble(ns()); } String[] nsa(int n) throws IOException { String[] res = new String[n]; for (int i = 0; i < n; i++) { res[i] = ns(); } return res; } int[] nia(int n) throws IOException { int[] res = new int[n]; for (int i = 0; i < n; i++) { res[i] = ni(); } return res; } long[] nla(int n) throws IOException { long[] res = new long[n]; for (int i = 0; i < n; i++) { res[i] = nl(); } return res; } public static void main(String[] args) throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); tok = new StringTokenizer(""); Main main = new Main(); main.solve(); out.close(); } }