| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 554015 | d4xn | 여행하는 상인 (APIO17_merchant) | C++17 | 912 ms | 1048576 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx2")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ii pair<int, int>
#define ff first
#define ss second
#define mp make_pair
#define UB upper_bound
#define LB lower_bound
#define pb push_back
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define vvb vector<vb>
#define vs vector<string>
#define vii vector<ii>
#define vvii vector<vii>
#define vll vector<ll>
#define vld vector<ld>
const int N = 101, K = 1001;
int n, m, k, ans;
vii adj[N];
bool vis[N][N];
int p[N];
int buy[N][K];
int sell[N][K];
int mx[K];
vi cycle;
int best() {
int cnt = 0;
for (int j = 0; j < k; j++) {
mx[j] = 0;
for (int i = 1; i < cycle.size()-1; i++) {
mx[j] = max(mx[j], sell[cycle[i]][j]);
}
int b = buy[0][j];
if (b != -1 && b < mx[j]) {
cnt += mx[j] - b;
}
}
return cnt;
}
void dfs(int u = 0, int par = 0, int d = 0) {
vis[par][u] = 1;
p[u] = par;
for (auto &[v, w] : adj[u]) {
if (vis[u][v]) continue;
if (v == 0) {
cycle.clear();
cycle.pb(0);
while (u != 0) {
cycle.pb(u);
u = p[u];
}
cycle.pb(0);
reverse(all(cycle));
ans = max(ans, best() / (d+w));
}
dfs(v, u, d+w);
}
//vis[par][u] = 0;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ans = 0;
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++) {
int b, s;
cin >> b >> s;
buy[i][j] = b;
sell[i][j] = s;
/*if (buy[i][j] != -1 && sell[i][j] != -1) {
assert(buy[i][j] >= sell[i][j]);
}*/
}
}
while (m--) {
int x, y, z;
cin >> x >> y >> z;
x--; y--;
adj[x].pb(mp(y, z));
}
dfs();
cout << ans << "\n";
return 0;
}컴파일 시 표준 에러 (stderr) 메시지
| # | 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... | ||||
