QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#208742 | #6767. Hourly Coding Problem | 275307894a | WA | 1ms | 8152kb | C++14 | 1.3kb | 2023-10-09 20:37:36 | 2023-10-09 20:37:37 |
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 ",x-i);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);printf("\n");
}
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: 0
Wrong Answer
time: 1ms
memory: 8152kb
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:
wrong answer 1st lines differ - expected: '3 3 1', found: '3 3 1 '