E. Corrupted Scoreboard Log
大模拟,暴搜。
预处理出 \(0\sim 299\) 和 \(1\sim 100\) 的组合字符串,后续处理出每个 \(\text{try}\) 前面的数字就能得到是哪些组合了,注意 \(\text{22tries}\) 这种还可以拆成 \(\text{2 2 tries}\),需要对过没过这道题分开处理。
数据有 \(00\) ,如果你的代码没处理,记得特判。
第一个数字串包含题数罚时和第一个 \(\text{try}\) 的信息,可以枚举信息然后得到题数和罚时,题数最多两位,再分开讨论一下就行。
剩下的是一些细节问题,比如我的一开始是 \(\text{dfs}\) 预处理后面的组合,超时了之后把 \(\text {dfs}\) 挪到枚举里的时候变量名复用了,导致里面 \(\text{dfs}\) 搜索的时候把外面的变量改了 ...
点击查看代码
#include <bits/stdc++.h>using namespace std;using i64 = long long;map<string, vector<array<int, 2>>> mp;int M;void solve() {string s;cin >> s;if (s == "00") {cout << 0 << " " << 0 << "\n";return;}vector<string> pro;int lst = 0;for (int i = 0; i < s.size(); i += 1) {if (s[i] == 'y' || s[i] == 's') {pro.push_back(s.substr(lst, i - lst + 1));lst = i + 1;}}int m = pro[0].size(), f = 0;m -= 3;if (pro[0].back() == 's') {m -= 2;f = 1;}int edl = pro.size(), ok = 0;auto check = [&](int T, int Fa, string& d)->bool{string ans = "";vector<array<int, 3>> res;auto dfs = [&](auto & self, int idx, int t, int fa)->void{if (ok || t < 0 || fa < 0) {return;}if (idx >= pro.size()) {if (t == 0 && fa == 0) {cout << ans;int now = 0;for (auto &[x1, y1, st] : res) {if (st) {cout << x1 << " ";}cout << y1 << " " << (y1 > 1 ? "tries" : "try");now += 1;cout << " \n"[now == edl];}ok = 1;}return;}string nd = "";int len = pro[idx].size(), nf = 0;len -= 3;if (pro[idx].back() == 's') {len -= 2;nf = 1;}nd = pro[idx].substr(0, len);for (auto &[x, y] : mp[nd]) {if (((nf && y > 1) || (!nf && y == 1))) {res.push_back({x, y, 1});if (to_string(x) + to_string(y) == nd) {self(self, idx + 1, t - 1, fa - x - (y - 1) * 20);}else {res.back()[2] = 0;self(self, idx + 1, t, fa);}res.pop_back();}}};for (auto [x, y] : mp[d]) {if (((f && y > 1) || (!f && y == 1))) {array<int, 2> tar{T - 1, Fa - x - (y - 1) * 20};ans = to_string(T) + " " + to_string(Fa) + " ";res.push_back({x, y , 1});if (to_string(x) + to_string(y) == d) {dfs(dfs, 1, tar[0], tar[1]);}else {res.back()[2] = 0;tar = {T, Fa};dfs(dfs, 1, tar[0], tar[1]);}res.pop_back();if (ok) {return true;}}}return false;};m -= 1;for (int l = 1; l <= 6 && m >= 2; l += 1, m -= 1) {string d = pro[0].substr(m, l);string num = pro[0].substr(1, m - 1);if (num.size() > 7 || !mp.count(d)) {continue;}int T = pro[0][0] - '0';int Fa = stoi(num);if (check(T, Fa, d)) {return ;}if (pro[0][0] == '1' && pro[0][1] <= '3' && Fa > 10) {T = T * 10 + (pro[0][1] - '0');Fa = stoi(num.substr(1));if (check(T, Fa, d)) {return ;}}}}
signed main() {ios::sync_with_stdio(false);cin.tie(nullptr);for (int i = 1; i <= 299; i += 1) {string si = to_string(i);for (int j = 1; j <= 100; j += 1) {string sj = to_string(j);mp[si + sj].push_back({i, j});}}for (int i = 1; i <= 100; i += 1) {string si = to_string(i);mp[si].push_back({0, i});si = "0" + si;mp[si].push_back({0, i});}int t;cin >> t >> M;while (t--) {solve();}return 0;
}