제출 #312772

#제출 시각아이디문제언어결과실행 시간메모리
312772Kuuhaku여행하는 상인 (APIO17_merchant)C++17
0 / 100
78 ms1408 KiB
//Oct14
#define tasknames "merchant"
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = 105;
int n, m, k, b[maxn][maxn*10], s[maxn][maxn*10];
long long a[maxn][maxn], d[maxn][maxn], vl[maxn][maxn], maxx=1e10;

void Enter()
{
    cin>>n>>m>>k;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            a[i][j]=1e10;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=k; j++)
            cin>>b[i][j]>>s[i][j];
    for(int i=1; i<=m; i++)
    {
        int u, v, w;
        cin>>u>>v>>w;
        a[u][v]=min(a[u][v],1ll*w);
    }
}

void Prepare()
{
    for(int t=1; t<=n; t++)
        for(int i=1; i<=n; i++)
            for(int j=1; j<=n; j++)
                a[i][j]=min(a[i][j],a[i][t]+a[t][j]);
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            for(int t=1; t<=k; t++)
            {
                if(b[i][t]==-1||s[j][t]==-1)
                    continue;
                vl[i][j]=max(vl[i][j],1ll*s[j][t]-b[i][t]);
            }
}

bool Check(int mid)
{
    for (int i=1;i<=n;++i)
        for (int j=1;j<=n;++j)
        {
            d[i][j]=-1e10;
            if(a[i][j]==1e10)
                continue;
            d[i][j]=vl[i][j]-1ll*mid*a[i][j];
        }
    for (int t=1;t<=n;++t)
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= n; ++j)
                d[i][j] = max(d[i][j], d[i][t] + d[t][j]);
    for(int i=1;i<=n;++i)
        if(d[i][i]>=0)
            return true;
    return false;
}

void Solve()
{
    long long l=1, r=1e10, mid;
    while(l<=r)
    {
        mid=(l+r)/2;
        if(Check(mid))
            l=mid+1;
        else
            r=mid-1;
    }
    cout<<r;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if(fopen(tasknames".INP","r"))
    {
        freopen(tasknames".INP","r",stdin);
        freopen(tasknames".OUT","w",stdout);
    }
    Enter();
    Prepare();
    Solve();
}

컴파일 시 표준 에러 (stderr) 메시지

merchant.cpp: In function 'int main()':
merchant.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   86 |         freopen(tasknames".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   87 |         freopen(tasknames".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...