0
1

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 1 year has passed since last update.

ABC327 提出したコードや感想 (言語:Python)

Posted at

記事構成

1. Atcoder自己紹介
2. 各問題の感想と提出コード
3. 今回の結果想
4. 最後に

1. Atcoder自己紹介

  • 茶色🟤コーダー
  • 主な使用言語:Python,C++(C++は最近使ってません)
  • 一時期休んでたけど最近再開
  • 本コンテスト終了時のグラフ↓

abc327.png

2. 各問題の感想と提出コード

A問題

特にいうこと無し.
A問題にしては中身書きすぎた?

A問題
def c_ab(S):
    N = len(S)
    for i in range(N - 1):
        if (S[i] == 'a' and S[i + 1] == 'b') or (S[i] == 'b' and S[i + 1] == 'a'):
            return "Yes"
    return "No"

a=int(input())
s = input()
print(c_ab(s))

B問題

B問題なら,どうにかなるだろと思い,while文で終了条件を判断
多分C問題以降なら,while文の最後のA^A計算は危険

B問題
def f_aa(b):
    a = 1
    while a ** a <= b:
        if a ** a == b:
            return a
        a += 1
    return -1

b=int(input())
print(f_aa(b))

C問題

問題の条件通りに,実装
思ったより綺麗に書けた

C問題
def is_c(grid):
    for r in grid:
        if len(set(r)) != 9:
            return "No"
    
    for c in range(9):
        if len(set(grid[r][c] for r in range(9))) != 9:
            return "No"
    
    for i in range(0, 9, 3):
        for j in range(0, 9, 3):
            ans_grid = [grid[x][y] for x in range(i, i+3) for y in range(j, j+3)]
            if len(set(ans_grid)) != 9:
                return "No"
    
    return "Yes"

g = [list(map(int, input().split())) for _ in range(9)]

print(is_c(g))

D問題

最近,解いてた過去問でグラフ系の問題があって,二部グラフじゃないか?の考えにつながった
ただそれが無ければ,100%答えに辿り着かなかったので,演習量足りないね
茶diffなのは驚いた(今回も二部グラフかどうか調べる関数はネット参照だし)

D問題
from collections import deque

def is_gragh(graph, n):
    colors = [-1] * n
    for i in range(n):
        if colors[i] == -1:
            queue = deque([i])
            colors[i] = 0
            while queue:
                u = queue.popleft()
                for v in graph[u]:
                    if colors[v] == -1:
                        colors[v] = 1 - colors[u]
                        queue.append(v)
                    elif colors[v] == colors[u]:
                        return False
    return True

def check_pair(N, M, A, B):
    graph = [[] for _ in range(N)]
    for a, b in zip(A, B):
        graph[a-1].append(b-1)
        graph[b-1].append(a-1)
    return is_gragh(graph, N)

n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

result = check_pair(n, m, a, b)
print("Yes" if result else "No")

3. 今回の結果

今回はこんな感じ.まあ上がってるからよし!
割と緑射程圏内

abc327_result.png

4. 最後に

鉄則本早く終わらせたい

0
1
2

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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?