/*input
4 4
JJOO
JJOO
IIJO
IIIJ
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
out<<'('<<P.F<<','<<P.S<<')';
return out;
}
#define version 20190713
//}}}
const ll maxn=3005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;
ll mypow(ll a,ll b){
ll res=1LL;
while(b){
if(b&1) res=res*a%MOD;
a=a*a%MOD;
b>>=1;
}
return res;
}
string s[maxn];
int r[maxn][maxn];
int c[maxn][maxn];
int main(){
IOS;
int n,m;
cin>>n>>m;
REP(i,n) cin>>s[i];
for(int j=m-1;j>=0;j--) REP(i,n){
if(j==m-1) r[i][j]=(s[i][j]=='O');
else r[i][j]=r[i][j+1]+(s[i][j]=='O');
}
for(int i=n-1;i>=0;i--) REP(j,m){
if(i==n-1) c[i][j]=(s[i][j]=='I');
else c[i][j]=c[i+1][j]+(s[i][j]=='I');
}
ll ans=0;
REP(i,n) REP(j,m) if(s[i][j]=='J'){
ans+=r[i][j]*c[i][j];
}
cout<<ans<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
1272 KB |
Output is correct |
6 |
Correct |
3 ms |
1400 KB |
Output is correct |
7 |
Correct |
2 ms |
1272 KB |
Output is correct |
8 |
Correct |
3 ms |
1400 KB |
Output is correct |
9 |
Correct |
3 ms |
1272 KB |
Output is correct |
10 |
Correct |
3 ms |
1272 KB |
Output is correct |
11 |
Correct |
3 ms |
1400 KB |
Output is correct |
12 |
Correct |
3 ms |
1400 KB |
Output is correct |
13 |
Correct |
3 ms |
1276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
1272 KB |
Output is correct |
6 |
Correct |
3 ms |
1400 KB |
Output is correct |
7 |
Correct |
2 ms |
1272 KB |
Output is correct |
8 |
Correct |
3 ms |
1400 KB |
Output is correct |
9 |
Correct |
3 ms |
1272 KB |
Output is correct |
10 |
Correct |
3 ms |
1272 KB |
Output is correct |
11 |
Correct |
3 ms |
1400 KB |
Output is correct |
12 |
Correct |
3 ms |
1400 KB |
Output is correct |
13 |
Correct |
3 ms |
1276 KB |
Output is correct |
14 |
Correct |
10 ms |
6392 KB |
Output is correct |
15 |
Correct |
5 ms |
3832 KB |
Output is correct |
16 |
Correct |
6 ms |
3832 KB |
Output is correct |
17 |
Correct |
2 ms |
504 KB |
Output is correct |
18 |
Correct |
11 ms |
6904 KB |
Output is correct |
19 |
Correct |
10 ms |
6776 KB |
Output is correct |
20 |
Correct |
9 ms |
6776 KB |
Output is correct |
21 |
Correct |
10 ms |
6904 KB |
Output is correct |
22 |
Correct |
9 ms |
6776 KB |
Output is correct |
23 |
Correct |
8 ms |
6776 KB |
Output is correct |
24 |
Correct |
10 ms |
6904 KB |
Output is correct |
25 |
Correct |
9 ms |
6776 KB |
Output is correct |
26 |
Correct |
9 ms |
6776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
1272 KB |
Output is correct |
6 |
Correct |
3 ms |
1400 KB |
Output is correct |
7 |
Correct |
2 ms |
1272 KB |
Output is correct |
8 |
Correct |
3 ms |
1400 KB |
Output is correct |
9 |
Correct |
3 ms |
1272 KB |
Output is correct |
10 |
Correct |
3 ms |
1272 KB |
Output is correct |
11 |
Correct |
3 ms |
1400 KB |
Output is correct |
12 |
Correct |
3 ms |
1400 KB |
Output is correct |
13 |
Correct |
3 ms |
1276 KB |
Output is correct |
14 |
Correct |
10 ms |
6392 KB |
Output is correct |
15 |
Correct |
5 ms |
3832 KB |
Output is correct |
16 |
Correct |
6 ms |
3832 KB |
Output is correct |
17 |
Correct |
2 ms |
504 KB |
Output is correct |
18 |
Correct |
11 ms |
6904 KB |
Output is correct |
19 |
Correct |
10 ms |
6776 KB |
Output is correct |
20 |
Correct |
9 ms |
6776 KB |
Output is correct |
21 |
Correct |
10 ms |
6904 KB |
Output is correct |
22 |
Correct |
9 ms |
6776 KB |
Output is correct |
23 |
Correct |
8 ms |
6776 KB |
Output is correct |
24 |
Correct |
10 ms |
6904 KB |
Output is correct |
25 |
Correct |
9 ms |
6776 KB |
Output is correct |
26 |
Correct |
9 ms |
6776 KB |
Output is correct |
27 |
Correct |
353 ms |
88456 KB |
Output is correct |
28 |
Correct |
25 ms |
19320 KB |
Output is correct |
29 |
Correct |
13 ms |
7800 KB |
Output is correct |
30 |
Correct |
2 ms |
760 KB |
Output is correct |
31 |
Correct |
255 ms |
72108 KB |
Output is correct |
32 |
Correct |
328 ms |
89408 KB |
Output is correct |
33 |
Correct |
350 ms |
89208 KB |
Output is correct |
34 |
Correct |
290 ms |
83400 KB |
Output is correct |
35 |
Correct |
317 ms |
89324 KB |
Output is correct |
36 |
Correct |
339 ms |
89440 KB |
Output is correct |
37 |
Correct |
354 ms |
89464 KB |
Output is correct |
38 |
Correct |
207 ms |
72056 KB |
Output is correct |
39 |
Correct |
209 ms |
71928 KB |
Output is correct |