Submission #384684

# Submission time Handle Problem Language Result Execution time Memory
384684 2021-04-02T04:57:25 Z AdiZer0 Strah (COCI18_strah) C++17
110 / 110
358 ms 71276 KB
#include <bits/stdc++.h>

#define pb push_back
#define whole(x) x.begin(), x.end()
#define sz(x) (int)x.size()

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = (int)2005 + 7;
const int INF = (int)1e9 + 7;
const ll linf = (ll)1e18 + 1;
 
int n, m;
char a[N][N];
ll sumW[N][N], sumH[N][N], pref[N];

ll get(ll x) { 
    ll res = (x * (x + 1)) / 2;
    return res;
}

int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) { 
        for (int j = 1; j <= m; ++j) { 
            cin >> a[i][j];
        }
    }
    ll ans = 0;
    for (int i = 1; i <= n; ++i) { 
        for (int j = 1; j <= m; ++j) { 
            if (a[i][j] == '.') ++pref[j];
            else pref[j] = 0;
        }
        stack<int> st;
        for (int j = 1; j <= m; ++j) { 
            while (!st.empty() && pref[st.top()] >= pref[j]) st.pop();
            int pos = 0;
            if (!st.empty()) pos = st.top();
            int width = j - pos, height = pref[j];
            sumW[i][j] += sumW[i][pos] + sumH[i][pos] * 1ll * width;
            sumH[i][j] += sumH[i][pos] + get(height) * 1ll * width;
            sumW[i][j] += get(width) * 1ll * get(height);
            ans += sumW[i][j];
            st.push(j);
        }
    }
    cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4844 KB Output is correct
2 Correct 11 ms 4972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4844 KB Output is correct
2 Correct 11 ms 4844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 4844 KB Output is correct
2 Correct 11 ms 4844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 101 ms 26124 KB Output is correct
2 Correct 219 ms 53356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 225 ms 47360 KB Output is correct
2 Correct 332 ms 68800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 140 ms 30572 KB Output is correct
2 Correct 267 ms 56812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 23020 KB Output is correct
2 Correct 269 ms 66156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 350 ms 71276 KB Output is correct
2 Correct 358 ms 71276 KB Output is correct