题解:GTOJ 2026 年 9、10 月入门组月赛 部分出题报告(修订版)
Wyh_dailyAC · · 题解
前言
下述题目命题人均为洛谷 Wyh_dailyAC。
下述题目均契合入门组对位难度。
“Ynoi”一题于 2026 年 7 月 30 日命制,“某科学的构造”一题于 2026 年 8 月 14 日命制,“GTA V”一题于 2026 年 8 月 12 日命制,“树梢的风铃”一题于 2026 年 8 月 16 日命制。
下述四题均为原创题目,且下述四题在命制、赛前、赛后三阶段均经过了 CPRet(cpret.online)、原题机(yuantiji.ac)、GPT(chatgpt.com)三平台的查重处理,每次查询均未发现原题。
感谢镰池和马撰写了《魔法禁书目录》及其一系列外传作品,使得出题人精神状态回满,进而使得 T2 有更多可供使用的素材;感谢段科亦在朋友圈发布的推理游戏,这个推理游戏直接奠定了 T3 的逻辑基础;感谢 albertting、Na1L0n9 在赛前对 T3 T4 进行的无偿非公开试做。
出题人 Wyh_dailyAC 自愿无偿捐题给 GTOJ,即未收取任何报酬。
题解
期望 T1 - Ynoi
预估难度:红题。
输入年份
#include <bits/stdc++.h>
using namespace std;
auto main() -> signed {
int q; cin >> q;
while (q--) {
int x; cin >> x;
if (x < 2000 || x > 2026) cout << "Yes\n";
else cout << "No\n";
}
}
期望 T2 - 某科学的构造
预估难度:橙题。
这里说一下如何构造矩阵。
方法就是把数字按
然后,从头开始,每
显然,只含
当然,有且最多有一段数是跨越
至于奇在上偶在下,在跨越
可以根据构造出来的矩阵输出
时间复杂度
#include <bits/stdc++.h>
#define sfr return cerr << "safe\n", 0;
#define sf_void return cerr << "safe\n", void();
using namespace std;
using ll = long long;
using i128 = __int128;
using pr = pair<int, int>;
using prt = tuple<int, int>;
using tpt = tuple<int, int, int>;
int /* t[5010][5010] */ r[5010], c[5010];
auto main() -> signed {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int n, m; cin >> n >> m;
vector<pr> qr(n * m + 5);
vector<char> bh(n * m + 5); vector<int> cnt(4);
// qr.emplace_back(-1, -1);
// int cur3 = 1, cur1 = cnt[3] + 1, cur2 = cnt[3] + cnt[1] + 1, cir0 = cnt[3] + cnt[1] + cnt[2] + 1;
for (int i = 1, x; i <= n * m; ++i) {
cin >> x;
bh[i] = x;
cnt[x]++;
// if (x == 0) qr0.emplace_back(x, i);
// if (x == 1) qr1.emplace_back(x, i);
// if (x == 2) qr2.emplace_back(x, i);
// if (x == 3) qr3.emplace_back(x, i);
}
vector<int> cur = {cnt[3] + cnt[1] + cnt[2] + 1, cnt[3] + 1, cnt[3] + cnt[1] + 1, 1};
for (int i = 1; i <= n * m; ++i) {
qr[cur[(int) bh[i]]++] = {(int) bh[i], i}; // ++cur[bh[i]];
}
// for (auto &x : qr3) qr.emplace_back(x); // qr3.pop_back();
// for (auto &x : qr1) qr.emplace_back(x); // qr1.pop_back();
// for (auto &x : qr2) qr.emplace_back(x); // qr2.pop_back();
// for (auto &x : qr0) qr.emplace_back(x); // qr0.pop_back();
for (int i = 1; i <= n * m; i += m) {
if (cur[1] <= i + m - 1 && cur[1] >= i) {
sort(qr.begin() + i, qr.begin() + i + m, greater<pr>());
// break;
}
// for (int j = i; j < i + m; ++j) ans[qr[j].second] = {(i + m - 1) / m, j - i + 1};
// int x = ans[i].first, y = ans[i].second;
for (int j = i; j < i + m; ++j) {
if (bh[qr[j].second] > 1) r[(i + m - 1) / m]++;
if (bh[qr[j].second] & 1) c[j - i + 1]++;
}
}
for (int i = 1; i <= n; ++i) cout << r[i] << " \n"[i == n];
for (int j = 1; j <= m; ++j) cout << c[j] << " \n"[j == m];
}
期望 T3 - GTA V
预估难度:中上黄(原版将本题定为中下黄,修订时觉得不妥,遂修改为中上黄的预计;部分考生认为这是青,这里不予评析,可以视为个人差问题)。
分类讨论:
-
不存在
XXX is a liar.类型的口供。此时只有指认凶手和自证无辜的情况。
如果肯定一个人
x 为凶手,则指认x 的人说辞正确(记指认x 的人数是c_x ),除x 外自证无辜的人说辞正确(记I_x=1 表示x 自认无辜,记I' 表示自证无辜的总人数)。凶案中只有一个人说真话,所以需要满足
c_x+I'-I_x=1 。把满足此条件的凶手待选线性找出来,并简单分讨追认唯一的真话者。题目显然要求一真话者对唯一凶手,所以每找到一个待选就对待选的唯一真话者打
1 的 Tag。如果 Tag 大小>1 ,则这些凶手待选就全体不成立了;反之,成立,按要求输出。 -
存在
XXX is a liar.类型的口供。考虑唯一的真话者
h 。对于一句i: x is a liar.,若i=h ,则x 必须说假话;若i\ne h ,则这句话为假,反而说明x=h 。因此必有h\in\{i,x\} 。所以取第一句此类口供后,真话者只可能是其中涉及的两个人;之后每遇到一句,就与新的
\{i,x\} 取交。最终至多留下两个真话者候选,分别按前面(无 liar)的方式检查对应凶手是否合法即可。
复杂度线性。代码有点长。
#include <bits/stdc++.h>
#define sfr return cerr << "safe\n", 0;
#define sf_void return cerr << "safe\n", void();
using namespace std;
using ll = long long;
using i128 = __int128;
using pr = pair<int, int>;
using prt = tuple<int, int>;
using tpt = tuple<int, int, int>;
int T, t; string s;
auto main() -> signed {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
cin >> T;
queue<pr> st;
// st.reserve((int) 1e7 + 10);
for (int _ = 1; _ <= T; ++_) {
int n; cin >> n;
vector<int> md(n + 5), lst(n + 5), say(n + 5);
int flag = 0, H1 = -1, H2 = -1, I = 0, I1 = -1, I2 = -1;
for (int i = 1; i <= n; ++i) {
cin >> s;
if (s[0] != 'I') {
t = stoi(s);
cin >> s; cin >> s;
if (s == "a") {
flag++;
say[i] = -t;
if (flag == 1) {
H1 = i, H2 = t;
} else {
if (H1 != -1 && H1 != i && H1 != t) H1 = -1;
if (H2 != -1 && H2 != i && H2 != t) H2 = -1;
}
} else {
say[i] = t;
md[t]++, lst[t] = i;
}
cin >> s;
} else {
++I;
if (I == 1) I1 = i;
if (I == 2) I2 = i;
cin >> s; cin >> s;
}
}
if (flag > 0) {
int zc = 0, z1 = -1, z2 = -1;
for (int i = 1; i <= n; ++i) {
if (!md[i]) {
++zc;
if (z1 == -1) z1 = i;
else if (z2 == -1) z2 = i;
}
}
auto chk = [&](int h) -> int {
if (h == -1) return -1;
int p = -1, othI = I - (say[h] == 0);
if (othI > 1) return -1;
if (say[h] > 0) p = say[h];
if (othI == 1) {
int x;
if (say[h] == 0) x = (I1 == h ? I2 : I1);
else x = I1;
if (p != -1 && p != x) return -1;
p = x;
}
if (p != -1) {
if (say[h] == 0 && p == h) return -1;
int ned = (say[h] > 0 && say[h] == p);
if (md[p] != ned) return -1;
return p;
}
if (say[h] == 0) {
int c = zc - (!md[h]);
if (c != 1) return -1;
if (z1 == h) return z2;
return z1;
}
if (zc != 1) return -1;
return z1;
};
int p1 = chk(H1), p2 = chk(H2);
cout << "Case " << _ << ":\n";
if (p1 == -1 && p2 == -1) {
cout << "-1\n";
} else if (p1 == -1) {
cout << p2 << "\n";
} else if (p2 == -1 || p1 == p2) {
cout << p1 << "\n";
} else {
if (p1 > p2) swap(p1, p2);
cout << p1 << " " << p2 << "\n";
}
} else {
if (I > 2) {
cout << "Case " << _ << ":\n" << "-1\n";
continue;
}
vector<int> cnt(n + 5);
for (int i = 1; i <= n; ++i) {
if ((md[i] == 1) && (I == (I1 == i || I2 == i))) st.emplace(i, lst[i]), cnt[lst[i]]++;
if ((md[i] == 0) && (I - (I1 == i || I2 == i) == 1)) st.emplace(i, (I1 == i ? I2 : I1)), cnt[(I1 == i ? I2 : I1)]++;
}
cout << "Case " << _ << ":\n";
int cntt = 0;
while (!st.empty()) {
auto [x, fx] = st.front(); st.pop();
if (cnt[fx] > 1) continue;
cout << x << " ";
cntt++;
}
if (!cntt) cout << "-1";
cout << "\n";
}
}
}
期望 T4 - 树梢的风铃
预估难度:中上黄(本题的难点在于代码量)。
一眼看上去,像是会超纲的树形 DP,不过树的形态决定了这题是入门组。
本题的树可以看作是若干个小树的根串在一条链上,且小树除了根就是叶子(可以看作菊花),不难想到对每个挂着的小树先行处理。
每个点可以钦定三个状态:
对一个小树,如果其根钦定为
小树内,根钦定为
显然,一条边两边不能同时是
对链
至于构造排列,可以给钦定为
于是本题结束了,时间复杂度
代码比较长,也涉及一些分讨。
#include <bits/stdc++.h>
#define sfr return cerr << "safe\n", 0;
#define sf_void return cerr << "safe\n", void();
using namespace std;
using ll = long long;
using i128 = __int128;
using pr = pair<int, int>;
using prt = tuple<int, int>;
using tpt = tuple<int, int, int>;
const int N = 2e5 + 10;
int n, a[N], b[N], ind[N], pre[3][N], st[N], p[N];
ll mx[N], mi[N], nn[N], f[3][N]; // 0 - none | 1 - max | 2 - min
vector<int> E[N];
auto main() -> signed {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i <= n; ++i) {
cin >> b[i];
}
for (int i = 1, u, v; i < n; ++i) {
cin >> u >> v;
++ind[u], ++ind[v];
E[u].emplace_back(v), E[v].emplace_back(u);
}
if (n == 2) {
if ((ll) a[1] + b[2] >= (ll) b[1] + a[2]) {
cout << (ll) a[1] + b[2] << "\n";
cout << 2 << " " << 1 << "\n";
} else {
cout << (ll) b[1] + a[2] << "\n";
cout << 1 << " " << 2 << "\n";
}
return 0;
}
for (int i = 1; i <= n; ++i) {
if (ind[i] == 1) {
mx[E[i][0]] += b[i];
mi[E[i][0]] += a[i];
nn[E[i][0]] += max(a[i], b[i]);
}
}
int S = 0;
for (int i = 1; i <= n; ++i) {
if (ind[i] > 1) {
int cnt = 0;
for (auto &v : E[i]) {
cnt += ind[v] > 1;
}
if (cnt <= 1) {
S = i;
break;
}
}
}
vector<int> nd;
int lst = 0;
while (S) {
nd.emplace_back(S);
int nxt = 0;
for (auto &v : E[S]) {
if (ind[v] > 1 && v != lst) {
nxt = v;
break;
}
}
lst = S, S = nxt;
}
int m = nd.size();
for (int i = 1; i <= m; ++i) {
int u = nd[i - 1];
mx[u] += a[u];
mi[u] += b[u];
if (i == 1) {
f[0][i] = nn[u];
f[1][i] = mx[u];
f[2][i] = mi[u];
continue;
}
if (f[0][i - 1] >= f[1][i - 1] && f[0][i - 1] >= f[2][i - 1]) {
f[0][i] = f[0][i - 1] + nn[u];
pre[0][i] = 0;
} else if (f[1][i - 1] >= f[2][i - 1]) {
f[0][i] = f[1][i - 1] + nn[u];
pre[0][i] = 1;
} else {
f[0][i] = f[2][i - 1] + nn[u];
pre[0][i] = 2;
}
if (f[0][i - 1] >= f[2][i - 1]) {
f[1][i] = f[0][i - 1] + mx[u];
pre[1][i] = 0;
} else {
f[1][i] = f[2][i - 1] + mx[u];
pre[1][i] = 2;
}
if (f[0][i - 1] >= f[1][i - 1]) {
f[2][i] = f[0][i - 1] + mi[u];
pre[2][i] = 0;
} else {
f[2][i] = f[1][i - 1] + mi[u];
pre[2][i] = 1;
}
}
int cur = 0;
if (f[1][m] > f[cur][m]) {
cur = 1;
}
if (f[2][m] > f[cur][m]) {
cur = 2;
}
ll ans = f[cur][m];
for (int i = m; i >= 1; --i) {
st[nd[i - 1]] = cur;
cur = pre[cur][i];
}
for (int i = 1; i <= n; ++i) {
if (ind[i] == 1) {
int u = E[i][0];
if (st[u] == 1) {
st[i] = 2;
} else if (st[u] == 2) {
st[i] = 1;
} else {
st[i] = a[i] >= b[i] ? 1 : 2;
}
}
}
cur = 1;
for (int i = 1; i <= n; ++i) {
if (st[i] == 2) {
p[i] = cur++;
}
}
for (int i = 1; i <= n; ++i) {
if (st[i] == 0) {
p[i] = cur++;
}
}
for (int i = 1; i <= n; ++i) {
if (st[i] == 1) {
p[i] = cur++;
}
}
cout << ans << "\n";
for (int i = 1; i <= n; ++i) cout << p[i] << " \n"[i == n];
}
主要题面
Ynoi
小杉是一个数据结构爱好者。
最近,小杉开始做起了 Ynoi 套题。众所周知,Ynoi 的题一般都会标注年份,而有些 Ynoi 题标注的年份就很离谱以至于诡异。
小杉决定不做这些诡异年份的题目,她认为这种题是“假的 Ynoi 题”。具体地,小杉认定标注年份早于
现在,小杉依次给出
对于
单个测试点
某科学的构造
美琴有
黑子对姐姐大人(美琴)的感情犹如滔滔江水般连绵不绝,所以她要把这
她对于矩阵性质的期望如下:
- 每一行:所有“大数”(
2 或3 )必须在所有“小数”(0 或1 )左边(比较只在同一行进行)。 - 每一列:所有“奇数”(
1 或3 )必须在所有“偶数”(0 或2 )上面(比较只在同一列进行)。
如果有一种方案可以满足黑子对矩阵性质的期望,那么黑子就有信心把自己的心意传达给姐姐大人,也就能达成她自己的一个小小愿望了。
当然了,黑子虽然有超能力但不大会构造抽象的方案,所以她就找上了你。
为了帮助黑子达成愿望,你需要告知她一种合乎她期望的矩阵构造方案(输出任意合乎期望的方案均可)。可以证明,这种方案一定存在。
对于
单个测试点
GTA V
洛圣都最近发生了一起凶案,涉案人数高达足足
当然,办案需要口供,因此洛圣都地方的警局对这
人心难以揣测,各位涉案人员的口供也是样式颇多,不过这些人的口供大致可以分为三类(不保证三类口供均有人作出):
XXX is a liar.,即指认 XXX 作出的口供是虚假的。XXX is the murderer.,即指认 XXX 为这起案件的凶手。I am innocent.,即指认自己在这起凶案中不是凶手。
出于办案多年的经验,警方认为这些人的口供,有且只会有一份是真实的。
我们认为,对于某个人
现在,请你协助警方,列出全部的凶手候选者。
注:前文的“XXX”指代人员编号。本题中,每个人仅作出一份口供。称一个人为真诚者,当且仅当其作出的口供为真。保证 XXX is a liar. 类型的口供均不会产生自指。本题中,凶手有且仅有一人,且一定出自于
对于
单个测试点
树梢的风铃
wyh 做了一架风铃。
风铃有
wyh 需要把
若第
请最大化所有清响与沉响的贡献之和,并输出任意一个达到最大值的音高排列。
保证输入的树满足:所有度数大于
对于
单个测试点