Submission #230215

#TimeUsernameProblemLanguageResultExecution timeMemory
230215AMO5Bitaro the Brave (JOI19_ho_t1)C++98
100 / 100
194 ms120256 KiB
// 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];
int orb[mxn][mxn],ing[mxn][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];
	}
	for(int i=0; i<=h; i++){
		for(int j=0; j<=w; j++){
			orb[i][j]=0;
			ing[i][j]=0;
		}
	}
	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][j]=1;
			else ing[i][j]=1;
		}
	}
	for(int i=h-1; i>=0; i--){
		for(int j=w-1; j>=0; j--){
			orb[i][j] += orb[i][j+1];
			ing[i][j] += ing[i+1][j];
		}
	}
	ll ans=0;
	for(ii j:J){
		int x = j.fi;
		int y = j.se;
		//cerr << x <<  ' ' << y << ' ' << orb[x][y] << ' ' << ing[x][y] << endl;
		ans += ll(orb[x][y])*ing[x][y];
	}
	cout << ans << endl;
}	
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...