結果

問題 No.43 野球の試合
ユーザー tottoripapertottoripaper
提出日時 2014-11-24 05:22:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,140 bytes
コンパイル時間 396 ms
コンパイル使用メモリ 48,552 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 22:41:29
合計ジャッジ時間 1,066 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// ナニソレイミワカンナイ

#include <cstdio>
#include <vector>
#include <algorithm>

int N;
char result[6][6];
int win[6];

int rec(int x, int y){
    if(y == N-1){
        std::vector<int> v(win, win+N);
        std::sort(v.begin(), v.end());
        v.erase(std::unique(v.begin(), v.end()), v.end());

        return v.size() - (std::lower_bound(v.begin(), v.end(), win[0]) - v.begin());
    }

    int nx, ny;
    if(x+1 == N){
        ny = y + 1;
        nx = ny + 1;
    }else{
        ny = y;
        nx = x + 1;
    }

    int res = N;
    if(result[y][x] == '-'){
        win[x] += 1;
        res = std::min(res, rec(nx, ny));
        win[x] -= 1;

        win[y] += 1;
        res = std::min(res, rec(nx, ny));
        win[y] -= 1;
    }else{
        res = std::min(res, rec(nx, ny));
    }

    return res;
}

int main(){
    scanf("%d", &N);

    for(int i=0;i<N;i++){
        scanf("%*c");
        for(int j=0;j<N;j++){
            scanf("%c", &result[i][j]);

            if(result[i][j] == 'o'){win[i] += 1;}
        }
    }

    printf("%d\n", rec(1, 0));
}
0