Submission #705002

#TimeUsernameProblemLanguageResultExecution timeMemory
705002Paul_Liao_1457Palindromi (COCI22_palindromi)C++17
10 / 110
1073 ms1232 KiB
//記得跳題 //#pragma GCC optimize("O4,unroll_loops") //#pragma GCC target("avx2") #include<iostream> #include<array> #include<vector> #include<string> #include<algorithm> #include<set> #include<queue> #include<stack> #include<math.h> #include<map> #include<unordered_map> #include<unordered_set> #include<cstring> #include<iomanip> #include<bitset> #include<tuple> #include<random> #define ll long long #define FOR(i,a,b) for(int i=a;i<b;i++) #define REP(i,a,b) for(int i=a;i>=b;i--) #define pb push_back #define INF (ll)(2e18) #define F first #define S second #define endl "\n" #define AC ios::sync_with_stdio(0); using namespace std; int boss[1005],ans[1005]; string s[1005]; set<string> st[1005]; int find (int x) { if (boss[x] == x) return x; return boss[x] = find(boss[x]); } void merge(int a, int b) { int n = (int)s[a].size(); boss[b] = a; s[a]+=s[b]; //cout << "sa=" << s[a] << endl; FOR(mid, 0, s[a].size()) { int len = 1; string now; now += s[a][mid]; while (mid - len >= 0 && mid + len < s[a].size() && s[a][mid-len] == s[a][mid+len]) { now = now + s[a][mid+len]; now = s[a][mid-len] + now; if (mid - len + 1 <= n && mid + len + 1 > n) { st[a].insert(now); } len++; } int l = mid, r = mid+1; if (r<s[a].size() && s[a][l] == s[a][r]) { now.clear(); now += s[a][l]; now += s[a][r]; st[a].insert(now); while (l-1 >= 0 && r+1 < s[a].size() && s[a][l-1] == s[a][r+1]) { l--; r++; now = now + s[a][r]; now = s[a][l] + now; if (l+1 <= n && r + 1 > n) { st[a].insert(now); } } } } for (auto i:st[b]) { st[a].insert(i); } st[b].clear(); cout << st[a].size() << endl; } signed main(){ AC; int n; cin >> n; string ss; cin >> ss; ss = '?' + ss; FOR (i, 1, n + 1) { string tmp; tmp+=ss[i]; boss[i] = i; st[i].insert(tmp); ans[i] = 1; s[i]+=ss[i]; } FOR (i, 1, n) { int a, b; cin >> a >> b; int fa = find(a), fb = find(b); merge(fa, fb); } }

Compilation message (stderr)

Main.cpp: In function 'void merge(int, int)':
Main.cpp:23:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 | #define FOR(i,a,b) for(int i=a;i<b;i++)
......
   48 |   FOR(mid, 0, s[a].size()) {
      |       ~~~~~~~~~~~~~~~~~~~        
Main.cpp:48:3: note: in expansion of macro 'FOR'
   48 |   FOR(mid, 0, s[a].size()) {
      |   ^~~
Main.cpp:51:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     while (mid - len >= 0 && mid + len < s[a].size() && s[a][mid-len] == s[a][mid+len]) {
      |                              ~~~~~~~~~~^~~~~~~~~~~~~
Main.cpp:60:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     if (r<s[a].size() && s[a][l] == s[a][r]) {
      |         ~^~~~~~~~~~~~
Main.cpp:65:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |       while (l-1 >= 0 && r+1 < s[a].size() && s[a][l-1] == s[a][r+1]) {
      |                          ~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...