CSES - Datatähti 2025 alku - Results
Submission details
Task:Niitty
Sender:rottis
Submission time:2024-11-04 10:32:37 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp:7:16: error: 'uint32_t' does not name a type
    7 | #define bitmap uint32_t
      |                ^~~~~~~~
input/code.cpp:23:1: note: in expansion of macro 'bitmap'
   23 | bitmap found_flowers = 0;
      | ^~~~~~
input/code.cpp:10:1: note: 'uint32_t' is defined in header '<cstdint>'; did you forget to '#include <cstdint>'?
    9 | #include <stdio.h>
  +++ |+#include <cstdint>
   10 | //#include <stdlib.h>
input/code.cpp:7:16: error: 'uint32_t' does not name a type
    7 | #define bitmap uint32_t
      |                ^~~~~~~~
input/code.cpp:24:1: note: in expansion of macro 'bitmap'
   24 | bitmap *board[500];
      | ^~~~~~
input/code.cpp:7:16: note: 'uint32_t' is defined in header '<cstdint>'; did you forget to '#include <cstdint>'?
    7 | #define bitmap uint32_t
      |                ^~~~~~~~
input/code.cpp:24:1: note: in expansion of macro 'bitmap'
   24 | bitmap *board[500];
      | ^~~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:7:16: error: '...

Code

//#define print_board for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { std::cout << (board[i][j]) << ' '; } std::cout << '\n'; } std::cout << std::endl
//#define print_flowers(flowers) for (int i = 0; i < 26; i++) { std::cout << ((flowers & (1<<i)) >> i); } std::cout << '\n' << "abcdefghijklmnopqrstuvwxyz" << std::endl
//#define print_rect(r) std::cout << r.left << ' ' << r.right << ' ' << r.top << ' ' << r.bottom << std::endl
#define to_bit(c) (1<<(c - 'A'))
//#define MAX_RECT ((rect) { .left = 0, .right = (int16_t) (n-1), .top = 0, .bottom = (int16_t) (n-1) })
//#define rect_size(r) ((1 + r.right - r.left) * (1 + r.bottom - r.top))
#define bitmap uint32_t
 
#include <stdio.h>
//#include <stdlib.h>
//#include <stdint.h>
 
// note: int16_t only needed for last part!
// other parts can do with int8_t
/*typedef struct {
    int16_t left;
    int16_t right;
    int16_t top;
    int16_t bottom;
} rect;*/

int n;
bitmap found_flowers = 0;
bitmap *board[500];

/*inline bool valid_rect(int16_t left, int16_t right, int16_t top, int16_t bottom) {
    bitmap flowers_in_rect = 0;
    for (uint16_t x = left; x <= right; x++) {
        for (uint16_t y = top; y <= bottom; y++) {
            flowers_in_rect = flowers_in_rect | board[x][y];
            if (found_flowers == flowers_in_rect) { return true; }
        }
    }
    return false;
}*/

int main() {
    //std::ios_base::sync_with_stdio(false);
    //std::cin.tie(NULL);

    scanf("%d", &n);
 
    //board = (bitmap**) malloc((n) * sizeof(bitmap*));
    
    char buf[501];
    
    for (int i = 0; i < n; i++) {
        bitmap row[500];
        scanf("%s", buf);
        for (int j = 0; j < n; j++) {
            found_flowers = found_flowers | to_bit(buf[j]);
            row[j] = to_bit(buf[j]);
        }
        board[i] = row;
    }

    //print_board;
 
    //print_flowers(found_flowers);
    long solutions = 0;
    
    bitmap columns[500];
    bitmap cols_bwise_ored;
    int right;
    int bottom;
    // brute force everything smaller than that
    for (int left = 0; left < n; left++) {
        for (int top = 0; top < n; top++) {
            right = n-1;
            bottom = top;
            for (int c_col = left; c_col <= right; c_col++) {
                columns[c_col] = board[c_col][top];
            }
            
            for (;;) {
                //print_rect(r);
                begin:
                    cols_bwise_ored = 0;
                    for (int c_col = left; c_col <= right; c_col++) {
                        cols_bwise_ored |= columns[c_col];
                        if (cols_bwise_ored == found_flowers) {
                            goto valid;
                        }
                    }
                    goto invalid;

                
                valid:
                    //std::cout << "valid!\n";
                    solutions += (n - bottom);
                    right--; // last column is no longer used at all
                    if (right < left) {
                        break;
                    }
                    goto begin;
                
                invalid:
                    //std::cout << "invalid...\n";
                    bottom++;
                    if (bottom >= n) {
                        break;
                    }

                    for (int c_col = left; c_col <= right; c_col++) {
                        columns[c_col] |= board[c_col][bottom];
                    }
                
                //std::cout << std::endl;
            }
        }
    } // */
    
    printf("%ld", solutions);
 
    /*
    for (unsigned int i = 0; i < n; i++) {
        free(board[i]);
    }
    free(board);
    */
 
    return 0;
}