LoginSignup
1
1

More than 1 year has passed since last update.

AtCoder Beginner Contest 278 A問題とB問題をPythonで解いてみました

Last updated at Posted at 2022-11-20

ABC278(AtCoder Beginners Contest 278)
A問題とB問題をPythonで解いてみました。

  • コードは雑めです。ゆるしてー
  • 競技プログラミングの勉強一切したこと無いので、テクニックは知らないよ。ごめんねー

A問題(diff=17)

提出コード

n, k = map(int,input().split())
a = list(map(int,input().split()))
k = min(n,k)
print(" ".join(str(n) for n in a[k:]+[0]*k))

B問題(diff=123)

提出コード

h, m = map(int,input().split())
 
def misread(h,m):
    b = h%10
    h2 = (h-b) + (m//10)
    m2 = b*10 + (m%10)
    if h2<24 and m2<60:     # 入れ替えても時間として正しい場合
        return True         # 見間違えやすい値として返す
    return False
 
def next(h,m):
    m+=1
    if m>59:
        h+=1
        m=0
        if h>23:
            h=0
    return h,m
 
while not misread(h,m):
    h,m = next(h,m)
 
print(f"{h} {m}")

B補足

質問のとこ、私もミスりました
質問してくれた人ナイス
https://atcoder.jp/contests/abc278/clarifications

0時0分や2時20分のように,題意の数字を入れ換えたときにもとの時刻と同じになる時刻は,見間違えやすい時刻に入りますか?

これ考慮してプログラムしちゃった

追記

初心者代表さんがPythonでAtCoderを解くときにちょっと得するメモにちょっとしたテクニックを書いてくれました!
緑の人を初心者と言って良いのかはさておき...
便利!あざす!

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