Submission #263892

# Submission time Handle Problem Language Result Execution time Memory
263892 2020-08-14T03:08:29 Z shrek12357 Bob (COCI14_bob) C++14
0 / 120
873 ms 20088 KB
#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 time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 5240 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 107 ms 5232 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 125 ms 5152 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 122 ms 5240 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 628 ms 20088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 868 ms 19976 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 848 ms 19824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 873 ms 19928 KB Output isn't correct
2 Halted 0 ms 0 KB -