Submission #460775

# Submission time Handle Problem Language Result Execution time Memory
460775 2021-08-09T09:32:28 Z grt Strah (COCI18_strah) C++17
110 / 110
192 ms 23892 KB
#include <bits/stdc++.h>
#define PB push_back
#define ST first
#define ND second
#define _ ios_base::sync_with_stdio(0); cin.tie(0);
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

using namespace std;

using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;

const int nax = 2010;
int n, m;
char t[nax][nax];
int up[nax][nax];

int main() {_
	cin >> n >> m;
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			cin >> t[i][j];
			if(t[i][j] == '.') up[i][j] = up[i - 1][j] + 1;
			else up[i][j] = 0;
		}
	}
	ll ans = 0;
	for(int i = 1; i <= n; ++i) {
		vector<pi> S = {{-1, 0}};
		for(int j = 1; j <= m; ++j) {
			while((int)S.size() > 0 && S.back().ST >= up[i][j]) {
				S.pop_back();
			}
			S.emplace_back(up[i][j], j);
			//cout << i << " " << j << ": ";
			//for(auto x : S) {
				//cout << x.ST << " " << x.ND << ", ";
			//}
			//cout << "\n";
			for(int k = (int)S.size() - 1; k > 0; --k) {
				int x = j - S[k].ND + 1;
				int y = j - S[k - 1].ND;
				ans += 1LL * (S[k].ST * (S[k].ST + 1)) / 2 * ((x + y) * (y - x + 1) / 2);
			}
		}
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2508 KB Output is correct
2 Correct 5 ms 2508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2508 KB Output is correct
2 Correct 5 ms 2508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2508 KB Output is correct
2 Correct 5 ms 2508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 9576 KB Output is correct
2 Correct 125 ms 17436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 15744 KB Output is correct
2 Correct 152 ms 22944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 10208 KB Output is correct
2 Correct 109 ms 18768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 12492 KB Output is correct
2 Correct 138 ms 21640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 192 ms 23892 KB Output is correct
2 Correct 166 ms 23892 KB Output is correct