QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#479337#5440. P-P-PalindromeUESTC_DECAYALI#TL 9ms7492kbC++17732b2024-07-15 16:30:492024-07-15 16:30:50

Judging History

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

  • [2024-07-15 16:30:50]
  • 评测
  • 测评结果:TL
  • 用时:9ms
  • 内存:7492kb
  • [2024-07-15 16:30:49]
  • 提交

answer

#include <bits/stdc++.h>

bool is_palin(const std::string& s) {
	for(int i = 0, j = s.size() - 1; i < j; ++i, --j)
		if(s[i] != s[j]) return false;
	return true;
}

int main() {
	// freopen("data.in", "r", stdin);
	// freopen("data.ans", "w", stdout);
	int n; std::cin >> n;
	std::vector<std::string> s(n);
	for(auto &s: s) std::cin >> s;
	std::set<std::string> hkr;
	std::set<std::pair<std::string, std::string>> ans;
	for(auto s: s) for(int i = 0; i < s.size(); ++i) for(int j = i; j < s.size(); ++j) {
		auto sub = s.substr(i, j - i + 1);
		if(is_palin(sub)) hkr.insert(sub);
	}
	for(auto p: hkr) for(auto q: hkr) if(is_palin(p + q)) ans.insert({p, q});
	std::cout << ans.size() << char(10);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
aaaa
aaa

output:

16

result:

ok 1 number(s): "16"

Test #2:

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

input:

3
abaaa
abbbba
bbbaba

output:

28

result:

ok 1 number(s): "28"

Test #3:

score: 0
Accepted
time: 9ms
memory: 7492kb

input:

1
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab

output:

15130

result:

ok 1 number(s): "15130"

Test #4:

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

input:

3
aaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbb
bababababababaabababababa

output:

1282

result:

ok 1 number(s): "1282"

Test #5:

score: -100
Time Limit Exceeded

input:

5
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...

output:


result: