Atcoder 记录

ABC389

G - Odd Even Graph

You are given a positive even integer N and a prime number P.
For M=N1,,N(N1)2, solve the following problem.
How many undirected connected simple graphs with N vertices labeled from 1 to N and M edges satisfy this: the number of vertices whose shortest distance from vertex 1 is even is equal to the number of vertices whose shortest distance from vertex 1 is odd? Find this number modulo P.

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 S of length N and an integer M. For each k=0,1,,N, solve the following problem:

  • There are 26M lowercase English strings of length M. Among these, find the number, modulo 998244353, of strings whose LCS with S has length exactly k.

1N10,1M100

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:

dpi,0=0

dpi,j+1dpi,j[0,1]

Thus, there are only dpi possible patterns for 2|S|.

We use this fact to solve the original problem.

Let DPi,dp_array be the number of strings T of length i such that dp_array is the DP array dpi when finding an LCS of T and S.

The updates on dp_array as i increases can be found according to the transitions of the DP for LCS described above.

There are O(2N) states for DPi, and computing transitions of dp_array costs O(σN), so the overall complexity is O(NMσ2N) (where σ is the size of alphabet). By precalculating the transitions, the complexity can be reduced to O(NM2N).

ABC392(unrated)

F - Insert

There is an empty array A. For i=1,2,,N, perform the following operation in order:

  • Insert the number i into A so that it becomes the Pi-th element from the beginning.
    Output the final array A after all operations have been completed.

赛时只会平衡树 /ll

G - Fine Triplets

For integers A,B,C ( A<B<C ), if they satisfy BA=CB, then (A,B,C) is called a fine triplet.
You are given a set of N distinct positive integers S={S1,S2,,SN}. Find the number of fine triplets (A,B,C) with A,B,CS.

sol

Transposing the terms in BA=CB, we get 2B=A+C.
First, let us count the number of integer pairs (A,C) with A,CS and A+C=k.

Note that the coefficient of the each term in the right hand side is no greater than 106, so one may find the convolution modulo 998244353 (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 N vertices, numbered 1,2,,N.Information about the edges is given by N2 characters C1,1,C1,2,,C1,N,C2,1,,CN,N. Here, each Ci,j is either a lowercase English letter or -. If Ci,j is a lowercase English letter, then there is exactly one directed edge from vertex i to vertex j labeled Ci,j. If Ci,j is -, there is no edge from vertex i to vertex j.

For each integer pair (i,j) with 1i,jN, answer the following question:

Among all (not necessarily simple) paths from vertex i to vertex j 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 1.

sol

For a lowercase English letter c and a palindrome S, the string obtained by concatenating c, S, and c 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 G be a graph with N2 vertices {(1,1),(1,2),,(1,N),(2,1),,(N,N)}. We will decide the edges so that vertex (i,j) corresponds to a path from vertex i to vertex j in the graph given in the problem statement.

For convenience, add another vertex S to G for it to have N2+1. Then the answer to the original problem for an integer pair (i,j) is the length of a shortest path from S to (i,j) in the graph with edges added as follows:

  • An edge from S to (i,i) of weight 0 for each i.
  • An edge from S to (i,j) of weight 1 for each (i,j) with Ci,j -.
  • An edge from (i,j) to (k,l) of weight 2 for each (i,j,k,l) with Ck,i -, Cj,l -, Ck,i=Cj,l.

The edges of the first kind represent the palindrome of length 0, and those for the second represent those of length 1. 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.

G has O(N2) vertices, each of degree O(N2), so it has O(N4) edges, allowing O(N4)-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 0 and 1 first.

G - Dense Buildings

这题过了,但赛后很多天才发现做麻烦了。

ARC194

第一场 ARC,unrated,只过 AB。

C - Cost to Flip

You are given two integer sequences of length N, A=(A1,A2,,AN) and B=(B1,B2,,BN), each consisting of 0 and 1.

You can perform the following operation on A any number of times (possibly zero):

  1. First, choose an integer i satisfying 1iN, and flip the value of Ai (if the original value is 0, change it to 1; if it is 1, change it to 0).
  2. Then, pay k=1NAkCk yen as the cost of this operation.

Print the minimum total cost required to make A identical to B.

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;

D - Reverse Brackets

E - Swap 0^X and 1^Y

posted @   wanggk  阅读(16)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示