답안 #172456

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
172456 2020-01-01T14:59:38 Z dndhk 회문 (APIO14_palindrome) C++14
23 / 100
708 ms 131076 KB
#include <bits/stdc++.h>

#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const ll p = 29;
const ll P1 = 1000000007;
const ll P2 = 1000000009;
const int MAX_N = 300000;

int N;
string str;
vector<pll> vt[MAX_N+1];

ll ans = 0;

int main(){
	cin>>str;
	N = str.size();
	for(int i=0; i<N; i++){
		pll now = {str[i]-'a'+1, str[i]-'a'+1};
		ll m1=p, m2=p;
		pll now2 = {str[i]-'a'+1, str[i]-'a'+1};
		vt[1].pb(now);
		for(int j=i+1; j<N; j++){
			now.first = (now.first * p + str[j]-'a' + 1) % P1;
			now.second = (now.second * p + str[j]-'a'+1) % P2;
			now2.first = (now2.first + m1 * (ll)(str[j]-'a'+1)) % P1;
			now2.second = (now2.second + m2 * (ll)(str[j]-'a'+1)) % P2;
			m1 = (m1 * p) % P1; m2 = (m2 * p) % P2;
			if(now.first==now2.first && now.second==now2.second)	vt[j-i+1].pb(now);
		}
	}
	for(int i=1; i<=N; i++){
		sort(vt[i].begin(), vt[i].end());
		int s = 0, e = 0;
		while(s<vt[i].size()){
			while(e<vt[i].size()-1 && vt[i][s].first==vt[i][e+1].first && vt[i][s].second==vt[i][e+1].second){
				e++;
			}
			ans = max(ans, (ll)(e-s+1) * (ll)i);
			s = e+1; e++;
		}
	}
	cout<<ans;
	return 0;
}

Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:56:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(s<vt[i].size()){
         ~^~~~~~~~~~~~~
palindrome.cpp:57:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while(e<vt[i].size()-1 && vt[i][s].first==vt[i][e+1].first && vt[i][s].second==vt[i][e+1].second){
          ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 7416 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 8 ms 7416 KB Output is correct
4 Correct 8 ms 7288 KB Output is correct
5 Correct 8 ms 7416 KB Output is correct
6 Correct 8 ms 7416 KB Output is correct
7 Correct 8 ms 7288 KB Output is correct
8 Correct 8 ms 7416 KB Output is correct
9 Correct 8 ms 7416 KB Output is correct
10 Correct 8 ms 7416 KB Output is correct
11 Correct 8 ms 7416 KB Output is correct
12 Correct 8 ms 7416 KB Output is correct
13 Correct 8 ms 7416 KB Output is correct
14 Correct 8 ms 7416 KB Output is correct
15 Correct 8 ms 7544 KB Output is correct
16 Correct 8 ms 7416 KB Output is correct
17 Correct 8 ms 7416 KB Output is correct
18 Correct 8 ms 7416 KB Output is correct
19 Correct 8 ms 7416 KB Output is correct
20 Correct 9 ms 7416 KB Output is correct
21 Correct 8 ms 7420 KB Output is correct
22 Correct 8 ms 7416 KB Output is correct
23 Correct 9 ms 7416 KB Output is correct
24 Correct 9 ms 7416 KB Output is correct
25 Correct 8 ms 7544 KB Output is correct
26 Correct 8 ms 7416 KB Output is correct
27 Correct 9 ms 7416 KB Output is correct
28 Correct 9 ms 7416 KB Output is correct
29 Correct 9 ms 7416 KB Output is correct
30 Correct 8 ms 7288 KB Output is correct
31 Correct 8 ms 7388 KB Output is correct
32 Correct 8 ms 7416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 12536 KB Output is correct
2 Correct 21 ms 9976 KB Output is correct
3 Correct 38 ms 17656 KB Output is correct
4 Correct 17 ms 8056 KB Output is correct
5 Correct 39 ms 17528 KB Output is correct
6 Correct 41 ms 17656 KB Output is correct
7 Correct 16 ms 7416 KB Output is correct
8 Correct 27 ms 12408 KB Output is correct
9 Correct 16 ms 7672 KB Output is correct
10 Correct 15 ms 7420 KB Output is correct
11 Correct 15 ms 7416 KB Output is correct
12 Correct 16 ms 7416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 466 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 631 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 708 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -