QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#284042#5065. Beautiful Stringx0rzzzWA 81ms199164kbC++141.6kb2023-12-15 21:41:502023-12-15 21:41:51

Judging History

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

  • [2023-12-15 21:41:51]
  • 评测
  • 测评结果:WA
  • 用时:81ms
  • 内存:199164kb
  • [2023-12-15 21:41:50]
  • 提交

answer

#include <bits/stdc++.h>

#define name ""
#define ll long long
#define ld long double
#define fi first 
#define se second
#define pll pair < ll, ll >
#define pii pair < int, int >
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define SZE(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define lnode node * 2, l, (l + r) / 2
#define rnode node * 2 + 1, (l + r) / 2 + 1, r

using namespace std;

const ld EPS = 1e-9;
const int INF = 1e9 + 7;
const ll LINF = 1E18;
const int N = 5e3;
const ll MOD = 1e9 + 7;
const ll BASE = 2309;

string s;

int dp[N + 3][N + 3], cnt[N + 3][N + 3], n;

void sol() {
	cin >> s;
	n = s.size(); s = ' ' + s;
	dp[n + 1][n + 1] = 0;
	for (int i = 0; i <= n; i++)
	for (int j = 0; j <= n; j++) cnt[i][j] = 0;
	for (int i = n; i >= 1; i--)
	for (int j = n; j >= 1; j--) dp[i][j] = (s[i] == s[j] ? dp[i + 1][j + 1] + 1 : 0);
	for (int i = 1; i <= n; i++) {
		for (int j = i + 2; j <= n; j++) {
			int temp = min(dp[i][j], j - i - 1);
			if (temp < 2) continue;
			// cout << i << " " << j << " " << temp << '\n';
			cnt[i][temp - 1] ++;	
		}
		for (int j = n - 1; j >= 1; j--) cnt[i][j] += 2 * cnt[i][j + 1];
	}
	int res = 0;
	for (int i = 1; i <= n; i++)
	for (int j = i + 1; j <= n; j++) {
		// cout << i << " " << j << " " << i + dp[i][j] - 1 << " " << j + dp[i][j] - 1 << '\n';
		if (dp[i][j] >= j - i) res += cnt[j][j - i];
	}
	cout << res << '\n';
}

int main() {
	fast;
	if(fopen(name".inp", "r")) {
		freopen(name".inp", "r", stdin);
		freopen(name".out", "w", stdout);
	}
	int t; cin >> t; while (t --) sol();
}

详细

Test #1:

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

input:

2
114514
0000000

output:

1
3

result:

ok 2 number(s): "1 3"

Test #2:

score: -100
Wrong Answer
time: 81ms
memory: 199164kb

input:

11
79380
2483905227
37902399703986576270
39991723655814713848046032694137883815354365954917
5541883522667841718787744915558298207485830622522715211018760095628594390563630840464643840093757297
56530485554219245862513973750218715585679416120445975390556326891488719311495909340757506478400624741858999...

output:

0
0
0
2
4
20
120
114
1092
2152
15317

result:

wrong answer 7th numbers differ - expected: '119', found: '120'