QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#490829#6567. Repetitive String InventionSmallAoPigBigPiPig#WA 39ms10992kbC++231.7kb2024-07-25 16:30:362024-07-25 16:30:36

Judging History

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

  • [2024-07-25 16:30:36]
  • 评测
  • 测评结果:WA
  • 用时:39ms
  • 内存:10992kb
  • [2024-07-25 16:30:36]
  • 提交

answer

#include <bits/stdc++.h>
#define inf (0x7f7f7f7f)
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Max(a, b) ((a) > (b) ? (a) : (b))
typedef long long ll;
using namespace std;
template <class T>
inline void read(T &x){
	int ch = 0, f = 0; x = 0;
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
	for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
	if(f) x = -x;
}
const int mod = 1e9 + 7, N = 805;
char s[N];
ll ans;
int nxt[N], st[N*N], buf[N*N], nor[N*N], n, cnt;
#define id(x, y) (((x) - 1) * n + (y))
inline void gao(char* str, int m, int l){
	for(int i = 2, j = 0; i <= m; nxt[i++] = j){
		while(j && str[j+1] != str[i]) j = nxt[j];
		if(str[j+1] == str[i]) j++;
	}
	cnt = 0;
	for(int t = m; t; t = nxt[t]) if(t * 2 < m){
		ans += buf[nor[id(l + t, l + m - 1 - t)]];
	}
}
int main(){
	scanf("%s", s + 1);
	n = strlen(s + 1);
	unordered_map<int, int> fir;
	for(int i = 1; i <= n; i++)
		for(int j = i, hsh = 0; j <= n; j++){
			hsh = (97ll * hsh + s[j]) % mod;
			if(!fir.count(hsh)) fir[hsh] = id(i, j);
			nor[id(i, j)] = fir[hsh];
		}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= i - 1; j++) buf[nor[id(j, i - 1)]]++;
		for(int j = n; j >= i + 1; j--){
			for(int k = j + 1; k <= n; k++) buf[nor[id(j + 1, k)]]++;
			gao(s + i - 1, j - i + 1, i);
		}
		for(int j  = n; j >= i + 1; j--)
			for(int k = j + 1; k <= n; k++) buf[nor[id(j + 1, k)]]--;
	}
	for(int i = 1; i <= n * n; i++) buf[i] = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= i - 1; j++) buf[nor[id(j, i - 1)]]++;
		for(int j = i; j <= n; j++){
			ans += buf[nor[id(i, j)]];
			//cout << i << " " << j << " " << buf[nor[id(i, j)]] << endl;
		}
	}
	cout << ans << endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3720kb

input:

aaaa

output:

9

result:

ok single line: '9'

Test #2:

score: 0
Accepted
time: 1ms
memory: 5724kb

input:

axabxbcxcdxd

output:

22

result:

ok single line: '22'

Test #3:

score: 0
Accepted
time: 39ms
memory: 5172kb

input:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:

536006700

result:

ok single line: '536006700'

Test #4:

score: 0
Accepted
time: 31ms
memory: 4940kb

input:

abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab...

output:

136016600

result:

ok single line: '136016600'

Test #5:

score: 0
Accepted
time: 1ms
memory: 5940kb

input:

a

output:

0

result:

ok single line: '0'

Test #6:

score: 0
Accepted
time: 1ms
memory: 5976kb

input:

ab

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 1ms
memory: 5976kb

input:

aa

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 36ms
memory: 8876kb

input:

bbbbbrrrrbrbrrbrbrbrbbrrbbbbrrbrrbrbrbrrrrrbbbrrbrrbbrrrbbbbbrrrrbbrbbrrrrrbbrrrbbbbbrbbrbbbrbrrbrrrrrrrrbbrbrbbrrrrrrbbbbbrbrrrrbrrbbrbrrrrrbrbrbbrbrrbrrrrbrbbrbrrbrrbbbbrrrrrbrbbrbbrrrrrbrbrbrbbbrrrrrrrbbbbbbrrbrbrrrrrbbbrbrrrrbbbbrrbrrbbbbbbbrbbbbrrrbrbbbrrrrrrbbbbbrbrrbbbbrbrbrrbbrrrbbbrbbbrbbrr...

output:

209015

result:

ok single line: '209015'

Test #9:

score: -100
Wrong Answer
time: 25ms
memory: 10992kb

input:

fkrryithikkpurfezufbthxxrtejxpprhrhurrfziigzgajipayrefarpxuggehkiggeppfjghuyejuagkjpiezhmfizgphkkfffifihrimuhgtgzykfupbprjyrbpbimapjmbkrhubzhgfhhpkrxgjgmkheiiugiyerggyukyfuuxgrehgayafzuxymxxabygpapbjxipkxgbxhzpekypfghaumukguaipphiyhzimzfmpmzahbmaagytygyekzhktbbheetxrbipgytppgbhkpimrybkbeirhrzytfehba...

output:

5700

result:

wrong answer 1st lines differ - expected: '5696', found: '5700'