結果

問題 No.43 野球の試合
ユーザー なおなお
提出日時 2014-10-20 00:17:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 1,031 bytes
コンパイル時間 775 ms
コンパイル使用メモリ 69,728 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-28 21:30:41
合計ジャッジ時間 1,282 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))

int N;
int maxrank = 6;
string sv[6];

void check(){
    set<int> s;
    int w = 0;
    REP(i,N){
        //cerr << sv[i] << endl;
        int win = 0;
        REP(j,N) if(sv[i][j] == 'o') win++;
        if(i == 0) w = win;
        s.insert(win);
    }
    int rank = 1;
    for(auto it = s.rbegin(); it != s.rend(); ++it){
        if(*it > w) rank++; else break;
    }
    maxrank = min(maxrank, rank);
}

void dfs(int i, int j){
    if(j == N) return dfs(i+1,0);
    if(i == N) return check();

    if(sv[i][j] != '-') return dfs(i,j+1);
    sv[i][j] = 'o'; sv[j][i] = 'x';
    dfs(i,j+1);
    sv[i][j] = 'x'; sv[j][i] = 'o';
    dfs(i,j+1);
    sv[i][j] = sv[j][i] = '-';
}

int main(){
    cin >> N;
    REP(i,N) cin >> sv[i];
    dfs(0,0);
    cout << maxrank << endl;
    return 0;
}
0