// model_solution/hazem_full.cpp
#include "bits/stdc++.h"
#include "mosaic.h"
using namespace std;
vector<long long> mosaic(vector<int> X, vector<int> Y, vector<int> T, vector<int> B, vector<int> L, vector<int> R) {
auto cell_index = [](int i, int j){
return ((i < j) - (i > j)) * (max(i, j) - min(i, j));
};
auto next_layer = [](vector<long long> l){
if(l.size() < 3) return vector<long long>();
int m = (int)l.size() / 2;
l[m] = !(l[m-1] | l[m+1]);
l.erase(l.begin() + m + 1);
l.erase(l.begin() + m - 1);
m--;
for(int i = 1; i <= m; i++){
l[m-i] = !(l[m-i] | l[m-i+1]);
l[m+i] = !(l[m+i] | l[m+i-1]);
}
return l;
};
auto accumulate_layer = [](vector<long long> l){
l.insert(l.begin(), 0);
for(int i = 1; i < (int)l.size(); i++)
l[i] += l[i-1];
return l;
};
vector<long long> layer[4];
layer[0] = {Y.rbegin(), Y.rend()};
layer[0].insert(layer[0].end(), X.begin()+1, X.end());
layer[1] = next_layer(layer[0]);
layer[2] = next_layer(layer[1]);
layer[0] = accumulate_layer(layer[0]);
layer[1] = accumulate_layer(layer[1]);
layer[2] = accumulate_layer(layer[2]);
layer[3] = accumulate_layer(layer[2]);
auto layer_sum = [&](int i, int l, int r){
if(r < l) return 0LL;
int m = (int)layer[i].size() / 2;
return layer[i][m + r] - layer[i][m + l - 1];
};
auto special_layers = [&](int t, int b, int l, int r){
long long tot = 0;
for(int k = 0; k < 3; k++){
if(t <= k && k <= b) tot += layer_sum(k, cell_index(k, max(l, k)), cell_index(k, r));
if(l <= k && k <= r) tot += layer_sum(k, cell_index(b, k), cell_index(max(t, k), k));
if(t <= k && k <= b && l <= k && k <= r) tot -= layer_sum(k, 0, 0);
}
return tot;
};
auto nested_sum = [&](int t, int b, int l, int r){
if(b < t || r < l) return 0LL;
return layer_sum(3, cell_index(t, r) - (b - t) + 1, cell_index(t, r) + 1)
- layer_sum(3, cell_index(t, l) - (b - t), cell_index(t, l));
};
vector<long long> C(T.size());
for(int q = 0; q < (int)C.size(); q++){
auto [t, b, l, r] = tie(T[q], B[q], L[q], R[q]);
C[q] = special_layers(t, b, l, r) + nested_sum(max(3, t), b, max(3, l), r);
}
return C;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
31960 KB |
Output is correct |
2 |
Correct |
93 ms |
30296 KB |
Output is correct |
3 |
Correct |
93 ms |
31504 KB |
Output is correct |
4 |
Correct |
96 ms |
28380 KB |
Output is correct |
5 |
Correct |
85 ms |
19500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
81 ms |
8756 KB |
Output is correct |
19 |
Correct |
66 ms |
8564 KB |
Output is correct |
20 |
Correct |
120 ms |
8780 KB |
Output is correct |
21 |
Correct |
84 ms |
8564 KB |
Output is correct |
22 |
Correct |
59 ms |
8776 KB |
Output is correct |
23 |
Correct |
66 ms |
8532 KB |
Output is correct |
24 |
Correct |
68 ms |
8700 KB |
Output is correct |
25 |
Correct |
61 ms |
8460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
99 ms |
8188 KB |
Output is correct |
2 |
Correct |
111 ms |
29220 KB |
Output is correct |
3 |
Correct |
103 ms |
28708 KB |
Output is correct |
4 |
Correct |
103 ms |
27920 KB |
Output is correct |
5 |
Correct |
105 ms |
29524 KB |
Output is correct |
6 |
Correct |
89 ms |
29984 KB |
Output is correct |
7 |
Correct |
111 ms |
31120 KB |
Output is correct |
8 |
Correct |
97 ms |
29472 KB |
Output is correct |
9 |
Correct |
76 ms |
17460 KB |
Output is correct |
10 |
Correct |
73 ms |
18128 KB |
Output is correct |
11 |
Correct |
76 ms |
17428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
29268 KB |
Output is correct |
2 |
Correct |
91 ms |
29916 KB |
Output is correct |
3 |
Correct |
84 ms |
27736 KB |
Output is correct |
4 |
Correct |
82 ms |
30752 KB |
Output is correct |
5 |
Correct |
86 ms |
32088 KB |
Output is correct |
6 |
Correct |
74 ms |
18640 KB |
Output is correct |
7 |
Correct |
78 ms |
13620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
31960 KB |
Output is correct |
2 |
Correct |
93 ms |
30296 KB |
Output is correct |
3 |
Correct |
93 ms |
31504 KB |
Output is correct |
4 |
Correct |
96 ms |
28380 KB |
Output is correct |
5 |
Correct |
85 ms |
19500 KB |
Output is correct |
6 |
Correct |
93 ms |
29268 KB |
Output is correct |
7 |
Correct |
91 ms |
29916 KB |
Output is correct |
8 |
Correct |
84 ms |
27736 KB |
Output is correct |
9 |
Correct |
82 ms |
30752 KB |
Output is correct |
10 |
Correct |
86 ms |
32088 KB |
Output is correct |
11 |
Correct |
74 ms |
18640 KB |
Output is correct |
12 |
Correct |
78 ms |
13620 KB |
Output is correct |
13 |
Correct |
101 ms |
26912 KB |
Output is correct |
14 |
Correct |
142 ms |
27220 KB |
Output is correct |
15 |
Correct |
146 ms |
32532 KB |
Output is correct |
16 |
Correct |
135 ms |
30740 KB |
Output is correct |
17 |
Correct |
188 ms |
25508 KB |
Output is correct |
18 |
Correct |
183 ms |
31004 KB |
Output is correct |
19 |
Correct |
128 ms |
20060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
93 ms |
31960 KB |
Output is correct |
20 |
Correct |
93 ms |
30296 KB |
Output is correct |
21 |
Correct |
93 ms |
31504 KB |
Output is correct |
22 |
Correct |
96 ms |
28380 KB |
Output is correct |
23 |
Correct |
85 ms |
19500 KB |
Output is correct |
24 |
Correct |
81 ms |
8756 KB |
Output is correct |
25 |
Correct |
66 ms |
8564 KB |
Output is correct |
26 |
Correct |
120 ms |
8780 KB |
Output is correct |
27 |
Correct |
84 ms |
8564 KB |
Output is correct |
28 |
Correct |
59 ms |
8776 KB |
Output is correct |
29 |
Correct |
66 ms |
8532 KB |
Output is correct |
30 |
Correct |
68 ms |
8700 KB |
Output is correct |
31 |
Correct |
61 ms |
8460 KB |
Output is correct |
32 |
Correct |
99 ms |
8188 KB |
Output is correct |
33 |
Correct |
111 ms |
29220 KB |
Output is correct |
34 |
Correct |
103 ms |
28708 KB |
Output is correct |
35 |
Correct |
103 ms |
27920 KB |
Output is correct |
36 |
Correct |
105 ms |
29524 KB |
Output is correct |
37 |
Correct |
89 ms |
29984 KB |
Output is correct |
38 |
Correct |
111 ms |
31120 KB |
Output is correct |
39 |
Correct |
97 ms |
29472 KB |
Output is correct |
40 |
Correct |
76 ms |
17460 KB |
Output is correct |
41 |
Correct |
73 ms |
18128 KB |
Output is correct |
42 |
Correct |
76 ms |
17428 KB |
Output is correct |
43 |
Correct |
93 ms |
29268 KB |
Output is correct |
44 |
Correct |
91 ms |
29916 KB |
Output is correct |
45 |
Correct |
84 ms |
27736 KB |
Output is correct |
46 |
Correct |
82 ms |
30752 KB |
Output is correct |
47 |
Correct |
86 ms |
32088 KB |
Output is correct |
48 |
Correct |
74 ms |
18640 KB |
Output is correct |
49 |
Correct |
78 ms |
13620 KB |
Output is correct |
50 |
Correct |
101 ms |
26912 KB |
Output is correct |
51 |
Correct |
142 ms |
27220 KB |
Output is correct |
52 |
Correct |
146 ms |
32532 KB |
Output is correct |
53 |
Correct |
135 ms |
30740 KB |
Output is correct |
54 |
Correct |
188 ms |
25508 KB |
Output is correct |
55 |
Correct |
183 ms |
31004 KB |
Output is correct |
56 |
Correct |
128 ms |
20060 KB |
Output is correct |
57 |
Correct |
186 ms |
28844 KB |
Output is correct |
58 |
Correct |
164 ms |
30320 KB |
Output is correct |
59 |
Correct |
182 ms |
29296 KB |
Output is correct |
60 |
Correct |
190 ms |
25824 KB |
Output is correct |
61 |
Correct |
167 ms |
29680 KB |
Output is correct |
62 |
Correct |
178 ms |
28728 KB |
Output is correct |
63 |
Correct |
155 ms |
18548 KB |
Output is correct |
64 |
Correct |
125 ms |
17748 KB |
Output is correct |