This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#ifdef LOCAL
#define dbg(x) cerr << "dgb: " << x << "\n";
#else
#define dbg(x)
#endif
#define int int_fast64_t
using namespace std;
string s;
int solve(int l, int r) {
dbg("l " << l << " r " << r);
if (l == r)
return 1;
int pl = l;
int pr = r;
while (s[pr] != s[pl]) {
pr--;
if (pr == pl)
return 1;
}
int len = r - pr + 1;
dbg("len " << len);
dbg(s.substr(pl, len));
dbg(s.substr(pr, len));
if (s.substr(pl, len) != s.substr(pr, len)) {
return 1;
}
return 2 + solve(pl + len, pr - 1);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
cin >> s;
dbg(s);
cout << solve(0, (int)s.size() - 1) << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |