結果

問題 No.43 野球の試合
コンテスト
ユーザー tottoripaper
提出日時 2014-11-24 05:22:20
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,140 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 484 ms
コンパイル使用メモリ 66,784 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-06 07:38:58
合計ジャッジ時間 1,471 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

#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