#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll; typedef pair<int, int> pii;
#define pb emplace_back
#define AI(x) begin(x),end(x)
#define ff first
#define ss second
#ifdef OWO
#define debug(args...) LKJ("\033[0;32m[ " + string(#args) + " ]\033[0m", args)
template<class I> void LKJ(I&&x) { cerr << x << endl; }
template<class I, class...T> void LKJ(I&&x, T&&...t) { cerr << x << ", "; LKJ(t...); }
template<class I> void OI(I a, I b) { while (a < b) cerr << *a << " \n"[next(a) == b]; }
#else
#define debug(...) 0
#define OI(...) 0
#endif
bool next_to(pii a, pii b) {
int da = a.ff - b.ff;
int db = a.ss - b.ss;
if (da < 0) da = -da;
if (db < 0) db = -db;
return (da + db == 1);
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int H, W; cin >> H >> W;
vector<vector<int>> A(H, vector<int>(W));
for (auto &v: A) for (int &i: v) cin >> i;
int ans = 0;
map<int, pii> mp;
for (int u = 0; u < H; ++u)
for (int l = 0; l < W; ++l) {
for (int r = l; r < W; ++r) {
mp.clear();
for (int d = u; d < H; ++d) {
debug(u, l, r, d);
for (int p = l; p <= r; ++p)
mp[A[d][p]] = pii(d, p);
bool all = true;
for (auto it = begin(mp); it != end(mp) and all; ++it) {
all &= (it == begin(mp) or next_to(it->ss, prev(it)->ss));
all &= (it == prev(end(mp)) or next_to(it->ss, next(it)->ss));
}
ans += all;
}
}
}
cout << ans << '\n';
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:15:20: warning: statement has no effect [-Wunused-value]
15 | #define debug(...) 0
| ^
Main.cpp:41:6: note: in expansion of macro 'debug'
41 | debug(u, l, r, d);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Execution timed out |
5093 ms |
852 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
204 KB |
Output is correct |
3 |
Correct |
17 ms |
204 KB |
Output is correct |
4 |
Correct |
6 ms |
204 KB |
Output is correct |
5 |
Correct |
7 ms |
204 KB |
Output is correct |
6 |
Correct |
8 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
204 KB |
Output is correct |
3 |
Correct |
17 ms |
204 KB |
Output is correct |
4 |
Correct |
6 ms |
204 KB |
Output is correct |
5 |
Correct |
7 ms |
204 KB |
Output is correct |
6 |
Correct |
8 ms |
324 KB |
Output is correct |
7 |
Execution timed out |
5062 ms |
516 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
204 KB |
Output is correct |
3 |
Correct |
17 ms |
204 KB |
Output is correct |
4 |
Correct |
6 ms |
204 KB |
Output is correct |
5 |
Correct |
7 ms |
204 KB |
Output is correct |
6 |
Correct |
8 ms |
324 KB |
Output is correct |
7 |
Execution timed out |
5062 ms |
516 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
204 KB |
Output is correct |
3 |
Correct |
17 ms |
204 KB |
Output is correct |
4 |
Correct |
6 ms |
204 KB |
Output is correct |
5 |
Correct |
7 ms |
204 KB |
Output is correct |
6 |
Correct |
8 ms |
324 KB |
Output is correct |
7 |
Execution timed out |
5062 ms |
516 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |