Submission #316045

#TimeUsernameProblemLanguageResultExecution timeMemory
316045FlashGamezzzBob (COCI14_bob)C++17
0 / 120
138 ms21752 KiB
#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 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...