QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#208745 | #6767. Hourly Coding Problem | 275307894a | TL | 520ms | 8140kb | C++14 | 1.3kb | 2023-10-09 20:38:31 | 2023-10-09 20:38:32 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=2e5+5,M=1e5,K=600+5,mod=1e9+7,Mod=mod-1;const db eps=1e-6;const ll INF=1e18+7;mt19937 rnd(263082);
int n,k;ll A[N],l[N],r[N];
int CK(ll mid){
l[0]=r[0]=0;int i,j;
for(i=1;i<=n;i++){
l[i]=INF;r[i]=-INF;
for(j=0;j<i;j++) if(A[i]-A[j]<=mid) l[i]=min(l[i],l[j]+1),r[i]=max(r[i],r[j]+1);
}
return l[n]<=k&&k<=r[n];
}
void find(int x,int y,ll mid){
if(!x){assert(!y);return;}
for(int i=0;i<x;i++) if(A[x]-A[i]<=mid&&l[i]<=y-1&&y-1<=r[i]) {printf("%d%c",x-i," \n"[y==1]);find(i,y-1,mid);return;}
assert(0);
}
void Solve(){
int i,j;scanf("%d%d",&n,&k);
for(i=1;i<=n;i++) scanf("%lld",&A[n-i+1]);for(i=1;i<=n;i++) A[i]+=A[i-1];
ll l=-INF,r=INF,mid;while(l+1<r) mid=l+r>>1,(CK(mid)?r:l)=mid;
CK(r);find(n,k,r);
}
int main(){
int t=1;
scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 6116kb
input:
3 7 3 5 1 0 2 7 -3 4 6 4 -1 3 -2 4 -3 5 6 2 0 -2 0 -1 -1 0
output:
3 3 1 1 1 2 2 3 3
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 231ms
memory: 5976kb
input:
200178 2 1 5 -1 4 3 4 -7 -4 10 2 1 -6 -2 4 1 8 10 -9 10 4 2 10 -4 10 1 4 1 7 -1 4 3 4 1 7 -5 10 10 2 1 -7 9 3 2 3 3 4 4 4 -1 4 -9 -8 3 1 10 6 7 2 2 3 8 4 4 0 -9 -2 -9 2 1 9 -3 1 1 -3 3 3 -8 -7 -3 4 3 -2 -3 3 1 4 4 7 -5 4 0 3 2 2 6 3 5 1 7 -3 2 3 0 4 1 10 -8 -8 -4 1 1 -2 1 1 -2 3 2 1 -9 -5 2 1 -6 4 1...
output:
2 1 1 2 2 4 1 3 4 4 2 2 1 1 1 1 1 3 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 5 4 1 1 2 1 2 1 1 3 1 1 1 1 1 1 1 2 1 1 2 3 1 1 2 1 1 1 1 1 2 1 4 5 1 1 1 1 1 1 1 2 2 1 1 5 1 2 1 3 1 5 1 1 2 1 4 4 1 3 1 1 1 1 1 1 3 1 1 1 1 1 1 1 3 2 1 1 1 1 1 1 4 1 1 1 2 2 1 2 1 1 1 1 1 3 1 3 1 1 1 1 1 1 2 1 2 2 2 3 2 3 ...
result:
ok 200178 lines
Test #3:
score: 0
Accepted
time: 277ms
memory: 5976kb
input:
199772 5 3 -46052578 659867356 -845691509 354080848 495499331 3 2 -723935257 710677961 444019907 2 2 -630160659 -152028149 2 1 588799363 -240251692 1 1 -194483310 3 3 374813337 273066639 -351814252 3 2 -730564958 797633747 637128587 4 4 -307084294 -676969505 558588609 -844837130 2 2 223904090 -50221...
output:
3 1 1 2 1 1 1 2 1 1 1 1 2 1 1 1 1 1 1 1 1 1 2 2 1 1 1 2 1 1 1 1 1 5 3 2 1 1 1 1 3 1 4 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 5 1 2 1 2 3 3 1 1 1 1 4 1 1 1 1 1 2 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 3 1 1 1 1 1 1 1 2 1 2 3 4 1 2 2 1 1 2 1 ...
result:
ok 199772 lines
Test #4:
score: 0
Accepted
time: 439ms
memory: 5956kb
input:
46211 17 3 6 3 0 5 -10 6 -4 10 5 -9 -7 9 8 0 3 1 -4 12 1 -6 -2 -10 10 5 5 5 7 6 -10 4 2 1 1 1 3 3 8 6 1 21 4 3 10 10 0 -5 -3 -1 -9 -10 -4 1 -5 -8 -8 -4 8 9 -4 -7 -6 3 21 1 0 2 8 5 -8 -8 3 -1 6 1 -7 4 2 3 8 -3 -8 5 -6 7 1 1 1 -9 25 1 0 -3 -3 5 6 -4 -1 -8 -9 0 4 5 4 9 -5 -9 -5 -1 -8 1 3 6 9 -7 -1 17 5...
output:
7 5 5 12 1 1 1 1 11 1 6 3 21 1 25 7 7 1 1 1 2 1 11 9 1 1 1 1 1 1 1 6 1 1 3 6 3 1 17 3 6 3 1 3 4 1 5 2 10 5 1 6 9 1 1 11 1 2 1 1 1 1 1 1 1 1 1 2 8 5 8 1 13 4 1 1 9 11 1 2 3 5 3 1 6 19 1 4 1 2 1 16 9 1 1 1 1 15 6 20 6 7 7 3 3 17 1 2 14 4 4 7 8 1 10 2 6 1 1 1 5 2 4 1 1 1 7 2 2 4 3 1 7 1 1 3 1 10 1 2 3 ...
result:
ok 46211 lines
Test #5:
score: 0
Accepted
time: 454ms
memory: 8140kb
input:
46128 15 3 -76 84 71 66 5 12 -34 82 50 -70 -96 80 -99 42 67 6 1 -93 78 -68 -97 -31 7 10 2 49 -46 -80 -36 -36 -42 -17 35 36 -81 12 4 80 -6 81 -17 -56 88 12 56 62 -79 84 7 22 1 32 13 5 100 37 -36 47 -73 -99 9 -46 27 68 1 -70 -30 -5 74 97 6 50 -29 20 2 -22 9 -77 -66 -28 36 54 34 32 55 9 -85 -94 -29 14 ...
output:
13 1 1 6 4 6 2 1 5 4 22 15 5 1 5 4 1 8 1 2 2 4 3 1 3 12 18 7 4 2 10 1 2 1 1 1 2 5 2 8 3 6 1 5 9 6 2 5 4 1 14 3 1 19 3 1 9 1 2 2 2 21 2 6 2 10 3 7 1 4 1 1 3 1 3 2 4 10 4 4 10 1 1 1 2 2 11 10 2 1 5 10 6 2 19 2 20 3 1 1 1 1 1 1 3 7 2 8 1 1 1 1 3 1 3 1 1 21 19 4 2 2 1 2 7 3 8 3 1 5 6 1 1 1 1 9 2 25 4 4 ...
result:
ok 46128 lines
Test #6:
score: 0
Accepted
time: 460ms
memory: 6100kb
input:
46275 8 3 46093769 -773754553 -392699827 -541568835 749997067 173070491 194887177 -791837957 10 3 -399615581 -974676777 572713394 -115419320 269846582 65640637 415752922 734872927 -935606077 -460599602 14 5 -272962438 -201008512 -221240850 914999800 -819437270 -35566423 709695488 -191248867 80608304...
output:
2 1 5 1 5 4 1 3 5 2 3 7 2 1 7 12 1 7 4 6 1 12 1 2 1 3 3 2 2 2 11 1 3 1 1 12 9 1 6 2 11 1 3 13 6 2 1 2 14 9 11 5 3 1 1 5 2 1 2 5 4 8 2 3 7 1 1 2 8 1 8 1 4 11 1 9 1 2 1 17 1 5 1 4 1 1 1 4 1 1 1 4 4 4 1 1 18 9 1 4 3 11 3 3 1 1 1 13 1 16 1 3 2 1 1 1 4 2 6 8 1 1 3 11 4 1 1 1 1 11 1 1 2 1 4 1 2 1 1 1 12 6...
result:
ok 46275 lines
Test #7:
score: 0
Accepted
time: 507ms
memory: 6036kb
input:
46255 20 7 1 1 -8 -3 1 -1 -4 -2 -7 -3 7 -9 -10 10 -10 -3 2 10 -4 7 22 10 -4 -3 0 -8 -8 6 10 -4 6 8 -7 5 1 0 6 6 -6 -10 -3 -9 -9 -6 8 4 6 9 -10 -6 9 -6 10 9 12 6 4 -7 -4 -7 -3 -10 -1 0 4 -1 10 8 8 6 4 10 2 -2 5 7 -8 -10 17 1 10 -5 -6 7 -4 -7 6 -10 7 -5 -9 -10 1 4 7 8 -3 9 7 6 -6 3 0 4 -8 -6 1 2 22 5 ...
output:
3 2 1 1 1 3 9 2 1 4 2 2 7 1 1 1 1 4 1 2 1 2 1 1 1 6 1 1 3 1 1 1 1 17 2 1 1 2 1 1 1 2 7 11 1 1 1 1 1 1 1 1 2 2 1 1 2 1 3 1 3 3 1 2 1 3 3 13 2 3 4 11 4 4 6 2 3 1 1 2 1 4 2 1 2 6 2 2 1 1 3 10 4 1 1 6 1 2 1 1 1 7 1 1 1 1 3 1 5 1 1 1 2 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 1 1 1 1 1 1 1 1 1 1 1 1 1...
result:
ok 46255 lines
Test #8:
score: 0
Accepted
time: 520ms
memory: 6032kb
input:
46177 24 20 25 14 -46 -61 -64 10 53 -80 -11 91 -59 43 48 -90 -82 -12 -25 72 99 -44 99 21 -92 5 13 12 58 24 -35 93 3 -96 42 6 -43 71 -12 -22 -8 2 1 -1 0 2 1 -93 80 14 3 -86 72 -65 14 -56 -2 -39 43 -87 29 -39 -15 -58 -33 20 4 50 -56 -5 13 -36 -18 73 -64 19 4 44 -58 -98 -44 14 93 63 56 -12 27 2 2 -32 -...
output:
1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 3 1 1 1 2 1 1 1 1 1 1 1 1 1 2 2 8 3 3 7 4 7 2 1 1 1 2 1 1 1 2 1 3 1 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 3 2 1 1 1 1 1 1 1 1 1 1 3 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 4 1 1 4 2 2 2 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 5 1 1 1 1 1 3 2 1 4 2 2 1 1 1 1 1 1 1 1 1 1 8 2 2 1 ...
result:
ok 46177 lines
Test #9:
score: 0
Accepted
time: 513ms
memory: 8104kb
input:
46053 7 2 805503116 -146327397 724584190 939057367 563892810 -321631878 772845285 11 8 -912954459 832035093 613578959 117809616 -850489232 -122333651 247540838 -724606797 -942073171 656161804 14899908 3 2 615417815 642804724 -313818109 20 14 451783792 -731819844 180260358 -9034098 -798871547 2308456...
output:
3 4 3 1 1 1 1 1 2 1 1 2 2 1 1 3 1 1 1 3 2 1 1 1 1 1 9 2 1 2 1 13 1 2 1 6 5 1 1 4 1 5 1 2 1 1 1 1 1 1 1 2 4 1 6 7 1 2 1 2 1 3 4 1 1 3 1 9 11 4 3 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 5 2 3 2 2 13 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 5 1 1 4 1 1 2 1 1 2 1 3 1 1 1 4 1 1 1 1 1 1 4 2 1 2 2 1...
result:
ok 46053 lines
Test #10:
score: -100
Time Limit Exceeded
input:
1484 224 6 -1 5 6 -6 2 -3 9 -7 5 -5 10 -9 -7 5 -5 3 -8 10 -10 -10 -9 -6 10 -10 8 0 -7 -2 -8 10 10 3 -9 -3 -6 -9 0 7 2 -3 4 -3 9 8 9 -1 10 4 0 -3 -4 -6 -4 -5 0 -8 -5 7 0 1 6 -9 -2 -4 0 -5 -10 -5 -5 -6 -10 2 4 -5 6 7 -8 4 -7 -5 -2 -9 -3 -3 4 7 6 -10 -10 9 5 4 9 3 -6 -6 4 -9 -10 9 6 4 6 2 7 -5 4 -9 6 1...
output:
13 2 35 158 15 1 1 1 1 2 75 1 1 1 1 1 2 5 2 86 52 1 12 383 1 3 3 1 1 8 1 4 5 23 2 14 2 7 6 1 15 1 69 1 8 49 18 1 1 4 4 15 7 150 12 91 10 1 2 1 3 2 13 6 2 58 9 52 10 10 299 22 105 3 67 82 1 1 3 18 9 1 3 3 1 4 20 5 2 2 1 2 1 190 19 19 17 95 9 1 19 5 25 4 4 2 1 2 2 1 1 1 2 1 8 3 1 1 1 1 1 1 1 135 4 8 2...