ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213436 | #2355. Digit | shiruiheng | 0 | 11ms | 2496kb | C++11 | 1.4kb | 2024-11-11 22:41:47 | 2024-11-11 23:11:33 |
answer
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define pi pair<ll, ll>
#define pl pair<ll, pi>
#define fi first
#define se second
#define N 222222
ll n, ans, p, pw[N] = {1}, sum[N], dp[N], vis[N];
ll calc(ll n)
{
ll ans = 0, t;
while (n > 0)
{
t = n % 10;
ans += (t * t);
n /= 10;
}
return ans;
}
ll phi(ll x){
ll ans = x;
for(int i = 2 ; i <= x / i ; i++){
if(x % i == 0){
ans = x / i * (i - 1);
while(x % i == 0)
x /= i;
}
}
return ans;
}
priority_queue<pl> q;
signed main()
{
cin >> n;
p = phi(n);
for(int i = 1 ; i <= p ; i++)
pw[0] = pw[0] * 10 % n;
sum[0] = pw[0];
for(int i = 1 ; i < 2 * p ; i++){
pw[i] = pw[i - 1] * 10 % n;
sum[i] = (sum[i - 1] + pw[i]) % n;
}
dp[0] = calc(n);
for(int i = 1 ; i <= 9 ; i++)
for(int j = 0 ; j < 2 * p ; j++){
if(dp[i * pw[j] % n])
continue;
dp[i * pw[j] % n] = i * i;
q.push({-i * i, {i * pw[j] % n, j}});
}
while(q.size()){
pi u = q.top().se;
q.pop();
if(vis[u.fi])
continue;
if(!u.fi)
break;
if(dp[u.fi] >= dp[0])
break;
vis[u.fi] = true;
for(ll t = 1 ; t <= 9 ; t++)
for(ll r = u.se + 1 ; r < 2 * p ; r++){
ll v = (u.fi + pw[r] * t % n) % n;
if((dp[v] > dp[u.fi] + t * t) || (!dp[v]))
q.push({-(dp[v] = (dp[u.fi] + t * t)), {v, r}});
}
}
cout << dp[0];
exit(0);
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 0
Wrong Answer
time: 11ms
memory: 2496kb
input:
81920
output:
150
result:
wrong answer 1st numbers differ - expected: '1', found: '150'
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: 0
Time Limit Exceeded
input:
15047
output:
result:
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