QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#53860 | #2929. Concert Rehearsal | abdelrahman001 | WA | 2ms | 3636kb | C++ | 2.3kb | 2022-10-06 05:59:51 | 2022-10-06 05:59:54 |
Judging History
answer
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int N = 2e5 + 5;
int n, p, k, a[N], pos[N];
ll sum[N];
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> p >> k;
for(int i = 1;i <= n;i++) {
cin >> a[i];
sum[i] = sum[i - 1] + a[i];
}
for(int i = 1;i <= n;i++) {
int rem = p % sum[n];
if(sum[n] - sum[i - 1] >= rem) {
pos[i] = i;
int low = i, high = n, mid;
while(low <= high) {
mid = low + high >> 1;
if(sum[mid] - sum[i - 1] <= rem)
pos[i] = mid, low = mid + 1;
else
high = mid - 1;
}
} else {
pos[i] = n;
rem -= sum[n] - sum[i - 1];
int low = 1, high = i - 1, mid;
while(low <= high) {
mid = low + high >> 1;
if(sum[mid] <= rem)
pos[i] = mid, low = mid + 1;
else
high = mid - 1;
}
}
}
int lst = 0;
set<int> st;
vector<int> v;
for(int i = 1;i <= k + 1;i++) {
int nxt = lst + 1;
if(nxt == n + 1)
nxt = 1;
if(st.count(nxt)) {
lst = nxt;
break;
}
v.push_back(nxt);
st.insert(nxt);
lst = pos[nxt];
}
ll cnt = (p / sum[n]) * k * n;
int rem = 0;
for(int i = 0;i < v.size();i++) {
if(v[i] == lst) {
ll cycLen = v.size() - i;
cnt += ((k - i) / cycLen) * n;
rem = (k - i) % cycLen;
break;
}
if(i + 1 < v.size()) {
if(v[i + 1] < v[i])
cnt += n - v[i] + v[i + 1];
else
cnt += v[i + 1] - v[i];
}
}
lst--;
while(rem--) {
int nxt = lst + 1;
if(nxt == n + 1)
nxt = 1;
if(pos[nxt] < nxt)
cnt += n - nxt + pos[nxt];
else
cnt += pos[nxt] - nxt + 1;
lst = pos[nxt];
}
cout << cnt / n;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3636kb
input:
3 20 10 6 9 5
output:
13
result:
wrong answer 1st lines differ - expected: '10', found: '13'