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 <iostream>
#include <vector>
#include <climits>
#include <cmath>
#include <algorithm>
#include <stack>
using namespace std;
int main(){
int n, m;
cin >> n >> m;
int grid[n][m];
int preL[n][m], preU[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int temp;
cin >> temp;
grid[i][j] = temp;
preL[i][j] = 1;
preU[i][j] = 1;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (i > 0) {
if (grid[i][j] == grid[i - 1][j]) {
preU[i][j] = preU[i - 1][j] + 1;
}
}
if (j > 0) {
if (grid[i][j] == grid[i][j - 1]) {
preL[i][j] = preL[i][j - 1] + 1;
}
}
}
}
int dp[n][m];
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (i == 0 && j == 0) {
dp[i][j] = 1;
}
else if (i == 0) {
dp[i][j] = preL[i][j];
}
else if (j == 0) {
dp[i][j] = preU[i][j];
}
else {
if (grid[i - 1][j - 1] != grid[i][j]) {
dp[i][j] = preL[i][j] + preU[i][j] - 1;
}
else {
dp[i][j] = min(preL[i][j], preL[i - 1][j - 1] + 1) * min(preU[i][j], preU[i - 1][j - 1] + 1);
}
}
ans += dp[i][j];
}
}
cout << ans << endl;
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... |