結果

問題 No.43 野球の試合
ユーザー tetsuzuki1115tetsuzuki1115
提出日時 2018-01-15 03:03:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 1,825 bytes
コンパイル時間 1,168 ms
コンパイル使用メモリ 80,320 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 17:39:55
合計ジャッジ時間 1,619 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 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 1 ms
4,384 KB
testcase_07 AC 9 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int calc()’:
main.cpp:24:17: warning: control reaches end of non-void function [-Wreturn-type]
     vector<int> V;
                 ^

ソースコード

diff #

#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;
}
0