#include #include #include #include #define pure __attribute__((pure)) #define pure_const __attribute__((const)) #define _cold __attribute__((cold, noinline)) #define noreturn __attribute__((noreturn)) void #ifdef DEBUG #define dlog(...) fprintf(stderr, "[debug]" __VA_ARGS__) #else inline extern void do_nothing(int _n, ...) {} #define dlog(...) do { if(0) { do_nothing(0 __VA_OPT__(,) __VA_ARGS__); } } while(0) #endif noreturn static _cold panic(const char* msg) { fputs(msg, stderr); fputc('\n', stderr); abort(); } typedef struct sloc { int row; int column; int id; } seat_t; static const char* input[] = { #ifdef TEST #include "input-test.h" #else #include "input.h" #endif }; #define input_sz (sizeof(input) / sizeof(char*)) #define ROW_MAX 128 #define COL_MAX 8 inline static void seat_calc_id(seat_t* restrict s) { s->id = (s->row * 8) + s->column; } static pure_const int sbsearch(const char* direct, size_t len, int max) { int min = 0; #define diff (1 + (max - min)) for(size_t i=0;iid < s2->id ? -1 : s1->id > s2->id ? 1 : 0; } #endif int main() { int max=0; seat_t seats[input_sz]; for(size_t i=0;i { .row = %d, .column = %d, .id = %d }\n", seat.row, seat.column, seat.id); if(id>max) max = id; } #ifdef PART2 qsort(seats, input_sz, sizeof(seat_t), &_seat_cmp); for(size_t i=1; i