Submission #970854

#TimeUsernameProblemLanguageResultExecution timeMemory
970854MercubytheFirstBitaro the Brave (JOI19_ho_t1)C++17
100 / 100
263 ms160084 KiB
#include <bits/stdc++.h> using ll = long long; #define pb push_back // overflow check strat : a * b / b == a using std::cin; using std::cout; template <typename T> std::ostream& operator<<( std::ostream& os, const std::vector<T>& v ); using namespace std; const ll inf = 1e9 + 37; void solve(){ ll n, m; cin >> n >> m; vector<string> g(n); for(auto& s : g) cin >> s; vector<vector<ll> > osuf(n + 1, vector<ll>(m + 1)), isuf(n + 1, vector<ll>(m + 1)); for(ll row = 0; row < n; ++row) { for(ll col = m - 1; col >= 0; --col) { osuf[row][col] = osuf[row][col + 1] + (g[row][col] == 'O'); } } for(ll col = 0; col < m; ++col) { for(ll row = n - 1; row >= 0; --row) { isuf[row][col] = isuf[row + 1][col] + (g[row][col] == 'I'); } } ll ans = 0; for(ll i = 0; i < n; ++i) { for(ll j = 0; j < m; ++j) { if(g[i][j] != 'J') continue; ans += osuf[i][j] * isuf[i][j]; } } cout << ans << endl; } signed main() { #ifdef LOCAL freopen("test.in", "r", stdin); freopen("test.out", "w", stdout); #endif std::ios_base::sync_with_stdio(0); cin.tie(NULL); // signed t = 0; cin >> t; while(t--) solve(); } template <typename T> std::ostream& operator<<( std::ostream& os, const std::vector<T>& v ) { os << "["; for (auto x : v) os << x << ", "; os << "]\n"; return os; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...