# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
705002 | Paul_Liao_1457 | Palindromi (COCI22_palindromi) | C++17 | 1073 ms | 1232 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//記得跳題
//#pragma GCC optimize("O4,unroll_loops")
//#pragma GCC target("avx2")
#include<iostream>
#include<array>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<iomanip>
#include<bitset>
#include<tuple>
#include<random>
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define INF (ll)(2e18)
#define F first
#define S second
#define endl "\n"
#define AC ios::sync_with_stdio(0);
using namespace std;
int boss[1005],ans[1005];
string s[1005];
set<string> st[1005];
int find (int x) {
if (boss[x] == x) return x;
return boss[x] = find(boss[x]);
}
void merge(int a, int b) {
int n = (int)s[a].size();
boss[b] = a;
s[a]+=s[b];
//cout << "sa=" << s[a] << endl;
FOR(mid, 0, s[a].size()) {
int len = 1;
string now; now += s[a][mid];
while (mid - len >= 0 && mid + len < s[a].size() && s[a][mid-len] == s[a][mid+len]) {
now = now + s[a][mid+len];
now = s[a][mid-len] + now;
if (mid - len + 1 <= n && mid + len + 1 > n) {
st[a].insert(now);
}
len++;
}
int l = mid, r = mid+1;
if (r<s[a].size() && s[a][l] == s[a][r]) {
now.clear();
now += s[a][l];
now += s[a][r];
st[a].insert(now);
while (l-1 >= 0 && r+1 < s[a].size() && s[a][l-1] == s[a][r+1]) {
l--; r++;
now = now + s[a][r];
now = s[a][l] + now;
if (l+1 <= n && r + 1 > n) {
st[a].insert(now);
}
}
}
}
for (auto i:st[b]) {
st[a].insert(i);
}
st[b].clear();
cout << st[a].size() << endl;
}
signed main(){
AC;
int n; cin >> n;
string ss; cin >> ss;
ss = '?' + ss;
FOR (i, 1, n + 1) {
string tmp; tmp+=ss[i];
boss[i] = i; st[i].insert(tmp); ans[i] = 1; s[i]+=ss[i];
}
FOR (i, 1, n) {
int a, b; cin >> a >> b;
int fa = find(a), fb = find(b);
merge(fa, fb);
}
}
Compilation message (stderr)
# | 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... |