QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#128272#5981. Costly Binary Searchgrass8cow8 114ms6268kbC++14814b2023-07-20 20:00:562023-07-20 20:00:58

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-20 20:00:58]
  • 评测
  • 测评结果:8
  • 用时:114ms
  • 内存:6268kb
  • [2023-07-20 20:00:56]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,tl[1010000][10],tr[1010000][10];
char c[1000100];
void sol(int st){
	scanf("%s",c+1);n=strlen(c+1);
	for(int i=1;i<=n;i++)for(int j=0;j<10;j++)tl[i][j]=-n-1,tr[i][j]=n+1;
	int step=0;
	while(tl[1][0]<n){
		step++;
		for(int i=1;i<=n;i++)for(int j=9;j;j--)tl[i][j]=tl[i][j-1],tr[i][j]=tr[i][j-1];
		for(int i=1;i<=n;i++){
			int e=c[i]-'0';
			if(e>step)continue;
			int L=((i==1)?i:tr[i-1][e]),R=((i==n)?i:(tl[i+1][e]));
			L=min(L,i),R=max(R,i);
			if(L<=R)tl[L][0]=max(tl[L][0],R),tr[R][0]=min(tr[R][0],L);
		}
		for(int i=2;i<=n;i++)tl[i][0]=max(tl[i][0],tl[i-1][0]);
		for(int i=n-1;i;i--)tr[i][0]=min(tr[i][0],tr[i+1][0]);
	}
	printf("Case #%d: %d\n",st,step);
} 
int main(){
	int T;cin>>T;for(int i=1;i<=T;i++)sol(i);
	return 0;
} 

詳細信息

Subtask #1:

score: 8
Accepted

Test #1:

score: 8
Accepted
time: 114ms
memory: 6268kb

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...

output:


result: