이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (b); i >= (a); i --)
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define REPD(i, a) for (int i = (a) - 1; i >= 0; --i)
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*
Phu Trong from Nguyen Tat Thanh High School for gifted student
*/
template <class X, class Y>
bool minimize(X &x, const Y &y){
X eps = 1e-9;
if (x > y + eps) {x = y; return 1;}
return 0;
}
template <class X, class Y>
bool maximize(X &x, const Y &y){
X eps = 1e-9;
if (x + eps < y) {x = y; return 1;}
return 0;
}
#define MAX_MARKET 105
#define MAX_CHOICE 1005
int buy[MAX_MARKET][MAX_CHOICE], sell[MAX_MARKET][MAX_CHOICE];
int minDist[MAX_MARKET][MAX_MARKET];
int profit[MAX_MARKET][MAX_MARKET];
int numNode, numEdge, numChoice;
namespace SUBTASK_1{
void main(void){
for (int s = 1; s <= numNode; ++s){
for (int u = 1; u <= numNode; ++u){
for (int v = 1; v <= numNode; ++v){
if(minDist[u][v] == minDist[u][s] + minDist[s][v])
maximize(profit[u][v], profit[u][s] + profit[s][v]);
}
}
}
int ans = 0;
for (int u = 1; u <= numNode; ++u){
for (int v = 1; v <= numNode; ++v) if(u != v){
maximize(ans, (profit[u][v]) / (minDist[u][v] + minDist[v][u]));
}
}
cout << ans;
}
}
namespace SUBTASK_4{
bool SUCCESS(int multi){
vector<vector<int>> totalCost(numNode + 5, vector<int>(numNode + 5, -1e15));
for (int u = 1; u <= numNode; ++u){
for (int v = 1; v <= numNode; ++v) if(u != v and minDist[u][v] < LINF){
totalCost[u][v] = profit[u][v] - 1LL * multi * minDist[u][v];
}
}
for (int u = 1; u <= numNode; ++u){
for (int v = 1; v <= numNode; ++v) if(u != v){
if(minDist[u][v] < LINF and minDist[v][u] < LINF)
maximize(totalCost[u][u], profit[u][u] - 1LL * multi * (minDist[u][v] + minDist[v][u]));
}
}
for (int s = 1; s <= numNode; ++s){
for (int u = 1; u <= numNode; ++u){
for (int v = 1; v <= numNode; ++v){
maximize(totalCost[u][v], totalCost[u][s] + totalCost[s][v]);
}
}
}
for (int u = 1; u <= numNode; ++u){
if(totalCost[u][u] >= 0) return true;
}
return false;
}
void main(void){
int L = 0, R = 2e9;
int ans = 0;
while (L <= R){
int M = (L + R) >> 1;
if(SUCCESS(M)) L = M + 1, ans = M;
else R = M - 1;
}
cout << ans;
}
}
void process(void){
cin >> numNode >> numEdge >> numChoice;
for (int i = 1; i <= numNode; ++i){
for (int j = 1; j <= numChoice; ++j){
cin >> buy[i][j] >> sell[i][j];
}
}
FOR(u, 1, numNode) FOR(v, 1, numNode) minDist[u][v] = LINF;
for (int i = 1; i <= numNode; ++i) minDist[i][i] = 0;
for (int i = 1; i <= numEdge; ++i){
int u, v, w; cin >> u >> v >> w;
minDist[u][v] = w;
}
for (int s = 1; s <= numNode; ++s){
for (int u = 1; u <= numNode; ++u){
for (int v = 1; v <= numNode; ++v){
minimize(minDist[u][v], minDist[u][s] + minDist[s][v]);
}
}
}
for (int u = 1; u <= numNode; ++u){
for (int v = 1; v <= numNode; ++v) if(minDist[u][v] < LINF){
for (int k = 1; k <= numChoice; ++k) if(sell[v][k] != -1 and buy[u][k] != -1) {
maximize(profit[u][v], sell[v][k] - buy[u][k]);
}
}
}
// SUBTASK_1 :: main();
SUBTASK_4 :: main();
}
signed main(){
#define name "Whisper"
cin.tie(nullptr) -> sync_with_stdio(false);
//freopen(name".inp", "r", stdin);
//freopen(name".out", "w", stdout);
process();
return (0 ^ 0);
}
# | 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... |