이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("trapv,Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include<bits/stdc++.h>
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
template<typename F>
void multitest(F func) {
int t;
cin >> t;
while(t--) func();
}
void report(int ok) {
cout << (ok?"YES":"NO") << '\n';
}
const int maxn = 101, maxk = 1010;
int n, m, k, b[maxn][maxk], s[maxn][maxk], deal[maxn][maxn];
ll dist[maxn][maxn];
vector<array<int, 3>> edges;
int main() {
cin.tie(0)->sync_with_stdio(0);
//multitest([&](){});
cin >> n >> m >> k;
for(int i = 0; i < n; i++)
for(int j = 0; j < k; j++)
cin >> b[i][j] >> s[i][j];
edges.resize(m);
for(auto &[x, y, z] : edges) cin >> x >> y >> z, x--, y--;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++) {
for(int x = 0; x < k; x++) if(s[j][x] != -1 && b[i][x] != -1) deal[i][j] = max(deal[i][j], s[j][x]-b[i][x]);
}
auto apsp = [&]() {
for(int k = 0; k < n; k++)
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
dist[i][j] = max(dist[i][j], dist[i][k]+dist[k][j]);//, cout << i << " " << j << " " << k << " " << dist[i][k] << " " << dist[k][j] << endl;
};
auto neg = [&]() {
for(int k = 0; k < n; k++)
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
if(i != j && i != k && k != j && dist[i][k]+dist[k][j]+dist[j][i] >= 0) return 1;
return 0;
};
auto print = [&]() {
for(int i = 0; i < n; i++, cout << endl)
for(int j = 0; j < n; j++)
cout << max(-1000ll, dist[i][j]) << " ";
cout << "------\n";
};
auto check = [&](ll f) {
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
dist[i][j] = -(1ll<<59);
for(int i = 0; i < n; i++) dist[i][i] = 0;
for(auto [x, y, z] : edges) dist[x][y] = max(dist[x][y], -z*f);
//apsp();
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
dist[i][j] += deal[i][j];
//apsp();
return neg();
};
ll ans = 0;
for(ll z = 1<<30; z>>=1;) ans += z*check(ans+z);
cout << ans << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
merchant.cpp: In function 'int main()':
merchant.cpp:34:7: warning: variable 'apsp' set but not used [-Wunused-but-set-variable]
34 | auto apsp = [&]() {
| ^~~~
merchant.cpp:47:7: warning: variable 'print' set but not used [-Wunused-but-set-variable]
47 | auto print = [&]() {
| ^~~~~
# | 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... |