QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#611585#7876. Cyclic Substrings7islandsCompile Error//C++171.6kb2024-10-04 21:35:322024-10-04 21:35:33

Judging History

你现在查看的是最新测评结果

  • [2024-10-04 21:35:33]
  • 评测
  • [2024-10-04 21:35:32]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 10000000 + 5;
int n;
namespace pam {
int sz, tot, last;
int cnt[maxn], ch[maxn][26], len[maxn], fail[maxn];
char s[maxn];

int node(int l) {  // 建立一个新节点,长度为 l
  sz++;
  memset(ch[sz], 0, sizeof(ch[sz]));
  len[sz] = l;
  fail[sz] = cnt[sz] = 0;
  return sz;
}

void clear() {  // 初始化
  sz = -1;
  last = 0;
  s[tot = 0] = '$';
  node(0);
  node(-1);
  fail[0] = 1;
}

int getfail(int x) {  // 找后缀回文
  while (s[tot - len[x] - 1] != s[tot]) x = fail[x];
  return x;
}

void insert(int num,char c) {  // 建树
  s[++tot] = c;
  int now = getfail(last);
  if (!ch[now][c - 'a']) {
    int x = node(len[now] + 2);
    fail[x] = ch[getfail(fail[now])][c - 'a'];
    ch[now][c - 'a'] = x;
  }
  last = ch[now][c - 'a'];
  if (num>n)cnt[last]++;
}

long long solve() {
  long long ans = 0;
  for (int i = sz; i >= 0; i--) {
    cnt[fail[i]] += cnt[i];
  }
  for (int i = 1; i <= sz; i++) {  // 更新答案
  
    if (len[i]>n||len[i]<0)continue;
    // if (i<=n+1)cnt[i]=cnt[i]/2+cnt[i]%2;
    //cout <<i<<" "<<len[i]<<" "<<cnt[i]<<endl;
    ans += 1ll * len[i] * cnt[i] * cnt[i];
  }
  return ans;
}
}  // namespace pam

char s[maxn];

signed main() {
  cin >>n;
  pam::clear();
  scanf("%s", s + 1);
  for (int i=1;i<=n;i++){
    s[n+i]=s[i];
  }
//   for (int i=1;i<=n*2;i++){
//     cout <<s[i];
//   }
  for (int i = 1; s[i]; i++) {
    pam::insert(i,s[i]);
  }
  printf("%lld\n", pam::solve());
  return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:66:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   66 |   scanf("%s", s + 1);
      |   ~~~~~^~~~~~~~~~~~~
/tmp/ccBZgN94.o: in function `pam::node(long long)':
answer.code:(.text+0x7): relocation truncated to fit: R_X86_64_PC32 against symbol `pam::sz' defined in .bss section in /tmp/ccBZgN94.o
answer.code:(.text+0x1e): relocation truncated to fit: R_X86_64_PC32 against symbol `pam::sz' defined in .bss section in /tmp/ccBZgN94.o
answer.code:(.text+0x4a): relocation truncated to fit: R_X86_64_PC32 against symbol `pam::cnt' defined in .bss section in /tmp/ccBZgN94.o
/tmp/ccBZgN94.o: in function `pam::clear()':
answer.code:(.text+0x9f): relocation truncated to fit: R_X86_64_PC32 against symbol `pam::last' defined in .bss section in /tmp/ccBZgN94.o
answer.code:(.text+0xaa): relocation truncated to fit: R_X86_64_PC32 against symbol `pam::tot' defined in .bss section in /tmp/ccBZgN94.o
answer.code:(.text+0xc0): relocation truncated to fit: R_X86_64_PC32 against symbol `pam::cnt' defined in .bss section in /tmp/ccBZgN94.o
answer.code:(.text+0xcb): relocation truncated to fit: R_X86_64_PC32 against symbol `pam::sz' defined in .bss section in /tmp/ccBZgN94.o
answer.code:(.text+0xeb): relocation truncated to fit: R_X86_64_PC32 against symbol `pam::cnt' defined in .bss section in /tmp/ccBZgN94.o
/tmp/ccBZgN94.o: in function `pam::getfail(long long)':
answer.code:(.text+0x107): relocation truncated to fit: R_X86_64_PC32 against symbol `pam::tot' defined in .bss section in /tmp/ccBZgN94.o
/tmp/ccBZgN94.o: in function `pam::insert(long long, char)':
answer.code:(.text+0x157): relocation truncated to fit: R_X86_64_PC32 against symbol `pam::tot' defined in .bss section in /tmp/ccBZgN94.o
answer.code:(.text+0x15e): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status