Submission #520940

# Submission time Handle Problem Language Result Execution time Memory
520940 2022-01-31T13:54:09 Z Wayne_Yan Cloud Computing (CEOI18_clo) C++17
100 / 100
713 ms 3652 KB
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
#define int long long
typedef int64_t ll;
typedef long double ld;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define RF(n) RFi(i,n)
#define RFi(i,n) RFl(i,0,n)
#define RFl(i,l,n) for(int i=n-1;i>=l;i--)
#define all(v) begin(v),end(v)
#define siz(v) (ll(v.size()))
#define get_pos(v,x) (lower_bound(all(v),x)-begin(v))
#define sort_uni(v) sort(begin(v),end(v)),v.erase(unique(begin(v),end(v)),end(v))
#define mem(v,x) memset(v,x,sizeof v)
#define ff first
#define ss second
#define mid ((l+r)>>1)
#define RAN(a,b) uniform_int_distribution<int> (a, b)(rng)
#define debug(x) (cerr << (#x) << " = " << x << "\n")
#define cmax(a,b) (a = max(a,b))
#define cmin(a,b) (a = min(a,b))

template <typename T> using max_heap = __gnu_pbds::priority_queue<T,less<T> >;
template <typename T> using min_heap = __gnu_pbds::priority_queue<T,greater<T> >;
template <typename T> using rbt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int maxN = 2005;
const int maxC = 50;
const int INF = 8e18; 
int N;
struct item{
  int c, f, p;  
  item(){}
  item(int cc, int ff, int pp) : c(cc), f(ff), p(pp) {}
  bool operator < (const item &rhs) const {
    if(f != rhs.f) return f > rhs.f;
    return c > rhs.c;
  }
} input[maxN << 1];

int dp[2][maxN * maxC * 2];

signed main(){
  
  int n;
  cin >> n;
  F(n){
    int a,b,c;
    cin >> a >> b >> c;
    input[i] = (item){a,b,-c};
  }
  int m;
  cin >> m;
  F(m){
    int a,b,c;
    cin >> a >> b >> c;
    input[i+n] = (item){-a, b, c};
  }
  
  N = n+m;

  sort(input, input+N);

  fill(dp[0], dp[0] + maxN*maxC * 2, -INF);
  fill(dp[1], dp[1] + maxN*maxC * 2, -INF);
  dp[0][0] = 0;

  bool flip = 0;
  int ans = -INF;
  F(N){
    int old = flip;
    int curr = 1 - flip;
    item proc = input[i];
   
    Fi(j, maxN*maxC * 2){
      dp[curr][j] = dp[old][j];
      if( j - proc.c < 0 || j - proc.c >= maxN*maxC) continue;
      cmax(dp[curr][j], dp[old][j-proc.c]+proc.p);
    }

    flip = 1-flip;

    if(i == N-1){
      Fi(j, maxN * maxC * 2)
        cmax(ans, dp[curr][j]);
    }
  }
  
  assert(ans >= 0);
  printf("%lld", ans);
  
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
3 Correct 20 ms 3440 KB Output is correct
4 Correct 38 ms 3404 KB Output is correct
5 Correct 338 ms 3508 KB Output is correct
6 Correct 353 ms 3404 KB Output is correct
7 Correct 347 ms 3404 KB Output is correct
8 Correct 347 ms 3508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 4 ms 3404 KB Output is correct
3 Correct 23 ms 3404 KB Output is correct
4 Correct 21 ms 3444 KB Output is correct
5 Correct 164 ms 3452 KB Output is correct
6 Correct 172 ms 3452 KB Output is correct
7 Correct 339 ms 3512 KB Output is correct
8 Correct 350 ms 3504 KB Output is correct
9 Correct 333 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 3404 KB Output is correct
2 Correct 7 ms 3404 KB Output is correct
3 Correct 32 ms 3404 KB Output is correct
4 Correct 32 ms 3404 KB Output is correct
5 Correct 69 ms 3436 KB Output is correct
6 Correct 66 ms 3380 KB Output is correct
7 Correct 86 ms 3444 KB Output is correct
8 Correct 93 ms 3440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3404 KB Output is correct
2 Correct 5 ms 3404 KB Output is correct
3 Correct 263 ms 3448 KB Output is correct
4 Correct 309 ms 3388 KB Output is correct
5 Correct 644 ms 3556 KB Output is correct
6 Correct 664 ms 3552 KB Output is correct
7 Correct 685 ms 3652 KB Output is correct
8 Correct 709 ms 3552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3404 KB Output is correct
2 Correct 32 ms 3444 KB Output is correct
3 Correct 147 ms 3444 KB Output is correct
4 Correct 342 ms 3480 KB Output is correct
5 Correct 713 ms 3564 KB Output is correct
6 Correct 689 ms 3540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
3 Correct 20 ms 3440 KB Output is correct
4 Correct 38 ms 3404 KB Output is correct
5 Correct 338 ms 3508 KB Output is correct
6 Correct 353 ms 3404 KB Output is correct
7 Correct 347 ms 3404 KB Output is correct
8 Correct 347 ms 3508 KB Output is correct
9 Correct 2 ms 3404 KB Output is correct
10 Correct 4 ms 3404 KB Output is correct
11 Correct 23 ms 3404 KB Output is correct
12 Correct 21 ms 3444 KB Output is correct
13 Correct 164 ms 3452 KB Output is correct
14 Correct 172 ms 3452 KB Output is correct
15 Correct 339 ms 3512 KB Output is correct
16 Correct 350 ms 3504 KB Output is correct
17 Correct 333 ms 3404 KB Output is correct
18 Correct 7 ms 3404 KB Output is correct
19 Correct 7 ms 3404 KB Output is correct
20 Correct 32 ms 3404 KB Output is correct
21 Correct 32 ms 3404 KB Output is correct
22 Correct 69 ms 3436 KB Output is correct
23 Correct 66 ms 3380 KB Output is correct
24 Correct 86 ms 3444 KB Output is correct
25 Correct 93 ms 3440 KB Output is correct
26 Correct 5 ms 3404 KB Output is correct
27 Correct 5 ms 3404 KB Output is correct
28 Correct 263 ms 3448 KB Output is correct
29 Correct 309 ms 3388 KB Output is correct
30 Correct 644 ms 3556 KB Output is correct
31 Correct 664 ms 3552 KB Output is correct
32 Correct 685 ms 3652 KB Output is correct
33 Correct 709 ms 3552 KB Output is correct
34 Correct 3 ms 3404 KB Output is correct
35 Correct 32 ms 3444 KB Output is correct
36 Correct 147 ms 3444 KB Output is correct
37 Correct 342 ms 3480 KB Output is correct
38 Correct 713 ms 3564 KB Output is correct
39 Correct 689 ms 3540 KB Output is correct
40 Correct 178 ms 3404 KB Output is correct
41 Correct 336 ms 3404 KB Output is correct
42 Correct 521 ms 3532 KB Output is correct
43 Correct 702 ms 3572 KB Output is correct
44 Correct 699 ms 3516 KB Output is correct
45 Correct 692 ms 3600 KB Output is correct
46 Correct 346 ms 3488 KB Output is correct
47 Correct 520 ms 3524 KB Output is correct
48 Correct 494 ms 3532 KB Output is correct