Submission #857392


Source Code Expand

Copy
#include<cstdio>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<string>
#include<assert.h>
#include<sstream>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define setIO(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
typedef long long ll;
typedef pair<int, int> pii;
const ll LINF = 1e18 + 7;
const int N = 5e5 + 7;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
//-------------head-------------
int n, p[N], f[N];
char w[N];
void kmp(int n, char s[]) {
	p[0] = -1;
	for (int i = 1, j = -1; i < n; ++i) {
		while (j >= 0 && s[j + 1] != s[i])
			j = p[j];
		j += s[j + 1] == s[i];
		p[i] = j;
	}
}
int main() {
	scanf(" %s", w);
	n = strlen(w);
	kmp(n, w);
	int L = n - 1 - p[n - 1];
	if (L == 1) {
		printf("%d\n1\n", n);
	} else if (L == n || n % L != 0) {
		printf("1\n1\n");
	} else {
		rep(i, 0, n - 1)
			f[i] = (p[i] == -1 || (i + 1) % (i - p[i]) != 0);
		reverse(w, w + n);
		kmp(n, w);
		int ans = 0;
		rep(i, 0, n)
			if ((p[i] == -1 || (i + 1) % (i - p[i]) != 0)
					&& (i == n - 1 || f[n - 2 - i]))
				++ans;
		printf("2\n%d\n", ans);
	}
	return 0;
}

Submission Info

Submission Time
Task F - Best Representation
User mcginn
Language C++14 (GCC 5.4.1)
Score 900
Code Size 1351 Byte
Status AC
Exec Time 26 ms
Memory 4608 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:39:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf(" %s", w);
                 ^

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 256 KB
subtask1_04.txt AC 4 ms 256 KB
subtask1_05.txt AC 4 ms 256 KB
subtask1_06.txt AC 4 ms 256 KB
subtask1_07.txt AC 4 ms 256 KB
subtask1_08.txt AC 4 ms 256 KB
subtask1_09.txt AC 4 ms 256 KB
subtask1_10.txt AC 4 ms 256 KB
subtask1_11.txt AC 4 ms 256 KB
subtask1_12.txt AC 4 ms 256 KB
subtask1_13.txt AC 4 ms 256 KB
subtask1_14.txt AC 4 ms 256 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 4 ms 256 KB
subtask1_20.txt AC 4 ms 256 KB
subtask1_21.txt AC 4 ms 256 KB
subtask1_22.txt AC 4 ms 256 KB
subtask1_23.txt AC 4 ms 256 KB
subtask1_24.txt AC 4 ms 256 KB
subtask1_25.txt AC 4 ms 256 KB
subtask1_26.txt AC 4 ms 256 KB
subtask1_27.txt AC 4 ms 256 KB
subtask1_28.txt AC 4 ms 256 KB
subtask1_29.txt AC 4 ms 256 KB
subtask1_30.txt AC 4 ms 256 KB
subtask1_31.txt AC 4 ms 256 KB
subtask1_32.txt AC 4 ms 256 KB
subtask1_33.txt AC 4 ms 256 KB
subtask2_01.txt AC 19 ms 3712 KB
subtask2_02.txt AC 11 ms 2688 KB
subtask2_03.txt AC 13 ms 2688 KB
subtask2_04.txt AC 12 ms 2688 KB
subtask2_05.txt AC 11 ms 2688 KB
subtask2_06.txt AC 13 ms 2688 KB
subtask2_07.txt AC 12 ms 2688 KB
subtask2_08.txt AC 11 ms 2688 KB
subtask2_09.txt AC 25 ms 4608 KB
subtask2_10.txt AC 24 ms 4608 KB
subtask2_11.txt AC 24 ms 4608 KB
subtask2_12.txt AC 23 ms 4608 KB
subtask2_13.txt AC 26 ms 4608 KB
subtask2_14.txt AC 12 ms 2688 KB
subtask2_15.txt AC 23 ms 4608 KB
subtask2_16.txt AC 12 ms 2688 KB
subtask2_17.txt AC 11 ms 2688 KB
subtask2_18.txt AC 13 ms 2688 KB
subtask2_19.txt AC 23 ms 4608 KB
subtask2_20.txt AC 24 ms 4608 KB
subtask2_21.txt AC 24 ms 4352 KB
subtask2_22.txt AC 24 ms 4608 KB
subtask2_23.txt AC 25 ms 4608 KB
subtask2_24.txt AC 21 ms 3968 KB
subtask2_25.txt AC 23 ms 4224 KB
subtask2_26.txt AC 23 ms 4480 KB
subtask2_27.txt AC 20 ms 3840 KB
subtask2_28.txt AC 7 ms 1536 KB
subtask2_29.txt AC 19 ms 3712 KB