Atcoder 记录
ABC389
G - Odd Even Graph
You are given a positive even integer and a prime number .
For , solve the following problem.
How many undirected connected simple graphs with vertices labeled from to and edges satisfy this: the number of vertices whose shortest distance from vertex is even is equal to the number of vertices whose shortest distance from vertex is odd? Find this number modulo .
sol
ll t[N][N][N*N];// 本层 j 个点仅向上一层 i 连边,本层间不连边共有 k 条边的方案数。
ll g[N][N][N*N];// 本层 j 个点仅向上一层 i 连边,加上本层间的边共有 k 条边的方案数。
ll f[2][N][N][N][N*N]; //层数,奇数层点数,偶数层点数,本层有 l 个点,共 k 条边的方案数
ABC391
G - Many LCS
You are given a lowercase English string of length and an integer . For each , solve the following problem:
- There are lowercase English strings of length . Among these, find the number, modulo 998244353, of strings whose LCS with has length exactly .
sol
Review how to find the length of an LCS of T and S.Taking a closer look at the transitions, we notice the following properties of the DP array:
Thus, there are only possible patterns for .
We use this fact to solve the original problem.
Let be the number of strings of length such that is the DP array when finding an LCS of and .
The updates on as increases can be found according to the transitions of the DP for LCS described above.
There are states for , and computing transitions of costs , so the overall complexity is (where is the size of alphabet). By precalculating the transitions, the complexity can be reduced to .
ABC392(unrated)
F - Insert
There is an empty array . For , perform the following operation in order:
- Insert the number into so that it becomes the -th element from the beginning.
Output the final array after all operations have been completed.
赛时只会平衡树 /ll
G - Fine Triplets
For integers ( ), if they satisfy , then is called a fine triplet.
You are given a set of distinct positive integers . Find the number of fine triplets with .
sol
Transposing the terms in , we get .
First, let us count the number of integer pairs with and .
Note that the coefficient of the each term in the right hand side is no greater than , so one may find the convolution modulo (which we can directly obtain with the convolution
function in ACL).
ABC394
这场过了 ABCDFG。获得了 ARC 资格,但是不知道获没获得 ARC 实力。
E - Palindromic Shortest Path
We have a directed graph with vertices, numbered .Information about the edges is given by characters . Here, each is either a lowercase English letter or
-
. If is a lowercase English letter, then there is exactly one directed edge from vertex to vertex labeled . If is-
, there is no edge from vertex to vertex .For each integer pair with , answer the following question:
Among all (not necessarily simple) paths from vertex to vertex whose concatenation of labels on the edges forms a palindrome, what is the length of the shortest such path? If there is no such path, the answer is .
sol
For a lowercase English letter and a palindrome , the string obtained by concatenating , , and in this order forms a palindrome. Conversely, a string of length at least two is a palindrome if and only if the first and the last characters are the same, and the string obtained by removing the first and last characters still forms a palindrome.
Using these properties, the problem can be formalized as a shortest path problem on a (directed) graph.
Let be a graph with vertices . We will decide the edges so that vertex corresponds to a path from vertex to vertex in the graph given in the problem statement.
For convenience, add another vertex to for it to have . Then the answer to the original problem for an integer pair is the length of a shortest path from to in the graph with edges added as follows:
- An edge from to of weight for each .
- An edge from to of weight for each with
-
. - An edge from to of weight for each with
-
,-
, .
The edges of the first kind represent the palindrome of length , and those for the second represent those of length . The edges of the third kind correspond to adding the same character at the beginning and the end of a palindrome to obtain a new palindrome with the length increased by two.
has vertices, each of degree , so it has edges, allowing -time BFS (Breadth-First Search) to find the answer.
Note that although the edges are weighted, one can still find the shortest distances by processing those with weight and first.
G - Dense Buildings
这题过了,但赛后很多天才发现做麻烦了。
ARC194
第一场 ARC,unrated,只过 AB。
C - Cost to Flip
You are given two integer sequences of length , and , each consisting of and .
You can perform the following operation on any number of times (possibly zero):
- First, choose an integer satisfying , and flip the value of (if the original value is , change it to ; if it is , change it to ).
- Then, pay yen as the cost of this operation.
Print the minimum total cost required to make identical to .
WA-code
ll nw=0;
For(i,1,ce)
{
int p1=lower_bound(d+1,d+1+cd,e[i])-d;
int p2=lower_bound(d+1,d+1+cd,-e[i])-d;
ll del=(p2-p1)*e[i]+(pred[p1-1]+nw+e[i]+sum)+(pred[p2-1]+nw+sum);
if(del>0) break;
nw+=e[i],ans+=del;
}
write(ans),End;
但其实是不能直接 break 的。
AC-code
ll nw=0,res=ans;
For(i,1,ce)
{
int p1=lower_bound(d+1,d+1+cd,e[i])-d;
int p2=lower_bound(d+1,d+1+cd,-e[i])-d;
ll del=(p2-p1)*e[i]+(pred[p1-1]+nw+e[i]+sum)+(pred[p2-1]+nw+sum);
nw+=e[i],ans+=del,res=min(res,ans);
}
write(res),End;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】