結果

問題 No.43 野球の試合
ユーザー krotonkroton
提出日時 2014-10-31 06:54:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 1,034 bytes
コンパイル時間 373 ms
コンパイル使用メモリ 53,220 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 23:36:27
合計ジャッジ時間 1,136 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 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 2 ms
4,376 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

int N;
string match[10];

int win[10];
int sum[10];

int dfs(int id){
    if(id >= N * N){
        for(int i=0;i<N;i++)sum[i] = 0;
        for(int i=0;i<N;i++){
            win[i] = 0;
            for(int j=0;j<N;j++)if(match[i][j] == 'o')++win[i];
            sum[win[i]] = 1;
        }
        for(int i=N-2;i>=0;i--){
            sum[i] += sum[i+1];
        }
        return sum[win[0]];
    }
   
    int res = 100;
    int y = id / N, x = id % N;
    
    if(match[y][x] == '-'){
        match[y][x] = 'o';
        match[x][y] = 'x';
        
        res = min(res, dfs(id + 1));
        
        match[y][x] = 'x';
        match[x][y] = 'o';
        
        res = min(res, dfs(id + 1));
        
        match[y][x] = '-';
        match[x][y] = '-';
    } else {
        res = dfs(id + 1);
    }
    
    return res;
}
int main(){
    cin >> N;
    for(int i=0;i<N;i++)cin >> match[i];
    
    cout << dfs(0) << endl;
    return 0;
}
0