9.23
TchongS1010C · · 个人记录
20260923
一、比赛基本情况
-
比赛日期:
2026.9.23 -
比赛时长:
14:00 至17:00 ,3 个小时 -
比赛得分:
1+1+1+1+0+0=4 -
比赛排名:
4 二、比赛整体回顾
A\to B\to C\to D\to E\to F A
套路题,飞速解决
B
思维题,快速解决
C
思维题,中速解决
D
思维题,满速解决
-
-
-
三、题目复盘
A:CF1538C
-
-
-
本题得分:
1 初始思路
首先排序,然后枚举
a_i ,然后二分就行了,注意细节考场解题过程
非常顺利
考场代码
#include <bits/stdc++.h> using namespace std ; long long t , n , l , r , a[200005] , cnt ; int main() { for(cin >> t ; t -- ;) { cin >> n >> l >> r ; for(int i = 1 ; i <= n ; i ++) { cin >> a[i] ; } sort(a + 1 , a + n + 1) ; cnt = 0 ; for(int i = 1 ; i <= n ; i ++) { long long pos1 = lower_bound(a + 1 , a + n + 1 , l - a[i]) - a ; long long pos2 = upper_bound(a + 1 , a + n + 1 , r - a[i]) - a - 1 ; cnt += pos2 - pos1 + 1 - (pos1 <= i && i <= pos2) ; } cout << cnt / 2 << "\n" ; } return 0 ; }赛后题解
我是对的
补题代码
我是对的
复杂度
-
时间复杂度:
O(n\log n) -
空间复杂度:
O(n) 本题总结
B:CF1670B
-
本题得分:
1 初始思路
遍历,上一个特殊字符在
last (刚开始=0 ),这个特殊字符在i ,max(last-i) 考场解题过程
非常顺利
考场代码
#include <bits/stdc++.h> using namespace std ; long long t , n , k ; string s ; char c ; map <char , int> mp ; int main() { ios::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ; for(cin >> t ; t -- ;) { cin >> n >> s >> k ; mp.clear() ; for(int i = 1 ; i <= k ; i ++) { cin >> c ; mp[c] = 1 ; } int maxn = 0 , last = 0 ; for(int i = 0 ; i < n ; i ++) { if(mp[s[i]]) { maxn = max(maxn , i - last) ; last = i ; } } cout << maxn << "\n" ; } return 0 ; }赛后题解
我的是对的
补题代码
我的是对的
复杂度
-
时间复杂度:
O(n) -
空间复杂度:
O(n) 本题总结
C:Cf1516B
-
本题得分:
1 初始思路
二分人数,遍历每个人,现在要选
sum 个人,已经选了cnt 个人,现在在看第i 个人,如果cnt\le b_i,sum-cnt-1\le a_i ,我们就选考场解题过程
非常顺利
考场代码
#include <bits/stdc++.h> using namespace std ; int t , n , a[200005] , b[200005] ; bool check(int mid) { int cnt = 0 ; for(int i = 1 ; i <= n ; i ++) { if(cnt <= b[i] && mid - cnt - 1 <= a[i]) { cnt ++ ; } if(cnt == mid) { return 1 ; } } return 0 ; } int main() { for(cin >> t ; t -- ;) { cin >> n ; for(int i = 1 ; i <= n ; i ++) { cin >> a[i] >> b[i] ; } int l = 0 , r = n + 1 ; while(l + 1 < r) { int mid = (l + r) / 2 ; if(check(mid)) { l = mid ; } else { r = mid ; } } cout << l << "\n" ; } return 0 ; }赛后题解
我是对的
补题代码
我是对的
复杂度
-
时间复杂度:
O(n\log n) -
空间复杂度:
O(n) 本题总结
D:CF1506E
-
本题得分:
1 初始思路
最小字典序:选当前没用过的最小的
最大字典序:选当前< q_i 没用过的最小的
(只针对q_i=q_{i-1} )考场解题过程
非常顺利
考场代码
#include <bits/stdc++.h> using namespace std ; int t , n , a[200005] , b[200005] , c ; int main() { for(cin >> t ; t -- ;) { cin >> n ; for(int i = 1; i <= n ; i ++) { cin >> a[i] ; } memset(b , 0 , sizeof b) ; int minn = 1 ; for(int i = 1 ; i <= n ; i ++) { if(!b[a[i]]) { cout << a[i] << " " ; b[a[i]] = 1 ; } else { while(b[minn]) { minn ++ ; } cout << minn << " " ; b[minn] = 1 ; } } cout << "\n" ; stack <int> s ; a[0] = 0 ; for(int i = 1 ; i <= n ; i ++) { if(a[i] != a[i - 1]) { cout << a[i] << " " ; b[a[i]] = 1; for(int j = a[i - 1] + 1; j < a[i] ; j ++) { s.push(j); } } else { cout << s.top() << " " ; s.pop(); } } cout << "\n" ; } return 0 ; }赛后题解
我是对的
补题代码
我是对的
复杂度
-
时间复杂度:
O(n) -
空间复杂度:
O(n) 本题总结
E:CF1744C
-
本题得分:
0 初始思路
考场解题过程
考场代码
赛后题解
先看
1 的总数是否\bmod n=0 ,是的话就找两个1 过多和过少的行再找一列使得多的为1 少的为0 ,交换复杂度
-
时间复杂度:
O(nm) -
空间复杂度:
O(nm) 补题代码
#include <bits/stdc++.h> using namespace std ; long long t , n , m , sumsum , sum[100005] ; struct node { int x , y , z ; } ; vector <node> ans ; vector <vector <int>> a ; vector <int> big , small ; int main() { for(cin >> t ; t -- ;) { cin >> n >> m ; for(int i = sumsum = 0 ; i < a.size() ; i ++) { a[i].resize(0) ; } a.resize(n + 5) ; for(int i = 0 ; i <= n + 3 ; i ++) { a[i].resize(m + 5) ; sum[i] = 0 ; if(1 <= i && i <= n) { for(int j = 1 ; j <= m ; j ++) { cin >> a[i][j] ; sum[i] += a[i][j] ; sumsum += a[i][j] ; } } } if(sumsum % n) { cout << "-1\n" ; continue ; } ans.clear() ; sumsum /= n ; for(int i = 1 ; i <= m ; i ++) { big.clear() ; small.clear() ; for(int j = 1 ; j <= n ; j ++) { if(sum[j] > sumsum && a[j][i] == 1) { big.push_back(j) ; } else if(sum[j] < sumsum && a[j][i] == 0) { small.push_back(j) ; } } for(int j = 0 ; j < min(big.size() , small.size()) ; j ++) { ans.push_back({big[j] , small[j] , i}) ; sum[big[j]] -- ; sum[small[j]] ++ ; } } cout << ans.size() << "\n" ; for(auto tmp : ans) { cout << tmp.x << " " << tmp.y << " " << tmp.z << "\n" ; } } return 0 ; }本题总结
F:CF1741E
-
本题得分:
0 初始思路
考场解题过程
考场代码
赛后题解
用dfs
补题代码
#include <bits/stdc++.h> using namespace std ; long long t , n , flag , f[200005] , a[200005] ; vector <int> v[2000005] ; void dfs(int step) { f[step] = 0 ; if(flag || step > n) { flag = 1 ; return ; } if(step + a[step] <= n && f[step + a[step] + 1]) { dfs(step + a[step] + 1) ; } for(int x : v[step]) { if(f[x + 1]) { dfs(x + 1) ; } } } int main() { for(cin >> t ; t -- ;) { cin >> n ; f[n + 1] = !(flag = 0) ; for(int i = 1 ; i <= n ; i ++) { cin >> a[i] ; v[i].clear() ; f[i] = 1 ; } for(int i = n ; i > 1 ; i --) { if(i - a[i] > 0) { v[i - a[i]].push_back(i) ; } } dfs(1) ; cout << (flag ? "yes\n" : "no\n") ; } return 0 ; }复杂度
-
时间复杂度:
O(n) -
空间复杂度:
O(n) 本题总结
四、整体反思
做得较好的地方
需要改进的地方
时间安排总结
还不错
20260925
一、比赛基本情况
-
比赛日期:
2026.9.25 -
比赛时长:
14:00 至16:15 ,2.25 个小时 -
比赛得分:
1+1+1+1+1+0+1=6 -
比赛排名:
1 二、比赛整体回顾
A\to B\to C\to E\to G\to D\to F A
思维题,慢速解决
B
贪心题,龟速解决
C
细节题,被卡了一会
D
思维题
E
见这周三
G
见上周四
-
-
-
三、题目复盘
A:CF1506A
-
-
-
本题得分:
1 初始思路
求出行数和列数,然后再从列编号变成行编号
考场解题过程
非常顺利
考场代码
#include <bits/stdc++.h> using namespace std ; long long t , n , m , x , a , b ; int main() { for(cin >> t ; t -- ;) { cin >> n >> m >> x ; a = x / n ; b = x % n ; if(b == 0) { b = n ; } else { a ++ ; } cout << (b - 1) * m + a << "\n" ; } return 0 ; }赛后题解
我是对的
补题代码
我是对的
复杂度
-
时间复杂度:
O(1) -
空间复杂度:
O(1) 本题总结
B:CF1506B
-
本题得分:
1 初始思路
用队列存相邻两个
*的下标差(第一个*存\inf ,使得他被迫把第一个改了),然后就直接模拟+贪心选择好了考场解题过程
非常顺利
考场代码
#include <bits/stdc++.h> using namespace std ; long long t , n , k ; string s ; queue <int> q ; int main() { for(cin >> t ; t -- ;) { cin >> n >> k >> s ; int cnt = 0 , last = -1 , sum = 0 ; for(int i = 0 ; i < n ; i ++) { if(s[i] == '*') { if(last != -1) { q.push(i - last) ; } else { q.push(1e8) ; } last = i ; } } while(q.size()) { if(sum + q.front() > k) { cnt ++ ; sum = q.front() ; } else { sum += q.front() ; } q.pop() ; } cout << cnt << "\n" ; } return 0 ; }赛后题解
我是对的
补题代码
我是对的
复杂度
-
时间复杂度:
O(n) -
空间复杂度:
O(n) 本题总结
C:CF1506C
-
本题得分:
1 初始思路
最长公共子串 可暴力枚举
复杂度
-
时间复杂度:
O(n^5) -
空间复杂度:
O(n^5) 考场解题过程
细节有点多
考场代码
#include <bits/stdc++.h> using namespace std ; int t , minn ; string a , b ; int main() { for(cin >> t ; t -- ;) { cin >> a >> b ; minn = 1e9 ; for(int la = 0 ; la < a.size() ; la ++) { for(int ra = la ; ra < a.size() ; ra ++) { for(int lb = 0 ; lb < b.size() ; lb ++) { for(int rb = lb ; rb < b.size() ; rb ++) { string x = a.substr(la , ra - la + 1) , y = b.substr(lb , rb - lb + 1) ; if(x == y) { minn = min(minn , int(a.size()) - (ra - la + 1) + int(b.size()) - (rb - lb + 1)) ; } } } } } cout << (minn == 1e9 ? a.size() + b.size() : minn) << "\n" ; } return 0 ; }赛后题解
可以用
O(n^2) 补题代码
复杂度
-
时间复杂度:
O(n^2) -
空间复杂度:
O(n^2) 本题总结
D:CF1506D
-
本题得分:
1 初始思路
优先删除出现次数最多的数字,然后推公式
考场解题过程
想到解法后很顺利
考场代码
#include <bits/stdc++.h> using namespace std ; int t , n , a[200005] , cnt , maxn ; int main() { for(cin >> t ; t -- ;) { cin >> n ; for(int i = 1 ; i <= n ; i ++) { cin >> a[i] ; } sort(a + 1 , a + n + 1) ; cnt = 0 , maxn = 0 ; for(int i = 1 ; i <= n ; i ++) { if(a[i] != a[i - 1]) { maxn = max(maxn , cnt) ; cnt = 1 ; } else { cnt ++ ; } } maxn = max(maxn , cnt) ; cout << (maxn > n / 2 ? 2 * maxn - n : n % 2) << "\n" ; } return 0 ; }赛后题解
可以用优先队列每次取最大的和第二大的删了
补题代码
我就不发了
复杂度
-
时间复杂度:
O(n\log n) -
空间复杂度:
O(n\log n) 本题总结
E:CF1506E
-
本题得分:
0 初始思路
最小字典序:选当前没用过的最小的
最大字典序:选当前< q_i 没用过的最小的
(只针对q_i=q_{i-1} )考场解题过程
非常顺利
考场代码
#include <bits/stdc++.h> using namespace std ; int t , n , a[200005] , b[200005] ; int main() { for(cin >> t ; t -- ;) { cin >> n ; for (int i = 1; i <= n ; i ++) { cin >> a[i] ; } memset(b , 0 , sizeof b) ; int minn = 1 ; for (int i = 1 ; i <= n ; i ++) { if(!b[a[i]]) { cout << a[i] << " " ; b[a[i]] = 1 ; } else { while (b[minn]) { minn ++ ; } cout << minn << " " ; b[minn] = 1 ; } } cout << "\n" ; stack <int> s ; a[0] = 0 ; for (int i = 1 ; i <= n ; i ++) { if (a[i] != a[i - 1]) { cout << a[i] << " " ; b[a[i]] = 1; for (int j = a[i - 1] + 1; j < a[i] ; j ++) { s.push(j); } } else { cout << s.top() << " " ; s.pop(); } } cout << "\n" ; } return 0 ; }赛后题解
我是对的
复杂度
-
时间复杂度:
O(n) -
空间复杂度:
O(n) 补题代码
我是对的
本题总结
F:CF1506F
-
本题得分:
0 初始思路
考场解题过程
考场代码
赛后题解
补题代码
#include <bits/stdc++.h> using namespace std; long long t , n , ans ; struct node { long long r , c ; } a[200005] ; bool cmp(node a, node b) { return a.r < b.r; } void solve() { cin >> n ; long long pos = -1 ; for (long long i = 1; i <= n; i++) { cin >> a[i].r; if (a[i].r == 1) { pos = i; } } for (long long i = 1; i <= n; i++) { cin >> a[i].c; if (a[i].c == 1 && pos == i) { pos = 0; } } if (pos != 0) { n++; a[n].r = a[n].c = 1; } sort(a + 1, a + n + 1, cmp); ans = 0; for (long long i = 2; i <= n; i++) { if (a[i].r - a[i].c == a[i - 1].r - a[i - 1].c) { if ((a[i].r + a[i].c) % 2 == 0) { ans += a[i].r - a[i - 1].r; } } else { long long r = a[i].r - a[i - 1].r + 1; long long c = a[i].c - a[i - 1].c + 1; if ((a[i - 1].r + a[i - 1].c) % 2 == 0) { ans += (r - c) / 2; } else { ans += (r - c + 1) / 2; } } } cout << ans << '\n'; } int main() { for (cin >> t ; t --; solve()) ; return 0; }复杂度
-
时间复杂度:
O(n+m) -
空间复杂度:
O(n+m) G:CF1506G
-
本题得分:
0 初始思路
- 就是求
s 的一个子序列,每一个字符都唯一,并且字典序要最大 - 利用反悔贪心,枚举
s 的每个字符,设当前字符串为ans ,如果s_i 已经在ans 里出现过了就跳过,否则如果ans 还有字符,并且最靠右的字符字典序比s_i 小,并且ans 的最右边的字符后边还有,那么就把ans 的最右边删了并取消标记,最后接上s_i 并标记 - 可以用栈
考场解题过程
非常顺利
考场代码
#include <bits/stdc++.h> using namespace std ; long long t , last[30] , n ; string s ; bool vis[30] ; void work() { string ans = "" ; stack <char> stk ; for(int i = 0 ; i < n ; i ++) { char c = s[i] ; if(vis[c - 'a' + 1]) { continue ; } while(stk.size() && stk.top() < c && last[stk.top() - 'a' + 1] > i) { vis[stk.top() - 'a' + 1] = 0 ; stk.pop() ; } vis[c - 'a' + 1] = 1 ; stk.push(c) ; } while(stk.size()) { ans = stk.top() + ans ; stk.pop() ; } cout << ans << "\n" ; } int main() { for(cin >> t ; t -- ; ) { cin >> s ; n = s.size() ; fill(last + 1 , last + 30 , 0) ; for(int i = 0 ; i < n ; i ++) { last[s[i] - 'a' + 1] = i ; } fill(vis + 1 , vis + 30 , 0) ; work() ; } return 0 ; }赛后题解
我是对的
补题代码
我是对的
复杂度
- 时间复杂度:
O(n) - 空间复杂度:
O(n) 本题总结
四、整体反思
做得较好的地方
简单题手速快
需要改进的地方
时间安排总结
20260927
注意到不是
Johnson,而是floyd
- 因为有些时候绕路反而比直走要短,所以我们可以枚举中转点
for(int k = 1 ; k <= n ; k ++) - 然后枚举起点和终点
i,j ,看i\to k\to j 是否比i\to j 短,如果是的话,更新(这个操作叫做松弛) - 然后等程序跑完就可以得到任意点之间的最短路了
B3647
#include <bits/stdc++.h> using namespace std ; long long n , m , dp[105][105] , u , v , w ; int main() { memset(dp , 0x3f , sizeof dp) ; cin >> n >> m ; for(int i = 1 ; i <= n ; i ++) { dp[i][i] = 0 ; } for(int i = 1 ; i <= m ; i ++) { cin >> u >> v >> w ; dp[u][v] = dp[v][u] = min(dp[u][v] , w) ; } for(int k = 1 ; k <= n ; k ++) { for(int i = 1 ; i <= n ; i ++) { for(int j = 1 ; j <= n ; j ++) { dp[i][j] = min(dp[i][j] , dp[i][k] + dp[k][j]) ; } } } for(int i = 1 ; i <= n ; i ++) { for(int j = 1 ; j <= n ; j ++) { cout << dp[i][j] << " " ; } cout << "\n" ; } return 0 ; }时间复杂度:
O(n^3)
空间复杂度:O(n^2) P4306
#include <bits/stdc++.h> using namespace std ; bitset <2005> f[2005] ;//减少空间+节省时间 long long n , ans ; int main() { cin >> n ; for(int i = n - 1 ; i >= 0 ; i --) { cin >> f[i] ;//输入 f[i][i] = 1 ; //不管怎么样i可以到i } for(int k = 0 ; k < n ; k ++) { for(int i = 0 ; i < n ; i ++) { if(f[i][k]) { f[i] |= f[k] ;//这样子不用枚举j } } } for(int i = 0 ; i < n ; i ++) { ans += f[i].count() ; } cout << ans ; return 0 ; }时间复杂度:
O(n^2)
空间复杂度:O(n^2) P6175
#include <bits/stdc++.h> using namespace std; int a[105][105] , f[105][105] , n , m , ans = 1e8 ; int main() { cin >> n >> m ; fill(f[1] , f[n + 1] , 1e8) ; for(int i = 1 , x , y , z ; i <= m ; i ++) { cin >> x >> y >> z ; f[x][y] = f[y][x] = a[y][x] = a[x][y] = min(f[x][y], z) ; } for(int k = 1 ; k <= n ; k ++) { for(int i = 1 ; i <= n ; i ++) { for(int j = 1 ; j <= n ; j ++) { (i != j && a[i][k] && a[k][j]) && (ans = min(ans , f[i][j] + a[i][k] + a[k][j])) ; f[i][j] = min(f[i][j], f[i][k] + f[k][j]) ; } } } if(ans == 1e8) { cout << "No solution." ; } else { cout << ans ; } return 0 ; }时间复杂度:
O(n^3)
空间复杂度:O(n^2)