Submission #292835

# Submission time Handle Problem Language Result Execution time Memory
292835 2020-09-07T14:06:08 Z 문홍윤(#5817) Express 20/19 (ROI19_express) C++17
0 / 100
713 ms 73004 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=5e16;

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)+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 25 ms 35584 KB Output is correct
2 Runtime error 68 ms 71804 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 35584 KB Output is correct
2 Correct 24 ms 35584 KB Output is correct
3 Runtime error 69 ms 71928 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 35580 KB Output is correct
2 Correct 713 ms 73004 KB Output is correct
3 Correct 577 ms 43256 KB Output is correct
4 Correct 505 ms 39672 KB Output is correct
5 Correct 399 ms 36472 KB Output is correct
6 Correct 610 ms 47932 KB Output is correct
7 Correct 531 ms 42104 KB Output is correct
8 Correct 637 ms 48120 KB Output is correct
9 Correct 560 ms 41848 KB Output is correct
10 Correct 567 ms 47736 KB Output is correct
11 Correct 501 ms 41592 KB Output is correct
12 Correct 139 ms 35712 KB Output is correct
13 Runtime error 75 ms 71928 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 35580 KB Output is correct
2 Correct 713 ms 73004 KB Output is correct
3 Correct 577 ms 43256 KB Output is correct
4 Correct 505 ms 39672 KB Output is correct
5 Correct 399 ms 36472 KB Output is correct
6 Correct 610 ms 47932 KB Output is correct
7 Correct 531 ms 42104 KB Output is correct
8 Correct 637 ms 48120 KB Output is correct
9 Correct 560 ms 41848 KB Output is correct
10 Correct 567 ms 47736 KB Output is correct
11 Correct 501 ms 41592 KB Output is correct
12 Correct 139 ms 35712 KB Output is correct
13 Runtime error 75 ms 71928 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 35584 KB Output is correct
2 Correct 24 ms 35496 KB Output is correct
3 Correct 26 ms 35584 KB Output is correct
4 Correct 29 ms 35704 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 Runtime error 71 ms 72056 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 35584 KB Output is correct
2 Correct 24 ms 35496 KB Output is correct
3 Correct 26 ms 35584 KB Output is correct
4 Correct 29 ms 35704 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 Runtime error 71 ms 72056 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 35584 KB Output is correct
2 Runtime error 68 ms 71804 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -