Submission #263892

#TimeUsernameProblemLanguageResultExecution timeMemory
263892shrek12357Bob (COCI14_bob)C++14
0 / 120
873 ms20088 KiB
#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; } } } } long long dp[n][m]; long long 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...