QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#637947 | #2929. Concert Rehearsal | enze114514 | TL | 0ms | 3632kb | C++20 | 2.2kb | 2024-10-13 14:26:58 | 2024-10-13 14:26:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define pb push_back
const ld pi = 3.14159265358979323846;
const int mod = 998244353;
const ll INF = 1e18;
struct pair_hash {
template<class T1, class T2>
size_t operator()(const std::pair<T1, T2> &pair) const {
return hash<T1>()(pair.first) ^ hash<T2>()(pair.second);
}
};
template<typename T>
T chmax(T a, T b) {
return a > b ? a : b;
}
template<typename T>
T chmin(T a, T b) {
return a > b ? b : a;
}
const int N = (int) 1e5 + 1, M = N * 2;
int n;
int day_time;
int total_days;
int total_time;
int total_training_time = 0;
vector<int> a;
void solve() {
cin >> n >> day_time >> total_days;
a.resize(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<int> cnt(n), nxt(n);
for (int pos = 0; pos < n; ++pos) {
int rem = day_time;
int curr = pos;
int c = 0;
while (rem >= a[curr]) {
rem -= a[curr];
curr = (curr + 1) % n;
c += 1;
}
cnt[pos] = c;
nxt[pos] = curr;
}
unordered_map<int, pair<int, ll>> mp; // pos -> (day, total_perf)
int pos = 0;
ll total_perf = 0;
int day = 0;
while (day < total_days) {
if (mp.find(pos) != mp.end()) {
// Cycle detected
int prev_day = mp[pos].first;
ll prev_perf = mp[pos].second;
int cycle_days = day - prev_day;
ll cycle_perf = total_perf - prev_perf;
ll cycles = (total_days - day) / cycle_days;
total_perf += cycles * cycle_perf;
day += cycles * cycle_days;
if (day >= total_days)
break;
}
mp[pos] = {day, total_perf};
total_perf += cnt[pos];
pos = nxt[pos];
day += 1;
}
ll full_passes = total_perf / n;
cout << full_passes << endl;
}
int main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
// int t = 1;
// cin >> t;
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3628kb
input:
3 20 10 6 9 5
output:
10
result:
ok single line: '10'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
5 11 2 5 5 5 5 5
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3632kb
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: 3628kb
input:
4 8 9 2 7 2 3
output:
4
result:
ok single line: '4'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
1 3 7 2
output:
7
result:
ok single line: '7'
Test #6:
score: -100
Time Limit Exceeded
input:
1 1000000000 1000000000 1