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?

More than 3 years have passed since last update.

PythonでABC037のA~Cを解く

Last updated at Posted at 2020-05-07

はじめに

今日は早起きできたので、記事書きます.

A問題

問題

考えたこと
minとって、割る

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

if a > b:
    ans = c // b
    print(ans)
else:
    ans = c // a
    print(ans)

B問題

問題

考えたこと
Qが小さいので、forで回せる

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

lrt = [list(map(int,input().split())) for _ in range(q)]

a = [0] * n
for i in range(q):
    a[lrt[i][0]-1:lrt[i][1]] = [lrt[i][2]] * (lrt[i][1]-lrt[i][0]+1)

for i in range(n):
    print(a[i])

C問題

問題

考えたこと
スライス使うと、おそらくTLEするので累積和を使います。numpyを使うと楽なので、numpyを使います。

import numpy as np
n, k = map(int,input().split())
a = list(map(int,input().split()))

a = np.cumsum(a)
a = np.append(0,a) #np.cumsumだと0が追加されないのでappendします
ans = 0
for i in range(n):
    if i + k >= n + 1:
        break
    ans += a[i+k]-a[i]

print(ans)

まとめ

Dはできない。ではまた。

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?