QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#799916#9549. The MagicianSword1E1RE 0ms0kbC++204.3kb2024-12-05 19:33:102024-12-05 19:33:13

Judging History

This is the latest submission verdict.

  • [2024-12-05 19:33:13]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 0kb
  • [2024-12-05 19:33:10]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long

#define dbg(x...) \
do { \
std::cout << #x << " -> "; \
err(x); \
} while (0)

void err() {
	std::cout << std::endl;
}

template<class T, class... Ts>
void err(T arg, Ts &... args) {
	std::cout << fixed << setprecision(10) << arg << ' ';
	err(args...);
}

string dic = "DCHS";

void GENSHEN_START() {
	int n;cin >> n;
	int cnt[4] = {};
	int pre_cnt[4] = {};
	int ok[4] ={};
	int pre_ok[4] = {};
	for (int i = 1;i <= n;++i) {
		string s;cin >> s;
		cnt[dic.find(s[i])]++;
	} 
	int ans = 0,sum = 0;
	for (int i = 0;i < 4;i++) {
		if (cnt[i]) ok[i] = 1;
		ans += cnt[i] / 5;
		cnt[i] %= 5;
		sum += cnt[i];
	}
	for (int i = 0;i < 4;i++) pre_cnt[i] = cnt[i],pre_ok[i] = ok[i];
	int op[6] = {};
	int pre_op[6] = {};
	for (int i = 0;i < 6;i++) cin >> op[i];
	for (int i = 0;i < 6;i++) pre_op[i] = op[i];
	if (sum < 5) {
		cout << ans << '\n';
		return ;
	}
	else if (sum < 10) {
		int mx = ans;
		for (int i = 0;i < 4;++i) {
			if (cnt[i] == 0) {
				if (op[i] + op[4] + op[5] == 3) {
					mx = max(mx,ans + 1);
				}	
			}
			else if (cnt[i] == 1) {
				if (op[i] == 1) {
					if (op[4] == 1 || op[5] == 1) mx = max(mx,ans + 1);
				}
			}
			else if (cnt[i] == 2) {
				if (op[i] == 1) {
					mx = max(mx,ans + 1);
				}
			}
			else if (cnt[i] == 3) {
				if ((op[i] == 1) || (op[4] == 1 && op[5] == 1)) {
					mx = max(mx,ans + 1);
				}
			}
			else if (cnt[i] == 4) {
				if ((op[i] == 1) || (op[4] == 1 || op[5] == 1)) {
					mx = max(mx,ans + 1);
				}
			}
		}
		cout << mx << '\n';
	}
	else if (sum < 15) {
		int mx = ans;
		for (int i = 0;i < 4;++i) {
			if (cnt[i] == 0) {
				if (op[i] + op[4] + op[5] == 3) {
					mx = max(mx,ans + 1);
				}	
			}
			else if (cnt[i] == 1) {
				if (op[i] == 1) {
					if (op[4] == 1 || op[5] == 1) mx = max(mx,ans + 1);
				}
			}
			else if (cnt[i] == 2) {
				if (op[i] == 1) {
					mx = max(mx,ans + 1);
				}
			}
			else if (cnt[i] == 3) {
				if ((op[i] == 1) || (op[4] == 1 && op[5] == 1)) {
					mx = max(mx,ans + 1);
				}
			}
			else if (cnt[i] == 4) {
				if ((op[i] == 1) || (op[4] == 1 || op[5] == 1)) {
					mx = max(mx,ans + 1);
				}
			}
		}
		for (int i = 0;i < 4;i++) {
			for (int j = 0;j < 4;j++) {
				if (i == j) continue;
				if (cnt[i] + cnt[j] <= 1) continue;
				if (cnt[i] == 1 && cnt[j] == 1) {
					if (op[i] && op[j] && op[4] && op[5]) mx = max(mx,ans + 2);
				}
				else if (cnt[i] == 1 && cnt[j] == 2) {
					if (op[i] && op[j] && (op[4] || op[5])) mx = max(mx,ans + 2);
				}
				else if (cnt[i] == 2 && cnt[j] == 1) {
					if (op[i] && op[j] && (op[4] || op[5])) mx = max(mx,ans + 2);
				}
				else if (cnt[i] == 2 && cnt[j] == 2) {
					if (op[i] && op[j]) mx = max(mx,ans + 2);
				}
				else if (cnt[i] == 1 && cnt[j] == 4) {
					if (op[i] && (op[j] + op[4] + op[5]) >= 2) mx = max(mx,ans + 2);
				}
				else if (cnt[i] == 4 && cnt[j] == 1) {
					if (op[j] && (op[i] + op[4] + op[5]) >= 2) mx = max(mx,ans + 2);
				}
				else if (cnt[i] == 3 && cnt[j] == 2) {
					if (op[j] && (op[i] || (op[4] && op[5]))) mx = max(mx,ans + 2);
				}
				else if (cnt[i] == 2 && cnt[j] == 3) {
					if (op[i] && (op[j] || (op[4] && op[5]))) mx = max(mx,ans + 2);
				}
				else if (cnt[i] == 2 && cnt[j] == 4) {
					if (op[i] && (op[j] + op[4] + op[5]) >= 1) mx = max(mx,ans + 2);
				}
				else if (cnt[i] == 4 && cnt[j] == 2) {
					if (op[j] && (op[i] + op[4] + op[5]) >= 1) mx = max(mx,ans + 2);
				}
				else if (cnt[i] == 3 && cnt[j] == 3) {
					if (op[i] + op[j] + op[4] + op[5] >= 3) mx = max(mx,ans + 2);
				}
				else if (cnt[i] == 4 && cnt[j] == 3) {
					if (op[i] + op[j] + op[4] + op[5] >= 3) mx = max(mx,ans + 2);
				}
				else if (cnt[i] == 3 && cnt[j] == 4) {
					if (op[i] + op[j] + op[4] + op[5] >= 3) mx = max(mx,ans + 2);
				}
				else if (cnt[i] == 4 && cnt[j] == 4) {
					if (op[i] + op[j] + op[4] + op[5] >= 2) mx = max(mx,ans + 2);
				}
			}
		}
		cout << mx << '\n';
	}
	else {
		int all = 0;
		for (int i = 0;i < 6;i++) all += op[i];
		cout << min(ans + 3,ans + all) << '\n';
	}
}

signed main()
{
	ios::sync_with_stdio(false);cin.tie(nullptr);
	int T = 1;
	cin >> T;
	while (T--) GENSHEN_START();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

4
5
2H 3H 4H 5H 6D
1 1 1 1 0 0
5
2S 3S 4D 5C 6D
0 0 1 0 1 1
5
2S 3S 4D 5C 6D
0 0 1 0 1 0
13
AS 2S 3S 4S 5H 6H 7H 8H 9H TH JH QH KH
0 0 0 0 0 1

output:


result: