QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#708298#5981. Costly Binary Searchfairyqq280 0ms0kbC++141.0kb2024-11-03 21:13:502024-11-03 21:13:51

Judging History

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

  • [2024-11-03 21:13:51]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-11-03 21:13:50]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
using namespace std;
const int N = 1000010, X = 190;
char c[N];
int n, a[N], f[X][N], g[X][N];
void cmx(int &x, int y) {if(x < y) x = y;}
void cmn(int &x, int y) {if(x > y) x = y;}

int main(){
	int T; scanf("%d", &T); rep(_, 1, T){
		scanf("%s", c+1); n = strlen(c+1);
		rep(i, 1, n) a[i] = c[i] ^ 48;
		memset(f, 0, sizeof(f));
		memset(g, 0x3f, sizeof(g));
		rep(i, 1, n) f[0][i] = i-1, g[0][i] = i+1;
		rep(i, 0, X-1) g[i][0] = 1, f[i][n+1] = n;
		rep(k, 0, X-1){
			if(k) rep(i, 1, n)
				cmx(f[k][i], f[k-1][i]), cmn(g[k][i], g[k-1][i]);
			rep(i, 2, n) cmx(f[k][i], f[k][i-1]);
			per(i, n-1, 1) cmn(g[k][i], g[k][i+1]);
			// printf("%d %d\n", k, f[k][1]);
			if(f[k][1] == n) {printf("Case #%d: %d\n", _, k); break;}
			rep(i, 1, n)
				cmx(f[k+a[i]][g[k][i-1]], f[k][i+1]), 
				cmn(g[k+a[i]][f[k][i+1]], g[k][i-1]);
		}
	}
	return 0;
}

详细

Subtask #1:

score: 0
Memory Limit Exceeded

Test #1:

score: 0
Memory Limit Exceeded

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:


Subtask #2:

score: 0
Memory Limit Exceeded

Test #2:

score: 0
Memory Limit Exceeded

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: