結果

問題 No.43 野球の試合
ユーザー tottoripaper
提出日時 2014-11-24 05:22:20
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,140 bytes
コンパイル時間 634 ms
コンパイル使用メモリ 50,556 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2025-01-02 21:08:08
合計ジャッジ時間 1,223 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:46:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   46 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
main.cpp:49:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   49 |         scanf("%*c");
      |         ~~~~~^~~~~~~
main.cpp:51:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   51 |             scanf("%c", &result[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~

ソースコード

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