Cod sursa(job #2017003)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 31 august 2017 00:52:48
Problema Sortare topologica Scor 0
Compilator c Status done
Runda Arhiva educationala Marime 2.42 kb
/* acest cod este un pamflet -- am facut asta doar pentru distractie
// codul asta nu e in niciun caz bun :)
*/
#pragma GCC optimize ("O3")
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char i_buf[100000] = {}, *i_buf_p = i_buf, *i_buf_ep = i_buf + sizeof(i_buf), o_buf[300000] = {}, *o_buf_p = o_buf, tmp_o_buf[10], *tmp_o_buf_p = tmp_o_buf;
int i, n, m, *tmp, cur, *p, x, y, j, nr_prevs[50010] = {}, st[50010], *st_p = st, rez[50010], *rez_p = rez, sz[50010], capacity[50010], *buf[50010], jumptowhere, *where;
FILE *f, *g;

int main(){
    f = fopen("sortaret.in", "r"), g = fopen("sortaret.out", "w");
    fread(i_buf_p = i_buf, sizeof(char), sizeof(i_buf), f);

    jumptowhere = 0;
    GETINT:

    *where = 0, j = 0;
    LOOP0:
    if(*i_buf_p >= '0') j = 1, *where = 10 * *where + *i_buf_p - '0';
    else if(j == 1 && jumptowhere == 0) goto JUMP0;
    else if(j == 1 && jumptowhere == 1) goto JUMP1;
    else if(j == 1 && jumptowhere == 2) goto JUMP2;
    else if(j == 1 && jumptowhere == 3) goto JUMP3;
    if(++i_buf_p == i_buf_ep) fread(i_buf_p = i_buf, sizeof(char), sizeof(i_buf), f);
    goto LOOP0;

    jumptowhere = 0;
    where = &n;
    goto GETINT;
    JUMP0:

    jumptowhere = 1;
    where = &m;
    goto GETINT;
    JUMP1:

    i = 0;
    LOOP3: if(i < n) {
    sz[i] = 0, capacity[i] = 4, buf[i] = malloc(4 * sizeof(int)), ++i;
    goto LOOP3; }

    i = 0;
    LOOP4: if(i < m) {
    jumptowhere = 2;
    where = &x;
    goto GETINT;
    JUMP2:

    jumptowhere = 3;
    where = &y;
    goto GETINT;
    JUMP3:

    --x, --y;
    if(sz[x]== capacity[x]) {
        tmp = malloc(2 * capacity[x] * sizeof(int));
        memcpy(tmp, buf[x], capacity[x]* sizeof(int));
        buf[x] = tmp, capacity[x] *= 3, capacity[x] /= 2; }
    buf[x][sz[x]++] = y, ++nr_prevs[y], ++i;
    goto LOOP4; }

    i = 0;
    LOOP5: if(i < n) {
    if(nr_prevs[i] == 0) *st_p++ = i;
    ++i;
    goto LOOP5; }


    LOOP6: if(st_p != st) {
    cur = *--st_p, *rez_p++ = cur, i = 0;
    LOOP7: if(i < sz[cur]){
    if(--nr_prevs[buf[cur][i]] == 0) *st_p++ = buf[cur][i];
    ++i;
    goto LOOP7; }
    goto LOOP6; }


    p = rez;
    LOOP8: if(p < rez_p) {
    ++*p;

    LOOP1: if(*p) {
    *tmp_o_buf_p++ = *p % 10 + '0', *p /= 10;
    goto LOOP1; }

    LOOP2: if(tmp_o_buf_p > tmp_o_buf) {
    *o_buf_p++ = *--tmp_o_buf_p;
    goto LOOP2; }
    *o_buf_p++ = ' ', ++p;
    goto LOOP8; }
 
    fwrite(o_buf, o_buf_p - o_buf, sizeof(char), g);
    return 0; }