QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#559535#8268. TychoMispertion0 1ms5952kbC++233.3kb2024-09-11 22:57:582024-09-11 22:57:59

Judging History

你现在查看的是最新测评结果

  • [2024-09-11 22:57:59]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:5952kb
  • [2024-09-11 22:57:58]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;    
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define int ll
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mispertion ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define F first
#define S second
#define getlast(s) (*s.rbegin())
#define debg cout << "OK\n"

const ld PI = 3.1415926535;
const int N = 1e6 + 10;
const int M = 1e5 + 10;
int mod = 1e9+7;
const int infi = INT_MAX;
const ll infl = 2e18;
const int P = 505319;
const ld eps = 1e-9;

int mult(int a, int b){
    return a * 1LL * b % mod;
}

int sum(int a, int b){
    a %= mod;
    b %= mod;
    if(a + b >= mod)
        return a + b - mod;
    if(a + b < 0)
        return a + b + mod;
    return a + b;
}

int binpow(int a, int n){
    if (n == 0)
        return 1;
    if (n % 2 == 1){
        return mult(binpow(a, n - 1), a);
    }
    else{
        auto b = binpow(a, n / 2);
        return mult(b, b);
    }
}

struct segtree{
    vector<int> t;

    segtree(int n){
        t.assign(4 * n + 2, 0);
    }

    int get(int v, int tl, int tr, int l, int r){
        if(l > r)
            return infl;
        if(tl > r || l > tr)
            return infl;
        if(l <= tl && tr <= r)
            return t[v];
        int tm = (tl + tr) / 2;
        return min(get(2 * v, tl, tm, l, r), get(2 * v + 1, tm + 1, tr, l, r));
    }

    void upd(int v, int tl, int tr, int i, int x){
        if(tl == tr){
            t[v] = min(t[v], x);
        }else{
            int tm = (tl + tr) / 2;
            if(i <= tm)
                upd(2 * v, tl, tm, i, x);
            else
                upd(2 * v + 1, tm + 1, tr, i, x);
            t[v] = min(t[2 * v], t[2 * v + 1]);
        }
    }

    void sett(int v, int tl, int tr, int i, int x){
        if(tl == tr){
            t[v] = x;
        }else{
            int tm = (tl + tr) / 2;
            if(i <= tm)
                sett(2 * v, tl, tm, i, x);
            else
                sett(2 * v + 1, tm + 1, tr, i, x);
            t[v] = min(t[2 * v], t[2 * v + 1]);
        }
    }
};

int b, p, d, n, x[N], dp[N];

void solve(){
    cin >> b >> p >> d >> n;
    vector<int> al = {0};
    for(int i = 1; i <= n; i++){
        cin >> x[i];
        al.pb(x[i] % p);
    }
    sort(all(al));
    segtree tr  = segtree(sz(al));
    for(int i = 2; i <= sz(al); i++)
        tr.sett(1, 1, sz(al), i, 2e18);
    for(int i = 1; i <= n; i++){
        int ps = upper_bound(all(al), x[i] % p) - al.begin();
        dp[i] = min(tr.get(1, 1, sz(al), ps, sz(al)), tr.get(1, 1, sz(al), 1, ps - 1) + p + d);
        dp[i] -= d;
        dp[i] += (int)(x[i] / p) * (p + d);
        tr.upd(1, 1, sz(al), ps, dp[i] - (x[i] / p) * (p + d));
    }
    int ans = 2e18;
    for(int i = 0; i <= n; i++){
        ans = min(ans, dp[i] + b - x[i] + (b - x[i] - 1) / p * d);
    }
    cout << ans << '\n';
}

