-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1107.cpp
More file actions
40 lines (31 loc) · 677 Bytes
/
1107.cpp
File metadata and controls
40 lines (31 loc) · 677 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<bool> broken(10, false);
bool check(int now){
string s = to_string(now);
for(int i = 0; i < s.length();i++){
if(broken[s[i]-'0']){
return false;
}
}
return true;
}
int main(void) {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> N >> M;
for(int i = 0; i < M; i++) {
int num;
cin >> num;
broken[num] = true;
}
int ans = abs(N-100);
for(int i = 0; i <= 1000000; i++){
if(check(i)) {
int tmp = abs(N-i) + to_string(i).length();
ans = min(ans, tmp);
}
}
cout << ans << '\n';
return 0;
}