ICPC22年程序设计赛正式题面The 2022 ICPC Asia Hangzhou Regional Programming ContestHangzhou Normal University,

35 篇文章 2 订阅
The 2022 ICPC Asia Hangzhou Regional Programming Contest
Hangzhou Normal University, December, 04, 2022
 
 

Problem A. Modulo Ruins the Legend

Input fifile:
standard input
Output fifile:
standard output
Time limit: 1 second
Memory limit: 1024 megabytes
Grammy has a sequence of integers a1 , a2 , . . . , a n. She thinks that the elements in the sequence are too
large, so she decided to add an arithmetic progression to the sequence. Formally, she can choose two
non-negative integers s, d, and add s + kd to a k for each k [1 , n].
Since we want to ruin the legend, please tell her the minimum sum of elements modulo m after the
operation. Note that you should minimize the sum after taking the modulo.
Input
The fifirst line contains two integers n, m (1 n 105 , 1 m 109 ).
The second line contains n integers a1 , a2 , . . . , a n (0 a i < m), denoting the initial sequence.
Output
Output exactly two lines.
The fifirst line contains one integer, denoting the minimum sum of elements modulo m.
The second line contains two integers s, d (0 s, d < m), denoting the integers chosen by Grammy.
Examples
standard input
standard output
6 24
1 1 4 5 1 4
1
0 5
7 29
1 9 1 9 8 1 0
0
0 0
Page 1 of 16The 2022 ICPC Asia Hangzhou Regional Programming Contest
Hangzhou Normal University, December, 04, 2022
 
 
 
 
 
 

Problem B. Useful Algorithm

Input fifile:
standard input
Output fifile:
standard output
Time limit: 6 seconds
Memory limit: 1024 megabytes
Putata is learning some useful algorithm called Binary Adding these days. This algorithm allows you to
calculate the sum of two m-bit binary integers.
An integer x is called to be a m-bit binary integer, if and only if 0 x < 2 m. The binary representation of
m is a 0-indexed sequence v of length m, where 0 i < m, v i ∈ {0 , 1 }, and x =
m 1
P
i=0
v i2 i . It is guaranteed
that for all m-bit binary integers, each one have its unique binary representation.
The Binary Adding algorithm for calculating the sum of two m-bit binary integers with binary
representation { a i } m
1
i=0
, { b i } m
1
i=0
is shown below:
Algorithm 1 BinaryAdding( a, b)
Input: input parameters a[0 , . . . , m 1], b[0 , . . . , m 1]
Output: output result sum[0 , . . . , m] , carry[0 , . . . , m]
1: carry[0] := 0
2: for i := 0 to m 1 do
3:
sum[ i] := a[ i] b[ i] carry[ i]
. denotes xor operation
4:
carry[ i + 1] := ( a[ i] b[ i]) ( a[ i] carry[ i]) ( b[ i] carry[ i])
. denotes and operation,
denotes or operation.
5: sum[ m] := carry[ m]
6: return sum[0 , . . . , m] , carry[0 , . . . , m]
In order to test if Putata really mastered this algorithm, Budada is going to prepare tests for
Putata. Before preparing his tests, Budada devised a way to calculate the diffiffifficulty of a problem.
Assume the problem is to calculate the sum of { a i } m
1
i=0
, { b i } m
1
i=0
, then we defifine the carry set of a, b,
S( a, b) = { x |when calling BinaryAdding( a, b) , carry x = 1 }. Budada has an integer sequence { w i } m
i=1,
denoting the diffiffifficulty of calculation when a carry occurred at the corresponding bit. The Carry
Diffiffifficulty is the maximum diffiffifficulty among all bits where a carry occurred. If there’s no carry occurred,
the Carry Diffiffifficulty is 0.
The problem database of Budada is an integer sequence { c i } n
i=1. Each integer has a corresponding
Numerical diffiffifficulty, which is also an integer sequence { d i } n
i=1. Please notice that c i are not necessarily
pairwise distinct, and for some c i = c j , d i might not be equal to d j . A Binary Adding problem consists
of two integers, so when Budada chooses c i and c j to set a test, the Numerical diffiffifficulty of this problem
is d i + d j .
Budada wants to prepare the most diffiffifficult test for Putata, so he will choose two integers i, j such
that 1 i, j n (not necessarily distinct), and use c i , c j to set a test. He wants to maximize
the Test Diffiffifficulty, which is the product of the Carry Diffiffifficulty and Numerical diffiffifficulty of
this test, and he asked you to tell him this production. Formally, the maximum Test Diffiffifficulty is
max
1 i,j n
{max {max { w x | x S( c i , c j ) } , 0 } · ( d i + d j ) }.
Budada also has q updates for his problem database, each time he will select an integer i, and modify
c i , d i . You are asked to answer the maximum Test Diffiffifficulty of q + 1 versions of the problem database.
Input
The fifirst line contains three integers n, m, q (1 n, q 105 , 1 m 16), corresponding to the meaning
described above.
Page 2 of 16The 2022 ICPC Asia Hangzhou Regional Programming Contest
Hangzhou Normal University, December, 04, 2022
The second line contains m integers, the i-th integer is w i (1 w i 109 ).
The third line contains n integers, the i-th integer is c i (0 c i < 2 m).
The fourth line contains n integers, the i-th integer is d i (1 d i 109 ).
For the following q lines, each line contains three integers x, u, v, let lastans denotes the maximum
Test Diffiffifficulty of the last version of the problem database, and x 0 = x lastans, u 0 = u lastans,
v 0 = v lastans (1 x 0 n, 0 u 0 < 2 m, 1 v 0 109 ), this represents Budada changes c x 0 to u 0 ,
and d x 0 to v 0 . Here, “ ” denotes the bitwise XOR operator. Please notice that you should use 64 -bit
integer to store x, u, v .
Output
Output q + 1 lines, denoting the maximum Test Diffiffifficulty of the q + 1 versions of the problem database.
Example
standard input
standard output
5 3 3
1 2 4
0 0 1 2 7
10 10 5 3 1
27 24 29
20 16 19
13 8 9
24
16
8
0
Note
The decrypted operations are:
x 0 = 3 , u 0 = 0 , v 0 = 5.
x 0 = 4 , u 0 = 0 , v 0 = 3.
x 0 = 5 , u 0 = 0 , v 0 = 1.
Page 3 of 16The 2022 ICPC Asia Hangzhou Regional Programming Contest
Hangzhou Normal University, December, 04, 2022
 
 
 
 
 
 
 
 
 
 

Problem C. No Bug No Game

Input fifile:
standard input
Output fifile:
standard output
Time limit: 1 second
Memory limit: 1024 megabytes
Putata is preparing the RPG Pro League (RPL) held by the International Computer Playing Company
(ICPC). In this RPG game, the player will wear n items at the same time. Each item can offffer the player
several points of power. There is a magic buffff in the game, which can upgrade each item such that they
can offffer several points of bonus power.
However, the buffff is limited, it can only buffff at most k points of power. Formally, assume the player is
wearing nothing initially, and then will wear all the n items one by one. The game server will scan through
all these n items one by one, according to the permutation that the player wears them. When the server is
scanning the i-th item, which can offffer p i points of power, let sum = P 1 j<i p j denoting the total points
of power scanned before:
• If sum + p i k, the whole item will be upgraded. The buffff will offffer w i,p i points of bonus power.
• If sum k, the item won’t be upgraded. The buffff will offffer nothing.
• Otherwise, only a part of the item will be upgraded. The buffff will offffer w i,k sum points of bonus
power.
Putata is clever, he soon realized that he can adjust the permutation to wear these n items to gain
more points of bonus power! Unfortunately, Putata doesn’t know the optimal permutation, please write
a program to help him.
The behavior of the magic buffff performed by the game server is a bug. The game code can work all thanks
to bugs, so it is possible that w i,a > w i,b where a < b.
Input
The fifirst line contains two integers n and k (1 n 3 000, 0 k 3 000), denoting the number of items
and the limit k.
Each of the following n lines starts with an integer p i (1 p i 10), denoting the base power of the i-th
item, followed by p i integers w i,1 , w i,2 , . . . , w i,p i (1 w i,j 105 ).
Output
Output a single line containing an integer, denoting the maximum points of total bonus power that can
be reached. The base power is not included in the answer.
Example
standard input
standard output
4 5
2 1 3
2 1 1
2 3 1
2 1 3
9
Page 4 of 16The 2022 ICPC Asia Hangzhou Regional Programming Contest
Hangzhou Normal University, December, 04, 2022
 
 
 
 
 
 

Problem D. Money Game

Input fifile:
standard input
Output fifile:
standard output
Time limit: 1 second
Memory limit: 1024 megabytes
Putata and Budada are organizing a game with n players. Each player has some deposit, which is a real
number. Player i has a i deposits in the beginning. During each round of the game, the followings happen
in order:
• Player 1 gives player 2 half of player 1’s deposit.
• Player 2 gives player 3 half of player 2’s deposit.
• . . .
• Player n 1 gives player n half of player n 1’s deposit.
• Player n gives player 1 half of player n’s deposit.
The n players played this game for exactly 20221204 rounds. Putata wonders how much deposit each player
has after the game. Please write a program to answer his question.
Input
The fifirst line contains an integer n (2 n 105 ), denoting the number of players.
The second line contains n integers a1 , a2 , . . . , a n (1 a i 106 ), denoting the deposit player i has in the
beginning.
Output
Output one line with n real numbers, denoting the deposit each player has after they played this game.
Your answer will be considered correct if its absolute or relative error does not exceed 10 6 . Formally, let
your answer be a, and the jury’s answer be b. Your answer will be considered correct if
| a b
|
max(1
, |
b |) 10 6 .
Example
standard input
standard output
2
4 2
4.00 2.00
Note
During one round, the deposit they have changed as follows: [4 , 2] [2 , 4] [4 , 2]. Their deposit does
not change after this round, so the answer is the same as the input.
Page 5 of 16The 2022 ICPC Asia Hangzhou Regional Programming Contest
Hangzhou Normal University, December, 04, 2022
 
 
 
 
 

Problem E. Oscar is All You Need

Input fifile:
standard input
Output fifile:
standard output
Time limit: 1 second
Memory limit: 1024 megabytes
Putata has a sequence p of length n, where p is a permutation of 1 , 2 , . . . , n. Budada can perform the
following operation at most 2 n + 1 times:
• Cut the sequence into three consecutive non-empty parts, and swap the fifirst part and the
last part. Formally, you should select two integers x, y satisfying that x > 0, y > 0,
x + y < n, and the sequence will change from p1 , . . . , p x , p x+1 , . . . , p n y , p n y+1 , . . . , p n to
p n y+1 , . . . , p n , p x+1 , . . . , p n y , p1 , . . . , p x.
Budada wants to make the lexicographical order of the permutation as small as possible after no more
than 2 n + 1 operations. Please help him fifind the way to perform operations so that the lexicographical
order of the permutation is as small as possible.
A permutation is an array where each integer from 1 to s (where s is the size of permutation) occurs
exactly once.
A permutation a is lexicographically smaller than a permutation b if and only if the following condition
holds:
• Let x be the smallest integer where a y = b y holds for all y x, then we have x < n and a x+1 < b x+1.
Input
The input contains several test cases.
The fifirst line contains an integer T (1 T 120), denoting the number of test cases.
For each test case, the fifirst line contains an integer n (3 n 1000), denoting the length of the
permutation.
The second line contains n integers, the i-th integer is p i (1 p i n), denoting the permutation. It is
guaranteed that p is a permutation of 1 , 2 , . . . , n.
It is guaranteed that the sum of n in all test cases will not exceed 1000.
Output
For each test case, output one integer m in the fifirst line, denoting the number of operations. You should
guarantee that 0 m 2 n + 1.
Then output m lines, each line contains two integers x, y, denoting one operation. You should guarantee
that 0 < x, 0 < y, x + y < n.
Please notice that you do not have to minimize the number of operations.
Example
standard input
standard output
2
3
1 3 2
5
4 1 2 3 5
0
2
2 1
1 1
Page 6 of 16The 2022 ICPC Asia Hangzhou Regional Programming Contest
Hangzhou Normal University, December, 04, 2022
 
 
 
 
 
 

Problem F. Da Mi Lao Shi Ai Kan De

Input fifile:
standard input
Output fifile:
standard output
Time limit: 1.5 seconds
Memory limit: 1024 megabytes
Grammy has joined n + 1 QQ groups numbered 0 n. Teacher Rice is in the group 0.
Every day, Grammy’s friends send messages to some groups in 1 n, and Grammy will select the messages
which Teacher Rice likes and forward them to the group 0.
Here we defifine a message as a string consisting of lowercase letters, and Teacher Rice likes a message if
and only if the string “bie” is a substring of the message.
Now, given the messages in groups 1 n, Grammy will search messages from group 1 to group n in order,
checking the messages in the group one by one. For each message, pick out it if Teacher Rice likes it and
it hasn’t appeared in group 0, and forward it to group 0. Here appear means the same message has been
forwarded to group 0 before.
Please output all the messages that Grammy will forward to group 0 in order. For each group, if Grammy
can’t pick out any message, output “Time to play Genshin Impact, Teacher Rice!” in one line.
Input
The fifirst line contains a single integer n (1 n 104 ), denoting the number of QQ groups. The following
lines describe the messages in groups 1 to n.
For the i-th group, the fifirst line contains an integer m i (0 m i 104 ), denoting the number of messages
in this group. The following m i lines each line contains a non-empty string s i,j representing a message.
It is guaranteed that P m i 104 , P | s i,j | ≤ 104 and all the messages only consist of lowercase letters.
Output
Output each message in a line, denoting all the messages that Grammy will forward to group 0 in order. For
each group, if Grammy can’t pick out any message, output “Time to play Genshin Impact, Teacher
Rice!” in one line.
Example
standard input
standard output
6
1
biebie
1
adwlknafdoaihfawofd
3
ap
ql
biebie
2
pbpbpbpbpbpbpbpb
bbbbbbbbbbie
0
3
abie
bbie
cbie
biebie
Time to play Genshin Impact, Teacher Rice!
Time to play Genshin Impact, Teacher Rice!
bbbbbbbbbbie
Time to play Genshin Impact, Teacher Rice!
abie
bbie
cbie
Page 7 of 16The 2022 ICPC Asia Hangzhou Regional Programming Contest
Hangzhou Normal University, December, 04, 2022
 
 
 
 
 
 
 

Problem G. Subgraph Isomorphism

Input fifile:
standard input
Output fifile:
standard output
Time limit: 3 seconds
Memory limit: 1024 megabytes
Grammy wants to get the Turing Award! She decided to solve the Subgraph Isomorphism problem in
polynomial time.
Since the problem is indeed too hard, she begins with doing some simplififications and trying to solve the
simplifified problem fifirst.
Now Grammy has a connected undirected graph G with n vertices and m edges. She wants to know
whether it is possible to fifind a tree T with n vertices such that all connected subgraphs of G with n
vertices and n 1 edges are isomorphic to T. Grammy knows the answer for sure, but she wants to give
you a quiz.
Two graphs G and H are isomorphic if and only if there exists a bijection between the vertex sets of G
and H ( f : V ( G) V ( H)) such that any two vertices u and v of G are adjacent in G if and only if f( u)
and f( v) are adjacent in H.
Two vertices are adjacent if and only if they are directly connected by an edge.
Input
The input consists of multiple test cases.
The fifirst line contains an integer T (1 T 105 ), denoting the number of test cases.
For each test case, the fifirst line contains two integers n, m (1 n 105 , n 1 m 105 ), denoting the
number of vertices and the number of edges respectively.
Each of the next m lines contains two integers u i , v i (1 u i , v i n, u i
6
=
v i), denoting an edge ( u i , v i).
It is guaranteed that there are no multiple edges and the graph is connected.
It is guaranteed that the sum of n and the sum of m in all test cases will not exceed 106 .
Output
For each test case, output one line containing either “YES” or “NO”.
Page 8 of 16The 2022 ICPC Asia Hangzhou Regional Programming Contest
Hangzhou Normal University, December, 04, 2022
Example
standard input
standard output
4
7 6
1 2
2 3
3 4
4 5
5 6
3 7
3 3
1 2
2 3
3 1
5 5
1 2
2 3
3 4
4 1
1 5
1 0
YES
YES
NO
YES
Page 9 of 16The 2022 ICPC Asia Hangzhou Regional Programming Contest
Hangzhou Normal University, December, 04, 2022
 
 
 
 
 
 
 

Problem H. RPG Pro League

Input fifile:
standard input
Output fifile:
standard output
Time limit: 1 second
Memory limit: 1024 megabytes
The International Computer Playing Company (ICPC) is recently scheduling the annual RPG Pro League
(RPL). In the RPG game, there are three kinds of difffferent roles: Damager, Synergier, and Buffffer. A team
consists of exactly four players. Only the following two types of teams are allowed in RPL:
• One Damager, two Synergiers, and one Buffffer.
• Two Damagers, one Synergier, and one Buffffer.
Before the real competition, the ICPC decides to hold an exhibition game. There are n players, labeled
by 1 , 2 , . . . , n. The i-th player can only play roles in set S i , and the price to invite him to participate in
the exhibition game is p i dollars.
You are working for the ICPC. Your job is to select which players to invite such that they can make the
maximum number of valid teams, and the total cost is minimized. Note that a player can not join multiple
teams.
Unfortunately, the players may always adjust their prices. You will be given q events, in each event, the
price of a player will be changed. Your task is to report the current minimum total cost for maximizing
the valid teams after each event.
Input
The fifirst line contains a single integer n (1 n 105 ), denoting the number of players.
Each of the following n lines contains a string S i and an integer p i (1 ≤ | S i | ≤ 3, 1 p i 109 ), denoting
the role set and the price of the i-th player. S i consists of at most three difffferent characters in {’D’, ’S’,
’B’ }, denoting Damager, Synergier, and Buffffer, respectively.
The next line contains a single integer q (1 q 105 ), denoting the number of events.
Each of the following q lines contains two integers x i and y i (1 x i n, 1 y i 109 ), denoting the
price of the x i-th player is changed into y i dollars.
Output
Output q lines, the i-th (1 i q) of which contains an integer denoting the minimum total cost for
maximizing the valid teams after the i-th event.
Example
standard input
standard output
5
BS 3
D 3
B 2
D 4
D 5
2
5 2
1 5
10
12
Page 10 of 16The 2022 ICPC Asia Hangzhou Regional Programming Contest
Hangzhou Normal University, December, 04, 2022
 
 
 
 
 
 
 

Problem I. Guess Cycle Length

Input fifile:
standard input
Output fifile:
standard output
Time limit: 1 second
Memory limit: 1024 megabytes
This is an interactive problem.
Grammy has a directed cyclic graph of n vertices (1 n 109 ) numbered from 1 to n. A directed cyclic
graph is a directed graph of n vertices that form one cycle. Specififically, there are n vertices and n edges
in the graph, and there exists a permutation p1 , p2 , . . . , p n such that there is a one-way edge from p i to
p( i mod n)+1.
Initially, there is a token on a predetermined vertex.
You can ask Grammy to move the token in the following way:
“walk x” where 0 x 109 . In response to the query, Grammy will move the token through exactly x
edges and tell you the position of the token after moving.
You win if you guess the number of vertices in the hidden graph (number n) by making no more than 104
queries.
The vertices in the graph and the initial position of the token are fifixed in advance.
Interaction Protocol
You can make no more than 104 queries. To make a query, output “walk x” (0 x 109 ) on a separate
line, then you should read the response from standard input.
In response to the query, the interactor will move the token through exactly x edges and output the
position of the token after moving.
To give your answer, print “guess n” on a separate line, where n is the size of the hidden graph
(1 n 109 ). The output of the answer is not counted towards the limit of 104 queries.
After that, your program should terminate.
After printing a query, do not forget to output end of line and flflush the output. To do this, use
fflush(stdout) or cout.flush() in C++, System.out.flush() in Java, flush(output) in Pascal,
or stdout.flush() in Python.
It is guaranteed that the vertices in the graph and the initial position of the token are fifixed in advance.
Example
standard input
standard output
3
10
4
5
3
5
walk 0
walk 1
walk 2
walk 3
walk 4
walk 6
guess 10
Page 11 of 16The 2022 ICPC Asia Hangzhou Regional Programming Contest
Hangzhou Normal University, December, 04, 2022
 
 
 
 
 
 
 

