QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#359630#6567. Repetitive String Inventionnkamzabek#WA 131ms11172kbC++231.6kb2024-03-20 19:35:552024-03-20 19:35:56

Judging History

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

  • [2024-03-20 19:35:56]
  • 评测
  • 测评结果:WA
  • 用时:131ms
  • 内存:11172kb
  • [2024-03-20 19:35:55]
  • 提交

answer

#include <bits/stdc++.h>

#define f first
#define s second
#define sz(s) (int)s.size()
#define pb push_back
using namespace std;

using vi = vector<int>;

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

string s, t;
int n, m;

const int p[] = {31, (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));
  }
};

int 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: 3652kb

input:

axabxbcxcdxd

output:

22

result:

ok single line: '22'

Test #3:

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

input:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:

536006700

result:

ok single line: '536006700'

Test #4:

score: 0
Accepted
time: 106ms
memory: 3940kb

input:

abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab...

output:

136016600

result:

ok single line: '136016600'

Test #5:

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

input:

a

output:

0

result:

ok single line: '0'

Test #6:

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

input:

ab

output:

0

result:

ok single line: '0'

Test #7:

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

input:

aa

output:

1

result:

ok single line: '1'

Test #8:

score: -100
Wrong Answer
time: 92ms
memory: 11172kb

input:

bbbbbrrrrbrbrrbrbrbrbbrrbbbbrrbrrbrbrbrrrrrbbbrrbrrbbrrrbbbbbrrrrbbrbbrrrrrbbrrrbbbbbrbbrbbbrbrrbrrrrrrrrbbrbrbbrrrrrrbbbbbrbrrrrbrrbbrbrrrrrbrbrbbrbrrbrrrrbrbbrbrrbrrbbbbrrrrrbrbbrbbrrrrrbrbrbrbbbrrrrrrrbbbbbbrrbrbrrrrrbbbrbrrrrbbbbrrbrrbbbbbbbrbbbbrrrbrbbbrrrrrrbbbbbrbrrbbbbrbrbrrbbrrrbbbrbbbrbbrr...

output:

204856

result:

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