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