#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vc> vvc;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (ll i = a; i < (b); i++)
#define F0R(i, a) for (ll i = 0; i < (a); i++)
#define FORd(i, a, b) for (ll i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (ll i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define len(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fst first
#define nl endl
#define sec second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ins insert
#define endl "\n"
const int MOD = 1000000007;
const int MX = INT_MAX;
const int MN = INT_MIN;
void init()
{
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
#endif
}
void fastIO()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
}
void solve()
{
ll h,w;cin>>h>>w;
vvc arr (h,vc(w));
vvi o_counter (h,vi(w+1,0));
vvi i_counter (h+1,vi(w,0));
FOR(i,0,h)FOR(j,0,w)cin>>arr[i][j];
FOR(i,0,h){
int sum=0;
FOR(j,0,w){
if(arr[i][j]=='O')sum++;
o_counter[i][j]=sum;
}o_counter[i][w]=sum;
}
FOR(i,0,w){
int sum=0;
FOR(j,0,h){
if(arr[j][i]=='I')sum++;
i_counter[j][i]=sum;
}i_counter[h][i]=sum;
}
// FOR(i,0,h){FOR(j,0,w){cout<<arr[i][j];}cout << endl;}
// cout<<endl;
// FOR(i,0,h){FOR(j,0,w+1){cout<<o_counter[i][j]<<" ";}cout << endl;}
// cout<<endl;
// FOR(i,0,h+1){FOR(j,0,w){cout<<i_counter[i][j]<<" ";}cout << endl;}
// cout<<endl;
ll ans=0;
FOR(i,0,h){
FOR(j,0,w){
if(arr[i][j]=='J'){
ans += (o_counter[i][w]-o_counter[i][j])*
(i_counter[h][j]-i_counter[i][j]);
}
}
}
cout << ans << endl;
}
int main()
{
fastIO();
// init();
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
Compilation message
joi2019_ho_t1.cpp: In function 'void init()':
joi2019_ho_t1.cpp:43:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | freopen("input.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t1.cpp:44:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | freopen("output.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
4 ms |
2132 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
1620 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
5 ms |
2764 KB |
Output is correct |
19 |
Correct |
4 ms |
2644 KB |
Output is correct |
20 |
Correct |
4 ms |
2644 KB |
Output is correct |
21 |
Correct |
5 ms |
2772 KB |
Output is correct |
22 |
Correct |
4 ms |
2632 KB |
Output is correct |
23 |
Correct |
4 ms |
2760 KB |
Output is correct |
24 |
Correct |
5 ms |
2772 KB |
Output is correct |
25 |
Correct |
5 ms |
2612 KB |
Output is correct |
26 |
Correct |
5 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
4 ms |
2132 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
1620 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
5 ms |
2764 KB |
Output is correct |
19 |
Correct |
4 ms |
2644 KB |
Output is correct |
20 |
Correct |
4 ms |
2644 KB |
Output is correct |
21 |
Correct |
5 ms |
2772 KB |
Output is correct |
22 |
Correct |
4 ms |
2632 KB |
Output is correct |
23 |
Correct |
4 ms |
2760 KB |
Output is correct |
24 |
Correct |
5 ms |
2772 KB |
Output is correct |
25 |
Correct |
5 ms |
2612 KB |
Output is correct |
26 |
Correct |
5 ms |
2644 KB |
Output is correct |
27 |
Correct |
259 ms |
83820 KB |
Output is correct |
28 |
Correct |
1 ms |
844 KB |
Output is correct |
29 |
Correct |
14 ms |
6708 KB |
Output is correct |
30 |
Correct |
1 ms |
464 KB |
Output is correct |
31 |
Correct |
188 ms |
61648 KB |
Output is correct |
32 |
Correct |
251 ms |
88152 KB |
Output is correct |
33 |
Correct |
251 ms |
88428 KB |
Output is correct |
34 |
Correct |
220 ms |
71604 KB |
Output is correct |
35 |
Correct |
251 ms |
88144 KB |
Output is correct |
36 |
Correct |
254 ms |
88304 KB |
Output is correct |
37 |
Correct |
288 ms |
88784 KB |
Output is correct |
38 |
Correct |
163 ms |
61228 KB |
Output is correct |
39 |
Correct |
163 ms |
61516 KB |
Output is correct |