Submission #292833

# Submission time Handle Problem Language Result Execution time Memory
292833 2020-09-07T14:00:29 Z 문홍윤(#5817) Express 20/19 (ROI19_express) C++17
67 / 100
5000 ms 1048580 KB
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(all(x))
#define press(x) x.erase(unique(all(x)), x.end());
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef pair<LL, LL> pll;
const int INF=1e9;
const LL LLINF=2e17;

int n, m, q, indeg[500010];
int topo[500010], re, fr;
LL p;

vector<pil> link[500010], rlink[500010];
vector<LL> dp[500010];
char str[500010];

void cl(int num, int qu){
    re=fr=0;
    for(int i=1; i<=num; i++){
        vector<pil>().swap(link[i]);
        vector<pil>().swap(rlink[i]);
        vector<LL>().swap(dp[i]);
    }
    for(int i=1; i<=qu; i++)str[i]=0;
}

void merge_dp(int num){
    int sz=rlink[num].size();
    LL st=0;
    vector<int> pv(sz);
    while(1){
        LL minn=LLINF;
        int minnum=-1;
        for(int i=0; i<pv.size(); i++){
            int nw=rlink[num][i].F;
            LL c=rlink[num][i].S;
            if(pv[i]==dp[nw].size())continue;
            if(minn>dp[nw][pv[i]]+c){
                minn=dp[nw][pv[i]]+c;
                minnum=i;
            }
        }
        if(minnum==-1)break;
        if(st*p/(p-1)<minn){
            dp[num].eb(minn);
            dp[num].eb(minn);
            st=minn;
        }
        else dp[num][dp[num].size()-1]=minn;
        pv[minnum]++;
    }
    press(dp[num]);
}

void solve(){
    scanf("%d %d %d %lld", &n, &m, &q, &p);
    for(int i=1; i<=m; i++){
        int a, b; LL c;
        scanf("%d %d %lld", &a, &b, &c);
        link[a].eb(b, c);
        rlink[b].eb(a, c);
        indeg[b]++;
    }
    for(int i=1; i<=n; i++){
        if(!indeg[i])topo[++re]=i;
    }
    for(fr=1; fr<=re; fr++){
        for(auto i:link[topo[fr]]){
            indeg[i.F]--;
            if(!indeg[i.F])topo[++re]=i.F;
        }
    }
    dp[1].eb(0);
    for(int i=2; i<=n; i++)merge_dp(topo[i]);
    for(int i=1; i<=q; i++){
        int a; LL s, e;
        scanf("%d %lld", &a, &s);
        e=s*p/(p-1);
        int num=upper_bound(all(dp[a]), e)-lower_bound(all(dp[a]), s);
        if(num)str[i]='1';
        else str[i]='0';
    }
    printf("%s\n", str+1);
    cl(n, q);
}

int main(){
    int t;
    scanf("%d", &t);
    while(t--)solve();
}

Compilation message

express.cpp: In function 'void merge_dp(int)':
express.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for(int i=0; i<pv.size(); i++){
      |                      ~^~~~~~~~~~
express.cpp:46:21: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |             if(pv[i]==dp[nw].size())continue;
express.cpp: In function 'void solve()':
express.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   65 |     scanf("%d %d %d %lld", &n, &m, &q, &p);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
express.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   68 |         scanf("%d %d %lld", &a, &b, &c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
express.cpp:86:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   86 |         scanf("%d %lld", &a, &s);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
express.cpp: In function 'int main()':
express.cpp:98:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   98 |     scanf("%d", &t);
      |     ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 24 ms 35584 KB Output is correct
2 Correct 24 ms 35584 KB Output is correct
3 Correct 25 ms 35584 KB Output is correct
4 Correct 25 ms 35584 KB Output is correct
5 Correct 38 ms 35584 KB Output is correct
6 Correct 26 ms 35576 KB Output is correct
7 Correct 24 ms 35580 KB Output is correct
8 Correct 24 ms 35584 KB Output is correct
9 Correct 24 ms 35584 KB Output is correct
10 Correct 24 ms 35584 KB Output is correct
11 Correct 24 ms 35584 KB Output is correct
12 Correct 35 ms 35584 KB Output is correct
13 Correct 36 ms 35584 KB Output is correct
14 Correct 35 ms 35584 KB Output is correct
15 Correct 33 ms 35584 KB Output is correct
16 Correct 34 ms 35584 KB Output is correct
17 Correct 34 ms 35576 KB Output is correct
18 Correct 34 ms 35584 KB Output is correct
19 Correct 34 ms 35584 KB Output is correct
20 Correct 34 ms 35584 KB Output is correct
21 Correct 34 ms 35584 KB Output is correct
22 Correct 33 ms 35584 KB Output is correct
23 Correct 33 ms 35584 KB Output is correct
24 Correct 31 ms 35584 KB Output is correct
25 Correct 31 ms 35584 KB Output is correct
26 Correct 30 ms 35584 KB Output is correct
27 Correct 31 ms 35616 KB Output is correct
28 Correct 31 ms 35584 KB Output is correct
29 Correct 33 ms 35584 KB Output is correct
30 Correct 31 ms 35584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 35584 KB Output is correct
2 Correct 25 ms 35584 KB Output is correct
3 Correct 24 ms 35584 KB Output is correct
4 Correct 24 ms 35584 KB Output is correct
5 Correct 24 ms 35576 KB Output is correct
6 Correct 26 ms 35712 KB Output is correct
7 Correct 24 ms 35584 KB Output is correct
8 Correct 24 ms 35584 KB Output is correct
9 Correct 26 ms 35584 KB Output is correct
10 Correct 29 ms 35712 KB Output is correct
11 Correct 42 ms 36216 KB Output is correct
12 Correct 30 ms 36096 KB Output is correct
13 Correct 34 ms 36096 KB Output is correct
14 Correct 29 ms 35584 KB Output is correct
15 Correct 28 ms 35584 KB Output is correct
16 Correct 30 ms 35712 KB Output is correct
17 Correct 30 ms 35584 KB Output is correct
18 Correct 28 ms 35704 KB Output is correct
19 Correct 29 ms 35584 KB Output is correct
20 Correct 28 ms 35584 KB Output is correct
21 Correct 29 ms 35584 KB Output is correct
22 Correct 30 ms 35968 KB Output is correct
23 Correct 30 ms 36096 KB Output is correct
24 Correct 28 ms 35584 KB Output is correct
25 Correct 29 ms 35576 KB Output is correct
26 Correct 31 ms 35584 KB Output is correct
27 Correct 29 ms 35712 KB Output is correct
28 Correct 27 ms 35584 KB Output is correct
29 Correct 27 ms 35584 KB Output is correct
30 Correct 27 ms 35584 KB Output is correct
31 Correct 26 ms 35712 KB Output is correct
32 Correct 939 ms 39672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 35584 KB Output is correct
2 Correct 733 ms 73080 KB Output is correct
3 Correct 574 ms 43308 KB Output is correct
4 Correct 535 ms 39672 KB Output is correct
5 Correct 397 ms 36604 KB Output is correct
6 Correct 600 ms 47864 KB Output is correct
7 Correct 528 ms 42096 KB Output is correct
8 Correct 612 ms 48120 KB Output is correct
9 Correct 539 ms 41976 KB Output is correct
10 Correct 570 ms 47736 KB Output is correct
11 Correct 490 ms 41724 KB Output is correct
12 Correct 140 ms 35832 KB Output is correct
13 Correct 31 ms 35584 KB Output is correct
14 Correct 32 ms 35584 KB Output is correct
15 Correct 35 ms 35584 KB Output is correct
16 Correct 35 ms 35584 KB Output is correct
17 Correct 53 ms 35712 KB Output is correct
18 Correct 174 ms 36480 KB Output is correct
19 Correct 46 ms 35576 KB Output is correct
20 Correct 68 ms 35640 KB Output is correct
21 Correct 71 ms 35584 KB Output is correct
22 Correct 69 ms 35648 KB Output is correct
23 Correct 372 ms 97400 KB Output is correct
24 Correct 958 ms 239548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 35584 KB Output is correct
2 Correct 733 ms 73080 KB Output is correct
3 Correct 574 ms 43308 KB Output is correct
4 Correct 535 ms 39672 KB Output is correct
5 Correct 397 ms 36604 KB Output is correct
6 Correct 600 ms 47864 KB Output is correct
7 Correct 528 ms 42096 KB Output is correct
8 Correct 612 ms 48120 KB Output is correct
9 Correct 539 ms 41976 KB Output is correct
10 Correct 570 ms 47736 KB Output is correct
11 Correct 490 ms 41724 KB Output is correct
12 Correct 140 ms 35832 KB Output is correct
13 Correct 31 ms 35584 KB Output is correct
14 Correct 32 ms 35584 KB Output is correct
15 Correct 35 ms 35584 KB Output is correct
16 Correct 35 ms 35584 KB Output is correct
17 Correct 53 ms 35712 KB Output is correct
18 Correct 174 ms 36480 KB Output is correct
19 Correct 46 ms 35576 KB Output is correct
20 Correct 68 ms 35640 KB Output is correct
21 Correct 71 ms 35584 KB Output is correct
22 Correct 69 ms 35648 KB Output is correct
23 Correct 372 ms 97400 KB Output is correct
24 Correct 958 ms 239548 KB Output is correct
25 Correct 952 ms 75636 KB Output is correct
26 Correct 1033 ms 55140 KB Output is correct
27 Correct 952 ms 45688 KB Output is correct
28 Correct 871 ms 37980 KB Output is correct
29 Correct 670 ms 36200 KB Output is correct
30 Correct 766 ms 37240 KB Output is correct
31 Correct 834 ms 66776 KB Output is correct
32 Correct 736 ms 51244 KB Output is correct
33 Correct 665 ms 51192 KB Output is correct
34 Correct 584 ms 43392 KB Output is correct
35 Correct 765 ms 66552 KB Output is correct
36 Correct 647 ms 51064 KB Output is correct
37 Correct 230 ms 35968 KB Output is correct
38 Correct 36 ms 35584 KB Output is correct
39 Correct 36 ms 36352 KB Output is correct
40 Runtime error 3350 ms 1048580 KB Execution killed with signal 9
41 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 35584 KB Output is correct
2 Correct 24 ms 35580 KB Output is correct
3 Correct 26 ms 35584 KB Output is correct
4 Correct 29 ms 35712 KB Output is correct
5 Correct 26 ms 35712 KB Output is correct
6 Correct 26 ms 35576 KB Output is correct
7 Correct 25 ms 35584 KB Output is correct
8 Correct 29 ms 37376 KB Output is correct
9 Correct 27 ms 35712 KB Output is correct
10 Correct 26 ms 35576 KB Output is correct
11 Correct 27 ms 35584 KB Output is correct
12 Correct 31 ms 35584 KB Output is correct
13 Correct 28 ms 35584 KB Output is correct
14 Correct 28 ms 35704 KB Output is correct
15 Correct 28 ms 35616 KB Output is correct
16 Correct 26 ms 35712 KB Output is correct
17 Correct 29 ms 35840 KB Output is correct
18 Correct 29 ms 36480 KB Output is correct
19 Correct 27 ms 35712 KB Output is correct
20 Correct 31 ms 36352 KB Output is correct
21 Correct 31 ms 36600 KB Output is correct
22 Correct 28 ms 36096 KB Output is correct
23 Correct 30 ms 36344 KB Output is correct
24 Correct 30 ms 36216 KB Output is correct
25 Correct 32 ms 36608 KB Output is correct
26 Correct 25 ms 35584 KB Output is correct
27 Correct 25 ms 35584 KB Output is correct
28 Correct 25 ms 35584 KB Output is correct
29 Correct 24 ms 35584 KB Output is correct
30 Correct 25 ms 35584 KB Output is correct
31 Correct 24 ms 35512 KB Output is correct
32 Correct 25 ms 35584 KB Output is correct
33 Correct 25 ms 35576 KB Output is correct
34 Correct 28 ms 35704 KB Output is correct
35 Correct 26 ms 35584 KB Output is correct
36 Correct 26 ms 35584 KB Output is correct
37 Correct 27 ms 35584 KB Output is correct
38 Correct 27 ms 35584 KB Output is correct
39 Correct 27 ms 35584 KB Output is correct
40 Correct 27 ms 35712 KB Output is correct
41 Correct 27 ms 35584 KB Output is correct
42 Correct 27 ms 35576 KB Output is correct
43 Correct 38 ms 39424 KB Output is correct
44 Correct 41 ms 39544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 35584 KB Output is correct
2 Correct 24 ms 35580 KB Output is correct
3 Correct 26 ms 35584 KB Output is correct
4 Correct 29 ms 35712 KB Output is correct
5 Correct 26 ms 35712 KB Output is correct
6 Correct 26 ms 35576 KB Output is correct
7 Correct 25 ms 35584 KB Output is correct
8 Correct 29 ms 37376 KB Output is correct
9 Correct 27 ms 35712 KB Output is correct
10 Correct 26 ms 35576 KB Output is correct
11 Correct 27 ms 35584 KB Output is correct
12 Correct 31 ms 35584 KB Output is correct
13 Correct 28 ms 35584 KB Output is correct
14 Correct 28 ms 35704 KB Output is correct
15 Correct 28 ms 35616 KB Output is correct
16 Correct 26 ms 35712 KB Output is correct
17 Correct 29 ms 35840 KB Output is correct
18 Correct 29 ms 36480 KB Output is correct
19 Correct 27 ms 35712 KB Output is correct
20 Correct 31 ms 36352 KB Output is correct
21 Correct 31 ms 36600 KB Output is correct
22 Correct 28 ms 36096 KB Output is correct
23 Correct 30 ms 36344 KB Output is correct
24 Correct 30 ms 36216 KB Output is correct
25 Correct 32 ms 36608 KB Output is correct
26 Correct 25 ms 35584 KB Output is correct
27 Correct 25 ms 35584 KB Output is correct
28 Correct 25 ms 35584 KB Output is correct
29 Correct 24 ms 35584 KB Output is correct
30 Correct 25 ms 35584 KB Output is correct
31 Correct 24 ms 35512 KB Output is correct
32 Correct 25 ms 35584 KB Output is correct
33 Correct 25 ms 35576 KB Output is correct
34 Correct 28 ms 35704 KB Output is correct
35 Correct 26 ms 35584 KB Output is correct
36 Correct 26 ms 35584 KB Output is correct
37 Correct 27 ms 35584 KB Output is correct
38 Correct 27 ms 35584 KB Output is correct
39 Correct 27 ms 35584 KB Output is correct
40 Correct 27 ms 35712 KB Output is correct
41 Correct 27 ms 35584 KB Output is correct
42 Correct 27 ms 35576 KB Output is correct
43 Correct 38 ms 39424 KB Output is correct
44 Correct 41 ms 39544 KB Output is correct
45 Correct 973 ms 46968 KB Output is correct
46 Correct 2801 ms 100572 KB Output is correct
47 Correct 1290 ms 83464 KB Output is correct
48 Correct 723 ms 36860 KB Output is correct
49 Correct 1044 ms 36860 KB Output is correct
50 Correct 716 ms 36216 KB Output is correct
51 Correct 26 ms 35584 KB Output is correct
52 Correct 26 ms 35584 KB Output is correct
53 Correct 62 ms 35584 KB Output is correct
54 Correct 41 ms 35584 KB Output is correct
55 Correct 574 ms 36520 KB Output is correct
56 Correct 1381 ms 37112 KB Output is correct
57 Correct 782 ms 36728 KB Output is correct
58 Correct 726 ms 36672 KB Output is correct
59 Correct 1293 ms 37016 KB Output is correct
60 Correct 585 ms 37752 KB Output is correct
61 Correct 1293 ms 62284 KB Output is correct
62 Execution timed out 5042 ms 57720 KB Time limit exceeded
63 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 35584 KB Output is correct
2 Correct 24 ms 35584 KB Output is correct
3 Correct 25 ms 35584 KB Output is correct
4 Correct 25 ms 35584 KB Output is correct
5 Correct 38 ms 35584 KB Output is correct
6 Correct 26 ms 35576 KB Output is correct
7 Correct 24 ms 35580 KB Output is correct
8 Correct 24 ms 35584 KB Output is correct
9 Correct 24 ms 35584 KB Output is correct
10 Correct 24 ms 35584 KB Output is correct
11 Correct 24 ms 35584 KB Output is correct
12 Correct 35 ms 35584 KB Output is correct
13 Correct 36 ms 35584 KB Output is correct
14 Correct 35 ms 35584 KB Output is correct
15 Correct 33 ms 35584 KB Output is correct
16 Correct 34 ms 35584 KB Output is correct
17 Correct 34 ms 35576 KB Output is correct
18 Correct 34 ms 35584 KB Output is correct
19 Correct 34 ms 35584 KB Output is correct
20 Correct 34 ms 35584 KB Output is correct
21 Correct 34 ms 35584 KB Output is correct
22 Correct 33 ms 35584 KB Output is correct
23 Correct 33 ms 35584 KB Output is correct
24 Correct 31 ms 35584 KB Output is correct
25 Correct 31 ms 35584 KB Output is correct
26 Correct 30 ms 35584 KB Output is correct
27 Correct 31 ms 35616 KB Output is correct
28 Correct 31 ms 35584 KB Output is correct
29 Correct 33 ms 35584 KB Output is correct
30 Correct 31 ms 35584 KB Output is correct
31 Correct 25 ms 35584 KB Output is correct
32 Correct 25 ms 35584 KB Output is correct
33 Correct 24 ms 35584 KB Output is correct
34 Correct 24 ms 35584 KB Output is correct
35 Correct 24 ms 35576 KB Output is correct
36 Correct 26 ms 35712 KB Output is correct
37 Correct 24 ms 35584 KB Output is correct
38 Correct 24 ms 35584 KB Output is correct
39 Correct 26 ms 35584 KB Output is correct
40 Correct 29 ms 35712 KB Output is correct
41 Correct 42 ms 36216 KB Output is correct
42 Correct 30 ms 36096 KB Output is correct
43 Correct 34 ms 36096 KB Output is correct
44 Correct 29 ms 35584 KB Output is correct
45 Correct 28 ms 35584 KB Output is correct
46 Correct 30 ms 35712 KB Output is correct
47 Correct 30 ms 35584 KB Output is correct
48 Correct 28 ms 35704 KB Output is correct
49 Correct 29 ms 35584 KB Output is correct
50 Correct 28 ms 35584 KB Output is correct
51 Correct 29 ms 35584 KB Output is correct
52 Correct 30 ms 35968 KB Output is correct
53 Correct 30 ms 36096 KB Output is correct
54 Correct 28 ms 35584 KB Output is correct
55 Correct 29 ms 35576 KB Output is correct
56 Correct 31 ms 35584 KB Output is correct
57 Correct 29 ms 35712 KB Output is correct
58 Correct 27 ms 35584 KB Output is correct
59 Correct 27 ms 35584 KB Output is correct
60 Correct 27 ms 35584 KB Output is correct
61 Correct 26 ms 35712 KB Output is correct
62 Correct 939 ms 39672 KB Output is correct
63 Correct 24 ms 35584 KB Output is correct
64 Correct 733 ms 73080 KB Output is correct
65 Correct 574 ms 43308 KB Output is correct
66 Correct 535 ms 39672 KB Output is correct
67 Correct 397 ms 36604 KB Output is correct
68 Correct 600 ms 47864 KB Output is correct
69 Correct 528 ms 42096 KB Output is correct
70 Correct 612 ms 48120 KB Output is correct
71 Correct 539 ms 41976 KB Output is correct
72 Correct 570 ms 47736 KB Output is correct
73 Correct 490 ms 41724 KB Output is correct
74 Correct 140 ms 35832 KB Output is correct
75 Correct 31 ms 35584 KB Output is correct
76 Correct 32 ms 35584 KB Output is correct
77 Correct 35 ms 35584 KB Output is correct
78 Correct 35 ms 35584 KB Output is correct
79 Correct 53 ms 35712 KB Output is correct
80 Correct 174 ms 36480 KB Output is correct
81 Correct 46 ms 35576 KB Output is correct
82 Correct 68 ms 35640 KB Output is correct
83 Correct 71 ms 35584 KB Output is correct
84 Correct 69 ms 35648 KB Output is correct
85 Correct 372 ms 97400 KB Output is correct
86 Correct 958 ms 239548 KB Output is correct
87 Correct 952 ms 75636 KB Output is correct
88 Correct 1033 ms 55140 KB Output is correct
89 Correct 952 ms 45688 KB Output is correct
90 Correct 871 ms 37980 KB Output is correct
91 Correct 670 ms 36200 KB Output is correct
92 Correct 766 ms 37240 KB Output is correct
93 Correct 834 ms 66776 KB Output is correct
94 Correct 736 ms 51244 KB Output is correct
95 Correct 665 ms 51192 KB Output is correct
96 Correct 584 ms 43392 KB Output is correct
97 Correct 765 ms 66552 KB Output is correct
98 Correct 647 ms 51064 KB Output is correct
99 Correct 230 ms 35968 KB Output is correct
100 Correct 36 ms 35584 KB Output is correct
101 Correct 36 ms 36352 KB Output is correct
102 Runtime error 3350 ms 1048580 KB Execution killed with signal 9
103 Halted 0 ms 0 KB -