1
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?

AtCoder ABC403 振り返り(緑コーダーがPythonでABC問題)

Posted at

AtCoder Beginner Contest 403 を振り返ります

AtCoder Beginner Contest 403(Promotion of AtCoder Career Design DAY) - AtCoder

前回に引き続き、今回もunratedで参加。用事があったため開始時間に間に合わず、2−3分ほど遅れて着手しております。

結果は、C問題までの3問にACでした。最近D問題が解けてないので、ちょっと厳しいですね...。

A - Odd Position Sum

奇数番目の文字のみを足していきます。配列のindexでは[0,2,4...] を足していけばよいです。

N = int(input())
A = list(map(int, input().split()))

answer = 0
for i in range(0, N, 2):
    answer += A[i]
print(answer)

B - Four Hidden

比較する文字数の条件が厳しくないので、全探索で求めます。

比較の条件のところがちょっと難しいですが、以下の2つの条件をチェックすればよいです。

  • T[x] が "?" であれば、S[y]は何でもok
  • T[x] が "?" でないなら、T[x] == S[y] ならOK
T = list(input())
U = list(input())

diff = len(T) - len(U) # 文字数の差

# 比較の開始地点をiとする
for i in range(diff + 1):
    is_ok = True

    for j in range(len(U)):        
        # "?" だった場合はok
        if T[i + j] == "?":
            continue

        # T, J が一致すればok
        if T[i + j] == U[j]:
            continue

        is_ok = False

    # 一致する文字列が存在
    if is_ok:
        print("Yes")
        exit()

print("No")

C - 403 Forbidden

以下の2つのデータ構造を作って解きました。

  • all_access_set: 全てのページにアクセスできるユーザーのset
  • access[Y]: ページ Y にアクセスできるユーザーのset

ユーザーX が ページY にアクセスできるかを判定するには、以下のどちらかに当てはまれば良いことになります。

  • all_access_set の中に ユーザーXがいる
  • access[Y] のなかに ユーザーXがいる
N, M, Q = map(int, input().split())

all_access_set = set()
access = defaultdict(set)

for i in range(Q):
    query = list(map(int, input().split()))

    if query[0] == 1:
        # ページYにアクセスできるユーザーに、Xを追加
        X = query[1]
        Y = query[2]
        access[Y].add(X)
    elif query[0] == 2:
        # all_accessにユーザーXを追加
        X = query[1]
        all_access_set.add(X)
    else:
        # ユーザーX が all_access_set or access[Y] にいるか?
        X = query[1]
        Y = query[2]
        if X in all_access_set:
            print("Yes")
            continue
        if X in access[Y]:
            print("Yes")
            continue
        print("No")
1
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
1
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?