답안 #292929

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
292929 2020-09-07T14:50:59 Z 문홍윤(#5817) 급행열차 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=4e16;

int sum, 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 qu){
    re=fr=0;
    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);
    vector<LL> tmp;
    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){
            tmp.eb(minn);
            tmp.eb(minn);
            st=minn;
        }
        else tmp[tmp.size()-1]=minn;
        pv[minnum]++;
    }
    press(tmp);
    dp[num].resize(tmp.size());
    for(int i=0; i<tmp.size(); i++)dp[num][i]=tmp[i];
}

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);
        a+=sum, b+=sum;
        link[a].eb(b, c);
        rlink[b].eb(a, c);
        indeg[b]++;
    }
    for(int i=sum+1; i<=sum+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[sum+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);
        a+=sum;
        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';
    }
    sum+=n;
    printf("%s\n", str+1);
    cl(q);
}

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

Compilation message

express.cpp: In function 'void merge_dp(int)':
express.cpp:39:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for(int i=0; i<pv.size(); i++){
      |                      ~^~~~~~~~~~
express.cpp:42: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]
   42 |             if(pv[i]==dp[nw].size())continue;
express.cpp:59:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for(int i=0; i<tmp.size(); i++)dp[num][i]=tmp[i];
      |                  ~^~~~~~~~~~~
