QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#163050#5981. Costly Binary SearchLCX75627 ✓10994ms86648kbC++141.3kb2023-09-03 19:35:312023-09-03 19:35:31

Judging History

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

  • [2023-09-03 19:35:31]
  • 评测
  • 测评结果:27
  • 用时:10994ms
  • 内存:86648kb
  • [2023-09-03 19:35:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define fir first
#define sec second
typedef vector <int> vi;
typedef vector <ll> vl;

const int maxn = 1e6 + 10;
int n, mnl[10][maxn], mxr[10][maxn], a[maxn];
char s[maxn];
void init(int p) {
    for (int i = 0; i <= n + 1; ++i) mnl[p][i] = i + 1, mxr[p][i] = i - 1;
}
void work() {
    scanf("%s", s + 1), n = strlen(s + 1);
    for (int i = 1; i <= n; ++i) a[i] = s[i] - '0';
    memset(mnl, 0, sizeof mnl);
    memset(mxr, 0, sizeof mxr);
    init(0);
    for (int x = 1; ; ++x) {
        int p = x % 10;
        init(p);
        for (int i = 1; i <= n; ++i) if (x >= a[i]) {
            int q = (x + 10 - a[i]) % 10;
            int l = mnl[q][i - 1], r = mxr[q][i + 1];
            mnl[p][r] = min(mnl[p][r], l);
            mxr[p][l] = max(mxr[p][l], r);
        }
        for (int i = 2; i <= n; ++i) mxr[p][i] = max(mxr[p][i], mxr[p][i - 1]);
        for (int i = n - 1; i >= 1; --i) mnl[p][i] = min(mnl[p][i], mnl[p][i + 1]);
        if (mxr[p][1] >= n || mnl[p][n] <= 1)
            return printf("%d\n", x), void();
    }
}

int main() {
    int T; scanf("%d", &T);
    for (int i = 1; i <= T; ++i) printf("Case #%d: ", i), work();
    return 0;
}

詳細信息

Subtask #1:

score: 8
Accepted

Test #1:

score: 8
Accepted
time: 379ms
memory: 83284kb

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: 10994ms
memory: 86648kb

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