Submission #486832


Source Code Expand

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
struct edge{ int to, time, cost; };
const double esp = 1e-9;
const int inf = (int)1e+9;

int d, n;
std::string w[10005];
std::string dp[205];
std::map<char, char> map;
int mode;

void init(){
	map['O'] = '0';
	map['D'] = '0';
	map['I'] = '1';
	map['Z'] = '2';
	map['E'] = '3';
	map['h'] = '4';
	map['s'] = '5';
	map['q'] = '6';
	map['L'] = '7';
	map['B'] = '8';
	map['G'] = '9';
}

std::string smax(std::string lhs, std::string rhs){
	if (mode == 0)return std::max(lhs, rhs);
	else if (mode == 1){
		if (lhs.size() == rhs.size())return std::max(lhs, rhs);
		return (lhs.size() > rhs.size() ? lhs : rhs);
	}
}

int main(){
	init();
	std::cin >> d >> n;
	std::string s = "0";
	rep(i, n){
		std::cin >> w[i];
		rep(j, w[i].size())w[i][j] = map[w[i][j]];
		std::reverse(w[i].begin(), w[i].end());
		s = std::max(s, w[i]);
	}
	rep(i, s.size()){
		if (s[i] != '0'){
			mode = 1;
			break;
		}
		if (i == s.size() - 1)mode = 2;
	}
	if (mode == 1 && s[0] == '0')mode = 0;
	if (mode == 2){
		std::cout << "0" << std::endl;
		return 0;
	}
	std::sort(w, w + n, [](const std::string &a, const std::string &b){return a + b > b + a; });

	rep(i, d + 1)dp[i] = "0";
	dp[0] = "";
	rep(i, n){
		for (int j = d; j >= 0; --j){
			if (dp[j] == "0")continue;
			int s = j + w[i].size();
			if (s <= d)dp[s] = smax(dp[s], dp[j] + w[i]);
		}
	}
	std::string ans = "0";
	rep(i, d + 1)ans = smax(ans, dp[i]);

	if (mode == 0){
		ans.insert(1, ".");
		while (ans[ans.size() - 1] == '0')ans.erase(ans.size() - 1);
	}
	std::cout << ans << std::endl;
	return 0;
}

Submission Info

Submission Time
Task D - 天下一電卓英作文
User Stack96
Language C++11 (GCC 4.9.2)
Score 0
Code Size 2043 Byte
Status WA
Exec Time 665 ms
Memory 1688 KiB

Judge Result

