結果

問題 No.334 門松ゲーム
ユーザー BantakoBantako
提出日時 2018-12-30 22:57:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 1,105 bytes
コンパイル時間 1,765 ms
コンパイル使用メモリ 166,016 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 11:43:59
合計ジャッジ時間 2,854 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 21 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 9 ms
5,376 KB
testcase_08 AC 8 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 18 ms
5,376 KB
testcase_11 AC 7 ms
5,376 KB
testcase_12 AC 92 ms
5,376 KB
testcase_13 AC 10 ms
5,376 KB
testcase_14 AC 18 ms
5,376 KB
testcase_15 AC 102 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:32:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   32 | main(){
      | ^~~~
main.cpp: In function 'bool dfs(int)':
main.cpp:27:50: warning: 'c' may be used uninitialized [-Wmaybe-uninitialized]
   27 |         if(iswin)cout << a << " " << b << " " << c << endl;
      |                                                  ^
main.cpp:13:18: note: 'c' was declared here
   13 |     int a = -1,b,c;
      |                  ^
main.cpp:27:43: warning: 'b' may be used uninitialized [-Wmaybe-uninitialized]
   27 |         if(iswin)cout << a << " " << b << " " << c << endl;
      |                                           ^~~
main.cpp:13:16: note: 'b' was declared here
   13 |     int a = -1,b,c;
      |                ^

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;    
int N;
vector<int> K,used;
bool dfs(int depth){

    //rep(i,0,N)cout << used[i] << " \n"[i==N-1];
    bool iswin = 0;
    int a = -1,b,c;
    rep(i,0,N)rep(j,i+1,N)rep(k,j+1,N){
        if(K[i] == K[j] || K[j] == K[k] || K[k] == K[i])continue;
        if(K[j] != max({K[i], K[j], K[k]}) && K[j] != min({K[i], K[j], K[k]}))continue;
        if(used[i] == 1|| used[j] == 1|| used[k] == 1)continue;
        used[i] = used[j] = used[k] = 1; 
        bool f = !dfs(depth + 1);
        iswin |= f;
        if(f && a == -1){
            a = i,b = j,c = k;
        }
        used[i] = used[j] = used[k] = 0;
    }
    if(depth == 0){
        if(iswin)cout << a << " " << b << " " << c << endl;
        else    cout << -1 << endl;
    }
    return iswin;
}
main(){
    cin >> N;
    K.resize(N),used.resize(N);
    rep(i,0,N)cin >> K[i];
    dfs(0);
    //勝ちならtrue
    //if(dfs(0))cout << "win" << endl;
    //else cout << "lose" << endl;
}
0