#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ii pair<int,int>
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int nax=2e3+5;
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
optimise;
int n,m;
cin>>n>>m;
char grid[n][m];
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
cin>>grid[i][j];
}
}
long long ans=0;
int xx[n][m];
int yy[n][m];
for (int i = 0; i < n; ++i)
{
int cur=0;
for (int j = m-1; j >= 0; --j)
{
if(grid[i][j]=='O') cur++;
xx[i][j]=cur;
}
}
for (int j = 0; j < m; ++j)
{
int cur=0;
for (int i = n-1; i >= 0; --i)
{
if(grid[i][j]=='I') cur++;
yy[i][j]=cur;
}
}
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
if(grid[i][j]=='J'){
ans+=yy[i][j]*xx[i][j];
}
}
}
cout <<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
456 KB |
Output is correct |
10 |
Correct |
0 ms |
460 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
456 KB |
Output is correct |
10 |
Correct |
0 ms |
460 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
4 ms |
2140 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
1628 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
5 ms |
2896 KB |
Output is correct |
19 |
Correct |
4 ms |
2772 KB |
Output is correct |
20 |
Correct |
4 ms |
2652 KB |
Output is correct |
21 |
Correct |
5 ms |
2652 KB |
Output is correct |
22 |
Correct |
3 ms |
2716 KB |
Output is correct |
23 |
Correct |
4 ms |
2764 KB |
Output is correct |
24 |
Correct |
5 ms |
2648 KB |
Output is correct |
25 |
Correct |
3 ms |
2652 KB |
Output is correct |
26 |
Correct |
4 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
456 KB |
Output is correct |
10 |
Correct |
0 ms |
460 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
4 ms |
2140 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
1628 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
5 ms |
2896 KB |
Output is correct |
19 |
Correct |
4 ms |
2772 KB |
Output is correct |
20 |
Correct |
4 ms |
2652 KB |
Output is correct |
21 |
Correct |
5 ms |
2652 KB |
Output is correct |
22 |
Correct |
3 ms |
2716 KB |
Output is correct |
23 |
Correct |
4 ms |
2764 KB |
Output is correct |
24 |
Correct |
5 ms |
2648 KB |
Output is correct |
25 |
Correct |
3 ms |
2652 KB |
Output is correct |
26 |
Correct |
4 ms |
2652 KB |
Output is correct |
27 |
Correct |
168 ms |
83484 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
10 ms |
6612 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
134 ms |
61436 KB |
Output is correct |
32 |
Correct |
148 ms |
87884 KB |
Output is correct |
33 |
Correct |
145 ms |
88148 KB |
Output is correct |
34 |
Correct |
132 ms |
71264 KB |
Output is correct |
35 |
Correct |
158 ms |
87768 KB |
Output is correct |
36 |
Correct |
158 ms |
88144 KB |
Output is correct |
37 |
Correct |
180 ms |
88340 KB |
Output is correct |
38 |
Correct |
100 ms |
61008 KB |
Output is correct |
39 |
Correct |
100 ms |
61268 KB |
Output is correct |