답안 #660268

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
660268 2022-11-21T11:37:15 Z berr Palindromi (COCI22_palindromi) C++17
0 / 110
1000 ms 7776 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+37;
string s[N];
int val[N];

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)
{

    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]=s[y]=t;
    val[x]=val[y]=st.size();

}


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;   
    }    

    for(int i=0; i<n-1; i++)
    {
        int x, y; cin>>x>>y;
        x--; y--;
        merge(x, y);
        cout<<val[x]<<endl;
    }
}   

Compilation message

Main.cpp: In function 'long long int check(std::string)':
Main.cpp:10: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]
   10 |     for(int i=0; i<t.size(); i++)
      |                  ~^~~~~~~~~
Main.cpp: In function 'void merge(long long int, long long int)':
Main.cpp:23: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]
   23 |     for(int i=0; i<t.size(); i++)
      |                  ~^~~~~~~~~
Main.cpp:26: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]
   26 |         for(int l=i; l<t.size(); l++)
      |                      ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Incorrect 3 ms 6484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Incorrect 3 ms 6484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1085 ms 7776 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Incorrect 3 ms 6484 KB Output isn't correct
3 Halted 0 ms 0 KB -