이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC Optimize "trapv"
#include <bits/stdc++.h>
using namespace std;
#define int long long
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
const int N = 110, K = 1010;
int nodes, edges, items;
int buy[N][K], sell[N][K];
int value[N][N], dist[N][N];
bool Check(long long x) {
long long efficiency[N][N];
for(int i = 0; i < N; i++) {
for(int j = 0; j < N; j++) {
efficiency[i][j] = -1e16;
}
}
for(int i = 1; i <= nodes; i++) {
for(int j = 1; j <= nodes; j++) {
if(dist[i][j] != 1e16) {
efficiency[i][j] = max(efficiency[i][j], value[i][j] - dist[i][j] * x);
}
}
}
for(int k = 1; k <= nodes; k++) {
for(int i = 1; i <= nodes; i++) {
for(int j = 1; j <= nodes; j++) {
efficiency[i][j] = max(efficiency[i][j], efficiency[i][k] + efficiency[k][j]);
}
}
}
/*cout << "Outputing the efficiency\n";
for(int i = 1; i <= nodes; i++) {
for(int j = 1; j <= nodes; j++) {
cout << efficiency[i][j] << " ";
}
cout << "\n";
}*/
for(int i = 1; i <= nodes; i++) {
if(efficiency[i][i] >= 0)
return true;
}
return false;
}
void Solve() {
for(int i = 0; i < N; i++) {
for(int j = 0; j < N; j++) {
dist[i][j] = 1e16;
value[i][j] = 0;
}
}
cin >> nodes >> edges >> items;
for(int i = 1; i <= nodes; i++) {
for(int j = 1; j <= items; j++) {
cin >> buy[i][j] >> sell[i][j];
}
}
for(int i = 1; i <= edges; i++) {
int v, u, w;
cin >> v >> u >> w;
dist[v][u] = w;
}
for(int k = 1; k <= nodes; k++) {
for(int i = 1; i <= nodes; i++) {
for(int j = 1; j <= nodes; j++) {
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
for(int item_number = 1; item_number <= items; item_number++) {
for(int buy_node = 1; buy_node <= nodes; buy_node++) {
for(int sell_node = 1; sell_node <= nodes; sell_node++) {
if(buy[buy_node][item_number] != -1 && sell[sell_node][item_number] != -1 && dist[buy_node][sell_node] != 1e15) {
value[buy_node][sell_node] = max(value[buy_node][sell_node], sell[sell_node][item_number] - buy[buy_node][item_number]);
}
}
}
}
/*cout << "Minimum distance to travel from a pair of indices (i, j) are as follows: \n";
for(int i = 1; i <= nodes; i++) {
for(int j = 1; j <= nodes; j++) {
cout << dist[i][j] << " ";
}
cout << "\n";
}
cout << "Maximum value which can be gained when travelling from i to j is as follows: \n";
for(int i = 1; i <= nodes; i++) {
for(int j = 1; j <= nodes; j++) {
cout << value[i][j] << " ";
}
cout << "\n";
}*/
int ans = 0;
int left = 0, right = 1e10;
while(left <= right) {
int mid = (left + right) >> 1;
if(Check(mid)) {
ans = mid;
left = mid + 1;
}
else {
right = mid - 1;
}
}
cout << ans << "\n";
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
Solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
merchant.cpp:1: warning: ignoring '#pragma GCC Optimize' [-Wunknown-pragmas]
1 | #pragma GCC Optimize "trapv"
|
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |