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
using namespace std; int main() { int N, m; cin >> N >> m; vector
zabraneti(10); for(int i = 0; i < m; i++) { int x; cin >> x; zabraneti[x] = true; } queue
q; vector
visited(2000005, false); for(int i = 100; i <= 100000; i++) { int mozhe = 1; int broj_na_cifri = 0; for(int j = i; j > 0; j /= 10) { int cifra = j % 10; broj_na_cifri++; if(zabraneti[cifra]) { mozhe = 0; } } if(mozhe == 1) { q.push(i); q.push(broj_na_cifri); visited[i] = true; } } while(!q.empty()) { int broj = q.front(); q.pop(); int stiskanja = q.front(); q.pop(); if(broj == N) { cout << min(stiskanja, abs(N - 100)) << endl; return 0; } if(broj + 1 < 200000 and !visited[broj + 1]) { q.push(broj + 1); q.push(stiskanja + 1); visited[broj + 1] = true; } if(broj > 0 and !visited[broj - 1]) { q.push(broj - 1); q.push(stiskanja + 1); visited[broj - 1] = true; } } cout << abs(N - 100) << 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)