Submission #39727257
Source Code Expand
#include <bits/stdc++.h> using i64 = long long; struct SuffixArray { int n; std::vector<int> sa, rk, lc; SuffixArray(const std::string &s) { n = s.length(); sa.resize(n); lc.resize(n - 1); rk.resize(n); std::iota(sa.begin(), sa.end(), 0); std::sort(sa.begin(), sa.end(), [&](int a, int b) {return s[a] < s[b];}); rk[sa[0]] = 0; for (int i = 1; i < n; ++i) rk[sa[i]] = rk[sa[i - 1]] + (s[sa[i]] != s[sa[i - 1]]); int k = 1; std::vector<int> tmp, cnt(n); tmp.reserve(n); while (rk[sa[n - 1]] < n - 1) { tmp.clear(); for (int i = 0; i < k; ++i) tmp.push_back(n - k + i); for (auto i : sa) if (i >= k) tmp.push_back(i - k); std::fill(cnt.begin(), cnt.end(), 0); for (int i = 0; i < n; ++i) ++cnt[rk[i]]; for (int i = 1; i < n; ++i) cnt[i] += cnt[i - 1]; for (int i = n - 1; i >= 0; --i) sa[--cnt[rk[tmp[i]]]] = tmp[i]; std::swap(rk, tmp); rk[sa[0]] = 0; for (int i = 1; i < n; ++i) rk[sa[i]] = rk[sa[i - 1]] + (tmp[sa[i - 1]] < tmp[sa[i]] || sa[i - 1] + k == n || tmp[sa[i - 1] + k] < tmp[sa[i] + k]); k *= 2; } for (int i = 0, j = 0; i < n; ++i) { if (rk[i] == 0) { j = 0; } else { for (j -= j > 0; i + j < n && sa[rk[i] - 1] + j < n && s[i + j] == s[sa[rk[i] - 1] + j]; ) ++j; lc[rk[i] - 1] = j; } } } }; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::string S; std::cin >> S; int K; std::cin >> K; int N = S.size(); if (std::count(S.begin(), S.end(), 'a') + K >= N) { std::cout << std::string(N - K, 'a') << "\n"; return 0; } SuffixArray sa(S); int cnt = 0; int len = 0, p = 0; for (int i = 0; i < N; i++) { int v = i - cnt + K; if (cnt > K) { break; } if (v > len || (v == len && sa.rk[i] < sa.rk[p])) { len = v; p = i; } cnt += (S[i] != 'a'); } auto ans = std::string(len, 'a') + S.substr(p); std::cout << ans << "\n"; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - アメージングな文字列は、きみが作る! |
User | jiangly |
Language | C++ (GCC 9.2.1) |
Score | 100 |
Code Size | 2551 Byte |
Status | AC |
Exec Time | 83 ms |
Memory | 9460 KiB |
Judge Result
Set Name | Sample | Subtask1 | Subtask2 | Subtask3 | All | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 10 / 10 | 10 / 10 | 20 / 20 | 60 / 60 | ||||||||||
Status |
|
|
|
|
|
Set Name | Test Cases |
---|---|
Sample | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt |
Subtask1 | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 10_rand_01.txt, 10_rand_02.txt, 10_rand_03.txt, 10_rand_04.txt, 10_rand_05.txt, 20_hand_01.txt, 20_hand_02.txt, 20_hand_03.txt, 20_hand_04.txt, 20_hand_05.txt |
Subtask2 | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 10_rand_01.txt, 10_rand_02.txt, 10_rand_03.txt, 10_rand_04.txt, 10_rand_05.txt, 20_hand_01.txt, 20_hand_02.txt, 20_hand_03.txt, 20_hand_04.txt, 20_hand_05.txt, 40_rand_01.txt, 40_rand_02.txt, 40_rand_03.txt, 40_rand_04.txt, 40_rand_05.txt, 40_rand_06.txt, 40_rand_07.txt, 40_rand_08.txt, 40_rand_09.txt, 40_rand_10.txt, 50_hand_01.txt, 50_hand_02.txt, 50_hand_03.txt, 50_hand_04.txt, 50_hand_05.txt |
Subtask3 | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 10_rand_01.txt, 10_rand_02.txt, 10_rand_03.txt, 10_rand_04.txt, 10_rand_05.txt, 20_hand_01.txt, 20_hand_02.txt, 20_hand_03.txt, 20_hand_04.txt, 20_hand_05.txt, 40_rand_01.txt, 40_rand_02.txt, 40_rand_03.txt, 40_rand_04.txt, 40_rand_05.txt, 40_rand_06.txt, 40_rand_07.txt, 40_rand_08.txt, 40_rand_09.txt, 40_rand_10.txt, 50_hand_01.txt, 50_hand_02.txt, 50_hand_03.txt, 50_hand_04.txt, 50_hand_05.txt, 60_rand_01.txt, 60_rand_02.txt, 60_rand_03.txt, 60_rand_04.txt, 60_rand_05.txt, 60_rand_06.txt, 60_rand_07.txt, 60_rand_08.txt, 70_hand_01.txt, 70_hand_02.txt, 70_hand_03.txt, 70_hand_04.txt, 70_hand_05.txt, 70_hand_06.txt, 70_hand_07.txt |
All | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 10_rand_01.txt, 10_rand_02.txt, 10_rand_03.txt, 10_rand_04.txt, 10_rand_05.txt, 20_hand_01.txt, 20_hand_02.txt, 20_hand_03.txt, 20_hand_04.txt, 20_hand_05.txt, 40_rand_01.txt, 40_rand_02.txt, 40_rand_03.txt, 40_rand_04.txt, 40_rand_05.txt, 40_rand_06.txt, 40_rand_07.txt, 40_rand_08.txt, 40_rand_09.txt, 40_rand_10.txt, 50_hand_01.txt, 50_hand_02.txt, 50_hand_03.txt, 50_hand_04.txt, 50_hand_05.txt, 60_rand_01.txt, 60_rand_02.txt, 60_rand_03.txt, 60_rand_04.txt, 60_rand_05.txt, 60_rand_06.txt, 60_rand_07.txt, 60_rand_08.txt, 70_hand_01.txt, 70_hand_02.txt, 70_hand_03.txt, 70_hand_04.txt, 70_hand_05.txt, 70_hand_06.txt, 70_hand_07.txt, 80_rand_01.txt, 80_rand_02.txt, 80_rand_03.txt, 80_rand_04.txt, 80_rand_05.txt, 80_rand_06.txt, 80_rand_07.txt, 80_rand_08.txt, 80_rand_09.txt, 80_rand_10.txt, 90_hand_01.txt, 90_hand_02.txt, 90_hand_03.txt, 90_hand_04.txt, 90_hand_05.txt, 90_hand_06.txt, 90_hand_07.txt, 90_hand_08.txt, 90_hand_09.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_example_01.txt | AC | 7 ms | 3376 KiB |
00_example_02.txt | AC | 2 ms | 3488 KiB |
00_example_03.txt | AC | 2 ms | 3520 KiB |
10_rand_01.txt | AC | 2 ms | 3468 KiB |
10_rand_02.txt | AC | 2 ms | 3476 KiB |
10_rand_03.txt | AC | 2 ms | 3480 KiB |
10_rand_04.txt | AC | 2 ms | 3416 KiB |
10_rand_05.txt | AC | 2 ms | 3512 KiB |
20_hand_01.txt | AC | 2 ms | 3460 KiB |
20_hand_02.txt | AC | 2 ms | 3372 KiB |
20_hand_03.txt | AC | 2 ms | 3516 KiB |
20_hand_04.txt | AC | 3 ms | 3468 KiB |
20_hand_05.txt | AC | 2 ms | 3516 KiB |
40_rand_01.txt | AC | 2 ms | 3552 KiB |
40_rand_02.txt | AC | 3 ms | 3476 KiB |
40_rand_03.txt | AC | 2 ms | 3516 KiB |
40_rand_04.txt | AC | 3 ms | 3540 KiB |
40_rand_05.txt | AC | 2 ms | 3544 KiB |
40_rand_06.txt | AC | 2 ms | 3416 KiB |
40_rand_07.txt | AC | 2 ms | 3516 KiB |
40_rand_08.txt | AC | 2 ms | 3548 KiB |
40_rand_09.txt | AC | 2 ms | 3504 KiB |
40_rand_10.txt | AC | 2 ms | 3556 KiB |
50_hand_01.txt | AC | 2 ms | 3512 KiB |
50_hand_02.txt | AC | 2 ms | 3516 KiB |
50_hand_03.txt | AC | 2 ms | 3452 KiB |
50_hand_04.txt | AC | 3 ms | 3552 KiB |
50_hand_05.txt | AC | 2 ms | 3424 KiB |
60_rand_01.txt | AC | 2 ms | 3536 KiB |
60_rand_02.txt | AC | 2 ms | 3544 KiB |
60_rand_03.txt | AC | 2 ms | 3492 KiB |
60_rand_04.txt | AC | 2 ms | 3396 KiB |
60_rand_05.txt | AC | 2 ms | 3488 KiB |
60_rand_06.txt | AC | 2 ms | 3432 KiB |
60_rand_07.txt | AC | 2 ms | 3476 KiB |
60_rand_08.txt | AC | 2 ms | 3536 KiB |
70_hand_01.txt | AC | 2 ms | 3560 KiB |
70_hand_02.txt | AC | 2 ms | 3524 KiB |
70_hand_03.txt | AC | 2 ms | 3404 KiB |
70_hand_04.txt | AC | 2 ms | 3568 KiB |
70_hand_05.txt | AC | 2 ms | 3496 KiB |
70_hand_06.txt | AC | 2 ms | 3472 KiB |
70_hand_07.txt | AC | 2 ms | 3568 KiB |
80_rand_01.txt | AC | 24 ms | 6384 KiB |
80_rand_02.txt | AC | 26 ms | 5748 KiB |
80_rand_03.txt | AC | 37 ms | 8440 KiB |
80_rand_04.txt | AC | 25 ms | 6652 KiB |
80_rand_05.txt | AC | 33 ms | 7280 KiB |
80_rand_06.txt | AC | 31 ms | 7440 KiB |
80_rand_07.txt | AC | 37 ms | 7972 KiB |
80_rand_08.txt | AC | 32 ms | 7376 KiB |
80_rand_09.txt | AC | 37 ms | 7964 KiB |
80_rand_10.txt | AC | 23 ms | 5680 KiB |
90_hand_01.txt | AC | 9 ms | 3788 KiB |
90_hand_02.txt | AC | 7 ms | 3792 KiB |
90_hand_03.txt | AC | 83 ms | 9460 KiB |
90_hand_04.txt | AC | 83 ms | 9444 KiB |
90_hand_05.txt | AC | 44 ms | 9292 KiB |
90_hand_06.txt | AC | 83 ms | 9308 KiB |
90_hand_07.txt | AC | 81 ms | 9384 KiB |
90_hand_08.txt | AC | 81 ms | 9308 KiB |
90_hand_09.txt | AC | 81 ms | 9292 KiB |