QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#359633#6567. Repetitive String Inventionnkamzabek#WA 124ms11300kbC++231.6kb2024-03-20 19:37:152024-03-20 19:37:15

Judging History

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

  • [2024-03-20 19:37:15]
  • 评测
  • 测评结果:WA
  • 用时:124ms
  • 内存:11300kb
  • [2024-03-20 19:37:15]
  • 提交

answer

#include <bits/stdc++.h>

#define f first
#define s second
#define sz(s) (int)s.size()
#define pb push_back
#define int long long

using namespace std;

using vi = vector<int>;

const int N = (int)5e3 + 100;

string s, t;
int n, m;

const int p[] = {(int)1e6 + 33, (int)1e6 + 7};
const int mod[] = {(int)1e9 + 7, (int)1e9 + 9};
int h[N][2];
int pw[N][2];

pair<int, int> get(int l, int r){
	int a = (h[r][0] - pw[r - l + 1][0] * 1ll * h[l - 1][0] % mod[0]);
	int b = (h[r][1] - pw[r - l + 1][1] * 1ll * h[l - 1][1] % mod[1]);
	
	if(a < 0)
		a += mod[0];
	if(b < 0)
		b += mod[1];
	return {a, b};
}


struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	cin >> s;
	n = s.size();
	pw[0][0] = pw[0][1] = 1;

	for(int i = 0; i < n; i++){
		for(int it = 0; it < 2; it++){
			h[i + 1][it] = (h[i][it] * 1ll * p[it] + s[i]) % mod[it];
			pw[i + 1][it] = (pw[i][it] * 1ll * p[it]) % mod[it];
		}
	}
	
	unordered_map<pair<int, int>, int, HASH> cnt, cnt1;
	long long ans = 0, ans1 = 0;
	for(int i = 1; i <= n; i++){
		int s[2] = {};
		for(int j = i; j <= n; j++){
			ans += cnt[get(i, j)];
			ans1 += cnt1[get(i, j)];
		}
		for(int j = 1; j <= i; j++){			
			for(int k = j; k < i; k++){
				int len = k - j + 1;
				if(get(j, j + len - 1) == get(i - len + 1, i)){
					if(j + len <= i - len)
						cnt1[get(j + len, i - len)]++;	
				}
			}
			cnt[get(j, i)]++;
		
		}
	}

	cout << ans + 2 * ans1 << "\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

aaaa

output:

9

result:

ok single line: '9'

Test #2:

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

input:

axabxbcxcdxd

output:

22

result:

ok single line: '22'

Test #3:

score: 0
Accepted
time: 124ms
memory: 3656kb

input:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:

536006700

result:

ok single line: '536006700'

Test #4:

score: 0
Accepted
time: 108ms
memory: 3896kb

input:

abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab...

output:

136016600

result:

ok single line: '136016600'

Test #5:

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

input:

a

output:

0

result:

ok single line: '0'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

ab

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3768kb

input:

aa

output:

1

result:

ok single line: '1'

Test #8:

score: -100
Wrong Answer
time: 99ms
memory: 11300kb

input:

bbbbbrrrrbrbrrbrbrbrbbrrbbbbrrbrrbrbrbrrrrrbbbrrbrrbbrrrbbbbbrrrrbbrbbrrrrrbbrrrbbbbbrbbrbbbrbrrbrrrrrrrrbbrbrbbrrrrrrbbbbbrbrrrrbrrbbrbrrrrrbrbrbbrbrrbrrrrbrbbrbrrbrrbbbbrrrrrbrbbrbbrrrrrbrbrbrbbbrrrrrrrbbbbbbrrbrbrrrrrbbbrbrrrrbbbbrrbrrbbbbbbbrbbbbrrrbrbbbrrrrrrbbbbbrbrrbbbbrbrbrrbbrrrbbbrbbbrbbrr...

output:

204856

result:

wrong answer 1st lines differ - expected: '209015', found: '204856'