QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#638109#2929. Concert Rehearsalenze114514TL 14ms10680kbPython32.0kb2024-10-13 14:55:472024-10-13 14:55:47

Judging History

你现在查看的是最新测评结果

  • [2024-10-13 14:55:47]
  • 评测
  • 测评结果:TL
  • 用时:14ms
  • 内存:10680kb
  • [2024-10-13 14:55:47]
  • 提交

answer

def main():
    n_str, p_str, k_str = input().split()
    n = int(n_str)
    p = int(p_str)
    k = int(k_str)
    d = []
    for _ in range(n):
        d.append(int(input()))

    passes_completed = [0] * n
    next_starting_student = [0] * n

    # Precompute passes_completed and next_starting_student for each starting student
    for s in range(n):
        time = 0
        passes = 0
        current_student = s
        while True:
            time += d[current_student]
            if time > p:
                next_starting_student[s] = current_student
                passes_completed[s] = passes
                break
            if current_student == n - 1:
                passes += 1
                current_student = 0
            else:
                current_student += 1

    total_passes = 0
    day = 0
    current_start = 0
    seen = {}
    passes_at_day = []
    while day < k:
        if current_start in seen:
            # Cycle detected
            first_day = seen[current_start]
            cycle_length = day - first_day
            total_passes_in_cycle = total_passes - passes_at_day[first_day]
            remaining_days = k - day
            num_cycles = remaining_days // cycle_length
            total_passes += num_cycles * total_passes_in_cycle
            day += num_cycles * cycle_length
            # Now simulate the remaining days one by one
            while day < k:
                seen[current_start] = day
                passes_at_day.append(total_passes)
                total_passes += passes_completed[current_start]
                current_start = next_starting_student[current_start]
                day += 1
            break
        else:
            seen[current_start] = day
            passes_at_day.append(total_passes)
            total_passes += passes_completed[current_start]
            current_start = next_starting_student[current_start]
            day += 1
    print(total_passes)

main()

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 14ms
memory: 10680kb

input:

3 20 10
6
9
5

output:

10

result:

ok single line: '10'

Test #2:

score: 0
Accepted
time: 12ms
memory: 10572kb

input:

5 11 2
5
5
5
5
5

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 5ms
memory: 10612kb

input:

7 11 3
1
2
3
4
5
6
7

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 10ms
memory: 10520kb

input:

4 8 9
2
7
2
3

output:

4

result:

ok single line: '4'

Test #5:

score: 0
Accepted
time: 12ms
memory: 10608kb

input:

1 3 7
2

output:

7

result:

ok single line: '7'

Test #6:

score: -100
Time Limit Exceeded

input:

1 1000000000 1000000000
1

output:


result: