# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1105677 |
2024-10-27T10:01:47 Z |
Zicrus |
Mosaic (IOI24_mosaic) |
C++17 |
|
123 ms |
51984 KB |
#include <bits/stdc++.h>
#include "mosaic.h"
using namespace std;
typedef long long ll;
ll n, q;
vector<vector<ll>> lay, layPref;
vector<ll> stairs;
vector<ll> mosaic(vector<int> X, vector<int> Y, vector<int> T, vector<int> B, vector<int> L, vector<int> R) {
n = X.size();
q = T.size();
lay = vector<vector<ll>>(5, vector<ll>(2*n-1));
layPref = vector<vector<ll>>(5, vector<ll>(2*n));
stairs = vector<ll>(2*n);
vector<ll> res(q);
for (int i = 0; i < n; i++) {
lay[0][n-1+i] = X[i];
lay[0][n-1-i] = Y[i];
}
for (int L = 1; L < min(5ll, n); L++) {
ll mid = n-1-L;
lay[L][mid] = !lay[L-1][mid] && !lay[L-1][mid+2];
for (int i = mid+1; i < 2*n-1-2*L; i++) {
lay[L][i] = !lay[L][i-1] && !lay[L-1][i+2];
}
for (int i = mid-1; i >= 0; i--) {
lay[L][i] = !lay[L][i+1] && !lay[L-1][i];
}
}
for (int L = 0; L < min(5ll, n); L++) {
for (int i = 0; i < 2*n-1-2*L; i++) {
layPref[L][i+1] = layPref[L][i] + lay[L][i];
}
}
if (n >= 5) {
for (int i = 0; i < 2*n-1; i++) {
stairs[i+1] = stairs[i] + (i+1)*lay[4][i];
}
}
// Solve
for (int k = 0; k < q; k++) {
ll t = T[k], b = B[k], l = L[k], r = R[k];
ll ans = 0;
bool skip = false;
while (t < 5 || l < 5) {
if (t < l) { // Move t
ll L = t;
ll mid = n-1-L;
ll ref = mid-L;
ll idL = ref + l;
ll idR = ref + r;
ans += layPref[L][idR+1] - layPref[L][idL];
t++;
}
else { // Move l
ll L = l;
ll idL = n-1-b;
ll idR = n-1-t;
ans += layPref[L][idR+1] - layPref[L][idL];
l++;
}
// Check if done
if (b-t < 0 || r-l < 0) {
skip = true;
break;
}
}
if (skip) {
res[k] = ans;
continue;
}
// Get remaining area
ll idBL = n-1-b + l-4;
ll idBR = n-1-b + r-4;
ll idTL = n-1-t + l-4;
ll idTR = n-1-t + r-4;
ll idL = min(idTL, idBR);
ll idR = max(idTL, idBR);
ll idLL = idBL;
ll idRR = idTR;
ll w = min(b-t+1, r-l+1);
ans += (layPref[4][idR+1] - layPref[4][idL]) * w; // middle
ans += stairs[idL] - stairs[idLL] - (layPref[4][idL] - layPref[4][idLL])*idLL; // left
ll rightStair = stairs[idRR+1] - stairs[idR+1] - (layPref[4][idRR+1] - layPref[4][idR+1])*(idR+1);
ans += (layPref[4][idRR+1] - layPref[4][idR+1])*(idRR-idR+1) - rightStair; // right
res[k] = ans;
}
return res;
}
#ifdef TEST
#include "grader.cpp"
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
608 KB |
Output is correct |
2 |
Correct |
1 ms |
436 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
504 KB |
Output is correct |
10 |
Correct |
1 ms |
436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
608 KB |
Output is correct |
2 |
Correct |
1 ms |
436 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
504 KB |
Output is correct |
10 |
Correct |
1 ms |
436 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
504 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
49664 KB |
Output is correct |
2 |
Correct |
94 ms |
49680 KB |
Output is correct |
3 |
Correct |
94 ms |
49100 KB |
Output is correct |
4 |
Correct |
96 ms |
49680 KB |
Output is correct |
5 |
Correct |
77 ms |
30424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
608 KB |
Output is correct |
2 |
Correct |
1 ms |
436 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
504 KB |
Output is correct |
10 |
Correct |
1 ms |
436 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
504 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
68 ms |
12616 KB |
Output is correct |
19 |
Correct |
65 ms |
12812 KB |
Output is correct |
20 |
Correct |
65 ms |
12432 KB |
Output is correct |
21 |
Correct |
67 ms |
12360 KB |
Output is correct |
22 |
Correct |
67 ms |
12616 KB |
Output is correct |
23 |
Correct |
68 ms |
12104 KB |
Output is correct |
24 |
Correct |
63 ms |
12104 KB |
Output is correct |
25 |
Correct |
62 ms |
12112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
9700 KB |
Output is correct |
2 |
Correct |
110 ms |
46352 KB |
Output is correct |
3 |
Correct |
116 ms |
50960 KB |
Output is correct |
4 |
Correct |
115 ms |
50960 KB |
Output is correct |
5 |
Correct |
114 ms |
51216 KB |
Output is correct |
6 |
Correct |
113 ms |
51528 KB |
Output is correct |
7 |
Correct |
121 ms |
51472 KB |
Output is correct |
8 |
Correct |
107 ms |
51472 KB |
Output is correct |
9 |
Correct |
88 ms |
31564 KB |
Output is correct |
10 |
Correct |
93 ms |
31716 KB |
Output is correct |
11 |
Correct |
102 ms |
31720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
45792 KB |
Output is correct |
2 |
Correct |
123 ms |
51472 KB |
Output is correct |
3 |
Correct |
106 ms |
49936 KB |
Output is correct |
4 |
Correct |
114 ms |
49932 KB |
Output is correct |
5 |
Correct |
101 ms |
51984 KB |
Output is correct |
6 |
Correct |
84 ms |
31952 KB |
Output is correct |
7 |
Correct |
73 ms |
23768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
49664 KB |
Output is correct |
2 |
Correct |
94 ms |
49680 KB |
Output is correct |
3 |
Correct |
94 ms |
49100 KB |
Output is correct |
4 |
Correct |
96 ms |
49680 KB |
Output is correct |
5 |
Correct |
77 ms |
30424 KB |
Output is correct |
6 |
Correct |
111 ms |
45792 KB |
Output is correct |
7 |
Correct |
123 ms |
51472 KB |
Output is correct |
8 |
Correct |
106 ms |
49936 KB |
Output is correct |
9 |
Correct |
114 ms |
49932 KB |
Output is correct |
10 |
Correct |
101 ms |
51984 KB |
Output is correct |
11 |
Correct |
84 ms |
31952 KB |
Output is correct |
12 |
Correct |
73 ms |
23768 KB |
Output is correct |
13 |
Correct |
105 ms |
51532 KB |
Output is correct |
14 |
Correct |
114 ms |
51656 KB |
Output is correct |
15 |
Correct |
101 ms |
51844 KB |
Output is correct |
16 |
Correct |
98 ms |
49936 KB |
Output is correct |
17 |
Correct |
106 ms |
51216 KB |
Output is correct |
18 |
Correct |
101 ms |
51536 KB |
Output is correct |
19 |
Correct |
82 ms |
27576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
608 KB |
Output is correct |
3 |
Correct |
1 ms |
436 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
504 KB |
Output is correct |
11 |
Correct |
1 ms |
436 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
504 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
109 ms |
49664 KB |
Output is correct |
20 |
Correct |
94 ms |
49680 KB |
Output is correct |
21 |
Correct |
94 ms |
49100 KB |
Output is correct |
22 |
Correct |
96 ms |
49680 KB |
Output is correct |
23 |
Correct |
77 ms |
30424 KB |
Output is correct |
24 |
Correct |
68 ms |
12616 KB |
Output is correct |
25 |
Correct |
65 ms |
12812 KB |
Output is correct |
26 |
Correct |
65 ms |
12432 KB |
Output is correct |
27 |
Correct |
67 ms |
12360 KB |
Output is correct |
28 |
Correct |
67 ms |
12616 KB |
Output is correct |
29 |
Correct |
68 ms |
12104 KB |
Output is correct |
30 |
Correct |
63 ms |
12104 KB |
Output is correct |
31 |
Correct |
62 ms |
12112 KB |
Output is correct |
32 |
Correct |
56 ms |
9700 KB |
Output is correct |
33 |
Correct |
110 ms |
46352 KB |
Output is correct |
34 |
Correct |
116 ms |
50960 KB |
Output is correct |
35 |
Correct |
115 ms |
50960 KB |
Output is correct |
36 |
Correct |
114 ms |
51216 KB |
Output is correct |
37 |
Correct |
113 ms |
51528 KB |
Output is correct |
38 |
Correct |
121 ms |
51472 KB |
Output is correct |
39 |
Correct |
107 ms |
51472 KB |
Output is correct |
40 |
Correct |
88 ms |
31564 KB |
Output is correct |
41 |
Correct |
93 ms |
31716 KB |
Output is correct |
42 |
Correct |
102 ms |
31720 KB |
Output is correct |
43 |
Correct |
111 ms |
45792 KB |
Output is correct |
44 |
Correct |
123 ms |
51472 KB |
Output is correct |
45 |
Correct |
106 ms |
49936 KB |
Output is correct |
46 |
Correct |
114 ms |
49932 KB |
Output is correct |
47 |
Correct |
101 ms |
51984 KB |
Output is correct |
48 |
Correct |
84 ms |
31952 KB |
Output is correct |
49 |
Correct |
73 ms |
23768 KB |
Output is correct |
50 |
Correct |
105 ms |
51532 KB |
Output is correct |
51 |
Correct |
114 ms |
51656 KB |
Output is correct |
52 |
Correct |
101 ms |
51844 KB |
Output is correct |
53 |
Correct |
98 ms |
49936 KB |
Output is correct |
54 |
Correct |
106 ms |
51216 KB |
Output is correct |
55 |
Correct |
101 ms |
51536 KB |
Output is correct |
56 |
Correct |
82 ms |
27576 KB |
Output is correct |
57 |
Correct |
111 ms |
51472 KB |
Output is correct |
58 |
Correct |
106 ms |
51216 KB |
Output is correct |
59 |
Correct |
112 ms |
51664 KB |
Output is correct |
60 |
Correct |
110 ms |
50960 KB |
Output is correct |
61 |
Correct |
109 ms |
50960 KB |
Output is correct |
62 |
Correct |
111 ms |
51148 KB |
Output is correct |
63 |
Correct |
94 ms |
31788 KB |
Output is correct |
64 |
Correct |
81 ms |
22564 KB |
Output is correct |