結果

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

ソースコード

diff #
プレゼンテーションモードにする

/* -*- coding: utf-8 -*-
*
* 437.cc: No.437 cww - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 13;
const int NBITS = 1 << MAX_N;
/* typedef */
typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;
typedef map<int,int> mii;
/* global variables */
int ds[MAX_N];
int dp[NBITS];
/* subroutines */
/* main */
int main() {
string s;
cin >> s;
int n = s.size();
for (int i = 0; i < n; i++) ds[i] = s[i] - '0';
mii cwws;
for (int i = 0; i < n; i++)
if (ds[i] > 0)
for (int j = i + 1; j < n; j++)
if (ds[i] != ds[j])
for (int k = j + 1; k < n; k++)
if (ds[j] == ds[k]) {
int bits = ((1 << i) | (1 << j) | (1 << k));
int d = ds[i] * 100 + ds[j] * 11;
cwws[bits] = d;
//printf("%d,%d,%d=%d\n", i, j, k, d);
}
//printf("%lu\n", cwws.size());
int nbits = 1 << n;
for (int bits = 0; bits < nbits; bits++) {
for (mii::iterator mit = cwws.begin(); mit != cwws.end(); mit++)
if ((bits & mit->first) == mit->first) {
int bits0 = bits ^ mit->first;
int d0 = mit->second + dp[bits0];
if (dp[bits] < d0) dp[bits] = d0;
}
}
printf("%d\n", dp[nbits - 1]);
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0