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.

ABC220 C - Long Sequence を解いた

Last updated at Posted at 2021-09-26

abc220_1.png
abc220_2.png
abc220_3.png
abc220_4.png

一応、以下で通った。

LongSequence.py
from sys import exit
N = int(input())
A = list(map(int,input().split()))
X = int(input())

B = sum(A)
base = X//B
rest = X%B

if rest == 0:
    print(base*N+1)#<= ココ1
    exit()
else:
    cnt = 0
    ans = 0
    for i in range(N):
        cnt += A[i]
        if cnt > rest:#<=ココ2
            ans = i+1
            break

print(base*N+ans)

問題文には **超えるのは何項目?**っと聞いている。
最初はココ1 and ココ2 を見逃していて、以下のような記述でWAだった。

LongSequence.py
from sys import exit
N = int(input())
A = list(map(int,input().split()))
X = int(input())

B = sum(A)
base = X//B
rest = X%B

if rest == 0:
    print(base*N)#<= ココ1
    exit()
else:
    cnt = 0
    ans = 0
    for i in range(N):
        cnt += A[i]
        if cnt >= rest:#<=ココ2
            ans = i+1
            break

print(base*N+ans)

シャキッと一発で通せるようになりたい。。

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?