Submission #474418

#TimeUsernameProblemLanguageResultExecution timeMemory
474418Killer2501Strah (COCI18_strah)C++14
110 / 110
164 ms35664 KiB
#include <bits/stdc++.h> #define ll long long #define pll pair<ll, ll> #define pii pair<ll, pll> #define pb push_back #define fi first #define se second using namespace std; const int N = 2e3+5; const ll mod = 1e9 + 7; const int base = 40; ll n, m, k, t, a[N][N], b[N], tong, dp[N], lab[N], st[N*4], lazy[N*4], ans; char c; vector<ll> adj[N], kq; pll p[N]; ll pw(ll k, ll n) { ll total = 1; for(; n; n >>= 1) { if(n & 1)total = total * k % mod; k = k * k % mod; } return total; } ll findp(ll u) { return lab[u] < 0 ? u : lab[u] = findp(lab[u]); } void hop(ll u, ll v) { if(lab[u] > lab[v])swap(u, v); lab[u] += lab[v]; lab[v] = u; } void sol() { cin >> n >> m; for(int i = 1; i <= n; i ++) { tong = 0; k = 0; kq.clear(); for(int j = 1; j <= m; j ++) { cin >> c; if(c == '.')a[i][j] = a[i-1][j] + 1; while(!kq.empty() && a[i][j] < a[i][kq.back()]) { ll r = kq.back(); kq.pop_back(); ll l = kq.empty() ? 0 : kq.back(); tong -= (r-l) * (r-1+l) / 2 * a[i][r] * (a[i][r] + 1) / 2; k -= (r-l) * a[i][r] * (a[i][r]+1)/2; } ll l = kq.empty() ? 0 : kq.back(); k += (j-l) * a[i][j] * (a[i][j] + 1) / 2; tong += (j-l) * (j-1+l) / 2 * a[i][j] * (a[i][j] + 1) / 2; ans += j * k - tong; kq.pb(j); //cout << j*k-tong <<" "; } //cout << '\n'; } cout << ans; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int test = 1; //cin >> test; while (test-- > 0) sol(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...