結果

問題 No.43 野球の試合
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2014-09-30 22:36:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 1,765 bytes
コンパイル時間 875 ms
コンパイル使用メモリ 101,384 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 19:56:04
合計ジャッジ時間 1,558 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))

#define MOD 1000000007

int N;

int f(int d[10][10]){
  int a;
  int s[10];
  clr(s,0);
  rep(i,0,N){
    int c = 0;
    rep(j,0,N){
      if(d[i][j]==1)c++;
    }
    s[i]=c;
  }
  a=s[0];
  set<int> se;
  rep(i,0,N){
    se.insert(s[i]);
  }
  vector<int> v(all(se));
  sort(all(v),greater<int>());
  rep(i,0,v.sz){
    if(v[i]==a){
      return i+1;
    }
  }
  return 0;
}

int main(){
  cin>>N;
  vector<string> v;
  rep(i,0,N){
    string s;
    cin>>s;
    v.pb(s);
  }
  int c = 0;
  rep(i,0,N){
    rep(j,i+1,N){
      if(v[i][j] == '-'){
        c++;
      }
    }
  }
  int mn = 1000;
  rep(b,0,(1<<c)){
    int a = 0;
    int d[10][10];
    clr(d,-1);
    rep(i,0,N){
      rep(j,i+1,N){
        if(v[i][j]=='o'){
          d[i][j] = 1;
          d[j][i] = 0;
        }
        else if(v[i][j]=='x'){
          d[i][j] = 0;
          d[j][i] = 1;
        }
        else if(v[i][j]=='-'){
          if(((b>>a)&1)==1){
            d[i][j] = 1;
            d[j][i] = 0;
          }
          else{
            d[i][j] = 0;
            d[j][i] = 1;
          }
          a++;
        }
      }
    }
    mn = min(mn,f(d));
  }
  cout << mn << endl;
  return 0;
}
0