This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define F first
#define S second
#define LL long long
#define rep(i, x) for(auto &i : (x))
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define left(x) ((x)<<1)
#define right(x) ((x)>>1)
#define LSOne(x) (x & -(x))
using namespace std;
using T = pair<pair<int, int>, int>;
const int SZ = 2e5 + 1;
const LL MOD = 1e9 + 7;
const LL INF = 1e18 + 1;
LL bp (LL b, LL e, LL m = MOD) {
if ( e == 0 ) return 1;
LL T = bp(b, e / 2);
T *= T; T %= m;
if ( e & 1 ) T *= b;
return T %= m;
}
LL nv_i (LL a) { return bp(a, MOD - 2); };
LL gcd (LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); }
LL lcm(LL a, LL b) { return (a * (b / gcd(a, b))); }
LL ceil (LL a, LL b) { return ((a + b - 1) / b); }
void solve() {
int n, m;
cin >> n >> m;
vector<int> I_1, J_1, I_2, J_2;
vector<bool> CI_1(n + 1), CJ_1(m + 1), CI_2(n + 1), CJ_2(m + 1);
vector<vector<char>> MC(n + 1, vector<char> (m + 1));
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= m; j ++) {
char x;
cin >> x;
MC[i][j] = x;
if(x == 'J') {
if(!CI_1[i]) {
I_1.push_back(i);
CI_1[i] = 1;
}
if(!CJ_1[j]) {
J_1.push_back(j);
CJ_1[j] = 1;
}
}
if(x == 'O') {
if(!CJ_2[j]) {
J_2.push_back(j);
CJ_2[j] = 1;
}
}
if(x == 'I') {
if(!CI_2[i]) {
I_2.push_back(i);
CI_2[i] = 1;
}
}
}
}
int cnt = 0;
rep(i_1, I_1) {
rep(j_1, J_1) {
rep(i_2, I_2) {
rep(j_2, J_2) {
if(i_1 > i_2 || j_1 > j_2) continue;
if(MC[i_1][j_1] == 'J' && MC[i_1][j_2] == 'O' && MC[i_2][j_1] == 'I') {
cnt ++;
}
}
}
}
}
cout << cnt;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |