Submission #4545

# Submission time Handle Problem Language Result Execution time Memory
4545 2013-10-24T13:51:04 Z tncks0121 Treasure (different grader from official contest) (CEOI13_treasure2) C++
Compilation error
0 ms 0 KB
#include "treasure.h"
#include <stdio.h>
#include <memory.h>

using namespace std;

int A[105][105], B[105][105], C[105][105], D[105][105], R[105][105];
int S[105][105];
int N;
map<int, int> rec;

int get (int a, int b, int c, int d) {
    int x = (a-1)*N+b-1, y = (c-1)*N+d-1;  
    int z = x*N*N + y;
    if(!rec.count(z)) rec[z] = countTreasure(a, b, c, d);
    return rec[z];
}

void findTreasure (int N) {
    ::N = N;

    int i, j;
     
    int T = N/2+1;
     
    // 각 사분면에서 최선의 경우를 가져옴
    for(i = 1; i <= T; i++) {
        for(j = 1; j <= T; j++) A[i][j] = get(i, j, N, N);
        for(j = T; j <= N; j++) B[i][j] = get(i, 1, N, j);
    }
     
    for(i = T; i <= N; i++) {
        for(j = 1; j <= T; j++) C[i][j] = get(1, j, i, N);
        for(j = T; j <= N; j++) D[i][j] = get(1, 1, i, j);
    }
     
    // 그러면 r = T or c = T인 십자가 제외하고 모든 게 다 나옴
    for(i = T-1; i > 0; i--) {
        for(j = T-1; j > 0; j--) R[i][j] = A[i][j] - A[i][j+1] - A[i+1][j] + A[i+1][j+1];
        for(j = T+1; j <= N; j++) R[i][j] = B[i][j] - B[i][j-1] - B[i+1][j] + B[i+1][j-1];
    }
     
    for(i = T+1; i <= N; i++) {
        for(j = T-1; j > 0; j--) R[i][j] = C[i][j] - C[i][j+1] - C[i-1][j] + C[i-1][j+1];
        for(j = T+1; j <= N; j++) R[i][j] = D[i][j] - D[i][j-1] - D[i-1][j] + D[i-1][j-1];
    }
     
    // r = T, c > T인 십자가 처리
    memset(S, 0, sizeof S);
    for(i = 1; i < T; i++) for(j = T+1; j <= N; j++) S[i][j] = S[i-1][j] + R[i][j];
    for(j = N; j >= T+1; j--) R[T][j] = D[T][j] - D[T][j-1] - S[T-1][j];
     
    // 그럼 c > T인 경우는 다 처리가 끝났고 c <= T만 남았음
    // 이제 r < T, c = T인 경우 처리
    memset(S, 0, sizeof S);
    for(i = 1; i < T; i++) {
        R[i][T] = A[i][T] - A[i+1][T];
        for(j = T+1; j <= N; j++) R[i][T] -= R[i][j];
    }
     
    // r > T, c = T인 경우 처리. 위와 똑같이 해줄 수 있음
    memset(S, 0, sizeof S);
    for(i = T+1; i <= N; i++) {
        R[i][T] = C[i][T] - C[i-1][T];
        for(j = T+1; j <= N; j++) R[i][T] -= R[i][j];
    }
     
    // 이제 c < T인 경우만 남았음. r = T, c < T인 직선 처리
    memset(S, 0, sizeof S);
    for(i = N; i >= T; i--) for(j = N; j > 0; j--) S[i][j] = S[i+1][j] + S[i][j+1] - S[i+1][j+1] + R[i][j];
    for(j = T-1; j > 0; j--) R[T][j] = A[T][j] - A[T][j+1] - S[T+1][j] + S[T+1][j+1];
     
     
    // r = c = T 부분 (정가운데) 처리
    R[T][T] = A[T][T] + B[T][T] + C[T][T] + D[T][T] - A[1][1];
    for(i = 1; i <= N; i++) if(i != T) R[T][T] -= (R[i][T] + R[T][i]);
    R[T][T] /= 3;
    /*
    puts("");
    for(i = 1; i <= N; i++) {
        printf("%3d ", i);
        for(j = 1; j <= N; j++) {
            printf("%3d",R[i][j]);
        }
        puts("");
    }*/
     
    for(i = 1; i <= N; i++) {
        for(j = 1; j <= N; j++) {
            if(R[i][j] == 1) Report(i, j);
        }
    }
}

Compilation message

grader.c: In function 'int main()':
grader.c:63:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         my_assert(strlen(A[i]+1) == N, "each line of the map must contain N zeroes or ones (before loop)");
                                  ^
treasure.cpp:10:1: error: 'map' does not name a type
 map<int, int> rec;
 ^
treasure.cpp: In function 'int get(int, int, int, int)':
treasure.cpp:15:9: error: 'rec' was not declared in this scope
     if(!rec.count(z)) rec[z] = countTreasure(a, b, c, d);
         ^
treasure.cpp:16:12: error: 'rec' was not declared in this scope
     return rec[z];
            ^