답안 #464695

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
464695 2021-08-13T17:11:45 Z Hamed5001 Strah (COCI18_strah) C++14
88 / 110
1000 ms 98824 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

/*
	dp[i][j] = potential value in range (i, j) -> (N, M);
	dp[i][j] = dp[i+1][j] + dp[i][j+1] - dp[i+1][j+1] + (sum())
*/

const int mxN = 2e3+10;
ll N, M;
char land[mxN][mxN]; 
ll cum[mxN][mxN], nxt[mxN][mxN];


ll calc(int i, int j) {
	ll ret = 0;
	if (land[i][j] == '#')
		return ret;
	ll pos = M+1;
	for (ll ii = i; ii <= N && land[ii][j] != '#'; ii++) {
		pos = min(pos, nxt[ii][j]);
		ll len = pos - j;
		ret += (len*(len+1)/2) * (ii-i+1);
	}

	return ret;
}

void solve() {
	scanf("%lld%lld", &N, &M);
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			scanf(" %c", &land[i][j]);
			cum[i][j] = ((land[i][j] == '#') + cum[i-1][j] + cum[i][j-1] - cum[i-1][j-1]);
		}
	}

	for (int i = 1; i <= N; i++) {
		int lst = M+1;
		for (int j = M; j; j--) {
			if (land[i][j] == '#')
				lst = j;
			nxt[i][j] = lst;
		}
	}



	vector<vector<ll>> dp(mxN, vector<ll>(mxN, 0));
	dp[N][M] = (land[N][M] != '#');

	for (int i = N; i; i--) {
		for (int j = M; j; j--) {
			dp[i][j] = dp[i+1][j] + dp[i][j+1] - dp[i+1][j+1] + calc(i, j);
		}
	}


	printf("%lld", dp[1][1]);
}

int main() {
	solve();
}

Compilation message

strah.cpp: In function 'void solve()':
strah.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |  scanf("%lld%lld", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~
strah.cpp:35:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |    scanf(" %c", &land[i][j]);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 32076 KB Output is correct
2 Correct 15 ms 32076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 32080 KB Output is correct
2 Correct 14 ms 32084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 36400 KB Output is correct
2 Correct 28 ms 36324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 36428 KB Output is correct
2 Correct 28 ms 36436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 36416 KB Output is correct
2 Correct 33 ms 36296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 131 ms 56724 KB Output is correct
2 Correct 382 ms 82620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 242 ms 76352 KB Output is correct
2 Correct 578 ms 96768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 702 ms 60496 KB Output is correct
2 Correct 423 ms 85796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 54272 KB Output is correct
2 Execution timed out 1084 ms 94712 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1086 ms 98824 KB Time limit exceeded
2 Halted 0 ms 0 KB -