結果

問題 No.437 cwwゲーム
ユーザー koba-e964
提出日時 2016-11-01 01:55:55
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,398 bytes
コンパイル時間 707 ms
コンパイル使用メモリ 90,792 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-12 08:34:26
合計ジャッジ時間 1,913 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void){
  string s;
  cin >> s;
  int n = s.length();
  VI dp(1 << n, -1);
  dp[0] = 0;
  REP(bits, 1, 1 << n) {
    int ma = -1;
    REP(i, 0, n) {
      if ((bits & 1 << i) == 0) { continue; }
      if (s[i] == '0') { continue; }
      REP(j, i + 1, n) {
	if ((bits & 1 << j) == 0) { continue; }
	REP(k, j + 1, n) {
	  if (s[k] != s[j]) { continue; }
	  if (s[i] == s[j]) { continue; }
	  if ((bits & 1 << k) == 0) { continue; }
	  int prev_bit = bits ^ 1 << i ^ 1 << j ^ 1 << k;
	  if (dp[prev_bit] < 0) { continue; }
	  assert (prev_bit < bits);
	  int num = (s[i] - '0') * 100 + 11 * (s[j] - '0');
	  ma = max(ma, dp[prev_bit] + num);
	}
      }
    }
    dp[bits] = ma;
  }
  int ma = 0;
  REP(bits, 0, 1 << n) { ma = max(ma, dp[bits]); }
  cout << ma << endl;
}
0