답안 #146836

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
146836 2019-08-26T11:10:34 Z MvC 회문 (APIO14_palindrome) C++14
23 / 100
901 ms 26940 KB
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
//#include "boxes.h"
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<61);
const int inf=(1<<30);
const int nmax=1e4+50;
const ll mod=1e9+7;
const ll p=31;
using namespace std;
int n,i,rs,x,r,l;
bitset<nmax>b[nmax];
string s;
char c[nmax];
ll pw[nmax],in;
map<int,int>mp;
void ad(int &x,int y)
{
	x+=y;
	if(x>=mod)x-=mod;
	if(x<0)x+=mod;
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>s;
	n=s.size();
	for(i=1;i<=n;i++)c[i]=s[i-1];
	pw[0]=1;
	for(i=1;i<=n;i++)pw[i]=(pw[i-1]*p)%mod;
	in=129032259;
	for(i=1;i<=n;i++)
	{
		x=0;
		mp.clear();
		for(r=1;r<i;r++)
		{
			ad(x,pw[r-1]*c[r]%mod);
		}
		for(r=i;r<=n;r++)
		{
			ad(x,pw[i-1]*c[r]%mod);
			l=r-i+1;
			if(i==1)b[l][r]=1;
			else if(i==2 && c[r]==c[l])b[l][r]=1;
			else if(i==3 && c[r]==c[l])b[l][r]=1;
			else if(i>3 && c[r]==c[l] && b[l+1][r-1])b[l][r]=1;
			if(b[l][r])
			{
				mp[x]++;
				rs=max(rs,i*mp[x]);
			}
			ad(x,-c[r-i+1]);
			x=(x*in)%mod;
		}
		if((double)clock()/CLOCKS_PER_SEC>0.900)break;
	}
	//cout<<fixed<<setprecision(5)<<(double)clock()/CLOCKS_PER_SEC<<endl;
	cout<<rs<<endl;
	return 0;
}

Compilation message

palindrome.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization("O3")
 
palindrome.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization("unroll-loops")
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 3 ms 504 KB Output is correct
24 Correct 2 ms 504 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 2 ms 504 KB Output is correct
27 Correct 2 ms 504 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 2 ms 504 KB Output is correct
31 Correct 2 ms 504 KB Output is correct
32 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 1704 KB Output is correct
2 Correct 15 ms 1528 KB Output is correct
3 Correct 17 ms 1656 KB Output is correct
4 Correct 16 ms 1528 KB Output is correct
5 Correct 16 ms 1528 KB Output is correct
6 Correct 16 ms 1656 KB Output is correct
7 Correct 15 ms 1528 KB Output is correct
8 Correct 15 ms 1656 KB Output is correct
9 Correct 16 ms 1528 KB Output is correct
10 Correct 17 ms 1656 KB Output is correct
11 Correct 17 ms 1656 KB Output is correct
12 Correct 17 ms 1656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 901 ms 12872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 27 ms 26488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 39 ms 26940 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -