#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, b) for(int i = 0; i < (int)b; i++)
#define FOR(i, a, b) for(int i = a; i < (int)b; i++)
#define dbg(v) cerr << "Line(" << __LINE__ << ") -> " << #v << " = " << (v) << endl;
#define debug(a, b) cerr << "[" << #a << ", " << #b << "] = [" << a << ", " << b << "]\n";
template<class T> inline void read(T& t){ cin >> t; }
template<class T, class... H> inline void read(T& t, H&... h){ cin >> t; read(h...); }
template<class T> inline void read(vector<T>& t){ for(auto&x : t) read(x); }
template<class T, class... H> inline void read(vector<T>& t, vector<H>&... h){ read(t); read(h...); }
template<class T> inline void wt(const T t) { cout << t; }
template<class T> inline void write(const T t) { cout << t << " "; }
template<class T> inline void print(const T t){ cout << t << "\n";}
template<class T, class... H> inline void wt(const T& t, const H&... h){ cout << t; wt(h...); }
template<class T, class... H> inline void print(const T& t, const H&... h){ cout << t; cout << " "; print(h...);}
#define all(x) x.begin(), x.end()
#define pb push_back
#define sz(a) (int)a.size()
const int MAX = 3030;
int pre[MAX][MAX][3];
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int n, m; read(n, m);
vector<vector<char>> v(n, vector<char>(m));
rep(i, n) rep(j, m){
read(v[i][j]);
pre[i + 1][j + 1][1] = pre[i + 1][j][1] + pre[i][j + 1][1] - pre[i][j][1] + (v[i][j] == 'O');
pre[i + 1][j + 1][2] = pre[i + 1][j][2] + pre[i][j + 1][2] - pre[i][j][2] + (v[i][j] == 'I');
}
int ans = 0;
rep(i, n) rep(j, m){
if(v[i][j] == 'J'){
ans += max(0LL, (pre[n][j + 1][2] - pre[n][j][2] - (pre[i + 1][j + 1][2] - pre[i + 1][j][2])) * (pre[i + 1][m][1] - pre[i][m][1] - (pre[i + 1][j + 1][1] - pre[i][j + 1][1])));
}
}
print(ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
848 KB |
Output is correct |
7 |
Correct |
1 ms |
852 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
1 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
852 KB |
Output is correct |
11 |
Correct |
1 ms |
980 KB |
Output is correct |
12 |
Correct |
1 ms |
852 KB |
Output is correct |
13 |
Correct |
1 ms |
848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
848 KB |
Output is correct |
7 |
Correct |
1 ms |
852 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
1 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
852 KB |
Output is correct |
11 |
Correct |
1 ms |
980 KB |
Output is correct |
12 |
Correct |
1 ms |
852 KB |
Output is correct |
13 |
Correct |
1 ms |
848 KB |
Output is correct |
14 |
Correct |
8 ms |
7252 KB |
Output is correct |
15 |
Correct |
2 ms |
2132 KB |
Output is correct |
16 |
Correct |
5 ms |
4692 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
12 ms |
8660 KB |
Output is correct |
19 |
Correct |
8 ms |
8404 KB |
Output is correct |
20 |
Correct |
10 ms |
8480 KB |
Output is correct |
21 |
Correct |
9 ms |
8656 KB |
Output is correct |
22 |
Correct |
11 ms |
8408 KB |
Output is correct |
23 |
Correct |
10 ms |
8532 KB |
Output is correct |
24 |
Correct |
9 ms |
8680 KB |
Output is correct |
25 |
Correct |
8 ms |
8404 KB |
Output is correct |
26 |
Correct |
8 ms |
8560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
848 KB |
Output is correct |
7 |
Correct |
1 ms |
852 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
1 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
852 KB |
Output is correct |
11 |
Correct |
1 ms |
980 KB |
Output is correct |
12 |
Correct |
1 ms |
852 KB |
Output is correct |
13 |
Correct |
1 ms |
848 KB |
Output is correct |
14 |
Correct |
8 ms |
7252 KB |
Output is correct |
15 |
Correct |
2 ms |
2132 KB |
Output is correct |
16 |
Correct |
5 ms |
4692 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
12 ms |
8660 KB |
Output is correct |
19 |
Correct |
8 ms |
8404 KB |
Output is correct |
20 |
Correct |
10 ms |
8480 KB |
Output is correct |
21 |
Correct |
9 ms |
8656 KB |
Output is correct |
22 |
Correct |
11 ms |
8408 KB |
Output is correct |
23 |
Correct |
10 ms |
8532 KB |
Output is correct |
24 |
Correct |
9 ms |
8680 KB |
Output is correct |
25 |
Correct |
8 ms |
8404 KB |
Output is correct |
26 |
Correct |
8 ms |
8560 KB |
Output is correct |
27 |
Correct |
275 ms |
228660 KB |
Output is correct |
28 |
Correct |
7 ms |
10580 KB |
Output is correct |
29 |
Correct |
20 ms |
17740 KB |
Output is correct |
30 |
Correct |
1 ms |
852 KB |
Output is correct |
31 |
Correct |
181 ms |
169432 KB |
Output is correct |
32 |
Correct |
247 ms |
231348 KB |
Output is correct |
33 |
Correct |
244 ms |
230700 KB |
Output is correct |
34 |
Correct |
208 ms |
196428 KB |
Output is correct |
35 |
Correct |
251 ms |
231284 KB |
Output is correct |
36 |
Correct |
242 ms |
230604 KB |
Output is correct |
37 |
Correct |
273 ms |
231628 KB |
Output is correct |
38 |
Correct |
180 ms |
168140 KB |
Output is correct |
39 |
Correct |
163 ms |
168712 KB |
Output is correct |