#include "mosaic.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using vi =vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pi = pair<int, int>;
using vpi = vector<pi>;
#ifdef LOCAL
#define dout std::cout
#else
#define dout if (0) std::cout
#endif
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin(), (x).end()
#define en(x) (x).end()
#define bg(x) (x).begin()
#define rev(x) reverse(all(x))
#define sz(x) int((x).size())
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define each(a, x) for (auto &a : x)
#define trace(x) for (auto &el : x) dout << el << " "
vl mosaic(vi X, vi Y, vi T, vi B, vi L, vi R) {
int Q = sz(T), n = sz(X);
vl C(Q, 0);
vvi grid(n, vi(3, 0)); grid[0].resize(n); grid[1].resize(n); grid[2].resize(n);
FOR(i, 0, n) {
grid[0][i] = X[i];
grid[i][0] = Y[i];
}
FOR(i, 1, n) {
int top = i <= 2 ? n : 3;
FOR(j, 1, top) {
if (grid[i-1][j] == 0 && grid[i][j-1] == 0) grid[i][j] = 1;
else grid[i][j] = 0;
}
}
// FOR(i, 0, n) {
// trace(grid[i]); dout << "\n";
// }
// vvl pref(n+1, vl(n+1, 0));
// FOR(i, 0, n) {
// FOR(j, 0, n) {
// pref[i+1][j+1] = grid[i][j] + pref[i+1][j];
// }
// FOR(j, 0, n) {
// pref[i+1][j+1] += pref[i][j+1];
// }
// }
FOR(qn, 0, Q) {
int x1 = T[qn], x2 = B[qn], y1 = L[qn], y2 = R[qn];
if (x1 <= 2 || y1 <= 2) {
C[qn] = grid[x1][y1];
} else {
int to_wrap = min(x1 - 2, y1 - 2);
x1 = x2 = x1 - to_wrap;
y1 = y2 = y1 - to_wrap;
C[qn] = grid[x1][y1];
}
// C[qn] += pref[x2+1][y2+1];
// C[qn] += pref[x1][y1];
// C[qn] -= pref[x1][y2+1];
// C[qn] -= pref[x2+1][y1];
// if (x2 == 0 || y2 == 0) continue;
// if (x1 == 0) x1 = 1;
// if (y1 == 0) y1 = 1;
// ll width = y2 - y1 + 1;
// ll height = x2 - x1 + 1;
// if (width % 2 == 0) {
// C[qn] = width / 2 * height;
// } else if (height % 2 == 0) {
// C[qn] = height / 2 * width;
// } else {
// int maj = height / 2, min = height / 2;
// if (x1 % 2 == y1 % 2) maj++;
// else min++;
// C[qn] = ((width + 1) / 2) * maj + ((width) / 2) * min;
// }
}
return C;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |