Submission #857128


Source Code Expand

Copy
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
string str[1];
int n,k;
vector<int>divb[500005];
int num[1][20][500005];
vector<int>G[500005];
void make(int p){
	for(int i=0;i<n;i++) num[p][0][i] = 1 + str[p][i]-'a'; 
	for(int i=1;i<20;i++){
		int nxtt = 1;
		for(int j=0;j<n;j++){
			if(j+(1<<i) > n) continue;
			ll hoge = 1LL* num[p][i-1][j] * 299833 + 1LL* num[p][i-1][j+(1<<(i-1))];
			hoge %= 500005; //cout << i << " " << j << " " << hoge << endl;
			if(G[hoge].empty()){
				num[p][i][j] = nxtt++;
				G[hoge].pb(j);
			}
			else{
				for(int ii=0;ii<G[hoge].size();ii++){
					int x = G[hoge][ii];
					if(num[p][i-1][j] == num[p][i-1][x] && num[p][i-1][j+(1<<(i-1))] == num[p][i-1][x+(1<<(i-1))]){
						num[p][i][j] = num[p][i][x];
						goto nxt1;
					}
				}
				num[p][i][j] = nxtt++;G[hoge].pb(j); nxt1:;
			}
		}
		for(int i=0;i<500005;i++) G[i].clear();
	}
}
int main(){
	cin >> str[0]; n = str[0].size();
	reverse(str[0].begin(),str[0].end()); 
	make(0); 
	bool as = 0,rep = 0; int M = INF;
	for(int i=1;i<n;i++){
		if(n%i != 0) continue;
		int x = (n-i);
		int a = 0,b = i;
		for(int j=0;j<20;j++){
			if(((x>>j)&1)){
				if(num[0][j][a] == num[0][j][b]){
					a += (1<<j);
					b += (1<<j);
				}
				else goto nxt2;
			}
		}
		rep = 1; if(i == 1) as = 1; nxt2:;
	}
	for(int i=1;i<=500000;i++){
		for(int j=i+i;j<=500000;j+=i){
			divb[j].pb(i);
		}
	}
	
	if(as){
		cout << n << endl << 1 << endl; return 0;
	}
	if(!rep){
		cout << 1 << endl << 1 << endl; return 0;
	}
	{
		cout << 2 << endl;
		int ret = 0;
		for(int i=1;i<=n-1;i++){
			//pre=i back=n-i
			for(int j=0;j<divb[i].size();j++){
				int x = (i-divb[i][j]);
				int a = 0,b = divb[i][j];
				for(int j=0;j<20;j++){
					if(((x>>j)&1)){
						if(num[0][j][a] == num[0][j][b]){
							a += (1<<j);
							b += (1<<j);
						}
						else goto nxt;
					}
				}
				goto bad1; nxt:;
			}
			for(int j=0;j<divb[n-i].size();j++){
				int x = (n-i-divb[n-i][j]);
				int a = i,b = i+divb[n-i][j];
				
				for(int j=0;j<20;j++){
					if(((x>>j)&1)){
						if(num[0][j][a] == num[0][j][b]){
							a += (1<<j);
							b += (1<<j);
						}
						else goto nxt3;
					}
				}
				goto bad1; nxt3:;
			}
			ret++; bad1:;
		}
		assert(ret) ; cout << ret << endl;
	}
}

Submission Info

Submission Time
Task F - Best Representation
User IH19980412
Language C++14 (GCC 5.4.1)
Score 400
Code Size 3127 Byte
Status TLE
Exec Time 2116 ms
Memory 118788 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 400 / 400 0 / 500
Status
AC × 3
AC × 36
AC × 60
TLE × 5
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 986 ms 67584 KB
example_02.txt AC 1010 ms 67584 KB
example_03.txt AC 979 ms 67584 KB
subtask1_01.txt AC 1003 ms 67584 KB
subtask1_02.txt AC 998 ms 67584 KB
subtask1_03.txt AC 977 ms 67712 KB
subtask1_04.txt AC 971 ms 67840 KB
subtask1_05.txt AC 975 ms 67840 KB
subtask1_06.txt AC 972 ms 67840 KB
subtask1_07.txt AC 975 ms 67840 KB
subtask1_08.txt AC 1028 ms 67840 KB
subtask1_09.txt AC 998 ms 67840 KB
subtask1_10.txt AC 1052 ms 67840 KB
subtask1_11.txt AC 1068 ms 67968 KB
subtask1_12.txt AC 1099 ms 67968 KB
subtask1_13.txt AC 1065 ms 67968 KB
subtask1_14.txt AC 1072 ms 68352 KB
subtask1_15.txt AC 1025 ms 67584 KB
subtask1_16.txt AC 976 ms 67584 KB
subtask1_17.txt AC 973 ms 67584 KB
subtask1_18.txt AC 975 ms 67584 KB
subtask1_19.txt AC 980 ms 67840 KB
subtask1_20.txt AC 978 ms 67840 KB
subtask1_21.txt AC 981 ms 67840 KB
subtask1_22.txt AC 997 ms 67840 KB
subtask1_23.txt AC 979 ms 67840 KB
subtask1_24.txt AC 980 ms 67840 KB
subtask1_25.txt AC 987 ms 67968 KB
subtask1_26.txt AC 994 ms 67968 KB
subtask1_27.txt AC 976 ms 67840 KB
subtask1_28.txt AC 1134 ms 67840 KB
subtask1_29.txt AC 1043 ms 67840 KB
subtask1_30.txt AC 990 ms 67840 KB
subtask1_31.txt AC 980 ms 67840 KB
subtask1_32.txt AC 999 ms 67840 KB
subtask1_33.txt AC 989 ms 68096 KB
subtask2_01.txt AC 1673 ms 104580 KB
subtask2_02.txt AC 1251 ms 103172 KB
subtask2_03.txt AC 1209 ms 103172 KB
subtask2_04.txt AC 1204 ms 103172 KB
subtask2_05.txt AC 1207 ms 103172 KB
subtask2_06.txt AC 1201 ms 103172 KB
subtask2_07.txt AC 1227 ms 103172 KB
subtask2_08.txt AC 1331 ms 112260 KB
subtask2_09.txt AC 1909 ms 116740 KB
subtask2_10.txt AC 1929 ms 116996 KB
subtask2_11.txt AC 1934 ms 116228 KB
subtask2_12.txt TLE 2116 ms 118788 KB
subtask2_13.txt AC 1358 ms 103172 KB
subtask2_14.txt AC 1200 ms 103172 KB
subtask2_15.txt AC 1435 ms 103172 KB
subtask2_16.txt AC 1207 ms 103172 KB
subtask2_17.txt AC 1211 ms 103172 KB
subtask2_18.txt AC 1199 ms 103172 KB
subtask2_19.txt TLE 2116 ms 115844 KB
subtask2_20.txt TLE 2094 ms 115844 KB
subtask2_21.txt TLE 2115 ms 106116 KB
subtask2_22.txt AC 1938 ms 103300 KB
subtask2_23.txt TLE 2115 ms 103300 KB
subtask2_24.txt AC 1506 ms 98052 KB
subtask2_25.txt AC 1511 ms 99332 KB
subtask2_26.txt AC 1550 ms 101636 KB
subtask2_27.txt AC 1458 ms 96260 KB
subtask2_28.txt AC 1192 ms 92036 KB
subtask2_29.txt AC 1668 ms 107396 KB