震惊!咕噜咕噜最新模型CSP-S2025成绩,结果令人忍俊不禁
sen_lin114514 · · 休闲·娱乐
【提示】:此处只用于测试目的(且未提交至自测赛)。比赛中请勿使用 AI 辅助参赛。
模型为gemini-3-pro-preview使用roo code插件完成测试.
未开启联网功能.
提示词:
你正在参加一个大模型oi代码能力竞赛!
不按要求答题会使成绩作废
problem文件夹中有若干道题目,题目的文件名即为题目名
sample文件夹中是样例数据,你可以用它测试
警告:有些样例可能非常大,不要阅读他们,避免api花费过大,你可以使用文件输入输出进行测试
代码编写完成后,将他们放置到code文件夹(提交后不允许再次修改)
Code文件夹内容:
题目名字1.cpp
题目名字2.cpp
题目名字3.cpp
…
答题完成后,生成summary.md 生成一个表格,汇报如下信息:
题目名称 完成时间(提示词中会提供) 预期得分
Token 用量:↑ 1.8m ↓ 50.1k
API 费用: $5.21
| 题目名称 | 完成时间(UTC时间) | 预期得分(人机自己预测的) | 实际得分 |
|---|---|---|---|
| club | 2025-11-23 12:56 | 100 | 100 |
| 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]
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;
struct Person {
int id;
int a[3];
int best_dept;
int best_val;
};
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];
} else if (people[i].a[1] >= people[i].a[0] && people[i].a[1] >= people[i].a[2]) {
best = 1;
val = people[i].a[1];
} 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 alternative
int alt_val = -1;
for (int j = 0; j < 3; ++j) {
if (j == overloaded_dept) continue;
if (people[i].a[j] > alt_val) {
alt_val = people[i].a[j];
}
}
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() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
if (cin >> t) {
while (t--) {
solve();
}
}
return 0;
}
:::
road :::info[code]
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
// Problem P14362 [CSP-S 2025] 道路修复 / road
struct Edge {
int u, v;
long long w;
bool operator<(const Edge& other) const {
return w < other.w;
}
};
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) {
parent[root_i] = root_j;
components--;
return true;
}
return false;
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, k;
if (!(cin >> n >> m >> k)) return 0;
vector<Edge> orig_edges(m);
for (int i = 0; i < m; ++i) {
cin >> orig_edges[i].u >> orig_edges[i].v >> orig_edges[i].w;
}
// Precompute MST of original graph to reduce edges
sort(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 data
struct Town {
long long c;
vector<long long> a; // a[i] is cost to city i+1
};
vector<Town> towns(k);
for (int j = 0; j < k; ++j) {
cin >> towns[j].c;
towns[j].a.resize(n);
for (int i = 0; i < n; ++i) {
cin >> towns[j].a[i];
}
}
long long min_total_cost = -1;
// Iterate over all subsets of towns
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);
}
}
// Collect edges
// We use reduced_edges + edges from active towns
vector<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 + 1
int 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 safe
DSU 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() - 1
int 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?
// Wait, "can build roads ... between it and city i".
// If a town has edges to cities, it will be connected.
// 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;
}
}
}
cout << min_total_cost << endl;
return 0;
}
:::
replace :::info[code]
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <cstring>
using namespace std;
// Using a custom hash for pairs of strings
struct CoreHash {
unsigned long long h1, h2;
bool operator<(const CoreHash& other) const {
if (h1 != other.h1) return h1 < other.h1;
return h2 < other.h2;
}
bool operator==(const CoreHash& other) const {
return h1 == other.h1 && h2 == other.h2;
}
};
const int MAX_TOTAL_LEN = 5000005;
const int MAX_NODES = MAX_TOTAL_LEN + 400005; // Heuristic
const int TRIE_WIDTH = 26;
// Global Trie arrays to reuse memory
int chL[MAX_NODES][TRIE_WIDTH];
int chR[MAX_NODES][TRIE_WIDTH];
// We don't need 'end' markers, we map strings to nodes.
int nodes_cntL = 1;
int nodes_cntR = 1;
int inL[MAX_NODES], outL[MAX_NODES], timerL;
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 {
int l_idx, r_idx; // Indices into string_pool
int id; // Query ID or -1 for Rule
};
// Hashing Utils
unsigned long long BASE = 131;
// We compute hash on the fly, no need for rolling hash array for all strings.
CoreHash compute_hash(const string& s, const string& t) {
unsigned long long h1 = 0, h2 = 0;
for (char c : s) h1 = h1 * BASE + c;
for (char c : t) h2 = h2 * BASE + c;
return {h1, h2};
}
// Group data
map<CoreHash, vector<Item>> groups;
vector<long long> answers;
// Fenwick Tree
int bit[MAX_NODES];
int bit_n;
void update(int idx, int val) {
for (; idx <= bit_n; idx += idx & -idx)
bit[idx] += val;
}
int query(int idx) {
int sum = 0;
for (; idx > 0; idx -= idx & -idx)
sum += bit[idx];
return sum;
}
// Trie Insert
int insert(int root, const string& s, int ch[][TRIE_WIDTH], int& nodes_cnt) {
int u = root;
for (char c : s) {
int v = c - 'a';
if (!ch[u][v]) {
ch[u][v] = ++nodes_cnt;
// Clear new node
memset(ch[nodes_cnt], 0, sizeof(ch[nodes_cnt]));
}
u = ch[u][v];
}
return u;
}
// DFS for Euler Tour
void dfs(int u, int ch[][TRIE_WIDTH], int* in, int* out, int& timer) {
in[u] = ++timer;
for (int i = 0; i < TRIE_WIDTH; ++i) {
if (ch[u][i]) {
dfs(ch[u][i], ch, in, out, timer);
}
}
out[u] = timer;
}
struct Event {
int x, type; // x coordinate (L-Trie in time), type: 0=start rule, 1=query, 2=end rule
int 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
}
};
void solve_group(const vector<Item>& items) {
// 1. Separate Rules and Queries
vector<Item> rules, queries;
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 counters
nodes_cntL = 1;
nodes_cntR = 1;
memset(chL[1], 0, sizeof(chL[1]));
memset(chR[1], 0, sizeof(chR[1]));
// Nodes mapping
vector<pair<int, int>> rule_nodes(rules.size());
vector<pair<int, int>> query_nodes(queries.size());
// Helper to get reversed string
auto get_rev = [](const string& s) {
string r = s;
reverse(r.begin(), r.end());
return r;
};
// Insert Rules
for (size_t i = 0; i < rules.size(); ++i) {
// L-Trie: Reverse of L context
string revL = get_rev(string_pool[rules[i].l_idx]);
rule_nodes[i].first = insert(1, revL, chL, nodes_cntL);
// R-Trie: R context
rule_nodes[i].second = insert(1, string_pool[rules[i].r_idx], chR, nodes_cntR);
}
// Insert Queries
for (size_t i = 0; i < queries.size(); ++i) {
// L-Trie: Reverse of Query L
string revL = get_rev(string_pool[queries[i].l_idx]);
query_nodes[i].first = insert(1, revL, chL, nodes_cntL);
// R-Trie: Query R
query_nodes[i].second = insert(1, string_pool[queries[i].r_idx], chR, nodes_cntR);
}
// 3. DFS ranges
timerL = 0;
dfs(1, chL, inL, outL, timerL);
timerR = 0;
dfs(1, chR, inR, outR, timerR);
// 4. Sweep-line
vector<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());
// Process
bit_n = timerR;
// Reset BIT
for (int i = 0; i <= bit_n; ++i) bit[i] = 0;
for (const auto& ev : events) {
if (ev.type == 0) { // Start Rule
update(ev.y1, 1);
update(ev.y2 + 1, -1);
} else if (ev.type == 2) { // End Rule
update(ev.y1, -1);
update(ev.y2 + 1, 1);
} else { // Query
answers[ev.id] += query(ev.y1);
}
}
}
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 Rules
for (int i = 0; i < n; ++i) {
string s1, s2;
cin >> s1 >> s2;
if (s1 == s2) continue; // Useless rule
// Find core diff
int 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 parts
string coreA = s1.substr(u, v - u + 1);
string coreB = s2.substr(u, v - u + 1);
// Context parts
string ctxL = s1.substr(0, u);
string ctxR = s1.substr(v + 1);
// Store
int 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 Queries
for (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 diff
int 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 groups
for (const auto& kv : groups) {
solve_group(kv.second);
}
for (int j = 0; j < q; ++j) {
cout << answers[j] << "\n";
}
return 0;
}
:::
employ
:::info[code]
#include <iostream>
#include <vector>
#include <string>
using namespace std;
const int MOD = 998244353;
const int MAXN = 505;
int n, m;
string s;
int C_counts[MAXN]; // C_counts[v] = count of people with c = v
int C_gt[MAXN]; // C_gt[v] = count of people with c > v
long long fact[MAXN], invFact[MAXN];
long long dp[2][MAXN][MAXN]; // dp[curr/prev][j][k]
// j: current failures
// k: used people with c > j
long long power(long long base, long long exp) {
long long res = 1;
base %= MOD;
while (exp > 0) {
if (exp % 2 == 1) res = (res * base) % MOD;
base = (base * base) % MOD;
exp /= 2;
}
return res;
}
long long modInverse(long long n) {
return power(n, MOD - 2);
}
void init_comb() {
fact[0] = 1;
invFact[0] = 1;
for (int i = 1; i < MAXN; ++i) {
fact[i] = (fact[i - 1] * i) % MOD;
invFact[i] = modInverse(fact[i]);
}
}
long long nCr(int n, int r) {
if (r < 0 || r > n) return 0;
return fact[n] * invFact[r] % MOD * invFact[n - r] % MOD;
}
int main() {
ios_base::sync_with_stdio(false);
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;
C_counts[val]++;
}
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();
// Base case
// dp[0][0][0] = 1
// Using rolling array for i
for (int j = 0; j <= n; ++j) {
for (int k = 0; k <= n; ++k) {
dp[0][j][k] = 0;
}
}
dp[0][0][0] = 1;
for (int i = 0; i < n; ++i) {
int cur = i % 2;
int nxt = (i + 1) % 2;
// Reset next
for (int j = 0; j <= n; ++j) {
for (int k = 0; k <= n; ++k) {
dp[nxt][j][k] = 0;
}
}
int difficulty = s[i] - '0';
// Iterate over current states
// j can go up to i
// k can go up to i
// Optimization: j <= i, k <= C_gt[j] (bounded by i and total avail)
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 fragile
int rem_fragile = total_fragile - used_fragile;
// 1. Success Transition
// Requires s[i] == '1'
// Requires picking from Robust
if (difficulty == 1) {
if (rem_robust > 0) {
// k increases by 1
// j stays same
int next_k = k + 1;
// No splitting since j doesn't change
dp[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} group
int 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 limit
int next_total_robust = C_gt[j+1]; // = total_R_prev - D
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_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;
}
}
}
}
}
}
long long ans = 0;
int final_cur = n % 2;
// We need at least m people hired
// => At most n - m failures
// So j <= n - m
for (int j = 0; j <= n - m; ++j) {
for (int k = 0; k <= n; ++k) {
ans = (ans + dp[final_cur][j][k]) % MOD;
}
}
cout << ans << endl;
return 0;
}
:::