Submission #219464

#TimeUsernameProblemLanguageResultExecution timeMemory
219464PeregudovSergeyBitaro the Brave (JOI19_ho_t1)C++14
100 / 100
278 ms160120 KiB
#include <bits/stdc++.h>

#define int long long

#define pii pair<int, int>

#define x1 x1228
#define y1 y1228

#define left left228
#define right right228

#define pb push_back
#define eb emplace_back

#define mp make_pair                                                                
                                                                                                                                        
#define ff first                                                                  
#define ss second   

#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << endl; 
#define TIME (ld)clock()/CLOCKS_PER_SEC

using namespace std;
typedef long long ll; 
typedef long double ld; 
                                                                                                   
const int maxn = 3000 + 7, mod = 1e9 + 7, MAXN = 1e6 + 7;
const double eps = 1e-9;
const ll inf = 1e18;
mt19937 rnd(time(0));
int h, w; 
string a[maxn];
int row[maxn][maxn]; 
int col[maxn][maxn]; 

void solve() {
    cin >> h >> w; 
    for (int i = 0; i < h; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) row[i][j + 1] = row[i][j] + (a[i][j] == 'O'); 
    }                                               
    for (int j = 0; j < w; ++j) {
        for (int i = 0; i < h; ++i) {
            col[j][i + 1] = col[j][i] + (a[i][j] == 'I');
        }
    }
    int ans = 0; 
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (a[i][j] == 'J') ans += (row[i][w] - row[i][j + 1]) * (col[j][h] - col[j][i + 1]);             
        }
    }
    cout << ans; 
}                                
   
signed main() {
#ifdef LOCAL
    freopen("TASK.in", "r", stdin);
    freopen("TASK.out", "w", stdout);
#else 
    
#endif // LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20); 
    cout << fixed; 
    int t = 1; 
    for (int i = 0; i < t; ++i) {              
        solve();
    }
    return 0;
}  
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...