제출 #57278

#제출 시각아이디문제언어결과실행 시간메모리
57278IvanC여행하는 상인 (APIO17_merchant)C++17
21 / 100
188 ms2612 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 110; const int MAXM = 1010; const ll INF = 1e17; const ll LMAX = 1e13; ll compra[MAXN][MAXM],venda[MAXN][MAXM]; ll matriz[MAXN][MAXN],lucro[MAXN][MAXN]; int chega[MAXN][MAXN],tem_lucro[MAXN][MAXN],existe[MAXN][MAXN]; ll shortest_path[MAXN][MAXN]; int N,M,K; int FloydWarshall(ll X){ for(int i = 1;i<=N;i++){ for(int j = 1;j<=N;j++){ shortest_path[i][j] = INF; existe[i][j] = 0; } } for(int i = 1;i<=N;i++){ for(int j = 1;j<=N;j++){ if(!tem_lucro[i][j] || !chega[i][j]) continue; shortest_path[i][j] = X*matriz[i][j] - lucro[i][j]; existe[i][j] = 1; } } for(int k = 1;k<=N;k++){ for(int i = 1;i<=N;i++){ for(int j = 1;j<=N;j++){ if(!existe[i][k] || !existe[k][j]) continue; existe[i][j] |= 1; shortest_path[i][j] = min(shortest_path[i][j], shortest_path[i][k] + shortest_path[k][j] ); } } } for(int i = 1;i<=N;i++){ if(shortest_path[i][i] <= 0) return 1; } return 0; } ll bruta_par(int u,int v){ if(u == v) return -1; ll best = 0; for(int i = 1;i<=K;i++){ if(compra[u][i] != -1 && venda[v][i] != -1) best = max(best, venda[v][i] - compra[u][i] ); } return best; } void calcula_lucro(int v){ for(int i = 1;i<=N;i++){ lucro[v][i] = bruta_par(v,i); if(lucro[v][i] >= 0) tem_lucro[v][i] = 1; } } int main(){ scanf("%d %d %d",&N,&M,&K); for(int i = 1;i<=N;i++){ for(int j = 1;j<=N;j++){ matriz[i][j] = INF; } } for(int i = 1;i<=N;i++){ for(int j = 1;j<=K;j++){ scanf("%lld %lld",&compra[i][j],&venda[i][j]); } } //printf("Custos\n"); for(int i = 1;i<=N;i++) calcula_lucro(i); for(int i = 1;i<=M;i++){ int u,v; ll w; scanf("%d %d %lld",&u,&v,&w); matriz[u][v] = w; chega[u][v] = 1; } //printf("Leu\n"); for(int k = 1;k<=N;k++){ for(int i = 1;i<=N;i++){ for(int j = 1;j<=N;j++){ if(!chega[i][k] || !chega[k][j]) continue; chega[i][j] |= 1; matriz[i][j] = min(matriz[i][j],matriz[i][k] + matriz[k][j]); } } } //printf("Floyd\n"); //for(int i = 1;i<=N;i++){ // printf("%d :",i); // for(int j = 1;j<=N;j++){ // printf(" (%lld,%lld)", chega[i][j] ? (matriz[i][j]) : (-1), lucro[i][j] ); // } // printf("\n"); //} ll resposta = 0,ini = 1,fim = LMAX,meio; while(ini <= fim){ meio = ini + (fim - ini)/2; if(FloydWarshall(meio)){ resposta = meio; ini = meio + 1; } else{ fim = meio - 1; } } printf("%lld\n",resposta); return 0; }

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

merchant.cpp: In function 'int main()':
merchant.cpp:68:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&N,&M,&K);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
merchant.cpp:76:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld %lld",&compra[i][j],&venda[i][j]);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:84:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %lld",&u,&v,&w);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...