Submission #647113

#TimeUsernameProblemLanguageResultExecution timeMemory
647113ghostwriterCloud Computing (CEOI18_clo)C++14
100 / 100
1710 ms3556 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <debug.h> #else #define debug(...) #endif #define ft front #define bk back #define st first #define nd second #define ins insert #define ers erase #define pb push_back #define pf push_front #define _pb pop_back #define _pf pop_front #define lb lower_bound #define ub upper_bound #define mtp make_tuple #define bg begin #define ed end #define all(x) (x).bg(), (x).ed() #define sz(x) (int)(x).size() typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef string str; template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i)) #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i)) #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i)) #define FSN(i, n) for (int (i) = (n) - 1; (i) >= 0; --(i)) #define EACH(i, x) for (auto &(i) : (x)) #define WHILE while #define file "TEST" mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); } /* ---------------------------------------------------------------- END OF TEMPLATE ---------------------------------------------------------------- Tran The Bao - ghostwriter Training for VOI23 gold medal ---------------------------------------------------------------- DIT ME CHUYEN BAO LOC ---------------------------------------------------------------- */ struct Computer { int c, f, v; Computer() {} Computer(int c, int f, int v) : c(c), f(f), v(v) {} }; #define Client Computer bool cmp(Computer &a, Computer &b) { return a.f < b.f; } const int N = 2001; const int C = 51; int n, m; Computer a[N]; Client b[N]; ll d[N][C][2], d1[N][C][2]; signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); // freopen(file".inp", "r", stdin); // freopen(file".out", "w", stdout); cin >> n; FOR(i, 1, n) cin >> a[i].c >> a[i].f >> a[i].v; cin >> m; FOR(i, 1, m) cin >> b[i].c >> b[i].f >> b[i].v; sort(a + 1, a + 1 + n, cmp); sort(b + 1, b + 1 + m, cmp); FOR(i, 1, m) { FOR(j, 1, n) FOR(w, 0, 50) FOR(stat, 0, 1) { ll &rs = d[j][w][stat]; rs = 0; if (stat) { rs = max(rs, d1[j][w][1]); rs = max(rs, d[j - 1][b[i].c][0]); if (a[j].f >= b[i].f) { if (w < b[i].c) rs = max(rs, d[j - 1][b[i].c - w][0] - (w < a[j].c? 0 : a[j].v)); else rs = max(rs, d1[j][w - b[i].c][1] + b[i].v - (w < a[j].c? 0 : a[j].v)); } } else { rs = max(rs, d[j - 1][w][0]); if (a[j].f >= b[i].f) { if (a[j].c < w) rs = max(rs, d[j - 1][w - a[j].c][0] - a[j].v); else if (w) rs = max(rs, d1[j][a[j].c - w][1] + b[i].v - a[j].v); } } } FOR(j, 1, n) FOR(w, 0, 50) FOR(stat, 0, 1) d1[j][w][stat] = d[j][w][stat]; } cout << d[n][a[n].c][1]; return 0; } /* 4 4 2200 700 2 1800 10 20 2550 9999 4 2000 750 3 1 1500 300 6 1900 1500 3 2400 4550 ---------------------------------------------------------------- From Benq: stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH ---------------------------------------------------------------- */

Compilation message (stderr)

clo.cpp: In function 'int main()':
clo.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
clo.cpp:69:5: note: in expansion of macro 'FOR'
   69 |     FOR(i, 1, n) cin >> a[i].c >> a[i].f >> a[i].v;
      |     ^~~
clo.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
clo.cpp:71:5: note: in expansion of macro 'FOR'
   71 |     FOR(i, 1, m) cin >> b[i].c >> b[i].f >> b[i].v;
      |     ^~~
clo.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
clo.cpp:74:5: note: in expansion of macro 'FOR'
   74 |     FOR(i, 1, m) {
      |     ^~~
clo.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
clo.cpp:75:6: note: in expansion of macro 'FOR'
   75 |      FOR(j, 1, n)
      |      ^~~
clo.cpp:32:31: warning: unnecessary parentheses in declaration of 'w' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
clo.cpp:76:6: note: in expansion of macro 'FOR'
   76 |      FOR(w, 0, 50)
      |      ^~~
clo.cpp:32:31: warning: unnecessary parentheses in declaration of 'stat' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
clo.cpp:77:6: note: in expansion of macro 'FOR'
   77 |      FOR(stat, 0, 1) {
      |      ^~~
clo.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
clo.cpp:96:6: note: in expansion of macro 'FOR'
   96 |      FOR(j, 1, n)
      |      ^~~
clo.cpp:32:31: warning: unnecessary parentheses in declaration of 'w' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
clo.cpp:97:6: note: in expansion of macro 'FOR'
   97 |      FOR(w, 0, 50)
      |      ^~~
clo.cpp:32:31: warning: unnecessary parentheses in declaration of 'stat' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
clo.cpp:98:6: note: in expansion of macro 'FOR'
   98 |      FOR(stat, 0, 1)
      |      ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...