Submission #704995

# Submission time Handle Problem Language Result Execution time Memory
704995 2023-03-03T07:41:59 Z browntoad Palindromi (COCI22_palindromi) C++14
10 / 110
1000 ms 6536 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i=(n)-1; i>=0; i--)
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())

const ll maxn = 1e5+5;

int n;
string str;
vector<pii> op(maxn);
vector<int> par(maxn);
void inp(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin>>n;
    cin>>str;
    REP(i, n-1){
        cin>>op[i].f>>op[i].s;
        op[i].f--;
        op[i].s--;
    }
}
vector<string> vc(maxn);
int fin(int a){
    if (a==par[a]) return a;
    return par[a] = fin(par[a]);
}
void merg(int a, int b){
    a=fin(a); b=fin(b);
    assert(a!=b);
    par[b]=a;
    vc[a]+=vc[b];
}
int cunt(string &a){
    set<string> st;
    REP(i, SZ(a)){
        string tmp, tmp2;
        FOR(j, i, SZ(a)){
            tmp2=tmp=a.substr(i, j-i+1);
            reverse(ALL(tmp2));
            if (tmp == tmp2) st.insert(tmp);
        }
    }
    return SZ(st);
}
void solve(){
    REP(i, n){
        vc[i]=str[i];
    }
    REP1(i, n){
        par[i]=i;
    }
    REP(i, n-1){
        merg(op[i].f, op[i].s);
        string t = vc[fin(op[i].f)];
        cout<<cunt(t)<<endl;
    }

}
signed main(){
    inp();
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5716 KB Output is correct
2 Correct 7 ms 5716 KB Output is correct
3 Correct 5 ms 5824 KB Output is correct
4 Correct 10 ms 5716 KB Output is correct
5 Correct 9 ms 5816 KB Output is correct
6 Correct 18 ms 5844 KB Output is correct
7 Correct 14 ms 5716 KB Output is correct
8 Correct 18 ms 5816 KB Output is correct
9 Correct 13 ms 5716 KB Output is correct
10 Correct 18 ms 5716 KB Output is correct
11 Correct 14 ms 5820 KB Output is correct
12 Correct 4 ms 5716 KB Output is correct
13 Correct 3 ms 5716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5716 KB Output is correct
2 Correct 7 ms 5716 KB Output is correct
3 Correct 5 ms 5824 KB Output is correct
4 Correct 10 ms 5716 KB Output is correct
5 Correct 9 ms 5816 KB Output is correct
6 Correct 18 ms 5844 KB Output is correct
7 Correct 14 ms 5716 KB Output is correct
8 Correct 18 ms 5816 KB Output is correct
9 Correct 13 ms 5716 KB Output is correct
10 Correct 18 ms 5716 KB Output is correct
11 Correct 14 ms 5820 KB Output is correct
12 Correct 4 ms 5716 KB Output is correct
13 Correct 3 ms 5716 KB Output is correct
14 Correct 3 ms 5716 KB Output is correct
15 Execution timed out 1081 ms 6188 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1065 ms 6536 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5716 KB Output is correct
2 Correct 7 ms 5716 KB Output is correct
3 Correct 5 ms 5824 KB Output is correct
4 Correct 10 ms 5716 KB Output is correct
5 Correct 9 ms 5816 KB Output is correct
6 Correct 18 ms 5844 KB Output is correct
7 Correct 14 ms 5716 KB Output is correct
8 Correct 18 ms 5816 KB Output is correct
9 Correct 13 ms 5716 KB Output is correct
10 Correct 18 ms 5716 KB Output is correct
11 Correct 14 ms 5820 KB Output is correct
12 Correct 4 ms 5716 KB Output is correct
13 Correct 3 ms 5716 KB Output is correct
14 Correct 3 ms 5716 KB Output is correct
15 Execution timed out 1081 ms 6188 KB Time limit exceeded
16 Halted 0 ms 0 KB -