QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#640134 | #2929. Concert Rehearsal | enze114514 | TL | 0ms | 3624kb | C++20 | 1.5kb | 2024-10-14 06:58:02 | 2024-10-14 06:58:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
int n;
ll p, k;
cin >> n >> p >> k;
vector<int> d(n);
for (int i = 0; i < n; ++i) {
cin >> d[i];
}
vector<ll> days_passes; // Store passes completed at each day
vector<int> next_day(n, -1); // Store next day index for each index
vector<ll> day_used(n, -1); // Store day when index is reached
ll total_passes = 0;
ll day = 0;
int idx = 0;
while (day < k) {
if (day_used[idx] != -1) {
// Cycle detected
ll cycle_length = day - day_used[idx];
ll passes_in_cycle = total_passes - days_passes[day_used[idx]];
ll remaining_days = k - day;
ll cycles = remaining_days / cycle_length;
total_passes += cycles * passes_in_cycle;
day += cycles * cycle_length;
if (day >= k) break;
}
day_used[idx] = day;
days_passes.push_back(total_passes);
ll time_left = p;
int start_idx = idx;
while (time_left >= d[idx]) {
time_left -= d[idx];
idx = (idx + 1) % n;
if (idx == 0) {
total_passes++;
}
if (idx == start_idx && time_left < d[idx]) {
break;
}
}
day++;
}
cout << total_passes << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
input:
3 20 10 6 9 5
output:
10
result:
ok single line: '10'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
5 11 2 5 5 5 5 5
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
7 11 3 1 2 3 4 5 6 7
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
4 8 9 2 7 2 3
output:
4
result:
ok single line: '4'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
1 3 7 2
output:
7
result:
ok single line: '7'
Test #6:
score: -100
Time Limit Exceeded
input:
1 1000000000 1000000000 1