Submission #648715

#TimeUsernameProblemLanguageResultExecution timeMemory
648715Johanncmp (balkan11_cmp)C++14
37 / 100
1993 ms82456 KiB
#include "cmp.h" #include "bits/stdc++.h" using namespace std; typedef vector<int> vi; #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() const int LOG3 = 8; vi getTern(int x) { vi ans(LOG3, 0); for (int i = 0; i < LOG3; ++i) { ans[i] = x % 3; x /= 3; } return ans; } int addr(int pos, int digit) { return digit * LOG3 + pos + 1; } void print(vi &ternary) { for (int t : ternary) printf("%d ", t); printf("\n"); } void remember(int n) { vi ternary = getTern(n); // print(ternary); for (int i = 0; i < LOG3; ++i) bit_set(addr(i, ternary[i])); } int compare(int b) { vi ternary = getTern(b); // print(ternary); for (int i = LOG3 - 1; i >= 0; --i) { if (ternary[i] == 0) { if (bit_get(addr(i, 0))) continue; return -1; } else if (ternary[i] == 1) { if (bit_get(addr(i, 1))) continue; if (bit_get(addr(i, 0))) return 1; else return -1; } else { // digit = 2 if (bit_get(addr(i, 2))) continue; return 1; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...