Submission #856226


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

struct RollingHash {
	static const ll mo0=1000000007,mo1=1000000009;
	static ll mul0,mul1;
	static const ll add0=1000010007, add1=1003333331;
	static vector<ll> pmo[2];
	string s; int l; vector<ll> hash_[2];
	void init(string s) {
		this->s=s; l=s.size(); int i,j;
		hash_[0]=hash_[1]=vector<ll>(1,0);
		if(!mul0) mul0=10009+(((ll)&mul0)>>5)%259,mul1=10007+(((ll)&mul1)>>5)%257;
		if(pmo[0].empty()) pmo[0].push_back(1),pmo[1].push_back(1);
		FOR(i,l) hash_[0].push_back((hash_[0].back()*mul0+add0+s[i])%mo0);
		FOR(i,l) hash_[1].push_back((hash_[1].back()*mul1+add1+s[i])%mo1);
	}
	pair<ll,ll> hash(int l,int r) { // s[l..r]
		if(l>r) return make_pair(0,0);
		while(pmo[0].size()<r+2)
			pmo[0].push_back(pmo[0].back()*mul0%mo0), pmo[1].push_back(pmo[1].back()*mul1%mo1);
		return make_pair((hash_[0][r+1]+(mo0-hash_[0][l]*pmo[0][r+1-l]%mo0))%mo0,
			             (hash_[1][r+1]+(mo1-hash_[1][l]*pmo[1][r+1-l]%mo1))%mo1);
	}
	pair<ll,ll> hash(string s) { init(s); return hash(0,s.size()-1); }
	static pair<ll,ll> concat(pair<ll,ll> L,pair<ll,ll> R,int RL) { // hash(L+R) RL=len-of-R
		while(pmo[0].size()<RL+2) pmo[0].push_back(pmo[0].back()*mul0%mo0), pmo[1].push_back(pmo[1].back()*mul1%mo1);
		return make_pair((R.first + L.first*pmo[0][RL])%mo0,(R.second + L.second*pmo[1][RL])%mo1);
	}
};
vector<ll> RollingHash::pmo[2]; ll RollingHash::mul0,RollingHash::mul1;

string W;
int L;
int NG[4040][4040];
int num[4040];
ll pat[4040];

int prefixNG[505050];
int suffixNG[505050];


ll mo=1000000007;

RollingHash rh;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>W;
	rh.init(W);
	L=W.size();
	
	// allsame;
	FOR(i,26) {
		if(count(W.begin(),W.end(),'a'+i)==L) return _P("%d\n%d\n",L,1);
	}
	
	for(l=1;l<=L;l++) if(prefixNG[l-1]==0) {
		for(x=l;x+l<=L;x+=l) {
			if(rh.hash(0,l-1)!=rh.hash(x,x+l-1)) break;
			prefixNG[x+l-1]=1;
		}
	}
	if(prefixNG[L-1]==0) return _P("1\n1\n");
	for(l=1;l<=L;l++) if(suffixNG[L-l]==0) {
		for(x=L-l-l;x-l>=0;x-=l) {
			if(rh.hash(x,x+l-1)!=rh.hash(x+l,x+l+l-1)) break;
			suffixNG[x]=1;
		}
	}
	int tot=0;
	FOR(i,L-1) if(prefixNG[i]==0 && suffixNG[i+1]==0) tot++;
	_P("%d\n%d\n",2,tot);
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}

Submission Info

