QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#202594#7406. Longest Lyndon PrefixScarlett_boyWA 4ms3496kbC++17916b2023-10-06 12:22:552023-10-06 12:22:56

Judging History

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

  • [2023-10-06 12:22:56]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:3496kb
  • [2023-10-06 12:22:55]
  • 提交

answer

#include<bits/stdc++.h>

typedef long long ll;

using namespace std;
const int N = 1e5 + 50;


int n;
char s[N];
int to[N];

void solve() {
    cin >> n >> (s + 1);
    to[n] = n;
    for (int i = n - 1; i >= 1; i--) {
        if (s[i] == s[i + 1]) to[i] = to[i + 1];
        else to[i] = i;
    }
    for (int i = 1; i <= n; i++) {
        int p = i;
        if (to[p] == n) {
            cout << 1 << " \n"[i == n];
            continue;
        }
        while (p <= n) {
            p = to[p];
            if (p == n) break;
            if (s[i] < s[p + 1]) {
                p++;
            } else break;
        }
        cout << p - i + 1 << " \n"[i == n];
    }
}


int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int _ = 1;
    cin >> _;
    for (int o = 1; o <= _; o++) {
        solve();
    }
    return 0;
}
/*



1
5
abcbd

 */

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3496kb

input:

3
3
aaa
3
aab
3
cba

output:

1 1 1
3 2 1
1 1 1

result:

ok 9 numbers

Test #2:

score: -100
Wrong Answer
time: 4ms
memory: 3356kb

input:

10000
10
ababbbbaaa
6
aabbaa
3
abb
9
bababbbbb
9
abbaaaaaa
8
ababbaab
7
abbbbbb
7
aaabaaa
2
ba
10
abaababbab
2
ab
1
a
1
a
5
ababa
6
aaabba
2
ba
4
abba
5
bbbba
9
aabbbbbaa
10
baaabaaaba
10
babbbbbbaa
9
babaaabba
1
b
6
abbbaa
7
aaaaaab
10
baaaaabaaa
9
bbbbabbba
3
bbb
8
abaababa
7
bbbbaba
5
ababb
1
b
7...

output:

2 1 5 4 3 2 1 1 1 1
4 3 2 1 1 1
3 1 1
1 2 1 6 1 1 1 1 1
3 2 1 1 1 1 1 1 1
2 1 3 2 1 3 2 1
7 1 1 1 1 1 1
4 3 2 1 1 1 1
1 1
2 1 3 2 1 3 2 1 2 1
2 1
1
1
2 1 2 1 1
5 4 3 2 1 1
1 1
3 2 1 1
4 3 2 1 1
7 6 5 4 3 2 1 1 1
1 4 3 2 1 4 3 2 1 1
1 7 6 5 4 3 2 1 1 1
1 2 1 5 4 3 2 1 1
1
4 3 2 1 1 1
7 6 5 4 3 2 1
1 ...

result:

wrong answer 1st numbers differ - expected: '7', found: '2'