QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#414573 | #2929. Concert Rehearsal | TheSleepyDevil# | TL | 1ms | 3712kb | C++14 | 4.0kb | 2024-05-19 10:02:20 | 2024-05-19 10:02:20 |
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----------------------------------//
void TestCake(){
int n,p,k;
cin>>n>>p>>k;
vector<pair<int,int>>all;
vector<int>pre;
int sum=0;
for(int i=0;i<n;i++){
int x;cin>>x;
all.pb({i,x});
sum+=x;
pre.pb(sum);
}
// if(sum<=p){
// int here=p*k;
// here/=sum;
// cout<<here<<el;return;
// }
set<vector<pair<int,int>>>st;
vector<vector<pair<int,int>>>last;
int ok=0;
int cur=0;
vector<pair<int,int>>here;
int bef=0,id=0,stt=0,key=0;
while(stt<n&&k){
int l=stt,r=n-1,id=stt;
while(l<=r){
int mid=(l+r)/2;
int here=pre[mid]-(!bef?0:pre[bef-1])+key;
if(here>p){
id=mid;
r=mid-1;
}
else{
l=mid+1;
}
}
for(int i=stt;i<l;i++){
here.pb({i,all[i].second});
key+=all[i].second;
}
// cout<<stt<<" "<<l<<el;
if(l>=n){
stt=0;
bef=0;
continue;
}
k--;
key=0;
last.pb(here);
if(st.find(here)!=st.end()){
ok=1;break;
}
bef=l;
stt=l;
st.insert(here);
here.clear();
}
if(!ok){
map<int,int>mp;
for(int i=0;i<last.size();i++){
for(auto x : last[i])mp[x.first]++;
}
int mn=inf;
for(int i=0;i<n;i++){
mn=min(mn,mp[i]);
}
cout<<mn<<el;
return;
}
k++;
// cout<<k<<el;
// for(auto z : last){
// for(auto x : z){
// cout<<x.first<<" "<<x.second<<el;
// }
// cout<<el;
// }
id=0;
for(int i=0;i<last.size()-1;i++){
if(last[i]==last.back()){
id=i;
break;
}
}
map<int,int>mp;
for(int i=id;i<last.size()-1;i++){
for(auto x : last[i])mp[x.first]++;
}
int sz=last.size()-id-1;
int cnt=k/sz,lft=k%sz;
for(int i=0;i<n;i++){
mp[i]+=(mp[i]*cnt);
}
for(int i=id;i<last.size()-1&&lft;i++){
for(auto x : last[i])mp[x.first]++;
lft--;
}
for(int i=0;i<id;i++){
for(auto x : last[i])mp[x.first]++;
}
int mn=inf;
for(int i=0;i<n;i++){
mn=min(mn,mp[i]);
}
cout<<mn;
}
//------------------------------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;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3576kb
input:
3 20 10 6 9 5
output:
10
result:
ok single line: '10'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3580kb
input:
5 11 2 5 5 5 5 5
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3552kb
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: 3524kb
input:
4 8 9 2 7 2 3
output:
4
result:
ok single line: '4'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
1 3 7 2
output:
7
result:
ok single line: '7'
Test #6:
score: -100
Time Limit Exceeded
input:
1 1000000000 1000000000 1