Submission #106198

#TimeUsernameProblemLanguageResultExecution timeMemory
106198ekremTravelling Merchant (APIO17_merchant)C++98
100 / 100
525 ms4088 KiB
#include <bits/stdc++.h> #define st first #define nd second #define mp make_pair #define pb push_back #define orta ((bas+son+1)/2) #define linf 10000000000000000ll #define inf 1000000007 #define N 1005 using namespace std; typedef long long ll; typedef pair < int , int > ii; ll n, m, k, mx, bas, son, a[N][N+N], d[105][105], dd[105][105]; bool yap(int x){ for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++){ if(i == j){ dd[i][i] = -linf; continue; } mx = 0; for(int y = 1; y <= k+k; y += 2) if(a[i][y] != -1 and a[j][y + 1] != -1) mx = max(mx, a[j][y + 1] - a[i][y]); dd[i][j] = mx - x*d[i][j]; // cout << i << " " << j << " " << d[i][j] << " " << mx << endl; } for(int k = 1; k <= n; k++) for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) dd[i][j] = max(dd[i][j], dd[i][k] + dd[k][j] ); // for(int i = 1; i <= n; i++) // for(int j = 1; j <= n; j++) // cout << i << " " << j << " " << dd[i][j] << endl; for(int i = 1; i <= n; i++) if(dd[i][i] >= 0) return true; return false; } int main() { // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); scanf("%lld %lld %lld",&n ,&m ,&k); for(int i = 1; i <= n; i++) for(int j = 1; j <= k+k; j++) scanf("%lld",&a[i][j]); for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++){ d[i][j] = inf; d[i][i] = 0; } for(int i = 1; i <= m; i++){ ll x, y, z; scanf("%lld %lld %lld",&x ,&y ,&z); d[x][y] = min(d[x][y], z); } for(int k = 1; k <= n; k++) for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]); // yap(2); // cout << yap(4) << endl; bas = 0, son = 1000000007; while(bas < son){ if(yap(orta)) bas = orta; else son = orta - 1; } printf("%lld\n", bas); return 0; }

Compilation message (stderr)

merchant.cpp: In function 'int main()':
merchant.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld %lld",&n ,&m ,&k);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:52:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld",&a[i][j]);
    ~~~~~^~~~~~~~~~~~~~~~~
merchant.cpp:63:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld %lld",&x ,&y ,&z);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...