Submission #36903869
Source Code Expand
#include <stdio.h>
#define MAX 3156
int N, P;
/* a + b mod P を返す */
int add(int a, int b) {
int ret = a + b;
/* [0, P) の数を2個足した結果は 2*P 未満 */
if (ret >= P) ret -= P;
return ret;
}
/* a * b mod P を返す */
int mul(int a, int b) {
return (int)((long long)a * b % P);
}
/* 同じ文字が len 文字連続した文字列に対して操作を行ったとき、何文字になるかを求める */
int elementLength(int len) {
int ans = 1; /* 最初にアルファベットを1個おく */
/* 文字数の十進表現の長さを求める */
do {
ans++;
len /= 10;
} while (len > 0);
return ans;
}
/* [もとの文字列を何文字決めたか][操作後の文字列が何文字になったか] */
int memo[MAX][MAX];
char memoValid[MAX][MAX];
int calc(int srcLen, int destLen) {
int ans = 0;
int i;
/* 操作後の文字列の長さが N 以上になったため、条件を満たさない */
if (destLen >= N) return 0;
/* 操作後の文字列の長さが N 未満のまま操作前の文字列が N 文字になったので、条件を満たす */
if (srcLen >= N) return 1;
/* メモがあるなら、その値を返す */
if (memoValid[srcLen][destLen]) return memo[srcLen][destLen];
/* 次に同じ文字を何文字置くか、それぞれを試す */
for (i = 1; srcLen + i <= N; i++) {
ans = add(ans, calc(srcLen + i, destLen + elementLength(i)));
}
if (srcLen == 0) {
/* 最初は、好きな文字を選べる */
ans = mul(ans, 26);
} else {
/* 前回使った文字以外の中から好きな文字を選べる */
ans = mul(ans, 25);
}
/* 結果をメモして返す */
memo[srcLen][destLen] = ans;
memoValid[srcLen][destLen] = 1;
return ans;
}
int main(void) {
if (scanf("%d%d", &N, &P) != 2) return 1;
printf("%d\n", calc(0, 0));
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - RLE |
| User | mikecat |
| Language | C (GCC 9.2.1) |
| Score | 0 |
| Code Size | 1909 Byte |
| Status | TLE |
| Exec Time | 3308 ms |
| Memory | 15028 KiB |
Judge Result
| Set Name | Sample | All | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 500 | ||||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example_00.txt, example_01.txt, example_02.txt, example_03.txt |
| All | example_00.txt, example_01.txt, example_02.txt, example_03.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| example_00.txt | AC | 4 ms | 1708 KiB |
| example_01.txt | AC | 1 ms | 1636 KiB |
| example_02.txt | AC | 1 ms | 1664 KiB |
| example_03.txt | TLE | 3308 ms | 15000 KiB |
| test_00.txt | TLE | 3308 ms | 14168 KiB |
| test_01.txt | AC | 26 ms | 3272 KiB |
| test_02.txt | TLE | 3308 ms | 13888 KiB |
| test_03.txt | TLE | 3308 ms | 14176 KiB |
| test_04.txt | AC | 5 ms | 1864 KiB |
| test_05.txt | AC | 295 ms | 6628 KiB |
| test_06.txt | TLE | 3308 ms | 13904 KiB |
| test_07.txt | TLE | 3308 ms | 13768 KiB |
| test_08.txt | AC | 1084 ms | 10140 KiB |
| test_09.txt | TLE | 3308 ms | 13980 KiB |
| test_10.txt | TLE | 3308 ms | 15028 KiB |
| test_11.txt | TLE | 3308 ms | 14152 KiB |
| test_12.txt | AC | 2646 ms | 13372 KiB |
| test_13.txt | TLE | 3308 ms | 13812 KiB |
| test_14.txt | TLE | 3308 ms | 13800 KiB |
| test_15.txt | AC | 12 ms | 2800 KiB |
| test_16.txt | AC | 137 ms | 5280 KiB |
| test_17.txt | TLE | 3308 ms | 13964 KiB |
| test_18.txt | TLE | 3308 ms | 13688 KiB |
| test_19.txt | TLE | 3308 ms | 14776 KiB |
| test_20.txt | TLE | 3308 ms | 14952 KiB |
| test_21.txt | TLE | 3308 ms | 14928 KiB |
| test_22.txt | TLE | 3308 ms | 14900 KiB |
| test_23.txt | TLE | 3308 ms | 14856 KiB |
| test_24.txt | TLE | 3308 ms | 14804 KiB |
| test_25.txt | TLE | 3308 ms | 14952 KiB |
| test_26.txt | AC | 7 ms | 1704 KiB |