Submission #380787

# Submission time Handle Problem Language Result Execution time Memory
380787 2021-03-23T02:33:32 Z wp1270 Treasure (different grader from official contest) (CEOI13_treasure2) C
Compilation error
0 ms 0 KB
#include "treasure.h"
#define MAX_N 100

int front;
int rear;
int shouldBeHere[105][105] = { 0, };
typedef struct {
    int r1, c1, r2, c2, t;
}pos;
pos queue[MAX_N];

void queueInit(void) {
    front = 0;
    rear = 0;
}
int queueIsEmpty(void) {
    return (front == rear);
}
int queueIsFull(void) {
    if ((rear + 1) % MAX_N == front) {
        return 1;
    }
    else {
        return 0;
    }
}
int queueEnqueue(pos value) {
    if (queueIsFull()) {
        return 0;
    }
    queue[rear] = value;
    rear++;
    if (rear == MAX_N) {
        rear = 0;
    }

    return 1;
}
int queueDequeue(pos* value) {
    if (queueIsEmpty()) {
        return 0;
    }
    *value = queue[front];
    front++;
    if (front == MAX_N) {
        front = 0;
    }
    return 1;
}

void findTreasure(int N) {
    int cnt = countTreasure(1, 1, N, N);
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            shouldBeHere[i][j] = 0;
        }
    }
    if (cnt > 0) {
        queueInit();
        pos first;
        first.r1 = 1;
        first.c1 = 1;
        first.r2 = N;
        first.c2 = N;
        first.t = cnt;
        queueEnqueue(first);
        while (!queueIsEmpty()) {
            pos now;
            queueDequeue(&now);
            if (now.r1 == now.r2 && now.c1 == now.c2) {
                shouldBeHere[now.r1][now.c1] = 1;
            }
            else {
                int numT = now.t;
                int center_r = (now.r1 + now.r2) / 2;
                int center_c = (now.c1 + now.c2) / 2;
                int foundHere = 0;
                if (numT > 0) {
                    foundHere = countTreasure(now.r1, now.c1, center_r, center_c);
                    if (foundHere) {
                        pos left_up;
                        left_up.r1 = now.r1;
                        left_up.c1 = now.c1;
                        left_up.r2 = center_r;
                        left_up.c2 = center_c;
                        left_up.t = foundHere;
                        numT -= foundHere;
                        queueEnqueue(left_up);
                    }
                }
                if (numT > 0) {
                    if (now.c2 >= center_c + 1) {
                        foundHere = countTreasure(now.r1, center_c + 1, center_r, now.c2);
                        if (foundHere) {
                            pos right_up;
                            right_up.r1 = now.r1;
                            right_up.c1 = center_c + 1;
                            right_up.r2 = center_r;
                            right_up.c2 = now.c2;
                            right_up.t = foundHere;
                            numT -= foundHere;
                            queueEnqueue(right_up);
                        }
                    }
                }
                if (numT > 0) {
                    if (now.r2 >= center_r + 1) {
                        foundHere = countTreasure(center_r + 1, now.c1, now.r2, center_c);
                        if (foundHere) {
                            pos left_down;
                            left_down.r1 = center_r + 1;
                            left_down.c1 = now.c1;
                            left_down.r2 = now.r2;
                            left_down.c2 = center_c;
                            left_down.t = foundHere;
                            numT -= foundHere;
                            queueEnqueue(left_down);
                        }
                    }
                }
                if (numT > 0) {
                    foundHere = 0;
                    if (now.r2 >= center_r + 1 && now.c2 >= center_c + 1) {
                            pos right_down;
                            right_down.r1 = center_r + 1;
                            right_down.c1 = center_c + 1;
                            right_down.r2 = now.r2;
                            right_down.c2 = now.c2;
                            right_down.t = numT;
                            queueEnqueue(right_down);
                        
                    }
                }
              
            }
           
        
        }
    }
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            if (shouldBeHere[i][j]) {
                Report(i, j);
            }
        }
    }
}

/*
10
1011010101
1100010001
0100100101
0000101100
1111010100
0010100000
1101010001
0001010100
0101000100
1101010101
*/

Compilation message

grader.c: In function 'main':
grader.c:63:19: error: expected expression before 'int'
   63 |         my_assert(int(strlen(A[i]+1)) == N, "each line of the map must contain N zeroes or ones (before loop)");
      |                   ^~~
grader.c:63:9: error: too few arguments to function 'my_assert'
   63 |         my_assert(int(strlen(A[i]+1)) == N, "each line of the map must contain N zeroes or ones (before loop)");
      |         ^~~~~~~~~
grader.c:18:6: note: declared here
   18 | void my_assert (int a, const char* s) {
      |      ^~~~~~~~~