QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#560693 | #5981. Costly Binary Search | yqh2025 | 0 | 1823ms | 46796kb | C++14 | 1.5kb | 2024-09-12 17:23:52 | 2024-09-12 17:23:52 |
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];
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);
for(int i=0;i<10;i++)for(int j=1;j<=n;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<=V;v++){
vector<pair<int,int> >ve;
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});
// cout<<i<<" "<<l<<" "<<r<<endl;
}
}
int mx=0;
sort(ve.begin(),ve.end());
for(int i=1,j=0;i<=n;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--){
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;
return ;
}
}
cout<<0<<endl;
}
signed main(){
int t;cin>>t;
for(int i=1;i<=t;i++)sol(t);
return 0;
}
/*
g++ 1.cpp -o 1 -std=c++14 -O2 -Wall
./1
*/
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1823ms
memory: 46796kb
input:
50 8 5128831164925953487661279378526736416489768154389124821528467927357884749642747626797857463132866343496157991453139582295398452863172464853698678624523849653538713928372648295734165346972222781179687541337591976277864785653638476127839556323849395641196246971351933655287441377531627938395427487...
output:
Case #50: 8 Case #50: 0 Case #50: 0 Case #50: 0 Case #50: 0 Case #50: 0 Case #50: 0 Case #50: 24 Case #50: 0 Case #50: 0 Case #50: 0 Case #50: 0 Case #50: 0 Case #50: 0 Case #50: 0 Case #50: 0 Case #50: 14 Case #50: 0 Case #50: 0 Case #50: 0 Case #50: 0 Case #50: 0 Case #50: 14 Case #50: 9 Case #50:...
result:
wrong answer 1st lines differ - expected: 'Case #1: 8', found: 'Case #50: 8'
Subtask #2:
score: 0
Time Limit Exceeded
Test #2:
score: 0
Time Limit Exceeded
input:
50 647322722753778843259213887674615134214258235986992692879314555957455541351526284343217116351733247781713552149464672262787737941588358671583528664757823365936975517145283412965139791726299864122725212222496898855627124979178341548651669956711341742838725446489235961853391195148929571712449139335...
output:
Case #50: 0 Case #50: 0 Case #50: 119 Case #50: 0 Case #50: 0 Case #50: 0 Case #50: 0 Case #50: 0