Submission #36904203
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 sub(int a, int b) { if (b == 0) return a; /* b が正のとき、P - b は P 未満 */ /* b が P 未満 のとき、P - b は正 */ return add(a, P - b); } /* 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]; /* もとの文字列の長さの降順の累積和 */ int memoSum[MAX][MAX]; int main(void) { int srcLen, destLen; if (scanf("%d%d", &N, &P) != 2) return 1; /* 操作後の文字列が N 文字未満で、操作前の文字列が N 文字に到達した */ for (destLen = 0; destLen < N; destLen++) { memo[N][destLen] = 1; memoSum[N][destLen] = 1; } /* 操作前の文字列の長い順に求めていく */ for (srcLen = N - 1; srcLen >= 0; srcLen--) { /* 操作後の文字列が N 文字以上になったら条件を満たさないので、そこまで求めればいい */ for (destLen = 0; destLen < N; destLen++) { int ans = 0; int i; int delta = 2; /* 操作後の文字列の長さが増える量 */ int deltaLast = 9; /* 増える量が delta となる最後の置く長さ */ /* 次に同じ文字を何文字置くか、それぞれを試す */ for (i = 1; srcLen + i <= N; ) { /* 操作前の文字列が N 文字になるまでで打ち切る */ if (srcLen + deltaLast > N) deltaLast = N - srcLen; /* 累積和を用いて加算する */ ans = add(ans, sub(memoSum[srcLen + i][destLen + delta], memoSum[srcLen + deltaLast + 1][destLen + delta])); /* 次の部分について求める準備をする */ i= deltaLast + 1; delta++; deltaLast = deltaLast * 10 + 9; } if (srcLen == 0) { /* 最初は、好きな文字を選べる */ ans = mul(ans, 26); } else { /* 前回使った文字以外の中から好きな文字を選べる */ ans = mul(ans, 25); } /* 結果をメモする */ memo[srcLen][destLen] = ans; /* 累積和をとる */ memoSum[srcLen][destLen] = add(memo[srcLen][destLen], memoSum[srcLen + 1][destLen]); } } printf("%d\n", memo[0][0]); return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - RLE |
User | mikecat |
Language | C (GCC 9.2.1) |
Score | 500 |
Code Size | 2849 Byte |
Status | AC |
Exec Time | 228 ms |
Memory | 75728 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 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 | 2 ms | 1660 KiB |
example_01.txt | AC | 1 ms | 1748 KiB |
example_02.txt | AC | 1 ms | 1700 KiB |
example_03.txt | AC | 228 ms | 75728 KiB |
test_00.txt | AC | 54 ms | 23916 KiB |
test_01.txt | AC | 4 ms | 3712 KiB |
test_02.txt | AC | 72 ms | 33028 KiB |
test_03.txt | AC | 48 ms | 23060 KiB |
test_04.txt | AC | 1 ms | 1972 KiB |
test_05.txt | AC | 16 ms | 8752 KiB |
test_06.txt | AC | 64 ms | 30516 KiB |
test_07.txt | AC | 72 ms | 32768 KiB |
test_08.txt | AC | 25 ms | 14768 KiB |
test_09.txt | AC | 145 ms | 59592 KiB |
test_10.txt | AC | 224 ms | 75552 KiB |
test_11.txt | AC | 46 ms | 22828 KiB |
test_12.txt | AC | 40 ms | 20712 KiB |
test_13.txt | AC | 83 ms | 39056 KiB |
test_14.txt | AC | 87 ms | 39772 KiB |
test_15.txt | AC | 2 ms | 3000 KiB |
test_16.txt | AC | 10 ms | 6636 KiB |
test_17.txt | AC | 50 ms | 24856 KiB |
test_18.txt | AC | 79 ms | 36644 KiB |
test_19.txt | AC | 209 ms | 72716 KiB |
test_20.txt | AC | 224 ms | 75716 KiB |
test_21.txt | AC | 227 ms | 75628 KiB |
test_22.txt | AC | 224 ms | 75648 KiB |
test_23.txt | AC | 215 ms | 74216 KiB |
test_24.txt | AC | 217 ms | 74364 KiB |
test_25.txt | AC | 224 ms | 75272 KiB |
test_26.txt | AC | 1 ms | 1668 KiB |