# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1030930 |
2024-07-22T12:27:22 Z |
Zicrus |
Rectangles (IOI19_rect) |
C++17 |
|
148 ms |
62172 KB |
#include <bits/stdc++.h>
#include "rect.h"
using namespace std;
typedef long long ll;
ll n, m;
ll pow2N, pow2M;
vector<vector<ll>> segN, segM;
ll segMaxN(ll low, ll high, ll m) {
low += pow2N; high += pow2N;
ll mx = 0;
while (low <= high) {
if (low & 1) mx = max(mx, segN[m][low++]);
if (!(high & 1)) mx = max(mx, segN[m][high--]);
low /= 2; high /= 2;
}
return mx;
}
ll segMaxM(ll low, ll high, ll n) {
low += pow2M; high += pow2M;
ll mx = 0;
while (low <= high) {
if (low & 1) mx = max(mx, segM[n][low++]);
if (!(high & 1)) mx = max(mx, segM[n][high--]);
low /= 2; high /= 2;
}
return mx;
}
ll otherSol(vector<vector<int>> a) {
if (a.size() <= 2) return 0;
n = a.size(); m = a[0].size();
pow2N = 1ll << (ll)ceil(log2(n));
pow2M = 1ll << (ll)ceil(log2(m));
vector<int> am = a[1];
segN = vector<vector<ll>>(m, vector<ll>(2*pow2N));
segM = vector<vector<ll>>(n, vector<ll>(2*pow2M));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
segN[j][pow2N+i] = a[i][j];
segM[i][pow2M+j] = a[i][j];
}
}
for (int meta = 0; meta < n; meta++) {
for (int i = pow2M-1; i > 0; i--) {
segM[meta][i] = max(segM[meta][2*i], segM[meta][2*i+1]);
}
}
for (int meta = 0; meta < m; meta++) {
for (int i = pow2N-1; i > 0; i--) {
segN[meta][i] = max(segN[meta][2*i], segN[meta][2*i+1]);
}
}
ll res = 0;
for (int lN = 1; lN <= n; lN++) {
for (int lM = 1; lM <= m; lM++) {
for (int i = 1; i+lN-1 < n-1; i++) {
for (int j = 1; j+lM-1 < m-1; j++) {
bool poss = 1;
for (int meta = i; meta < i+lN && poss; meta++) {
ll border = min(a[meta][j-1], a[meta][j+lM]);
if (border <= segMaxM(j, j+lM-1, meta)) {
poss = 0;
}
}
for (int meta = j; meta < j+lM && poss; meta++) {
ll border = min(a[i-1][meta], a[i+lN][meta]);
if (border <= segMaxN(i, i+lN-1, meta)) {
poss = 0;
}
}
res += poss;
if (poss) j += lM;
}
}
}
}
return res;
}
ll count_rectangles(vector<vector<int>> a) {
if (a.size() <= 2) return 0;
n = a.size(); m = a[0].size();
if (n <= 3 || (n <= 80 && m <= 80)) {
return otherSol(a);
}
vector<vector<bool>> vst(n, vector<bool>(m));
ll res = 0;
for (int i = 1; i < n-1; i++) {
for (int j = 1; j < m-1; j++) {
if (a[i][j] || vst[i][j]) continue;
ll ptrN = i, ptrM = j;
while (!a[ptrN][ptrM] && ptrM < m-1) ptrM++;
ptrM--;
while (!a[ptrN][ptrM] && ptrN < n-1) ptrN++;
ptrN--;
bool poss = true;
for (int x = i; x <= ptrN && poss; x++) {
for (int y = j; y <= ptrM && poss; y++) {
vst[x][y] = true;
if (a[x][y]) poss = false;
}
}
for (int x = i; x <= ptrN && poss; x++) {
if (!a[x][j-1]) poss = false;
if (!a[x][ptrM+1]) poss = false;
}
for (int y = j; y <= ptrM && poss; y++) {
if (!a[i-1][y]) poss = false;
if (!a[ptrN+1][y]) poss = false;
}
res += poss;
}
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
600 KB |
Output is correct |
11 |
Correct |
2 ms |
344 KB |
Output is correct |
12 |
Correct |
2 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
600 KB |
Output is correct |
11 |
Correct |
2 ms |
344 KB |
Output is correct |
12 |
Correct |
2 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
144 ms |
860 KB |
Output is correct |
23 |
Correct |
144 ms |
864 KB |
Output is correct |
24 |
Correct |
148 ms |
1112 KB |
Output is correct |
25 |
Correct |
82 ms |
604 KB |
Output is correct |
26 |
Correct |
83 ms |
600 KB |
Output is correct |
27 |
Correct |
89 ms |
860 KB |
Output is correct |
28 |
Correct |
109 ms |
840 KB |
Output is correct |
29 |
Correct |
19 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
600 KB |
Output is correct |
11 |
Correct |
2 ms |
344 KB |
Output is correct |
12 |
Correct |
2 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
144 ms |
860 KB |
Output is correct |
18 |
Correct |
144 ms |
864 KB |
Output is correct |
19 |
Correct |
148 ms |
1112 KB |
Output is correct |
20 |
Correct |
82 ms |
604 KB |
Output is correct |
21 |
Correct |
83 ms |
600 KB |
Output is correct |
22 |
Correct |
89 ms |
860 KB |
Output is correct |
23 |
Correct |
109 ms |
840 KB |
Output is correct |
24 |
Correct |
19 ms |
600 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Incorrect |
1 ms |
968 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
600 KB |
Output is correct |
11 |
Correct |
2 ms |
344 KB |
Output is correct |
12 |
Correct |
2 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
144 ms |
860 KB |
Output is correct |
18 |
Correct |
144 ms |
864 KB |
Output is correct |
19 |
Correct |
148 ms |
1112 KB |
Output is correct |
20 |
Correct |
82 ms |
604 KB |
Output is correct |
21 |
Correct |
83 ms |
600 KB |
Output is correct |
22 |
Correct |
89 ms |
860 KB |
Output is correct |
23 |
Correct |
109 ms |
840 KB |
Output is correct |
24 |
Correct |
19 ms |
600 KB |
Output is correct |
25 |
Incorrect |
1 ms |
968 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
141 ms |
860 KB |
Output is correct |
2 |
Correct |
96 ms |
860 KB |
Output is correct |
3 |
Correct |
123 ms |
1032 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
130 ms |
860 KB |
Output is correct |
6 |
Correct |
131 ms |
1072 KB |
Output is correct |
7 |
Correct |
128 ms |
860 KB |
Output is correct |
8 |
Correct |
131 ms |
860 KB |
Output is correct |
9 |
Correct |
128 ms |
860 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
58 ms |
28800 KB |
Output is correct |
8 |
Correct |
125 ms |
61780 KB |
Output is correct |
9 |
Correct |
133 ms |
62040 KB |
Output is correct |
10 |
Correct |
133 ms |
62172 KB |
Output is correct |
11 |
Correct |
40 ms |
31060 KB |
Output is correct |
12 |
Correct |
76 ms |
58456 KB |
Output is correct |
13 |
Correct |
80 ms |
62036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
600 KB |
Output is correct |
11 |
Correct |
2 ms |
344 KB |
Output is correct |
12 |
Correct |
2 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
144 ms |
860 KB |
Output is correct |
18 |
Correct |
144 ms |
864 KB |
Output is correct |
19 |
Correct |
148 ms |
1112 KB |
Output is correct |
20 |
Correct |
82 ms |
604 KB |
Output is correct |
21 |
Correct |
83 ms |
600 KB |
Output is correct |
22 |
Correct |
89 ms |
860 KB |
Output is correct |
23 |
Correct |
109 ms |
840 KB |
Output is correct |
24 |
Correct |
19 ms |
600 KB |
Output is correct |
25 |
Incorrect |
1 ms |
968 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |