Submission #316336

# Submission time Handle Problem Language Result Execution time Memory
316336 2020-10-25T22:58:07 Z FlashGamezzz Bob (COCI14_bob) C++17
0 / 120
301 ms 19064 KB
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <utility>

using namespace std;

int n, m, grid[1001][1001] = {}, nl[1001][1001] = {}, nu[1001][1001] = {}, dp[1001][1001] = {};
map<int, int> mps[1001];

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			cin >> grid[i][j]; nl[i][j] = 1; nu[i][j] = 1;
			if (grid[i][j] == grid[i][j-1]){
				nl[i][j] += nl[i][j-1];
			}
			if (grid[i][j] == grid[i-1][j]){
				nu[i][j] += nu[i-1][j];
			}
		}
	}
	for (int r = 1; r <= n; r++){
		dp[r][1] = nu[r][1]; mps[r][dp[r][1]] = 1;
	}
	for (int c = 2; c <= m; c++){
		for (int r = 1; r <= n; r++){
			if (grid[r][c] != grid[r][c-1]){
				mps[r].clear();
			}
			dp[r][c] = nu[r][c] * nl[r][c];
			if (mps[r].size() > 0){
				map<int, int>::iterator lb = mps[r].lower_bound(nu[r][1]);
				if (lb != mps[r].begin()){
					lb--; dp[r][c] -= nl[r][lb->second] * nu[r][c]; dp[r][c] += dp[r][lb->second];
				}
			}
			mps[r].insert(make_pair(nu[r][c], c)); mps[r].erase(mps[r].upper_bound(nu[r][c]), mps[r].end());
		}
	}
	long ans = 0;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			ans += dp[i][j];
		}
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1152 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1152 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 8952 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 55 ms 9336 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 9516 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 9472 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 278 ms 17832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 301 ms 17656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 213 ms 17784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 228 ms 19064 KB Output isn't correct
2 Halted 0 ms 0 KB -