제출 #656983

#제출 시각아이디문제언어결과실행 시간메모리
656983Iliya여행하는 상인 (APIO17_merchant)C++17
100 / 100
99 ms3828 KiB
#include<bits/stdc++.h>
using namespace std;
 
const int N = 1e2 + 2;
const int K = 1e3 + 3;
const long long INF = LONG_LONG_MAX / 2;
long long buy[N][K] , sel[N][K] , d[N][N] , sod[N][N] , dp[N][N] , val;
int n , m , k;
 
bool f(int x){
    for(int u = 1 ; u <= n ; u++)
        for(int v = 1 ; v <= n ; v++){
          if(d[u][v] == INF)
			dp[u][v] = INF;            
          else
                dp[u][v] = d[u][v] * x - sod[u][v];
        }
     for(int w = 1 ; w <= n ; w++)
        for(int u = 1 ; u <= n ; u++)
            for(int v = 1 ; v <= n ; v++)
                dp[u][v] = min(dp[u][v] , dp[u][w] + dp[w][v]);
    bool ch = false;
    for(int u = 1 ; u <= n ; u++)
        if(dp[u][u] <= 0)
            ch = true;
    return ch;
}
 
int main(){
    ios::sync_with_stdio(0), cout.tie(0), cin.tie(0);
    memset(buy , -1 , sizeof(buy));
    memset(sel , -1 , sizeof(sel));
    val = d[0][0];
    cin >> n >> m >> k;
    for(int i = 1 ; i <= n ; i++)
        for(int j = 1 ; j <= k ; j++)
            cin >> buy[i][j] >> sel[i][j];
    for(int i = 1 ; i <= n ; i++)
        for(int j = 1 ; j <= n ; j++)
            for(int p = 1 ; p <= k ; p++)
                if(buy[i][p] != -1 && sel[j][p] != -1)
                    sod[i][j] = max(sod[i][j] , sel[j][p] - buy[i][p]);
  	for(int i = 1; i <= n; i++)
      for(int j = 1; j <= n; j++)
        d[i][j] = INF;
    for(int i = 1 ; i <= m ; i++){
        int u , v;
        long long w;
        cin >> u >> v >> w;
        d[u][v] = w;
    }
    for(int w = 1 ; w <= n ; w++)
        for(int u = 1 ; u <= n ; u++)
            for(int v = 1 ; v <= n ; v++)
                d[u][v] = min(d[u][v] , d[u][w] + d[w][v]);
    int low = 0 , high = 1e9;
    while(high - low > 1){
        int mid = (high + low) >> 1;
        if(f(mid))
            low = mid;
        else
            high = mid;
    }
    cout << low << '\n';
    return 0;
}

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

merchant.cpp: In function 'int main()':
merchant.cpp:38:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   38 |     for(int i = 1 ; i <= n ; i++)
      |     ^~~
merchant.cpp:43:4: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   43 |    for(int i = 1; i <= n; i++)
      |    ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...