AtCoder Beginner Contest 090 Review of past questions

Time required

スクリーンショット 2020-03-31 16.13.43.png

Impressions

The D problem was terrible. It was later than when I was solving it in December. I will review it firmly.

Problem A

Since it is diagonal, the row and column numbers are the same.

answerA1.py


s=[input()[i] for i in range(3)]
print("".join(s))

B problem

Judge whether it is a palindrome in order from A to B. You just have to judge one character at a time.

answerB.py


a,b=map(int,input().split())
ans=0
for i in range(a,b+1):
    s=str(i)
    l=len(s)
    for i in range(l//2):
        if s[i]!=s[l-1-i]:
            break
    else:
        ans+=1
print(ans)

C problem

** I misread the question sentence ** and thought that there were ** cards in all of the 9 squares **, but it was easy because I only had to ** exist **. It's spicy.

answerC.py


n,m=map(int,input().split())
if n==1 and m==1:
    print(1)
elif n==1:
    print(m-2)
elif m==1:
    print(n-2)
else:
    print((n-2)*(m-2))

D problem

The easiest way is to move both a and b, but it's O ($ n ^ 2 ) so it's too late. In this problem, it is clear from experiments that there is some relationship between the two numbers **, so it is only necessary to fix one and find the other with O (1). I thought it might be. Regarding which one to fix here, I found that if ** a is fixed, moving b will cause irregular movements **. Therefore, think of it as fixing b. First, considering the range of b, the remainder is k or more, so it is k + 1 ~ n. I will fix it in this range, but before that, I thought that ** it is hard to think that the remainder is k + 1 ~ n **, so I decided to draw it considering its complement. Therefore, consider that ** subtract the remainder of 0 ~ k-1 from the number of combinations of b of k + 1 ~ n and a of 1 ~ n ( (nk) \ times n $) **. Consider a ** where b is divided by k + 1 ~ n and the remainder is 0 ~ k-1. A generalized export of such ** a candidates ** would look like this:

Consider the number of candidates for a above. First of all, for l above, it is sufficient to consider how many b are below n, so it can be calculated by n // b. Furthermore, the number of numbers between l * b + 1 and n that have a remainder of 0 to k-1 is the smaller of n divided by b and k-1 (where k = When it is 0, k-1 becomes negative, so it is assumed to be larger than 0). The answer can be obtained by subtracting the above candidates for a ** and thinking about this by moving b.

Through this problem

Experiment and understand the behavior

Write it down and think about it when generalizing

I learned that.

answerD.py


n,k=map(int,input().split())
ans=n*(n-k)
for i in range(k+1,n+1):
    ans-=(k*(n//i))
    ans-=max(0,min(k-1,n%i))
print(ans)

Recommended Posts

AtCoder Beginner Contest 102 Review of past questions
AtCoder Beginner Contest 072 Review of past questions
AtCoder Beginner Contest 085 Review of past questions
AtCoder Beginner Contest 113 Review of past questions
AtCoder Beginner Contest 074 Review of past questions
AtCoder Beginner Contest 051 Review of past questions
AtCoder Beginner Contest 127 Review of past questions
AtCoder Beginner Contest 119 Review of past questions
AtCoder Beginner Contest 151 Review of past questions
AtCoder Beginner Contest 075 Review of past questions
AtCoder Beginner Contest 054 Review of past questions
AtCoder Beginner Contest 110 Review of past questions
AtCoder Beginner Contest 117 Review of past questions
AtCoder Beginner Contest 070 Review of past questions
AtCoder Beginner Contest 105 Review of past questions
AtCoder Beginner Contest 112 Review of past questions
AtCoder Beginner Contest 076 Review of past questions
AtCoder Beginner Contest 069 Review of past questions
AtCoder Beginner Contest 056 Review of past questions
AtCoder Beginner Contest 087 Review of past questions
AtCoder Beginner Contest 067 Review of past questions
AtCoder Beginner Contest 093 Review of past questions
AtCoder Beginner Contest 046 Review of past questions
AtCoder Beginner Contest 049 Review of past questions
AtCoder Beginner Contest 081 Review of past questions
AtCoder Beginner Contest 047 Review of past questions
AtCoder Beginner Contest 060 Review of past questions
AtCoder Beginner Contest 057 Review of past questions
AtCoder Beginner Contest 121 Review of past questions
AtCoder Beginner Contest 126 Review of past questions
AtCoder Beginner Contest 090 Review of past questions
AtCoder Beginner Contest 103 Review of past questions
AtCoder Beginner Contest 061 Review of past questions
AtCoder Beginner Contest 059 Review of past questions
AtCoder Beginner Contest 044 Review of past questions
AtCoder Beginner Contest 083 Review of past questions
AtCoder Beginner Contest 048 Review of past questions
AtCoder Beginner Contest 124 Review of past questions
AtCoder Beginner Contest 116 Review of past questions
AtCoder Beginner Contest 097 Review of past questions
AtCoder Beginner Contest 088 Review of past questions
AtCoder Beginner Contest 092 Review of past questions
AtCoder Beginner Contest 099 Review of past questions
AtCoder Beginner Contest 065 Review of past questions
AtCoder Beginner Contest 053 Review of past questions
AtCoder Beginner Contest 094 Review of past questions
AtCoder Beginner Contest 063 Review of past questions
AtCoder Beginner Contest 107 Review of past questions
AtCoder Beginner Contest 071 Review of past questions
AtCoder Beginner Contest 064 Review of past questions
AtCoder Beginner Contest 082 Review of past questions
AtCoder Beginner Contest 084 Review of past questions
AtCoder Beginner Contest 068 Review of past questions
AtCoder Beginner Contest 058 Review of past questions
AtCoder Beginner Contest 043 Review of past questions
AtCoder Beginner Contest 098 Review of past questions
AtCoder Beginner Contest 114 Review of past questions
AtCoder Beginner Contest 045 Review of past questions
AtCoder Beginner Contest 120 Review of past questions
AtCoder Beginner Contest 108 Review of past questions
AtCoder Beginner Contest 106 Review of past questions