Submission #1118784

#TimeUsernameProblemLanguageResultExecution timeMemory
1118784horezusholBitaro the Brave (JOI19_ho_t1)C++14
100 / 100
219 ms159600 KiB
#include<bits/stdc++.h>
#define F first
#define S second
#define SZ(x) lint((x).size())
const char nl = '\n';
using lint = long long;
using namespace std;
void hotline(string name) {
#ifndef ONLINE_JUDGE
	freopen((name + ".in").c_str(), "r", stdin);
	freopen((name + ".out").c_str(), "w", stdout);
#endif
}

const lint N = 3010;
char a[N][N];
lint n, m;

lint prefo[N][N]; // in string
lint prefi[N][N]; // in column

lint geto(lint i, lint l, lint r) {
	lint f = prefo[i][r] - prefo[i][l-1];
	return f;
}

lint geti(lint j, lint l, lint r) {
	lint f = prefi[r][j] - prefi[l-1][j];
	return f;
}	

void verkefni() {
	cin >> n >> m;
	for (lint i = 1; i <= n; i ++) {
		for (lint j = 1; j <= m; j ++) {
			cin >> a[i][j];
			prefo[i][j] = prefo[i][j-1] + (a[i][j] == 'O');
		}
	}
	for (lint i = 1; i <= m; i ++) {
		for (lint j = 1; j <= n; j ++) {
			prefi[j][i] = prefi[j-1][i] + (a[j][i] == 'I');
		}
	}
// 	for (lint i = 1; i <= n; i ++) {
// 		for (lint j = 1; j <= m; j ++) {
// 			cout << prefi[i][j] << " ";
// 		}
// 		cout << nl;
// 	}
	lint tot = 0;
	for (lint i = 1; i <= n; i ++) {
		for (lint j = 1; j <= m; j ++) {
			if (a[i][j] == 'J') {
				tot += geto(i,j,m) * geti(j,i,n);
			}
		}
	}
	cout << tot;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
// 	hotline("t");
	lint tst = 1;
// 	cin >> tst;
	while (tst --) {
		verkefni();
		cout << nl;
	}
}

Compilation message (stderr)

joi2019_ho_t1.cpp: In function 'void hotline(std::string)':
joi2019_ho_t1.cpp:10:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |  freopen((name + ".in").c_str(), "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t1.cpp:11:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  freopen((name + ".out").c_str(), "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...