Submission #554641

# Submission time Handle Problem Language Result Execution time Memory
554641 2022-04-29T02:57:34 Z Yazan_Alattar Strah (COCI18_strah) C++14
110 / 110
150 ms 39704 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 2007;
const ll inf = 2e9;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const double eps = 1e-6;
const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
const int block = 320;

ll Add(ll x, ll y) { return x + y; }
ll Mul(ll x, ll y) { return x * y; }

vector < pair <ll,ll> > v;
ll n, m, len[M][M], ans;
char a[M][M];

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

ll rid(ll x){
    ll w = 0;
    while(v.size() && v.back().F >= x){
        ans = Add(ans, Mul( Add(Mul(v.back().S, get(w)), Mul(w, get(v.back().S))), get(v.back().F)));
        w += v.back().S;
        v.pop_back();
    }
    return w + 1;
}


int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) cin >> a[i][j];

    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
            if(a[i][j] == '.') len[i][j] = len[i - 1][j] + 1;

    for(int i = n; i; --i){
        for(int j = 1; j <= m; ++j){
            ll w = rid(len[i][j]);
            v.pb({len[i][j], w});
            ans = Add(ans, Mul(get(w), get(len[i][j])));
        }
        rid(0);
    }

    cout << ans << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2900 KB Output is correct
2 Correct 4 ms 2916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2900 KB Output is correct
2 Correct 5 ms 2900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2904 KB Output is correct
2 Correct 4 ms 2900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 14488 KB Output is correct
2 Correct 101 ms 29644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 26192 KB Output is correct
2 Correct 139 ms 38032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 16796 KB Output is correct
2 Correct 95 ms 31308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 13524 KB Output is correct
2 Correct 98 ms 36336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 39704 KB Output is correct
2 Correct 150 ms 39572 KB Output is correct