結果

問題 No.334 門松ゲーム
ユーザー h_nosonh_noson
提出日時 2016-03-14 11:52:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,159 bytes
コンパイル時間 624 ms
コンパイル使用メモリ 65,904 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-26 04:15:08
合計ジャッジ時間 1,341 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 4 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 4 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 11 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 11 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}

0