UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213430#2355. Digiterican1001692ms38492kbC++111.6kb2024-11-11 22:08:032024-11-11 23:10:25

answer

// Problem: I - Escape
// Contest: Virtual Judge - 思维
// URL: https://vjudge.net/contest/670080#problem/I
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Challenger: Erica N
// ----
// 
#include<bits/stdc++.h>

using namespace std;
#define rd read()
#define ull unsigned long long
#define int long long 
#define pb push_back
#define itn int
#define ps second 
#define pf first


#define rd read()
int read(){
  int xx = 0, ff = 1;char ch = getchar();
  while (ch < '0' || ch > '9'){
    if (ch == '-')ff = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')xx = xx * 10 + (ch - '0'), ch = getchar();
  return xx * ff;
}
#define zerol = 1
#ifdef zerol
#define cdbg(x...) do { cerr << #x << " -> "; err(x); } while (0)
void err() {cerr << endl;}
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) {
	for (auto v: a) cerr << v << ' ';err(x...);
}
template<typename T, typename... A>
void err(T a, A... x) {
	cerr << a << ' ';err(x...);
}
#else
#define dbg(...)
#endif
const int N=5e5+5;
const ull P=137;
const int INF=1e18+7;
/*

策略


*/	



int f[N];
struct Node{
	int r=0;
	int s;
};
queue <Node> q;

signed main(){
	int k=rd;
	
	for(int i=0;i<N;i++)f[i]=INF;
	
	Node cur,cur2;
	for(int i=1;i<=9;i++){
		cur.r=i%k;
		cur.s=i*i;
		q.push(cur);
	}
	while(!q.empty()){
		cur2=q.front();
		q.pop();
		if(f[cur2.r]<=cur2.s)
			continue;
		f[cur2.r]=cur2.s;
		for(int i=0;i<=9;i++){
			cur.r=(10*cur2.r+i*i)%k;
			cur.s=cur2.s+i*i;
			q.push(cur);
		}
	}
	cout<<f[0];
}

详细

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

Test #1:

score: 10
Accepted
time: 73ms
memory: 21120kb

input:

81920

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 10
Accepted
time: 238ms
memory: 23256kb

input:

55966

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 10
Accepted
time: 314ms
memory: 35916kb

input:

92661

output:

3

result:

ok 1 number(s): "3"

Test #4:

score: 10
Accepted
time: 153ms
memory: 27436kb

input:

68013

output:

18

result:

ok 1 number(s): "18"

Test #5:

score: 10
Accepted
time: 150ms
memory: 28624kb

input:

72927

output:

27

result:

ok 1 number(s): "27"

Test #6:

score: 10
Accepted
time: 51ms
memory: 9776kb

input:

15047

output:

5

result:

ok 1 number(s): "5"

Test #7:

score: 10
Accepted
time: 134ms
memory: 23708kb

input:

59994

output:

36

result:

ok 1 number(s): "36"

Test #8:

score: 10
Accepted
time: 303ms
memory: 38492kb

input:

97273

output:

10

result:

ok 1 number(s): "10"

Test #9:

score: 10
Accepted
time: 142ms
memory: 21776kb

input:

51139

output:

14

result:

ok 1 number(s): "14"

Test #10:

score: 10
Accepted
time: 134ms
memory: 23592kb

input:

55788

output:

15

result:

ok 1 number(s): "15"

Extra Test:

score: 0
Extra Test Passed