Submission #1107675

# Submission time Handle Problem Language Result Execution time Memory
1107675 2024-11-01T22:20:55 Z SabaKharebava Mosaic (IOI24_mosaic) C++17
100 / 100
111 ms 40784 KB
#include <bits/stdc++.h>
#include <vector>

using namespace std;
using lint = long long;
using pi = array<lint, 2>;

#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define cr(v, n) (v).clear(), (v).resize(n);

const int MAXN = 200005;

int d0[3][MAXN], d1[3][MAXN];
lint ps0[3][MAXN], ps1[3][MAXN];
lint psi0[3][MAXN], psi1[3][MAXN];

vector<long long> mosaic(vector<int> X, vector<int> Y, vector<int> T, vector<int> B, vector<int> L, vector<int> R) {
	while (sz(X) < 3)
		X.push_back(0);
	while (sz(Y) < 3)
		Y.push_back(0);
	for (int i = 0; i < sz(X); i++)
		d0[0][i] = X[i];
	for (int i = 0; i < sz(Y); i++)
		d1[0][i] = Y[i];
	for (int i = 1; i < 3; i++) {
		d0[i][0] = Y[i];
		d1[i][0] = X[i];
		for (int j = 1; j < sz(X); j++)
			d0[i][j] = (1 - d0[i - 1][j]) && (1 - d0[i][j - 1]);
		for (int j = 1; j < sz(Y); j++)
			d1[i][j] = (1 - d1[i - 1][j]) && (1 - d1[i][j - 1]);
	}
	for (int i = 0; i < 3; i++)
		for (int j = 0; j < MAXN; j++) {
			ps0[i][j] = (j ? ps0[i][j - 1] : 0) + d0[i][j];
			ps1[i][j] = (j ? ps1[i][j - 1] : 0) + d1[i][j];
			psi0[i][j] = (j ? psi0[i][j - 1] : 0) + d0[i][j] * j;
			psi1[i][j] = (j ? psi1[i][j - 1] : 0) + d1[i][j] * j;
		}
	vector<lint> ans(sz(T));
	auto f = [&](int x, int y) {
		int d = min(x, y) - 2;
		if (d >= 0) {
			x -= d;
			y -= d;
		}
		if (x <= 2)
			return d0[x][y];
		return d1[y][x];
	};
	auto h = [&](int *d0, int *d1, lint *s0, lint *s1, lint *si0, lint *si1, int x, int y) {
		lint ans = 0;
		ans -= (si1[x - 1] - si1[x - y + 2]);
		ans -= (si0[y - 1] - si0[1]);
		ans += 1ll * (y - 2) * (s1[x - y + 2] - s1[2]);
		ans += 1ll * y * (s0[y - 1] - s0[1]);
		ans += 1ll * x * (s1[x - 1] - s1[x - y + 2]);
		return ans;
	};
	auto g = [&](int x, int y) {
		if (x < 0 || y < 0)
			return 0ll;
		lint ans = 0;
		if (x <= 2) {
			for (int i = 0; i <= x; i++)
				ans += ps0[i][y];
			return ans;
		}
		if (y <= 2) {
			for (int i = 0; i <= y; i++)
				ans += ps1[i][x];
			return ans;
		}
		for (int i = 0; i <= 2; i++)
			ans += ps0[i][y];
		for (int i = 0; i <= 2; i++)
			ans += ps1[i][x] - ps1[i][2];
		if (x >= y)
			ans += h(d0[2], d1[2], ps0[2], ps1[2], psi0[2], psi1[2], x, y);
		else
			ans += h(d1[2], d0[2], ps1[2], ps0[2], psi1[2], psi0[2], y, x);
		return ans;
	};
	for (int i = 0; i < sz(T); i++)
		ans[i] += g(B[i], R[i]) - g(B[i], L[i] - 1) - g(T[i] - 1, R[i]) + g(T[i] - 1, L[i] - 1);
	return ans;
}

Compilation message

