QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#117429#6567. Repetitive String InventionUNos_maricones#WA 55ms4132kbC++201.7kb2023-07-01 07:58:372023-07-01 07:58:40

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:58:40]
  • 评测
  • 测评结果:WA
  • 用时:55ms
  • 内存:4132kb
  • [2023-07-01 07:58:37]
  • 提交

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 = 0;
			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]) {
				  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;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3412kb

input:

aaaa

output:

9

result:

ok single line: '9'

Test #2:

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

input:

axabxbcxcdxd

output:

22

result:

ok single line: '22'

Test #3:

score: 0
Accepted
time: 52ms
memory: 4132kb

input:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:

536006700

result:

ok single line: '536006700'

Test #4:

score: -100
Wrong Answer
time: 55ms
memory: 4096kb

input:

abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab...

output:

268003400

result:

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