# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
297033 | BThero | Broken Device (JOI17_broken_device) | C++17 | 52 ms | 3840 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.
// chrono::system_clock::now().time_since_epoch().count()
#include "Annalib.h"
#include<bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " = " << x << endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
namespace {
string V[] = {"", "0", "1", "00", "10", "11", "0", "01"};
int n, k, bad_pos[45];
int is_bad[205], mem[205];
ll msg;
int bit(ll x, int p) {
if (p > 60) return 0;
return (x >> p) & 1;
}
void set(int p, int x) {
if (p < n) {
mem[p] = x;
}
}
void send() {
for (int i = 0; i < n; ++i) {
Set(i, mem[i]);
}
}
void solve() {
fill(is_bad, is_bad + n, 0);
for (int i = 0; i < k; ++i) {
is_bad[bad_pos[i]] = 1;
}
fill(mem, mem + n, 0);
int p = 0;
for (int i = 0; i < n; i += 3) {
string me;
me.pb('0' + bit(msg, p));
me.pb('0' + bit(msg, p + 1));
int mask = 0;
for (int j = 0; j < 3; ++j) {
if (!is_bad[i + j]) {
mask += (1 << j);
}
}
if (__builtin_popcount(mask) < 2) {
set(i, 0);
set(i + 1, 0);
set(i + 2, 0);
continue;
}
int found1 = -1, found2 = -1;
for (int s = 1; s < 8; ++s) {
if ((mask & s) == s) {
if (V[s].size() == 2 && V[s] == me) {
found2 = s;
}
if (V[s].size() == 1 && V[s][0] == me[0]) {
found1 = s;
}
}
}
assert(found1 != -1 || found2 != -1);
if (found2 != -1) {
set(i, bit(found2, 0));
set(i + 1, bit(found2, 1));
set(i + 2, bit(found2, 2));
p += 2;
}
else {
set(i, bit(found1, 0));
set(i + 1, bit(found1, 1));
set(i + 2, bit(found1, 2));
p++;
}
}
send();
}
};
void Anna( int N, long long X, int K, int P[] ){
n = N;
msg = X;
k = K;
for (int i = 0; i < k; ++i) {
bad_pos[i] = P[i];
}
solve();
}
// chrono::system_clock::now().time_since_epoch().count()
#include "Brunolib.h"
#include<bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " = " << x << endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
namespace {
string V[] = {"", "0", "1", "00", "10", "11", "0", "01"};
int n, arr[205];
ll solve() {
ll ret = 0;
int p = 0;
for (int i = 0; i < n; i += 3) {
int mask = arr[i] + arr[i + 1] * 2 + arr[i + 2] * 4;
for (char c : V[mask]) {
if (c == '1') {
ret += (1ll << p);
}
++p;
}
}
return ret;
}
};
long long Bruno( int N, int A[] ){
n = N;
for (int i = 0; i < n; ++i) {
arr[i] = A[i];
}
return solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |