이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (ll) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge")))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n, m, K, buy[105][1005], sell[105][1005], dist[105][105], earn[105][105];
bool check(ll x) {
ll diff[105][105]; FOR(i, 1, n) FOR(j, 1, n) diff[i][j] = LLINF;
FOR(i, 1, n) FOR(j, 1, n) diff[i][j] = min(diff[i][j], dist[i][j] * x - earn[i][j]);
// how much you must earn to profit - how much you can earn
FOR(k, 1, n) FOR(i, 1, n) FOR(j, 1, n) diff[i][j] = min(diff[i][j], diff[i][k] + diff[k][j]);
FOR(i, 1, n) if (diff[i][i] <= 0) return 1;
return 0;
}
int main() {
fastio; cin >> n >> m >> K;
FOR(i, 1, n) FOR(k, 1, K) {
cin >> buy[i][k] >> sell[i][k];
if (buy[i][k] == -1) buy[i][k] = LLINF;
if (sell[i][k] == -1) sell[i][k] = -LLINF;
}
FOR(i, 1, n) FOR(j, 1, n) dist[i][j] = LLINF;
FOR(i, 1, m) {
ll a, b, c; cin >> a >> b >> c;
dist[a][b] = c;
}
FOR(k, 1, n) FOR(i, 1, n) FOR(j, 1, n) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
FOR(i, 1, n) FOR(j, 1, n) FOR(k, 1, K) earn[i][j] = max(earn[i][j], sell[j][k] - buy[i][k]);
ll lower = 0, upper = 1000000001;
while (upper - lower > 1) {
ll mid = (upper + lower)/2;
if (check(mid)) lower = mid;
else upper = mid;
}
cout << lower;
}
# | 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... |