답안 #209197

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
209197 2020-03-13T11:14:23 Z AryaKnight Bitaro the Brave (JOI19_ho_t1) C++14
100 / 100
763 ms 55164 KB
//#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include<bits/stdc++.h>
using namespace std;

#define all(a) begin(a),end(a)
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

void clr(auto &a,int n){
  a.clear();
  a.resize(n);
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
  input>>x.F>>x.S;
  return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}

template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}

template<typename T>
vector<pair<T,int>> getvec(int n){
  vector<pair<T,int>>a(n);
  for(int i=0;i<a.size();i++){
    cin>>a[i].F;
    a[i].S=i;
  }
  return a;
}

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int mul(int a,int b){
  return ((a)*1ll*(b))%mod;
}

void add(int &a,int b){
  a+=b;
  if(a>=mod)a-=mod;
}

int sub(int a,int b){
  a-=b;
  if(a<0){
    a+=mod;
  }
  return a;
}

int powz(int a,int b){
  int res=1;
  while(b){
    if(b&1){
      res=mul(res,a);
    }
    b/=2;
    a=mul(a,a);
  }
  return res;
}

const int N=200005;

vector<int>rw[3005],cl[3005];

void solve(){
  int n,m;
  cin>>n>>m;
  vector<string>a(n);
  cin>>a;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      if(a[i][j]=='O'){
	rw[i].push_back(j);
      }
      if(a[i][j]=='I'){
	cl[j].push_back(i);
      }
    }
  }
  for(int i=0;i<n;i++){
    sort(all(rw[i]));
  }
  for(int i=0;i<m;i++){
    sort(all(cl[i]));
  }
  ll ans=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      if(a[i][j]=='J'){
	int it=upper_bound(all(rw[i]),j)-rw[i].begin();
	int it2=upper_bound(all(cl[j]),i)-cl[j].begin();
	ans+=(rw[i].size()-it)*1ll*(cl[j].size()-it2);
      }
    }
  }
  cout<<ans;
 
}

signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc=1;
  //cin>>tc;
  for(int _=0;_<tc;_++){
    // cout<<"Case #"<<_+1<<": ";
    solve();
    if(_!=tc-1){
      cout<<'\n';
    }
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 16 ms 1400 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 8 ms 1016 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 20 ms 1912 KB Output is correct
19 Correct 13 ms 1912 KB Output is correct
20 Correct 11 ms 1400 KB Output is correct
21 Correct 20 ms 1912 KB Output is correct
22 Correct 13 ms 1656 KB Output is correct
23 Correct 11 ms 1400 KB Output is correct
24 Correct 20 ms 1528 KB Output is correct
25 Correct 11 ms 1912 KB Output is correct
26 Correct 11 ms 1400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 16 ms 1400 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 8 ms 1016 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 20 ms 1912 KB Output is correct
19 Correct 13 ms 1912 KB Output is correct
20 Correct 11 ms 1400 KB Output is correct
21 Correct 20 ms 1912 KB Output is correct
22 Correct 13 ms 1656 KB Output is correct
23 Correct 11 ms 1400 KB Output is correct
24 Correct 20 ms 1528 KB Output is correct
25 Correct 11 ms 1912 KB Output is correct
26 Correct 11 ms 1400 KB Output is correct
27 Correct 681 ms 41208 KB Output is correct
28 Correct 6 ms 632 KB Output is correct
29 Correct 22 ms 3960 KB Output is correct
30 Correct 7 ms 632 KB Output is correct
31 Correct 479 ms 28684 KB Output is correct
32 Correct 334 ms 55164 KB Output is correct
33 Correct 301 ms 42360 KB Output is correct
34 Correct 558 ms 32248 KB Output is correct
35 Correct 418 ms 43384 KB Output is correct
36 Correct 300 ms 42360 KB Output is correct
37 Correct 763 ms 47988 KB Output is correct
38 Correct 217 ms 37368 KB Output is correct
39 Correct 210 ms 33916 KB Output is correct