Submission #1258491

#TimeUsernameProblemLanguageResultExecution timeMemory
1258491bnd2100Cloud Computing (CEOI18_clo)C++20
0 / 100
3093 ms5192 KiB
/*
* @Author: Twynzz
* @Last Modified by: Twynzz
* @Note For This Problem: https://wbd.ms/share/v2/aHR0cHM6Ly93aGl0ZWJvYXJkLm1pY3Jvc29mdC5jb20vYXBpL3YxLjAvd2hpdGVib2FyZHMvcmVkZWVtLzVhZWY2Y2M0YWM0YjRkODFiYTJjODJlZjk3ZDQzYTg3X0JCQTcxNzYyLTEyRTAtNDJFMS1CMzI0LTVCMTMxRjQyNEUzRF85MmM3ZTI1Yi00N2Y0LTQzMTAtOWI3Yy02ZmVjMjkxYTMzMTU=
*/


#include <bits/stdc++.h>
using namespace std;

// ------------ Define ------------

#define el "\n"
#define int long long
#define ld long double
#define str string
#define file(name) {freopen(name".inp","r",stdin);freopen(name".out","w",stdout);}
#define IOS {std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define _TBN_ signed main()
#define setp(n) setprecision(n)<< fixed
#define fi first
#define se second
#define ii pair<int,int>
#define gcd(a,b) __gcd(a,b)
#define tup pair<int,ii>
#define pb push_back
#define pf push_front
#define eb emplace_back
#define sz(v) (int)v.size()

const int maxn = 2e5+9;
const long long oo = 1e18;
const int MOD = 1e9+7, Mod = 998244353;
const int base = 311;

template<class X>
    bool maximize(X &a, const X &b)
    {
        if (a<b)
        {
            a = b;
            return 1;
        }
        return 0;
    }

template<class X>
    bool minimize(X &a, const X &b)
    {
        if (a>b)
        {
            a = b;
            return 1;
        }
        return 0;
    }

namespace sub1
{
    bool checkSub1();
    void sub1();
}
namespace sub2
{
    bool checkSub2();
    void sub2();
}
namespace sub3
{
    bool checkSub3();
    void sub3();
}

int lcm(int a, int b)
{
    return a/gcd(a,b)*b;
}

int sqr(int x) {return x*x;}

inline bool MASK(int mask, int bit) {return ((mask>>bit)&1);}
inline long long F(int n) {return n*(n+1)/2;}
inline int add(int a, int b, int m = MOD) {return ((a%m+b%m)%m+m)%m;}
inline int sub(int a, int b, int m = MOD) {return ((a-b)%m+m)%m;}
inline int mul(int a, int b, int m = MOD) {return ((a%m)*(b%m))%m;}

int dx[] = {-1, 0, 1};
int dy[] = {1, 1, 1};

// ------------ Code ------------

struct cp
{
    int c, f, v;
};

bool cmp(cp a, cp b)
{
    return a.f < b.f;
}

int n, m;
cp a[2009], b[2009];
_TBN_
{
    IOS;
    if (fopen("CLOUD.inp","r")) file("CLOUD");
    cin >>n;
    for(int i = 1; i <= n; i++) cin >>a[i].c >>a[i].f >>a[i].v;
    cin >>m;
    for(int i = 1; i <= m; i++) cin >>b[i].c >>b[i].f >>b[i].v;
    for(int i = 1; i <= 1; i++)
    {
        if (sub1::checkSub1()) {sub1::sub1(); return 0;}
        // if (sub2::checkSub2()) {sub2::sub2(); return 0;}
        // if (sub3::checkSub3()) {sub3::sub3(); return 0;}
    }
    return 0;
}

namespace sub1
{
    bool checkSub1()
    {
        return n <= 15;
    }
    int cnt[100], c[maxn], d;
    int dp[800];
    vector<int> group[maxn];
    int solve(int total)
    {
        for(int j = 0; j <= total; j++)
            dp[j] = -oo;
        dp[0] = 0;
        for(int lvl = d; lvl >= 1; lvl--)
        {
            int cap = cnt[lvl];
            if (!cap) continue;
            for(int i : group[lvl])
            {
                for(int j = cap; j >= b[i].c; j--)
                    maximize(dp[j], dp[j - b[i].c] + b[i].v);
            }
        }
        int mx = 0;
        for(int j = 0; j <= total; j++)
            maximize(mx, dp[j]);
        return mx;
    }
    void comp()
    {
        for(int i = 1; i <= n; i++)
            c[++d] = a[i].f;
        sort(c + 1, c + 1 + d);
        d = unique(c + 1, c + 1 + d) - c - 1;
        for(int i = 1; i <= n; i++)
            a[i].f = lower_bound(c + 1, c + 1 + d, a[i].f) - c;
        for(int i = 1; i <= m; i++)
        {
            b[i].f = lower_bound(c + 1, c + 1 + d, b[i].f) - c;
            group[b[i].f].pb(i);
        }
    }
    void sub1()
    {
        comp();
        int ans = 0;
        for(int mask = 1; mask < (1ll << n); mask++)
        {
            for(int i = 1; i <= d; i++) cnt[i] = 0;
            int total = 0, bought = 0;
            for(int i = 1; i <= n; i++)
            {
                if (!MASK(mask, i - 1)) continue;
                cnt[a[i].f] += a[i].c;
                total += a[i].c;
                bought += a[i].v;
            }
            for(int i = d; i >= 1; i--)
                cnt[i] += cnt[i + 1];
            maximize(ans, solve(total) - bought);
            // maximize(ans, solve(total));
            // cout<< total<< el;
        }
        cout<< ans<< el;
    }
}
 




Compilation message (stderr)

clo.cpp: In function 'int main()':
clo.cpp:17:28: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | #define file(name) {freopen(name".inp","r",stdin);freopen(name".out","w",stdout);}
      |                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
clo.cpp:107:33: note: in expansion of macro 'file'
  107 |     if (fopen("CLOUD.inp","r")) file("CLOUD");
      |                                 ^~~~
clo.cpp:17:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | #define file(name) {freopen(name".inp","r",stdin);freopen(name".out","w",stdout);}
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:107:33: note: in expansion of macro 'file'
  107 |     if (fopen("CLOUD.inp","r")) file("CLOUD");
      |                                 ^~~~
#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...