Submission #660268

# Submission time Handle Problem Language Result Execution time Memory
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++)
      |                      ~^~~~~~~~~
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory Grader output
1 Execution timed out 1085 ms 7776 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 -