# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
40604 | pce913 | Treasure (different grader from official contest) (CEOI13_treasure2) | C++14 | 2 ms | 800 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 "treasure.h"
#include<algorithm>
#include<iostream>
using namespace std;
//격자크기 5 이상일때는 부분 합으로 가져오는게 이득이다.
int M[105][105];
int sum1[105][105], sum2[105][105], sum3[105][105], sum4[105][105];
int n;
void find_ans(){
//4개의 구역으로 나눈후에 sum table을 채운다. 반대쪽 지점을 이용해서 채운다.
int mr = n / 2, mc = n / 2;
for (int i = 1; i <= mr; i++){ //ok
for (int j = 1; j <= mc; j++){ //범위 안넘어가도록 if문 덕지덕지 붙여주자.
sum1[i][j] = countTreasure(i, j, n, n);
if (i + 1 <= n)
sum1[i][j] -= countTreasure(i + 1, j, n, n);
if (j + 1 <= n)
sum1[i][j] -= countTreasure(i, j + 1, n, n);
if (i + 1 <= n && j + 1 <= n)
sum1[i][j] += countTreasure(i + 1, j + 1, n, n);
//sum1[i][j] = countTreasure(i, j, n, n) - countTreasure(i + 1, j, n, n) - countTreasure(i, j + 1, n, n) + countTreasure(i + 1, j + 1, n, n);
M[i][j] = sum1[i][j];
}
}
for (int i = n; i >= mr + 1; i--){ // ok
for (int j = 1; j <= mc; j++){
//sum2[i][j] = countTreasure(i, j, 1, n) - countTreasure(i - 1, j, 1, n) - countTreasure(i, j - 1, 1, n) + countTreasure(i - 1, j - 1, 1, n);
sum2[i][j] = countTreasure(1, j, i, n);
if (i - 1 >= 1)
sum2[i][j] -= countTreasure(1, j, i - 1, n);
if (j + 1 <= n)
sum2[i][j] -= countTreasure(1, j + 1, i, n);
if (i - 1 >= 1 && j + 1 <= n)
sum2[i][j] += countTreasure(1, j + 1, i - 1, n);
//sum2[i][j] = countTreasure(1, j, i, n) - countTreasure(1, j, i-1, n) - countTreasure(1, j + 1, i, n) + countTreasure(1, j + 1, i-1, n);
M[i][j] = sum2[i][j];
}
}
for (int i = n; i >= mr + 1; i--){ //ok
for (int j = n; j >= mc + 1; j--){
sum3[i][j] = countTreasure(1, 1, i, j);
if (i - 1 >= 1)
sum3[i][j] -= countTreasure(1, 1, i - 1, j);
if (j - 1 >= 1)
sum3[i][j] -= countTreasure(1, 1, i, j - 1);
if (i - 1 >= 1 && j - 1 >= 1)
sum3[i][j] += countTreasure(1, 1, i - 1, j - 1);
//sum3[i][j] = countTreasure(1, 1, i, j) - countTreasure(1, 1, i - 1, j) - countTreasure(1, 1, i, j - 1) + countTreasure(1, 1, i - 1, j - 1);
M[i][j] = sum3[i][j];
}
}
for (int i = 1; i <= mr; i++){
for (int j = n; j >= mc + 1; j--){
sum4[i][j] = countTreasure(i, 1, n, j);
if (i + 1 <= n)
sum4[i][j] -= countTreasure(i + 1, 1, n, j);
if (j - 1 >= 1)
sum4[i][j] -= countTreasure(i, 1, n, j - 1);
if (i + 1 <= n && j - 1 >= 1)
sum4[i][j] += countTreasure(i + 1, 1, n, j - 1);
//sum4[i][j] = countTreasure(i, 1, n, j) - countTreasure(i + 1, 1, n, j) - countTreasure(i, 1, n, j - 1) + countTreasure(i + 1, 1, n, j - 1);
M[i][j] = sum4[i][j];
}
}
}
void findTreasure(int N) {
n = N;
find_ans();
for (int i = 1; i <= N; i++){
for (int j = 1; j <= N; j++){
if (M[i][j] == 1){
Report(i, j);
}
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |