[PYTHON] Codeforces Round # 658 (Div. 2) Bacha Review (7/29)

This time's results

スクリーンショット 2020-07-30 11.49.41.png

Impressions of this time

I misread it again as I did last time. See C problem for details. It is inefficient to solve only 3 questions over 2 hours, so we will gradually increase the number of problems that can be solved.

Problem A

If the shortest common subsequence of $ a $ and $ b $ exists, the length will be 1, so you can output one of the common characters of $ a $ and $ b $. Also, here you can find out if there are any characters contained in $ a $ that are also contained in $ b $, and if one of them has a set structure, you can check with $ O (N) $.

A.py


t=int(input())
for _ in range(t):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=set(map(int,input().split()))
    for i in a:
        if i in b:
            print("YES")
            print(f"1 {i}")
            break
    else:
        print("NO")

Problem B

First of all, it is a game problem, so ** pay attention to the final state **. When paying attention to the final state, all the mountains will be 0, but just before that, only the last mountain will remain as it is.

What I paid attention to here was whether to leave each mountain or not (** binarization! **). That is, if the number of stones in each mountain is greater than 1, the player who chooses that mountain cannot give his opponent a choice. This can be done by leaving only one stone from the mountain and handing it to the other party.

However, ** if the number of stones in the mountain is originally one **, the player who chooses the mountain has no choice but to remove that one stone. Therefore, when operating on a mountain with more than 1 stone, you can adjust whether to leave one stone or remove all stones from that mountain depending on whether the number of stones in the next mountain is one or not. Also, if a mountain with only one stone continues from the first mountain, the player has no choice, so the player who can choose a mountain without one stone for the first time has the choice and wins. Can be said to be possible

B.py


t=int(input())
for i in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    s=["First","Second"]
    ans=0
    for i in range(n):
        if a[i]!=1:
            ans=i
            break
    else:
        ans=n-1
    print(s[ans%2])

C1 problem

I misread it completely. I thought that the inversion operation was the entire character string, but when I often saw the problem statement, it was written that it was done only with the prefix that I chose. In Codeforces, I read the original English text as it is, and there are many mistakes, so I would like to focus on ** eliminating such non-essential mistakes **.

As for the problem, the first policy is to think about what happens to the $ i $ th bit (** abstraction **). At this time, consider the case of inverting only the $ i $ th bit, but here it is possible by selecting in the order of $ i $ → $ 1 $ → $ i $. Also, in this simulation, it will be about $ 3n $ times. The first $ i $ operation changes the $ i $ th element to the $ 1 $ th element, so the $ 1 $ operation reverses only the originally $ i $ th element at the $ 1 $ th element, and finally $ Think of it as undoing with i $. If you don't know, I think you should show it. I feel that such problems can only be solved discoverably, so I think the important thing is ** familiarity and experimentation **.

C1.py


#misreading…
t=int(input())
for _ in range(t):
    n,a,b=int(input()),input(),input()
    ans=[]
    for i in range(n):
        if a[i]!=b[i]:
            ans.append(f"{i+1}")
            ans.append("1")
            ans.append(f"{i+1}")
    print(f"{len(ans)}"+" "+" ".join(ans))

After the C2 problem

I will skip this time

Recommended Posts

Codeforces Round # 658 (Div. 2) Bacha Review (7/29)
Codeforces Round # 654 (Div. 2) Bacha Review (8/18)
Codeforces Round # 594 (Div. 2) Bacha Review (10/29)
Codeforces Round # 609 (Div. 2) Bacha Review (10/8)
Codeforces Round # 597 (Div. 2) Bacha Review (10/27)
Codeforces Round # 666 (Div. 2) Bacha Review (9/2)
Codeforces Round # 651 (Div. 2) Bacha Review (8/20)
Codeforces Round # 659 (Div. 2) Bacha Review (8/5)
Codeforces Round # 610 (Div. 2) Bacha Review (10/5)
Codeforces Round # 479 (Div. 3) Bacha Review (9/25)
Codeforces Round # 603 (Div. 2) Bacha Review (10/15)
Codeforces Round # 600 (Div. 2) Bacha Review (10/21)
Codeforces Round # 481 (Div. 3) Bacha Review (9/24)
Codeforces Round # 639 (Div. 2) Bacha Review (9/4)
Codeforces Round # 612 (Div. 2) Bacha Review (10/2)
Codeforces Round # 521 (Div. 3) Bacha Review (10/9)
Codeforces Round # 652 (Div. 2) Bacha Review (8/24)
Codeforces Round # 673 (Div. 2) Bacha Review (10/22)
Codeforces Round # 606 (Div. 3) Bacha Review (10/13)
Codeforces Round # 613 (Div. 2) Bacha Review (10/1)
Codeforces Round # 665 (Div. 2) Bacha Review (8/23)
Codeforces Round # 592 (Div. 2) Bacha Review (11/03)
Codeforces Round # 662 (Div. 2) Bacha Review (8/8)
Codeforces Round # 618 (Div. 2) Bacha Review (9/26)
Codeforces Round # 648 (Div. 2) Bacha Review (9/5)
Codeforces Round # 676 (Div. 2) Bacha Review (10/31)
Codeforces Round # 675 (Div. 2) Bacha Review (10/30)
Codeforces Round # 486 (Div. 3) Bacha Review (9/23)
Codeforces Round # 671 (Div. 2) Bacha Review (9/22)
Codeforces Round # 669 (Div. 2) Bacha Review (9/9)
Codeforces Round # 672 (Div. 2) Bacha Review (10/16)
Codeforces Round # 638 (Div. 2) Bacha Review (9/16)
Codeforces Round # 663 (Div. 2) Bacha Review (8/13)
Codeforces Round # 668 (Div. 2) Bacha Review (9/7)
Codeforces Round # 663 (Div. 2) Bacha Review (8/16)
Codeforces Round # 609 (Div. 2) Bacha Review (10/6)
Codeforces Round # 645 (Div. 2) Bacha Review (9/10)
Codeforces Round # 664 (Div. 2) Bacha Review (8/13)
Codeforces Round # 660 (Div. 2) Bacha Review (8/4)
Codeforces Round # 643 (Div. 2) Review
Codeforces Round # 679 (Div. 2) Review (10/25)
Codeforces Round # 657 (Div. 2) Review
Educational Codeforces Round 93 Bacha Review (8/17)
Educational Codeforces Round 94 Bacha Review (9/3)
Educational Codeforces Round 91 Bacha Review (7/28)
Educational Codeforces Round 88 Bacha Review (8/4)
Educational Codeforces Round 86 Bacha Review (9/17)
Educational Codeforces Round 89 Bacha Review (9/8)
Educational Codeforces Round 92 Bacha Review (7/30)
Educational Codeforces Round 90 Bacha Review (8/19)
Codeforces Round # 609 (Div. 2) (up to B)
Educational Codeforces Round 87
Codeforces Beta Round # 13
Codeforces Beta Round # 1
Codeforces Beta Round # 2
DP100 Question Bacha Review 1 ~ 10 (8 / 26,27)
Codeforces Round # 626 B. Count Subrectangles