結果

問題 No.43 野球の試合
ユーザー CleyLCleyL
提出日時 2022-01-17 00:15:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 5,000 ms
コード長 1,737 bytes
コンパイル時間 1,019 ms
コンパイル使用メモリ 80,760 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-15 06:50:53
合計ジャッジ時間 1,833 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;cin>>n;
  vector<vector<char>> A(n,vector<char>(n));
  vector<vector<char>> T(n,vector<char>(n,'.'));
  for(int i = 0; n > i; i++){
    for(int j = 0; n > j; j++){
      cin>>A[i][j];
    }
  }
  int ret = n+1;
  for(int i = 0; (1<<(n*(n-1)/2)) > i; i++){
    bool ok = true;
    for(int j = 0; (n*(n-1)/2) > j; j++){
      //n-1, n-2, ..., 1
      int nw = j+1;
      int v = 0;
      for(int k = n-1; 1 <= k; k--){
        nw -= k;
        if(nw <= 0){
          nw+=k;
          break;
        }
        v++;
      }
      char x = ((i & (1<<j)) ? 'o' : 'x');
      nw +=v;
      //cout << j << " " << v << " " << nw << " " << A[v][nw] << " " << x << endl;
      if(!(A[v][nw] == '-' || A[v][nw] == x)){
        ok = false;
      }
      T[v][nw] = x;
      T[nw][v] = (x=='x'?'o':'x');
    }
    if(!ok)continue;
    //cout << "!!" << i << endl;
    vector<pair<int,int>> Z;
    // for(int j = 0; n > j; j++){
    //   for(int k = 0; n > k; k++){
    //     cout << T[j][k] << " ";
    //   }
    //   cout << endl;
    // }
    for(int j = 0; n > j; j++){
      int win = 0;
      for(int k = 0; n > k; k++){
        if(j==k)continue;
        if(T[j][k] == 'o')win++;
      }
      Z.push_back({j,win});
    }
    
    sort(Z.begin(),Z.end(),[&](pair<int,int> a, pair<int,int> b){return a.second > b.second;});
    // for(int j = 0; n > j; j++){
    //   cout << Z[j].first << " " << Z[j].second << endl;
    // }
    int rank = 1;

    for(int j = 0; n > j; j++){
      if(j && Z[j-1].second != Z[j].second){
        rank++;
      }
      if(Z[j].first == 0){
        ret = min(ret,rank);
      }
    }
  }
  cout << ret << endl;
}
0