# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
927997 | 2024-02-15T16:34:52 Z | Naser | 비교 (balkan11_cmp) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> #include "cmp.h" #define vint vector<int> using namespace std; void remember(int a) { int ans = 0, p = 1; while (a) { ans += p * (a % 8); a /= 8; p *= 10; } a = ans; vint prf(4); prf[0] = a; for (int i = 1; i < 4; i++) { prf[i] = a / power(10, i); for (int j = 0; j < i; j++) { prf[i] *= 10; prf[i] += 8; } } for (int i = 0; i < 4; i++) bit_set(1 + prf[i]); } int compare(int b) { int ans = 0, p = 1; while (b) { ans += p * (b % 8); b /= 8; p *= 10; } b = ans; if (bit_get(1 + b)) return 0; vint prf(4); prf[0] = b; for (int i = 1; i < 4; i++) { prf[i] = b / power(10, i); for (int j = 0; j < i; j++) { prf[i] *= 10; prf[i] += 8; } } int l = 0, r = 3; while (l < r) { int mid = (l + r + 1) / 2; if (bit_get(1 + prf[mid])) r = mid - 1; else l = mid; } int dig = l, base = power(10, dig); if (prf[dig] % (base * 10) == 8) return -1; if ((b/base)%10 > 3) { for (int i = (b / base) % 10 + 1; i < 8; i++) { if (bit_get(1 + prf[dig] + (i - ((b / base) % 10)) * base)) return -1; } return 1; } else { for (int i = (b / base) % 10 - 1; i >= 0; i--) { if (bit_get(1 + prf[dig] + (i - ((b / base) % 10)) * base)) return 1; } return -1; } }