Submission #49739

# Submission time Handle Problem Language Result Execution time Memory
49739 2018-06-02T13:23:19 Z IvanC Bob (COCI14_bob) C++17
120 / 120
737 ms 64372 KB
#include <bits/stdc++.h>
#define gc getchar_unlocked
void getint(int &x){
    int c = gc();
    x = 0;
    for(;(c<48 || c>57);c = gc());
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
}
using namespace std;
typedef long long ll;
const int MAXN = 1e3 + 10;
int matriz[MAXN][MAXN],vaiate[MAXN][MAXN],n,m;
ll resp;
int main(){
	getint(n);getint(m);
	for(int i = 1;i<=n;i++){
		for(int j = 1;j<=m;j++){
			getint(matriz[i][j]);
		}
	}
	for(int coluna = 1;coluna <= m;coluna++){
		vaiate[n][coluna] = 1;
		for(int linha = n - 1;linha >= 1;linha--){
			if(matriz[linha][coluna] == matriz[linha+1][coluna]) vaiate[linha][coluna] = 1 + vaiate[linha+1][coluna];
			else vaiate[linha][coluna] = 1;
		}
	}
	for(int i = 1;i<=n;i++){
		for(int j = 1;j <= m;j++){
			int minimo = vaiate[i][j];
			for(int k = j;k <= m;k++){
				if(matriz[i][k] != matriz[i][j]) break;
				minimo = min(minimo,vaiate[i][k]);
				resp += 1LL*minimo;
			}
		}
	}
	printf("%lld\n",resp);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 5164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 6388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 7748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 8948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 19460 KB Output is correct
2 Correct 658 ms 21516 KB Output is correct
3 Correct 642 ms 23472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 33156 KB Output is correct
2 Correct 296 ms 35200 KB Output is correct
3 Correct 737 ms 37164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 164 ms 46856 KB Output is correct
2 Correct 592 ms 48812 KB Output is correct
3 Correct 590 ms 50780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 134 ms 60412 KB Output is correct
2 Correct 629 ms 62412 KB Output is correct
3 Correct 660 ms 64372 KB Output is correct