[CF1954] Educational Codeforces Round 164 (Rated for Div. 2) 题解
[CF1954] Educational Codeforces Round 164 (Rated for Div. 2) 题解
A. Painting the Ribbon
最优策略是染
void work() {
int n, m, k, c;
cin >> n >> m >> k;
c = (n + m - 1) / m;
cout << (k >= n - c ? "NO" : "YES") << '\n';
return ;
}
B. Make It Ugly
波动不超过一,答案是波动间隔的
int n, a[N];
vector<int> c;
void work() {
cin >> n;
for(int i = 1; i <= n; i ++) cin >> a[i];
int x = a[1];
a[0] = -1, a[n + 1] = -1;
c.clear();
c.push_back(0);
for(int i = 1; i <= n; i ++) if(a[i] ^ x) c.push_back(i);
c.push_back(n + 1);
int mx = 1e9;
for(int i = 1; i < c.size(); i ++) {
mx = min(mx, c[i] - c[i - 1] - 1);
}
cout << (mx >= n ? -1 : mx) << '\n';
return ;
}
C. Long Multiplication
和一定,差小积大。
D. Colored Balls
有趣的计数。
一个颜色集合的 value 是
根据这个观察,我们可以计数 value 是
如果把
sort(a + 1, a + n + 1);
f[0] = 1;
for(int i = 1; i <= n; i ++) {
for(int j = 0; j <= a[i]; j ++)
ans = (ans + f[j] * a[i] % mod) % mod;
for(int j = a[i] + 1; j <= 5000; j ++)
ans = (ans + ((j + a[i] + 1) / 2) * f[j] % mod) % mod;
for(int j = 5000; j >= a[i]; j --)
f[j] = (f[j] + f[j - a[i]]) % mod;
}
cout << ans << '\n';
E. Chain Reaction
这是一个上取整整除分块的形式,
上取整整除分块与下取整唯一的不同就是如果
稍微卡常,时间复杂度:
// Problem: E. Chain Reaction
// Contest: Codeforces - Educational Codeforces Round 164 (Rated for Div. 2)
// Author: Moyou
// Copyright (c) 2024 Moyou All rights reserved.
// Date: 2024-04-12 23:31:10
#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
// #define int long long
using namespace std;
const int N = 1e5 + 10;
int n, a[N], b[N], d[N], mx;
vector<int> c[N];
long long ans;
void chk(int k, int i) {
b[i] = (a[i] + k - 1) / k;
if(d[i] >= 0) ans -= d[i];
d[i] = b[i] - b[i - 1];
if(d[i] >= 0) ans += d[i];
if(d[i + 1] >= 0) ans -= d[i + 1];
d[i + 1] = b[i + 1] - b[i];
if(d[i + 1] >= 0) ans += d[i + 1];
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i ++) cin >> a[i], b[i] = a[i], mx = max(mx, a[i]), d[i] = a[i] - a[i - 1];
for(int i = 1; i <= n; i ++) if(d[i] >= 0) ans += d[i];
for(int i = 1; i <= n; i ++) {
bool flg = 0;
for(int l = 1, r; l <= a[i]; l = r + 1) {
r = a[i] / (a[i] / l);
if(!flg) c[l].push_back(i);
else flg = 0;
if(a[i] % r == 0) {
if(l != r) {
c[r].push_back(i);
flg = 1;
}
}
}
}
cout << ans << ' ';
for(int k = 2; k <= mx; k ++) {
for(auto i : c[k]) chk(k, i);
cout << ans << ' ';
}
return 0;
}
总结
打得还行,唯一的遗憾是 E 题没写完,主要是没写过上取整整除分块调了半天,后来用 STL 帮忙写还被卡常了,只能老老实实写上取整整除分块了·。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!