0
0

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

Posted at

記事構成

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

1. Atcoder自己紹介

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

abc329.png

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

A問題

特にいうこと無し.ABCのAって感じの問題が久しぶりに来た
コードは結構綺麗に書けたんじゃないかな

A問題
s = input()
for char in s:
    print(char, end=' ')

B問題

一回最大値探してからもう一回走査.
2番目引き出す関数あるのかな?
A,B問題用にリスト内のn番目の最大値(最小値)返す関数は作っても良いかも

B問題
n = int(input())
a = list(map(int, input().split()))

maxn = max(a)
second_max = max([x for x in a if x != maxn])

print(second_max)

C問題

2回TLE使っちゃった.
やっぱり事前の点数を元に思考しちゃうの良くないな.
雑に実装すれば解けると思っちゃった

C問題
n=int(input())
s=input()
abc = [0] * 26
count, cx = 1, ord(s[0]) - ord('a')

for i in range(1, len(s)):
    if s[i] == s[i - 1]:
        count += 1
    else:
        abc[cx] = max(abc[cx], count)
        count = 1
        cx = ord(s[i]) - ord('a')

abc[cx] = max(abc[cx], count)

result = sum(abc)

print(result)

D問題

問題解いてるときは,一旦Cを諦めてこっちに移行
正直こっちの方が変に考えることないから楽だった

D問題
def ele(N, M, votes):
    v = [0] * (N + 1)
    c = 0
    results = []

    for i in range(M):
        v[votes[i]] += 1

        if v[votes[i]] > v[c] or (v[votes[i]] == v[c] and votes[i] < c):
            c = votes[i]

        results.append(c)

    return results

n,m = map(int, input().split())

a = list(map(int, input().split()))

result = ele(n, m, a)

for i in result:
    print(i)

3. 今回の結果

今回はこんな感じ.下がっちゃったね
次回緑行きたいな〜

スクリーンショット 2023-11-22 0.27.08.png

4. 最後に

公式ドキュメントを読む,的な記事を書きたい

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