답안 #537109

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
537109 2022-03-14T14:31:46 Z qwerasdfzxcl Semiexpress (JOI17_semiexpress) C++14
100 / 100
1 ms 340 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;
typedef long long ll;
struct Block{
    ll l, r, t, i;
    Block(){}
    Block(ll _l, ll _r, ll _t, ll _i): l(_l), r(_r), t(_t), i(_i) {}
    bool operator<(const Block &B) const{
        return r-l < B.r - B.l;
    }
};
int a[3030];

signed main(){
    int n, m, k;
    scanf("%lld %lld %lld", &n, &m, &k);

    int A, B, C;
    scanf("%lld %lld %lld", &A, &B, &C);

    ll T;
    scanf("%lld", &T);
    for (int i=1;i<=m;i++) scanf("%lld", a+i);

    int ans = -1;
    if (T>=B*(a[m]-1)) ans++;
    priority_queue<Block> pq;
    for (int i=1;i<m;i++){
        if (T<(ll)B*(a[i]-1)) continue;

        ll dist = (T - (ll)B*(a[i]-1)) / A;
        ans += min((ll)a[i+1]-a[i]-1, dist) + 1;
        //printf(" %lld: %lld ", i, dist);

        if (dist < a[i+1]-a[i]-1){
            ll r = T - (ll)B*(a[i]-1) - (ll)C*(dist+1);
            //printf("%lld (%lld %lld %lld)", r, T, B*(a[i]-1), C*(dist+1));
            if (r>=0) pq.emplace(a[i]+dist+1, min((ll)a[i+1]-1, r/A + a[i]+dist+1), r, i);
        }
        //printf("\n");
    }

    for (int z=1;z<=k-m;z++){
        if (pq.empty()) break;

        auto B = pq.top(); pq.pop();
        //printf(" %lld %lld %lld %lld\n", B.l, B.r, B.t, B.i);
        ans += B.r - B.l + 1;

        if (B.r==a[B.i+1]-1) continue;
        if (B.t - (ll)C*(B.r-B.l+1) < 0) continue;

        ll nr = B.t - (ll)C*(B.r-B.l+1);

        pq.emplace(B.r+1, min((ll)a[B.i+1]-1, B.r+1 + nr/A), nr, B.i);
    }

    printf("%lld\n", max(ans, 0LL));
    return 0;
}

Compilation message

semiexpress.cpp: In function 'int main()':
semiexpress.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     scanf("%lld %lld %lld", &n, &m, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
semiexpress.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     scanf("%lld %lld %lld", &A, &B, &C);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
semiexpress.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     scanf("%lld", &T);
      |     ~~~~~^~~~~~~~~~~~
semiexpress.cpp:25:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     for (int i=1;i<=m;i++) scanf("%lld", a+i);
      |                            ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 308 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 212 KB Output is correct