0% found this document useful (0 votes)
8 views

2023 HZCUPC Tutorial

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

2023 HZCUPC Tutorial

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

A. B. C. D. E. F. G. . H. I. J. . . . K. L. M.

END
. . . . . . .. . . .... . . . ..

The 20th HangZhou City University Programing


Contest - Solution

HZCU ACM Group

HangZhou City University

2023.04.01

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .

HZCU ACM Group HangZhou City University


The 20th HangZhou City University Programing Contest - Solution 1 / 20
A. B. C. D. E. F. G. . H. I. J. . . . K. L. M. END
. . . . . . .. . . .... . . . ..

Easy: A B M
Easy - Medium: C D F L
Medium - Hard: E H I J
Hard: K G

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .

HZCU ACM Group HangZhou City University


The 20th HangZhou City University Programing Contest - Solution 2 / 20
A. B. C. D. E. F. G. . H. I. J. . . . K. L. M. END
. . . . . . .. . . .... . . . ..

A - Zawei The Rock

O(1)

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .

HZCU ACM Group HangZhou City University


The 20th HangZhou City University Programing Contest - Solution 3 / 20
A. B. C. D. E. F. G. . H. I. J. . . . K. L. M. END
. . . . . . .. . . .... . . . ..

B - Emoji Master BSQ

O(n)

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .

HZCU ACM Group HangZhou City University


The 20th HangZhou City University Programing Contest - Solution 4 / 20
A. B. C. D. E. F. G. . H. I. J. . . . K. L. M. END
. . . . . . .. . . .... . . . ..

C - Genshin Master

5 min
( 108 char
)
O(n log(n))

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .

HZCU ACM Group HangZhou City University


The 20th HangZhou City University Programing Contest - Solution 5 / 20
A. B. C. D. E. F. G. . H. I. J. . . . K. L. M. END
. . . . . . .. . . .... . . . ..

D - Add 9 Zeros

ai = aj + 9 i, j
size ⌈ size
2 ⌉

O(n log(n))

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .

HZCU ACM Group HangZhou City University


The 20th HangZhou City University Programing Contest - Solution 6 / 20
A. B. C. D. E. F. G. . H. I. J. . . . K. L. M. END
. . . . . . .. . . .... . . . ..

E - XOR on Tree

+ 01trie 01trie

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .

HZCU ACM Group HangZhou City University


The 20th HangZhou City University Programing Contest - Solution 7 / 20
A. B. C. D. E. F. G. . H. I. J. . . . K. L. M. END
. . . . . . .. . . .... . . . ..

E - XOR on Tree

+ 01trie 01trie
S x
x

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .

HZCU ACM Group HangZhou City University


The 20th HangZhou City University Programing Contest - Solution 7 / 20
A. B. C. D. E. F. G. . H. I. J. . . . K. L. M. END
. . . . . . .. . . .... . . . ..

E - XOR on Tree

+ 01trie 01trie
S x
x

v
insert
TLE

dfs
dfs
O(n log(n) log(A)) O(n log(A)), A

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .

HZCU ACM Group HangZhou City University


The 20th HangZhou City University Programing Contest - Solution 7 / 20
A. B. C. D. E. F. G. . H. I. J. . . . K. L. M. END
. . . . . . .. . . .... . . . ..

F - Crazy Thursday, V me 50!

n ≤ 8, DFS
std::next_permutation
O(n!)

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .

HZCU ACM Group HangZhou City University


The 20th HangZhou City University Programing Contest - Solution 8 / 20
A. B. C. D. E. F. G. . H. I. J. . . . K. L. M. END
. . . . . . .. . . .... . . . ..

G - Domino

1.Ai Bi
2.Ai
3.
1 2
Ai
K 2 Bi L
Ai 1 N −K

1 1 Bi + 2
Ai
O(n log(n))
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .

HZCU ACM Group HangZhou City University


The 20th HangZhou City University Programing Contest - Solution 9 / 20
A. B. C. D. E. F. G. . H. I. J. . . . K. L. M. END
. . . . . . .. . . .... . . . ..

G - Domino

Bi i
L Ai + Bi K −L Ai

1
i 1
Aj Ak
j Aj
Bj >= Bi i Aj <= Ai
Aj + Bj Ai i
1 A i
1
O(n log(n))

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .

HZCU ACM Group HangZhou City University


