# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
415230 | fvogel499 | cmp (balkan11_cmp) | C++14 | 2124 ms | 94432 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
File created on 05/31/2021 at 18:32:22.
Link to problem: https://oj.uz/problem/view/balkan11_cmp
Description: https://usaco.guide/adv/interactive?lang=cpp#tip-1---dont-send-everything
Time complexity: irrelevant
Space complexity: irrelevant
Status: DEV
Copyright: Ⓒ 2021 Francois Vogel
*/
#include <iostream>
#include <vector>
#include "cmp.h"
using namespace std;
vector<int> start = {0, 4, 20, 84, 340, 965, 2261};
// const int N = 10241;
// bool bits [N];
// int callsTracker;
// void bit_set(int i) {
// bits[i] = true;
// callsTracker++;
// }
// void bit_reset(int i) {
// bits[i] = false;
// }
// bool bit_get(int i) {
// callsTracker++;
// return bits[i];
// }
// void undo(int n) {
// for (int i = 0; i < 6; i++) {
// int cons = n>>(2*(5-i));
// bit_reset(cons+start[i]+1);
// }
// }
void remember(int n) {
for (int i = 0; i < 6; i++) {
int cons = n>>(2*(5-i));
bit_set(cons+start[i]+1);
}
}
int compare(int n) {
int l = 0;
int r = 5;
int mv = -1;
while (l <= r) {
int mid = (l+r)/2;
int cons = n>>(2*(5-mid));
bool res = bit_get(start[mid]+cons+1);
if (res) {
mv = mid;
l = mid+1;
}
else r = mid-1;
}
l = mv+1;
if (l == 6) return 0;
int cons = n>>(2*(5-l));
if (cons%4 == 0) return -1;
else if (cons%4 == 3) return 1;
else if (cons%4 == 1) {
bool res = bit_get(start[l]+cons-1+1);
if (res) return 1;
else return -1;
}
else if (cons%4 == 2) {
bool res = bit_get(start[l]+cons+1+1);
if (res) return -1;
else return 1;
}
}
// int main() {
// for (int i = 0; i < N; i++) bits[i] = false;
// remember(0);
// compare(0);
// int lim = 4096;
// int maxCalls = 0;
// for (int i = 0; i < lim; i++) {
// if (i%500 == 0) cout << endl << "PROGRESS: " << (i*100)/lim << " |";
// else if (i%100 == 0) cout << ".";
// for (int j = 0; j < 4096; j++) {
// // cout << endl << "RUNNING: " << i << " " << j;
// callsTracker = 0;
// remember(i);
// int res = compare(j);
// undo(i);
// if ((res == 0 and i != j) or (res == -1 and i <= j) or (res == 1 and i >= j)) {
// cout << endl << "-> PROBLEM: " << i << " " << j;
// }
// maxCalls = max(maxCalls, callsTracker);
// }
// }
// cout << "\n100% Completed, MAX_CALLS = " << maxCalls;
// int d = 0;
// d++;
// }
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |