답안 #1101869

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1101869 2024-10-17T05:30:07 Z simona1230 Toll (BOI17_toll) C++17
17 / 100
111 ms 22368 KB
// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;
int k,n,m,o;
vector<pair<int,int> > v[200001],op[200001];
void read()
{
    cin>>k>>n>>m>>o;
    for(int i=1;i<=m;i++)
    {
        int a,b,t;
        cin>>a>>b>>t;
        v[a].push_back({b,t});
        op[b].push_back({a,t});
    }
}


pair<int,int> q[200001];

long long p[200001];

void subt1()
{
    for(int i=0;i<n;i++)
    {
        p[i+1]=1e9;
        for(int j=0;j<v[i].size();j++)
        {
            long long nb=v[i][j].second;
            p[i+1]=min(p[i+1],nb);
        }
        p[i+1]+=p[i];
    }
    
    for(int i=1;i<=o;i++)
        if(p[q[i].second]-p[q[i].first]<1e9)cout<<p[q[i].second]-p[q[i].first]<<endl;
        else cout<<-1<<endl;
    exit(0);
}

long long dp[200001];

void subt2()
{
    int lm=n;
    for(int i=1;i<n;i++)
    {
        dp[i]=1e9;
        for(int j=0;j<op[i].size();j++)
        {
            pair<int,long long> nb=op[i][j];
            dp[i]=min(dp[i],dp[nb.first]+nb.second);
        }
    }
    
    for(int i=1;i<=o;i++)
        if(dp[q[i].second]<1e9)cout<<dp[q[i].second]<<endl;
        else cout<<-1<<endl;
    exit(0);
}

int lf=0;
void solve()
{
    for(int i=1;i<=o;i++)
    {
        cin>>q[i].first>>q[i].second;
        lf=min(lf,q[i].first);
    }
    
    if(k==1)subt1();
    if(lf==0)subt2();
    
    
}

int main() {
    read();
    solve();
    return 0;
}

Compilation message

toll.cpp: In function 'void subt1()':
toll.cpp:28:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         for(int j=0;j<v[i].size();j++)
      |                     ~^~~~~~~~~~~~
toll.cpp: In function 'void subt2()':
toll.cpp:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for(int j=0;j<op[i].size();j++)
      |                     ~^~~~~~~~~~~~~
toll.cpp:46:9: warning: unused variable 'lm' [-Wunused-variable]
   46 |     int lm=n;
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 15864 KB Output is correct
2 Correct 3 ms 12112 KB Output is correct
3 Correct 3 ms 12112 KB Output is correct
4 Correct 3 ms 12112 KB Output is correct
5 Correct 6 ms 12368 KB Output is correct
6 Correct 5 ms 12368 KB Output is correct
7 Correct 7 ms 12368 KB Output is correct
8 Correct 60 ms 15844 KB Output is correct
9 Correct 50 ms 15680 KB Output is correct
10 Correct 23 ms 12624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 17484 KB Output is correct
2 Correct 3 ms 12300 KB Output is correct
3 Correct 4 ms 12280 KB Output is correct
4 Correct 4 ms 12120 KB Output is correct
5 Correct 3 ms 12212 KB Output is correct
6 Correct 4 ms 12116 KB Output is correct
7 Correct 20 ms 12372 KB Output is correct
8 Correct 20 ms 12388 KB Output is correct
9 Correct 52 ms 16716 KB Output is correct
10 Correct 110 ms 21592 KB Output is correct
11 Correct 77 ms 19256 KB Output is correct
12 Correct 73 ms 18728 KB Output is correct
13 Correct 111 ms 22368 KB Output is correct
14 Correct 67 ms 19036 KB Output is correct
15 Correct 54 ms 18276 KB Output is correct
16 Correct 58 ms 18268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12112 KB Output is correct
2 Incorrect 3 ms 12112 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12112 KB Output is correct
2 Incorrect 3 ms 12112 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 15864 KB Output is correct
2 Correct 3 ms 12112 KB Output is correct
3 Correct 3 ms 12112 KB Output is correct
4 Correct 3 ms 12112 KB Output is correct
5 Correct 6 ms 12368 KB Output is correct
6 Correct 5 ms 12368 KB Output is correct
7 Correct 7 ms 12368 KB Output is correct
8 Correct 60 ms 15844 KB Output is correct
9 Correct 50 ms 15680 KB Output is correct
10 Correct 23 ms 12624 KB Output is correct
11 Correct 84 ms 17484 KB Output is correct
12 Correct 3 ms 12300 KB Output is correct
13 Correct 4 ms 12280 KB Output is correct
14 Correct 4 ms 12120 KB Output is correct
15 Correct 3 ms 12212 KB Output is correct
16 Correct 4 ms 12116 KB Output is correct
17 Correct 20 ms 12372 KB Output is correct
18 Correct 20 ms 12388 KB Output is correct
19 Correct 52 ms 16716 KB Output is correct
20 Correct 110 ms 21592 KB Output is correct
21 Correct 77 ms 19256 KB Output is correct
22 Correct 73 ms 18728 KB Output is correct
23 Correct 111 ms 22368 KB Output is correct
24 Correct 67 ms 19036 KB Output is correct
25 Correct 54 ms 18276 KB Output is correct
26 Correct 58 ms 18268 KB Output is correct
27 Correct 3 ms 12112 KB Output is correct
28 Incorrect 3 ms 12112 KB Output isn't correct
29 Halted 0 ms 0 KB -