Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
#include
#include
#include
using namespace std; struct node { int idx, cost; node () {} node(int _idx, int _cost) { idx = _idx; cost = _cost; } bool operator < (const node &t) const { return cost > t.cost; } }; int main() { int K; cin >> K; vector
dist(K + 1, 2e9); priority_queue
pq; pq.push(node(K, 0)); while(!pq.empty()) { node c = pq.top(); pq.pop(); for(int i = 0; i <= 9; ++i) { if(i == 0 and c.idx == K) continue; int next_number = (c.idx * 10 + i) % K; if(i + c.cost < dist[next_number]) { dist[next_number] = i + c.cost; pq.push(node(next_number, c.cost + i)); } } } cout << dist[0] << endl; return 0; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)