結果
問題 | No.334 門松ゲーム |
ユーザー |
|
提出日時 | 2016-01-15 22:45:29 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,590 bytes |
コンパイル時間 | 1,302 ms |
コンパイル使用メモリ | 165,752 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-19 19:20:03 |
合計ジャッジ時間 | 1,934 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
ソースコード
#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; }