이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 0x3f3f3f3f3f3f3f3f;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, M, K;
cin >> N >> M >> K;
vector<vector<pair<int, int>>> items(N+1, vector<pair<int, int>>(K+1));
for (int i = 1; i <= N; i++)
for (auto &[B,S] : items[i]) {cin >> B >> S;}
vector<vector<int>> maxDiff(N+1, vector<int>(N+1));
for (int i = 1; i <= N; i++)
for (int j = 1; j <= N; j++)
{
if (i == j) continue;
for (int k = 1; k <= K; k++)
{
auto [Bi, Si] = items[i][k];
auto [Bj, Sj] = items[j][k];
if (Bi == -1 || Sj == -1) continue;
if (Bi > Sj) continue;
maxDiff[i][j] = max(maxDiff[i][j], Sj - Bi);
}
}
vector<vector<int>> dist(N+1, vector<int>(N+1, INF));
for (int i = 1; i <= M; i++)
{
int X, Y, P;
cin >> X >> Y >> P;
dist[X][Y] = min(dist[X][Y], P);
}
for (int i = 1; i <= N; i++) dist[i][i] = 0;
for (int k = 1; k <= N; k++)
for (int i = 1; i <= N; i++)
for (int j = 1; j <= N; j++)
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
int resp = 0;
for (int i = 2; i <= N; i++)
resp = max(resp, maxDiff[1][i] / (dist[1][i] + dist[i][1]));
cout << resp << '\n';
// vector<vector<vector<int>>> dp(N+1, vector<vector<int>>(N+1, vector<int>(N+1, -INF)));
// for (int i = 1; i <= N; i++) dp[0][i][i] = 0;
// for (int t = 1; t <= N; t++)
// for (int fim = 1; fim <= N; fim++)
// for (int ini = 1; ini <= N; ini++)
// for (int prox = 1; prox <= N; prox++)
// {
// if (prox == ini || dist[ini][prox] > t) continue;
// dp[t][fim][ini] = max(dp[t][fim][ini], dp[t-dist[ini][prox]][fim][prox] + maxDiff[ini][prox]);
// }
// int resp = 0;
// for (int t = 1; t <= N; t++)
// for (int i = 1; i <= N; i++)
// resp = max(resp, (dp[t][i][i] / t));
// cout << resp << '\n';
}
# | 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... |