답안 #208400

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
208400 2020-03-11T07:18:47 Z Siberian Bitaro the Brave (JOI19_ho_t1) C++14
100 / 100
438 ms 80504 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}

const int MAXN = 3010;
int n, m;
char table[MAXN][MAXN];

void read() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> table[i][j];
		}
	}
}

ll ans;

int dp[MAXN][MAXN][2];

void build() {
	for (int i = 0; i < n; i++) {
		dp[i][m - 1][0] = (int)(table[i][m - 1] == 'O');
		for (int j = m - 2; j >= 0; j--) {
			dp[i][j][0] = dp[i][j + 1][0] + (int)(table[i][j] == 'O');
		}
	}
	for (int j = 0; j < m; j++) {
		dp[n - 1][j][1] = table[n - 1][j] == 'I';
		for (int i = n - 2; i >= 0; i--) {
			dp[i][j][1] = dp[i + 1][j][1] + (int)(table[i][j] == 'I');
		}
	}

	/*cout << "dp = " << endl;
	for (int it = 0; it < 2; it++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				cout << dp[i][j][it] << " ";
			}
			cout << endl;
		}
		cout << endl;
	}*/
}

void calc() {
	ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (table[i][j] == 'J') {
				ans += dp[i][j][0] * dp[i][j][1];
			}
		}
	}
}

void run() {
	build();
	calc();
}

void write() {
	cout << ans << endl;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 1144 KB Output is correct
6 Correct 5 ms 1144 KB Output is correct
7 Correct 5 ms 1016 KB Output is correct
8 Correct 5 ms 1144 KB Output is correct
9 Correct 5 ms 1144 KB Output is correct
10 Correct 5 ms 1048 KB Output is correct
11 Correct 5 ms 1144 KB Output is correct
12 Correct 5 ms 1144 KB Output is correct
13 Correct 5 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 1144 KB Output is correct
6 Correct 5 ms 1144 KB Output is correct
7 Correct 5 ms 1016 KB Output is correct
8 Correct 5 ms 1144 KB Output is correct
9 Correct 5 ms 1144 KB Output is correct
10 Correct 5 ms 1048 KB Output is correct
11 Correct 5 ms 1144 KB Output is correct
12 Correct 5 ms 1144 KB Output is correct
13 Correct 5 ms 1016 KB Output is correct
14 Correct 12 ms 5496 KB Output is correct
15 Correct 6 ms 3320 KB Output is correct
16 Correct 9 ms 3324 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 14 ms 6008 KB Output is correct
19 Correct 12 ms 6008 KB Output is correct
20 Correct 13 ms 5880 KB Output is correct
21 Correct 14 ms 6008 KB Output is correct
22 Correct 13 ms 6008 KB Output is correct
23 Correct 12 ms 5880 KB Output is correct
24 Correct 14 ms 6028 KB Output is correct
25 Correct 13 ms 5880 KB Output is correct
26 Correct 12 ms 5880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 1144 KB Output is correct
6 Correct 5 ms 1144 KB Output is correct
7 Correct 5 ms 1016 KB Output is correct
8 Correct 5 ms 1144 KB Output is correct
9 Correct 5 ms 1144 KB Output is correct
10 Correct 5 ms 1048 KB Output is correct
11 Correct 5 ms 1144 KB Output is correct
12 Correct 5 ms 1144 KB Output is correct
13 Correct 5 ms 1016 KB Output is correct
14 Correct 12 ms 5496 KB Output is correct
15 Correct 6 ms 3320 KB Output is correct
16 Correct 9 ms 3324 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 14 ms 6008 KB Output is correct
19 Correct 12 ms 6008 KB Output is correct
20 Correct 13 ms 5880 KB Output is correct
21 Correct 14 ms 6008 KB Output is correct
22 Correct 13 ms 6008 KB Output is correct
23 Correct 12 ms 5880 KB Output is correct
24 Correct 14 ms 6028 KB Output is correct
25 Correct 13 ms 5880 KB Output is correct
26 Correct 12 ms 5880 KB Output is correct
27 Correct 413 ms 80504 KB Output is correct
28 Correct 13 ms 16760 KB Output is correct
29 Correct 22 ms 7672 KB Output is correct
30 Correct 5 ms 632 KB Output is correct
31 Correct 304 ms 67064 KB Output is correct
32 Correct 406 ms 80120 KB Output is correct
33 Correct 398 ms 79864 KB Output is correct
34 Correct 357 ms 77816 KB Output is correct
35 Correct 403 ms 80120 KB Output is correct
36 Correct 397 ms 79736 KB Output is correct
37 Correct 438 ms 79992 KB Output is correct
38 Correct 287 ms 66168 KB Output is correct
39 Correct 289 ms 66416 KB Output is correct