結果

問題 No.43 野球の試合
ユーザー ふーらくたるふーらくたる
提出日時 2016-07-29 02:11:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 1,256 bytes
コンパイル時間 591 ms
コンパイル使用メモリ 71,408 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 10:40:36
合計ジャッジ時間 1,110 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <utility>
#include <set>
using namespace std;

typedef pair<int, int> PII;

const int kMaxN = 6;
string s[kMaxN];

int N;
vector<PII> matchs;

int Judge() {
    vector<int> win(N, 0);
    for (int r = 0; r < N; r++) {
        for (int c = 0; c < N; c++) {
            if (s[r][c] == 'o') win[r]++;
        }
    }
    set<int> win_set;
    for (int i = 0; i < N; i++) {
        win_set.insert(win[i]);
    }

    int rank = 1;
    for (auto it = win_set.rbegin(); it != win_set.rend(); it++) {
        if (win[0] == *it) return rank;
        rank++;
    }
    return rank;
}

int DFS(int index) {
    if (index == matchs.size()) {
        return Judge();
    }

    PII match = matchs[index];
    int row = match.first, col = match.second, rank = N;

    s[row][col] = 'o'; s[col][row] = 'x';
    rank = min(rank, DFS(index + 1));

    s[row][col] = 'x'; s[col][row] = 'o';
    rank = min(rank, DFS(index + 1));

    return rank;
}

int main() {
    cin >> N;

    for (int r = 0; r < N; r++) {
        cin >> s[r];
        for (int c = 0; c < r; c++) {
            if (s[r][c] == '-') {
                matchs.push_back(PII(r, c));
            }
        }
    }

    cout << DFS(0) << endl;

    return 0;
}
0