# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
660269 | berr | Palindromi (COCI22_palindromi) | C++17 | 1089 ms | 8276 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.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+37;
string s[N];
int val[N];
int par[N];
int find(int x)
{
if(x==par[x]) return x;
return par[x]=find(par[x]);
}
int check(string t)
{
for(int i=0; i<t.size(); i++)
{
if(t[i]!=t[t.size()-i-1]) return 0;
}
return 1;
}
void merge(int x, int y)
{
x=find(x);
y=find(y);
string t=s[x]+s[y];
set<string> st;
for(int i=0; i<t.size(); i++)
{
string f;
for(int l=i; l<t.size(); l++)
{
f+=t[l];
if(check(f))
{
st.insert(f);
}
}
}
s[x]=t;
val[x]=st.size();
par[y]=x;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n; cin>>n;
string sr; cin>>sr;
for(int i=0; i<n; i++)
{
s[i]=sr[i];
val[i]=1;
par[i]=i;
}
for(int i=0; i<n-1; i++)
{
int x, y; cin>>x>>y;
x--; y--;
merge(x, y);
cout<<val[find(x)]<<endl;
}
}
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... |