// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;
ll INF=LLONG_MAX;
int const mxn=3e3+3;
string s[mxn];
vi orb[mxn],ing[mxn];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
int h,w;
cin >> h >> w;
for(int i=0; i<h; i++)cin >> s[i];
vector<ii>J;
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
if(s[i][j]=='J')J.pb(ii(i,j));
else if(s[i][j]=='O')orb[i].pb(j);
else ing[j].pb(i);
}
}
ll ans=0;
for(ii j:J){
int x = j.fi;
int y = j.se;
auto ptrx = lower_bound(all(orb[x]),y)-orb[x].begin();
auto ptry = lower_bound(all(ing[y]),x)-ing[y].begin();
int szx = (int)orb[x].size();
int szy = (int)orb[y].size();
ans += ll(szx-ptrx)*(szy-ptry) ;
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
640 KB |
Output is correct |
2 |
Correct |
6 ms |
640 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
640 KB |
Output is correct |
2 |
Correct |
6 ms |
640 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
640 KB |
Output is correct |
2 |
Correct |
6 ms |
640 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |