QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#96500 | #2929. Concert Rehearsal | Abdelrahman_K | WA | 5ms | 8256kb | C++14 | 2.0kb | 2023-04-13 23:05:40 | 2023-04-13 23:05:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef long double ld;
#define F first
#define S second
const int N = 1e5 + 2, mod = 1e9 + 7;
const ld eps = 1e-6;
int grid[57][57];
typedef complex<ld> point;
#define X real()
#define Y imag()
int main() {
ll n, p, k;
cin>>n>>p>>k;
ll arr[2 * n + 5], sum = 0;
ll pref[2 * n + 5];
for(int i = 0; i < n; i++){
cin>>arr[i];
sum += arr[i];
arr[i + n] = arr[i];
pref[i] = sum;;
}
ll cur = 0;
for(int i = 0; i < n; i++){
cur += arr[i];
pref[i + n] = sum + cur;
}
ll people[n + 5], next[n + 5];
for(int i = 0; i < n; i++){
people[i] = (p / sum) * n;
ll x = p % sum;
ll start = i, end = i + n - 1, ans = 0;
while(start <= end){
ll mid = (start + end) / 2, a;
a = pref[mid] - (i ? pref[i - 1] : 0);
if(a <= x){
start = mid + 1;
ans = mid - i + 1;
}
else
end = mid - 1;
}
people[i] += ans;
next[i] = (ans + i) % n;
}
// for(int i = 0; i < n; i++){
// cout<<people[i]<<' '<<next[i]<<endl;
// }
ll acc[4 * N + 5];
int last_day[4 * N + 5];
memset(last_day, -1, sizeof last_day);
last_day[0] = 1;
int now = 0;
acc[0] = 0;
acc[1] = people[0];
for(int day = 2; day <= (ll)4e5; day++){
now = next[now];
acc[day] = acc[day - 1] + people[now];
if(last_day[now] != -1){
ll y = acc[day] - (acc[last_day[now]]);
// ll y = (last_day[now] == 0)? acc[day] - acc[last_day[now]] : acc[day];
ll fans = acc[last_day[now]] + y * ((k - last_day[now]) / (day - last_day[now]));
ll z = ((k - last_day[now]) % (day - last_day[now]));
fans += acc[last_day[now] + z - 1] - acc[last_day[now] - 1];
return cout<<fans / n, 0;
}
last_day[now] = day;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 8256kb
input:
3 20 10 6 9 5
output:
10
result:
ok single line: '10'
Test #2:
score: 0
Accepted
time: 1ms
memory: 7976kb
input:
5 11 2 5 5 5 5 5
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 2ms
memory: 7916kb
input:
7 11 3 1 2 3 4 5 6 7
output:
1
result:
ok single line: '1'
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 8052kb
input:
4 8 9 2 7 2 3
output:
3
result:
wrong answer 1st lines differ - expected: '4', found: '3'