이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define loli
using namespace std;
typedef long long ll;
#define int ll
#define pii pair<int, int>
#define X first
#define Y second
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define eb emplace_back
#define push emplace
#define lb(x, v) lower_bound(ALL(x), v)
#define ub(x, v) upper_bound(ALL(x), v)
#define re(x) reverse(ALL(x))
#define uni(x) x.resize(unique(ALL(x)) - x.begin())
#define inf 1000000000
#define INF 1000000000000000000
#define mod 1000000007
#define get_bit(x, y) ((x>>y)&1)
#define mkp make_pair
#define IO ios_base::sync_with_stdio(0); cin.tie(0);
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
for (; l != r; ++l) cout << *l << " \n"[l + 1 == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
return o >> a.X >> a.Y;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
return o << '(' << a.X << ", " << a.Y << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
bool is = false;
if (a.empty()) return o << "{}";
for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
return o << '}';
}
#ifdef loli
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif
const int mxN = 100 + 5, mxK = 1000 + 5;
int n, m, k, b[mxN][mxK], s[mxN][mxK];
int dp[mxN][mxK];
int profit[mxN][mxN];
int mat[mxN][mxN], tmp[mxN][mxN];
int check(int thres) {
for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) {
if (mat[i][j] != INF) tmp[i][j] = profit[i][j] - mat[i][j] * thres;
else tmp[i][j] = -INF;
}
for (int x = 1; x <= n; x++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) {
tmp[i][j] = max(tmp[i][j], tmp[i][x] + tmp[x][j]);
}
int ans = -INF;
for (int i = 1; i <= n; i++) ans = max(ans, tmp[i][i]);
// test(thres, ans);
return ans >= 0;
}
inline void solve() {
cin >> n >> m >> k;
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 <= n; i++) for (int j = 1; j <= n; j++) for (int c = 1; c <= k; c++) {
if (b[i][c] != -1 and s[j][c] != -1)
profit[i][j] = max(profit[i][j], s[j][c] - b[i][c]);
}
for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) mat[i][j] = INF;
for (int i = 0; i < m; i++) {
int u, v, t;
cin >> u >> v >> t;
mat[u][v] = t;
}
// binary search
int l = 0, r = 1e9 + 1;
while (l < r) {
int mid = (l + r + 1) >> 1;
if (check(mid)) l = mid;
else r = mid - 1;
}
cout << l << '\n';
}
signed main() {
IO;
solve();
}
# | 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... |