結果

問題 No.43 野球の試合
ユーザー itezpaceitezpace
提出日時 2016-08-09 08:32:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,359 bytes
コンパイル時間 597 ms
コンパイル使用メモリ 70,236 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 22:36:09
合計ジャッジ時間 1,134 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int n;
char a[6][6];

vector<int> calc(int x){
  vector<int> vc;
  int y,z;
  y=0;
  z=0;
  for(int i=0; i<n; ++i){
    if(a[x][i]=='o'){
      y++;
    } else if(a[x][i]=='-'){
      z++;
    }
  }
  vc.push_back(y);
  vc.push_back(z);
  return vc;
}

int main(){
  cin>>n;
  string s;
  for(int i=0; i<6; ++i){
    for(int j=0; j<6; ++j){
      a[i][j]='#';
    }
  }
  for(int i=0; i<n; ++i){
    cin>>s;
    for(int j=0; j<s.size(); ++j){
      a[i][j]=s[j];
    }
  }
  for(int i=0; i<n; ++i){
    if(a[0][i]=='-'){
      a[0][i]='o';
      a[i][0]='x';
    }
  }
  for(int i=1; i<n; ++i){
    for(int j=0; j<n; ++j){
      if(a[i][j]=='-'){
        vector<int> vz,vi,vj;
        vz=calc(0);
        vi=calc(i);
        vj=calc(j);
        if(vi[0]==vz[0] && vj[0]!=vz[0]){
          a[i][j]='x';
          a[j][i]='o';
        } else if(vi[0]!=vz[0] && vj[0]==vz[0]){
          a[i][j]='o';
          a[j][i]='x';
        } else {
        if(vi[0]>vj[0]){
          a[i][j]='x';
          a[j][i]='o';
        } else if(vi[0]<vj[0]){
          a[i][j]='o';
          a[j][i]='x';
        } else {
          if(vi[1]>vj[1]){
            a[i][j]='x';
            a[j][i]='o';
          } else if(vi[1]<vj[1]){
            a[i][j]='o';
            a[j][i]='x';
          } else {
            a[i][j]='o';
            a[j][i]='x';
          }
        }
        }
      }
    }
  }
  int x;
  x=0;
  int b[n];
  for(int i=0; i<n; ++i){
    for(int j=0; j<n; ++j){
      if(a[i][j]=='o') x++;
    }
    b[i]=x;
    x=0;
  }
  int f;
  f=0;
  while(1){
    if(b[0]==0) break;
    for(int i=1; i<n; ++i){
      if(b[0]==b[i]){
        f=1;
        break;
      }
    }
    if(f==1) break;
    int m,p,q;
    p=0;
    q=0;
    for(int i=1; i<n; ++i){
      if(b[i]>b[0]){
        p=1;
        m=0;
        for(int j=1; j<n; ++j){
          if(i!=j && b[i]==b[j]) m=1;
        }
        if(m==1){
          //
        } else {
        q=1;
        for(int j=1; j<n; ++j){
          if(b[i]+1==b[j]){
            b[0]--;
            b[i]++;
            break;
          }
        }
        }
      }
    }
    if(p==0) break;
    if(q==0) break;
  }
  set<int> si;
  for(int i=1; i<n; ++i){
    if(b[i]>b[0]) si.insert(b[i]);
  }
  cout<<si.size()+1<<endl;
  return 0;
}
0