Submission #388357

#TimeUsernameProblemLanguageResultExecution timeMemory
388357talant117408Travelling Merchant (APIO17_merchant)C++17
0 / 100
20 ms3148 KiB
/* Code written by Talant I.D. */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; #define precision(n) fixed << setprecision(n) #define pb push_back #define ub upper_bound #define lb lower_bound #define mp make_pair #define eps (double)1e-9 #define PI 2*acos(0.0) #define endl "\n" #define sz(v) int((v).size()) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define OK cout << "OK" << endl; const int mod = 1e9+7; ll mode(ll a) { a %= mod; if (a < 0) a += mod; return a; } ll subt(ll a, ll b) { return mode(mode(a)-mode(b)); } ll add(ll a, ll b) { return mode(mode(a)+mode(b)); } ll mult(ll a, ll b) { return mode(mode(a)*mode(b)); } ll binpow(ll a, ll b, ll m) { ll res = 1; while (b) { if (b&1) res = ((res*a)%m+m)%m; a = ((a*a)%m+m)%m; b >>= 1; } return res; } void usaco(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); } const int N = 103, K = 1003; vector <pll> graph[N]; ll buy[N][K], sell[N][K], dist[N]; int n, k; void subtask1() { for (int i = 1; i <= n; i++) { dist[i] = 9e18; } dist[1] = 0; priority_queue <pll> K; K.push(mp(0, 1)); while (!K.empty()) { auto v = K.top().second; K.pop(); for (auto to : graph[v]) { if (dist[to.first] > dist[v]+to.second) { dist[to.first] = dist[v]+to.second; K.push(mp(-dist[to.first], to.first)); } } } int flag = 1; for (int i = 2; i <= n; i++) { for (int j = 1; j <= k; j++) { if (buy[i][j] != -1) { flag = 0; } } } if (!flag) return; ll ans = 0; for (int i = 2; i <= n; i++) { for (int j = 1; j <= k; j++) { if (sell[i][j] != -1) { ans = max(ans, (sell[i][j]-buy[1][j])/dist[i]/2); } } } cout << ans; exit(0); } int main() { do_not_disturb int m; cin >> n >> m >> k; for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { cin >> buy[i][j] >> sell[i][j]; } } for (int i = 0; i < m; i++) { ll x, y, t; cin >> x >> y >> t; graph[x].pb(mp(y, t)); graph[y].pb(mp(x, t)); } subtask1(); return 0; }

Compilation message (stderr)

merchant.cpp: In function 'void usaco(std::string)':
merchant.cpp:57:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   57 |     freopen((s+".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:58:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   58 |     freopen((s+".out").c_str(), "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...