Submission #856429


Source Code Expand

Copy
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

char S[100005];
int dp[4003][4003];
int pre[100005];

LL MOD = 1000000007;
int cnt[4003];
LL ans[4003];

int main()
{
	scanf("%s", S);
	int len = strlen(S);
	assert(len <= 4000);

	for (int i = 0; i < len; i++) {
		int now = i - 1;
		pre[i] = i - 1;
		for (int j = i + 1; j < len; j++) {
			while (now != i - 1 && S[j] != S[now + 1]) {
				now = pre[now];
			}
			if (S[j] == S[now + 1]) pre[j] = now = now + 1;
			else pre[j] = now = i - 1;

			if (now != i - 1) {
				int last = (j - i + 1) % (j - now);
				if (last == 0) dp[i][j] = 1;
			}
		}
	}

	MEM(cnt, -1);
	MEM(ans, 0);

	cnt[0] = 0;
	ans[0] = 1;
	for (int i = 0; i < len; i++) {
		for (int j = 0; j <= i; j++) {
			if (dp[j][i]) continue;
			if ((j == 0 || cnt[j - 1 + 1] != -1)) {
				int now_cnt = (j == 0 ? 1 : cnt[j - 1 + 1] + 1);
				LL now_ans = (j == 0 ? 1 : ans[j - 1 + 1]);
				if (cnt[i + 1] == -1 || cnt[i + 1] > now_cnt) {
					cnt[i + 1] = now_cnt;
					ans[i + 1] = now_ans;
				}
				else if (cnt[i + 1] == now_cnt) {
					ans[i + 1] = (ans[i + 1] + now_ans) % MOD;
				}
			}
		}
	}
	printf("%d\n%lld\n", cnt[len], ans[len]);
	return 0;
}

Submission Info

Submission Time
Task F - Best Representation
User dragoon
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2287 Byte
Status RE
Exec Time 295 ms
Memory 45568 KB

Compile Error

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

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 400 / 400 0 / 500
Status
AC × 3
AC × 36
AC × 36
RE × 29
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 14 ms 4096 KB
subtask1_04.txt AC 252 ms 44800 KB
subtask1_05.txt AC 284 ms 44800 KB
subtask1_06.txt AC 252 ms 44800 KB
subtask1_07.txt AC 266 ms 45568 KB
subtask1_08.txt AC 290 ms 45440 KB
subtask1_09.txt AC 259 ms 45440 KB
subtask1_10.txt AC 261 ms 36224 KB
subtask1_11.txt AC 250 ms 27136 KB
subtask1_12.txt AC 243 ms 27136 KB
subtask1_13.txt AC 234 ms 22144 KB
subtask1_14.txt AC 188 ms 1152 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 293 ms 45440 KB
subtask1_20.txt AC 286 ms 45440 KB
subtask1_21.txt AC 295 ms 45440 KB
subtask1_22.txt AC 286 ms 45440 KB
subtask1_23.txt AC 294 ms 45440 KB
subtask1_24.txt AC 264 ms 45440 KB
subtask1_25.txt AC 232 ms 24448 KB
subtask1_26.txt AC 242 ms 24448 KB
subtask1_27.txt AC 262 ms 40704 KB
subtask1_28.txt AC 274 ms 44544 KB
subtask1_29.txt AC 272 ms 44544 KB
subtask1_30.txt AC 240 ms 35200 KB
subtask1_31.txt AC 264 ms 38912 KB
subtask1_32.txt AC 265 ms 41344 KB
subtask1_33.txt AC 212 ms 12800 KB
subtask2_01.txt RE 191 ms 384 KB
subtask2_02.txt RE 192 ms 384 KB
subtask2_03.txt RE 188 ms 384 KB
subtask2_04.txt RE 190 ms 384 KB
subtask2_05.txt RE 189 ms 384 KB
subtask2_06.txt RE 191 ms 384 KB
subtask2_07.txt RE 192 ms 384 KB
subtask2_08.txt RE 193 ms 384 KB
subtask2_09.txt RE 192 ms 384 KB
subtask2_10.txt RE 190 ms 384 KB
subtask2_11.txt RE 189 ms 384 KB
subtask2_12.txt RE 189 ms 384 KB
subtask2_13.txt RE 189 ms 384 KB
subtask2_14.txt RE 190 ms 384 KB
subtask2_15.txt RE 188 ms 384 KB
subtask2_16.txt RE 187 ms 384 KB
subtask2_17.txt RE 191 ms 384 KB
subtask2_18.txt RE 188 ms 384 KB
subtask2_19.txt RE 188 ms 384 KB
subtask2_20.txt RE 187 ms 384 KB
subtask2_21.txt RE 189 ms 384 KB
subtask2_22.txt RE 190 ms 384 KB
subtask2_23.txt RE 190 ms 384 KB
subtask2_24.txt RE 189 ms 384 KB
subtask2_25.txt RE 194 ms 384 KB
subtask2_26.txt RE 193 ms 384 KB
subtask2_27.txt RE 188 ms 384 KB
subtask2_28.txt RE 191 ms 384 KB
subtask2_29.txt RE 191 ms 384 KB