Submission #554641

#TimeUsernameProblemLanguageResultExecution timeMemory
554641Yazan_AlattarStrah (COCI18_strah)C++14
110 / 110
150 ms39704 KiB
#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 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...