# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
110457 | Breno_XD | Bitaro the Brave (JOI19_ho_t1) | C++14 | 8 ms | 568 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define int long long
typedef pair<int,int> pii;
const int MAXN = 3420;
int N,M, ans;
pii J[MAXN], O[MAXN], I[MAXN];
int oeO[MAXN], oeI[MAXN];
int contj, conto, conti;
char letra;
main(){
//Inicializo com -1, indicando que não tem como chegar lá
memset(oeO, -1, sizeof(oeO));
memset(oeI, -1, sizeof(oeI));
//leitura
scanf("%d%d", &N, &M);
for(int i=1; i<=N; i++){
for(int j=1; j<=M; j++){
cin >> letra;
if(letra == 'J'){
J[++contj] = {i,j};
}
if(letra == 'O'){
O[++conto] = {i,j};
if(oeO[i]==-1) oeO[i] = conto;
}
if(letra == 'I'){
I[++conti] = {j,i};
}
}
}
//Ordeno o vetor I
sort(I+1, I+conti+1); //Ordena em ordem crescente
for(int top=1; top<=MAXN; top++){
int i = I[top].x;
if(oeI[i]==-1) oeI[i] = top;
}
for(int ind=1; ind<=contj; ind++){ //Indice que percorre J
int i = J[ind].x; int j = J[ind].y;
if(oeO[i]>=1){
for(int ini = oeO[i]; O[ini].x==i; ini++){
int l = O[ini].y;
if(j<l){ //Se for um valor possível, continuo a buscar
if(oeI[j]>=1){
for(int comeco = oeI[j]; I[comeco].x==j; comeco++){
int k = I[comeco].y;
if(i<k){
ans++;
}
}
}
}
//Caso contrário eu dessprezo, pois não é uma possibilidade
}
}
}
cout << ans << endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |