結果

問題 No.437 cwwゲーム
ユーザー tkmst201tkmst201
提出日時 2017-05-05 17:13:27
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,392 bytes
コンパイル時間 1,243 ms
コンパイル使用メモリ 148,440 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-12 09:48:33
合計ジャッジ時間 4,176 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 3 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 2 ms
4,352 KB
testcase_08 RE -
testcase_09 AC 3 ms
4,352 KB
testcase_10 WA -
testcase_11 RE -
testcase_12 WA -
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 WA -
testcase_16 AC 2 ms
4,348 KB
testcase_17 WA -
testcase_18 AC 2 ms
4,352 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 WA -
testcase_24 AC 2 ms
4,352 KB
testcase_25 AC 2 ms
4,352 KB
testcase_26 WA -
testcase_27 AC 2 ms
4,352 KB
testcase_28 AC 3 ms
4,352 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,352 KB
testcase_33 AC 2 ms
4,352 KB
testcase_34 AC 2 ms
4,352 KB
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,356 KB
testcase_38 AC 2 ms
4,352 KB
testcase_39 AC 2 ms
4,348 KB
testcase_40 AC 2 ms
4,352 KB
testcase_41 AC 2 ms
4,352 KB
testcase_42 WA -
testcase_43 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int dfs(std::vector<int>)’:
main.cpp:39:20: warning: ‘mapos’ may be used uninitialized in this function [-Wmaybe-uninitialized]
      res += n[mapos] * 100 + n[k] * 10 + n[j];
                    ^

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> P;

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

string n;

int dfs(vector<int> v) {
	int res;
	
	if (v.size() == 4) {
		res = 0;
		bool done[13] = {};
		
		REP(i, 4) {
			bool ok = false;
			
			for (int j = n.size() - 1; j >= 2; j--) if (!done[j] && n[j] == v[i]) {
				for (int k = j - 1; k >= 1; k--) if (!done[k] && n[k] == v[i]) {
					int ma = -1, mapos;
					REP(l, k) if (n[l] != 0 && n[l] != v[i] && !done[l] && chmax(ma, n[l])) mapos = l;
					
					res += n[mapos] * 100 + n[k] * 10 + n[j];
					done[mapos] = done[j] = done[k] = true;
					
					ok = true;
					j = k = 0;
				}
			}
			
			if (!ok) break;
		}
	}
	else {
		res = 0;
		
		v.push_back(0);
		REP(i, 10) {
			v[v.size() - 1] = i;
			chmax(res, dfs(v));
		}
	}
	return res;
}

int main() {
	cin >> n;
	REP(i, n.size()) n[i] -= '0';
	
	cout << dfs(vector<int>()) << endl;
	
	return 0;
}
0