Submission #292036

# Submission time Handle Problem Language Result Execution time Memory
292036 2020-09-06T08:28:37 Z Diuven Express 20/19 (ROI19_express) C++17
15 / 100
3000 ms 539616 KB
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second

const int csize = 1000 * 1000;
const int magic = 5000;

int n, m, q;
long long p;

int tc;
long long* dists[csize];
int len[csize];
vector <pair <int, long long> > vertex[csize];
long long help[csize];

void prune(int v) {
    int step = 0;
    if (len[v] <= magic) {
        return;
    }
    step = (len[v] + magic - 1) / magic;
    
    int ptr = 0;
    for (int i = 0; i < len[v]; i += step)
        help[ptr++] = dists[v][i];
    if (help[ptr - 1] != dists[v][len[v] - 1]) {
        help[ptr++] = dists[v][len[v] - 1];
    }
    for (int i = 0; i < ptr; i++)
        dists[v][i] = help[i];
    len[v] = ptr;
}

int main () {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    
    scanf("%d", &tc);

    for (int tnum = 0; tnum < tc; tnum++) {
        scanf("%d%d%d%lld", &n, &m, &q, &p);

        for (int i = 0; i < m; i++) {
            int u, v;
            long long t;
            scanf("%d%d%lld", &u, &v, &t);
            vertex[v - 1].pb(mp(u - 1, t));
        }

        len[0] = 1;
        dists[0] = new long long[1];
        dists[0][0] = 0ll;
        for (int i = 1; i < n; i++) {
            int total = 0;
            for (int j = 0; j < (int) vertex[i].size(); j++) {
                total += len[vertex[i][j].fs];
            }        
            dists[i] = new long long[total];
            int cur = 0;
            for (int j = 0; j < (int) vertex[i].size(); j++) {
                int tg = vertex[i][j].fs;
                int curlen = len[tg];
                long long toadd = vertex[i][j].sc;
                for (int h = 0; h < curlen; h++) {
                    dists[i][cur++] = dists[tg][h] + toadd;
                }                
            }
            len[i] = cur;
            sort(dists[i], dists[i] + len[i]);

            len[i] = unique(dists[i], dists[i] + len[i]) - dists[i];
            prune(i);
        }

        for (int i = 0; i < q; i++) {
            int tg;
            long long tlen;
            scanf("%d%lld", &tg, &tlen);
            tg--;

            int it = lower_bound(dists[tg], dists[tg] + len[tg], tlen) - dists[tg];
            if (it < len[tg] && dists[tg][it] <= tlen * p / (p - 1)) {
                printf("1");
            } else {
                printf("0");
            }
        }

        for (int i = 0; i < n; i++) {
            delete [] dists[i];
            vertex[i].clear();
        }

        printf("\n");
    }

    return 0;
}

Compilation message

main.cpp: In function 'int main()':
main.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   57 |     scanf("%d", &tc);
      |     ~~~~~^~~~~~~~~~~
main.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   60 |         scanf("%d%d%d%lld", &n, &m, &q, &p);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:65:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   65 |             scanf("%d%d%lld", &u, &v, &t);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:97:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   97 |             scanf("%d%lld", &tg, &tlen);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 16 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 23 ms 23808 KB Output is correct
6 Correct 16 ms 23808 KB Output is correct
7 Correct 18 ms 23808 KB Output is correct
8 Correct 16 ms 23808 KB Output is correct
9 Correct 16 ms 23808 KB Output is correct
10 Correct 17 ms 23808 KB Output is correct
11 Correct 16 ms 23808 KB Output is correct
12 Correct 25 ms 23808 KB Output is correct
13 Correct 25 ms 23808 KB Output is correct
14 Correct 25 ms 23880 KB Output is correct
15 Correct 24 ms 23808 KB Output is correct
16 Correct 24 ms 23808 KB Output is correct
17 Correct 24 ms 23808 KB Output is correct
18 Correct 25 ms 23808 KB Output is correct
19 Correct 26 ms 23808 KB Output is correct
20 Correct 26 ms 23808 KB Output is correct
21 Correct 24 ms 23808 KB Output is correct
22 Correct 23 ms 23808 KB Output is correct
23 Correct 23 ms 23808 KB Output is correct
24 Correct 22 ms 23808 KB Output is correct
25 Correct 22 ms 23808 KB Output is correct
26 Correct 21 ms 23808 KB Output is correct
27 Correct 23 ms 23808 KB Output is correct
28 Correct 21 ms 23808 KB Output is correct
29 Correct 22 ms 23808 KB Output is correct
30 Correct 22 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23936 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 16 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 16 ms 23808 KB Output is correct
6 Correct 17 ms 23808 KB Output is correct
7 Correct 17 ms 23808 KB Output is correct
8 Correct 16 ms 23808 KB Output is correct
9 Correct 16 ms 23808 KB Output is correct
10 Correct 22 ms 23936 KB Output is correct
11 Correct 33 ms 26616 KB Output is correct
12 Correct 20 ms 24192 KB Output is correct
13 Correct 49 ms 29432 KB Output is correct
14 Correct 21 ms 23808 KB Output is correct
15 Correct 19 ms 23936 KB Output is correct
16 Correct 21 ms 23808 KB Output is correct
17 Correct 21 ms 23808 KB Output is correct
18 Correct 20 ms 23808 KB Output is correct
19 Correct 20 ms 23936 KB Output is correct
20 Correct 23 ms 23808 KB Output is correct
21 Correct 23 ms 23928 KB Output is correct
22 Correct 21 ms 24064 KB Output is correct
23 Correct 20 ms 24192 KB Output is correct
24 Correct 26 ms 24832 KB Output is correct
25 Correct 24 ms 24704 KB Output is correct
26 Correct 34 ms 25116 KB Output is correct
27 Correct 25 ms 24704 KB Output is correct
28 Correct 19 ms 23808 KB Output is correct
29 Correct 18 ms 23808 KB Output is correct
30 Correct 18 ms 23808 KB Output is correct
31 Correct 19 ms 23840 KB Output is correct
32 Incorrect 981 ms 127352 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23808 KB Output is correct
2 Execution timed out 3080 ms 334696 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3070 ms 337940 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 17 ms 23808 KB Output is correct
3 Correct 18 ms 23808 KB Output is correct
4 Correct 96 ms 36344 KB Output is correct
5 Correct 18 ms 23936 KB Output is correct
6 Correct 17 ms 23808 KB Output is correct
7 Correct 18 ms 23808 KB Output is correct
8 Correct 27 ms 27768 KB Output is correct
9 Correct 18 ms 23808 KB Output is correct
10 Correct 18 ms 23808 KB Output is correct
11 Correct 31 ms 24652 KB Output is correct
12 Correct 20 ms 23936 KB Output is correct
13 Correct 20 ms 23936 KB Output is correct
14 Correct 42 ms 25464 KB Output is correct
15 Incorrect 49 ms 26456 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 676 ms 32784 KB Output is correct
2 Execution timed out 3123 ms 539616 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 707 ms 32460 KB Output is correct
2 Execution timed out 3142 ms 539276 KB Time limit exceeded
3 Halted 0 ms 0 KB -