답안 #661152

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
661152 2022-11-24T17:33:38 Z KING 여행하는 상인 (APIO17_merchant) C++14
0 / 100
135 ms 2628 KB
```#include<bits/stdc++.h>
#define NOT_STONKS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define int long long

using namespace std;
const int maxn = 100 + 10, maxk = 1e3 + 10; //4e6 + 10; //3e5 + 10;
const int mod = 1e9 + 7, inf = 1e18; //998244353;
typedef long long ll;

ll n, m, k, b[maxn][maxk], s[maxn][maxk], floyd[maxn][maxn], val[maxn][maxn], dis[maxn];
vector< pair<int, int> > G[maxn], adj[maxn];

bool f(ll x) {
vector< array<ll, 3> > vec;
fill(dis, dis + maxn, inf);
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; 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;
}

ll tmp[maxn][maxn];
bool morgh(ll x) {
memset(tmp, 63, sizeof tmp);
for (int u = 1; u <= n; u++) for (int v = 1; v <= n; v++) if (u != v)
tmp[u][v] = min(tmp[u][v], x * floyd[u][v] - val[u][v]);
for (int k = 1; k <= n; k++) {
for (int u = 1; u <= n; u++) {
for (int v = 1; v <= n; v++) {
tmp[u][v] = min(tmp[u][v], tmp[u][k] + tmp[k][v]);
}
}
}
for (int i = 1; i <= n; i++) if (tmp[i][i] <= 0)
return true;
return false;
}

int32_t 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++)
for (auto [ u, w ] : adj[v])
floyd[v][u] = min(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 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 && b[v][i] != -1)
val[v][u] = max(val[v][u], s[u][i] - b[v][i]);
if (s[v][i] != -1 && b[u][i] != -1)
val[u][v] = max(val[u][v], s[v][i] - b[u][i]);
}
}
}

ll high = 1e10, low = -1, mid;
while (high - low > 1) {
mid = (high + low) >> 1;
if (f(mid)) low = mid;
else high = mid;
}
cout << low + 1;

return 0;
}

```

Compilation message

```merchant.cpp: In function 'bool f(ll)':
merchant.cpp:25:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
25 |         for (auto [ u, v, w ] : vec)
|                   ^
merchant.cpp:27:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
27 |     for (auto [ u, v, w ] : vec) if (dis[v] > dis[u] + w)
|               ^
merchant.cpp: In function 'int32_t main()':
merchant.cpp:65:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
65 |         for (auto [ u, w ] : adj[v])
|                   ^```

Subtask #1 0 / 12.0

# 결과 실행 시간 메모리 Grader output
1 Incorrect 135 ms 2628 KB Output isn't correct
2 Halted 0 ms 0 KB -

Subtask #2 0 / 21.0

# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 1044 KB Output isn't correct
2 Halted 0 ms 0 KB -

Subtask #3 0 / 33.0

# 결과 실행 시간 메모리 Grader output
1 Incorrect 125 ms 2048 KB Output isn't correct
2 Halted 0 ms 0 KB -

Subtask #4 0 / 34.0

# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 1044 KB Output isn't correct
2 Halted 0 ms 0 KB -