제출 #775319

#제출 시각아이디문제언어결과실행 시간메모리
775319vjudge1여행하는 상인 (APIO17_merchant)C++17
12 / 100
15 ms2004 KiB
#include<bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef double db; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define pbds tree<pair<ll, ll>, null_type, less<pair<ll,ll>>,rb_tree_tag, tree_order_statistics_node_update> using namespace __gnu_pbds; ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} // greatest common divisor (PGCD) ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);} // least common multiple (PPCM) int dx[8] = {1, 0, 0, -1, 1, 1, -1, -1}; int dy[8] = {0, 1, -1, 0, 1, -1, -1, 1}; #define endl "\n" #define ss second #define ff first #define all(x) (x).begin() , (x).end() #define pb push_back #define vi vector<int> #define vii vector<pair<int,int>> #define vl vector<ll> #define vll vector<pair<ll,ll>> #define pii pair<int,int> #define pll pair<ll,ll> #define pdd pair<double,double> #define vdd vector<pdd> #define speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; ////////////////////Only Clear Code////////////////////////// void usaco_problem(){ freopen("milkvisits.in", "r", stdin); freopen("milkvisits.out", "w", stdout); } void init(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // ONLINE_JUDGE } const int mx = 105; const int LOG = 25; const ll inf = 1e18; const ll mod = 1e8; int n, m, k; vl B[mx], S[mx]; vii graph[mx]; ll adj[mx][mx]; ll distances[mx][mx]; void run_case(){ cin >> n >> m >> k; for(int i = 1; i <= n;i++){ for(int j = 0; j < k;j++){ int x;cin >> x; B[i].pb(x); cin >> x; S[i].pb(x); } } memset(adj, -1, sizeof adj); while(m--){ int a, b, w;cin >> a >> b >> w; adj[a][b] = w; } for(int i = 1; i <= n;i++){ for(int j = 1; j <= n;j++){ if(i == j)distances[i][j] = 0; else if(adj[i][j] != -1)distances[i][j] = adj[i][j]; else distances[i][j] = inf; } } for(int k = 1; k <= n;k++){ for(int i = 1; i <= n;i++){ for(int j = 1; j <= n;j++){ distances[i][j] = min(distances[i][j], distances[i][k]+distances[k][j]); } } } ll ans = 0; ll cyd = inf; for(int i = 2; i <= n;i++){ if(distances[1][i] != inf && distances[i][1] != inf){ ll x = distances[1][i] + distances[i][1]; cyd = min(cyd, x); ll cost = 0; for(int j = 0;j < k;j++){ if(B[1][j] != -1 && S[i][j] != -1){ cost = max(cost, S[i][j] - B[1][j]); } } ans = max(ans, cost/x); } } ll cost = 0; for(int i = 0; i < k;i++){ if(B[1][i] != -1 && S[1][i] != -1){ cost = max(cost, S[1][i] - B[1][i]); } } ans = max(ans, cost / cyd); cout << ans << endl; } int main(){ //init(); speed; int t; //cin >> t; t = 1; while(t--){ run_case(); } } /* NEVER GIVE UP! DOING SMTHNG IS BETTER THAN DOING NTHNG!!! Your Guide when stuck: - Continue keyword only after reading the whole input - Don't use memset with testcases - Check for corner cases(n=1, n=0) - Check where you declare n(Be careful of declaring it globally and in main) */

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

merchant.cpp: In function 'void usaco_problem()':
merchant.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     freopen("milkvisits.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     freopen("milkvisits.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp: In function 'void init()':
merchant.cpp:39:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 | freopen("input.txt", "r", stdin);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:41:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 | freopen("output.txt", "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...