結果

問題 No.334 門松ゲーム
ユーザー tetsuzuki1115tetsuzuki1115
提出日時 2018-04-07 17:16:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,620 bytes
コンパイル時間 771 ms
コンパイル使用メモリ 86,376 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 18:14:13
合計ジャッジ時間 1,711 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;


int N;
vector<int> A;
int Used = 0;
int best[3] = {-1,-1,-1};

void print() {
    for ( int i = 0; i < N; i++ ) {
        cout << ( Used&(1<<i) ? "1" : "0" );
    }
    cout << endl;
}

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

int func() {
    // print();

    int win = 0;

    vector<int> X;
    for ( int i = 0; i < N; i++ ) {
        if ( (Used&(1<<i)) == 0 ) { X.push_back(i); }
    }
    for ( int i = 0; i < X.size(); i++ ) {
    for ( int j = i+1; j < X.size(); j++ ) {
    for ( int k = j+1; k < X.size(); k++ ) {
        int t = Used;
        if ( isKadomatsu( A[X[i]], A[X[j]], A[X[k]] ) ) {
            // cout << A[X[i]] << " " << A[X[j]] << " " << A[X[k]] << endl;
            Used |= (1<<X[i]) | (1<<X[j]) | (1<<X[k]);
            if ( func() == 0 ) {
                best[0] = X[i];
                best[1] = X[j];
                best[2] = X[k];
                Used = t;
                return 1;
            } 
        }
        Used = t;
    }
    }
    }

    return 0;
}

int main() {
    
    cin >> N;
    A.resize(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }

    if ( func() ) {
        cout << best[0] << " " << best[1] << " " << best[2] << endl;
    }
    else { cout << -1 << endl; }


    return 0;
}
0