signed main(){
    mispertion;
    int t = 1;
    //cin >> t;
    while (t--){
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 8
Accepted
time: 0ms
memory: 3644kb

input:

1000000000000 1 1000000 0

output:

1000000999999000000

result:

ok single line: '1000000999999000000'

Test #2:

score: 0
Wrong Answer
time: 1ms
memory: 5712kb

input:

100 10 11 10
10
11
20
30
38
49
50
60
70
90

output:

143

result:

wrong answer 1st lines differ - expected: '122', found: '143'

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 5
Accepted
time: 1ms
memory: 5716kb

input:

108 100 10000 5
10
20
30
40
98

output:

110

result:

ok single line: '110'

Test #12:

score: 5
Accepted
time: 1ms
memory: 5720kb

input:

118 100 10000 5
10
20
30
98
108

output:

120

result:

ok single line: '120'

Test #13:

score: 5
Accepted
time: 1ms
memory: 5656kb

input:

206 100 10000 5
10
20
30
98
196

output:

210

result:

ok single line: '210'

Test #14:

score: 5
Accepted
time: 1ms
memory: 5792kb

input:

128 100 10000 5
10
20
98
108
118

output:

130

result:

ok single line: '130'

Test #15:

score: 5
Accepted
time: 1ms
memory: 5716kb

input:

206 100 10000 5
10
20
98
108
196

output:

210

result:

ok single line: '210'

Test #16:

score: 5
Accepted
time: 1ms
memory: 5684kb

input:

216 100 10000 5
10
20
98
196
206

output:

220

result:

ok single line: '220'

Test #17:

score: 5
Accepted
time: 1ms
memory: 5716kb

input:

304 100 10000 5
10
20
98
196
294

output:

310

result:

ok single line: '310'

Test #18:

score: 5
Accepted
time: 0ms
memory: 5684kb

input:

138 100 10000 5
10
98
108
118
128

output:

140

result:

ok single line: '140'

Test #19:

score: 5
Accepted
time: 1ms
memory: 5948kb

input:

206 100 10000 5
10
98
108
118
196

output:

210

result:

ok single line: '210'

Test #20:

score: 5
Accepted
time: 1ms
memory: 5900kb

input:

216 100 10000 5
10
98
108
196
206

output:

220

result:

ok single line: '220'

Test #21:

score: 5
Accepted
time: 0ms
memory: 5664kb

input:

304 100 10000 5
10
98
108
196
294

output:

310

result:

ok single line: '310'

Test #22:

score: 5
Accepted
time: 1ms
memory: 5724kb

input:

226 100 10000 5
10
98
196
206
216

output:

230

result:

ok single line: '230'

Test #23:

score: 5
Accepted
time: 1ms
memory: 5720kb

input:

304 100 10000 5
10
98
196
206
294

output:

310

result:

ok single line: '310'

Test #24:

score: 5
Accepted
time: 1ms
memory: 5772kb

input:

314 100 10000 5
10
98
196
294
304

output:

320

result:

ok single line: '320'

Test #25:

score: 5
Accepted
time: 1ms
memory: 5688kb

input:

402 100 10000 5
10
98
196
294
392

output:

410

result:

ok single line: '410'

Test #26:

score: 5
Accepted
time: 1ms
memory: 5876kb

input:

148 100 10000 5
98
108
118
128
138

output:

150

result:

ok single line: '150'

Test #27:

score: 5
Accepted
time: 1ms
memory: 5668kb

input:

206 100 10000 5
98
108
118
128
196

output:

210

result:

ok single line: '210'

Test #28:

score: 5
Accepted
time: 1ms
memory: 5724kb

input:

216 100 10000 5
98
108
118
196
206

output:

220

result:

ok single line: '220'

Test #29:

score: 5
Accepted
time: 1ms
memory: 5716kb

input:

304 100 10000 5
98
108
118
196
294

output:

310

result:

ok single line: '310'

Test #30:

score: 5
Accepted
time: 1ms
memory: 5716kb

input:

226 100 10000 5
98
108
196
206
216

output:

230

result:

ok single line: '230'

Test #31:

score: 5
Accepted
time: 1ms
memory: 5660kb

input:

304 100 10000 5
98
108
196
206
294

output:

310

result:

ok single line: '310'

Test #32:

score: 5
Accepted
time: 0ms
memory: 5688kb

input:

314 100 10000 5
98
108
196
294
304

output:

320

result:

ok single line: '320'

Test #33:

score: 5
Accepted
time: 0ms
memory: 5720kb

input:

402 100 10000 5
98
108
196
294
392

output:

410

result:

ok single line: '410'

Test #34:

score: 5
Accepted
time: 1ms
memory: 5692kb

input:

236 100 10000 5
98
196
206
216
226

output:

240

result:

ok single line: '240'

Test #35:

score: 5
Accepted
time: 1ms
memory: 5660kb

input:

304 100 10000 5
98
196
206
216
294

output:

310

result:

ok single line: '310'

Test #36:

score: 5
Accepted
time: 1ms
memory: 5768kb

input:

314 100 10000 5
98
196
206
294
304

output:

320

result:

ok single line: '320'

Test #37:

score: 5
Accepted
time: 1ms
memory: 5648kb

input:

402 100 10000 5
98
196
206
294
392

output:

410

result:

ok single line: '410'

Test #38:

score: 5
Accepted
time: 1ms
memory: 5736kb

input:

324 100 10000 5
98
196
294
304
314

output:

330

result:

ok single line: '330'

Test #39:

score: 5
Accepted
time: 1ms
memory: 5712kb

input:

402 100 10000 5
98
196
294
304
392

output:

410

result:

ok single line: '410'

Test #40:

score: 5
Accepted
time: 1ms
memory: 5712kb

input:

412 100 10000 5
98
196
294
392
402

output:

420

result:

ok single line: '420'

Test #41:

score: 5
Accepted
time: 1ms
memory: 5748kb

input:

500 100 10000 5
98
196
294
392
490

output:

510

result:

ok single line: '510'

Test #42:

score: 5
Accepted
time: 1ms
memory: 5720kb

input:

10 2 10 2
1
3

output:

41

result:

ok single line: '41'

Test #43:

score: 5
Accepted
time: 1ms
memory: 5716kb

input:

100 21 10 2
5
54

output:

140

result:

ok single line: '140'

Test #44:

score: 0
Wrong Answer
time: 1ms
memory: 5716kb

input:

100 21 10 9
18
21
53
62
85
86
88
90
91

output:

131

result:

wrong answer 1st lines differ - expected: '121', found: '131'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #109:

score: 15
Accepted
time: 0ms
memory: 3668kb

input:

1000000000000 1 1000000 0

output:

1000000999999000000

result:

ok single line: '1000000999999000000'

Test #110:

score: 15
Accepted
time: 1ms
memory: 5720kb

input:

108 100 10000 5
10
20
30
40
98

output:

110

result:

ok single line: '110'

Test #111:

score: 15
Accepted
time: 0ms
memory: 5788kb

input:

118 100 10000 5
10
20
30
98
108

output:

120

result:

ok single line: '120'

Test #112:

score: 15
Accepted
time: 1ms
memory: 5712kb

input:

206 100 10000 5
10
20
30
98
196

output:

210

result:

ok single line: '210'

Test #113:

score: 15
Accepted
time: 1ms
memory: 5752kb

input:

128 100 10000 5
10
20
98
108
118

output:

130

result:

ok single line: '130'

Test #114:

score: 15
Accepted
time: 1ms
memory: 5724kb

input:

206 100 10000 5
10
20
98
108
196

output:

210

result:

ok single line: '210'

Test #115:

score: 15
Accepted
time: 1ms
memory: 5652kb

input:

216 100 10000 5
10
20
98
196
206

output:

220

result:

ok single line: '220'

Test #116:

score: 15
Accepted
time: 1ms
memory: 5716kb

input:

304 100 10000 5
10
20
98
196
294

output:

310

result:

ok single line: '310'

Test #117:

score: 15
Accepted
time: 1ms
memory: 5668kb

input:

138 100 10000 5
10
98
108
118
128

output:

140

result:

ok single line: '140'

Test #118:

score: 15
Accepted
time: 1ms
memory: 5660kb

input:

206 100 10000 5
10
98
108
118
196

output:

210

result:

ok single line: '210'

Test #119:

score: 15
Accepted
time: 1ms
memory: 5716kb

input:

216 100 10000 5
10
98
108
196
206

output:

220

result:

ok single line: '220'

Test #120:

score: 15
Accepted
time: 1ms
memory: 5756kb

input:

304 100 10000 5
10
98
108
196
294

output:

310

result:

ok single line: '310'

Test #121:

score: 15
Accepted
time: 1ms
memory: 5716kb

input:

226 100 10000 5
10
98
196
206
216

output:

230

result:

ok single line: '230'

Test #122:

score: 15
Accepted
time: 1ms
memory: 5952kb

input:

304 100 10000 5
10
98
196
206
294

output:

310

result:

ok single line: '310'

Test #123:

score: 15
Accepted
time: 1ms
memory: 5720kb

input:

314 100 10000 5
10
98
196
294
304

output:

320

result:

ok single line: '320'

Test #124:

score: 15
Accepted
time: 1ms
memory: 5912kb

input:

402 100 10000 5
10
98
196
294
392

output:

410

result:

ok single line: '410'

Test #125:

score: 15
Accepted
time: 1ms
memory: 5648kb

input:

148 100 10000 5
98
108
118
128
138

output:

150

result:

ok single line: '150'

Test #126:

score: 15
Accepted
time: 1ms
memory: 5672kb

input:

206 100 10000 5
98
108
118
128
196

output:

210

result:

ok single line: '210'

Test #127:

score: 15
Accepted
time: 1ms
memory: 5756kb

input:

216 100 10000 5
98
108
118
196
206

output:

220

result:

ok single line: '220'

Test #128:

score: 15
Accepted
time: 1ms
memory: 5920kb

input:

304 100 10000 5
98
108
118
196
294

output:

310

result:

ok single line: '310'

Test #129:

score: 15
Accepted
time: 0ms
memory: 5952kb

input:

226 100 10000 5
98
108
196
206
216

output:

230

result:

ok single line: '230'

Test #130:

score: 15
Accepted
time: 0ms
memory: 5660kb

input:

304 100 10000 5
98
108
196
206
294

output:

310

result:

ok single line: '310'

Test #131:

score: 15
Accepted
time: 0ms
memory: 5648kb

input:

314 100 10000 5
98
108
196
294
304

output:

320

result:

ok single line: '320'

Test #132:

score: 15
Accepted
time: 1ms
memory: 5920kb

input:

402 100 10000 5
98
108
196
294
392

output:

410

result:

ok single line: '410'

Test #133:

score: 15
Accepted
time: 1ms
memory: 5652kb

input:

236 100 10000 5
98
196
206
216
226

output:

240

result:

ok single line: '240'

Test #134:

score: 15
Accepted
time: 1ms
memory: 5880kb

input:

304 100 10000 5
98
196
206
216
294

output:

310

result:

ok single line: '310'

Test #135:

score: 15
Accepted
time: 1ms
memory: 5920kb

input:

314 100 10000 5
98
196
206
294
304

output:

320

result:

ok single line: '320'

Test #136:

score: 15
Accepted
time: 1ms
memory: 5888kb

input:

402 100 10000 5
98
196
206
294
392

output:

410

result:

ok single line: '410'

Test #137:

score: 15
Accepted
time: 1ms
memory: 5788kb

input:

324 100 10000 5
98
196
294
304
314

output:

330

result:

ok single line: '330'

Test #138:

score: 15
Accepted
time: 1ms
memory: 5772kb

input:

402 100 10000 5
98
196
294
304
392

output:

410

result:

ok single line: '410'

Test #139:

score: 15
Accepted
time: 1ms
memory: 5920kb

input:

412 100 10000 5
98
196
294
392
402

output:

420

result:

ok single line: '420'

Test #140:

score: 15
Accepted
time: 1ms
memory: 5720kb

input:

500 100 10000 5
98
196
294
392
490

output:

510

result:

ok single line: '510'

Test #141:

score: 15
Accepted
time: 1ms
memory: 5668kb

input:

10 2 10 2
1
3

output:

41

result:

ok single line: '41'

Test #142:

score: 15
Accepted
time: 1ms
memory: 5916kb

input:

100 21 10 2
5
54

output:

140

result:

ok single line: '140'

Test #143:

score: 0
Wrong Answer
time: 1ms
memory: 5720kb

input:

100 21 10 9
18
21
53
62
85
86
88
90
91

output:

131

result:

wrong answer 1st lines differ - expected: '121', found: '131'

Subtask #5:

score: 0
Skipped

Dependency #2:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%