UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213392#2355. DigitSTASISZHY402140ms27720kbC++11860b2024-11-11 21:21:052024-11-11 23:06:39

answer

// Problem: D. Digit
// Contest: undefined - NOIP2024训练赛 02
// URL: http://119.28.3.174/contest/1154/problem/2355
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
#define fi first
#define se second
#define PII pair<int, int>

using namespace std;

const int N = 1e5 + 10, INF = 0x3f3f3f3f;

int n, up;
bool dp[N][330]; 
 
void dfs(int now, int sum)
{
	if(sum >= up || dp[now][sum]) return;
	dp[now][sum] = true;
	for(int i = 0; i <= 9; i ++) dfs((now * 10 + i) % n, sum + i * i);
}

signed main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n; int x = n; while(x) up += (x % 10) * (x % 10), x /= 10;
	for(int i = 1; i <= 9; i ++) dfs(i, i);
	for(int i = 1; i <= up; i ++) if(dp[0][i]) {cout << i << '\n'; return 0;}
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 753ms
memory: 27720kb

input:

81920

output:

1

result:

ok 1 number(s): "1"

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: 90ms
memory: 11156kb

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: 10
Accepted
time: 392ms
memory: 17780kb

input:

51139

output:

14

result:

ok 1 number(s): "14"

Test #10:

score: 10
Accepted
time: 905ms
memory: 19284kb

input:

55788

output:

15

result:

ok 1 number(s): "15"