2
1
Fork 0

Day 10/C: Support streaming, use heap memory

This commit is contained in:
Mia Herkt 2021-12-10 20:19:54 +01:00
parent 9a00ee5a90
commit faf3fd1358
Signed by: mia
GPG key ID: 72E154B8622EC191

View file

@ -3,42 +3,42 @@
#include <string.h> #include <string.h>
#include <inttypes.h> #include <inttypes.h>
typedef unsigned __int128 u;int X[ typedef unsigned __int128 u;int X
]= {3,57,1197,25137};void O(u n){if(n> []={3,57,1197,25137};void O(u n){if(n
#define P10uI64 10000000000000000000ULL #define P10uI64 10000000000000000000ULL
UINT64_MAX) { O ( n /P10uI64);n%=P10uI64;} >UINT64_MAX ) { O(n/P10uI64);n%=P10uI64;}
printf( "%"PRIu64,(uint64_t)n);}int Q(const printf("%"PRIu64,(uint64_t)n);}int Q(const
void* A , const void*B){u a=*(u*)A,b=*(u*)B; void* A , const void*B){u a=*(u*)A,b=*(u*)B;
return a>b?a<b?-1: return a>b?a<b?-1:
0: 1 ;}char C[]={ 0: 1 ;}char C[]={
'(', ')','[',']', '(', ')','[',']',
'{','}','<','>'}; '{','}','<','>'};
int main(int H, int main(){char*
char**J){if(H<2) p, * s , * P,*B;
return 1;char*p, size_t L=0,i,U=0
*P,n;u L=0,i,S=0, ,g = 1000 ; u *G=
U=0;FILE*f=fopen malloc(sizeof(u)
(J[1],"r");for(;(n *g ) , S =0;while(
=fgetc (f))!=EOF;L+=n scanf("%ms",&p)==1){s
=='\n' ) ;rewind(f);u G[L];for(L=0; =p ; B=s;for(P=p;*P;P++)for(i=0;i<
fscanf(f,"%ms",&p)==1;L++){char s sizeof(C);i+=2)if(*P==C[i])*B++=
[strlen(p)],*B=s;G[L]=0;for(P= C[i+1];else if(*P==C[i+1])if(
p;*P;P++)for(i=0;i<sizeof(C B==s||*(B-1)!=*P){S+=X[i/2
);i+=2)if(*P==C[i])*B ]; goto N;}else B--;
++=C[i+1];else if if(B!=s){G[L]=0;
(* P==C[i+1])if(B for(B--;B>=s;B--
==s||*(B-1)!=*P){ )for ( i = 0 ;i<
S+=X[i/2];goto N; sizeof( C);i+=2)
}else B--; if(*B==C[
if(B!=s){for(B--;B i+1]){G[L]=G[L]*5
>=s ; B -- )for(i=0;i< +i/2+1;break;}U++;L++
sizeof(C);i+=2)if(*B==C[ ;if (L+1>g)G=realloc(G,
i+ 1 ]){G[L]=G[L]*5+i/2+1; sizeof( u)*(g+=1000));}N:
break; } U ++;}N:free(p);} free(p);}qsort(G,L,sizeof
qsort( & G,L,sizeof(u),Q); (u),Q); printf("\xe2\x98"
printf("\xe2\x98\x86");O "\x86");O(S);printf("\n"
(S);printf("\n\xe2\x98" "\xe2\x98\x85");O (G[
"\x85");O(G[U/2]); U/ 2]); free(G);
puts("");} puts("");}