# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
305099 | phathnv | Strah (COCI18_strah) | C++11 | 123 ms | 70904 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 X first
#define Y second
#define taskname "Strah"
using namespace std;
typedef long long ll;
typedef pair <int, int> ii;
const int N = 2001;
int m, n;
char s[N][N];
int h[N];
ll sumS[N][N], sumH[N][N];
void readInput(){
scanf("%d %d", &m, &n);
for(int i = 1; i <= m; i++)
scanf("%s", s[i] + 1);
}
void solve(){
ll res = 0;
for(int i = 1; i <= m; i++){
for(int j = 1; j <= n; j++)
if (s[i][j] == '.')
h[j]++;
else
h[j] = 0;
stack <int> st;
st.push(0);
h[0] = -1;
for(int j = 1; j <= n; j++){
while (h[st.top()] >= h[j])
st.pop();
int w = j - st.top();
sumS[i][j] = sumS[i][st.top()] + sumH[i][st.top()] * w;
sumS[i][j] += (ll) h[j] * (h[j] + 1) * w * (w + 1) / 4;
sumH[i][j] = sumH[i][st.top()] + h[j] * (h[j] + 1) / 2 * w;
st.push(j);
res += sumS[i][j];
}
}
cout << res;
}
int main(){
//freopen(taskname".inp", "r", stdin);
//freopen(taskname".out", "w", stdout);
readInput();
solve();
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... |