結果
問題 | No.334 門松ゲーム |
ユーザー | pekempey |
提出日時 | 2016-01-15 22:45:29 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,590 bytes |
コンパイル時間 | 1,402 ms |
コンパイル使用メモリ | 166,112 KB |
実行使用メモリ | 4,348 KB |
最終ジャッジ日時 | 2023-10-19 23:25:21 |
合計ジャッジ時間 | 2,088 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 2 ms
4,348 KB |
testcase_03 | AC | 1 ms
4,348 KB |
testcase_04 | AC | 2 ms
4,348 KB |
testcase_05 | AC | 2 ms
4,348 KB |
testcase_06 | AC | 1 ms
4,348 KB |
testcase_07 | AC | 2 ms
4,348 KB |
testcase_08 | AC | 2 ms
4,348 KB |
testcase_09 | AC | 2 ms
4,348 KB |
testcase_10 | AC | 2 ms
4,348 KB |
testcase_11 | AC | 2 ms
4,348 KB |
testcase_12 | AC | 3 ms
4,348 KB |
testcase_13 | AC | 2 ms
4,348 KB |
testcase_14 | AC | 2 ms
4,348 KB |
testcase_15 | AC | 3 ms
4,348 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define GET_MACRO(a, b, c, NAME, ...) NAME #define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__) #define rep2(i, a) rep3 (i, 0, a) #define rep3(i, a, b) for (int i = (a); i < (b); i++) #define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__) #define repr2(i, a) repr3 (i, 0, a) #define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--) template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); } template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } using ll = long long; int n; int a[12]; bool reg[1 << 12]; tuple<int, int, int> dp[1 << 12]; const int inf = 1e9; bool kadomatsu(int x, int y, int z) { if (x == y || y == z || x == z) return false; if (x < y && y > z) return true; if (x > y && y < z) return true; return false; } tuple<int, int, int> f(int s) { if (reg[s]) return dp[s]; tuple<int, int, int> ret { inf, inf, inf }; rep(i, n) rep(j, i + 1, n) rep(k, j + 1, n) { if (s & 1 << i) continue; if (s & 1 << j) continue; if (s & 1 << k) continue; if (kadomatsu(a[i], a[j], a[k])) { auto val = f(s | (1 << i) | (1 << j) | (1 << k)); if (get<0>(val) == inf) { chmin(ret, make_tuple(i, j, k)); } } } dp[s] = ret; reg[s] = true; return ret; } int main() { rep(i, 1 << 12) reg[i] = false; cin >> n; rep(i, n) cin >> a[i]; auto ans = f(0); if (get<0>(ans) == inf) { cout << -1 << endl; } else { int x, y, z; tie(x, y, z) = ans; cout << x << " " << y << " " << z << endl; } return 0; }