답안 #104489

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
104489 2019-04-07T06:46:18 Z E869120 회문 (APIO14_palindrome) C++14
47 / 100
957 ms 1712 KB
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;
#pragma warning (disable: 4996)

const int MAX_N = 10009;
long long L[MAX_N]; string S;
pair<long long, int> L1[MAX_N]; int cnt1;

bool ispalindrome(string V) {
	for (int i = 0; i < V.size(); i++) {
		if (V[i] != V[V.size() - 1 - i]) return false;
	}
	return true;
}

long long solve_Jury() {
	long long maxn = 0; map<long long, long long>Map;
	for (int i = 0; i < S.size(); i++) {
		long long r = 0;
		for (int j = i; j < S.size(); j++) {
			r *= 311; r += (long long)(S[j] - 'a' + 1);
			if (ispalindrome(S.substr(i, j - i + 1)) == false) continue;
			Map[r] += 1LL * (j - i + 1);
			maxn = max(maxn, Map[r]);
		}
	}
	return maxn;
}

long long solve_Output() {
	cnt1 = 0; for (int i = 0; i < MAX_N; i++) L1[i] = make_pair(0, 0);
	for (int i = 0; i < S.size(); i++) L[i] = (S[i] - 'a') + 1;

	long long maxn = 0;

	// 真ん中が決まっている場合
	cnt1 = 0;
	for (int t = 1; t <= 26; t++) {
		for (int i = 0; i < S.size(); i++) { if (L[i] == t) { L1[cnt1] = make_pair(L[i], i); cnt1++; } }
	}

	long long BASE1 = 1000000007LL;
	for (int i = 1; i <= S.size(); i += 2) {
		int t1 = 0; BASE1 *= 1000000007LL;
		for (int j = 0; j < cnt1; j++) {
			t1++;
			maxn = max(maxn, 1LL * t1 * i);
			if (L1[j].first != L1[j + 1].first) t1 = 0;
		}
		vector<pair<long long, int>>G[28];
		for (int j = 0; j < cnt1; j++) {
			int pos1 = L1[j].second - (i / 2) - 1, pos2 = L1[j].second + (i / 2) + 1;
			if (pos1 >= 0 && pos2 < S.size() && L[pos1] == L[pos2]) {
				G[L[pos1]].push_back(make_pair(L1[j].first + BASE1 * L[pos1], L1[j].second));
			}
		}
		cnt1 = 0;
		for (int j = 1; j <= 26; j++) {
			for (int k = 0; k < G[j].size(); k++) {
				L1[cnt1] = G[j][k]; cnt1++;
			}
		}
	}

	// 真ん中が決まっていない場合
	cnt1 = 0;
	for (int t = 1; t <= 26; t++) {
		for (int i = 0; i < S.size() - 1; i++) { if (L[i] == L[i + 1] && L[i] == t) { L1[cnt1] = make_pair(L[i], i); cnt1++; } }
	}

	long long BASE = 1000000007LL;
	for (int i = 2; i <= S.size(); i += 2) {
		int t1 = 0; BASE *= 1000000007LL;
		for (int j = 0; j < cnt1; j++) {
			t1++;
			maxn = max(maxn, 1LL * t1 * i);
			if (L1[j].first != L1[j + 1].first) t1 = 0;
		}
		vector<pair<long long, int>>G[28];
		for (int j = 0; j < cnt1; j++) {
			int pos1 = L1[j].second - (i / 2), pos2 = L1[j].second + (i / 2) + 1;
			if (pos1 >= 0 && pos2 < S.size() && L[pos1] == L[pos2]) {
				G[L[pos1]].push_back(make_pair(L1[j].first + L[pos1] * BASE, L1[j].second));
			}
		}
		cnt1 = 0;
		for (int j = 1; j <= 26; j++) {
			for (int k = 0; k < G[j].size(); k++) {
				L1[cnt1] = G[j][k]; cnt1++;
			}
		}
	}
	return maxn;
}

void random_generate() {
	S = "";
	for (int i = 0; i < 1000; i++) { S += ('a' + (rand() % 2)); }
}

int main() {
	cin >> S;
	cout << solve_Output() << endl;
	return 0;
}

Compilation message

palindrome.cpp:7:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning (disable: 4996)
 
palindrome.cpp: In function 'bool ispalindrome(std::__cxx11::string)':
palindrome.cpp:14:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < V.size(); i++) {
                  ~~^~~~~~~~~~
palindrome.cpp: In function 'long long int solve_Jury()':
palindrome.cpp:22:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < S.size(); i++) {
                  ~~^~~~~~~~~~
palindrome.cpp:24:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = i; j < S.size(); j++) {
                   ~~^~~~~~~~~~
palindrome.cpp: In function 'long long int solve_Output()':
palindrome.cpp:36:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < S.size(); i++) L[i] = (S[i] - 'a') + 1;
                  ~~^~~~~~~~~~
palindrome.cpp:43:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < S.size(); i++) { if (L[i] == t) { L1[cnt1] = make_pair(L[i], i); cnt1++; } }
                   ~~^~~~~~~~~~
palindrome.cpp:47:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 1; i <= S.size(); i += 2) {
                  ~~^~~~~~~~~~~
palindrome.cpp:57:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (pos1 >= 0 && pos2 < S.size() && L[pos1] == L[pos2]) {
                     ~~~~~^~~~~~~~~~
palindrome.cpp:63:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int k = 0; k < G[j].size(); k++) {
                    ~~^~~~~~~~~~~~~
palindrome.cpp:72:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < S.size() - 1; i++) { if (L[i] == L[i + 1] && L[i] == t) { L1[cnt1] = make_pair(L[i], i); cnt1++; } }
                   ~~^~~~~~~~~~~~~~
palindrome.cpp:76:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 2; i <= S.size(); i += 2) {
                  ~~^~~~~~~~~~~
palindrome.cpp:86:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (pos1 >= 0 && pos2 < S.size() && L[pos1] == L[pos2]) {
                     ~~~~~^~~~~~~~~~
palindrome.cpp:92:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int k = 0; k < G[j].size(); k++) {
                    ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 3 ms 428 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
21 Correct 3 ms 556 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 2 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 3 ms 556 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 10 ms 512 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 12 ms 512 KB Output is correct
6 Correct 11 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 7 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 484 ms 1712 KB Output is correct
2 Correct 250 ms 888 KB Output is correct
3 Correct 957 ms 1084 KB Output is correct
4 Correct 575 ms 1156 KB Output is correct
5 Correct 6 ms 768 KB Output is correct
6 Correct 22 ms 768 KB Output is correct
7 Correct 94 ms 848 KB Output is correct
8 Correct 6 ms 664 KB Output is correct
9 Correct 4 ms 512 KB Output is correct
10 Correct 7 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 1408 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 15 ms 1692 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -