QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#561087 | #5981. Costly Binary Search | yqh2025 | 0 | 40ms | 6284kb | C++14 | 1.7kb | 2024-09-12 20:02:46 | 2024-09-12 20:02:47 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10,V=180;
int n,c[N],id[V+10];
int L[12][N],R[12][N];
int s1[N],s2[N];
bool cmp(pair<int,int>x,pair<int,int>y){return x.second>y.second;}
void sol(int T){
static char ch[N];scanf("%s",ch+1);
n=strlen(ch+1);if(n>10000)return;
for(int i=0;i<=10;i++)for(int j=0;j<=n+1;j++)L[i][j]=R[i][j]=0;
for(int i=1;i<=n;i++)c[i]=ch[i]-'0';
for(int i=0;i<=n+1;i++)L[0][i]=i+1,R[0][i]=i-1;
for(int i=0;i<9;i++)id[i]=i;
for(int i=10;i<=V;i++)id[i]=id[i-10];
cout<<"Case #"<<T<<": ";
for(int v=1;;v++){
// vector<pair<int,int> >ve;
for(int i=0;i<=n+1;i++)s1[i]=0,s2[i]=n+1;
for(int i=1;i<=n;i++){
if(v>=c[i]){
int l=L[id[v-c[i]]][i-1],r=R[id[v-c[i]]][i+1];
// ve.push_back({l,r});
s1[l]=max(s1[l],r);
s2[r]=min(s2[r],l);
// cout<<i<<" "<<l<<" "<<r<<endl;
}
}
int mx=0;
// sort(ve.begin(),ve.end());
for(int i=1,j=0;i<=n;i++){
mx=max(mx,s1[i]);
// while(j<ve.size()&&ve[j].first<=i)mx=max(mx,ve[j].second),j++;
R[id[v]][i]=mx;
}
int mi=n;
// sort(ve.begin(),ve.end(),cmp);
// for(pair<int,int>i:ve){
// cout<<i.first<<" "<<i.second<<" ";
// }cout<<endl;
for(int i=n,j=0;i>=0;i--){
mi=min(mi,s2[i]);
// while(j<ve.size()&&ve[j].second>=i)mi=min(mi,ve[j].first),j++;
L[id[v]][i]=mi;
}
// for(int i=1;i<=n;i++)cout<<L[id[v]][i]<<" ";
// cout<<" ";
// for(int i=1;i<=n;i++)cout<<R[id[v]][i]<<" ";
// cout<<endl;
if(R[id[v]][1]==n){
cout<<v<<endl;
memset(L,0,sizeof(L));
memset(R,0,sizeof(R));
return ;
}
}
}
signed main(){
int t;cin>>t;
for(int i=1;i<=t;i++)sol(i);
return 0;
}
/*
g++ 1.cpp -o 1 -std=c++14 -O2 -Wall
./1
*/
詳細信息
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
input:
50 8 5128831164925953487661279378526736416489768154389124821528467927357884749642747626797857463132866343496157991453139582295398452863172464853698678624523849653538713928372648295734165346972222781179687541337591976277864785653638476127839556323849395641196246971351933655287441377531627938395427487...
output:
Case #1: 8
result:
Subtask #2:
score: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 40ms
memory: 6284kb
input:
50 647322722753778843259213887674615134214258235986992692879314555957455541351526284343217116351733247781713552149464672262787737941588358671583528664757823365936975517145283412965139791726299864122725212222496898855627124979178341548651669956711341742838725446489235961853391195148929571712449139335...
output:
result:
wrong answer 1st lines differ - expected: 'Case #1: 42', found: ''