mosaic.cpp: In function 'std::vector<long long int> mosaic(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
mosaic.cpp:43:7: warning: variable 'f' set but not used [-Wunused-but-set-variable]
   43 |  auto f = [&](int x, int y) {
      |       ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23120 KB Output is correct
2 Correct 5 ms 23336 KB Output is correct
3 Correct 5 ms 23120 KB Output is correct
4 Correct 5 ms 23288 KB Output is correct
5 Correct 5 ms 23288 KB Output is correct
6 Correct 5 ms 23292 KB Output is correct
7 Correct 5 ms 23120 KB Output is correct
8 Correct 5 ms 23120 KB Output is correct
9 Correct 5 ms 23176 KB Output is correct
10 Correct 5 ms 23120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23120 KB Output is correct
2 Correct 5 ms 23336 KB Output is correct
3 Correct 5 ms 23120 KB Output is correct
4 Correct 5 ms 23288 KB Output is correct
5 Correct 5 ms 23288 KB Output is correct
6 Correct 5 ms 23292 KB Output is correct
7 Correct 5 ms 23120 KB Output is correct
8 Correct 5 ms 23120 KB Output is correct
9 Correct 5 ms 23176 KB Output is correct
10 Correct 5 ms 23120 KB Output is correct
11 Correct 5 ms 23288 KB Output is correct
12 Correct 4 ms 22988 KB Output is correct
13 Correct 5 ms 23284 KB Output is correct
14 Correct 5 ms 23120 KB Output is correct
15 Correct 4 ms 23120 KB Output is correct
16 Correct 4 ms 23120 KB Output is correct
17 Correct 4 ms 23192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 38728 KB Output is correct
2 Correct 81 ms 38728 KB Output is correct
3 Correct 80 ms 38216 KB Output is correct
4 Correct 82 ms 38728 KB Output is correct
5 Correct 68 ms 32840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23120 KB Output is correct
2 Correct 5 ms 23336 KB Output is correct
3 Correct 5 ms 23120 KB Output is correct
4 Correct 5 ms 23288 KB Output is correct
5 Correct 5 ms 23288 KB Output is correct
6 Correct 5 ms 23292 KB Output is correct
7 Correct 5 ms 23120 KB Output is correct
8 Correct 5 ms 23120 KB Output is correct
9 Correct 5 ms 23176 KB Output is correct
10 Correct 5 ms 23120 KB Output is correct
11 Correct 5 ms 23288 KB Output is correct
12 Correct 4 ms 22988 KB Output is correct
13 Correct 5 ms 23284 KB Output is correct
14 Correct 5 ms 23120 KB Output is correct
15 Correct 4 ms 23120 KB Output is correct
16 Correct 4 ms 23120 KB Output is correct
17 Correct 4 ms 23192 KB Output is correct
18 Correct 72 ms 34632 KB Output is correct
19 Correct 65 ms 34632 KB Output is correct
20 Correct 63 ms 31048 KB Output is correct
21 Correct 68 ms 34372 KB Output is correct
22 Correct 62 ms 31048 KB Output is correct
23 Correct 67 ms 34428 KB Output is correct
24 Correct 62 ms 31048 KB Output is correct
25 Correct 64 ms 34640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 32584 KB Output is correct
2 Correct 108 ms 40520 KB Output is correct
3 Correct 100 ms 40004 KB Output is correct
4 Correct 105 ms 40008 KB Output is correct
5 Correct 99 ms 40260 KB Output is correct
6 Correct 102 ms 40520 KB Output is correct
7 Correct 101 ms 40588 KB Output is correct
8 Correct 96 ms 40520 KB Output is correct
9 Correct 82 ms 32772 KB Output is correct
10 Correct 82 ms 37704 KB Output is correct
11 Correct 88 ms 37704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 40192 KB Output is correct
2 Correct 104 ms 40720 KB Output is correct
3 Correct 93 ms 38992 KB Output is correct
4 Correct 100 ms 38984 KB Output is correct
5 Correct 99 ms 37960 KB Output is correct
6 Correct 85 ms 37960 KB Output is correct
7 Correct 75 ms 36680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 38728 KB Output is correct
2 Correct 81 ms 38728 KB Output is correct
3 Correct 80 ms 38216 KB Output is correct
4 Correct 82 ms 38728 KB Output is correct
5 Correct 68 ms 32840 KB Output is correct
6 Correct 105 ms 40192 KB Output is correct
7 Correct 104 ms 40720 KB Output is correct
8 Correct 93 ms 38992 KB Output is correct
9 Correct 100 ms 38984 KB Output is correct
10 Correct 99 ms 37960 KB Output is correct
11 Correct 85 ms 37960 KB Output is correct
12 Correct 75 ms 36680 KB Output is correct
13 Correct 97 ms 34888 KB Output is correct
14 Correct 105 ms 40520 KB Output is correct
15 Correct 103 ms 40784 KB Output is correct
16 Correct 92 ms 38984 KB Output is correct
17 Correct 99 ms 37584 KB Output is correct
18 Correct 100 ms 40520 KB Output is correct
19 Correct 84 ms 37192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23120 KB Output is correct
2 Correct 5 ms 23120 KB Output is correct
3 Correct 5 ms 23336 KB Output is correct
4 Correct 5 ms 23120 KB Output is correct
5 Correct 5 ms 23288 KB Output is correct
6 Correct 5 ms 23288 KB Output is correct
7 Correct 5 ms 23292 KB Output is correct
8 Correct 5 ms 23120 KB Output is correct
9 Correct 5 ms 23120 KB Output is correct
10 Correct 5 ms 23176 KB Output is correct
11 Correct 5 ms 23120 KB Output is correct
12 Correct 5 ms 23288 KB Output is correct
13 Correct 4 ms 22988 KB Output is correct
14 Correct 5 ms 23284 KB Output is correct
15 Correct 5 ms 23120 KB Output is correct
16 Correct 4 ms 23120 KB Output is correct
17 Correct 4 ms 23120 KB Output is correct
18 Correct 4 ms 23192 KB Output is correct
19 Correct 83 ms 38728 KB Output is correct
20 Correct 81 ms 38728 KB Output is correct
21 Correct 80 ms 38216 KB Output is correct
22 Correct 82 ms 38728 KB Output is correct
23 Correct 68 ms 32840 KB Output is correct
24 Correct 72 ms 34632 KB Output is correct
25 Correct 65 ms 34632 KB Output is correct
26 Correct 63 ms 31048 KB Output is correct
27 Correct 68 ms 34372 KB Output is correct
28 Correct 62 ms 31048 KB Output is correct
29 Correct 67 ms 34428 KB Output is correct
30 Correct 62 ms 31048 KB Output is correct
31 Correct 64 ms 34640 KB Output is correct
32 Correct 56 ms 32584 KB Output is correct
33 Correct 108 ms 40520 KB Output is correct
34 Correct 100 ms 40004 KB Output is correct
35 Correct 105 ms 40008 KB Output is correct
36 Correct 99 ms 40260 KB Output is correct
37 Correct 102 ms 40520 KB Output is correct
38 Correct 101 ms 40588 KB Output is correct
39 Correct 96 ms 40520 KB Output is correct
40 Correct 82 ms 32772 KB Output is correct
41 Correct 82 ms 37704 KB Output is correct
42 Correct 88 ms 37704 KB Output is correct
43 Correct 105 ms 40192 KB Output is correct
44 Correct 104 ms 40720 KB Output is correct
45 Correct 93 ms 38992 KB Output is correct
46 Correct 100 ms 38984 KB Output is correct
47 Correct 99 ms 37960 KB Output is correct
48 Correct 85 ms 37960 KB Output is correct
49 Correct 75 ms 36680 KB Output is correct
50 Correct 97 ms 34888 KB Output is correct
51 Correct 105 ms 40520 KB Output is correct
52 Correct 103 ms 40784 KB Output is correct
53 Correct 92 ms 38984 KB Output is correct
54 Correct 99 ms 37584 KB Output is correct
55 Correct 100 ms 40520 KB Output is correct
56 Correct 84 ms 37192 KB Output is correct
57 Correct 111 ms 40520 KB Output is correct
58 Correct 105 ms 40148 KB Output is correct
59 Correct 107 ms 40520 KB Output is correct
60 Correct 103 ms 40008 KB Output is correct
61 Correct 104 ms 40008 KB Output is correct
62 Correct 102 ms 40212 KB Output is correct
63 Correct 85 ms 37704 KB Output is correct
64 Correct 84 ms 36548 KB Output is correct