版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
title: 题解 - Japanese Student Championship 2021 categories:
题号1 | 标题 | 做法 |
---|---|---|
A | Competition | 签到 |
B | Xor of Sequences | 签到 |
C | Max GCD 2 | 签到, 枚举 |
D | Nowhere $P$ | 签到, 找规律 |
*E | Level K Palindrome | |
*F | Max Matrix | 线段树 / 平衡树 |
G | Spanning Tree | 并查集 + 矩阵树定理 |
*H | Shipping |
Time Limit: 2 sec / Memory Limit: 1024 MB
Score: 100 points
A Supermarket Takahashi sells an $X$-gram beef pack for $Y$ yen
Another Supermarket Snuke has decided to sell a beef pack at a lower price per gram
In Snuke, one beef pack weighs $Z$ grams. What is the greatest possible price (a non-negative integer) for Snuke's beef pack such that it is strictly cheaper than Takahashi's beef pack per gram?
Input is given from Standard Input in the following format:
$X\ Y\ Z$
Print the answer
100 200 100
199
Both stores sell $100$-gram packs, so Snuke can just make it one yen cheaper than that in Takahashi
103 971 593
5590
Takahashi sells beef for $\frac{971}{103}=9.4271...$ yen per gram. Snuke can sell $593$ grams of beef for $5590$ yen to make it $\frac{5590}{593}=9.4266...$ yen per gram
1000 1 1
0
The price is allowed to be $0$ yen
$\lfloor\frac{yz}{x}\rfloor-[x\mid yz]$
Time Limit: 2 sec / Memory Limit: 1024 MB
Score: 200 points
We have two strictly increasing integer sequences $A=(A_1,A_2,...,A_N)$ and $B=(B_1,B_2,...,B_M)$
Find all integers that appear in exactly one of $A$ and $B$ and print them in ascending order
Input is given from Standard Input in the following format:
$N\ M$
$A_1\ A_2\ ...\ A_N$
$B_1\ B_2\ ...\ B_M$
Print all integers that appear in exactly one of $A$ and $B$
in ascending order, with space as separator
2 2
1 2
1 3
2 3
$1$ is contained in both $A$ and$B$
$2$ is contained in only $A$
$3$ is contained in only $B$
Thus, we should print $2$ and $3$
4 4
1 2 3 4
1 2 3 4
You can print an empty line or nothing
给两串严格递增的序列, 求这两个序列的对称差
随便做
Time Limit: 2 sec / Memory Limit: 1024 MB
Score: 300 points
Given are integers $A$ and $B$. Find the maximum possible value of $\gcd(x,y)$ when we choose integers x and y so that $A\leqslant x<y\leqslant B$
Here, $\gcd(x,y)$ denotes the greatest common divisor of $x$ and $y$
Input is given from Standard Input in the following format:
$A\ B$
Print the answer
2 4
2
We have three ways to choose $(x,y)$ such that $A\leqslant x<y\leqslant B$: $(2,3),(2,4),(3,4)$, where the greatest common divisors are $1,2,1$, respectively, so the maximum possible value is $2$
199999 200000
1
We have $\gcd(199999,200000)=1$
101 139
34
给定 $A,B$, 求 $\displaystyle\max_{A\leqslant x<y\leqslant B}(x,y)$
直接暴力枚举即可
Time Limit: 2 sec / Memory Limit: 1024 MB
Score: 400 points
You are given a prime number $P$ not less than $2$, which you don't like
Let's call an array of integers $A_1,A_2,...,A_N$ very good if it satisfies the following condition:
Consider all $(P-1)^N$ arrays of length $N$ with elements from $1$ to $P-1$. How many of them are very good?
As this number can be very big, output it modulo $10^9+7$
Input is given from Standard Input in the following format:
$N\ P$
Print the count modulo $10^9+7$
3 3
2
Two arrays, $(1,1,2)$ and $(2,2,1)$, satisfy the condition
3 2
0
45108 2571593
224219544
给定质数 $P$, 求有多少序列 $(A_1,A_2,\dots,A_N)$ 满足:
$$ \forall i\in[1,n]{\mathbb{N}},~\sum{j=1}^iA_j{\equiv}\llap{/\,}0\pmod P $$
显然, 当 $n=1$ 时答案为 $p-1$, 对应合法序列即为 $(1),(2),...,(p-1)$
之后在这些合法序列后插入新数时, 每个序列都有且仅有一个数使得这个数插入后该序列非法 (该数即为 $(-\sum_{i}a_i)\bmod p$)
故答案为 $(p-1)(p-2)^{n-1}$
Time Limit: 2 sec / Memory Limit: 1024 MB
Score: 500 points
As a token of his gratitude, Takahashi has decided to give Snuke a level-$K$ palindrome. A level-$L$ palindrome, where $L$ is a non-negative integer, is defined as follows:
Now, Takahashi has a string $S$. Determine whether it is possible to make $S$ an exactly level-$K$ palindrome by doing the following action zero or more times: choose a character in $S$ and change it to another lowercase English letter. If it is possible, find the minimum number of changes needed to make $S$ a level-$K$ palindrome
Input is given from Standard Input in the following format:
$K\ S$
If it is possible to get an exactly level-$K$ palindrome, print the minimum number of changes needed. If it is impossible, print impossible
4
aabaaaabaa
0
We can find the level of aabaaaabaa
as follows:
a
is a concatenation of (empty string), a
, (empty string) in this order, so it is a level-$1$ palindromeaa
is a concatenation of a, a in this order, so it is a level-$2$ palindromeaabaa
is a concatenation of aa
, b
, aa
in this order, so it is a level-$3$ palindromeaabaaaabaa
is a concatenation of aabaa
, aabaa
in this order, so it is a level-$4$ palindromeThus, aabaaaabaa
is already a level-$4$ palindrome and needs no changes
2
aabaaaabaa
4
We can, for example, change aabaaaabaa
to acbcaacbca
to get a level-$2$ palindrome
Note that aabaaaabaa
is not a level-$2$ palindrome
3
aabaaaabaa
impossible
5
aabaaaabaa
impossible
2
acaabcbababaaac
6
本题所有的字符串均指只由小写英文字母构成的字符串
对字符串 $s$,
定义 $k$ 阶回文串如下:
给一字符串 $s$, 问至少经几次变换可使其恰好为 $k$ 阶回文串
显然, 若有解则 $k$ 不可能过大
Time Limit: 3 sec / Memory Limit: 1024 MB
Score: 600 points
We have a sequence a of length $N$ and a sequence $b$ of length $M$. Initially, every element in $a$ and $b$ is $0$
You are asked to process $Q$ queries. In the $i$-th query, given three integers $T_i$, $X_i$, and $Y_i$, do the following:
Then, after processing each query, print the value $\displaystyle\sum{i=1}^N\sum{j=1}^M\max(a_i,b_j)$
Input is given from Standard Input in the following format:
$N\ M\ Q$
$T_1\ X_1\ Y_1$
$T_2\ X_2\ Y_2$
$T_3\ X_3\ Y_3$
$\vdots$
$T_Q\ X_Q\ Y_Q$
Print $Q$ integers as instructed in Problem Statement, with newline as separator
2 2 4
1 1 10
2 1 20
2 2 5
1 1 30
20
50
55
85
If we write $\max(a_i,b_j)$ at the $i$-th row and $j$-th column in a grid, the four queries will change it as follows:
3 3 5
1 3 10
2 1 7
1 3 5
2 2 10
2 1 1
30
44
31
56
42
200000 200000 4
2 112219 100000000
1 73821 100000000
2 26402 100000000
1 73821 100000000
20000000000000
39999900000000
59999800000000
59999800000000
The integers to be printed may not fit into a $32$-bit integer type
有一个长为 $n$ 的全零序列 $a$ 和长为 $m$ 的全零序列 $b$, 对其做如下操作
这两种操作一共进行 $Q$ 次, 要求每次操作后都要输出 $\displaystyle\sum{i=1}^n\sum{j=1}^M\max{a_i,b_j}$
Time Limit: 2 sec / Memory Limit: 1024 MB
Score: 600 points
We have a graph with $N$ vertices numbered $1,2,...,N$. Initially, it has no edges
Now, let us add some number of undirected edges to $G$ so that the following condition holds for any $i,j(i\ne j)$
after addition
Among the graphs that can be $G$ after addition, how many are trees?
Since the count can be enormous, find it modulo $10^9+7$
Input is given from Standard Input in the following format:
$N$
$A{1,1}\ ...\ A{1,N}$
$\vdots$
$A{N,1}\ ...\ A{N,N}$
Print the count modulo $10^9+7$
4
0 1 -1 0
1 0 -1 -1
-1 -1 0 0
0 -1 0 0
2
We need an edge between Vertex $1$ and Vertex $2$, and we must not add an edge between Vertex $1$ and Vertex $4$ or between Vertex $3$ and Vertex $4$
Thus, we have the following two valid graphs:
3
0 1 1
1 0 1
1 1 0
0
3
0 0 0
0 0 0
0 0 0
0
11
0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0
357947677
When we distinguish the vertices, there are $11^9$ trees with $11$ vertices
有 $n$ 个点, 考虑以这 $n$ 个点为顶点, 满足如下条件的所有图:
求这些图中树的个数
首先, 考虑所以已经存在的边构成的图, 如果有环了, 则答案一定为 $0$, 否则森林中的每个树都可缩成一个点, 之后用矩阵树定理即可
Time Limit: 5 sec / Memory Limit: 1024 MB
Score: 600 points
In the Republic of AtCoder, there are $N$ cities called City $1$ through City $N$ and $N$ canals called Canal $1$ through Canal $N$
Canal $i$ connects City $i$ and City $A_i$ bidirectionally, and you have to pay the toll of $C_i$
yen to go through it, but after paying the toll once, you can use it any number of times in any direction
It is guaranteed that you can reach from any city to any city using some canals
You are asked to deliver $M$ cargoes in this country. The $i$-th cargo should be delivered from City $X_i$ to City $Y_i$
There is no way other than using the canals to deliver the cargoes, but you yourself can travel between the cities freely without using the canals
Find the minimum total toll you have to pay to deliver all $M$ cargoes
Input is given from Standard Input in the following format:
$N\ M$
$A_1\ C_1$
$A_2\ C_2$
$A_3\ C_3$
$\vdots$
$A_N\ C_N$
$X_1\ Y_1$
$X_2\ Y_2$
$X_3\ Y_3$
$\vdots$
$X_M\ Y_M$
Print the minimum total toll you have to pay, as an integer
4 2
3 3
1 7
2 5
1 2
4 3
2 1
10
The figure below shows the cities and canals in this country, where numbers along the lines representing canals represent the tolls:
You can deliver the cargoes as follows to make the total toll $10$ yen:
5 2
2 2
5 5
5 7
2 4
3 10
3 5
4 1
13
Multiple canals may connect the same pair of cities
11 4
8 1
9 9
8 10
8 3
1 2
11 3
9 2
6 5
3 4
1 7
3 2
7 8
10 1
4 9
11 6
26
给一个带权无向图, 求满足如下条件的子图的最小边权和
打*的是还没写的题↩