이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define NOT_STONKS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
const int maxn = 100 + 10, maxk = 1e3 + 10; //4e6 + 10; //3e5 + 10;
const long long int mod = 1e9 + 7, inf = 1e18; //998244353;
typedef long long ll;
ll n, m, k, b[maxn][maxk], s[maxn][maxk], floyd[maxn][maxn], cost[maxn][maxn], val[maxn][maxn], dis[maxn];
vector< pair<int, int> > G[maxn], adj[maxn];
bool f(ll x) {
vector< array<ll, 3> > vec;
memset(dis, 63, sizeof dis);
dis[1] = 0;
for (int v = 1; v <= n; v++) {
for (int u = v + 1; u <= n; u++) {
vec.push_back({ v, u, floyd[v][u] * x - val[v][u] });
vec.push_back({ u, v, floyd[u][v] * x - val[u][v] });
}
}
for (int i = 0; i < n - 1; i++)
for (auto [ u, v, w ] : vec)
dis[v] = min(dis[v], dis[u] + w);
for (auto [ u, v, w ] : vec) if (dis[v] > dis[u] + w)
return true;
return false;
}
int main() {
NOT_STONKS;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) for (int j = 0; j < k; j++) {
cin >> b[i][j] >> s[i][j];
}
for (int i = 0; i < m; i++) {
int u, v, w;
cin >> u >> v >> w;
adj[u].push_back({ v, w });
}
memset(floyd, 63, sizeof floyd);
for (int v = 1; v <= n; v++) {
floyd[v][v] = 0;
for (auto [ u, w ] : adj[v])
floyd[v][u] = w;
}
for (int k = 1; k <= n; k++)
for (int v = 1; v <= n; v++)
for (int u = 1; u <= n; u++)
floyd[v][u] = min(floyd[v][u], floyd[v][k] + floyd[k][u]);
for (int i = 1; i <= n; i++) fill(val[i], val[i] + maxn, -inf);
for (int v = 1; v <= n; v++) {
for (int u = v + 1; u <= n; u++) {
for (int i = 0; i < k; i++) {
if (s[u][i] == -1 || s[v][i] == -1) continue;
val[v][u] = max(val[v][u], s[u][i] - b[v][i]);
val[u][v] = max(val[u][v], s[v][i] - b[u][i]);
}
}
}
ll high = 1e12, low = -1, mid;
while (high - low > 1) {
mid = (high + low) >> 1;
if (f(mid)) low = mid;
else high = mid;
}
cout << low + 1;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
merchant.cpp: In function 'bool f(ll)':
merchant.cpp:24:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
24 | for (auto [ u, v, w ] : vec)
| ^
merchant.cpp:26:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
26 | for (auto [ u, v, w ] : vec) if (dis[v] > dis[u] + w)
| ^
merchant.cpp: In function 'int main()':
merchant.cpp:48:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
48 | for (auto [ u, w ] : adj[v])
| ^
# | 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... |