This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "vision.h"
/// #pragma GCC optimize ("Ofast")
/// #pragma GCC target ("avx2")
/// #pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
using ii = pair<ll, ll>;
using vi = vector<int>;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb lower_bound
const int MOD = 1e9 + 7;
int H, W;
map<int, int> A[2], B[2];
int dist(int x, int y, int X, int Y) {
return abs(x - X) + abs(y - Y);
}
int calc(int x, int y) {
return x * W + y;
}
int diagR(int K) {
vector<int> V;
for(int l = 0; l < H + W; l++) {
if(l + K - 1 < H + W - 1) {
vector<int> X, Y;
for(int i = l; i < l + K; i++)
X.push_back(A[0][i]), Y.push_back(B[0][i]);
int C = add_xor({add_or(X), add_xor(X)});
Y.push_back(C); V.push_back(add_or(Y));
}
}
return add_or(V);
}
int diagL(int K) {
vector<int> V;
for(int l = -W + 1; l < H; l++) {
if(l + K - 1 < H) {
vector<int> X, Y;
for(int i = l; i < l + K; i++)
X.push_back(A[1][i]), Y.push_back(B[1][i]);
int C = add_xor({add_or(X), add_xor(X)});
Y.push_back(C); V.push_back(add_or(Y));
}
}
return add_or(V);
}
int solve(int K) {
return add_and({diagR(K), diagL(K)});
}
void construct_network(int h, int w, int K) {
H = h, W = w;
for(int l = 0; l < H + W; l++) {
vector<int> V;
for(int i = 0; i < H; i++)
for(int j = 0; j < W; j++)
if(i + j == l) V.push_back(calc(i, j));
if(V.empty()) continue;
A[0][l] = add_or(V);
B[0][l] = add_xor({add_or(V), add_xor(V)});
}
for(int l = -H - W; l < H + W; l++) {
vector<int> V;
for(int i = 0; i < H; i++)
for(int j = 0; j < W; j++)
if(i - j == l) V.push_back(calc(i, j));
if(V.empty()) continue;
A[1][l] = add_or(V);
B[1][l] = add_xor({add_or(V), add_xor(V)});
}
add_and({solve(K + 1), add_not(solve(K))});
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |