제출 #1277265

#제출 시각아이디문제언어결과실행 시간메모리
1277265nhmktuCloud Computing (CEOI18_clo)C++17
100 / 100
473 ms2128 KiB
#include <bits/stdc++.h>
#define ll long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define pi pair<int,int>
#define pii pair<int,pi>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) (int) a.size()
#define endl '\n'
#define data "data"

using namespace std;
const ll linf = 1e18;
const int inf = 1e9;
const int MOD = 1e9 + 7, N = 2e5;

void add(int &a, int b)
{
    a += b;
    if(a>=MOD)
        a-=MOD;
    if(a<0)
        a += MOD;
}

int modulo(int x)
{
    if(x<=1)
        return 1;
    return (MOD - MOD/x) * modulo(MOD/x) % MOD;
}

int mul(int a, int b)
{
    return (1ll *a%MOD * b%MOD) % MOD;
}

struct net
{
    int c, f, v, t;

    bool operator < (const net &o) const
    {
        if(f != o.f)
            return f > o.f;
        return t < o.t;
    }
};

int n, m;
vector<net> V;
ll dp[N+3];

void inp(void)
{
    cin >> n;
    FOR(i, 1, n)
    {
        int c, f, v; cin >> c >> f >> v;
        V.pb({c, f, v, -1});
    }
    cin >> m;
    FOR(i, 1, m)
    {
        int c, f, v; cin >> c >> f >> v;
        V.pb({c, f, v, 1});
    }
}

void solve(void)
{
    sort(all(V));
    memset(dp, -0x3f, sizeof(dp));
    dp[0]= 0;
    FOR(i, 0, sz(V) -1)
    {
        int t = V[i].t;
        int c = V[i].c;
        int v = V[i].v;

        if(t == -1)
        {
            ROF(j, N, c)
            {
                dp[j] = max(dp[j], dp[j-c] - 1ll * v);
            }
        }
        else
        {
            FOR(j, 0, N - c)
            {
                dp[j] = max(dp[j], dp[j+c] + 1ll * v);
            }
        }
    }

    cout << *max_element(dp, dp + N + 1);
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    if(fopen(data".inp", "r"))
    {
        freopen(data".inp","r",stdin);
        freopen(data".out","w",stdout);
    }

    inp();
    solve();
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

clo.cpp: In function 'int main()':
clo.cpp:110:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  110 |         freopen(data".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
clo.cpp:111:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |         freopen(data".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...