QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#456652 | #8089. Flaaffy | sszcdjr | WA | 553ms | 43076kb | C++20 | 1.9kb | 2024-06-28 10:23:57 | 2024-06-28 10:23:58 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned ll;
const int N=1e5,n=N-1,K=50;
int T,L,R,f[K][N],g[K][N];
int find(int Lim,int Tar,int k){
static const int M=6;
static int lim[M],tar[M],f[M];
for(int x=Lim,i=1;i<M;x/=10)lim[i++]=x%10;
for(int x=Tar,i=1;i<M;x/=10)tar[i++]=x%10;
f[0]=0;
for(int i=1;i<M;i++){
if(tar[i]<lim[i])f[i]=0;
else if(tar[i]==lim[i])f[i]=f[i-1];
else f[i]=f[i-1]+1;
if(lim[i]>0)f[i]=min(f[i],1);
}
if(f[1]>k)return -1;
int cur=1,res=0;
for(int i=M-1;i>=1;i--){
if(cur){
if(k>=(tar[i]!=lim[i])+f[i-1]){
res=res*10+lim[i],k-=tar[i]!=lim[i];
}else if(lim[i]>0&&k>=(tar[i]!=lim[i]-1)){
res=res*10+lim[i]-1,k-=tar[i]!=lim[i]-1,cur=0;
}else if(tar[i]<lim[i]){
res=res*10+tar[i],cur=0;
}else assert(0);
}else{
int val=k?9:tar[i];
res=res*10+val,k-=val!=tar[i];
}
}
return res;
}
int dis[N];
void init(){
for(int t=0;t<K;t++){
for(int i=0;i<=n;i++)f[t][i]=min(i+1,n);
for(int k=1;k<=5&&k<t;k++){
for(int i=0,x=0;i<=n;i++){
for(;x<n&&g[t-k-1][x+1]<=i+1;x++);
int p=find(x,i,k);
if(p>=i)f[t][i]=max(f[t][i],f[t-k-1][p]);
}
}
for(int i=0;i<=n;i++)g[t][i]=n-f[t][n-i];
// if(f[t][0]>=n)debug(t);
}
for(int i=0;i<=n;i++){
for(int x=i;x;x/=10)dis[i]+=x%10>0;
}
}
int calc(int x,int y){
int l=-1,r=K-1,mid;
for(;l+1<r;){
mid=(l+r)>>1;
if(f[mid][x]>=y)r=mid;
else l=mid;
}
// debug("calc",x,y,r);
return r;
}
void get(){
cin>>L>>R;
if(L==R)return puts("0"),void();
int ans=K;
for(int i=L;i<=R;i++){
ans=min(ans,max(calc(i,R),calc(n-i,n-L))+dis[i]+1);
}
cout<<ans<<endl;
}
int main(){
for(init(),cin>>T;T--;)get();
return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 549ms
memory: 43076kb
input:
3 97 107 12043 12045 61 69
output:
6 5 7
result:
ok 3 number(s): "6 5 7"
Test #2:
score: -100
Wrong Answer
time: 553ms
memory: 42984kb
input:
36 19997 20007 9997 10012 59813 60010 39993 40004 89878 90009 9909 10028 89898 90005 373 3773 93012 94646 93013 94617 7171 10601 7546 10546 15290 20600 446 16446 6440 97000 9713 12175 6000 37766 55115 76767 16 161 1713 2062 1 99999 1024 65536 13000 99999 49999 50000 70000 70001 27999 28001 27998 280...
output:
8 9 19 10 19 19 18 28 28 28 29 29 32 35 41 28 37 37 17 21 42 40 41 2 2 3 6 4 6 2 14 2 4 5 4 4
result:
wrong answer 10th numbers differ - expected: '27', found: '28'