답안 #660269

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
660269 2022-11-21T11:40:55 Z berr Palindromi (COCI22_palindromi) C++17
10 / 110
1000 ms 8276 KB
#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

Main.cpp: In function 'long long int check(std::string)':
Main.cpp:16:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for(int i=0; i<t.size(); i++)
      |                  ~^~~~~~~~~
Main.cpp: In function 'void merge(long long int, long long int)':
Main.cpp:31:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for(int i=0; i<t.size(); i++)
      |                  ~^~~~~~~~~
Main.cpp:34:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for(int l=i; l<t.size(); l++)
      |                      ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6504 KB Output is correct
2 Correct 9 ms 6612 KB Output is correct
3 Correct 6 ms 6484 KB Output is correct
4 Correct 12 ms 6592 KB Output is correct
5 Correct 9 ms 6484 KB Output is correct
6 Correct 21 ms 6620 KB Output is correct
7 Correct 11 ms 6484 KB Output is correct
8 Correct 17 ms 6612 KB Output is correct
9 Correct 11 ms 6484 KB Output is correct
10 Correct 17 ms 6612 KB Output is correct
11 Correct 11 ms 6592 KB Output is correct
12 Correct 4 ms 6612 KB Output is correct
13 Correct 4 ms 6592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6504 KB Output is correct
2 Correct 9 ms 6612 KB Output is correct
3 Correct 6 ms 6484 KB Output is correct
4 Correct 12 ms 6592 KB Output is correct
5 Correct 9 ms 6484 KB Output is correct
6 Correct 21 ms 6620 KB Output is correct
7 Correct 11 ms 6484 KB Output is correct
8 Correct 17 ms 6612 KB Output is correct
9 Correct 11 ms 6484 KB Output is correct
10 Correct 17 ms 6612 KB Output is correct
11 Correct 11 ms 6592 KB Output is correct
12 Correct 4 ms 6612 KB Output is correct
13 Correct 4 ms 6592 KB Output is correct
14 Correct 3 ms 6484 KB Output is correct
15 Execution timed out 1083 ms 7048 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1089 ms 8276 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6504 KB Output is correct
2 Correct 9 ms 6612 KB Output is correct
3 Correct 6 ms 6484 KB Output is correct
4 Correct 12 ms 6592 KB Output is correct
5 Correct 9 ms 6484 KB Output is correct
6 Correct 21 ms 6620 KB Output is correct
7 Correct 11 ms 6484 KB Output is correct
8 Correct 17 ms 6612 KB Output is correct
9 Correct 11 ms 6484 KB Output is correct
10 Correct 17 ms 6612 KB Output is correct
11 Correct 11 ms 6592 KB Output is correct
12 Correct 4 ms 6612 KB Output is correct
13 Correct 4 ms 6592 KB Output is correct
14 Correct 3 ms 6484 KB Output is correct
15 Execution timed out 1083 ms 7048 KB Time limit exceeded
16 Halted 0 ms 0 KB -