Problem J. Painting

Input fifile:
standard input
Output fifile:
standard output
Time limit: 2 seconds
Memory limit: 1024 megabytes
Putata likes painting very much. He is now painting on a piece of white paper, which can be regarded
as a 2D plane. Initially, Putata drew a straight line x = W on the paper. In each of the next n steps,
Putata will draw a segment. He will start drawing the i-th segment from (0 , a i) to ( W, b i). If his pencil
touches any other segment drawn before, he will stop drawing at the point he touches other segments.
After drawing a segment, Putata may think the current fifigure is not so beautiful, and erase the segment
he just drew.
In this problem, your task is to report where each segment will end at.
Input
The fifirst line contains two integers n and W (1 n 3 × 105 , 1 W 106 ), denoting the number of
segments and the parameter W.
Each of the following n lines contains three integers a i , b i and c i (1 a i , b i 106 , 0 c i 1). Putata
will erase the i-th segment if and only if c i = 0. It is guaranteed that (0 , a i) will not coincide with other
segments.
Output
Output n lines, the k-th (1 k n) of which contains the coordinate ( u1 /v1 , u2 /v2) where the k-th
segment will end at. You should guarantee that gcd( u1 , v1) = gcd( u2 , v2) = 1.
Example
standard input
standard output
4 3
1 2 1
2 1 1
3 1 0
3 2 1
(3/1,2/1)
(3/2,3/2)
(2/1,5/3)
(3/1,2/1)
Page 12 of 16The 2022 ICPC Asia Hangzhou Regional Programming Contest
Hangzhou Normal University, December, 04, 2022
Problem K. Master of Both
Input fifile:
standard input
Output fifile:
standard output
Time limit: 1 second
Memory limit: 1024 megabytes
Professor Hui-Bot is the master of string theory and advanced data structures, so he came up with an
interesting problem. Given a sequence of n strings consisting of only lowercase English letters, how many
inversions are there in this sequence when the strings are compared by lexicographical order?
As the most extraordinary student of Hui-Bot, Putata and Budada mastered superb string theory and
advanced data structure skills respectively, and they solved this problem together with ease. However,
there are q difffferent parallel universes, where the characters in the alphabet are not appearing in the
original order.
Formally, the alphabet in each universe is a string, which is a permutation of the 26 lowercase English
letter, denoting the order each character appears.
A string a is lexicographically smaller than a string b if and only if one of the following holds:
a is a prefifix of b, but a
6
=
b;
• in the fifirst position where a and b diffffer, the string a has a letter that appears earlier in the alphabet
than the corresponding letter in b.
The number of inversions in a sequence a of length n is the number of ordered pairs ( i, j) such that
1 i < j n, a j < a i .
Please help Putata and Budada in each universe to solve the problem.
Input
The fifirst line of the input contains two integers n, q (1 n 5 × 105 , 1 q 5 × 104 ), denoting the
length of the sequence.
For the following n lines, the i-th line contains a string s i (1 ≤ | s i | ≤ 106 ). It is guaranteed that the string
consists of only lowercase English letters, and
n
P
i=1
| s i | ≤ 106 .
For the following q lines, each line contains a string t, denoting the alphabet in one universe. It is
guaranteed that t is a permutation of 26 lowercase English letters.
Output
Output q lines, denoting the answer in q universes.
Example
standard input
standard output
5 3
aac
oiputata
aaa
suikabudada
aba
abcdefghijklmnopqrstuvwxyz
qwertyuiopasdfghjklzxcvbnm
aquickbrownfxjmpsvethlzydg
4
3
4
Page 13 of 16The 2022 ICPC Asia Hangzhou Regional Programming Contest
Hangzhou Normal University, December, 04, 2022
 
 
 
 
 

Problem L. Levenshtein Distance

Input fifile:
standard input
Output fifile:
standard output
Time limit: 4 seconds
Memory limit: 1024 megabytes
The Levenshtein Distance between two strings is the smallest number of simple one-letter operations
needed to change one string to the other. The operations are:
• Adding a letter anywhere in the string.
• Removing a letter from anywhere in the string.
• Changing any letter in the string to any other letter.
You will be given a number k and two strings S and T. Your task is to fifind the number of non-empty
substrings of T whose Levenshtein Distance between S is exactly i for every possible non-negative integer
i (0 i k). Two substrings are considered difffferent if and only if they occur in difffferent places.
Input
The fifirst line contains a single integer k (0 k 30), denoting the parameter k.
The second line contains a string S (1 ≤ | S | ≤ 105 ), denoting the pattern string.
The third line contains a string T (1 ≤ | T | ≤ 105 ), denoting the text string.
It is guaranteed that the input strings only consist of lowercase English letters (’a’ to ’z’), uppercase
English letters (’A’ to ’Z’), and digits (’0’ to ’9’).
Output
Output k+ 1 lines, the i-th (1 i k+ 1) of which contains an integer denoting the number of substrings
of T whose Levenshtein Distance between S is exactly i 1.
Example
standard input
standard output
4
aaa
aabbaab
0
5
15
7
1
Page 14 of 16The 2022 ICPC Asia Hangzhou Regional Programming Contest
Hangzhou Normal University, December, 04, 2022
 
 
 
 
 
 
 

Problem M. Please Save Pigeland

Input fifile:
standard input
Output fifile:
standard output
Time limit: 3 seconds
Memory limit: 1024 megabytes
Some horrible disease called Mysterious Oscar is spreading in Pigeland. The Pigeland has n cities and is
connected by n 1 bi-directional roads. The i-th road is connecting city u i and city v i , with length w i . It
is guaranteed that for every city it is possible to travel to any other city using these roads.
Now, there are k distinct cities c1 , c2 , . . . , c k having the horrible disease. As the leader of the Pigeland,
Putata and Budada are going to save the Pigeland. First they will fifind a city r to build up a hospital,
without considering whether city r is infected by the disease. Then, they will use the rest of their money
to build the only vehicle which could travel in Pigeland, the Pigpigcar. Because they are strapped for
cash, they can only build one Pigpigcar, and once a Pigpigcar is built, some parameter d of the Pigpigcar
is set, and could not be changed. The Pigpigcar having parameter d can only travel from one city to
the other, where the distance between the two cities should be a multiple of d. Formally, if you want to
travel from city u to city v, the distance of the shortest path between u, v should be p × d, where p is a
non-negative integer, and this would cost p Pigecoins. Please notice that if you want to travel from city
u to city v, it is not necessary to stop at every city on the path from u to v, the Pigpigcar can directly
go from u to v, if the minimum distance between u and v is a multiple of d.
For the following k days, Putata and Budada will take the following actions to save the Pigeland. On the
i-th day, they will travel to city c i from city r along the shortest path between city r and city c i using
the Pigpigcar, cure all the piggies in the city and then travel back to city r from city c i .
Putata and Budada want you to choose the proper city r to build the hospital, and the parameter d of
the Pigpigcar they should build, so that the Pigecoins spent during the travel is minimized. Please help
them to fifind the minimum number of Pigecoins spent.
Input
The fifirst line contains two integers n, k (1 n 5 × 105 , 1 k n), denoting the number of cities and
the number of cities having disease.
The second line contains k distinct integers c1 , c2 , . . . , c k (1 c i n), denoting the cities having disease.
For the following n 1 lines, each line contains three integers u, v, w (1 u, v n, u
6
=
v, 1 w 107 ),
denoting a road connecting city u and v with length w.
It is guaranteed that you can go from any city to any other city using these roads.
Output
Output one integer in one line, denoting the minimum number of Pigecoins spent.
Example
standard input
standard output
5 3
3 4 5
1 2 2
2 3 4
2 5 4
3 4 6
8
Note
In the sample, you should choose city 1 to build hospital and build a Pigpigcar with parameter 6, the
Page 15 of 16The 2022 ICPC Asia Hangzhou Regional Programming Contest
Hangzhou Normal University, December, 04, 2022
distance between city 1 and city 3 , 4 , 5 is 6 , 12 , 6, so the total Pigcoins costed is 1 × 2 + 2 × 2 + 1 × 2 = 8.
Page 16 of 16

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值