Submission #542007

#TimeUsernameProblemLanguageResultExecution timeMemory
542007Cookie197Bitaro the Brave (JOI19_ho_t1)C++17
100 / 100
328 ms114964 KiB
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>

using namespace std;
#define ll long long
#define endl "\n"
#define mp make_pair
#define out(x) cout<< #x << " = " << x << endl
#define pii pair<int,int> 
#pragma GCC optimize("Ofast")

int n,m;
int arr[3005][3005];
int Opre[3005][3005], Ipre[3005][3005];
signed main(){
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n>>m;
    for (int i=1;i<=n;i++) for (int j=1;j<=m;j++){
        char c; cin>>c;
        if (c=='J') arr[i][j] = 0;
        if (c=='O') arr[i][j] = 1;
        if (c=='I') arr[i][j] = 2;
    }

    for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) Opre[i][j] = Opre[i][j-1] + (arr[i][j] == 1);
    for (int j=1;j<=m;j++) for (int i=1;i<=n;i++) Ipre[i][j] = Ipre[i-1][j] + (arr[i][j] == 2);
        
    
    ll ans = 0;
    for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) if (arr[i][j] == 0){
        int x = Opre[i][m] - Opre[i][j];
        int y = Ipre[n][j] - Ipre[i][j];
        ans += 1ll * x * y;
    }
    cout<<ans<<endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...