QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#468623#6224. 节日庆典little_sun100 ✓335ms18564kbC++141.6kb2024-07-08 21:52:462024-07-08 21:52:46

Judging History

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

  • [2024-07-08 21:52:46]
  • 评测
  • 测评结果:100
  • 用时:335ms
  • 内存:18564kb
  • [2024-07-08 21:52:46]
  • 提交

answer

#include <bits/stdc++.h>

#define R register
#define ll long long
#define sum(a, b, mod) (((a) + (b)) % mod)
#define meow(cat...) fprintf(stderr, cat)

const int MaxN = 3e6 + 10;

char s[MaxN];
int n, z[MaxN];

void exkmp()
{
    int l = 0, r = 0; z[1] = n;
    for(int i = 2; i <= n; i++)
    {
        if(r > i) z[i] = std::min(z[i - l + 1], r - i + 1);
        while(i + z[i] <= n && s[i + z[i]] == s[z[i] + 1])
            z[i]++;
        if(i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
    }
}

std::vector<int> now, tmp;

signed main()
{   
    scanf("%s", s + 1);
    n = strlen(s + 1), exkmp();
    for(int i = 1; i <= n; i++)
    {
        now.push_back(i), tmp.clear();
        for(auto p : now)
        {
            int flag = 1;
            while(!tmp.empty())
            {
                int q = tmp.back();
                if(s[i] > s[q + i - p]) flag = 0;
                if(s[i] >= s[q + i - p]) break;
                tmp.pop_back();
            }
            if(flag && (tmp.empty() || i - p + 1 < p - tmp.back()))
                tmp.push_back(p);
        }
        now = tmp; int pos = now[0];
        for(int j = 1; j < now.size(); j++)
        {
            int x = now[j], k = pos + i - x;
            if(z[k + 1] >= i - k)
            {
                int l = i - k;
                if(z[l + 1] < x - l - 1 && s[l + z[l + 1] + 1] < s[z[l + 1] + 1])
                    pos = x;
            }    
            else if(s[z[k + 1] + 1] < s[k + z[k + 1] + 1])
                pos = x;
        }
        printf("%d ", pos);
    }
    return 0;
}

详细

Test #1:

score: 10
Accepted
time: 0ms
memory: 6000kb

input:

cabacabacaccabbbaa

output:

1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 17 

result:

ok 18 numbers

Test #2:

score: 10
Accepted
time: 0ms
memory: 5952kb

input:

cabacabacbaaabbccccaabbabbccabbbbbbbcaccbcbcccbbbccbccbbcccabacbacccbbcacbcabcbcbabbacbccbacbbbbbbaacbbbcccbbcccbbaacaccababaacacccbbbabbbcaaaabcabaacabcacaabbacabcbaccbbbbbcaacccabcacbbbabbaccabaccbbaacccababbacbaacaaabbbbabbbbbbbbcacbabaabababbbacabcbabacbccaaacbabcaaccbbcbacaaccbacbabaccaccbcbcbb...

output:

1 2 2 2 2 2 2 2 2 2 2 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11...

result:

ok 1000 numbers

Test #3:

score: 10
Accepted
time: 1ms
memory: 5956kb

input:

cabacabacbbaaaacbbabcbaaacbabcaaaacccaabaacbcccabbabcabbabcaacbccbbbcbbaabbabaabcbbaaacababccbbbbaacccbabbbcbbababcbbbaaabbbbcbcbbcbbacaaccbbaacbbcbccacaaabaccbccbaacbaaccaccacacbbcaacaacccbbabbbabbaaaacabcbaaacccbcacbabbaaccaccbbcbcbbccabbcbbababaaccabccbabaacacabcaacccbaccccacccbcbccccbabcbaccbcbc...

output:

1 2 2 2 2 2 2 2 2 2 2 2 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 31 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 ...

result:

ok 1000 numbers

Test #4:

score: 10
Accepted
time: 7ms
memory: 6736kb

input:

cabacabaacbbbcbaaacbbacbcccbccaacbcaaaacabcbcbbcabaabcbccbabcabcbacbaccaaccaccbccacbcaacaaaaabbaabcabacacbcbaccacabcbcccabcbbcccbbcccbaccccbcbabcccbcabacabcbaccacababbcabcaccaaabcbacccaabaaabcacacacbaacbccacccccaacaaabbbcabaabbbabbcccbccbccaabccaacabcacbbcabaccaacaacbacbcabcaccbababbaaababaaaabcaaba...

output:

1 2 2 2 2 2 2 2 8 8 8 8 8 8 8 8 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 89 89 89 89 89 89 89 89 89 89 89 89 89 89 8...

result:

ok 200000 numbers

Test #5:

score: 10
Accepted
time: 4ms
memory: 5920kb

input:

yzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxz...

output:

1 1 3 1 5 1 7 1 9 1 11 1 13 1 15 1 17 1 19 1 21 1 23 1 25 1 27 1 29 1 31 1 33 1 35 1 37 1 39 1 41 1 43 1 45 1 47 1 49 1 51 1 53 1 55 1 57 1 59 1 61 1 63 1 65 1 67 1 69 1 71 1 73 1 75 1 77 1 79 1 81 1 83 1 85 1 87 1 89 1 91 1 93 1 95 1 97 1 99 1 101 1 103 1 105 1 107 1 109 1 111 1 113 1 115 1 117 1 1...

result:

ok 49400 numbers

Test #6:

score: 10
Accepted
time: 93ms
memory: 10092kb

input:

tutvtutwtutvtutxtutvtutwtutvtutytutvtutwtutvtutxtutvtutwtutvtuttutvtutwtutvtutxtutvtutwtutvtutytutvtutwtutvtutxtutvtutwtutvtuttutvtutwtutvtutxtutvtutwtutvtutytutvtutwtutvtutxtutvtutwtutvtuttutvtutwtutvtutxtutvtutwtutvtutytutvtutwtutvtutxtutvtutwtutvtuttutvtutwtutvtutxtutvtutwtutvtutytutvtutwtutvtutx...

output:

1 1 3 1 5 5 7 1 9 9 11 9 13 13 15 1 17 17 19 17 21 21 23 17 25 25 27 25 29 29 31 1 33 33 35 33 37 37 39 33 41 41 43 41 45 45 47 33 49 49 51 49 53 53 55 49 57 57 59 57 61 61 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 6...

result:

ok 1000000 numbers

Test #7:

score: 10
Accepted
time: 94ms
memory: 8032kb

input:

stsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsystsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsstsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsystsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsstsustsvstsustswstsustsvstsustsxstsustsvstsust...

output:

1 1 3 1 5 5 7 1 9 9 11 9 13 13 15 1 17 17 19 17 21 21 23 17 25 25 27 25 29 29 31 1 33 33 35 33 37 37 39 33 41 41 43 41 45 45 47 33 49 49 51 49 53 53 55 49 57 57 59 57 61 61 63 1 65 65 67 65 69 69 71 65 73 73 75 73 77 77 79 65 81 81 83 81 85 85 87 81 89 89 91 89 93 93 95 65 97 97 99 97 101 101 103 97...

result:

ok 1000000 numbers

Test #8:

score: 10
Accepted
time: 335ms
memory: 13432kb

input:

stsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsystsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsstsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsystsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsstsustsvstsustswstsustsvstsustsxstsustsvstsust...

output:

1 1 3 1 5 5 7 1 9 9 11 9 13 13 15 1 17 17 19 17 21 21 23 17 25 25 27 25 29 29 31 1 33 33 35 33 37 37 39 33 41 41 43 41 45 45 47 33 49 49 51 49 53 53 55 49 57 57 59 57 61 61 63 1 65 65 67 65 69 69 71 65 73 73 75 73 77 77 79 65 81 81 83 81 85 85 87 81 89 89 91 89 93 93 95 65 97 97 99 97 101 101 103 97...

result:

ok 3000000 numbers

Test #9:

score: 10
Accepted
time: 319ms
memory: 18564kb

input:

abacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabahabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabaiabacabadabacabaeabacabadabacabafabacabadabac...

output:

1 1 3 1 5 5 7 1 9 9 11 9 13 13 15 1 17 17 19 17 21 21 23 17 25 25 27 25 29 29 31 1 33 33 35 33 37 37 39 33 41 41 43 41 45 45 47 33 49 49 51 49 53 53 55 49 57 57 59 57 61 61 63 1 65 65 67 65 69 69 71 65 73 73 75 73 77 77 79 65 81 81 83 81 85 85 87 81 89 89 91 89 93 93 95 65 97 97 99 97 101 101 103 97...

result:

ok 3000000 numbers

Test #10:

score: 10
Accepted
time: 267ms
memory: 11000kb

input:

stsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsystsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsstsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsystsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsstsustsvstsustswstsustsvstsustsxstsustsvstsust...

output:

1 1 3 1 5 5 7 1 9 9 11 9 13 13 15 1 17 17 19 17 21 21 23 17 25 25 27 25 29 29 31 1 33 33 35 33 37 37 39 33 41 41 43 41 45 45 47 33 49 49 51 49 53 53 55 49 57 57 59 57 61 61 63 1 65 65 67 65 69 69 71 65 73 73 75 73 77 77 79 65 81 81 83 81 85 85 87 81 89 89 91 89 93 93 95 65 97 97 99 97 101 101 103 97...

result:

ok 3000000 numbers

Extra Test:

score: 0
Extra Test Passed