結果
問題 | No.334 門松ゲーム |
ユーザー |
![]() |
提出日時 | 2016-03-14 11:52:04 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 11 ms / 2,000 ms |
コード長 | 1,159 bytes |
コンパイル時間 | 758 ms |
コンパイル使用メモリ | 65,092 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-25 12:02:59 |
合計ジャッジ時間 | 1,147 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; #define RREP(i,s,e) for (i = e-1; i >= s; i--) #define rrep(i,n) RREP(i,0,n) #define REP(i,s,e) for (i = s; i < e; i++) #define rep(i,n) REP(i,0,n) #define INF 1e8 typedef long long ll; int ans1, ans2, ans3; bool dfs(vector<int> a, int d) { int i, j, k, n; bool ret, ans; if (a.size() < 3) return false; n = a.size(); ans = false; rrep (i,n-2) RREP (j,i+1,n-1) RREP (k,j+1,n) { if (a[i] != a[k] && (a[j] < min(a[i],a[k]) || a[j] > max(a[i],a[k]))) { vector<int> b = a; auto p = b.begin(); b.erase(p+k); b.erase(p+j); b.erase(p+i); if (!dfs(b,d+1)) { if (d == 1) { ans1 = i; ans2 = j; ans3 = k; } ans = true; } } } return ans; } int main() { int i, j, k, n; vector<int> a; cin >> n; rep (i,n) { cin >> k; a.push_back(k); } if (dfs(a,1)) cout << ans1 << " " << ans2 << " " << ans3 << endl; else cout << -1 << endl; return 0; }