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

AtCoder Grand Contest 036

This document describes 4 problems related to graphs, sequences, and geometry from the AtCoder Grand Contest 036. The problems involve finding combinations of integers that satisfy triangle area constraints, removing duplicate elements from a sequence, counting possible outcomes of operations on an integer sequence, and finding the minimum cost of removing edges from a graph to eliminate negative cycles.

Uploaded by

alpha
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)
119 views

AtCoder Grand Contest 036

This document describes 4 problems related to graphs, sequences, and geometry from the AtCoder Grand Contest 036. The problems involve finding combinations of integers that satisfy triangle area constraints, removing duplicate elements from a sequence, counting possible outcomes of operations on an integer sequence, and finding the minimum cost of removing edges from a graph to eliminate negative cycles.

Uploaded by

alpha
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/ 11

AtCoder Grand Contest 036 https://atcoder.

jp/contests/agc036/tasks_print

A - Triangle

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 400 points

Problem Statement
Given is an integer S . Find a combination of six integers X1 , Y1 , X2 , Y2 , X3 , and Y3 that satisfies all of the
following conditions:

0 ≤ X1 , Y1 , X2 , Y2 , X3 , Y3 ≤ 109
The area of the triangle in a two-dimensional plane whose vertices are (X1 , Y1 ), (X2 , Y2 ), and
(X3 , Y3 ) is S/2.
We can prove that there always exist six integers that satisfy the conditions under the constraints of this
problem.

Constraints
1 ≤ S ≤ 1018
All values in input are integers.

Input
Input is given from Standard Input in the following format:

Output
Print six integers X1 , Y1 , X2 , Y2 , X3 , and Y3 that satisfy the conditions, in this order, with spaces in
between. If multiple solutions exist, any of them will be accepted.

Sample Input 1
3

Sample Output 1
1 0 2 2 0 1

The area of the triangle in a two-dimensional plane whose vertices are (1, 0), (2, 2), and (0, 1) is 3/2.
Printing ' 3 0 3 1 0 1 ' or ' 1 0 0 1 2 2 ' will also be accepted.

1 of 11 21/07/19, 20.57
AtCoder Grand Contest 036 https://atcoder.jp/contests/agc036/tasks_print

Sample Input 2
100

Sample Output 2
0 0 10 0 0 10

Sample Input 3
311114770564041497

Sample Output 3
314159265 358979323 846264338 327950288 419716939 937510582

B - Do Not Duplicate

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 700 points

Problem Statement
We have a sequence of N × K integers: X = (X0 , X1 , ⋯ , XN×K−1 ). Its elements are represented by
another sequence of N integers: A = (A0 , A1 , ⋯ , AN−1 ). For each pair i, j (
0 ≤ i ≤ K − 1,  0 ≤ j ≤ N − 1), Xi×N+j = Aj holds.

Snuke has an integer sequence s, which is initially empty. For each i = 0, 1, 2, ⋯ , N × K − 1, in this
order, he will perform the following operation:

If s does not contain Xi : add Xi to the end of s.


If s does contain Xi : repeatedly delete the element at the end of s until s no longer contains Xi . Note
that, in this case, we do not add Xi to the end of s.

Find the elements of s after Snuke finished the operations.

Constraints
1 ≤ N ≤ 2 × 105
1 ≤ K ≤ 1012
1 ≤ Ai ≤ 2 × 105
All values in input are integers.

2 of 11 21/07/19, 20.57
AtCoder Grand Contest 036 https://atcoder.jp/contests/agc036/tasks_print

Input
Input is given from Standard Input in the following format:

N K
A0 A1 ⋯ AN−1

Output
Print the elements of s after Snuke finished the operations, in order from beginning to end, with spaces in
between.

Sample Input 1
3 2
1 2 3

Sample Output 1
2 3

In this case, X = (1, 2, 3, 1, 2, 3). We will perform the operations as follows:

i = 0: s does not contain 1, so we add 1 to the end of s, resulting in s = (1).


i = 1: s does not contain 2, so we add 2 to the end of s, resulting in s = (1, 2).
i = 2: s does not contain 3, so we add 3 to the end of s, resulting in s = (1, 2, 3).
i = 3: s does contain 1, so we repeatedly delete the element at the end of s as long as s contains 1,
which causes the following changes to s: (1, 2, 3) → (1, 2) → (1) → ().
i = 4: s does not contain 2, so we add 2 to the end of s, resulting in s = (2).
i = 5: s does not contain 3, so we add 3 to the end of s, resulting in s = (2, 3).

Sample Input 2
5 10
1 2 3 2 3

Sample Output 2
3

3 of 11 21/07/19, 20.57
AtCoder Grand Contest 036 https://atcoder.jp/contests/agc036/tasks_print

Sample Input 3
6 1000000000000
1 1 2 2 3 3

Sample Output 3

s may be empty in the end.

Sample Input 4
11 97
3 1 4 1 5 9 2 6 5 3 5

Sample Output 4
9 2 6

C - GP 2

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 900 points

Problem Statement
We have a sequence of N integers: x = (x0 , x1 , ⋯ , xN−1 ). Initially, xi = 0 for each i (0 ≤ i ≤ N − 1).

Snuke will perform the following operation exactly M times:

Choose two distinct indices i, j (0 ≤ i, j ≤ N − 1,  i ≠ j). Then, replace xi with xi + 2 and xj with
x j + 1.

Find the number of different sequences that can result after M operations. Since it can be enormous,
compute the count modulo 998244353.

Constraints
2 ≤ N ≤ 106
1 ≤ M ≤ 5 × 105
All values in input are integers.

4 of 11 21/07/19, 20.57
AtCoder Grand Contest 036 https://atcoder.jp/contests/agc036/tasks_print

Input
Input is given from Standard Input in the following format:

N M

Output
Print the number of different sequences that can result after M operations, modulo 998244353.

Sample Input 1
2 2

Sample Output 1
3

After two operations, there are three possible outcomes:

x = (2, 4)
x = (3, 3)
x = (4, 2)
For example, x = (3, 3) can result after the following sequence of operations:

First, choose i = 0, j = 1, changing x from (0, 0) to (2, 1).


Second, choose i = 1, j = 0, changing x from (2, 1) to (3, 3).

Sample Input 2
3 2

Sample Output 2
19

Sample Input 3
10 10

Sample Output 3
211428932

5 of 11 21/07/19, 20.57
AtCoder Grand Contest 036 https://atcoder.jp/contests/agc036/tasks_print

Sample Input 4
100000 50000

Sample Output 4
3463133

D - Negative Cycle

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 1200 points

Problem Statement
We have a weighted directed graph with N vertices numbered 0 to N − 1.

The graph initially has N − 1 edges. The i-th edge (0 ≤ i ≤ N − 2) is directed from Vertex i to Vertex
i + 1 and has a weight of 0.

Snuke will now add a new edge (i → j) for every pair i, j (0 ≤ i, j ≤ N − 1,  i ≠ j). The weight of the edge
will be −1 if i < j, and 1 otherwise.

Ringo is a boy. A negative cycle (a cycle whose total weight is negative) in a graph makes him sad. He will
delete some of the edges added by Snuke so that the graph will no longer contain a negative cycle. The cost
of deleting the edge (i → j) is Ai,j . He cannot delete edges that have been present from the beginning.

Find the minimum total cost required to achieve Ringo's objective.

Constraints
3 ≤ N ≤ 500
1 ≤ Ai,j ≤ 109
All values in input are integers.

6 of 11 21/07/19, 20.57
AtCoder Grand Contest 036 https://atcoder.jp/contests/agc036/tasks_print

Input
Input is given from Standard Input in the following format:

N
A0,1 A0,2 A0,3 ⋯ A0,N−1
A1,0 A1,2 A1,3 ⋯ A1,N−1
A2,0 A2,1 A2,3 ⋯ A2,N−1

AN−1,0 AN−1,1 AN−1,2 ⋯ AN−1,N−2

Output
Print the minimum total cost required to achieve Ringo's objective.

Sample Input 1
3
2 1
1 4
3 3

Sample Output 1
2

If we delete the edge (0 → 1) added by Snuke, the graph will no longer contain a negative cycle. The cost
will be 2 in this case, which is the minimum possible.

Sample Input 2
4
1 1 1
1 1 1
1 1 1
1 1 1

Sample Output 2
2

If we delete the edges (1 → 2) and (3 → 0) added by Snuke, the graph will no longer contain a negative
cycle. The cost will be 1 + 1 = 2 in this case, which is the minimum possible.

7 of 11 21/07/19, 20.57
AtCoder Grand Contest 036 https://atcoder.jp/contests/agc036/tasks_print

Sample Input 3
10
190587 2038070 142162180 88207341 215145790 38 2 5 20
32047998 21426 4177178 52 734621629 2596 102224223 5 1864
41 481241221 1518272 51 772 146 8805349 3243297 449
918151 126080576 5186563 46354 6646 491776 5750138 2897 161
3656 7551068 2919714 43035419 495 3408 26 3317 2698
455357 3 12 1857 5459 7870 4123856 2402 258
3 25700 16191 102120 971821039 52375 40449 20548149 16186673
2 16 130300357 18 6574485 29175 179 1693 2681
99 833 131 2 414045824 57357 56 302669472 95
8408 7 1266941 60620177 129747 41382505 38966 187 5151064

Sample Output 3
2280211

E - ABC String

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 1500 points

Problem Statement
Given is a string S consisting of ' A ',' B ', and ' C '.

Consider the (not necessarily contiguous) subsequences x of S that satisfy all of the following conditions:

' A ', ' B ', and ' C ' all occur the same number of times in x.
No two adjacent characters in x are the same.

Among these subsequences, find one of the longest. Here a subsequence of S is a string obtained by deleting
zero or more characters from S .

Constraints
1 ≤ |S| ≤ 106
S consists of ' A ',' B ', and ' C '.

Input
Input is given from Standard Input in the following format:

8 of 11 21/07/19, 20.57
AtCoder Grand Contest 036 https://atcoder.jp/contests/agc036/tasks_print

Output
Print one longest subsequence that satisfies the conditions. If multiple solutions exist, any of them will be
accepted.

Sample Input 1
ABBCBCAB

Sample Output 1
ACBCAB

Consider the subsequence ' ACBCAB ' of S . It satisfies the conditions and is one of the longest with these
properties, along with ' ABCBCA '. On the other hand, the subsequences ' ABCBCAB ' and ' ABBCCA ' do not
satisfy the conditions.

Sample Input 2
ABABABABACACACAC

Sample Output 2
BABCAC

Sample Input 3
ABCABACBCBABABACBCBCBCBCBCAB

Sample Output 3
ACABACABABACBCBCBCBCA

Sample Input 4
AAA

9 of 11 21/07/19, 20.57
AtCoder Grand Contest 036 https://atcoder.jp/contests/agc036/tasks_print

Sample Output 4

It is possible that only the empty string satisfies the condition.

F - Square Constraints

Time Limit: 4 sec / Memory Limit: 1024 MB

Score : 1800 points

Problem Statement
Given is an integer N . How many permutations (P0 , P1 , ⋯ , P2N−1 ) of (0, 1, ⋯ , 2N − 1) satisfy the
following condition?

For each i (0 ≤ i ≤ 2N − 1), N 2 ≤ i2 + Pi2 ≤ (2N)2 holds.

Since the number can be enormous, compute it modulo M .

Constraints
1 ≤ N ≤ 250
2 ≤ M ≤ 109
All values in input are integers.

Input
Input is given from Standard Input in the following format:

N M

Output
Print the number of permutations that satisfy the condition, modulo M .

Sample Input 1
2 998244353

10 of 11 21/07/19, 20.57
AtCoder Grand Contest 036 https://atcoder.jp/contests/agc036/tasks_print

Sample Output 1
4

Four permutations satisfy the condition:

(2, 3, 0, 1)
(2, 3, 1, 0)
(3, 2, 0, 1)
(3, 2, 1, 0)

Sample Input 2
10 998244353

Sample Output 2
53999264

Sample Input 3
200 998244353

Sample Output 3
112633322

11 of 11 21/07/19, 20.57

You might also like