# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
529901 |
2022-02-24T02:31:19 Z |
8e7 |
Sandcastle 2 (JOI22_ho_t5) |
C++17 |
|
5000 ms |
17268 KB |
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 105
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
int dir[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
int main() {
io
int n, m;
cin >> n >> m;
bool sw = 0;
if (n > m) swap(n, m), sw = 1; //n <= m
vector<vector<int> > a(n, vector<int>(m, 0));
vector<vector<vector<int> > > p(81, vector< vector<int> >(n, vector<int>(m)));
vector<int> val;
if (sw) {
for (int i = 0;i < m;i++) {
for (int j = 0;j < n;j++) cin >> a[j][i];
}
} else {
for (int i = 0;i < n;i++) {
for (int j = 0;j < m;j++) cin >> a[i][j];
}
}
for (int i = 0;i < n;i++) {
for (int j = 0;j < m;j++) val.push_back(a[i][j]);
}
sort(val.begin(), val.end());
val.resize(int(unique(val.begin(), val.end()) - val.begin()));
for (int i = 0;i < n;i++) {
for (int j = 0;j < m;j++) a[i][j] = lower_bound(val.begin(), val.end(), a[i][j]) - val.begin() + 1;
}
auto check = [&] (int pv, int av, int cx, int cy) {
return !(a[cx][cy] > av && a[cx][cy] < pv);
};
for (int k = 0;k < 81;k++) {
int du = k%3, dr = (k/3)%3, dd = (k/9)%3, dl = (k/27);
int d[4] = {du, dr, dd, dl};
for (int i = 0;i < n;i++) {
for (int j = 0;j < m;j++) {
if (i < du || j < dl || n - i - 1 < dd || m - j - 1< dr) continue;
int cnt = 0;
for (int x = 0;x < 4;x++) {
if (!d[x]) continue;
int px = i + dir[x][0], py = j + dir[x][1], pv = a[px][py];
if (pv < a[i][j]) continue;
bool con = 1;
if (d[x] == 2) con &= check(pv, a[i][j], px+dir[x][0], py+dir[x][1]);
//if (k == 6 && i == 0 && j == 0) debug("upd", px, py, px+dir[x][0], py+dir[x][1]);
if (d[(x+1)%4]) con &= check(pv, a[i][j], px+dir[(x+1)%4][0], py+dir[(x+1)%4][1]);
if (d[(x+3)%4]) con &= check(pv, a[i][j], px+dir[(x+3)%4][0], py+dir[(x+3)%4][1]);
cnt += con ? 1 : 0;
}
if (cnt == 0) p[k][i][j]++;
else if (cnt == 2) p[k][i][j] += 2;
if (j) p[k][i][j] += p[k][i][j-1];
}
if (i) {
for (int j = 0;j < m;j++) p[k][i][j] += p[k][i-1][j];
}
}
}
auto pref = [&](int k, int rx, int ry, int lx, int ly) {
int ret = p[k][rx][ry];
if (lx) ret -= p[k][lx-1][ry];
if (ly) ret -= p[k][rx][ly-1];
if (lx&&ly) ret += p[k][lx-1][ly-1];
return ret;
};
auto get_rect = [&] (int u, int d, int l, int r) {
int tot = 0;
for (int i = u;i <= d;i++) {
int nx = i;
if (i == u + 2 && d - u + 1 >= 5) nx = d - 2;
for (int j = l;j <= r;j++) {
int ny = j;
if (j == l + 2 && r - l + 1 >= 5) ny = r - 2;
int du = min(i-u, 2), dr = min(r-j, 2), dd = min(d-i, 2), dl = min(j-l, 2);
int state = du + dr*3 + dd*9 + dl*27;
tot += pref(state, nx, ny, i, j);
//if (tot > 1) return 0;
j = ny;
}
i = nx;
}
//debug(u, d, l, r, tot);
return tot == 1 ? 1 : 0;
};
int ans = 0;
for (int u = 0;u < n;u++) {
for (int d = u;d < n;d++) {
for (int l = 0;l < m;l++) {
for (int r = l;r < m;r++) {
ans += get_rect(u, d, l, r);
}
}
}
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Execution timed out |
5057 ms |
17268 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
23 ms |
716 KB |
Output is correct |
8 |
Correct |
23 ms |
716 KB |
Output is correct |
9 |
Correct |
57 ms |
884 KB |
Output is correct |
10 |
Correct |
60 ms |
888 KB |
Output is correct |
11 |
Correct |
24 ms |
716 KB |
Output is correct |
12 |
Correct |
24 ms |
820 KB |
Output is correct |
13 |
Correct |
52 ms |
884 KB |
Output is correct |
14 |
Correct |
27 ms |
716 KB |
Output is correct |
15 |
Correct |
57 ms |
884 KB |
Output is correct |
16 |
Correct |
59 ms |
880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
23 ms |
716 KB |
Output is correct |
8 |
Correct |
23 ms |
716 KB |
Output is correct |
9 |
Correct |
57 ms |
884 KB |
Output is correct |
10 |
Correct |
60 ms |
888 KB |
Output is correct |
11 |
Correct |
24 ms |
716 KB |
Output is correct |
12 |
Correct |
24 ms |
820 KB |
Output is correct |
13 |
Correct |
52 ms |
884 KB |
Output is correct |
14 |
Correct |
27 ms |
716 KB |
Output is correct |
15 |
Correct |
57 ms |
884 KB |
Output is correct |
16 |
Correct |
59 ms |
880 KB |
Output is correct |
17 |
Correct |
471 ms |
2680 KB |
Output is correct |
18 |
Correct |
1229 ms |
2764 KB |
Output is correct |
19 |
Correct |
1105 ms |
2636 KB |
Output is correct |
20 |
Correct |
1248 ms |
2904 KB |
Output is correct |
21 |
Correct |
1241 ms |
2916 KB |
Output is correct |
22 |
Correct |
1230 ms |
2892 KB |
Output is correct |
23 |
Correct |
1164 ms |
2740 KB |
Output is correct |
24 |
Correct |
1000 ms |
2552 KB |
Output is correct |
25 |
Correct |
1257 ms |
2844 KB |
Output is correct |
26 |
Correct |
1259 ms |
2904 KB |
Output is correct |
27 |
Correct |
1256 ms |
2836 KB |
Output is correct |
28 |
Correct |
1256 ms |
2892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
23 ms |
716 KB |
Output is correct |
8 |
Correct |
23 ms |
716 KB |
Output is correct |
9 |
Correct |
57 ms |
884 KB |
Output is correct |
10 |
Correct |
60 ms |
888 KB |
Output is correct |
11 |
Correct |
24 ms |
716 KB |
Output is correct |
12 |
Correct |
24 ms |
820 KB |
Output is correct |
13 |
Correct |
52 ms |
884 KB |
Output is correct |
14 |
Correct |
27 ms |
716 KB |
Output is correct |
15 |
Correct |
57 ms |
884 KB |
Output is correct |
16 |
Correct |
59 ms |
880 KB |
Output is correct |
17 |
Correct |
471 ms |
2680 KB |
Output is correct |
18 |
Correct |
1229 ms |
2764 KB |
Output is correct |
19 |
Correct |
1105 ms |
2636 KB |
Output is correct |
20 |
Correct |
1248 ms |
2904 KB |
Output is correct |
21 |
Correct |
1241 ms |
2916 KB |
Output is correct |
22 |
Correct |
1230 ms |
2892 KB |
Output is correct |
23 |
Correct |
1164 ms |
2740 KB |
Output is correct |
24 |
Correct |
1000 ms |
2552 KB |
Output is correct |
25 |
Correct |
1257 ms |
2844 KB |
Output is correct |
26 |
Correct |
1259 ms |
2904 KB |
Output is correct |
27 |
Correct |
1256 ms |
2836 KB |
Output is correct |
28 |
Correct |
1256 ms |
2892 KB |
Output is correct |
29 |
Execution timed out |
5050 ms |
16904 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |