結果

問題 No.334 門松ゲーム
ユーザー MisterMister
提出日時 2020-04-13 22:32:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,175 bytes
コンパイル時間 1,026 ms
コンパイル使用メモリ 77,336 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-26 03:14:28
合計ジャッジ時間 1,881 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>

bool judge(int a, int b, int c) {
    return !(a == b || b == c || c == a ||
             (a < b && b < c) || (a > b && b > c));
}

std::vector<int> sim(std::vector<int> v) {
    int n = v.size();

    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            for (int k = j + 1; k < n; ++k) {
                if (!judge(v[i], v[j], v[k])) continue;

                std::vector<int> nv;
                for (int l = 0; l < n; ++l) {
                    if (l == i || l == j || l == k) continue;
                    nv.push_back(v[l]);
                }

                if (sim(nv).empty()) {
                    return {i, j, k};
                }
            }
        }
    }

    return {};
}

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> xs(n);
    for (auto& x : xs) std::cin >> x;

    auto ans = sim(xs);
    if (ans.empty()) {
        std::cout << -1 << std::endl;
    } else {
        for (auto a : ans) std::cout << a << " ";
        std::cout << std::endl;
    }
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0