답안 #147788

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
147788 2019-08-30T16:17:25 Z HellAngel 여행하는 상인 (APIO17_merchant) C++14
33 / 100
103 ms 4300 KB
#include <bits/stdc++.h>
#define int long long
const int maxn = 1e2 + 7;
const int maxk = 1e4 + 7;
const int Inf = 1e18;
using namespace std;

int dist[maxn][maxn], b[maxn][maxk], s[maxn][maxk], n, m, k, cost[maxn][maxk], gau[maxn][maxn];

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
    fill_n(&dist[0][0], maxn * maxn, Inf);
    cin >> n >> m >> k;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= k; j++) cin >> b[i][j] >> s[i][j];
        dist[i][i] = 0;
    }
    for(int i = 1; i <= m; i++)
    {
        int u, v, c;
        cin >> u >> v >> c;
        dist[u][v] = min(dist[u][v], c);
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            for(int k = 1; k <= n ; k++)
            {
                dist[i][j] = min(dist[i][j], max(dist[i][k] + dist[k][j], -Inf));
            }
        }
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            for(int type = 1; type <= k; type++)
            {
                if(s[i][type] == -1 || b[j][type] == -1) continue;
                cost[j][i] = max(cost[j][i], s[i][type] - b[j][type]);
            }
        }
    }
    int l = 0;
    int r = 1e9;
    while(l <= r)
    {
        int mid = l + r >> 1;
        /// check(mid)
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= n; j++)
            {
                if(dist[i][j] != Inf)
                gau[i][j] = mid * dist[i][j] - cost[i][j];
                else
                gau[i][j] = Inf;
            }
        }
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= n; j++)
            {
                for(int k = 1; k <= n; k++)
                {
                    gau[i][j] = min(gau[i][j], min(gau[i][k] + gau[k][j], Inf));
                }
            }
        }
        bool cac = false;
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= n; j++)
            {
                if(i == j) continue;
                if(gau[i][j] + gau[j][i] <= 0) cac = true;
            }
        }
        if(cac) l = mid + 1;
        else r = mid - 1;
    }
    cout << r;
}

Compilation message

merchant.cpp: In function 'int32_t main()':
merchant.cpp:53:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid = l + r >> 1;
                   ~~^~~
merchant.cpp:14:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:14:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 3964 KB Output is correct
2 Correct 49 ms 1528 KB Output is correct
3 Correct 49 ms 1400 KB Output is correct
4 Incorrect 9 ms 888 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 1144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 2224 KB Output is correct
2 Correct 103 ms 4300 KB Output is correct
3 Correct 52 ms 2036 KB Output is correct
4 Correct 56 ms 2296 KB Output is correct
5 Correct 56 ms 2296 KB Output is correct
6 Correct 52 ms 2040 KB Output is correct
7 Correct 10 ms 1272 KB Output is correct
8 Correct 1 ms 504 KB Output is correct
9 Correct 11 ms 1272 KB Output is correct
10 Correct 12 ms 1260 KB Output is correct
11 Correct 8 ms 1260 KB Output is correct
12 Correct 10 ms 1144 KB Output is correct
13 Correct 9 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 1144 KB Output isn't correct
2 Halted 0 ms 0 KB -