#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pii pair<int, int>
#define f first
#define s second
#define REP(i,n) for (int i = 0; i<n; ++i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)
#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define MX(a,b) a = max(a,b)
#define MN(a,b) a = min(a,b)
#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<" "<<#__VA_ARGS__<<" - ", _do(__VA_ARGS__)
template <typename T> void _do( T && x) {cerr<<x<<endl;}
template <typename T, typename ...S> void _do( T && x, S && ...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#define endl '\n'
#endif // BALBIT
const int maxn = 7000*7000+5;
vector<vector<int> > G;
vector<int> legal[305*305];
void upd(int a, int b) {
if (a < b) {
legal[a].pb(b);
}
}
bool ok(int a, int b) {
return find(ALL(legal[a]), b) != legal[a].end();
}
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
bug(1,2);
int n,m; cin>>n>>m;
G.resize(n, vector<int> (m));
REP(i,n) REP(j,m) {
cin>>G[i][j];
}
REP(i,n) REP(j,m) {
if (i) upd(G[i][j], G[i-1][j]);
if (i<n-1) upd(G[i][j], G[i+1][j]);
if (j<m-1) upd(G[i][j], G[i][j+1]);
if (j) upd(G[i][j], G[i][j-1]);
}
int re =0 ;
REP(h2, n) {
REP(h1, h2+1) {
// using only rows from h1 to h2
// play ball
for( int w1 = 0; w1 < m; ++w1) {
// for subtask... just enumerate w1, w2...
vector<int> tmp;
for( int w2 = w1; w2 < m; ++w2) {
for (int k = h1; k<=h2; ++k) {
tmp.pb(G[k][w2]);
}
sort(ALL(tmp));
REP(i, SZ(tmp)-1) {
if (!ok(tmp[i], tmp[i+1])) {
goto nope;
}
}
re++;
nope:;
}
}
}
}
cout<<re<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2380 KB |
Output is correct |
2 |
Runtime error |
13 ms |
6084 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
4812 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
4812 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
4812 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
4812 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |