0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

B - Bingo, C - Takahashi's Information, C - 山崩し

0
Last updated at Posted at 2021-03-06

##B - Bingo

O(N)
実装問題です。

python
import math
import heapq
import itertools
from functools import reduce
 
# main
def main():
    A = []
    Field = [[False] * 3, [False] * 3, [False] * 3]
 
    for i in range(0, 3):
        a = list(map(int, input().split()))
        A.append(a)
 
    N = int(input())
    B = [0] * N
    for i in range(0, N):
        B[i] = int(input())
 
    for b in B:
        for i in range(3):
            for j in range(3):
                if A[i][j] == b:
                    Field[i][j] = True
 
    bingo = False
    if Field[0][0] and Field[1][1] and Field[2][2]:
            bingo = True

    if Field[0][2] and Field[1][1] and Field[2][0]:
            bingo = True
    
    for i in range(3):
        if Field[i][0] and Field[i][1] and Field[i][2]:
            bingo = True
 
    for i in range(3):
        if Field[0][i] and Field[1][i] and Field[2][i]:
            bingo = True
    
    if bingo:
        print("Yes")
    else:
        print("No")
 
# エントリポイント
if __name__ == '__main__':
    main()

##C - Takahashi's Information

O(1)
問題文から下記の要素が推測できる。
引き算をして各要素が等しいか判定。


a_1 + b_1,  a_1 + b_2, a_1 + b_3 \\
a_2 + b_1,  a_2 + b_2, a_2 + b_3 \\
a_3 + b_1,  a_3 + b_2, a_3 + b_3 \\

python
import math
import heapq
import itertools
from functools import reduce
 
# main
def main():
    C = []

    for _ in range(0, 3):
        row = list(map(int, input().split()))
        C.append(row)

    ok = True
    if C[0][0] - C[0][1] != C[1][0] - C[1][1] or C[1][0] - C[1][1] != C[2][0] - C[2][1]:
        ok = False
    if C[0][1] - C[0][2] != C[1][1] - C[1][2] or C[1][1] - C[1][2] != C[2][1] - C[2][2]:
        ok = False
    
    if ok:
        print("Yes")
    else:
        print("No")

# エントリポイント
if __name__ == '__main__':
    main()

##C - 山崩し

O(N*(2N-1))
全探索の問題です。
実装問題。

5
....#....
...##X...
..#####..
.#X#####.
#########

配列の下から判定すると上手くいきますね。

python
import math
import heapq
import itertools
from functools import reduce
 
# main
def main():
    N = int(input())
    field = []

    for _ in range(0, N):
        S = str(input())
        field.append(S)

    for i in range(N-1, 0, -1):
        for j in range(0, 2*N-1):
            if field[i][j] == 'X':
                if j-1>=0 and field[i-1][j-1] == '#':
                    field[i-1] = field[i-1][:j-1] + 'X' + field[i-1][j:]

                if field[i-1][j] == '#':
                    field[i-1] = field[i-1][:j] + 'X' + field[i-1][j+1:]

                if j+1<2*N-1 and field[i-1][j+1] == '#':
                    field[i-1] = field[i-1][:j+1] + 'X' + field[i-1][j+2:]
                    
    for i in range(0, N):
        print(field[i])

# エントリポイント
if __name__ == '__main__':
    main()
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?