QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#561198 | #5981. Costly Binary Search | 123456xwd | 8 | 107ms | 9944kb | C++14 | 1.3kb | 2024-09-12 21:08:41 | 2024-09-12 21:08:42 |
Judging History
answer
#include<bits/stdc++.h>
#define ull unsigned long long
#define p_b push_back
#define m_p make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define ls k<<1
#define rs k<<1|1
#define mid ((l+r)>>1)
#define gcd __gcd
#define lowbit(x) (x&(-x))
using namespace std;
int rd(){
int x=0,f=1; char ch=getchar();
for(;ch<'0'||ch>'9';ch=getchar())if (ch=='-') f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
return x*f;
}
void write(int x){
if(x>9) write(x/10);
putchar('0'+x%10);
}
const int N=1e6+5,INF=0x3f3f3f3f,mod=998244353;
int n,a[N],L[N][10],R[N][10];
char s[N];
int solve(){
scanf("%s",s+1);
n=strlen(s+1);
for(int i=1;i<=n;i++) a[i]=(s[i]-'0');
for(int c=0;c<=180;c++){
int now=c%10;
for(int i=0;i<=n+1;i++) L[i][now]=i+1,R[i][now]=i-1;
for(int k=1;k<=n;k++){
if(c>=a[k]){
int x=L[k-1][(c-a[k])%10],y=R[k+1][(c-a[k])%10];
L[y][now]=min(L[y][now],x);
R[x][now]=max(R[x][now],y);
}
}
for(int i=n-1;i>=1;i--)L[i][now]=min(L[i][now],L[i+1][now]);
for(int i=2;i<=n;i++) R[i][now]=max(R[i][now],R[i-1][now]);
if(R[1][now]>=n||L[n][now]<=1) return c;
}
return 0;
}
int main(){
int T=rd(),t=0;
while(T--){
printf("Case #%d: %d\n",++t,solve());
}
return 0;
}
詳細信息
Subtask #1:
score: 8
Accepted
Test #1:
score: 8
Accepted
time: 107ms
memory: 9944kb
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: 0
Time Limit Exceeded
Test #2:
score: 0
Time Limit Exceeded
input:
50 647322722753778843259213887674615134214258235986992692879314555957455541351526284343217116351733247781713552149464672262787737941588358671583528664757823365936975517145283412965139791726299864122725212222496898855627124979178341548651669956711341742838725446489235961853391195148929571712449139335...