답안 #213302

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
213302 2020-03-25T12:39:27 Z Hideo 코알라 (JOI13_koala) C++11
0 / 100
130 ms 13184 KB
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2,fma")

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

#define all(s) s.begin(), s.end()
#define ok puts("ok")
#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >
#define pii pair < int, pi >
#define next next123
#define left left123

const int N = 1e5 + 7;
const ll INF = 1e18 + 7;

ll t[4 * N], lz[4 * N];
int a[N], b[N], md[N];
int s, m, d, c, n;
int cons;

void push (int v, int l, int r){
    if (l != r){
        lz[v + v] = min(lz[v + v], lz[v]);
        lz[v + v + 1] = min(lz[v + v + 1], lz[v]);
    }
    t[v] = min(t[v], lz[v]);
    lz[v] = INF;
}

void upd (int v, int l, int r, int ql, int qr, ll val){
    push(v, l, r);
    if (ql <= l && r <= qr){
        lz[v] = val;
        push(v, l, r);
        return;
    }
    if (r < ql || qr < l)
        return;
    int mid = (l + r) >> 1;
    upd(v + v, l, mid, ql, qr, val);
    upd(v + v + 1, mid + 1, r, ql, qr, val);
    t[v] = min(t[v + v], t[v + v + 1]);
}

ll get (int v, int l, int r, int ql, int qr){
    push(v, l, r);
    if (ql <= l && r <= qr)
        return t[v];
    if (r < ql || qr < l)
        return INF;
    int mid = (l + r) >> 1;
    return min(get(v + v, l, mid, ql, qr), get(v + v + 1, mid + 1, r, ql, qr));
}

main(){
    cin >> s >> m >> d >> c >> n;
    memset(lz, 0x3f3f3f3f, sizeof(lz));
    memset(t, 0x3f3f3f3f, sizeof(t));
    for (int i = 1; i <= n; i++){
        scanf("%d%d", &a[i], &b[i]);
        md[i] = (m - a[i]) % d;
        md[i] = (d - md[i]) % d;
    }
    md[0] = (m - s) % d;
    md[0] = (d - md[0]) % d;
    cons = 1LL * ((m - s + d - 1) / d) * 1LL * c;
    upd(1, 0, d, 0, md[0], cons);
    upd(1, 0, d, md[0] + 1, d, cons + c);
    for (int i = 1; i <= n; i++){
        int v1 = get(1, 0, d, 0, max(0, md[i] - 1)) + c - b[i];
        int v2 = get(1, 0, d, md[i], d) - b[i];
        upd(1, 0, d, md[i], md[i], min(v1, v2));
    }
    cout << -get(1, 0, d, 0, d);
}

Compilation message

koala.cpp:62:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
koala.cpp: In function 'int main()':
koala.cpp:67:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &a[i], &b[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 15 ms 13184 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 70 ms 7800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 130 ms 7800 KB Output isn't correct
2 Halted 0 ms 0 KB -