이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define emb emplace_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline T range(T l, T r) {
return uniform_int_distribution<T>(l, r)(rng);
}
template <typename T> void Min(T &a, T b) {
a = min(a, b);
}
template <typename T> void Max(T &a, T b) {
a = max(a, b);
}
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e15;
const int N = 1e2 + 15;
const int K = 1e3 + 15;
int n, m, k, buy[N][K], sell[N][K];
int g[N][N];
int mx[N][N], d[N][N];
int dp[N][N];
bool used[N];
bool check(int mid) {
for(int i = 0; i < N; ++i) {
fill(d[i], d[i] + N, inf);
fill(dp[i], dp[i] + N, inf);
}
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
if(g[i][j])
d[i][j] = g[i][j] * mid;
for(int k = 1; k <= n; ++k)
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
Min(d[i][j], d[i][k] + d[k][j]);
memcpy(mx, d, sizeof(d));
for(int i = 1; i <= n; ++i)
dp[i][i] = 0;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
for(int s = 1; s <= k; ++s)
if(buy[i][s] != -1 && sell[j][s] != -1) {
Min(mx[i][j], d[i][j] + buy[i][s] - sell[j][s]);
Max(mx[i][j], -inf);
}
memcpy(dp, mx, sizeof(dp));
for(int k = 1; k <= n; ++k)
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j) {
Min(dp[i][j], dp[i][k] + dp[k][j]);
Max(dp[i][j], -inf);
}
int ans = inf;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
if(i != j)
Min(ans, dp[i][j] + dp[j][i]);
return ans <= 0;
}
main() {
ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
// freopen("input.txt", "r", stdin);
cin >> n >> m >> k;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= k; ++j)
cin >> buy[i][j] >> sell[i][j];
for(int i = 1; i <= m; ++i) {
int u, v;
cin >> u >> v;
cin >> g[u][v];
}
int l = 1, r = 1e9, res = 0;
while(l <= r) {
int mid = l + r >> 1;
if(check(mid))
l = mid + 1, res = mid;
else
r = mid - 1;
}
cout << res << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
merchant.cpp:115:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
115 | main() {
| ^
merchant.cpp: In function 'int main()':
merchant.cpp:129:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
129 | int 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... |