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 <cstdlib>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
using namespace std;
int n, m, grid[1000][1000];
long long dp[1000][1000];
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> m;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
cin >> grid[i][j];
}
}
dp[0][0] = 1;
for (int i = 1; i < n; i++){
dp[i][0] = 1;
if (grid[i-1][0] == grid[i][0]){
dp[i][0] += dp[i-1][0];
}
}
for (int i = 1; i < m; i++){
dp[0][i] = 1;
if (grid[0][i-1] == grid[0][i]){
dp[0][i] += dp[0][i-1];
}
}
for (int i = 1; i < n; i++){
for (int j = 1; j < m; j++){
dp[i][j] = 1;
if (grid[i-1][j] == grid[i][j]){
dp[i][j] += dp[i-1][j];
}
if (grid[i][j-1] == grid[i][j]){
dp[i][j] += dp[i][j-1];
}
if (grid[i][j] > 1 && grid[i-1][j-1] == grid[i][j]){
dp[i][j] -= dp[i-1][j-1];
}
}
}
long long ans = 0;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
//cout << dp[i][j] << " ";
ans += dp[i][j];
}
//cout << endl;
}
cout << ans << endl;
}
# | 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... |