Submission #466450

#TimeUsernameProblemLanguageResultExecution timeMemory
466450Killer2501Travelling Merchant (APIO17_merchant)C++14
0 / 100
131 ms3904 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define task "262144" #define pll pair<ll, ll> #define pi pair<pll, pll> #define fi first #define se second using namespace std; const ll mod = 1e16; const ll N = 1e2+5; const int base = 313; ll n, m, t, k, T, ans, tong, a[N], c[N][N], dp[N][N], b[N][N*10], s[N][N*10], w[N][N]; vector<ll> adj[N]; vector<ll> kq; ll pw(ll k, ll n) { ll total = 1; for(; n; n >>= 1) { if(n & 1)total = total * k % mod; k = k * k % mod; } return total; } bool check(ll x) { for(int i = 1; i <= n; i ++) { for(int j = 1; j <= n; j ++) { if(w[i][j] == mod)dp[i][j] = -mod; else dp[i][j] = c[i][j] - w[i][j] * x; } } for(int p = 1; p <= n; p ++) { for(int i = 1; i <= n; i ++) { for(int j = 1; j <= n; j ++) { dp[i][j] = max(dp[i][j], dp[i][p] + dp[p][j]); } } } for(int i = 1; i <= n; i ++) { for(int j = 1; j <= n; j ++) { if(i == j)continue; if(dp[i][j] + dp[j][i] >= 0)return true; } } return false; } void sol() { cin >> n >> m >> k; for(int i = 1; i <= n; i ++) { for(int j = 1; j <= k; j ++)cin >> b[i][j] >> s[i][j]; for(int j = 1; j <= n; j ++) { if(i == j)continue; w[i][j] = mod; } } while(m -- > 0) { ll x, y; cin >> x >> y; cin >> w[x][y]; } for(int p = 1; p <= n; p ++) { for(int i = 1; i <= n; i ++) { for(int j = 1; j <= n; j ++) { w[i][j] = min(w[i][j], w[i][p]+w[p][j]); } for(int j = 1; j <= k; j ++) { if(s[p][j] == -1 || b[i][j] == -1)continue; c[i][p] = max(c[i][p], s[p][j]-b[i][j]); } } } //for(int i = 1; i <= n; i ++)for(int j = 1; j <= n; j ++)cout << w[i][j] << " " << c[i][j] << '\n'; ll lf = 1, rt = mod, mid; while(lf <= rt) { mid = (lf + rt) / 2; if(check(mid))lf = mid + 1; else rt = mid - 1; } cout << rt; } int main() { if(fopen(task".in", "r")) { freopen(task".in", "r", stdin); freopen(task".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int ntest = 1; //cin >> ntest; while(ntest -- > 0) sol(); } /* 8 6 3 3 2 4 3 0 0 3 5 4 */

Compilation message (stderr)

merchant.cpp: In function 'int main()':
merchant.cpp:104:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |        freopen(task".in", "r", stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:105:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |        freopen(task".out", "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...