Rezultati

Up. imeNalogaJezikRezultatČas oddaje
finalsolution-2018 Prehod čez cesto C 100/100OK 04. okt '18 @ 18:19

Test Točke Porabljen spomin Porabljen čas Status
#1 9/9 1,516 MiB 0,005 s OK
#2 9/9 1,508 MiB 0,000 s OK
#3 9/9 1,590 MiB 0,000 s OK
#4 9/9 1,488 MiB 0,005 s OK
#5 9/9 1,488 MiB 0,005 s OK
#6 9/9 1,488 MiB 0,000 s OK
#7 9/9 1,461 MiB 0,005 s OK
#8 9/9 1,457 MiB 0,000 s OK
#9 9/9 1,461 MiB 0,000 s OK
#10 9/9 1,488 MiB 0,005 s OK
#11 10/10 1,488 MiB 0,005 s OK

Ocenjevani program (prehodceste.c):
#include <stdio.h>
#include <stdlib.h>

struct edge {
    double t;
    int v;
};

struct edge E[2048];

static int compar(const struct edge *a, const struct edge *b) {
    if (a->t < b->t) return -1;
    if (a->t > b->t) return 1;
    return b->v - a->v;
}

int main() {
    int n = 0, m = 0, i = 0, s = 0;
    scanf("%d %d", &n, &m);
    for (; i < m; i++) {
        int p = 0;
        double x = 0, v = 0, d = 0;
        scanf("%d %lf %lf %lf", &p, &x, &v, &d);
        E[2*i].t = (-x) / v - 10 * p;
        E[2*i].v = 1;
        E[2*i+1].t = (-x + (v > 0 ? d : -d)) / v + 10 - 10 * p;
        E[2*i+1].v = -1;
    }
    qsort(E, 2 * m, sizeof(E[0]), (int (*)(const void *, const void *))compar);
    for (i = 0; i < 2 * m && E[i].t <= 0; i++) {
        s += E[i].v;
    }
    if (s == 0) {
        printf("0.0\n");
        return 0;
    }
    for (; i < 2 * m; i++) {
        s += E[i].v;
        if (s == 0) {
            printf("%.7f\n", E[i].t);
            return 0;
        }
    }
    return 0;
}