제출 #522242

#제출 시각아이디문제언어결과실행 시간메모리
522242ddy888여행하는 상인 (APIO17_merchant)C++17
0 / 100
27 ms1820 KiB
// code storage #undef _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define int long long #define pb push_back #define fi first #define si second #define ar array typedef pair<int,int> pi; typedef tuple<int,int,int> ti; void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H);debug_out(T...);} #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) const int INF = 1e9; int N, M, K; int B[110][110], S[110][110], profit[110][110]; vector<vector<int> > dist; void apsp(vector<vector<int> > V) { for (int k = 1; k <= N; ++k) { for (int i = 1; i <= N; ++i) { for (int j = 1; j <= N; ++j) { V[i][j] = min(V[i][j], V[i][k] + V[k][j]); } } } } bool good(int x) { // check profit - x * time >= 0 vector<vector<int> > V = dist; for (int i = 1; i <= N; ++i) { for (int j = 1; j <= N; ++j) { if (dist[i][j] == INF) continue; V[i][j] = profit[i][j] - dist[i][j] * x; debug(V[i][j]); } } apsp(V); for (int i = 1; i <= N; ++i) { debug(V[i][i], i); if (V[i][i] == INF || V[i][i] == 0) continue; if (V[i][i] >= 0) return 1; } return 0; } signed main() { fast; cin >> N >> M >> K; dist.resize(N + 1, vector<int>(N + 1, INF)); for (int i = 1; i <= N; ++i) { for (int j = 1; j <= K; ++j) { cin >> B[i][j] >> S[i][j]; } } for (int i = 1; i <= M; ++i) { int u, v, c; cin >> u >> v >> c; dist[u][v] = c; } apsp(dist); for (int i = 1; i <= N; ++i) { for (int j = 1; j <= N; ++j) { for (int k = 1; k <= K; ++k) { if (B[i][k] == -1 || S[j][k] == -1) continue; profit[i][j] = max(profit[i][j], S[j][k] - B[i][k]); } } } // int lo = 0, hi = 1e12; // while (lo + 1 < hi) { // int mid = (lo + hi) / 2; // if (good(mid)) lo = mid; // else hi = mid; // } // cout << lo; 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...