QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#117436#6567. Repetitive String InventionUNos_mariconesWA 53ms4116kbC++201.7kb2023-07-01 09:20:102023-07-01 09:20:11

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-01 09:20:11]
  • 评测
  • 测评结果:WA
  • 用时:53ms
  • 内存:4116kb
  • [2023-07-01 09:20:10]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "../debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define pb   push_back
const long long N = 1000;

vector <long long> z_algorithm (string &s) {
	long long n = s.size();
	vector <long long> z(n);
	long long l = 0, r = 0;
	for (long long i = 1; i < n; ++i) { 
		z[i] = max(0ll, min(z[i - l], r - i + 1));
		while (i + z[i] < n && s[z[i]] == s[i + z[i]])
			l = i, r = i + z[i],  ++z[i];
	}
	return z;
}

vector <long long> zs[N];

long long solve (string s, long long flag) { 
	long long n = s.size();
	for (long long i = 0; i < n; ++i) { 
     string cur = "";
		 for (long long j = i; j < n; ++j) cur.pb(s[j]);
		 zs[i] = z_algorithm(cur);
	}

	//cout << zs[0][6] << '\n';
	long long ans = 0;
	for (long long k = 0; k < n; ++k) {
		for (long long i = k + flag; i < n; ++i) { 
			vector <long long> wh(n + 1, -1);
			long long add = 0, x = 0;
			long long mx = 1;
			vector <long long> prf(n + 1, 0);
			for (long long j = i + 1; j < n; ++j) {
				if (zs[k][j - k] >= i - k) wh[j + i - k] = j - i;
				
				while (mx <= wh[j]) {
				  prf[mx] = prf[mx - 1] + 1;	
					mx++;
				}

				if (i == k) ans += min(j - i, zs[i][j-i]); 
				else ans += prf[min(zs[i][j-i], mx-1)];
				//cout << " " << k << ' ' << i << ' '<< j <<' ' << zs[i][j-i] << ' ' << ans << '\n';
			}
		}
	}

	return ans;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s;
	cin >> s;
  string snw = s;
	reverse(snw.begin(), snw.end());
	cout << solve(s, 0) + solve(snw, 1) << '\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

aaaa

output:

9

result:

ok single line: '9'

Test #2:

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

input:

axabxbcxcdxd

output:

22

result:

ok single line: '22'

Test #3:

score: 0
Accepted
time: 53ms
memory: 4116kb

input:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:

536006700

result:

ok single line: '536006700'

Test #4:

score: -100
Wrong Answer
time: 49ms
memory: 4116kb

input:

abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab...

output:

268003400

result:

wrong answer 1st lines differ - expected: '136016600', found: '268003400'