結果
| 問題 | No.334 門松ゲーム |
| コンテスト | |
| ユーザー |
nenuon
|
| 提出日時 | 2017-07-01 14:19:24 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,575 bytes |
| 記録 | |
| コンパイル時間 | 830 ms |
| コンパイル使用メモリ | 94,856 KB |
| 実行使用メモリ | 814,720 KB |
| 最終ジャッジ日時 | 2024-10-05 03:34:55 |
| 合計ジャッジ時間 | 4,383 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | MLE * 1 -- * 2 |
| other | -- * 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;
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 || z == x) return false;
if(x > y && y < z) return true;
if(x < y && y > z) return true;
return false;
}
// sは集合
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; // 調査済み
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(){
FOR(i,0,1<<12) reg[i] = false;
cin >> n;
FOR(i,0,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;
printf("%d %d %d\n",x,y,z);
}
return 0;
}
nenuon