Set Name small All
Score / Max Score 0 / 45 0 / 75
Status
AC × 39
WA × 2
AC × 84
WA × 3
Set Name Test Cases
small 00_sample_1.txt, 00_sample_2.txt, 00_sample_4.txt, 05_small_random_1.txt, 05_small_random_10.txt, 05_small_random_11.txt, 05_small_random_12.txt, 05_small_random_13.txt, 05_small_random_14.txt, 05_small_random_15.txt, 05_small_random_16.txt, 05_small_random_17.txt, 05_small_random_18.txt, 05_small_random_19.txt, 05_small_random_2.txt, 05_small_random_20.txt, 05_small_random_21.txt, 05_small_random_22.txt, 05_small_random_23.txt, 05_small_random_24.txt, 05_small_random_25.txt, 05_small_random_26.txt, 05_small_random_27.txt, 05_small_random_28.txt, 05_small_random_29.txt, 05_small_random_3.txt, 05_small_random_30.txt, 05_small_random_4.txt, 05_small_random_5.txt, 05_small_random_6.txt, 05_small_random_7.txt, 05_small_random_8.txt, 05_small_random_9.txt, 10_manual_1.txt, 10_manual_2.txt, 10_manual_3.txt, 10_manual_4.txt, 10_manual_5.txt, 10_manual_6.txt, 10_manual_7.txt, 10_manual_8.txt
All 00_sample_1.txt, 00_sample_2.txt, 00_sample_4.txt, 05_small_random_1.txt, 05_small_random_10.txt, 05_small_random_11.txt, 05_small_random_12.txt, 05_small_random_13.txt, 05_small_random_14.txt, 05_small_random_15.txt, 05_small_random_16.txt, 05_small_random_17.txt, 05_small_random_18.txt, 05_small_random_19.txt, 05_small_random_2.txt, 05_small_random_20.txt, 05_small_random_21.txt, 05_small_random_22.txt, 05_small_random_23.txt, 05_small_random_24.txt, 05_small_random_25.txt, 05_small_random_26.txt, 05_small_random_27.txt, 05_small_random_28.txt, 05_small_random_29.txt, 05_small_random_3.txt, 05_small_random_30.txt, 05_small_random_4.txt, 05_small_random_5.txt, 05_small_random_6.txt, 05_small_random_7.txt, 05_small_random_8.txt, 05_small_random_9.txt, 10_manual_1.txt, 10_manual_2.txt, 10_manual_3.txt, 10_manual_4.txt, 10_manual_5.txt, 10_manual_6.txt, 10_manual_7.txt, 10_manual_8.txt, 50_sample_3.txt, 55_large_random_1.txt, 55_large_random_10.txt, 55_large_random_11.txt, 55_large_random_12.txt, 55_large_random_13.txt, 55_large_random_14.txt, 55_large_random_15.txt, 55_large_random_16.txt, 55_large_random_17.txt, 55_large_random_18.txt, 55_large_random_19.txt, 55_large_random_2.txt, 55_large_random_20.txt, 55_large_random_21.txt, 55_large_random_22.txt, 55_large_random_23.txt, 55_large_random_24.txt, 55_large_random_25.txt, 55_large_random_26.txt, 55_large_random_27.txt, 55_large_random_28.txt, 55_large_random_29.txt, 55_large_random_3.txt, 55_large_random_30.txt, 55_large_random_4.txt, 55_large_random_5.txt, 55_large_random_6.txt, 55_large_random_7.txt, 55_large_random_8.txt, 55_large_random_9.txt, 60_manual_1.txt, 60_manual_2.txt, 60_manual_3.txt, 60_manual_4.txt, 60_manual_5.txt, 60_manual_6.txt, 60_manual_7.txt, 60_manual_8.txt, 70_cl_killer_13.txt, 70_cl_killer_24.txt, 70_cl_killer_3.txt, 70_cl_killer_9.txt, 90_max_random_1.txt, 90_max_random_2.txt, 90_max_random_3.txt
Case Name Status Exec Time Memory
00_sample_1.txt AC 27 ms 916 KiB
00_sample_2.txt AC 25 ms 928 KiB
00_sample_4.txt AC 26 ms 840 KiB
05_small_random_1.txt AC 25 ms 924 KiB
05_small_random_10.txt AC 25 ms 844 KiB
05_small_random_11.txt AC 23 ms 860 KiB
05_small_random_12.txt AC 23 ms 924 KiB
05_small_random_13.txt AC 25 ms 924 KiB
05_small_random_14.txt AC 25 ms 796 KiB
05_small_random_15.txt AC 25 ms 924 KiB
05_small_random_16.txt AC 24 ms 796 KiB
05_small_random_17.txt AC 26 ms 928 KiB
05_small_random_18.txt AC 23 ms 924 KiB
05_small_random_19.txt AC 26 ms 920 KiB
05_small_random_2.txt WA 23 ms 800 KiB
05_small_random_20.txt AC 25 ms 800 KiB
05_small_random_21.txt AC 23 ms 800 KiB
05_small_random_22.txt AC 23 ms 800 KiB
05_small_random_23.txt AC 27 ms 924 KiB
05_small_random_24.txt AC 25 ms 852 KiB
05_small_random_25.txt AC 25 ms 840 KiB
05_small_random_26.txt AC 23 ms 924 KiB
05_small_random_27.txt AC 23 ms 928 KiB
05_small_random_28.txt AC 24 ms 912 KiB
05_small_random_29.txt AC 25 ms 804 KiB
05_small_random_3.txt AC 24 ms 916 KiB
05_small_random_30.txt AC 24 ms 920 KiB
05_small_random_4.txt AC 25 ms 852 KiB
05_small_random_5.txt AC 23 ms 928 KiB
05_small_random_6.txt AC 23 ms 928 KiB
05_small_random_7.txt AC 25 ms 932 KiB
05_small_random_8.txt AC 23 ms 924 KiB
05_small_random_9.txt AC 26 ms 916 KiB
10_manual_1.txt AC 25 ms 920 KiB
10_manual_2.txt AC 23 ms 800 KiB
10_manual_3.txt AC 25 ms 928 KiB
10_manual_4.txt AC 24 ms 916 KiB
10_manual_5.txt WA 25 ms 800 KiB
10_manual_6.txt AC 25 ms 924 KiB
10_manual_7.txt AC 23 ms 800 KiB
10_manual_8.txt AC 25 ms 924 KiB
50_sample_3.txt AC 25 ms 932 KiB
55_large_random_1.txt AC 214 ms 1056 KiB
55_large_random_10.txt AC 135 ms 1064 KiB
55_large_random_11.txt AC 62 ms 936 KiB
55_large_random_12.txt AC 164 ms 1312 KiB
55_large_random_13.txt AC 305 ms 1452 KiB
55_large_random_14.txt AC 70 ms 1112 KiB
55_large_random_15.txt AC 271 ms 1440 KiB
55_large_random_16.txt AC 163 ms 1180 KiB
55_large_random_17.txt AC 63 ms 1052 KiB
55_large_random_18.txt AC 138 ms 1192 KiB
55_large_random_19.txt AC 70 ms 1060 KiB
55_large_random_2.txt AC 182 ms 1056 KiB
55_large_random_20.txt AC 33 ms 856 KiB
55_large_random_21.txt AC 34 ms 852 KiB
55_large_random_22.txt AC 145 ms 1064 KiB
55_large_random_23.txt AC 28 ms 852 KiB
55_large_random_24.txt AC 347 ms 1320 KiB
55_large_random_25.txt AC 261 ms 1364 KiB
55_large_random_26.txt AC 106 ms 1052 KiB
55_large_random_27.txt AC 140 ms 1068 KiB
55_large_random_28.txt AC 94 ms 1056 KiB
55_large_random_29.txt AC 270 ms 1324 KiB
55_large_random_3.txt AC 110 ms 1324 KiB
55_large_random_30.txt AC 35 ms 924 KiB
55_large_random_4.txt AC 33 ms 796 KiB
55_large_random_5.txt AC 63 ms 1064 KiB
55_large_random_6.txt AC 381 ms 1440 KiB
55_large_random_7.txt AC 328 ms 1240 KiB
55_large_random_8.txt AC 141 ms 1064 KiB
55_large_random_9.txt AC 356 ms 1376 KiB
60_manual_1.txt AC 664 ms 1576 KiB
60_manual_2.txt AC 626 ms 1568 KiB
60_manual_3.txt AC 608 ms 1564 KiB
60_manual_4.txt AC 665 ms 1576 KiB
60_manual_5.txt WA 120 ms 1572 KiB
60_manual_6.txt AC 168 ms 1688 KiB
60_manual_7.txt AC 621 ms 1560 KiB
60_manual_8.txt AC 48 ms 1568 KiB
70_cl_killer_13.txt AC 51 ms 1112 KiB
70_cl_killer_24.txt AC 116 ms 1048 KiB
70_cl_killer_3.txt AC 341 ms 1364 KiB
70_cl_killer_9.txt AC 595 ms 1576 KiB
90_max_random_1.txt AC 152 ms 1580 KiB
90_max_random_2.txt AC 648 ms 1568 KiB
90_max_random_3.txt AC 200 ms 1568 KiB