답안 #199520

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199520 2020-02-01T18:53:51 Z ZwariowanyMarcin Strah (COCI18_strah) C++14
55 / 110
177 ms 24024 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ss(x) (int) x.size()
#define pb push_back
#define LL long long
#define LD long double
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, j, n) for(int i = j; i <= n; ++i)
#define boost cin.tie(0), ios_base::sync_with_stdio(0);


using namespace std;			
	
const int nax = 2011;

int n, m;
char s[nax][nax];	

int up[nax][nax];

LL ans;

LL tyt[nax];

LL f(int x) {
	return (LL) x * (x + 1) / 2;
}

int L[nax];
int R[nax];

vector <int> v;

int main() {	
	scanf ("%d %d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		scanf ("%s", s[i] + 1);
		for (int j = 1; j <= m; ++j) {
			if (s[i][j] == '#') up[i][j] = 0;
			else up[i][j] = up[i - 1][j] + 1;	
		}	
	}
	
	for (int i = 1; i <= n; ++i) {
		LL res = 0;
		for (int j = 1; j <= i; ++j)
			res += j * (i - j + 1);
		tyt[i] = res;
	}
	
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m + 1; ++j) {
			while (ss(v) && up[i][v.back()] > up[i][j]) {
				R[v.back()] = j - 1;
				v.pop_back();
			}
			if (j != m + 1) v.pb(j);
		}
		
		for (int j = m; 0 <= j; --j) {
			while (ss(v) && up[i][v.back()] >= up[i][j]) {
				L[v.back()] = j + 1;
				v.pop_back();
			}
			if (j != 0) v.pb(j);
		}
		
		for (int j = 1; j <= m; ++j) {
			if (!up[i][j]) continue;
			int h = max(up[i][L[j] - 1], up[i][R[j] + 1]);
			int gao = (LL) (f(up[i][j]) - f(h)) * tyt[R[j] - L[j] + 1];
			ans += gao;
		}
	}
	printf ("%lld", ans);
		
	
	return 0;
}

Compilation message

strah.cpp: In function 'int main()':
strah.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d %d", &n, &m);
  ~~~~~~^~~~~~~~~~~~~~~~~
strah.cpp:39:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%s", s[i] + 1);
   ~~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Incorrect 5 ms 376 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 2536 KB Output is correct
2 Correct 11 ms 2556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 2552 KB Output is correct
2 Correct 10 ms 2552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 2552 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 9720 KB Output is correct
2 Correct 117 ms 17656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 15864 KB Output is correct
2 Correct 177 ms 23032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 74 ms 10588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 12536 KB Output is correct
2 Correct 127 ms 21888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 163 ms 24024 KB Output isn't correct
2 Halted 0 ms 0 KB -