結果

問題 No.334 門松ゲーム
ユーザー moti
提出日時 2016-01-16 00:29:55
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 1,947 bytes
コンパイル時間 953 ms
コンパイル使用メモリ 114,608 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-19 19:43:23
合計ジャッジ時間 1,795 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
using namespace std;
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
typedef long long ll;
int const inf = 1<<29;
int N;
int A[15];
bool kadomatsu(int a, int b, int c) {
if(!(A[a] != A[b] && A[b] != A[c] && A[c] != A[a])) { return false; }
if(A[b] < A[a] && A[b] < A[c]) { return true; }
if(A[b] > A[a] && A[b] > A[c]) { return true; }
return false;
}
bool dfs(set<int>& used) {
bool win = 0;
rep(i, N) REP(j, i+1, N) REP(k, j+1, N) {
if(used.count(i) || used.count(j) || used.count(k)) { continue; }
if(kadomatsu(i, j, k)) {
used.insert(i);
used.insert(j);
used.insert(k);
win = win || !dfs(used);
used.erase(i);
used.erase(j);
used.erase(k);
}
}
return win;
}
int main() {
cin >> N;
rep(i, N) {
cin >> A[i];
}
vector<int> res = {inf, inf, inf};
bool win = 0;
rep(i, N) REP(j, i+1, N) REP(k, j+1, N) {
if(kadomatsu(i, j, k)) {
set<int> used;
used.insert(i);
used.insert(j);
used.insert(k);
if(!dfs(used)) {
win = 1;
res = min(res, {i, j, k});
}
}
}
if(win) {
cout << res[0] << " " << res[1] << " " << res[2] << endl;
}
else {
cout << "-1\n";
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0