总结
100 + 0 + 0 + 20 + 25 = 145,rk126
糖炸了 T2 没输出边数+忘记 bfs 复杂度我丢我是大傻逼
不知道为什么 T3 获得了 0 分的好成绩
T4T5 倒是没挂,但是都是最低的暴力;T1 还挺顺利调了一小会就过了
状态不太好,感觉一整场比赛都没烧烤出什么好玩的东西,一直在犯糖,题目也不好玩
A. 蜗蜗的魔法序列
54 分钟过掉
注意到异或的操作最多做一次, 次的话如果有重复的位就抵消了等于没有,否则就可以合并到一次
再注意到异或操作一定是最开始直接搞完然后再交换,如果换完了再异或,跟异或完了再换是一样的
然后因为是交换相邻的数,所以交换次数就是逆序对数,那么最开始异或就是在尽量减少逆序对数,按位考虑,看看每一位异或了能不能减少,能就全都异或上
如果有至少一位有异或的操作答案就加一
最后算一下逆序对数就结束了
代码
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int K = 18;
LL n, a[1 << K], x, s[1 << K], k, tr[1 << K + 1], ans;
int lb (int x) {
return x & -x;
}
LL query (int x) {
LL ret = 0;
for (; x; x -= lb(x)) {
ret += tr[x];
}
return ret;
}
void add (int x) {
for (; x <= n; x += lb(x)) {
tr[x]++;
}
}
int main () {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n;
if (n == 1) {
cout << 0;
return 0;
}
for (; (1 << k) != n; k++);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = k - 1; i >= 0; i--) {
LL zs = 0, sm = 0;
fill(s, s + n, 0);
for (int j = 0; j < n; j++) {
// cout << (a[j] >> i) << ' ' << zs << '\n';
if ((a[j] >> i) & 1) {
s[a[j] >> i + 1]++;
} else {
zs += s[a[j] >> i + 1];
}
}
for (int j = 0; j < n; j++) a[j] ^= 1 << i;
fill(s, s + n, 0);
for (int j = 0; j < n; j++) {
// cout << (a[j] >> i) << ' ' << zs << '\n';
if ((a[j] >> i) & 1) {
s[a[j] >> i + 1]++;
} else {
sm += s[a[j] >> i + 1];
}
}
if (zs > sm) x = 1;
else {
for (int j = 0; j < n; j++) a[j] ^= 1 << i;
}
}
if (x != 0) ans++;
for (int i = 0; i < n; i++) {
// cout << a[i] << ' ';
ans += query(n) - query(a[i] + 1);
add(a[i] + 1);
}
// cout << '\n';
cout << ans;
return 0;
}B. 蜗蜗的灵脉地图
我是大傻逼我是大傻逼我是大傻逼我是大傻逼我是大傻逼我是大傻逼我是大傻逼我是大傻逼我是大傻逼我是大傻逼我是大傻逼我是大傻逼我是大傻逼我是大傻逼
气笑了
太好啦我没有输出边数!
做了 42 分钟然后没输出边数保龄啦!【这个故事告诉我们大样例不能没有输出【早知道细看一眼小样例了。。
首先有了 这个题 的经验(?),我们有一个大致的烧烤方向就是先确定一部分边再完成整个图
根据直觉,注意到如果直接按照题目给的矩阵建图,是 1 就连边否则不连,那么至少 1 的条件可以满足
0 的话,因为它的长度一定 ,所以在路径中间一定存在一个点 ,使得 和 都是奇数,这样的话在我们建出来的图中它们的距离一定 ,又因为没有直接连边所以距离 ,满足条件
于是直接建好一个图,再判一判合法就好啦
怎么判无解??
考场上我成奶龙了,居然以为 bfs 的复杂度是 的,于是写出了这样依托答辩
代码
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 2e3 + 5;
int t, n, dis[N], f[N][N];
vector <int> v[N];
string s[N];
void bfs (int x) {
fill(dis + 1, dis + n + 1, n);
dis[x] = 0;
queue <int> q;
q.push(x);
while (q.size()) {
int x = q.front(); q.pop();
for (int i : v[x]) {
if (dis[i] > dis[x] + 1) {
dis[i] = dis[x] + 1;
q.push(i);
}
}
}
}
int main () {
ios::sync_with_stdio(0), cin.tie(0);
for (cin >> t; t--;) {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s[i];
v[i].clear();
for (int j = 1; j <= n; j++) {
f[i][j] = s[i][j - 1] - '0';
if (f[i][j]) {
v[i].emplace_back(j);
}
}
}
int ans = 1;
for (int i = 1; i <= n && ans; i++) {
bfs(i);
for (int j = 1; j <= n; j++) {
if ((dis[j] & 1) != f[i][j] || dis[j] == n) {
ans = 0;
break;
}
}
}
if (ans) {
cout << "YES\n";
for (int i = 1; i <= n; i++) {
for (int j : v[i]) {
if (j > i) {
cout << i << ' ' << j << '\n';
}
}
}
} else {
cout << "NO\n";
}
}
return 0;
}是的它没有 T 掉,因为同时我没有输出边数,在 T 之前已经 WA 了:):):)【糖炸了我靠
但是实际上根据我们上面的分析,判无解其实就是判连通,再加上判 的 和 的 有没有共同的 1,用 bitset 搞一搞就好了
AC 代码
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 2e3 + 5;
int t, n, dis[N], f[N][N], fa[N];
bitset <N> b[N];
vector <int> v[N];
string s[N];
int fd (int x) {
return fa[x] ? fa[x] = fd(fa[x]) : x;
}
int main () {
ios::sync_with_stdio(0), cin.tie(0);
for (cin >> t; t--;) {
cin >> n;
int qwq = 0, c = 0;
fill(fa + 1, fa + n + 1, 0);
for (int i = 1; i <= n; i++) {
cin >> s[i];
b[i].reset();
v[i].clear();
for (int j = 1; j <= n; j++) {
f[i][j] = s[i][j - 1] - '0';
if (f[i][j]) {
int x = fd(i), y = fd(j);
if (x != y) {
fa[x] = y;
c++;
}
v[i].emplace_back(j);
b[i].set(j);
if (j > i) qwq++;
}
}
}
if (c != n - 1) {
cout << "NO\n";
continue;
}
int ans = 1;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (f[i][j]) continue;
if ((b[i] & b[j]).none()) {
ans = 0;
break;
}
}
}
if (ans) {
cout << "YES\n" << qwq << '\n';
for (int i = 1; i <= n; i++) {
for (int j : v[i]) {
if (j > i) {
cout << i << ' ' << j << '\n';
}
}
}
} else {
cout << "NO\n";
}
}
return 0;
}总结:我是奶龙哦 要仔细看题不要犯糖
C. 魔法材料整理
保龄啦
暴力 TLE 啦,特殊性质 WA 啦
捆绑测试**啦
先分析一下最小总代价怎么算:按顺序排好,中间会有一些空出来的连续段,比方说如果有 个数 ,不分组的话是 ,如果分开:,那么当 时分开会更优,所以算代价的时候从左往右扫过去,有长的间隙就分开否则就接上
首先是一个没什么好说的纯暴力
然后是 的特殊性质,注意到此时没有长的间隙,一定是最大的减最小的再加 ,那么算出最大的减最小的,再用插板法算一算就好了
依旧不知道为什么保龄的代码
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 3e6 + 5, mod = 998244353;
LL t, n, m, d, k, qwq[N][2], a[N], ans;
LL qpow (LL x, LL y) {
LL ret = 1;
for (; y; y >>= 1) {
if (y & 1) {
(ret *= x) %= mod;
}
(x *= x) %= mod;
}
return ret;
}
void init () {
qwq[0][0] = qwq[0][1] = 1;
for (LL i = 1; i <= 3e6; i++) {
qwq[i][0] = qwq[i - 1][0] * i % mod;
qwq[i][1] = qpow(qwq[i][0], mod - 2);
}
}
void dfs (int x, int f, int s, int zs, int sum) {
if (x > m) {
int l, r;
for (int i = 1; i <= m; i++) {
if (a[i]) {
l = i;
break;
}
}
for (int i = m; i >= 1; i--) {
if (a[i]) {
r = i;
break;
}
}
if (r - l + d - zs == k) {
ans++;
}
return;
}
if (x == m) {
a[x] = sum;
if (sum) {
dfs(x + 1, 0, 0, zs + max(0ll, s + 1 - d), 0);
} else {
dfs(x + 1, 0, 0, zs, 0);
}
a[x] = 0;
return;
}
for (int i = 0; i <= sum; i++) {
a[x] = i;
if (i == 0) {
dfs(x + 1, f, s + f, zs, sum);
} else {
dfs(x + 1, 1, 0, zs + max(0ll, s + 1 - d), sum - i);
}
}
}
LL C (LL x, LL y) {
if (x < y) return 0;
// cout << x << ' ' << y << '\n';
return qwq[x][0] * qwq[y][1] % mod * qwq[x - y][1] % mod;
}
int main () {
ios::sync_with_stdio(0), cin.tie(0);
init();
for (cin >> t; t--;) {
ans = 0;
cin >> n >> m >> d >> k;
if (n <= 15 && m < 16 && d < 16 && k < 16) {
dfs(1, 0, 0, 0, n);
cout << ans << '\n';
} else {
if (k < d) {
cout << "0\n";
continue;
}
k -= d;
if (m < k) {
cout << "0\n";
continue;
}
// cout << m - k << '\n';
cout << (m - k) % mod * C(n + k - 2, k) % mod << '\n';
}
}
return 0;
}这么优美到底是如何保龄的qwq
正解:
我在场上一直在以 的视角烧烤,于是毫无头猪qwq 其实可以先放下 不管,最后再乘上塞进 里的方案数
设 ,
我们把 的 称作大间隙,其他的叫做小间隙
枚举大间隙的数量 ,再把它们塞进 个间隙里面,方案数是:
那么小间隙的和 ,有 个小间隙,然后它们必须
所以容斥一下,方案数为:
【前面的两个括号是容斥+选位置,后面那个是插板法
好啦如果这样乘起来那就是没有 的限制的方案数,考虑加上 的限制
考虑把大间隙的 拆成 ,那么在 里放了所有其他的间隙以及这些 ,也就是 之后,剩下的就可以全部用插板法放进 里面
方案数:
总方案数:
然而并没有结束。。注意到如果 ,后面那个西格玛就不好搞,可以特判掉:
当 时答案为 ,否则就是
做完啦!
代码
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 3e6 + 5, mod = 998244353;
LL t, n, m, d, k, qwq[N][2], ans;
LL qpow (LL x, LL y) {
LL ret = 1;
for (; y; y >>= 1) {
if (y & 1) {
(ret *= x) %= mod;
}
(x *= x) %= mod;
}
return ret;
}
void init () {
qwq[0][0] = qwq[0][1] = 1;
for (int i = 1; i <= 3e6; i++) {
qwq[i][0] = qwq[i - 1][0] * i % mod;
qwq[i][1] = qpow(qwq[i][0], mod - 2);
}
}
LL C (LL x, LL y) {
if (x < y) return 0;
if (x < 0) return 0;
return qwq[x][0] * qwq[y][1] % mod * qwq[x - y][1] % mod;
}
int main () {
ios::sync_with_stdio(0), cin.tie(0);
init();
for (cin >> t; t--;) {
cin >> n >> m >> d >> k;
if (d == 0) {
if (k) {
cout << "0\n";
} else {
cout << C(m - 1 + n, n) << '\n';
}
continue;
}
ans = 0;
for (int i = 0, R = k - d, S = R; i < n && i * d <= R; i++, S -= d) {
LL zs = 0;
for (int j = 0; j * d <= S; j++) {
zs = (zs + C(n - 1 - i, j) * (j == 0 && n - i - 1 == 0 && S == 0 ? 1 : C(S - j * d + n - i - 2, n - i - 2)) % mod * (j & 1 ? -1 : 1) + mod) % mod;
}
ans = (ans + zs * C(n - 1, i) % mod * C(m - R + i, i + 1) % mod) % mod;
}
cout << ans << '\n';
}
return 0;
}D. 星际跃迁
20pts
懒得写了
最后 30min 写了 的
但是下样例用了 30min
但是样例并没有什么用
代码
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int n, m, s;
int main () {
cin >> n >> m >> s;
if (m == 0) {
for (int i = 1; i <= n; i++) {
cout << min(abs(s - i), n - abs(s - i)) << '\n';
}
return 0;
} else {
int a, b;
cin >> a >> b;
for (int i = 1; i <= n; i++) {
if (i == s) {
if (b == s || b % n + 1 == s) {
cout << n - 1 << '\n';
} else {
cout << "0\n";
}
} else {
if (i > s) {
if (b >= s && b < i) {
cout << min(i - s - 1, n - i + s) << '\n';
} else {
cout << min(i - s, n - i + s - 1) << '\n';
}
} else {
if (b >= i && b < s) {
cout << min(s - i - 1, n - s + i) << '\n';
} else {
cout << min(s - i, n - s + i - 1) << '\n';
}
}
}
}
}
return 0;
}正解【?
稍微看了眼题解,发现跟我赛后大致想象的差不多,就是倒过来搞一个 dp
设 表示从 走到 最少要加几个桥(其实还要带一个离中心的距离也就是离中心还有几个桥,但是可以滚动就不写了),那么转移方程就是
然后考虑经过一个桥的时候,因为 会到 , 会到 ,所以直接把两个 交换。接下来考虑周围的点的变化
注意到相邻的 最多差 ,可以根据这个分讨
首先如果两个 相同,就没有变化
假设是 的 减了 ,那么从 开始往远离 的方向一段连续的 的点都可以减一
这时 加了 ,其实这对它旁边的点是没有影响的,因为如果它旁边的点没有把桥架到它就肯定没有影响,如果架到它,就可以往上移一点不去
但是如果原来的 ,就可以把 在去 之前拉回来,这样它的 就不用加
好差不多就这样【感觉这个思路还好啊没有特别变态【不过听说代码又臭又长还很难调【?
代码没写
E. 逆序对
纯暴力嘿嘿
看到数据范围还烧烤了一下折半搜索无果
代码
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 45;
LL n, a[N], ans[N][2], tr[N];
int lb (int x) {
return x & -x;
}
void add (int x, int y) {
for (; x <= n; x += lb(x)) {
tr[x] += y;
}
}
int query (int x) {
int ret = 0;
for (; x; x -= lb(x)) {
ret += tr[x];
}
return ret;
}
void dfs (int x, int s, int zs) {
if (x > n) {
if (ans[s][0] > zs) {
ans[s][0] = zs, ans[s][1] = 1;
} else if (ans[s][0] == zs) {
ans[s][1]++;
}
return;
}
dfs(x + 1, s, zs);
zs += query(n) - query(a[x]);
add(a[x], 1);
dfs(x + 1, s + 1, zs);
add(a[x], -1);
}
int main () {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
ans[i][0] = n * n;
}
dfs(1, 0, 0);
for (int i = 1; i <= n; i++) {
cout << ans[i][0] << ' ' << ans[i][1] << '\n';
}
return 0;
}总结:糖炸了我是奶龙