-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1107.cpp
More file actions
39 lines (35 loc) · 696 Bytes
/
1107.cpp
File metadata and controls
39 lines (35 loc) · 696 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
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <climits>
#define io ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
vector<bool> nums(10,true);
int res=INT_MAX;
int N,M;
void selectNum(string num){
for(int i=0;i<10;i++){
if(nums[i]){
num+=to_string(i);
res=min(res,abs(N-stoi(num))+(int)num.length());
if(num.length()<6) selectNum(num);
num.pop_back();
}
}
}
int main()
{
io;
cin>>N>>M;
for(int i=0;i<M;i++){
int n;
cin>>n;
nums[n]=false;
}
res=abs(N-100);
selectNum("");
cout<<res;
return 0;
}