QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#53863 | #2929. Concert Rehearsal | abdelrahman001 | RE | 2ms | 3680kb | C++ | 2.5kb | 2022-10-06 06:15:17 | 2022-10-06 06:15:18 |
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;
if(p % sum[n] == 0)
return cout << cnt / n, 0;
if(n == 1)
return cout << (p / a[0]) * k, 0;
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;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
input:
3 20 10 6 9 5
output:
10
result:
ok single line: '10'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3656kb
input:
5 11 2 5 5 5 5 5
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
7 11 3 1 2 3 4 5 6 7
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3680kb
input:
4 8 9 2 7 2 3
output:
4
result:
ok single line: '4'
Test #5:
score: -100
Runtime Error
input:
1 3 7 2