# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
167666 | rzbt | Strah (COCI18_strah) | C++14 | 189 ms | 129960 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>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define MAXN 2005
typedef long long ll;
using namespace std;
ll n,m;
ll iznad[MAXN][MAXN],mat[MAXN][MAXN],res[MAXN][MAXN],zbirvis[MAXN][MAXN];
char ss[MAXN];
stack<pair<ll,ll> > s;
ll sol;
int main()
{
scanf("%lld %lld", &n, &m);
for(ll i=1;i<=n;i++){
scanf("%s",ss);
for(ll j=1;j<=m;j++)mat[i][j]=(ss[j-1]=='#'?0:1);
}
for(ll i=1;i<=n;i++){
for(ll j=1;j<=m;j++){
iznad[i][j]=mat[i][j]*(iznad[i-1][j]+1);
//printf("lol");
}
}
for(ll i=1;i<=n;i++){
while(!s.empty()){s.pop();}
s.push(mp(-1,0));
ll tz=1;
for(ll j=1;j<=m;j++){
ll kolko=1;
while(!s.empty() && s.top().first>=iznad[i][j]){
kolko+=s.top().second;
tz-=s.top().first*s.top().second;
s.pop();
}
ll prosli=j-kolko;
res[i][j]=(kolko*(kolko+1)*iznad[i][j]*(iznad[i][j]+1))/4 + zbirvis[i][prosli]*kolko+res[i][prosli];
zbirvis[i][j]=zbirvis[i][prosli]+kolko*iznad[i][j]*(iznad[i][j]+1)/2;
s.push(mp(iznad[i][j],kolko));
sol+=res[i][j];
}
}
printf("%lld",sol);
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... |