제출 #555145

#제출 시각아이디문제언어결과실행 시간메모리
555145nutella여행하는 상인 (APIO17_merchant)C++17
12 / 100
710 ms1176 KiB
//#define _GLIBCXX_DEBUG //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> using namespace std; //#include <ext/pb_ds/assoc_container.hpp> // //using namespace __gnu_pbds; // //template<typename T> //using ordered_set = tree<T, null_type, less < T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename T> using normal_queue = priority_queue<T, vector<T>, greater<>>; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); #define ll long long #define trace(x) cout << #x << ": " << (x) << endl; #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define uniq(x) x.resize(unique(all(x)) - begin(x)) #define ld long double #define sz(s) ((int) size(s)) #define pii pair<int, int> #define mp(x, y) make_pair(x, y) #define int128 __int128 #define pb push_back #define eb emplace_back #define fi first #define se second template<typename T> bool ckmn(T &x, T y) { if (x > y) { x = y; return true; } return false; } template<typename T> bool ckmx(T &x, T y) { if (x < y) { x = y; return true; } return false; } int bit(int x, int b) { return (x >> b) & 1; } int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; } const ll infL = 3e18; const int infI = 1000000000 + 7; const int infM = 2139062143; const ll infML = 9187201950435737471LL; const int maxN = 101, maxK = 1001; const ll mod = 998244353; const ld eps = 1e-9; int N, M, K, b[maxN][maxK], s[maxN][maxK], dist[maxN][maxN], bb[maxN][maxN]; pair<ll, ll> dp[2][maxN]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> M >> K; for (int i = 0; i < N; ++i) { for (int j = 0; j < K; ++j) { cin >> b[i][j] >> s[i][j]; } fill(dist[i], dist[i] + N, infI); dist[i][i] = 0; } for (int i = 0; i < M; ++i) { int a, v, w; cin >> a >> v >> w; --a, --v; dist[a][v] = w; } for (int k = 0; k < N; ++k) for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) if (dist[i][k] != infI && dist[k][j] != infI) ckmn(dist[i][j], dist[i][k] + dist[k][j]); for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { for (int k = 0; k < K; ++k) { if (b[i][k] != -1 && s[j][k] != -1) ckmx(bb[i][j], s[j][k] - b[i][k]); } } } ll ans = 0; for (int v = 0; v < N; ++v) { auto mxx = [](pair<ll, ll> &a, pair<ll, ll> b) { if (b == mp(-infL, -infL)) return; if (a == mp(-infL, -infL)) { a = b; return; } if (((ld)a.first / a.second) < ((ld)b.first < b.second)) a = b; }; for (int i = 0; i < N; ++i) { dp[0][i] = {-infL, -infL}; } dp[0][v] = {0, 0}; for (int mv = 1; mv < 2 * N + 3; ++mv) { int nw = mv & 1; int prv = nw ^ 1; for (int i = 0; i < N; ++i) { dp[nw][i] = {-infL, -infL}; for (int j = 0; j < N; ++j) { pair<ll, ll> now = dp[prv][j]; if (now == mp(-infL, -infL)) continue; now.first += bb[j][i]; now.second += dist[j][i]; mxx(dp[nw][i], now); } } if (dp[nw][v] != mp(-infL, -infL) && dp[nw][v].first > 0) ckmx(ans, dp[nw][v].first / dp[nw][v].second); } } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...