Submission Time
Task F - Best Representation
User kmjp
Language C++14 (GCC 5.4.1)
Score 900
Code Size 2890 Byte
Status AC
Exec Time 145 ms
Memory 20940 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 400 / 400 500 / 500
Status
AC × 3
AC × 36
AC × 65
Set Name Test Cases
Sample example_01.txt, example_02.txt, example_03.txt
Subtask1 example_01.txt, example_02.txt, example_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt, subtask1_22.txt, subtask1_23.txt, subtask1_24.txt, subtask1_25.txt, subtask1_26.txt, subtask1_27.txt, subtask1_28.txt, subtask1_29.txt, subtask1_30.txt, subtask1_31.txt, subtask1_32.txt, subtask1_33.txt
All example_01.txt, example_02.txt, example_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt, subtask1_22.txt, subtask1_23.txt, subtask1_24.txt, subtask1_25.txt, subtask1_26.txt, subtask1_27.txt, subtask1_28.txt, subtask1_29.txt, subtask1_30.txt, subtask1_31.txt, subtask1_32.txt, subtask1_33.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask2_13.txt, subtask2_14.txt, subtask2_15.txt, subtask2_16.txt, subtask2_17.txt, subtask2_18.txt, subtask2_19.txt, subtask2_20.txt, subtask2_21.txt, subtask2_22.txt, subtask2_23.txt, subtask2_24.txt, subtask2_25.txt, subtask2_26.txt, subtask2_27.txt, subtask2_28.txt, subtask2_29.txt
Case Name Status Exec Time Memory
example_01.txt AC 4 ms 256 KB
example_02.txt AC 4 ms 256 KB
example_03.txt AC 4 ms 256 KB
subtask1_01.txt AC 4 ms 256 KB
subtask1_02.txt AC 4 ms 256 KB
subtask1_03.txt AC 4 ms 384 KB
subtask1_04.txt AC 4 ms 384 KB
subtask1_05.txt AC 5 ms 512 KB
subtask1_06.txt AC 5 ms 512 KB
subtask1_07.txt AC 5 ms 384 KB
subtask1_08.txt AC 5 ms 512 KB
subtask1_09.txt AC 5 ms 512 KB
subtask1_10.txt AC 5 ms 512 KB
subtask1_11.txt AC 5 ms 512 KB
subtask1_12.txt AC 5 ms 512 KB
subtask1_13.txt AC 5 ms 512 KB
subtask1_14.txt AC 5 ms 512 KB
subtask1_15.txt AC 4 ms 256 KB
subtask1_16.txt AC 4 ms 256 KB
subtask1_17.txt AC 4 ms 256 KB
subtask1_18.txt AC 4 ms 256 KB
subtask1_19.txt AC 5 ms 512 KB
subtask1_20.txt AC 5 ms 512 KB
subtask1_21.txt AC 5 ms 512 KB
subtask1_22.txt AC 5 ms 512 KB
subtask1_23.txt AC 5 ms 512 KB
subtask1_24.txt AC 5 ms 512 KB
subtask1_25.txt AC 5 ms 512 KB
subtask1_26.txt AC 5 ms 512 KB
subtask1_27.txt AC 5 ms 512 KB
subtask1_28.txt AC 5 ms 512 KB
subtask1_29.txt AC 5 ms 512 KB
subtask1_30.txt AC 5 ms 512 KB
subtask1_31.txt AC 5 ms 512 KB
subtask1_32.txt AC 5 ms 512 KB
subtask1_33.txt AC 5 ms 512 KB
subtask2_01.txt AC 110 ms 16772 KB
subtask2_02.txt AC 72 ms 11280 KB
subtask2_03.txt AC 129 ms 19624 KB
subtask2_04.txt AC 112 ms 18600 KB
subtask2_05.txt AC 62 ms 11280 KB
subtask2_06.txt AC 129 ms 19620 KB
subtask2_07.txt AC 119 ms 18596 KB
subtask2_08.txt AC 114 ms 18724 KB
subtask2_09.txt AC 130 ms 18724 KB
subtask2_10.txt AC 130 ms 18596 KB
subtask2_11.txt AC 130 ms 18724 KB
subtask2_12.txt AC 130 ms 18596 KB
subtask2_13.txt AC 145 ms 20940 KB
subtask2_14.txt AC 125 ms 19620 KB
subtask2_15.txt AC 140 ms 20940 KB
subtask2_16.txt AC 125 ms 19620 KB
subtask2_17.txt AC 124 ms 19620 KB
subtask2_18.txt AC 119 ms 18596 KB
subtask2_19.txt AC 131 ms 18980 KB
subtask2_20.txt AC 133 ms 18980 KB
subtask2_21.txt AC 123 ms 18120 KB
subtask2_22.txt AC 128 ms 20940 KB
subtask2_23.txt AC 133 ms 20940 KB
subtask2_24.txt AC 117 ms 18160 KB
subtask2_25.txt AC 123 ms 18692 KB
subtask2_26.txt AC 128 ms 19816 KB
subtask2_27.txt AC 108 ms 17924 KB
subtask2_28.txt AC 76 ms 14464 KB
subtask2_29.txt AC 108 ms 16780 KB