//CFLAGS="-O3 -std=c11" #include "stdlib.h" #include "stdio.h" #include "time.h" typedef struct node { int val; struct node* prev; struct node* next; } node_t ; int count = 0; node_t pool[20000000]; int main(int argc, char** argv) { int marbles; int players; unsigned int scores[1000] = { 0 }; sscanf(argv[1], "%d", &players); sscanf(argv[2], "%d", &marbles); struct timespec ts; timespec_get(&ts, TIME_UTC); node_t* curnode = &pool[count]; count++; curnode->val = 0; curnode->next = curnode->prev = curnode; int i=0; int player = 0; int marble = 0; int next23 = 23; for (i=0;iprev->prev->prev->prev->prev->prev; node_t* prev = curnode->prev; int othernode = prev->val; prev = prev->prev; prev->next = curnode; curnode->prev = prev; scores[player] += (marble + othernode); } else { node_t* node = curnode->next; curnode = &pool[count]; count++; node_t* tmp = node->next; curnode->val=marble; node->next = curnode; curnode->prev = node; curnode->next = tmp; tmp->prev = curnode; } } unsigned int max = 0; for (i=0; i max ? scores[i] : max; } { struct timespec ts2; timespec_get(&ts2, TIME_UTC); long long nanos = (ts2.tv_sec - ts.tv_sec)*1000000000 + ts2.tv_nsec - ts.tv_nsec; printf("%lldms, %lldmicros, %lld nanos\n",nanos/1000000,nanos/1000,nanos); } printf("%u\n", max); }