結果

問題 No.437 cwwゲーム
ユーザー tetsuzuki1115
提出日時 2018-04-07 01:19:50
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,354 bytes
コンパイル時間 820 ms
コンパイル使用メモリ 88,432 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-12 08:45:05
合計ジャッジ時間 2,000 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

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;

string S;
int x;

void print() {
    for ( int i = S.length()-1; i >= 0; i-- ) {
        cout << ( x&(1<<i) ? 1 : 0 );
    }
    cout << endl;
}

int func( int score ) {
    // print();
    int ret = score;

    vector<int> A;
    for ( int i = S.length()-1; i >= 0; i-- ) {
        if ( x&(1<<i) ) { A.push_back(i) ; }
    }

    for ( int a = 0; a < A.size(); a++ ) {
    for ( int b = a+1; b < A.size(); b++ ) {
    for ( int c = b+1; c < A.size(); c++ ) {
        int y = x;
        int sa = S.length()-1-A[a];
        int sb = S.length()-1-A[b];
        int sc = S.length()-1-A[c];
        if ( S[sa] != '0' && S[sa] != S[sb] && S[sb] == S[sc] ) {
            x = x^(1<<A[a])^(1<<A[b])^(1<<A[c]);
            string s = "";
            s += S[sa];
            s += S[sb];
            s += S[sc];
            // cout << s << endl;
            ret = max( ret, func( score+stoi(s) ) );
        }
        x = y;
    }
    }
    }

    return ret;
}

int main() {
    
    cin >> S;
    x = ( 1 << S.length() )-1;    

    cout << func(0) << endl;

    return 0;
}
0