QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#122741#6567. Repetitive String Inventioncada_dia_mas_insanosWA 40ms4756kbC++172.1kb2023-07-10 23:43:342023-07-10 23:43:36

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-10 23:43:36]
  • 评测
  • 测评结果:WA
  • 用时:40ms
  • 内存:4756kb
  • [2023-07-10 23:43:34]
  • 提交

answer

// Too many mind, no mind.
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <array>
#include <iomanip>

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define COMP(x) sort(ALL(x)); x.resize(unique(ALL(x)) - (x).begin())
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)

using pii = pair <int, int>;
using vi = vector <int>;
using vpi = vector <pii>;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using ld = long double;
using vld = vector<ld>;

const int maxn = 810;
int n;
int lcp[maxn][maxn];
char s[maxn];
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> s;
	n = strlen(s);
	forn(i, n) fore(j, i+1, n-1) {
		int k = 0;
		while (i+k<j && j+k<n && s[i+k] == s[j+k]) k++;
		lcp[i][j]=k;
	}
	int ans = 0;
	forn(i, n) fore(j, i, n-1) ans += min({j-i, n-j, lcp[i][j]});
	//cout << ans << endl;
	//cout << "dif" << endl;
	forn(i, n) fore(j, i, n-1) {
		int len = j-i+1, su=0, pre=0;
		fore(k, j+1, n-1) su += lcp[i][k] >= len;
		ford(k, i-len) pre += lcp[k][i] >= len;
		int l=i-len, r=j+1;

		fore(k, 1, min(i, n-j-1)) {
			while (r < n && r <= j+k) {
				if (lcp[i][r] >= len) su--;
				r++;
			}
			while(l >= 0 && l >= i-k) {
				if (lcp[i][l] >= len) pre--;
				l--;
			}

			//cout << i << ' ' << j << ' ' << k << ' ' << " -> " << su << ' ' << pre << endl;
			if (lcp[i-k][j+1] >= k) ans += su + pre;
		}
	}
	cout << ans << endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3416kb

input:

aaaa

output:

9

result:

ok single line: '9'

Test #2:

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

input:

axabxbcxcdxd

output:

22

result:

ok single line: '22'

Test #3:

score: -100
Wrong Answer
time: 40ms
memory: 4756kb

input:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:

711128889

result:

wrong answer 1st lines differ - expected: '536006700', found: '711128889'