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?

[ABC424] ABC 424(Atcoder Beginner Contest)のA~C(A,B,C)問題をPythonで解説(復習)

0
Posted at

[ABC424] ABC 424(Atcoder Beginner Contest)のA~C(A,B,C)問題をPythonで解説(復習)

合計回答時間:30分

A問題

自分の回答

かかった時間:3分

a,b,c = map(int,input().split())

if a == b or a == c or b == c:
    print('Yes')
else:
    print('No')

終了後考えた最適な回答

上と同じコードです。

a,b,c = map(int,input().split())

if a == b or a == c or b == c:
    print('Yes')
else:
    print('No')

B問題

自分の回答

かかった時間:7分

N,M,K = map(int,input().split())

result = []
count = [0]*(N+1)

for i in range(K):
    A,B = map(int,input().split())
    count[A] += 1
    if count[A] == M:
        result.append(A)

print(*result)

終了後考えた最適な回答

公式の解説などだと、どの問題を解いたかを管理しているけど、解いた問題数さえ分かればいいからいらない気がした。制約で同じイベント起こらんって書いてるし、なんでなのかシンプルに知りたい

N,M,K = map(int,input().split())

result = []
count = [0]*(N+1)

for i in range(K):
    A,B = map(int,input().split())
    count[A] += 1
    if count[A] == M:
        result.append(A)

print(*result)

C問題

自分の回答

解けてないです、DFS勉強しないと
かかった時間:20分

# (0,0)の時、高橋くんはスキルiを習得済み
# A,Bどちらかのスキルを習得済み→スキルiを習得
N = int(input())

# スキルを習得済みかどうか調べるリスト(0なら取得してない、1なら取得済み)
skill = [0] * N
for i in range(N):
    A,B = map(int,input().split())
    if A == 0 and B == 0:
        skill[i] = 1
    if skill[A-1] == 1 or skill[B-1] == 1:
        skill[i] = 1
    
count = 0
for i in range(N):
    if skill[i] == 1:
        count += 1
print(count)

終了後考えた最適な回答

import sys
sys.setrecursionlimit(10**9)

N=int(input())
# グラフ構築
G=[[] for _ in range(N+1)]

for i in range(1,N+1):
  a,b=map(int,input().split())
  G[a].append(i)
  G[b].append(i)

# 到達できた頂点の数を数える
ok=[0]*(N+1)
ok[0]=1

# DFSで頂点の数を数える
def dfs(v):
  ok[v]=1
  for vv in G[v]:
    if not ok[vv]:
      dfs(vv)
      
dfs(0)
print(sum(ok)-1)

次に向けてやること

・A,Bは安定して解けてきたので、解けなかった問題を復習することに時間を使う
・DFSアルゴリズムの勉強

感想

週末思いっきり風邪ひいてたので今日といたけど、今までで一番スムーズにA,Bが解けた。C問題はアルゴリズムの知識があるかの差だと思うから勉強する

補足

関係するリンク(参考文献など)

今回のコンテスト

回答の正当性は保証できません。ベストエフォート方式です。

0
0
0

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?