이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define _DE132BUG
// #include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
// using namespace atcoder;
#define endl "\n"
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<int> vi;
typedef vector<pii> vii;
const long double pi = acos(-1.0);
const int INF = 1987654321;
const ll LLINF = 2e18;
const double eps = 1e-9;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//
ll buy[104][2004];
ll sell[104][2004];
ll dist[104][104];
ll bs[104][104];
ld newdist[104][104];
struct Edge{
int u, v, weight;
bool operator<(Edge const& other){
return weight < other.weight;
}
};
int main(){
#ifdef _DEBUG
freopen ("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(NULL);
int N, M, K; cin >> N >> M >> K;
for(int i = 1; i <= N; i++){
for(int k = 0; k < K; k++){
cin >> buy[i][k] >> sell[i][k];
}
}
memset(dist, 0x3f, sizeof(dist));
while(M--){
ll u, v, w; cin >> u >> v >> w;
dist[u][v] = w;
}
for(int k = 1; k <= N; k++){
for(int i = 1; i <= N; i++){
for(int j = 1; j <= N; j++){
chmin(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
// item
for(int i = 1; i <= N; i++){
for(int j = 1; j <= N; j++){
for(int k = 0; k < K; k++){
if(sell[j][k] != -1 && buy[i][k] != -1){
chmax(bs[i][j], 1LL* sell[j][k]-buy[i][k]);
}
}
}
}
ld lo = 0, hi = 2e9;
for(int it = 0; it < 100; it++){
ld mid = (lo + hi) / 2;
for(int i = 1; i <= N; i++){
for(int j = 1; j <= N; j++){
if(dist[i][j] > 1e9+5) newdist[i][j] = -1e12;
else newdist[i][j] = bs[i][j]-mid*dist[i][j];
}
}
for(int k = 1; k <= N; k++){
for(int i = 1; i <= N; i++){
for(int j = 1; j <= N; j++){
chmax(newdist[i][j], newdist[i][k] + newdist[k][j]);
}
}
}
bool flag = false;
for(int i = 1; i <= N; i++){
if(newdist[i][i] >= 0){
flag = true;
break;
}
}
if(flag) lo = mid;
else hi = mid;
// cout << hi << endl;
}
// cout << hi d<< endl;
cout << (ll)floor(hi) << endl;
return 0;
}
# | 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... |