結果

問題 No.43 野球の試合
ユーザー ShibuyapShibuyap
提出日時 2020-02-25 23:25:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 1,468 bytes
コンパイル時間 1,998 ms
コンパイル使用メモリ 165,760 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 15:45:09
合計ジャッジ時間 2,549 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n;
    cin >> n;

    int ans = 100;

    string s[n];
    rep(i,n)cin >> s[i];

    int m = n * (n-1) / 2;

    rep(i,1<<m){
        // cout << i;
        int ii = i;
        int f[m] = {};
        rep(j,m){
            f[j] = ii % 2;
            ii /= 2;
        }
        int cnt = 0;
        string t[n];
        rep(j,n)t[j] = s[j];
        rep(j,n){
            srep(k,j+1,n){
                if(t[j][k] == '-'){
                    if(f[cnt]){
                        t[j][k] = 'o';
                        t[k][j] = 'x';
                    }else{
                        t[j][k] = 'x';
                        t[k][j] = 'o';
                    }
                }
                cnt++;
            }
        }
        // cout << "OK";
        int b[n+1] = {};
        rep(j,n){
            int c = 0;
            rep(k,n)if(t[j][k] == 'o')c++;
            b[c] = 1;
        }
        int c = 0;
        rep(k,n)if(t[0][k] == 'o')c++;
        int ju = 0;
        drep(j,n+1){
            if(b[j])ju++;
            if(c == j)ans = min(ans, ju);
        }
        // cout << endl;
    }

    cout << ans << endl;
    return 0;
}
 
 
0