QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#117426#6567. Repetitive String InventionUNos_maricones#WA 52ms3824kbC++201.6kb2023-07-01 07:49:442023-07-01 07:49:45

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 07:49:45]
  • 评测
  • 测评结果:WA
  • 用时:52ms
  • 内存:3824kb
  • [2023-07-01 07:49:44]
  • 提交

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 int N = 1000;

vector <int> z_algorithm (string &s) {
	int n = s.size();
	vector <int> z(n);
	int l = 0, r = 0;
	for (int i = 1; i < n; ++i) { 
		z[i] = max(0, 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 <int> zs[N];

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

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

				if (i == k) ans += min(j - i, zs[i][j-i]); 
				else if (mx)
					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: 1ms
memory: 3488kb

input:

aaaa

output:

9

result:

ok single line: '9'

Test #2:

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

input:

axabxbcxcdxd

output:

22

result:

ok single line: '22'

Test #3:

score: 0
Accepted
time: 49ms
memory: 3824kb

input:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:

536006700

result:

ok single line: '536006700'

Test #4:

score: -100
Wrong Answer
time: 52ms
memory: 3792kb

input:

abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab...

output:

268003400

result:

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