結果

問題 No.437 cwwゲーム
ユーザー seven_threeseven_three
提出日時 2020-07-14 22:39:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 1,791 bytes
コンパイル時間 932 ms
コンパイル使用メモリ 99,532 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 18:45:24
合計ジャッジ時間 2,374 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 6 ms
5,376 KB
testcase_08 AC 6 ms
5,376 KB
testcase_09 AC 6 ms
5,376 KB
testcase_10 AC 6 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 10 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 6 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 1 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 1 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int dp[1000][4400] = { 0 };
int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<pair<int, int>> vec;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                if (s[j] == s[k] && s[i] != s[j] && s[i] != '0') {
                    bitset<12> bit;
                    bit[i] = 1;
                    bit[j] = 1;
                    bit[k] = 1;
                    string s1 = "";
                    s1 += s[i];
                    s1 += s[j];
                    s1 += s[k];
                    int x = stoi(s1);
                    vec.emplace_back(make_pair(bit.to_ulong(), x));
                }
            }
        }
    }
    for (int i = 0; i < vec.size(); i++) {
        for (int j = 0; j < (1 << n); j++) {
            bool b = true;
            bitset<12> bit = vec[i].first, bit1 = j;
            for (int i = 0; i < 12; i++) {
                if (bit[i] == 1 && bit1[i] == 1) {
                    b = false;
                }
            }
            if (b) {
                dp[i + 1][j | vec[i].first] = max(dp[i + 1][j | vec[i].first], dp[i][j] + vec[i].second);
            }
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        }
    }
    int ans = 0;
    for (int i = 0; i < (1 << n); i++) {
        if (ans < dp[vec.size()][i]) {
            ans = dp[vec.size()][i];
        }
    }
    cout << ans << endl;
}
0