This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e3 + 5;
int a[maxN][maxN], N, M;
namespace subtask1{
bool check(){
return max(N, M) <= 50;
}
bool ok[51][51][51][51];
void solve(){
int res = 0;
for(int i = 1; i <= N; ++i)for(int j = 1; j <= M; ++j)ok[i][j][i][j] = 1;
for(int i = 1; i <= N; ++i){
for(int j = 1; j <= M; ++j){
for(int x = i + 1; x <= N; ++x){
if(a[i][j] == a[x][j]) ok[i][j][x][j] = ok[i][j][x - 1][j];
}
for(int y = j + 1; y <= M; ++y){
if(a[i][j] == a[i][y]) ok[i][j][i][y] = ok[i][j][i][y - 1];
}
for(int x = i + 1; x <= N; ++x){
for(int y = j + 1; y <= M; ++y){
if(a[x][y] == a[i][j]){
ok[i][j][x][y] = ok[i][j][x - 1][y] && ok[i][j][x][y - 1];
}
}
}
}
}
for(int i = 1; i <= N; ++i)for(int j = 1; j <= M; ++j)for(int x = i; x <= N; ++x)for(int y = j; y <= M; ++y)
if(ok[i][j][x][y]){
++res;
}
cout << res;
}
}
int main(){
// freopen("s2.inp", "r", stdin);
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> N >> M;
for(int i = 1; i <= N; ++i)
for(int j = 1; j <= M; ++j){
cin >> a[i][j];
}
if(subtask1 :: check()) return subtask1 :: solve(), 0;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |