# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
526914 |
2022-02-16T16:20:06 Z |
eecs |
Sandcastle 2 (JOI22_ho_t5) |
C++17 |
|
5000 ms |
888 KB |
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
const int maxn = 50010;
const int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};
int h, w, ans, tim, a[maxn], vis[maxn];
int id(int x, int y) {
return (x - 1) * w + y;
}
int main() {
scanf("%d %d", &h, &w);
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
scanf("%d", &a[id(i, j)]);
}
}
if (h == 1) {
static int f[maxn], id[maxn];
fill(f + 1, f + w + 1, 1);
iota(id + 1, id + w + 1, 1);
sort(id + 1, id + w + 1, [&](int x, int y) { return a[x] < a[y]; });
for (int i = 1; i <= w; i++) {
int x = id[i];
if (x > 1 && a[x - 1] < a[x]) f[x] += f[x - 1];
if (x < w && a[x + 1] < a[x]) f[x] += f[x + 1];
}
printf("%lld\n", accumulate(f + 1, f + w + 1, 0LL)), exit(0);
}
for (int lx = 1; lx <= h; lx++) for (int rx = lx; rx <= h; rx++) {
for (int ly = 1; ly <= w; ly++) for (int ry = ly; ry <= w; ry++) {
int mx = 0, x, y;
for (int i = lx; i <= rx; i++) {
for (int j = ly; j <= ry; j++) {
if (a[id(i, j)] > mx) mx = a[id(i, j)], x = i, y = j;
}
}
tim++;
bool flag = 1;
for (int i = 1; i <= (rx - lx + 1) * (ry - ly + 1); i++) {
if (vis[id(x, y)] == tim) { flag = 0; break; }
vis[id(x, y)] = tim, mx = 0;
int foo = x, bar = y;
for (int d = 0; d < 4; d++) {
int _x = x + dx[d], _y = y + dy[d];
if (_x < lx || _x > rx || _y < ly || _y > ry) continue;
if (a[id(x, y)] > a[id(_x, _y)] && a[id(_x, _y)] > mx) mx = a[id(_x, _y)], foo = _x, bar = _y;
}
x = foo, y = bar;
}
if (flag) ans++;
}
}
printf("%d\n", ans);
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%d %d", &h, &w);
| ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:17:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | scanf("%d", &a[id(i, j)]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:49:35: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
49 | if (a[id(x, y)] > a[id(_x, _y)] && a[id(_x, _y)] > mx) mx = a[id(_x, _y)], foo = _x, bar = _y;
| ~~~~~~~~~~^
Main.cpp:10:26: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
10 | return (x - 1) * w + y;
| ^
Main.cpp:34:28: note: 'y' was declared here
34 | int mx = 0, x, y;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
6 ms |
820 KB |
Output is correct |
3 |
Correct |
9 ms |
844 KB |
Output is correct |
4 |
Correct |
8 ms |
872 KB |
Output is correct |
5 |
Correct |
8 ms |
888 KB |
Output is correct |
6 |
Correct |
11 ms |
884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1455 ms |
296 KB |
Output is correct |
8 |
Correct |
500 ms |
296 KB |
Output is correct |
9 |
Correct |
178 ms |
204 KB |
Output is correct |
10 |
Correct |
780 ms |
296 KB |
Output is correct |
11 |
Correct |
1756 ms |
296 KB |
Output is correct |
12 |
Correct |
2071 ms |
296 KB |
Output is correct |
13 |
Correct |
292 ms |
296 KB |
Output is correct |
14 |
Correct |
132 ms |
204 KB |
Output is correct |
15 |
Correct |
326 ms |
204 KB |
Output is correct |
16 |
Correct |
212 ms |
296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1455 ms |
296 KB |
Output is correct |
8 |
Correct |
500 ms |
296 KB |
Output is correct |
9 |
Correct |
178 ms |
204 KB |
Output is correct |
10 |
Correct |
780 ms |
296 KB |
Output is correct |
11 |
Correct |
1756 ms |
296 KB |
Output is correct |
12 |
Correct |
2071 ms |
296 KB |
Output is correct |
13 |
Correct |
292 ms |
296 KB |
Output is correct |
14 |
Correct |
132 ms |
204 KB |
Output is correct |
15 |
Correct |
326 ms |
204 KB |
Output is correct |
16 |
Correct |
212 ms |
296 KB |
Output is correct |
17 |
Execution timed out |
5054 ms |
336 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1455 ms |
296 KB |
Output is correct |
8 |
Correct |
500 ms |
296 KB |
Output is correct |
9 |
Correct |
178 ms |
204 KB |
Output is correct |
10 |
Correct |
780 ms |
296 KB |
Output is correct |
11 |
Correct |
1756 ms |
296 KB |
Output is correct |
12 |
Correct |
2071 ms |
296 KB |
Output is correct |
13 |
Correct |
292 ms |
296 KB |
Output is correct |
14 |
Correct |
132 ms |
204 KB |
Output is correct |
15 |
Correct |
326 ms |
204 KB |
Output is correct |
16 |
Correct |
212 ms |
296 KB |
Output is correct |
17 |
Execution timed out |
5054 ms |
336 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |