提出 #64073926
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
constexpr int MAXN = 1'000'007;
constexpr int INF = 2'000'000'000;
constexpr ll INFF = 1'000'000'000'000'000'000LL;
constexpr ll MOD = 998'244'353;
#define mkp make_pair
#define F first
#define S second
#define pb emplace_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
auto manacher = [&](string s) {
// z[i] => longest odd palindrome centered at i is
// s[i - z[i] ... i + z[i]]
// to get all palindromes (including even length),
// insert a '#' between each s[i] and s[i + 1]
int n = s.size();
vector<int> z;
z.resize(n);
z[0] = 0;
for (int b = 0, i = 1; i < n; i++) {
if (z[b] + b >= i)
z[i] = min(z[2 * b - i], b + z[b] - i);
else
z[i] = 0;
while (i + z[i] + 1 < n && i - z[i] - 1 >= 0 &&
s[i + z[i] + 1] == s[i - z[i] - 1])
z[i]++;
if (z[i] + i > z[b] + b)
b = i;
}
return z;
};
string s;
cin >> s;
int n = sz(s);
string ss;
ss.push_back(s[0]);
for (int i = 1; i < sz(s); i++)
ss.push_back('*'), ss.push_back(s[i]);
// cout << ss << endl;
auto z = manacher(ss);
for (int i = sz(ss) - n; i <= sz(ss) - 1; i++) {
if (z[i] == sz(ss) - i - 1) {
cout << s;
for (int j = i - z[i] - 1; j >= 0; j--) {
if (ss[j] != '*')
cout << ss[j];
}
cout << '\n';
break;
}
}
}
/*
- How to come up with solutions? (https://hackmd.io/-3cIVAFSQMC3iJTh9EpszA)
- Play with some small examples.
- Make observations (or random guesses) by intuition.
- Try to find counterexamples of the "observations."
- Find the characteristics of an optimal solution.
- Try to solve simple cases.
- Brute force and print out the results.
- Pick a method (greedy, dp, d&c, ...)
- But DO NOT force algos on problems!
- IF YOU'RE STUCK, TRY SOMETHING ELSE! Make new observations!
- Before writing the solution:
- check TL/ML/correctness of samples/implementation details!
- Pre-submit:
- Did you make a typo when copying a template?
- Test more cases if unsure.
- Write a naive solution and check small cases.
- Submit the correct file.
- Debugging:
- General Debugging:
- Read the whole problem again.
- Think over the algorithm again.
- Go to the toilet.
- Wrong Answer:
- Any possible overflows?
- > `__int128` ?
- Try `-ftrapv` or `#pragma GCC optimize("trapv")`
- Floating point errors?
- > `long double` ?
- turn off math optimizations
- check for `==`, `>=`, `acos(1.000000001)`, etc.
- Did you forget to sort or unique?
- Generate large and worst "corner" cases.
- Check your `m` / `n`, `i` / `j`, `x` / `y` and `<` / `>`.
- Are everything initialized or reset properly?
- Are you sure about the STL thing you are using?
- Read cppreference.
- Print everything and run it on pen and paper.
- Time Limit Exceeded:
- Calculate your time complexity again.
- Does the program actually end?
- Check for `while(q.size())` etc.
- Test the largest cases locally.
- Did you do unnecessary stuff?
- e.g. pass vectors by value
- e.g. `memset` for every test case
- Is your constant factor reasonable?
- Runtime Error:
- Check memory usage.
- Forget to clear or destroy stuff?
- > `vector::shrink_to_fit()`
- Stack overflow?
- Bad pointer / array access?
- Try `-fsanitize=address`
- Division by zero? NaN's?
*/
提出情報
| 提出日時 | |
|---|---|
| 問題 | F - ABCBA |
| ユーザ | henotrix |
| 言語 | C++ 20 (gcc 12.2) |
| 得点 | 500 |
| コード長 | 3788 Byte |
| 結果 | AC |
| 実行時間 | 16 ms |
| メモリ | 9628 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 500 / 500 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt |
| All | sample_01.txt, sample_02.txt, sample_03.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| sample_01.txt | AC | 1 ms | 3320 KiB |
| sample_02.txt | AC | 1 ms | 3432 KiB |
| sample_03.txt | AC | 1 ms | 3436 KiB |
| test_01.txt | AC | 1 ms | 3520 KiB |
| test_02.txt | AC | 1 ms | 3464 KiB |
| test_03.txt | AC | 1 ms | 3400 KiB |
| test_04.txt | AC | 1 ms | 3376 KiB |
| test_05.txt | AC | 1 ms | 3472 KiB |
| test_06.txt | AC | 1 ms | 3312 KiB |
| test_07.txt | AC | 1 ms | 3472 KiB |
| test_08.txt | AC | 1 ms | 3604 KiB |
| test_09.txt | AC | 1 ms | 3472 KiB |
| test_10.txt | AC | 16 ms | 9464 KiB |
| test_11.txt | AC | 15 ms | 9500 KiB |
| test_12.txt | AC | 15 ms | 9484 KiB |
| test_13.txt | AC | 15 ms | 9628 KiB |
| test_14.txt | AC | 13 ms | 9528 KiB |
| test_15.txt | AC | 11 ms | 9508 KiB |
| test_16.txt | AC | 15 ms | 9496 KiB |
| test_17.txt | AC | 12 ms | 9500 KiB |
| test_18.txt | AC | 13 ms | 9536 KiB |
| test_19.txt | AC | 12 ms | 9500 KiB |
| test_20.txt | AC | 12 ms | 9524 KiB |
| test_21.txt | AC | 15 ms | 9488 KiB |
| test_22.txt | AC | 14 ms | 9396 KiB |
| test_23.txt | AC | 14 ms | 9492 KiB |
| test_24.txt | AC | 14 ms | 9528 KiB |
| test_25.txt | AC | 11 ms | 9492 KiB |
| test_26.txt | AC | 16 ms | 9488 KiB |
| test_27.txt | AC | 15 ms | 9624 KiB |
| test_28.txt | AC | 14 ms | 9484 KiB |
| test_29.txt | AC | 14 ms | 9516 KiB |
| test_30.txt | AC | 12 ms | 9524 KiB |
| test_31.txt | AC | 15 ms | 9520 KiB |
| test_32.txt | AC | 14 ms | 9536 KiB |
| test_33.txt | AC | 15 ms | 9484 KiB |