QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#746580 | #5981. Costly Binary Search | l_615 | 27 ✓ | 11193ms | 83016kb | C++14 | 1.1kb | 2024-11-14 15:02:44 | 2024-11-14 15:02:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define PII pair<int,int>
#define fi first
#define se second
#define MP make_pair
inline int read()
{
int s=0;char c=getchar();
for(;!isdigit(c);c=getchar());
for(;isdigit(c);c=getchar())s=(s<<1)+(s<<3)+(c^48);
return s;
}
const int N=1e6+7;
char s[N];
int L[10][N],R[10][N];
int main()
{
int tt=read(),n;
for(int num=1;num<=tt;num++)
{
scanf("%s",s+1);
n=strlen(s+1);
for(int i=0;i<=9;i++)
for(int j=0;j<=n+1;j++)
L[i][j]=j+1,R[i][j]=j-1;
for(int i=1;i<=n;i++)L[s[i]^48][i]=i,R[s[i]^48][i]=i;
for(int i=0;i<=180;i++)
{
int x=i%10;
if(R[x][1]==n)
{
printf("Case #%d: %d\n",num,i);
break;
}
int y=(x+9)%10,l=0,r=0;
if(i)for(int j=1;j<=n;j++)L[x][j]=min(L[x][j],L[y][j]),R[x][j]=max(R[x][j],R[y][j]);
for(int i=1;i<=n;i++)R[x][i]=max(R[x][i],R[x][i-1]);
for(int i=n-1;i;i--)L[x][i]=min(L[x][i],L[x][i+1]);
for(int i=1;i<=n;i++)
{
y=(x+s[i]-'0')%10;
l=L[x][i-1],r=R[x][i+1];
R[y][l]=max(R[y][l],r);
L[y][r]=min(L[y][r],l);
}
}
}
}
詳細信息
Subtask #1:
score: 8
Accepted
Test #1:
score: 8
Accepted
time: 78ms
memory: 46936kb
input:
50 8 5128831164925953487661279378526736416489768154389124821528467927357884749642747626797857463132866343496157991453139582295398452863172464853698678624523849653538713928372648295734165346972222781179687541337591976277864785653638476127839556323849395641196246971351933655287441377531627938395427487...
output:
Case #1: 8 Case #2: 37 Case #3: 34 Case #4: 37 Case #5: 34 Case #6: 114 Case #7: 126 Case #8: 24 Case #9: 37 Case #10: 103 Case #11: 36 Case #12: 64 Case #13: 37 Case #14: 117 Case #15: 37 Case #16: 35 Case #17: 14 Case #18: 34 Case #19: 36 Case #20: 37 Case #21: 38 Case #22: 39 Case #23: 14 Case #2...
result:
ok 50 lines
Subtask #2:
score: 19
Accepted
Test #2:
score: 19
Accepted
time: 11193ms
memory: 83016kb
input:
50 647322722753778843259213887674615134214258235986992692879314555957455541351526284343217116351733247781713552149464672262787737941588358671583528664757823365936975517145283412965139791726299864122725212222496898855627124979178341548651669956711341742838725446489235961853391195148929571712449139335...
output:
Case #1: 42 Case #2: 43 Case #3: 120 Case #4: 42 Case #5: 43 Case #6: 43 Case #7: 31 Case #8: 43 Case #9: 171 Case #10: 42 Case #11: 39 Case #12: 42 Case #13: 42 Case #14: 44 Case #15: 39 Case #16: 20 Case #17: 180 Case #18: 30 Case #19: 45 Case #20: 43 Case #21: 44 Case #22: 31 Case #23: 83 Case #2...
result:
ok 50 lines
Extra Test:
score: 0
Extra Test Passed