0
0

More than 1 year has passed since last update.

ABC222 チャレンジ結果

Posted at

ABC222結果 : ABC3完
相変わらずD問題で詰まってしまう...
以下ソースコード

A : Four Digits
パッと構文が分からないときのとりあえずfor文で回す.

N = input()
k = 4 - len(N)
for i in range(k):
    print(0, end="")

print(N)

B : Failing Grade
問題文そのまま. 解説見たら内包表記使えば行数少なくできることに気づかされる.

N, P = list(map(int, input().split(" ")))
list_N = list(map(int, input().split(" ")))

num = 0
for i in range(N):
    if list_N[i] < P:
        num += 1

print(num)

C : Swiss-System Tournament
勝数とindexでソートするために, 勝った場合は減算することに.
途中でindexもいると気づいてコードいじったため, リストが[勝数, じゃんけんの情報, index]の順になり見栄え悪し.

import operator

def janken(p, q, i):
    if (hito_list[p][1][i] == "G" and hito_list[q][1][i] == "C") \
       or (hito_list[p][1][i] == "C" and hito_list[q][1][i] == "P") \
       or (hito_list[p][1][i] == "P" and hito_list[q][1][i] == "G"):
        hito_list[p][0] -= 1
    elif (hito_list[p][1][i] == "C" and hito_list[q][1][i] == "G") \
          or (hito_list[p][1][i] == "P" and hito_list[q][1][i] == "C") \
          or (hito_list[p][1][i] == "G" and hito_list[q][1][i] == "P"):
        hito_list[q][0] -= 1

N, M = list(map(int, input().split(" ")))
hito_list = []

for i in range(2 * N):
    GCP_list = input()
    hito_list.append([0, GCP_list, i+1])

for i in range(M):
    for j in range(N):
        janken(2 * j , 2 * j + 1, i)

    hito_list = sorted(hito_list, key=operator.itemgetter(0, 2))


for num in range(2 * N):
    print(hito_list[num][2])

D : Between Two Arrays
・間違いコード
自分なりに一通り組んでみたが, 提出すると後半実行時エラーのオンパレード.
再帰でうまくいくと思ったのにー
TLEはしょうがないが, REになるのは未だ分かっておらず泣

DP使う発想が全くなく使い方も分かってないので修行を重ねるしかあるまい...

N = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
num = 0
d = 0

def ktz_kosuu(list1, list2, N):
    global d, num

    d = max(list1[0], d)
    if N == 1:
        erabikata = list2[0] - d + 1
        num += erabikata


    else:
        e = d
        for j in range(e, list2[0]+1):
            d = j
            x = list1.pop(0)
            y = list2.pop(0)
            ktz_kosuu(list1, list2, N-1)
            list1.insert(0, x)
            list2.insert(0, y)

    return num % 998244353

kotae = ktz_kosuu(a_list, b_list, N) 
print(kotae)
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