The 20th HangZhou City University Programing Contest - Solution 10 / 20
A. B. C. D. E. F. G. . H. I. J. . . . K. L. M. END
. . . . . . .. . . .... . . . ..

H - Maze

q = max (q, 2 ∗ p), 2

i j (i + j) mod 2 1

V ≤ n ∗ n, E ≤ 4 ∗ V, TLE
√ Dinic Hopcroft
O(E V )
: O(n3 )

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .

HZCU ACM Group HangZhou City University


The 20th HangZhou City University Programing Contest - Solution 11 / 20
A. B. C. D. E. F. G. . H. I. J. . . . K. L. M. END
. . . . . . .. . . .... . . . ..

I - Magic Tree

1
depth

1 depthx depthn+i x
depth 1

2 : x depth 1 x
1
3
O(n log(n))

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .

HZCU ACM Group HangZhou City University


The 20th HangZhou City University Programing Contest - Solution 12 / 20
A. B. C. D. E. F. G. . H. I. J. . . . K. L. M. END
. . . . . . .. . . .... . . . ..

J - Disjoint-Set-Union Sum

998244353 O(n)

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .

HZCU ACM Group HangZhou City University


The 20th HangZhou City University Programing Contest - Solution 13 / 20
A. B. C. D. E. F. G. . H. I. J. . . . K. L. M. END
. . . . . . .. . . .... . . . ..

J - Disjoint-Set-Union Sum

merge i i +1
merge

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .

HZCU ACM Group HangZhou City University


The 20th HangZhou City University Programing Contest - Solution 14 / 20
A. B. C. D. E. F. G. . H. I. J. . . . K. L. M. END
. . . . . . .. . . .... . . . ..

J - Disjoint-Set-Union Sum O(n3 )


dp dp[l][r ] [l, r ] ans
[l, r ]
[l, r ]
[l, m] [m + 1, r ]
L=m−l R =r −m−1

dp[l][r ] (L+R )
L
,
[l, r ]
dp[l][r ]+ = ( ) ∑
(dp[l][m] ∗ R! + dp[m + 1][r ] ∗ L!) ∗ L+R
L + ( rl ai ) ∗ (L + R)!

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .

HZCU ACM Group HangZhou City University


The 20th HangZhou City University Programing Contest - Solution 15 / 20
A. B. C. D. E. F. G. . H. I. J. . . . K. L. M. END
. . . . . . .. . . .... . . . ..

J - Disjoint-Set-Union Sum O(n)

ans
(i, i + 1)
i +1

(i, i + 1)
(n−1)! (n−1)!
x x! = x ai
(x −1)!
ans
O(n2 ),
O(n)

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .

HZCU ACM Group HangZhou City University


The 20th HangZhou City University Programing Contest - Solution 16 / 20
A. B. C. D. E. F. G. . H. I. J. . . . K. L. M. END
. . . . . . .. . . .... . . . ..

K - Equal Difference Prime

π(n) n , π(106 ) = 79498


O(π 2 (n)) c, d

n=i ansi , O(π 2 (n)) ans

i ≡ 0 (mod 500) ansi (2000


10 200 )
i = ⌊ 500
n
⌋ × 500, d ≤i ansi
i < d ≤ n, d 500 (
100 )
c, d
O(π 2 (n)), O(π(n) × 100)

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .

HZCU ACM Group HangZhou City University


The 20th HangZhou City University Programing Contest - Solution 17 / 20
A. B. C. D. E. F. G. . H. I. J. . . . K. L. M. END
. . . . . . .. . . .... . . . ..

L - Auto Chess

( )
45
: O(n log(n))

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .

HZCU ACM Group HangZhou City University


The 20th HangZhou City University Programing Contest - Solution 18 / 20
A. B. C. D. E. F. G. . H. I. J. . . . K. L. M. END
. . . . . . .. . . .... . . . ..

M - Jiubei and Construction

distinct)
⌈ n2 ⌉ − 1
{x , −x }(|x | > k) k, n 0
: O(n)

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .

HZCU ACM Group HangZhou City University


The 20th HangZhou City University Programing Contest - Solution 19 / 20
A. B. C. D. E. F. G. . H. I. J. . . . K. L. M. END
. . . . . . .. . . .... . . . ..

END

END

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .

HZCU ACM Group HangZhou City University


The 20th HangZhou City University Programing Contest - Solution 20 / 20

You might also like