版本比较
震惊!咕噜咕噜最新模型CSP-S2025成绩,结果令人忍俊不禁
正文
增加 92 行删除 88 行
123425 行未改动303132333435363714 行未改动52535455565758596061626364656667686970713 行未改动757677787980818283848586878889909192939495969798991001015 行未改动10710810911011111211311411511611711811912012112232 行未改动15515615715815916016116216316416516616716816917017117217317417518 行未改动19419519619719819920020120220320420520620720820921013 行未改动2242252262272282292302312323 行未改动2362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802 行未改动28328428528628728828929029131 行未改动3233243253263273283293303317 行未改动33934034134234334434534634734861 行未改动4104114124134144154164174185 行未改动4244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085098 行未改动51851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760855 行未改动6646656666676686696706716723 行未改动67667767867968068168268368410 行未改动6956966976986997007017027039 行未改动7137147157167177187197207217227237247257267277287294 行未改动73473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880921 行未改动模型为`gemini-3-pro-preview`使用`roo code`插件完成测试.未开启联网功能.25 行未改动| road | 2025-11-23 13:09 | 100 | 80| replace | 2025-11-23 13:05 | 100 | 100| employ | 2025-11-23 13:03 | 100 | 100附答题代码:club:::info[code]14 行未改动void solve() {int n;if (!(cin >> n)) return;vector<Person> people(n);vector<int> count(3, 0);long long total_sat = 0;for (int i = 0; i < n; ++i) {people[i].id = i;cin >> people[i].a[0] >> people[i].a[1] >> people[i].a[2];int best = -1;int val = -1;// Find preferred department (0-indexed)if (people[i].a[0] >= people[i].a[1] && people[i].a[0] >= people[i].a[2]) {best = 0;val = people[i].a[0];3 行未改动} else {best = 2;val = people[i].a[2];}people[i].best_dept = best;people[i].best_val = val;count[best]++;total_sat += val;}int overloaded_dept = -1;for (int i = 0; i < 3; ++i) {if (count[i] > n / 2) {overloaded_dept = i;break;}}if (overloaded_dept != -1) {int remove_count = count[overloaded_dept] - n / 2;vector<int> losses;for (int i = 0; i < n; ++i) {if (people[i].best_dept == overloaded_dept) {// Find best alternativeint alt_val = -1;5 行未改动}losses.push_back(people[i].best_val - alt_val);}}sort(losses.begin(), losses.end());for (int i = 0; i < remove_count; ++i) {total_sat -= losses[i];}}cout << total_sat << endl;}int main() {32 行未改动struct DSU {vector<int> parent;int components;DSU(int n) {parent.resize(n + 1);iota(parent.begin(), parent.end(), 0);components = n;}int find(int i) {if (parent[i] == i)return i;return parent[i] = find(parent[i]);}bool unite(int i, int j) {int root_i = find(i);int root_j = find(j);if (root_i != root_j) {18 行未改动}// Precompute MST of original graph to reduce edgessort(orig_edges.begin(), orig_edges.end());vector<Edge> reduced_edges;DSU dsu_orig(n);for (const auto& e : orig_edges) {if (dsu_orig.unite(e.u, e.v)) {reduced_edges.push_back(e);}}// Read towns datastruct Town {long long c;vector<long long> a; // a[i] is cost to city i+113 行未改动int total_masks = 1 << k;for (int mask = 0; mask < total_masks; ++mask) {long long current_base_cost = 0;vector<int> active_towns;for (int j = 0; j < k; ++j) {if ((mask >> j) & 1) {current_base_cost += towns[j].c;active_towns.push_back(j);3 行未改动// Collect edges// We use reduced_edges + edges from active townsvector<Edge> current_edges;current_edges.reserve(reduced_edges.size() + active_towns.size() * n);for (const auto& e : reduced_edges) {current_edges.push_back(e);}for (int town_idx : active_towns) {// Town node index: n + 1 + town_idx (0-based inside town_idx, 1-based in graph n+1..n+k)int u = n + 1 + town_idx;for (int i = 0; i < n; ++i) {// City node index: i + 1int v = i + 1;current_edges.push_back({u, v, towns[town_idx].a[i]});}}sort(current_edges.begin(), current_edges.end());// Run Kruskal// Total nodes: n + k (we can just map active towns to their indices)// But for DSU size, we can use n + k + 1 to be safeDSU dsu(n + k);long long mst_cost = 0;int edges_count = 0;// We need to connect all n cities AND all active towns.// Total vertices in component: n + active_towns.size()// Expected edges: n + active_towns.size() - 1int target_edges = n + active_towns.size() - 1;for (const auto& e : current_edges) {if (dsu.unite(e.u, e.v)) {mst_cost += e.w;edges_count++;}}// Check if all cities are connected// We can check if edges_count == target_edges.// Assuming the graph of (cities + active towns) is connected.// The original cities are connected, and each town connects to all cities?2 行未改动// Is it possible a town is NOT connected?// Only if we didn't pick any edge for it.// But if we didn't pick any edge, edges_count < target_edges.// So checking edges_count is sufficient.if (edges_count == target_edges) {long long total = current_base_cost + mst_cost;if (min_total_cost == -1 || total < min_total_cost) {min_total_cost = total;31 行未改动return h1 == other.h1 && h2 == other.h2;}};const int MAX_TOTAL_LEN = 5000005;const int MAX_NODES = MAX_TOTAL_LEN + 400005; // Heuristicconst int TRIE_WIDTH = 26;// Global Trie arrays to reuse memory7 行未改动int inR[MAX_NODES], outR[MAX_NODES], timerR;// String storage references// Store strings as (string*) and (start, len) to avoid copies?// Or just store string objects if N is small?// N is 2e5, total length large.// We can use vector<string> global buffer.vector<string> string_pool;struct Item {61 行未改动struct Event {int x, type; // x coordinate (L-Trie in time), type: 0=start rule, 1=query, 2=end ruleint y1, y2; // range or point on R-axis. For query y1=y2. For rule [y1, y2].int id; // for rules: dummy. for queries: query index.bool operator<(const Event& other) const {if (x != other.x) return x < other.x;return type < other.type; // Process start, then query, then end}5 行未改动for (const auto& item : items) {if (item.id == -1) rules.push_back(item);else queries.push_back(item);}if (queries.empty()) return;if (rules.empty()) return; // Answers remain 0// 2. Build Tries// Reset global countersnodes_cntL = 1;nodes_cntR = 1;memset(chL[1], 0, sizeof(chL[1]));memset(chR[1], 0, sizeof(chR[1]));// Nodes mappingvector<pair<int, int>> rule_nodes(rules.size());vector<pair<int, int>> query_nodes(queries.size());// Helper to get reversed stringauto get_rev = [](const string& s) {string r = s;reverse(r.begin(), r.end());return r;};// Insert Rulesfor (size_t i = 0; i < rules.size(); ++i) {// L-Trie: Reverse of L contextstring revL = get_rev(string_pool[rules[i].l_idx]);rule_nodes[i].first = insert(1, revL, chL, nodes_cntL);// R-Trie: R contextrule_nodes[i].second = insert(1, string_pool[rules[i].r_idx], chR, nodes_cntR);}// Insert Queriesfor (size_t i = 0; i < queries.size(); ++i) {// L-Trie: Reverse of Query Lstring revL = get_rev(string_pool[queries[i].l_idx]);query_nodes[i].first = insert(1, revL, chL, nodes_cntL);// R-Trie: Query Rquery_nodes[i].second = insert(1, string_pool[queries[i].r_idx], chR, nodes_cntR);}// 3. DFS rangestimerL = 0;dfs(1, chL, inL, outL, timerL);timerR = 0;dfs(1, chR, inR, outR, timerR);// 4. Sweep-linevector<Event> events;events.reserve(rules.size() * 2 + queries.size());// Rule events: Rectangle [inL, outL] x [inR, outR]for (size_t i = 0; i < rules.size(); ++i) {int u = rule_nodes[i].first;int v = rule_nodes[i].second;// Start of rectangle at inL[u]events.push_back({inL[u], 0, inR[v], outR[v], -1});// End of rectangle at outL[u]events.push_back({outL[u], 2, inR[v], outR[v], -1});}// Query events: Point (inL[u], inR[v])for (size_t i = 0; i < queries.size(); ++i) {int u = query_nodes[i].first;int v = query_nodes[i].second;events.push_back({inL[u], 1, inR[v], inR[v], queries[i].id});}sort(events.begin(), events.end());// Processbit_n = timerR;// Reset BITfor (int i = 0; i <= bit_n; ++i) bit[i] = 0;for (const auto& ev : events) {if (ev.type == 0) { // Start Ruleupdate(ev.y1, 1);update(ev.y2 + 1, -1);8 行未改动int main() {ios_base::sync_with_stdio(false);cin.tie(NULL);int n, q;if (!(cin >> n >> q)) return 0;answers.resize(q, 0);string_pool.reserve(2 * (n + q));// Read Rulesfor (int i = 0; i < n; ++i) {string s1, s2;cin >> s1 >> s2;if (s1 == s2) continue; // Useless rule// Find core diffint u = 0;while (u < s1.length() && s1[u] == s2[u]) u++;int v = s1.length() - 1;while (v >= 0 && s1[v] == s2[v]) v--;// Core partsstring coreA = s1.substr(u, v - u + 1);string coreB = s2.substr(u, v - u + 1);// Context partsstring ctxL = s1.substr(0, u);string ctxR = s1.substr(v + 1);// Storeint idxL = string_pool.size();string_pool.push_back(ctxL);int idxR = string_pool.size();string_pool.push_back(ctxR);CoreHash h = compute_hash(coreA, coreB);groups[h].push_back({idxL, idxR, -1});}// Read Queriesfor (int j = 0; j < q; ++j) {string t1, t2;cin >> t1 >> t2;if (t1.length() != t2.length()) {answers[j] = 0;continue;}if (t1 == t2) {// Problem statement says t1 != t2, so we assume 0 or handle it// "different strings t_{j,1}, t_{j,2}"answers[j] = 0;continue;}// Find core diffint u = 0;while (u < t1.length() && t1[u] == t2[u]) u++;int v = t1.length() - 1;while (v >= 0 && t1[v] == t2[v]) v--;string coreS = t1.substr(u, v - u + 1);string coreT = t2.substr(u, v - u + 1);string ctxL = t1.substr(0, u);string ctxR = t1.substr(v + 1);int idxL = string_pool.size();string_pool.push_back(ctxL);int idxR = string_pool.size();string_pool.push_back(ctxR);CoreHash h = compute_hash(coreS, coreT);groups[h].push_back({idxL, idxR, j});}// Process groupsfor (const auto& kv : groups) {solve_group(kv.second);}for (int j = 0; j < q; ++j) {cout << answers[j] << "\n";}return 0;}```:::55 行未改动cin.tie(NULL);if (!(cin >> n >> m)) return 0;cin >> s;for (int i = 0; i < n; ++i) {int val;cin >> val;if (val > n) val = n;3 行未改动for (int i = n; i >= 0; --i) {if (i == n) C_gt[i] = 0;else C_gt[i] = C_gt[i+1] + C_counts[i+1];}// C_gt[j] is the count of people with c > j.// Specifically, sum(C_counts[x] for x = j+1 to n).init_comb();10 行未改动for (int i = 0; i < n; ++i) {int cur = i % 2;int nxt = (i + 1) % 2;// Reset nextfor (int j = 0; j <= n; ++j) {for (int k = 0; k <= n; ++k) {dp[nxt][j][k] = 0;9 行未改动for (int j = 0; j <= i; ++j) {int max_k = min(i, C_gt[j]);for (int k = 0; k <= max_k; ++k) {if (dp[cur][j][k] == 0) continue;long long ways = dp[cur][j][k];int total_robust = C_gt[j];int rem_robust = total_robust - k;int total_fragile = n - total_robust;int used_fragile = i - k; // Total used i, k are robust, rest fragileint rem_fragile = total_fragile - used_fragile;// 1. Success Transition// Requires s[i] == '1'// Requires picking from Robustif (difficulty == 1) {4 行未改动// No splitting since j doesn't changedp[nxt][j][next_k] = (dp[nxt][j][next_k] + ways * rem_robust) % MOD;}}// 2. Failure Transition// Always increases j -> j+1// Can we pick?// Option A: Pick from Robust// Possible if difficulty == 0 (unconstrained)if (difficulty == 0) {if (rem_robust > 0) {int k_temp = k + 1;// Now transition j -> j+1// Robust set shrinks by removing {c = j+1} groupint D = C_counts[j+1];int total_R_prev = total_robust; // C_gt[j]int rem_R_prev = rem_robust; // at start of step// We used k_temp from total_R_prev.// We need to split k_temp into x (from D) and k_new (from rest)// x ranges from max(0, k_temp - (total_R_prev - D)) to min(k_temp, D)// Actually, simplified bounds: 0 to D, check validity// Optimization: Precompute limitint next_total_robust = C_gt[j+1]; // = total_R_prev - Dlong long denom = nCr(total_R_prev, k_temp);long long invDenom = modInverse(denom);for (int x = 0; x <= D; ++x) {if (x > k_temp) break;if (D - x > total_R_prev - k_temp) continue;long long num = (nCr(D, x) * nCr(total_R_prev - D, k_temp - x)) % MOD;long long prob = (num * invDenom) % MOD;int k_new = k_temp - x;long long added = (ways * rem_robust) % MOD;added = (added * prob) % MOD;dp[nxt][j+1][k_new] = (dp[nxt][j+1][k_new] + added) % MOD;}}}// Option B: Pick from Fragile{if (rem_fragile > 0) {int k_temp = k;int D = C_counts[j+1];int total_R_prev = total_robust;long long denom = nCr(total_R_prev, k_temp);long long invDenom = modInverse(denom);for (int x = 0; x <= D; ++x) {if (x > k_temp) break;if (D - x > total_R_prev - k_temp) continue;long long num = (nCr(D, x) * nCr(total_R_prev - D, k_temp - x)) % MOD;long long prob = (num * invDenom) % MOD;int k_new = k_temp - x;long long added = (ways * rem_fragile) % MOD;added = (added * prob) % MOD;dp[nxt][j+1][k_new] = (dp[nxt][j+1][k_new] + added) % MOD;}}}21 行未改动12345625 行未改动3233343536373839404114 行未改动56575859606162636465666768697071727374753 行未改动7980818283848586878889909192939495969798991001011021031041055 行未改动11111211311411511611711811912012112212312412512632 行未改动15916016116216316416516616716816917017117217317417517617717817918 行未改动19819920020120220320420520620720820921021121221321413 行未改动2282292302312322332342352363 行未改动2402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842 行未改动28728828929029129229329429531 行未改动3273283293303313323333343357 行未改动34334434534634734834935035135261 行未改动4144154164174184194204214225 行未改动4284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125138 行未改动52252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161255 行未改动6686696706716726736746756763 行未改动68068168268368468568668768810 行未改动6997007017027037047057067079 行未改动7177187197207217227237247257267277287297307317327334 行未改动73873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281321 行未改动【提示】:此处只用于测试目的(且未提交至自测赛)。比赛中请勿使用 AI 辅助参赛。模型为`gemini-3-pro-preview`使用`roo code`插件完成测试.未开启联网功能.25 行未改动| road | 2025-11-23 13:09 | 100 | 80| replace | 2025-11-23 13:05 | 100 | 100| employ | 2025-11-23 13:03 | 100 | 100按这个水平可以进省队,全国大概是150名左右(附答题代码:club:::info[code]14 行未改动void solve() {int n;if (!(cin >> n)) return;vector<Person> people(n);vector<int> count(3, 0);long long total_sat = 0;for (int i = 0; i < n; ++i) {people[i].id = i;cin >> people[i].a[0] >> people[i].a[1] >> people[i].a[2];int best = -1;int val = -1;// Find preferred department (0-indexed)if (people[i].a[0] >= people[i].a[1] && people[i].a[0] >= people[i].a[2]) {best = 0;val = people[i].a[0];3 行未改动} else {best = 2;val = people[i].a[2];}people[i].best_dept = best;people[i].best_val = val;count[best]++;total_sat += val;}int overloaded_dept = -1;for (int i = 0; i < 3; ++i) {if (count[i] > n / 2) {overloaded_dept = i;break;}}if (overloaded_dept != -1) {int remove_count = count[overloaded_dept] - n / 2;vector<int> losses;for (int i = 0; i < n; ++i) {if (people[i].best_dept == overloaded_dept) {// Find best alternativeint alt_val = -1;5 行未改动}losses.push_back(people[i].best_val - alt_val);}}sort(losses.begin(), losses.end());for (int i = 0; i < remove_count; ++i) {total_sat -= losses[i];}}cout << total_sat << endl;}int main() {32 行未改动struct DSU {vector<int> parent;int components;DSU(int n) {parent.resize(n + 1);iota(parent.begin(), parent.end(), 0);components = n;}int find(int i) {if (parent[i] == i)return i;return parent[i] = find(parent[i]);}bool unite(int i, int j) {int root_i = find(i);int root_j = find(j);if (root_i != root_j) {18 行未改动}// Precompute MST of original graph to reduce edgessort(orig_edges.begin(), orig_edges.end());vector<Edge> reduced_edges;DSU dsu_orig(n);for (const auto& e : orig_edges) {if (dsu_orig.unite(e.u, e.v)) {reduced_edges.push_back(e);}}// Read towns datastruct Town {long long c;vector<long long> a; // a[i] is cost to city i+113 行未改动int total_masks = 1 << k;for (int mask = 0; mask < total_masks; ++mask) {long long current_base_cost = 0;vector<int> active_towns;for (int j = 0; j < k; ++j) {if ((mask >> j) & 1) {current_base_cost += towns[j].c;active_towns.push_back(j);3 行未改动// Collect edges// We use reduced_edges + edges from active townsvector<Edge> current_edges;current_edges.reserve(reduced_edges.size() + active_towns.size() * n);for (const auto& e : reduced_edges) {current_edges.push_back(e);}for (int town_idx : active_towns) {// Town node index: n + 1 + town_idx (0-based inside town_idx, 1-based in graph n+1..n+k)int u = n + 1 + town_idx;for (int i = 0; i < n; ++i) {// City node index: i + 1int v = i + 1;current_edges.push_back({u, v, towns[town_idx].a[i]});}}sort(current_edges.begin(), current_edges.end());// Run Kruskal// Total nodes: n + k (we can just map active towns to their indices)// But for DSU size, we can use n + k + 1 to be safeDSU dsu(n + k);long long mst_cost = 0;int edges_count = 0;// We need to connect all n cities AND all active towns.// Total vertices in component: n + active_towns.size()// Expected edges: n + active_towns.size() - 1int target_edges = n + active_towns.size() - 1;for (const auto& e : current_edges) {if (dsu.unite(e.u, e.v)) {mst_cost += e.w;edges_count++;}}// Check if all cities are connected// We can check if edges_count == target_edges.// Assuming the graph of (cities + active towns) is connected.// The original cities are connected, and each town connects to all cities?2 行未改动// Is it possible a town is NOT connected?// Only if we didn't pick any edge for it.// But if we didn't pick any edge, edges_count < target_edges.// So checking edges_count is sufficient.if (edges_count == target_edges) {long long total = current_base_cost + mst_cost;if (min_total_cost == -1 || total < min_total_cost) {min_total_cost = total;31 行未改动return h1 == other.h1 && h2 == other.h2;}};const int MAX_TOTAL_LEN = 5000005;const int MAX_NODES = MAX_TOTAL_LEN + 400005; // Heuristicconst int TRIE_WIDTH = 26;// Global Trie arrays to reuse memory7 行未改动int inR[MAX_NODES], outR[MAX_NODES], timerR;// String storage references// Store strings as (string*) and (start, len) to avoid copies?// Or just store string objects if N is small?// N is 2e5, total length large.// We can use vector<string> global buffer.vector<string> string_pool;struct Item {61 行未改动struct Event {int x, type; // x coordinate (L-Trie in time), type: 0=start rule, 1=query, 2=end ruleint y1, y2; // range or point on R-axis. For query y1=y2. For rule [y1, y2].int id; // for rules: dummy. for queries: query index.bool operator<(const Event& other) const {if (x != other.x) return x < other.x;return type < other.type; // Process start, then query, then end}5 行未改动for (const auto& item : items) {if (item.id == -1) rules.push_back(item);else queries.push_back(item);}if (queries.empty()) return;if (rules.empty()) return; // Answers remain 0// 2. Build Tries// Reset global countersnodes_cntL = 1;nodes_cntR = 1;memset(chL[1], 0, sizeof(chL[1]));memset(chR[1], 0, sizeof(chR[1]));// Nodes mappingvector<pair<int, int>> rule_nodes(rules.size());vector<pair<int, int>> query_nodes(queries.size());// Helper to get reversed stringauto get_rev = [](const string& s) {string r = s;reverse(r.begin(), r.end());return r;};// Insert Rulesfor (size_t i = 0; i < rules.size(); ++i) {// L-Trie: Reverse of L contextstring revL = get_rev(string_pool[rules[i].l_idx]);rule_nodes[i].first = insert(1, revL, chL, nodes_cntL);// R-Trie: R contextrule_nodes[i].second = insert(1, string_pool[rules[i].r_idx], chR, nodes_cntR);}// Insert Queriesfor (size_t i = 0; i < queries.size(); ++i) {// L-Trie: Reverse of Query Lstring revL = get_rev(string_pool[queries[i].l_idx]);query_nodes[i].first = insert(1, revL, chL, nodes_cntL);// R-Trie: Query Rquery_nodes[i].second = insert(1, string_pool[queries[i].r_idx], chR, nodes_cntR);}// 3. DFS rangestimerL = 0;dfs(1, chL, inL, outL, timerL);timerR = 0;dfs(1, chR, inR, outR, timerR);// 4. Sweep-linevector<Event> events;events.reserve(rules.size() * 2 + queries.size());// Rule events: Rectangle [inL, outL] x [inR, outR]for (size_t i = 0; i < rules.size(); ++i) {int u = rule_nodes[i].first;int v = rule_nodes[i].second;// Start of rectangle at inL[u]events.push_back({inL[u], 0, inR[v], outR[v], -1});// End of rectangle at outL[u]events.push_back({outL[u], 2, inR[v], outR[v], -1});}// Query events: Point (inL[u], inR[v])for (size_t i = 0; i < queries.size(); ++i) {int u = query_nodes[i].first;int v = query_nodes[i].second;events.push_back({inL[u], 1, inR[v], inR[v], queries[i].id});}sort(events.begin(), events.end());// Processbit_n = timerR;// Reset BITfor (int i = 0; i <= bit_n; ++i) bit[i] = 0;for (const auto& ev : events) {if (ev.type == 0) { // Start Ruleupdate(ev.y1, 1);update(ev.y2 + 1, -1);8 行未改动int main() {ios_base::sync_with_stdio(false);cin.tie(NULL);int n, q;if (!(cin >> n >> q)) return 0;answers.resize(q, 0);string_pool.reserve(2 * (n + q));// Read Rulesfor (int i = 0; i < n; ++i) {string s1, s2;cin >> s1 >> s2;if (s1 == s2) continue; // Useless rule// Find core diffint u = 0;while (u < s1.length() && s1[u] == s2[u]) u++;int v = s1.length() - 1;while (v >= 0 && s1[v] == s2[v]) v--;// Core partsstring coreA = s1.substr(u, v - u + 1);string coreB = s2.substr(u, v - u + 1);// Context partsstring ctxL = s1.substr(0, u);string ctxR = s1.substr(v + 1);// Storeint idxL = string_pool.size();string_pool.push_back(ctxL);int idxR = string_pool.size();string_pool.push_back(ctxR);CoreHash h = compute_hash(coreA, coreB);groups[h].push_back({idxL, idxR, -1});}// Read Queriesfor (int j = 0; j < q; ++j) {string t1, t2;cin >> t1 >> t2;if (t1.length() != t2.length()) {answers[j] = 0;continue;}if (t1 == t2) {// Problem statement says t1 != t2, so we assume 0 or handle it// "different strings t_{j,1}, t_{j,2}"answers[j] = 0;continue;}// Find core diffint u = 0;while (u < t1.length() && t1[u] == t2[u]) u++;int v = t1.length() - 1;while (v >= 0 && t1[v] == t2[v]) v--;string coreS = t1.substr(u, v - u + 1);string coreT = t2.substr(u, v - u + 1);string ctxL = t1.substr(0, u);string ctxR = t1.substr(v + 1);int idxL = string_pool.size();string_pool.push_back(ctxL);int idxR = string_pool.size();string_pool.push_back(ctxR);CoreHash h = compute_hash(coreS, coreT);groups[h].push_back({idxL, idxR, j});}// Process groupsfor (const auto& kv : groups) {solve_group(kv.second);}for (int j = 0; j < q; ++j) {cout << answers[j] << "\n";}return 0;}```:::55 行未改动cin.tie(NULL);if (!(cin >> n >> m)) return 0;cin >> s;for (int i = 0; i < n; ++i) {int val;cin >> val;if (val > n) val = n;3 行未改动for (int i = n; i >= 0; --i) {if (i == n) C_gt[i] = 0;else C_gt[i] = C_gt[i+1] + C_counts[i+1];}// C_gt[j] is the count of people with c > j.// Specifically, sum(C_counts[x] for x = j+1 to n).init_comb();10 行未改动for (int i = 0; i < n; ++i) {int cur = i % 2;int nxt = (i + 1) % 2;// Reset nextfor (int j = 0; j <= n; ++j) {for (int k = 0; k <= n; ++k) {dp[nxt][j][k] = 0;9 行未改动for (int j = 0; j <= i; ++j) {int max_k = min(i, C_gt[j]);for (int k = 0; k <= max_k; ++k) {if (dp[cur][j][k] == 0) continue;long long ways = dp[cur][j][k];int total_robust = C_gt[j];int rem_robust = total_robust - k;int total_fragile = n - total_robust;int used_fragile = i - k; // Total used i, k are robust, rest fragileint rem_fragile = total_fragile - used_fragile;// 1. Success Transition// Requires s[i] == '1'// Requires picking from Robustif (difficulty == 1) {4 行未改动// No splitting since j doesn't changedp[nxt][j][next_k] = (dp[nxt][j][next_k] + ways * rem_robust) % MOD;}}// 2. Failure Transition// Always increases j -> j+1// Can we pick?// Option A: Pick from Robust// Possible if difficulty == 0 (unconstrained)if (difficulty == 0) {if (rem_robust > 0) {int k_temp = k + 1;// Now transition j -> j+1// Robust set shrinks by removing {c = j+1} groupint D = C_counts[j+1];int total_R_prev = total_robust; // C_gt[j]int rem_R_prev = rem_robust; // at start of step// We used k_temp from total_R_prev.// We need to split k_temp into x (from D) and k_new (from rest)// x ranges from max(0, k_temp - (total_R_prev - D)) to min(k_temp, D)// Actually, simplified bounds: 0 to D, check validity// Optimization: Precompute limitint next_total_robust = C_gt[j+1]; // = total_R_prev - Dlong long denom = nCr(total_R_prev, k_temp);long long invDenom = modInverse(denom);for (int x = 0; x <= D; ++x) {if (x > k_temp) break;if (D - x > total_R_prev - k_temp) continue;long long num = (nCr(D, x) * nCr(total_R_prev - D, k_temp - x)) % MOD;long long prob = (num * invDenom) % MOD;int k_new = k_temp - x;long long added = (ways * rem_robust) % MOD;added = (added * prob) % MOD;dp[nxt][j+1][k_new] = (dp[nxt][j+1][k_new] + added) % MOD;}}}// Option B: Pick from Fragile{if (rem_fragile > 0) {int k_temp = k;int D = C_counts[j+1];int total_R_prev = total_robust;long long denom = nCr(total_R_prev, k_temp);long long invDenom = modInverse(denom);for (int x = 0; x <= D; ++x) {if (x > k_temp) break;if (D - x > total_R_prev - k_temp) continue;long long num = (nCr(D, x) * nCr(total_R_prev - D, k_temp - x)) % MOD;long long prob = (num * invDenom) % MOD;int k_new = k_temp - x;long long added = (ways * rem_fragile) % MOD;added = (added * prob) % MOD;dp[nxt][j+1][k_new] = (dp[nxt][j+1][k_new] + added) % MOD;}}}21 行未改动