QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#414960 | #2929. Concert Rehearsal | TheSleepyDevil | WA | 2ms | 12204kb | C++20 | 4.1kb | 2024-05-20 05:54:54 | 2024-05-20 05:54:54 |
Judging History
answer
/*
Hell, 'til I reach Hell, I ain't scared
Mama checkin' in my bedroom, I ain't there
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Major ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define TxtIO freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define read(a,n) for(int i = 0 ; i<n ; i++) cin>>a[i];
#define write(a) for(auto x : a) cout<<x<<" ";
#define int long long
#define pb push_back
#define all(a) a.begin(),a.end()
#define el "\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int inf=4e18;
int dx[]={1,0,-1,0,1,1,-1,-1};
int dy[]={0,1,0,-1,1,-1,1,-1};
const int mod=1e9+7;
const int MAX =1e6+7;
// ---------------------------Function----------------------------------//
int n,p,k;
vector<array<int,2>>arr;
vector<int>pre;
int check(int i, int x) {
int cnt = pre[n - 1] * (x / n);
if(i + x % n >= n)
cnt += pre[n - 1] - pre[i - 1] + pre[(i + x % n) % n];
else {
cnt += pre[i + x % n];
if(i)
cnt -= pre[i - 1];
}
return cnt ;
}
int vis[MAX],ans[MAX],base[MAX];
void TestCake(){
cin>>n>>p>>k;
int sum=0;
for(int i=0;i<n;i++){
int x;cin>>x;
arr.pb({x,i});sum+=x;
pre.pb(sum);
}
if(n==1 || p%sum==0){
cout<<(p/sum)*k<<el;return;
}
vector<array<int,2>>nxt;
for(int i=0;i<n;i++){
int l=1,r=1e9,z=1;
while(l<=r){
int mid=(l+r)/2;
if(check(i,mid)>p){
z=mid;
r=mid-1;
}
else{
l=mid+1;
}
}
// cout<<check(i,r)<<" "<<i<<" "<<r<<el;
nxt.pb({(i+r)%n,r});
// cout<<i<<" "<<(i+r)%n<<" "<<r<<el;
}
memset(vis,-1,sizeof vis);
int st=0,cnt=0;
vector<array<int,3>>here;
while(vis[st]==-1){
vis[st]=cnt;
here.pb({st,nxt[st][0],nxt[st][1]});
st=nxt[st][0];
cnt++;
}
here.pb({st,nxt[st][0],nxt[st][1]});
// cout<<cnt<<el;
// for(auto x : here){
// cout<<x[0]<<" "<<x[1]<<" "<<x[2]<<el;
// }
int tot=0;
if(cnt>k){
for(int i=0;i<here.size()-1&&k--;i++){
int l=here[i][0],r=here[i][1];
// cout<<l<<" "<<r<<el;
int m3aya=here[i][2],zyada=here[i][2]%n;
tot+=m3aya;
}
}
else{
k-=cnt;
// cout<<k<<" "<<cnt<<el;
int id=0;
for(int i=0;i<here.size()-1;i++){
if(here[i]==here.back()){id=i;break;}
}
int sz=(cnt-id);
for(int i=0;i<here.size()-1;i++){
int m3aya=here[i][2];
tot+=m3aya;
}
if(!sz){
cout<<(tot/n)<<el;return;
}
int have=(k/sz),ba2y=(k%sz);
for(int i=id;i<here.size()-1;i++){
int m3aya=here[i][2],zyada=here[i][2]%n;
tot+=(have*m3aya);
}
for(int i=id;i<here.size()-1&&ba2y--;i++){
int m3aya=here[i][2];
tot+=(m3aya);
}
}
// cout<<tot<<el;
cout<<tot/n<<el;
}
//------------------------------Main---------------------------//
signed main(){
Major
int T = 1;
// cin >> T;
while(T--){
TestCake();
// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3788kb
input:
3 20 10 6 9 5
output:
10
result:
ok single line: '10'
Test #2:
score: 0
Accepted
time: 2ms
memory: 11820kb
input:
5 11 2 5 5 5 5 5
output:
0
result:
ok single line: '0'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 12204kb
input:
7 11 3 1 2 3 4 5 6 7
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0'