Atcoder Acing Programming Contest Python

Summary

It was difficult. It was A, B, C 3 questions AC. I don't know the binary number well, so D skips the moment I see the problem, and I feel like I can do the E problem, but I don't understand even if I look at the answer example.

problem

(https://atcoder.jp/contests/aising2020/tasks)

A. Number of Multiples image.png

Answer

L, R, d = map(int, input().split())

count = 0
for i in range(L, R+1):
    if i % d == 0:
        count += 1

print(count)

I wrote it obediently. Others seem to be writing in a cooler way.

B. An Odd Problem image.png

Answer

N = int(input())
a = list(map(int, input().split()))

count = 0
for i in range(0, N, 2):
    if i % 2 == 0 and a[i] % 2 != 0:
        count += 1
print(count)

I wrote this honestly as well. The problem is odd, but the subscripts in the list are even.

C. XYZ Triplets image.png

Answer
N = int(input())

keys = [i for i in range(1, N+1)]
values = [0] * N
count_dict = dict(zip(keys, values))

for x in range(1, N//6+7):
    for y in range(x, N//6+7):
        for z in range(y, N//6+7):
            n = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if n > N:
                break
            if x == y and y == z:
                count_dict[n] += 1
            elif x != y and x != z and y != z:
                count_dict[n] += 6
            else:
                count_dict[n] += 3

for v in count_dict.values():
    print(v)

To be honest, turn the for loop of `range (1, N + 1) ``` for each of x, y, z and `x ** 2 + y ** 2 + z ** 2 + x It seems that * y + y * z + z * x = n``` should be judged. However, since the constraint is 10 ** 4, it will not be in time for a normal triple loop, so consider reducing the amount of calculation.

The first thing I thought about was that if `(x, y, z) = (1,1,1) ```, n is 6, so the maximum value to turn in a for loop is . N // 6 ``` looks good. However, considering that the subscript must be ``` + 1```, I chose `` N // 6 + 7 with a margin. (In production, I used `` `N // 6 + 7, but if I use the constraint 10 ** 4 in reverse, `(x, y, z)` You can see that can only be used up to about 100. I didn't notice this during production ...)

So, it seems that this alone will probably not be in time, so I will consider reducing the amount of calculation a little more.

If you give some examples, you will notice the following. --(1,2,3) `` `and` `(1,3,2)` `` and `` `(2,1,3)` `` and` `(2,3) , 1) and (3,1,2)`` and ``(3,2,1) , where x, y, z are all different, n is equivalent There are 6 combinations that become --The two are the same, like ``` (1,1,2)`` and ``(1,2,1) `` and (2,1,1) There are three combinations where n is equivalent when one is different --There is one combination where n is equivalent if all the numbers are the same, such as ``(1,1,1)` ``.

Therefore, the range of the for loop of x, y, z is `range (1, N // 6 + 7)`, `range (x, N // 6 + 7)`, respectively. As `range (y, N // 6 + 7)`, it seems that count should be +6, +3, +1 in the above three cases.

After that, if n exceeds N, you can manage to make it by adding `` `break```.

Recommended Posts

Atcoder Acing Programming Contest Python
Acing Programming Contest 2020
AtCoder Acing Programming Contest 2020 Participation Report
Atcoder Beginner Contest 152 Kiroku (python)
atCoder 173 Python
AtCoder HHKB Programming Contest 2020 Participation Report
AtCoder Keyence Programming Contest 2020 Participation Report
AtCoder Beginner Contest 174 C Problem (Python)
AtCoder Panasonic Programming Contest 2020 Participation Report
atcoder Review of Panasonic Programming Contest 2020, up to question E (Python)
Python programming note
AtCoder Beginner Contest 179
AtCoder ABC 174 Python
AtCoder Library Practice Contest Participation Report (Python)
[Python] [Explanation] AtCoder Typical DP Contest: A Contest
AtCoder Beginner Contest 172
AtCoder Beginner Contest 180
AtCoder ABC187 Python
HHKB Programming Contest 2020
AtCoder ABC188 Python
Programming in python
AtCoder Beginner Contest 173
AtCoder Beginner Contest: D Question Answers Python
Atcoder Beginner Contest 153
AtCoder ABC 175 Python
AtCoder Beginner Contest 167 B Problem "Easy Linear Programming" Explanation (Python3, C ++, Java)
Daily AtCoder # 36 in Python
Daily AtCoder # 2 in Python
Daily AtCoder # 32 in Python
Daily AtCoder # 6 in Python
Daily AtCoder # 18 in Python
Daily AtCoder # 53 in Python
AtCoder Beginner Contest 181 Note
AtCoder Grand Contest 041 Review
Daily AtCoder # 33 in Python
Daily AtCoder # 7 in Python
AtCoder Regular Contest 105 Review
AtCoder Beginner Contest 187 Note
Daily AtCoder # 24 in Python
Daily AtCoder # 37 in Python
Solve AtCoder 167 with python
Daily AtCoder # 8 in Python
Daily AtCoder # 42 in Python
Keyence Programming Contest 2020 Review
AtCoder Beginner Contest 160 Review
AtCoder Beginner Contest 178 Review
AtCoder Beginner Contest 180 Note
[Python] Sumitomo Mitsui Trust Bank Programming Contest 2019 C (How to use DP) [AtCoder]
AtCoder Beginner Contest 166 Review
Daily AtCoder # 21 in Python
AtCoder Beginner Contest 167 Review
Daily AtCoder # 17 in Python
Daily AtCoder # 38 in Python
3. 3. AI programming with Python
Daily AtCoder # 54 in Python
AtCoder Regular Contest 106 Note
Daily AtCoder # 11 in Python
Daily AtCoder # 15 in Python
Daily AtCoder # 47 in Python
Daily AtCoder # 13 in Python
AtCoder Beginner Contest 182 Note