Submission #857703

#TimeUsernameProblemLanguageResultExecution timeMemory
857703serifefedartarStrah (COCI18_strah)C++17
0 / 110
1047 ms23196 KiB
#include <bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(0);cin.tie(0); #define s second #define f first typedef long long ll; const ll MOD = 1e9 + 7; const ll LOGN = 18; const ll INF = 1e15; const ll MAXN = 2005; vector<int> occ[MAXN]; int N, M; int emp[MAXN][MAXN]; ll total = 0, ans = 0; set<pair<ll,ll>> st; ll calc(ll x) { return (x * x * x + 3 * x * x + 2 * x) / 6; } void split(int pos) { pair<ll,ll> Q = *(prev(st.upper_bound(make_pair(pos, 0)))); ans += calc(pos - Q.f) + calc(Q.f + Q.s - 1 - pos) - calc(Q.s); st.erase(Q); if (pos - Q.f > 0) st.insert({Q.f, pos - Q.f}); if (Q.f + Q.s - 1 - pos > 0) st.insert({pos + 1, Q.f + Q.s - 1 - pos}); } string s; int main() { fast cin >> N >> M; for (int i = 1; i <= N; i++) { cin >> s; for (int j = M; j >= 1; j--) { if (s[j-1] == '.') emp[i][j] = emp[i][j+1] + 1; } } for (int j = 1; j <= M; j++) { st.clear(); st.insert({1, N}); ans = calc(N); for (int i = 1; i <= N; i++) occ[emp[i][j]].push_back(i); for (ll q = 0; q <= 2000; q++) { total += ans * q; while (occ[q].size()) { split(occ[q].back()); occ[q].pop_back(); } } } cout << total << "\n"; }
#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...