結果

問題 No.43 野球の試合
ユーザー face4face4
提出日時 2018-07-24 22:25:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 1,410 bytes
コンパイル時間 815 ms
コンパイル使用メモリ 78,700 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-06 01:11:14
合計ジャッジ時間 1,698 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

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

    char s[n][n];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> s[i][j];
        }
    }

    vector<pair<int,int>> v;
    int residual = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(s[i][j] == '-'){
                residual++;
                v.push_back({i,j});
            }  
        }
    }

    int ans = 6;
    for(int i = 0; i < 1<<residual; i++){
        for(int j = 0; j < residual; j++){
            if(i & 1<<j){
                s[v[j].first][v[j].second] = 'o';
                s[v[j].second][v[j].first] = 'x';
            }else{
                s[v[j].first][v[j].second] = 'x';
                s[v[j].second][v[j].first] = 'o';
            }
        }

        set<int> scores;
        int zero = 0;
        for(int i = 0; i < n; i++) if(s[0][i] == 'o')   zero++;
        scores.insert(zero);
        for(int i = 1; i < n; i++){
            int tmp = 0;
            for(int j = 0; j < n; j++)  if(s[i][j] == 'o')  tmp++;
            scores.insert(tmp);
        }

        int pos = 1;
        for(set<int>::reverse_iterator it = scores.rbegin();; it++){
            if(*it == zero) break;
            pos++;
        }

        ans = min(ans, pos);
    }

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