#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll int
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 4000
#define INF 1e9+7
using namespace std;
ll n,m;
long long ans;
ll orbs[N][N],jewels[N][N],ignots[N][N];
ll sumo[N][N],sumi[N][N];
char c;
ll get_orbs(ll si,ll sj,ll ei,ll ej)
{
if(si == 0 && sj == 0)
return sumo[ei][ej];
else if(si == 0)
return sumo[ei][ej] - sumo[ei][sj-1];
else if(sj == 0)
return sumo[ei][ej] - sumo[si-1][ej];
return sumo[ei][ej] - sumo[si-1][ej] - sumo[ei][sj-1] + sumo[si-1][sj-1];
}
ll get_ignots(ll si,ll sj,ll ei,ll ej)
{
if(si == 0 && sj == 0)
return sumi[ei][ej];
else if(si == 0)
return sumi[ei][ej] - sumi[ei][sj-1];
else if(sj == 0)
return sumi[ei][ej] - sumi[si-1][ej];
return sumi[ei][ej] - sumi[si-1][ej] - sumi[ei][sj-1] + sumi[si-1][sj-1];
}
int main()
{
ios_base::sync_with_stdio(false);
cin >> n >> m;
rep(i,0,n)
{
rep(j,0,m)
{
cin >> c;
if(c == 'J')
jewels[i][j] = 1;
else if(c == 'O')
orbs[i][j] = 1;
else
ignots[i][j] = 1;
}
}
rep(i,0,n)
{
rep(j,0,m)
{
if(i == 0 && j == 0)
{
sumi[i][j] = ignots[i][j];
sumo[i][j] = orbs[i][j];
}
else if(i == 0)
{
sumi[i][j] = sumi[i][j-1]+ignots[i][j];
sumo[i][j] = sumo[i][j-1]+orbs[i][j];
}
else if(j == 0)
{
sumi[i][j] = sumi[i-1][j]+ignots[i][j];
sumo[i][j] = sumo[i-1][j]+orbs[i][j];
}
else
{
sumi[i][j] = sumi[i-1][j] - sumi[i-1][j-1] + sumi[i][j-1]+ ignots[i][j];
sumo[i][j] = sumo[i-1][j] - sumo[i-1][j-1] + sumo[i][j-1] + orbs[i][j];
}
}
}
rep(i,0,n)
{
rep(j,0,m)
{
if(i != n-1 && j != m-1 && jewels[i][j])
{
ans = (ans + get_ignots(i,j,n-1,j)*1LL*get_orbs(i,j,i,m-1));
}
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
4 ms |
2560 KB |
Output is correct |
6 |
Correct |
4 ms |
2404 KB |
Output is correct |
7 |
Correct |
3 ms |
2048 KB |
Output is correct |
8 |
Correct |
4 ms |
2560 KB |
Output is correct |
9 |
Correct |
3 ms |
2432 KB |
Output is correct |
10 |
Correct |
4 ms |
2048 KB |
Output is correct |
11 |
Correct |
4 ms |
2560 KB |
Output is correct |
12 |
Correct |
4 ms |
2432 KB |
Output is correct |
13 |
Correct |
3 ms |
2176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
4 ms |
2560 KB |
Output is correct |
6 |
Correct |
4 ms |
2404 KB |
Output is correct |
7 |
Correct |
3 ms |
2048 KB |
Output is correct |
8 |
Correct |
4 ms |
2560 KB |
Output is correct |
9 |
Correct |
3 ms |
2432 KB |
Output is correct |
10 |
Correct |
4 ms |
2048 KB |
Output is correct |
11 |
Correct |
4 ms |
2560 KB |
Output is correct |
12 |
Correct |
4 ms |
2432 KB |
Output is correct |
13 |
Correct |
3 ms |
2176 KB |
Output is correct |
14 |
Correct |
19 ms |
14208 KB |
Output is correct |
15 |
Correct |
7 ms |
7680 KB |
Output is correct |
16 |
Correct |
10 ms |
7424 KB |
Output is correct |
17 |
Correct |
2 ms |
640 KB |
Output is correct |
18 |
Correct |
22 ms |
15496 KB |
Output is correct |
19 |
Correct |
18 ms |
14208 KB |
Output is correct |
20 |
Correct |
17 ms |
12160 KB |
Output is correct |
21 |
Correct |
20 ms |
15352 KB |
Output is correct |
22 |
Correct |
17 ms |
14208 KB |
Output is correct |
23 |
Correct |
16 ms |
12160 KB |
Output is correct |
24 |
Correct |
23 ms |
15488 KB |
Output is correct |
25 |
Correct |
17 ms |
14208 KB |
Output is correct |
26 |
Correct |
17 ms |
12160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
4 ms |
2560 KB |
Output is correct |
6 |
Correct |
4 ms |
2404 KB |
Output is correct |
7 |
Correct |
3 ms |
2048 KB |
Output is correct |
8 |
Correct |
4 ms |
2560 KB |
Output is correct |
9 |
Correct |
3 ms |
2432 KB |
Output is correct |
10 |
Correct |
4 ms |
2048 KB |
Output is correct |
11 |
Correct |
4 ms |
2560 KB |
Output is correct |
12 |
Correct |
4 ms |
2432 KB |
Output is correct |
13 |
Correct |
3 ms |
2176 KB |
Output is correct |
14 |
Correct |
19 ms |
14208 KB |
Output is correct |
15 |
Correct |
7 ms |
7680 KB |
Output is correct |
16 |
Correct |
10 ms |
7424 KB |
Output is correct |
17 |
Correct |
2 ms |
640 KB |
Output is correct |
18 |
Correct |
22 ms |
15496 KB |
Output is correct |
19 |
Correct |
18 ms |
14208 KB |
Output is correct |
20 |
Correct |
17 ms |
12160 KB |
Output is correct |
21 |
Correct |
20 ms |
15352 KB |
Output is correct |
22 |
Correct |
17 ms |
14208 KB |
Output is correct |
23 |
Correct |
16 ms |
12160 KB |
Output is correct |
24 |
Correct |
23 ms |
15488 KB |
Output is correct |
25 |
Correct |
17 ms |
14208 KB |
Output is correct |
26 |
Correct |
17 ms |
12160 KB |
Output is correct |
27 |
Correct |
460 ms |
235332 KB |
Output is correct |
28 |
Correct |
32 ms |
40824 KB |
Output is correct |
29 |
Correct |
25 ms |
14080 KB |
Output is correct |
30 |
Correct |
4 ms |
1024 KB |
Output is correct |
31 |
Correct |
332 ms |
178780 KB |
Output is correct |
32 |
Correct |
351 ms |
209116 KB |
Output is correct |
33 |
Correct |
317 ms |
168056 KB |
Output is correct |
34 |
Correct |
429 ms |
207224 KB |
Output is correct |
35 |
Correct |
395 ms |
209272 KB |
Output is correct |
36 |
Correct |
317 ms |
168184 KB |
Output is correct |
37 |
Correct |
481 ms |
244088 KB |
Output is correct |
38 |
Correct |
243 ms |
152824 KB |
Output is correct |
39 |
Correct |
221 ms |
124536 KB |
Output is correct |