QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#559500#8268. TychoMispertion0 1ms5908kbC++233.2kb2024-09-11 22:33:412024-09-11 22:33:41

Judging History

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

  • [2024-09-11 22:33:41]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:5908kb
  • [2024-09-11 22:33:41]
  • 提交

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;
    for(int i = 1; i <= n; i++)
        cin >> x[i];
    segtree tr  = segtree(p + 1);
    for(int i = 1; i < p; i++)
        tr.sett(1, 0, p - 1, i, 2e18);
    for(int i = 1; i <= n; i++){
        dp[i] = min(tr.get(1, 0, p - 1, x[i] % p, p - 1), tr.get(1, 0, p - 1, 0, x[i] % p - 1) + p + d);
        dp[i] -= d;
        dp[i] += (int)ceil((ld)x[i] / (ld)p) * (p + d);
        tr.upd(1, 0, p - 1, x[i] % p, dp[i] - (int)ceil((ld)x[i] / (ld)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: 3656kb

input:

1000000000000 1 1000000 0

output:

1000000999999000000

result:

ok single line: '1000000999999000000'

Test #2:

score: 8
Accepted
time: 1ms
memory: 5704kb

input:

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

output:

122

result:

ok single line: '122'

Test #3:

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

input:

100 10 11 15
1
5
9
15
24
25
39
40
45
66
75
79
85
95
97

output:

159

result:

wrong answer 1st lines differ - expected: '138', found: '159'

Subtask #2:

score: 0
Wrong Answer

Test #11:

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

input:

108 100 10000 5
10
20
30
40
98

output:

10108

result:

wrong answer 1st lines differ - expected: '110', found: '10108'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #109:

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

input:

1000000000000 1 1000000 0

output:

1000000999999000000

result:

ok single line: '1000000999999000000'

Test #110:

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

input:

108 100 10000 5
10
20
30
40
98

output:

10108

result:

wrong answer 1st lines differ - expected: '110', found: '10108'

Subtask #5:

score: 0
Skipped

Dependency #2:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%