243 words
1 minutes
[BOJ] 리모컨
리모컨
TimeLimit | MemoryLimit | Condition | TAG |
---|---|---|---|
2s | 256MB | (1 ≤ X ≤ 20) | BruteForce |
문제는 별로 어렵진 않았지만 약간 시간이 걸렸습니다. 왜냐! 제 IDE가 바뀌었긴 때문에!! Xcode에서 vim으로 아예 갈아탔어용!! 확실히 연습이 더 잘되더라구요.
또 자동완성이 없으니까 타자도 다시 원래 상태로 돌아가는 그 느낌! 아주 좋습니다.
어차피 그냥 브포 문제라서 요정도 코드는 그냥 까겠습니다.
즐거운 ps 되십숑!
정답 코드
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m;
bool buttons[10];
ll solve(int depth, ll current) {
if(depth > 6) return abs(current - n) + depth;
ll result = 10000000000;
if(depth) result = abs(n - current) + depth;
for(int i = 0; i < 10; i++){
if(buttons[i]) continue;
result = min(result, solve(depth+1, current*10+i));
}
return result;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
cin >> m;
int tmp;
for(int i = 0; i < m; i++){
cin >> tmp;
buttons[tmp] = true;
}
ll result = min(llabs(n - 100), solve(0, 0));
cout << result;
return 0;
}