QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#562287#5981. Costly Binary SearchZ_drj0 25205ms86404kbC++141.8kb2024-09-13 16:29:422024-09-13 16:29:44

Judging History

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

  • [2024-09-13 16:29:44]
  • 评测
  • 测评结果:0
  • 用时:25205ms
  • 内存:86404kb
  • [2024-09-13 16:29:42]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

const int N = 1E6 + 5;

int n;
std::string s;
int a[N];
int L[10][N], R[10][N];
// int f[300][300];

void solve() {
	std::cin >> s;
	n = s.length();
	
	for (int i = 1; i <= n; i++) {
		a[i] = s[i - 1] - '0';
		// f[i][i] = a[i];
	}

	// for (int i = 1; i < n; i++) {
	// 	f[i][i + 1] = a[i] + a[i + 1];
	// }

	// for (int len = 3; len <= n; len++) {
	// 	for (int l = 1, r = len; r <= n; ++l, ++r) {
	// 		f[l][r] = 1E9;
	// 		for (int k = l + 1; k < r; k++) {
	// 			f[l][r] = std::min(f[l][r], a[k] + std::max(f[l][k - 1], f[k + 1][r]));
	// 		}
	// 	}
	// }

	// for (int i = 1; i <= n; i++) {
	// 	for (int j = i + 1; j <= n; j++) {
	// 		std::cerr << f[i][j] << " ";
	// 	}
	// 	std::cerr << "\n";
	// }

	// std::cerr << f[1][n] << "\n";

	int ans = 1E9;
	for (int c = 0; c <= 180; c++) {
		int now = c % 10;
		for (int i = 0; i <= n + 1; i++) {
			L[now][i] = i + 1;
			R[now][i] = i - 1;
		}

		for (int i = 1; i <= n; i++) {
			if (a[i] <= now) {
				int x = L[(now - a[i]) % 10][i - 1], y = R[(now - a[i]) % 10][i + 1];
				L[now][y] = std::min(L[now][y], x);
				R[now][x] = std::max(R[now][x], y);
			}
		}

		for (int i = n; i >= 1; i--) {
			L[now][i] = std::min(L[now][i], L[now][i + 1]);
		}
		
		for (int i = 1; i <= n; i++) {
			R[now][i] = std::max(R[now][i], R[now][i - 1]);
		}

		for (int i = 1; i <= n; i++) {
			if (L[now][i - 1] <= 1 && R[now][i + 1] >= n) {
				ans = std::min(ans, c + a[i]);
			}
		}
	}

	std::cout << ans << "\n";
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int T;
	std::cin >> T;

	for (int i = 1; i <= T; i++) {
		std::cout << "Case #" << i << ": ";
		solve(); 
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 246ms
memory: 46676kb

input:

50
8
5128831164925953487661279378526736416489768154389124821528467927357884749642747626797857463132866343496157991453139582295398452863172464853698678624523849653538713928372648295734165346972222781179687541337591976277864785653638476127839556323849395641196246971351933655287441377531627938395427487...

output:

Case #1: 8
Case #2: 1000000000
Case #3: 1000000000
Case #4: 1000000000
Case #5: 1000000000
Case #6: 1000000000
Case #7: 1000000000
Case #8: 1000000000
Case #9: 1000000000
Case #10: 1000000000
Case #11: 1000000000
Case #12: 1000000000
Case #13: 1000000000
Case #14: 1000000000
Case #15: 1000000000
Cas...

result:

wrong answer 2nd lines differ - expected: 'Case #2: 37', found: 'Case #2: 1000000000'

Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 25205ms
memory: 86404kb

input:

50
647322722753778843259213887674615134214258235986992692879314555957455541351526284343217116351733247781713552149464672262787737941588358671583528664757823365936975517145283412965139791726299864122725212222496898855627124979178341548651669956711341742838725446489235961853391195148929571712449139335...

output:

Case #1: 1000000000
Case #2: 1000000000
Case #3: 1000000000
Case #4: 1000000000
Case #5: 1000000000
Case #6: 1000000000
Case #7: 1000000000
Case #8: 1000000000
Case #9: 1000000000
Case #10: 1000000000
Case #11: 1000000000
Case #12: 1000000000
Case #13: 1000000000
Case #14: 1000000000
Case #15: 10000...

result:

wrong answer 1st lines differ - expected: 'Case #1: 42', found: 'Case #1: 1000000000'