# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1034232 |
2024-07-25T11:00:28 Z |
vjudge1 |
cmp (balkan11_cmp) |
C++17 |
|
436 ms |
82340 KB |
#include "cmp.h"
#include <bits/stdc++.h>
using namespace std;
const int inf = INT_MAX;
int a[4096], b[2][64];
void remember(int n) {
for (int i = 0; i < 4096; i++) {
a[i] = -2;
b[0][i] = inf;
b[1][i] = -inf;
}
int x = __builtin_popcount(n);
if (x <= 1 + 12-x) {
for (int i = 0; i <= 11; i++) {
if ((n >> i) & 1) bit_set(i+1);
}
}
else {
bit_set(13);
for (int i = 0; i <= 11; i++) {
if (!((n >> i) & 1)) bit_set(i+1);
}
}
}
void update(int x, int y) {
a[x] = y;
b[0][x/64] = min(b[0][x/64], y);
b[1][x/64] = max(b[1][x/64], y);
}
int compare(int n) {
if (n && a[n-1] == 1 && n+1 < 4096 && a[n+1] == -1) {
update(n, 0);
return 0;
}
for (int i = 0; i < n; i++) {
if (i%64 == 0 && i+63 < n) {
if (b[0][i/64] < 1) {
update(n, -1);
return -1;
}
i += 63;
continue;
}
if (a[i] == -2) continue;
else if (a[i] < 1) {
update(n, -1);
return -1;
}
}
for (int i = 0; i < n; i++) {
if (i%64 == 0 && i+63 < n) {
if (b[1][i/64] > -1) {
update(n, 1);
return 1;
}
i += 63;
continue;
}
if (a[i] == -2) continue;
else if (a[i] > -1) {
update(n, 1);
return 1;
}
}
int inv = bit_get(13);
for (int i = 11; i >= 0; i--) {
int x = bit_get(i+1);
if (inv) x = !x;
int y = (n >> i) & 1;
if (x > y) return -1;
else if (x < y) return 1;
}
return 0;
}
Compilation message
cmp.cpp: In function 'void remember(int)':
cmp.cpp:12:13: warning: iteration 64 invokes undefined behavior [-Waggressive-loop-optimizations]
12 | b[0][i] = inf;
| ~~~~~~~~^~~~~
cmp.cpp:10:21: note: within this loop
10 | for (int i = 0; i < 4096; i++) {
| ~~^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
436 ms |
82340 KB |
ZERO POINTS: For a=3069 and b=1532, correct answer is -1, got 1 |