# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
81641 | IvanC | Strah (COCI18_strah) | C++17 | 121 ms | 752 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
const int MAXN = 2010;
char entrada[MAXN];
int tamanho[MAXN],esq[MAXN],dir[MAXN],N,M;
ii vetor[MAXN];
ll tot_area;
ll somatorio(ll x){
return (x*(x+1))/2;
}
ll soma_especial(ll x){
return somatorio(x) - x;
}
ll calculate_area(){
//printf("##########\n");
ll resp = 0;
stack<int> pilha;
vetor[0] = ii(-1,0);
pilha.push(0);
for(int i = 1;i<=M;i++){
vetor[i] = ii(tamanho[i],i);
while(!pilha.empty() && vetor[pilha.top()] > vetor[i]){
dir[pilha.top()] = i;
pilha.pop();
}
esq[i] = pilha.top();
pilha.push(i);
}
while(!pilha.empty()){
dir[pilha.top()] = M+1;
pilha.pop();
}
for(int i = 1;i<=M;i++){
esq[i]++;
dir[i]--;
//printf("I %d %d %d %lld\n",i,(i - esq[i] + 1),(dir[i] - i + 1),somatorio(tamanho[i]));
int a = i - esq[i] + 1;
int b = dir[i] - i + 1;
resp += 1LL*(b*somatorio(a) + a*soma_especial(b))*somatorio(tamanho[i]);
}
//printf("#########\n");
return resp;
}
int main(){
scanf("%d %d",&N,&M);
for(int linha = 0;linha<N;linha++){
scanf("%s",entrada);
for(int i = 0;i<M;i++){
if(entrada[i] == '.'){
tamanho[i+1]++;
}
else{
tamanho[i+1] = 0;
}
}
//for(int i = 1;i<=M;i++) printf("%d ",tamanho[i]);
//printf("\n");
tot_area += calculate_area();
}
printf("%lld\n",tot_area);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |