ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213355 | #2355. Digit | KXG | 10 | 319ms | 632kb | C++11 | 893b | 2024-11-11 19:48:46 | 2024-11-11 23:02:29 |
answer
#include <cstdio>
#include <algorithm>
using namespace std;
int n, ans;
int pw10[610];
int dp[2][100010];
int main() {
scanf("%d", &n);
for (int i = 0; i <= 500; i++) {
if (i == 0) pw10[i] = 1;
else pw10[i] = pw10[i - 1] * 10 % n;
}
int flag = 0;
for (int i = 0; i < n; i++) {
dp[0][i] = 1e9;
}
for (int i = 0; i <= 500; i++) {
flag ^= 1;
for (int j = 0; j < n; j++) {
dp[flag][j] = 1e9;
}
for (int j = 0; j <= 9; j++) {
for (int k = 0; k < n; k++) {
dp[flag][k] = min(dp[flag][k], dp[flag ^ 1][(k - j * pw10[i] % n + n) % n] + j * j);
}
if (j != 0) {
dp[flag][j * pw10[i] % n] = min(dp[flag][j * pw10[i] % n], j * j);
}
}
}
printf("%d\n", dp[flag][0]);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 0
Time Limit Exceeded
input:
81920
output:
result:
Test #2:
score: 0
Time Limit Exceeded
input:
55966
output:
result:
Test #3:
score: 0
Time Limit Exceeded
input:
92661
output:
result:
Test #4:
score: 0
Time Limit Exceeded
input:
68013
output:
result:
Test #5:
score: 0
Time Limit Exceeded
input:
72927
output:
result:
Test #6:
score: 10
Accepted
time: 319ms
memory: 632kb
input:
15047
output:
5
result:
ok 1 number(s): "5"
Test #7:
score: 0
Time Limit Exceeded
input:
59994
output:
result:
Test #8:
score: 0
Time Limit Exceeded
input:
97273
output:
result:
Test #9:
score: 0
Time Limit Exceeded
input:
51139
output:
result:
Test #10:
score: 0
Time Limit Exceeded
input:
55788