結果

問題 No.43 野球の試合
ユーザー h_nosonh_noson
提出日時 2016-02-25 16:07:02
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,196 bytes
コンパイル時間 446 ms
コンパイル使用メモリ 61,540 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 20:01:20
合計ジャッジ時間 1,777 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define RREP(i,s,e) for (i = e-1; i >= s; i--)
#define rrep(i,n) RREP(i,0,n)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1e8

typedef long long ll;

int N;
int win[6];
string s[6];

int dfs(int x, int y) {
    int nx = x + (y+1) / N;
    int ny = (y+1) % N;
    if (x == N) {
        int i, rank = 1;
        bool used[6] {};
        REP (i,1,N) {
            if (!used[win[i]] && win[0] < win[i])
                rank++;
            used[win[i]] = true;
        }
        return rank;
    }
    if (s[x][y] == '-') {
        int rank;
        win[x]++;
        s[x][y] = 'o';
        s[y][x] = 'x';
        rank = dfs(nx,ny);
        win[x]--;
        s[x][y] = 'x';
        s[y][x] = 'o';
        return min(rank,dfs(nx,ny));
    }
    else if (s[x][y] == 'o')
        win[x]++;
    return dfs(nx,ny);
}

int main() {
    int i, j;
    cin >> N;
    rep (i,N) cin >> s[i];
    rep (j,N) {
        if (s[0][j] == '-' || s[0][j] == 'o') {
            s[j][0] = 'x';
            s[0][j] = 'o';
            win[0]++;
        }
    }
    cout << dfs(1,0) << endl;
    return 0;
}
0