Submission #660269

#TimeUsernameProblemLanguageResultExecution timeMemory
660269berrPalindromi (COCI22_palindromi)C++17
10 / 110
1089 ms8276 KiB
#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)

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++)
      |                      ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...