ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213405 | #2355. Digit | Filberte | 100 | 4071ms | 34296kb | C++11 | 1.3kb | 2024-11-11 21:38:44 | 2024-11-11 23:10:45 |
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 100;
namespace dijkstra{
vector<pair<int, ll>> g[N];
bool vis[N];
ll dis[N];
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> q;
ll Dij(int s, int t){
memset(dis, 0x3f, sizeof(dis));
memset(vis, 0, sizeof(vis));
ll _unr = dis[0];
dis[s] = 0;
q.push(make_pair(dis[s], s));
while(!q.empty()){
int u = q.top().second;q.pop();
if(vis[u]) continue;
vis[u] = 1;
for(int i = 0;i < (int)g[u].size();i++){
int v = g[u][i].first, w = g[u][i].second;
if(dis[u] + w < dis[v]){
dis[v] = dis[u] + w;
q.push(make_pair(dis[v], v));
}
}
}
return dis[t];
}
}
using namespace dijkstra;
int n;
int main(){
cin >> n;
for(int x = 1;x < n;x++){
for(int r = 0;r <= 9;r++){
int u = x, v = (x * 10 + r) % n, w = r * r;
g[u].push_back({v, w});
}
}
ll ans = 1e18;
for(int s = 1;s < min(10, n);s++) ans = min(ans, Dij(s, 0) + s);
cout << ans << endl;
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 382ms
memory: 27072kb
input:
81920
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 10
Accepted
time: 405ms
memory: 21224kb
input:
55966
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 10
Accepted
time: 491ms
memory: 33068kb
input:
92661
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: 10
Accepted
time: 554ms
memory: 26524kb
input:
68013
output:
18
result:
ok 1 number(s): "18"
Test #5:
score: 10
Accepted
time: 625ms
memory: 27828kb
input:
72927
output:
27
result:
ok 1 number(s): "27"
Test #6:
score: 10
Accepted
time: 57ms
memory: 8916kb
input:
15047
output:
5
result:
ok 1 number(s): "5"
Test #7:
score: 10
Accepted
time: 348ms
memory: 22296kb
input:
59994
output:
36
result:
ok 1 number(s): "36"
Test #8:
score: 10
Accepted
time: 621ms
memory: 34296kb
input:
97273
output:
10
result:
ok 1 number(s): "10"
Test #9:
score: 10
Accepted
time: 329ms
memory: 19940kb
input:
51139
output:
14
result:
ok 1 number(s): "14"
Test #10:
score: 10
Accepted
time: 259ms
memory: 21176kb
input:
55788
output:
15
result:
ok 1 number(s): "15"
Extra Test:
score: 0
Extra Test Passed