結果
問題 | No.334 門松ゲーム |
ユーザー |
![]() |
提出日時 | 2017-07-01 18:27:08 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,646 bytes |
コンパイル時間 | 892 ms |
コンパイル使用メモリ | 95,696 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-04 23:55:33 |
合計ジャッジ時間 | 1,621 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
ソースコード
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <cmath> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #include <stdlib.h> #include <stdio.h> #include <bitset> using namespace std; #define FOR(I,A,B) for(int I = (A); I < (B); ++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); } typedef long long ll; // bit でとったとってないを表現 // その状態をsとする int N; int K[12]; bool reg[1<<12]; tuple<int, int, int> dp[1<<12]; // 1手目 const int inf = 1e9; bool kadomatsu(int x, int y, int z) { if(x == y || y == z || z == x) 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}; FOR(i,0,N) FOR(j,i+1,N) FOR(k,j+1,N) { if (s & (1 << i)) continue; // 取られていたらcontinue if (s & (1 << j)) continue; if (s & (1 << k)) continue; if (kadomatsu(K[i], K[j], K[k])) { auto val = f(s | (1 << i) | (1 << j) | (1 << k)); if(get<0>(val) == inf){ chmin(ret, make_tuple(i, j, k)); } } } reg[s] = true; dp[s] = ret; return ret; } int main(){ cin >> N; FOR(i,0,N) cin >> K[i]; FOR(i,0,1<<12) reg[i] = false; auto ans = f(0); if(get<0>(ans) == inf){ cout << -1 << endl; } else { int x, y, z; tie(x, y, z) = ans; printf("%d %d %d\n", x, y, z); } return 0; }