結果
| 問題 | No.43 野球の試合 | 
| コンテスト | |
| ユーザー |  tetsuzuki1115 | 
| 提出日時 | 2018-01-15 03:03:38 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 10 ms / 5,000 ms | 
| コード長 | 1,825 bytes | 
| コンパイル時間 | 805 ms | 
| コンパイル使用メモリ | 84,688 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-12-24 03:12:28 | 
| 合計ジャッジ時間 | 1,402 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 7 | 
コンパイルメッセージ
main.cpp: In function ‘int calc()’:
main.cpp:42:1: warning: control reaches end of non-void function [-Wreturn-type]
   42 | }
      | ^
            
            ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;
long long MOD = 1000000007;
int N;
int B[6][6];
int calc() {
    
    vector<int> V;
    int s0 = 0;
    for ( int i = 0; i < N; i++ ) {
        int s = 0;
        for ( int j = 0; j < N; j++ ) {
            if ( !i ) { s0 += B[i][j]; }
            s += B[i][j];
        }
        V.push_back(s);
    }
    sort( V.begin(), V.end(), greater<int>() );
    
    int cnt = 1;
    for ( int i = 0; i < V.size(); i++ ) {
        if ( i && V[i] != V[i-1] ) { cnt++; }
        if ( s0 == V[i] ) { return cnt; }
    }
     
}
int func() {
    
    for ( int i = 0; i < N-1; i++ ) {
    for ( int j = i+1; j < N; j++ ) {
        if ( B[i][j] == 0 ) {
            B[i][j] = 1;
            B[j][i] = -1;
            int s1 = func();
            B[i][j] = -1;
            B[j][i] = 1;
            int s2 = func();
            
            B[i][j] = 0;
            B[j][i] = 0;
            
            return min( s1, s2 );
        }
    }
    }
    
    return calc();
}
int main() {
    
    
    cin >> N;
    
    for ( int i = 0; i < N; i++ ) {
    for ( int j = 0; j < N; j++ ) {
        B[i][j] = 0;
    }
    }
    
    for ( int i = 0; i < N; i++ ) {
        string s;
        cin >> s;
        for ( int j = 0; j < N; j++ ) {
            if ( s[j] == 'o' ) { B[i][j] = 1; }
            else if ( s[j] == 'x' ) { B[i][j] = -1; }
        }
    }
    
    // for ( int j = 1; j < N; j++ ) {
        // if ( B[0][j] == 0 ) {
            // B[0][j] = 1;
            // B[j][0] = -1;
        // }
    // }
    
    cout << func() << endl;
    
    
    return 0;
}
            
            
            
        