이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sep ' '
#define endl '\n'
#define SZ(x) ll(x.size())
const ll MAXN = 100 + 10;
const ll MAXK = 1000 + 10;
const ll LOG = 22;
const ll INF = 2e18;
const ll MOD = 1e9 + 7; //998244353; //1e9 + 9;
ll n , m , k , adj[2][MAXN][MAXN] , cost[MAXN][MAXN] , sell[MAXN][MAXK] , buy[MAXN][MAXK];
void floyd(int ind){
for(int k = 0 ; k < n ; k++){
for(int i = 0 ; i < n ; i++){
for(int j = 0 ; j < n ; j++){
adj[ind][i][j] = min(adj[ind][i][j] , adj[ind][i][k] + adj[ind][k][j]);
}
}
}
}
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin >> n >> m >> k;
for(int i = 0 ; i < n ; i++){
for(int j = 0 ; j < k ; j++){
cin >> buy[i][j] >> sell[i][j];
}
fill(adj[0][i] , adj[0][i] + MAXN , INF);
//adj[0][i][i] = 0;
}
for(int i = 0 ; i < m ; i++){
int v , u , w;
cin >> v >> u >> w; v--; u--;
adj[0][v][u] = w;
}
for(int i = 0 ; i < n ; i++){
for(int j = 0 ; j < n ; j++){
cost[i][j] = 0;
for(int l = 0 ; l < k ; l++){
if(buy[i][l] == -1 || sell[j][l] == -1) continue;
cost[i][j] = min(cost[i][j] , buy[i][l] - sell[j][l]);
}
// cout << i << sep << j << sep << cost[i][j] << endl;
}
}
floyd(0);
ll l = 0 , r = 1e11 + 10;
while(r - l > 1){
ll mid = l + r >> 1;
// cout << mid << endl;
for(int i = 0 ; i < n ; i++){
for(int j = 0 ; j < n ; j++){
adj[1][i][j] = min(INF , adj[0][i][j] * mid + cost[i][j]);
// cout << i << sep << j << sep << adj[0][i][j] << sep << adj[1][i][j] << endl;
}
}
// cout << "==============" << endl;
floyd(1);
int flag = 0;
for(int i = 0 ; i < n ; i++) if(adj[1][i][i] <= 0) flag = 1;
if(flag) l = mid;
else r = mid;
}
cout << l << endl;
return 0;
}
/*
*/
컴파일 시 표준 에러 (stderr) 메시지
merchant.cpp: In function 'int main()':
merchant.cpp:62:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
62 | ll mid = l + r >> 1;
| ~~^~~
# | 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... |