답안 #704994

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704994 2023-03-03T07:41:54 Z Paul_Liao_1457 Palindromi (COCI22_palindromi) C++17
0 / 110
51 ms 976 KB
//記得跳題
//#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;
  ans[a]+=ans[b];
  s[a]+=s[b];
  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]) {
      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);
    }
  }
  for (auto i:st[b]) {
    st[a].insert(i);
  }
  cout << st[a].size() << endl;
}

signed main(){
  AC;
  int n; cin >> n;
  string ss; cin >> ss;
  ss = '?' + ss;
  FOR (i, 1, n + 1) {
    boss[i] = i; st[i].insert(s[i]); ans[i] = 1;
  }
  FOR (i, 1, n) {
    int a, b; cin >> a >> b;
    int fa = find(a), fb = find(b);
    merge(fa, fb);
  }
}

Compilation message

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]) {
      |                              ~~~~~~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 51 ms 976 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -