# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
197062 | quocnguyen1012 | Strah (COCI18_strah) | C++14 | 161 ms | 4316 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 fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
const int maxn = 2005;
int N, M;
string str;
int L[maxn], R[maxn], h[maxn];
ll sumto(int x)
{
return 1ll * x * (x + 1) / 2;
}
signed main(void)
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen("A.INP", "r")){
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
}
cin >> N >> M;
ll res = 0;
for (int i = 1; i <= N; ++i){
cin >> str; str = " " + str;
for (int j = 1; j <= M; ++j){
if (str[j] == '.') h[j]++;
else h[j] = 0;
}
vector<int> st;
for (int j = 1; j <= M; ++j){
while (st.size() && h[st.back()] >= h[j]) st.pop_back();
if (st.empty()) L[j] = 0;
else L[j] = st.back();
st.pb(j);
}
st.clear();
for (int j = M; j >= 1; --j){
while (st.size() && h[st.back()] > h[j]) st.pop_back();
if (st.empty()) R[j] = M + 1;
else R[j] = st.back();
st.pb(j);
}
for (int j = 1; j <= M; ++j){
int r = R[j] - j;
int l = j - L[j];
int tmp = r * sumto(l) + l * sumto(r) - 1ll * l * r;
res += sumto(h[j]) * tmp;
//cerr << i << ' ' << j << ' ' << sumto(h[j]) * tmp << '\n';
}
}
cout << res;
}
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... |