結果

問題 No.43 野球の試合
ユーザー KKT89KKT89
提出日時 2020-07-17 02:27:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 1,689 bytes
コンパイル時間 2,396 ms
コンパイル使用メモリ 115,304 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-17 13:38:39
合計ジャッジ時間 3,333 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

char fi[6][6];
char pi[6][6];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin >> fi[i][j];
        }
    }
    int res=n;
    int m=n*(n-1)/2;
    for(int i=0;i<(1<<m);i++){
        bool ok=1;
        int id=0;
        for(int j=0;j<n;j++){
            for(int k=0;k<j;k++){
                if((1<<id)&i){
                    pi[j][k]='o';
                    pi[k][j]='x';
                    if(fi[j][k]=='o'||fi[j][k]=='-'){}
                    else ok=0;    
                }
                else{
                    pi[j][k]='x';
                    pi[k][j]='o';
                    if(fi[j][k]=='x'||fi[j][k]=='-'){}
                    else ok=0;
                }
                id++;
            }
        }
        if(ok){
            vector<int> win;
            for(int j=0;j<n;j++){
                int cnt=0;
                for(int k=0;k<n;k++){
                    if(pi[j][k]=='o')cnt++;
                }
                win.push_back(cnt);
            }
            int one=win[0];
            sort(win.begin(), win.end());
            win.erase(unique(win.begin(), win.end()),win.end());
            int ju=1;
            for(auto p:win){
                if(p>one)ju++;
            }
            res=min(res,ju);
        }
    }
    printf("%d\n",res );
}
0