express.cpp: In function 'void solve()':
express.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   63 |     scanf("%d %d %d %lld", &n, &m, &q, &p);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
express.cpp:66:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   66 |         scanf("%d %d %lld", &a, &b, &c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
express.cpp:85:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   85 |         scanf("%d %lld", &a, &s);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
express.cpp: In function 'int main()':
express.cpp:99:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   99 |     scanf("%d", &t);
      |     ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 35576 KB Output is correct
2 Correct 25 ms 35584 KB Output is correct
3 Correct 24 ms 35584 KB Output is correct
4 Correct 26 ms 35584 KB Output is correct
5 Correct 34 ms 35968 KB Output is correct
6 Correct 26 ms 35584 KB Output is correct
7 Correct 24 ms 35580 KB Output is correct
8 Correct 25 ms 35628 KB Output is correct
9 Correct 25 ms 35560 KB Output is correct
10 Correct 24 ms 35584 KB Output is correct
11 Correct 25 ms 35576 KB Output is correct
12 Correct 37 ms 36472 KB Output is correct
13 Correct 38 ms 36224 KB Output is correct
14 Correct 39 ms 36344 KB Output is correct
15 Correct 35 ms 36232 KB Output is correct
16 Correct 36 ms 36216 KB Output is correct
17 Correct 36 ms 36300 KB Output is correct
18 Correct 36 ms 36344 KB Output is correct
19 Correct 37 ms 36480 KB Output is correct
20 Correct 36 ms 36272 KB Output is correct
21 Correct 37 ms 36480 KB Output is correct
22 Correct 36 ms 36224 KB Output is correct
23 Correct 36 ms 36472 KB Output is correct
24 Correct 33 ms 36224 KB Output is correct
25 Correct 35 ms 36216 KB Output is correct
26 Correct 34 ms 36216 KB Output is correct
27 Correct 35 ms 36224 KB Output is correct
28 Correct 33 ms 36216 KB Output is correct
29 Correct 33 ms 36216 KB Output is correct
30 Correct 33 ms 36216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 35584 KB Output is correct
2 Correct 26 ms 35584 KB Output is correct
3 Correct 26 ms 35620 KB Output is correct
4 Correct 24 ms 35588 KB Output is correct
5 Correct 25 ms 35584 KB Output is correct
6 Correct 24 ms 35496 KB Output is correct
7 Correct 24 ms 35584 KB Output is correct
8 Correct 24 ms 35584 KB Output is correct
9 Correct 27 ms 35584 KB Output is correct
10 Correct 31 ms 35968 KB Output is correct
11 Correct 45 ms 36096 KB Output is correct
12 Correct 31 ms 35968 KB Output is correct
13 Correct 35 ms 36096 KB Output is correct
14 Correct 31 ms 35960 KB Output is correct
15 Correct 32 ms 35880 KB Output is correct
16 Correct 31 ms 36088 KB Output is correct
17 Correct 32 ms 36040 KB Output is correct
18 Correct 31 ms 36088 KB Output is correct
19 Correct 32 ms 35968 KB Output is correct
20 Correct 29 ms 36096 KB Output is correct
21 Correct 32 ms 35968 KB Output is correct
22 Correct 31 ms 35888 KB Output is correct
23 Correct 32 ms 35996 KB Output is correct
24 Correct 38 ms 35840 KB Output is correct
25 Correct 31 ms 35832 KB Output is correct
26 Correct 33 ms 35832 KB Output is correct
27 Correct 33 ms 35864 KB Output is correct
28 Correct 28 ms 35704 KB Output is correct
29 Correct 29 ms 35712 KB Output is correct
30 Correct 35 ms 35704 KB Output is correct
31 Correct 27 ms 35712 KB Output is correct
32 Correct 983 ms 38556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 35584 KB Output is correct
2 Correct 791 ms 73016 KB Output is correct
3 Correct 629 ms 71900 KB Output is correct
4 Correct 586 ms 71956 KB Output is correct
5 Correct 512 ms 70856 KB Output is correct
6 Correct 700 ms 70336 KB Output is correct
7 Correct 700 ms 72420 KB Output is correct
8 Correct 751 ms 72440 KB Output is correct
9 Correct 646 ms 71364 KB Output is correct
10 Correct 637 ms 71044 KB Output is correct
11 Correct 603 ms 70652 KB Output is correct
12 Correct 188 ms 49304 KB Output is correct
13 Correct 38 ms 36352 KB Output is correct
14 Correct 36 ms 36480 KB Output is correct
15 Correct 39 ms 36984 KB Output is correct
16 Correct 41 ms 36856 KB Output is correct
17 Correct 73 ms 39032 KB Output is correct
18 Correct 215 ms 52440 KB Output is correct
19 Correct 56 ms 38264 KB Output is correct
20 Correct 93 ms 40952 KB Output is correct
21 Correct 83 ms 41080 KB Output is correct
22 Correct 86 ms 41080 KB Output is correct
23 Correct 428 ms 91012 KB Output is correct
24 Correct 1063 ms 183888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 35584 KB Output is correct
2 Correct 791 ms 73016 KB Output is correct
3 Correct 629 ms 71900 KB Output is correct
4 Correct 586 ms 71956 KB Output is correct
5 Correct 512 ms 70856 KB Output is correct
6 Correct 700 ms 70336 KB Output is correct
7 Correct 700 ms 72420 KB Output is correct
8 Correct 751 ms 72440 KB Output is correct
9 Correct 646 ms 71364 KB Output is correct
10 Correct 637 ms 71044 KB Output is correct
11 Correct 603 ms 70652 KB Output is correct
12 Correct 188 ms 49304 KB Output is correct
13 Correct 38 ms 36352 KB Output is correct
14 Correct 36 ms 36480 KB Output is correct
15 Correct 39 ms 36984 KB Output is correct
16 Correct 41 ms 36856 KB Output is correct
17 Correct 73 ms 39032 KB Output is correct
18 Correct 215 ms 52440 KB Output is correct
19 Correct 56 ms 38264 KB Output is correct
20 Correct 93 ms 40952 KB Output is correct
21 Correct 83 ms 41080 KB Output is correct
22 Correct 86 ms 41080 KB Output is correct
23 Correct 428 ms 91012 KB Output is correct
24 Correct 1063 ms 183888 KB Output is correct
25 Correct 1010 ms 75720 KB Output is correct
26 Correct 1133 ms 112588 KB Output is correct
27 Correct 1114 ms 112140 KB Output is correct
28 Correct 1106 ms 111696 KB Output is correct
29 Correct 867 ms 91048 KB Output is correct
30 Correct 905 ms 91764 KB Output is correct
31 Correct 901 ms 104312 KB Output is correct
32 Correct 867 ms 104316 KB Output is correct
33 Correct 729 ms 79188 KB Output is correct
34 Correct 696 ms 79096 KB Output is correct
35 Correct 856 ms 104452 KB Output is correct
36 Correct 882 ms 104244 KB Output is correct
37 Correct 301 ms 63016 KB Output is correct
38 Correct 41 ms 37368 KB Output is correct
39 Correct 39 ms 37244 KB Output is correct
40 Execution timed out 5072 ms 1048580 KB Time limit exceeded
41 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 35584 KB Output is correct
2 Correct 25 ms 35616 KB Output is correct
3 Correct 26 ms 35712 KB Output is correct
4 Correct 30 ms 35712 KB Output is correct
5 Correct 26 ms 35712 KB Output is correct
6 Correct 26 ms 35584 KB Output is correct
7 Correct 26 ms 35584 KB Output is correct
8 Correct 34 ms 36608 KB Output is correct
9 Correct 30 ms 35968 KB Output is correct
10 Correct 30 ms 35704 KB Output is correct
11 Correct 28 ms 35808 KB Output is correct
12 Correct 30 ms 35812 KB Output is correct
13 Correct 30 ms 35840 KB Output is correct
14 Correct 29 ms 35968 KB Output is correct
15 Correct 30 ms 35964 KB Output is correct
16 Correct 31 ms 35712 KB Output is correct
17 Correct 32 ms 35832 KB Output is correct
18 Correct 32 ms 36216 KB Output is correct
19 Correct 28 ms 35712 KB Output is correct
20 Correct 30 ms 36224 KB Output is correct
21 Correct 36 ms 36352 KB Output is correct
22 Correct 28 ms 35968 KB Output is correct
23 Correct 35 ms 36248 KB Output is correct
24 Correct 30 ms 35968 KB Output is correct
25 Correct 37 ms 36472 KB Output is correct
26 Correct 26 ms 35712 KB Output is correct
27 Correct 25 ms 35584 KB Output is correct
28 Correct 25 ms 35584 KB Output is correct
29 Correct 25 ms 35584 KB Output is correct
30 Correct 25 ms 35584 KB Output is correct
31 Correct 26 ms 35584 KB Output is correct
32 Correct 25 ms 35584 KB Output is correct
33 Correct 26 ms 35584 KB Output is correct
34 Correct 28 ms 35832 KB Output is correct
35 Correct 28 ms 35840 KB Output is correct
36 Correct 27 ms 35840 KB Output is correct
37 Correct 27 ms 35840 KB Output is correct
38 Correct 29 ms 35840 KB Output is correct
39 Correct 28 ms 35968 KB Output is correct
40 Correct 28 ms 35968 KB Output is correct
41 Correct 30 ms 35968 KB Output is correct
42 Correct 28 ms 35968 KB Output is correct
43 Correct 40 ms 38264 KB Output is correct
44 Correct 41 ms 38392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 35584 KB Output is correct
2 Correct 25 ms 35616 KB Output is correct
3 Correct 26 ms 35712 KB Output is correct
4 Correct 30 ms 35712 KB Output is correct
5 Correct 26 ms 35712 KB Output is correct
6 Correct 26 ms 35584 KB Output is correct
7 Correct 26 ms 35584 KB Output is correct
8 Correct 34 ms 36608 KB Output is correct
9 Correct 30 ms 35968 KB Output is correct
10 Correct 30 ms 35704 KB Output is correct
11 Correct 28 ms 35808 KB Output is correct
12 Correct 30 ms 35812 KB Output is correct
13 Correct 30 ms 35840 KB Output is correct
14 Correct 29 ms 35968 KB Output is correct
15 Correct 30 ms 35964 KB Output is correct
16 Correct 31 ms 35712 KB Output is correct
17 Correct 32 ms 35832 KB Output is correct
18 Correct 32 ms 36216 KB Output is correct
19 Correct 28 ms 35712 KB Output is correct
20 Correct 30 ms 36224 KB Output is correct
21 Correct 36 ms 36352 KB Output is correct
22 Correct 28 ms 35968 KB Output is correct
23 Correct 35 ms 36248 KB Output is correct
24 Correct 30 ms 35968 KB Output is correct
25 Correct 37 ms 36472 KB Output is correct
26 Correct 26 ms 35712 KB Output is correct
27 Correct 25 ms 35584 KB Output is correct
28 Correct 25 ms 35584 KB Output is correct
29 Correct 25 ms 35584 KB Output is correct
30 Correct 25 ms 35584 KB Output is correct
31 Correct 26 ms 35584 KB Output is correct
32 Correct 25 ms 35584 KB Output is correct
33 Correct 26 ms 35584 KB Output is correct
34 Correct 28 ms 35832 KB Output is correct
35 Correct 28 ms 35840 KB Output is correct
36 Correct 27 ms 35840 KB Output is correct
37 Correct 27 ms 35840 KB Output is correct
38 Correct 29 ms 35840 KB Output is correct
39 Correct 28 ms 35968 KB Output is correct
40 Correct 28 ms 35968 KB Output is correct
41 Correct 30 ms 35968 KB Output is correct
42 Correct 28 ms 35968 KB Output is correct
43 Correct 40 ms 38264 KB Output is correct
44 Correct 41 ms 38392 KB Output is correct
45 Correct 953 ms 78456 KB Output is correct
46 Correct 2765 ms 89596 KB Output is correct
47 Correct 1277 ms 79788 KB Output is correct
48 Correct 824 ms 82552 KB Output is correct
49 Correct 1077 ms 60408 KB Output is correct
50 Correct 767 ms 60784 KB Output is correct
51 Correct 27 ms 35704 KB Output is correct
52 Correct 26 ms 35704 KB Output is correct
53 Correct 80 ms 39392 KB Output is correct
54 Correct 45 ms 36984 KB Output is correct
55 Correct 726 ms 71132 KB Output is correct
56 Correct 1601 ms 204292 KB Output is correct
57 Correct 942 ms 126708 KB Output is correct
58 Correct 814 ms 77560 KB Output is correct
59 Correct 1481 ms 188820 KB Output is correct
60 Correct 658 ms 75640 KB Output is correct
61 Correct 1491 ms 198020 KB Output is correct
62 Execution timed out 5031 ms 57848 KB Time limit exceeded
63 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 35576 KB Output is correct
2 Correct 25 ms 35584 KB Output is correct
3 Correct 24 ms 35584 KB Output is correct
4 Correct 26 ms 35584 KB Output is correct
5 Correct 34 ms 35968 KB Output is correct
6 Correct 26 ms 35584 KB Output is correct
7 Correct 24 ms 35580 KB Output is correct
8 Correct 25 ms 35628 KB Output is correct
9 Correct 25 ms 35560 KB Output is correct
10 Correct 24 ms 35584 KB Output is correct
11 Correct 25 ms 35576 KB Output is correct
12 Correct 37 ms 36472 KB Output is correct
13 Correct 38 ms 36224 KB Output is correct
14 Correct 39 ms 36344 KB Output is correct
15 Correct 35 ms 36232 KB Output is correct
16 Correct 36 ms 36216 KB Output is correct
17 Correct 36 ms 36300 KB Output is correct
18 Correct 36 ms 36344 KB Output is correct
19 Correct 37 ms 36480 KB Output is correct
20 Correct 36 ms 36272 KB Output is correct
21 Correct 37 ms 36480 KB Output is correct
22 Correct 36 ms 36224 KB Output is correct
23 Correct 36 ms 36472 KB Output is correct
24 Correct 33 ms 36224 KB Output is correct
25 Correct 35 ms 36216 KB Output is correct
26 Correct 34 ms 36216 KB Output is correct
27 Correct 35 ms 36224 KB Output is correct
28 Correct 33 ms 36216 KB Output is correct
29 Correct 33 ms 36216 KB Output is correct
30 Correct 33 ms 36216 KB Output is correct
31 Correct 25 ms 35584 KB Output is correct
32 Correct 26 ms 35584 KB Output is correct
33 Correct 26 ms 35620 KB Output is correct
34 Correct 24 ms 35588 KB Output is correct
35 Correct 25 ms 35584 KB Output is correct
36 Correct 24 ms 35496 KB Output is correct
37 Correct 24 ms 35584 KB Output is correct
38 Correct 24 ms 35584 KB Output is correct
39 Correct 27 ms 35584 KB Output is correct
40 Correct 31 ms 35968 KB Output is correct
41 Correct 45 ms 36096 KB Output is correct
42 Correct 31 ms 35968 KB Output is correct
43 Correct 35 ms 36096 KB Output is correct
44 Correct 31 ms 35960 KB Output is correct
45 Correct 32 ms 35880 KB Output is correct
46 Correct 31 ms 36088 KB Output is correct
47 Correct 32 ms 36040 KB Output is correct
48 Correct 31 ms 36088 KB Output is correct
49 Correct 32 ms 35968 KB Output is correct
50 Correct 29 ms 36096 KB Output is correct
51 Correct 32 ms 35968 KB Output is correct
52 Correct 31 ms 35888 KB Output is correct
53 Correct 32 ms 35996 KB Output is correct
54 Correct 38 ms 35840 KB Output is correct
55 Correct 31 ms 35832 KB Output is correct
56 Correct 33 ms 35832 KB Output is correct
57 Correct 33 ms 35864 KB Output is correct
58 Correct 28 ms 35704 KB Output is correct
59 Correct 29 ms 35712 KB Output is correct
60 Correct 35 ms 35704 KB Output is correct
61 Correct 27 ms 35712 KB Output is correct
62 Correct 983 ms 38556 KB Output is correct
63 Correct 25 ms 35584 KB Output is correct
64 Correct 791 ms 73016 KB Output is correct
65 Correct 629 ms 71900 KB Output is correct
66 Correct 586 ms 71956 KB Output is correct
67 Correct 512 ms 70856 KB Output is correct
68 Correct 700 ms 70336 KB Output is correct
69 Correct 700 ms 72420 KB Output is correct
70 Correct 751 ms 72440 KB Output is correct
71 Correct 646 ms 71364 KB Output is correct
72 Correct 637 ms 71044 KB Output is correct
73 Correct 603 ms 70652 KB Output is correct
74 Correct 188 ms 49304 KB Output is correct
75 Correct 38 ms 36352 KB Output is correct
76 Correct 36 ms 36480 KB Output is correct
77 Correct 39 ms 36984 KB Output is correct
78 Correct 41 ms 36856 KB Output is correct
79 Correct 73 ms 39032 KB Output is correct
80 Correct 215 ms 52440 KB Output is correct
81 Correct 56 ms 38264 KB Output is correct
82 Correct 93 ms 40952 KB Output is correct
83 Correct 83 ms 41080 KB Output is correct
84 Correct 86 ms 41080 KB Output is correct
85 Correct 428 ms 91012 KB Output is correct
86 Correct 1063 ms 183888 KB Output is correct
87 Correct 1010 ms 75720 KB Output is correct
88 Correct 1133 ms 112588 KB Output is correct
89 Correct 1114 ms 112140 KB Output is correct
90 Correct 1106 ms 111696 KB Output is correct
91 Correct 867 ms 91048 KB Output is correct
92 Correct 905 ms 91764 KB Output is correct
93 Correct 901 ms 104312 KB Output is correct
94 Correct 867 ms 104316 KB Output is correct
95 Correct 729 ms 79188 KB Output is correct
96 Correct 696 ms 79096 KB Output is correct
97 Correct 856 ms 104452 KB Output is correct
98 Correct 882 ms 104244 KB Output is correct
99 Correct 301 ms 63016 KB Output is correct
100 Correct 41 ms 37368 KB Output is correct
101 Correct 39 ms 37244 KB Output is correct
102 Execution timed out 5072 ms 1048580 KB Time limit exceeded
103 Halted 0 ms 0 KB -