제출 #1351489

#제출 시각아이디문제언어결과실행 시간메모리
1351489dex111222333444555Semiexpress (JOI17_semiexpress)C++20
100 / 100
271 ms46972 KiB
#include <bits/stdc++.h>
#define all(v) begin(v), end(v)
#define ii pair<int, int>
#define fi first
#define se second
#define siz(v) (int)(v).size()
#define lli pair<long long, int>
#define dbg(x) "[" #x " = " << x << "]"
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(i) (1LL << (i))

using namespace std;

bool M1;
const long long inf = 1e18 + 123;
const int mod = 1e9 + 7, infINT = 1e9 + 1321;

template<class X, class Y> bool minimize(X &x, const Y &y){return x > y ? x = y, 1: 0;}
template<class X, class Y> bool maximize(X &x, const Y &y){return x < y ? x = y, 1: 0;}

const int MAXM = 3005, MAXK = 3005;

int numVal, numPos, numLim, pos[MAXM][MAXK], cur[MAXM], A, B, C, f[MAXM][MAXK];
long long limCost;

void input(){
    cin >> numVal >> numPos >> numLim;
    numLim -= numPos;
    cin >> A >> B >> C;
    cin >> limCost;
    for(int i = 1; i <= numPos; i++) cin >> pos[i][0];
}

long long calc(const long long &used, const int &L, const int &R, const int &v){
    int l = L, r = R, m, res = l;
//    if (v == A){
////        cout << used << ' ' << L << ' ' << R << ' ' << v << '\n';
//    }
    while(l <= r){
        m = (l + r) >> 1;
        if (used + 1LL * (m - L) * 1LL * v <= limCost) res = m, l = m + 1;
        else r = m - 1;
    }
//    cout << dbg(res) << '\n';
    return res;
}

void solve(){
    for(int i = 1; i < numPos; i++){
        cur[i] = pos[i][0];
        for(int j = 1; j <= numLim; j++){
            long long used = 1LL * B * 1LL * (pos[i][0] - 1) + 1LL * C * 1LL * (pos[i][j - 1] - pos[i][0]);
//            int far = calc(used, pos[i][j - 1], pos[i + 1][0] - 1, A);
            pos[i][j] = calc(used, pos[i][j - 1], pos[i + 1][0] - 1, A);
            used = 1LL * B * 1LL * (pos[i][0] - 1) + 1LL * C * 1LL * (pos[i][j] - pos[i][0]);
            if (used + C <= limCost && pos[i][j] < pos[i + 1][0] - 1) pos[i][j]++;
        }
        for(int j = numLim + 1; j >= 0; j--){
            long long used = 1LL * B * 1LL * (pos[i][0] - 1) + 1LL * C * 1LL * (pos[i][j] - pos[i][0]);
//            int far = calc(used, pos[i][j - 1], pos[i + 1][0] - 1, A);
            pos[i][j] = calc(used, pos[i][j], pos[i + 1][0] - 1, A);
//            cout << i << ' ' << j << ": " << pos[i][j] << '\n';
        }
    }
    memset(f, -0x3f, sizeof f);

    int res = 0;

    f[1][0] = 0;
    for(int i = 1; i <= numPos; i++) if (1LL * B * 1LL * (pos[i][0] - 1) <= limCost)
    for(int j = 0; j <= numLim; j++) if (f[i][j] >= 0){
//        cout << i << ' ' << j << ": " << f[i][j] << '\n';
        for(int k = 0; j + k <= numLim && i < numPos; k++){
            maximize(f[i + 1][j + k], f[i][j] + (pos[i][k] - cur[i]) + 1);
//            cout << "-> " << i + 1 << ' ' << j + k << ": " << f[i + 1][j + k] << ' ' << pos[i][k] << ' ' << pos[i][0] << '\n';
            res = max(res, f[i + 1][j + k] - 1);
        }
        res = max(res, f[i][j]);
    }
    cout << res << '\n';
}

bool M2;
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define task "test"
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    input();
    solve();
    cerr << (&M2 - &M1) / 1048576 << " mb\n";
    cerr << (1.0 * clock()) / CLOCKS_PER_SEC << ".s\n";
}

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

semiexpress.cpp: In function 'int main()':
semiexpress.cpp:88:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
semiexpress.cpp:89:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...