답안 #1101865

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1101865 2024-10-17T05:24:09 Z simona1230 Toll (BOI17_toll) C++17
0 / 100
57 ms 17484 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];

int p[200001];

void subt1()
{
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<v[i].size();j++)
        {
            int 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++)
        cout<<p[q[i].second]-p[q[i].first]<<endl;
}

int dp[200001];

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

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==1)subt2();
    
    
}

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

Compilation message

toll.cpp: In function 'void subt1()':
toll.cpp:27: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]
   27 |         for(int j=0;j<v[i].size();j++)
      |                     ~^~~~~~~~~~~~
toll.cpp: In function 'void subt2()':
toll.cpp:46: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]
   46 |         for(int j=0;j<op[i].size();j++)
      |                     ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 47 ms 16744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 57 ms 17484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 12628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 12628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 47 ms 16744 KB Output isn't correct
2 Halted 0 ms 0 KB -