제출 #50747

#제출 시각아이디문제언어결과실행 시간메모리
50747ayhcbagnop여행하는 상인 (APIO17_merchant)C++14
100 / 100
126 ms1676 KiB
//Power Of Ninja Go #include <bits/stdc++.h> //#ifdef atom #else #endif using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector< ii > vii; #define X first #define Y second #define pb push_back const int maxn = 105; const int maxk = 1005; int dist[maxn][maxn]; int buy[maxn][maxk]; int sell[maxn][maxk]; ll prof[maxn][maxn]; ll aug[maxn][maxn]; int n, m, k; bool works(ll x) { //printf("x = %lld\n", x); for(int i = 1; i<= n; i++) { for(int j = 1; j<= n; j++) { aug[i][j] = 1LL*x*dist[i][j] - prof[i][j]; //printf("aug[%d][%d] = %lld\n", i, j, aug[i][j]); } } for(int k = 1; k<= n; k++) for(int i = 1; i<= n; i++) for(int j = 1; j<= n; j++) aug[i][j] = min(aug[i][j], aug[i][k]+aug[k][j]); for(int i = 1; i<= n; i++) if(aug[i][i]<= 0) return true; return false; } int main() { scanf("%d %d %d", &n, &m, &k); for(int i = 1; i<= n; i++) for(int j = 1; j<= n; j++) dist[i][j] = 1e9; for(int i = 1; i<= n; i++) { for(int j = 1; j<= k; j++) scanf("%d %d", &buy[i][j], &sell[i][j]); } while(m--) { int u, v, w; scanf("%d %d %d", &u, &v, &w); dist[u][v] = min(dist[u][v], w); } for(int k = 1; k<= n; k++) for(int i = 1; i<= n; i++) for(int j = 1; j<= n; j++) dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]); for(int i = 1; i<= n; i++) for(int j = 1; j<= n; j++) prof[i][j] = 0; for(int i = 1; i<= n; i++) { for(int j = 1; j<= n; j++) { for(int prod = 1; prod<= k; prod++) { if(buy[i][prod] == -1 || sell[j][prod] == -1) continue; prof[i][j] = max(prof[i][j], 1LL*sell[j][prod]-buy[i][prod]); } //printf("prof[%d][%d] = %lld\n", i, j, prof[i][j]); } } ll lo = 0, hi = 1e9; while(lo< hi) { ll mid = (lo+hi+1)/2; if(works(mid)) lo = mid; else hi = mid-1; } printf("%lld\n", lo); }

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

merchant.cpp: In function 'int main()':
merchant.cpp:35:10: 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:39:41: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         for(int j = 1; j<= k; j++) scanf("%d %d", &buy[i][j], &sell[i][j]);
                                    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:43:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int u, v, w; scanf("%d %d %d", &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...