Advertisement
SorahISA

5-trip-planner

Apr 10th, 2023
796
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.30 KB | None | 0 0
  1. #pragma GCC optimize("Ofast", "unroll-loops")
  2. // #pragma GCC target("avx")
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. #define int int64_t
  7. #define double __float80
  8. using pii = pair<int, int>;
  9. template <typename T> using Prior = std::priority_queue<T>;
  10. template <typename T> using prior = std::priority_queue<T, vector<T>, greater<T>>;
  11.  
  12. #define X first
  13. #define Y second
  14. #define eb emplace_back
  15. #define ef emplace_front
  16. #define ee emplace
  17. #define pb pop_back
  18. #define pf pop_front
  19. #define ALL(x) begin(x), end(x)
  20. #define RALL(x) rbegin(x), rend(x)
  21. #define SZ(x) ((int)(x).size())
  22.  
  23. #define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
  24. template <typename T> void _do(T &&_t) {cerr << _t << "\n";}
  25. template <typename T, typename ...U> void _do(T &&_t, U &&..._u) {cerr << _t << ", ", _do(_u...);}
  26.  
  27. template <typename T, typename U> bool chmin(T &lhs, U rhs) {return lhs > rhs ? lhs = rhs, 1 : 0;}
  28. template <typename T, typename U> bool chmax(T &lhs, U rhs) {return lhs < rhs ? lhs = rhs, 1 : 0;}
  29.  
  30. template <typename T, typename U> bool chpmax(T &lhs, U rhs) {
  31.     if (lhs.first < rhs.first) return lhs = rhs, 1;
  32.     if (lhs.first == rhs.first and lhs.second > rhs.second) return lhs = rhs, 1;
  33.     return 0;
  34. }
  35.  
  36. const int INF = LLONG_MAX >> 2;
  37.  
  38. void solve() {
  39.     int N, D, M; cin >> N >> D >> M;
  40.    
  41.     vector<vector<int>> Price(N+1, vector<int>(D+1, 0));
  42.     for (int i = 1; i <= N; ++i) {
  43.         for (int j = 1; j <= D; ++j) cin >> Price[i][j];
  44.     }
  45.    
  46.     vector<vector<int>> prePrice = Price;
  47.     for (int i = 1; i <= N; ++i) {
  48.         for (int j = 1; j <= D; ++j) prePrice[i][j] += prePrice[i][j-1];
  49.     }
  50.    
  51.     vector<vector<int>> Dist(N+1, vector<int>(N+1, INF));
  52.     for (int i = 1; i <= N; ++i) Dist[i][i] = 0;
  53.     for (int i = 0; i < M; ++i) {
  54.         int u, v, c; cin >> u >> v >> c;
  55.         chmin(Dist[u][v], c), chmin(Dist[v][u], c);
  56.     }
  57.     for (int _ : {0, 1, 2}) {
  58.         for (int k = 1; k <= N; ++k) {
  59.             for (int i = 1; i <= N; ++i) {
  60.                 for (int j = 1; j <= N; ++j) {
  61.                     chmin(Dist[i][j], Dist[i][k] + Dist[k][j]);
  62.                 }
  63.             }
  64.         }
  65.     }
  66.    
  67.     int P_discount; cin >> P_discount;
  68.     vector<pii> discount(N+1, {D+1, 0});
  69.     for (int i = 0; i < P_discount; ++i) {
  70.         int Q_hotel, X_days, Y_dis; cin >> Q_hotel >> X_days >> Y_dis;
  71.         discount[Q_hotel] = {X_days, Y_dis};
  72.     }
  73.    
  74.     int K_cash; cin >> K_cash;
  75.     vector<vector<int>> Cash(N+1, vector<int>(D+1, 0));
  76.     for (int i = 0; i < K_cash; ++i) {
  77.         int R_hotel, S_day, T_cash; cin >> R_hotel >> S_day >> T_cash;
  78.         Cash[R_hotel][S_day] = T_cash;
  79.     }
  80.    
  81.     vector<vector<int>> preCash = Cash;
  82.     for (int i = 1; i <= N; ++i) {
  83.         for (int j = 1; j <= D; ++j) preCash[i][j] += preCash[i][j-1];
  84.     }
  85.    
  86.     auto get_price = [&](int hotel, int dayL, int dayR) -> int {
  87.         int dc = 0;
  88.         if (discount[hotel].X <= dayR - dayL + 1) dc = discount[hotel].Y;
  89.         return (prePrice[hotel][dayR] - prePrice[hotel][dayL-1]) * (100 - dc) / 100;
  90.     };
  91.    
  92.     auto get_cash = [&](int hotel, int dayL, int dayR) -> int {
  93.         return (preCash[hotel][dayR] - preCash[hotel][dayL-1]);
  94.     };
  95.    
  96.     auto get_dist = [&](int st, int ed, bool free = false) -> int {
  97.         if (free) return 0;
  98.         return Dist[st][ed];
  99.     };
  100.    
  101.     vector<vector<pii>> dp(D+1, vector<pii>(N+1, {-1, 0}));
  102.     for (int i = 1; i <= N; ++i) dp[0][i] = {0, 0};
  103.     for (int d = 1; d <= D; ++d) {
  104.         for (int i = 1; i <= N; ++i) {
  105.             for (int _d = 0; _d <= d; ++_d) {
  106.                 for (int j = 1; j <= N; ++j) {
  107.                     if (Dist[i][j] == INF) continue;
  108.                     chpmax(dp[d][i], pii{
  109.                         dp[_d][j].X + get_cash(i, _d+1, d),
  110.                         dp[_d][j].Y + get_price(i, _d+1, d) + get_dist(j, i, (_d == 0))
  111.                     });
  112.                 }
  113.             }
  114.             // printf("dp[%d][%d] = {%d, %d}\n", d, i, dp[d][i].X, dp[d][i].Y);
  115.         }
  116.     }
  117.    
  118.     pii ans = {-1, 0};
  119.     for (int i = 1; i <= N; ++i) chpmax(ans, dp[D][i]);
  120.     cout << ans.X << " " << ans.Y << "\n";
  121. }
  122.  
  123. int32_t main() {
  124.     fastIO();
  125.    
  126.     int t = 1; // cin >> t;
  127.     for (int _ = 1; _ <= t; ++_) {
  128.         solve();
  129.     }
  130.    
  131.     return 0;
  132. }
  133.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement