답안 #979873

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
979873 2024-05-11T14:24:47 Z hariaakas646 Feast (NOI19_feast) C++14
100 / 100
246 ms 11720 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;


void usaco()
{
    freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
//    freopen("problem.out", "w", stdout);
}

int main() {
    // usaco();
    int n, k;
    scd(n);
    scd(k);

    
    vll pref(n+1);

    forr(i, 1, n+1) {
        lli a;
        sclld(a);
        pref[i] = pref[i-1] + a;
    }

    
    lli lo = 0;
    lli hi = 1e12;
    while(lo != hi) {
        lli mid = (lo+hi)/2;
        deque<pair<lli, int>> stk;
        stk.pb(mp(0, 0));

        vll dp(n+1);
        vi cnt(n+1);

        forr(j, 1, n+1) {
            dp[j] = dp[j-1];
            cnt[j] = cnt[j-1];
            if(stk.front().f + pref[j] - mid > dp[j]) {
                dp[j] = stk.front().f + pref[j] - mid;
                cnt[j] = cnt[stk.front().s]+1;
            }
            while(stk.size() && stk.back().f <= dp[j] - pref[j]) {
                stk.pop_back();
            }
            stk.pb(mp(dp[j] - pref[j], j));
            // printf("%lld ", dp[i][j]);
        }
        if(cnt[n] <= k) hi = mid;
        else lo = mid+1;
    }

    deque<pair<lli, int>> stk;
    stk.pb(mp(0, 0));

    vll dp(n+1);
    vi cnt(n+1);

    forr(j, 1, n+1) {
        dp[j] = dp[j-1];
        cnt[j] = cnt[j-1];
        if(stk.front().f + pref[j] - lo > dp[j]) {
            dp[j] = stk.front().f + pref[j] - lo;
            cnt[j] = cnt[stk.front().s]+1;
        }
        while(stk.size() && stk.back().f <= dp[j] - pref[j]) {
            stk.pop_back();
        }
        stk.pb(mp(dp[j] - pref[j], j));
        // printf("%lld ", dp[i][j]);
    }

    printf("%lld", dp[n] + lo * cnt[n]);
}

Compilation message

feast.cpp: In function 'void usaco()':
feast.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp: In function 'int main()':
feast.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
feast.cpp:37:5: note: in expansion of macro 'scd'
   37 |     scd(n);
      |     ^~~
feast.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
feast.cpp:38:5: note: in expansion of macro 'scd'
   38 |     scd(k);
      |     ^~~
feast.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 | #define sclld(t) scanf("%lld", &t)
      |                  ~~~~~^~~~~~~~~~~~
feast.cpp:45:9: note: in expansion of macro 'sclld'
   45 |         sclld(a);
      |         ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 158 ms 8788 KB Output is correct
2 Correct 165 ms 9004 KB Output is correct
3 Correct 168 ms 9456 KB Output is correct
4 Correct 166 ms 9040 KB Output is correct
5 Correct 160 ms 8984 KB Output is correct
6 Correct 161 ms 8868 KB Output is correct
7 Correct 157 ms 8784 KB Output is correct
8 Correct 185 ms 9040 KB Output is correct
9 Correct 159 ms 8788 KB Output is correct
10 Correct 162 ms 9040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 162 ms 9712 KB Output is correct
2 Correct 193 ms 11152 KB Output is correct
3 Correct 178 ms 11512 KB Output is correct
4 Correct 168 ms 11556 KB Output is correct
5 Correct 164 ms 8784 KB Output is correct
6 Correct 179 ms 11720 KB Output is correct
7 Correct 172 ms 11612 KB Output is correct
8 Correct 181 ms 9132 KB Output is correct
9 Correct 157 ms 8828 KB Output is correct
10 Correct 177 ms 10480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 238 ms 9248 KB Output is correct
2 Correct 231 ms 9140 KB Output is correct
3 Correct 245 ms 9216 KB Output is correct
4 Correct 243 ms 9132 KB Output is correct
5 Correct 232 ms 9156 KB Output is correct
6 Correct 233 ms 9272 KB Output is correct
7 Correct 240 ms 9324 KB Output is correct
8 Correct 246 ms 9232 KB Output is correct
9 Correct 230 ms 9308 KB Output is correct
10 Correct 238 ms 9352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 436 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 452 KB Output is correct
23 Correct 2 ms 488 KB Output is correct
24 Correct 2 ms 344 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 2 ms 344 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 2 ms 348 KB Output is correct
30 Correct 2 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 158 ms 8788 KB Output is correct
2 Correct 165 ms 9004 KB Output is correct
3 Correct 168 ms 9456 KB Output is correct
4 Correct 166 ms 9040 KB Output is correct
5 Correct 160 ms 8984 KB Output is correct
6 Correct 161 ms 8868 KB Output is correct
7 Correct 157 ms 8784 KB Output is correct
8 Correct 185 ms 9040 KB Output is correct
9 Correct 159 ms 8788 KB Output is correct
10 Correct 162 ms 9040 KB Output is correct
11 Correct 162 ms 9712 KB Output is correct
12 Correct 193 ms 11152 KB Output is correct
13 Correct 178 ms 11512 KB Output is correct
14 Correct 168 ms 11556 KB Output is correct
15 Correct 164 ms 8784 KB Output is correct
16 Correct 179 ms 11720 KB Output is correct
17 Correct 172 ms 11612 KB Output is correct
18 Correct 181 ms 9132 KB Output is correct
19 Correct 157 ms 8828 KB Output is correct
20 Correct 177 ms 10480 KB Output is correct
21 Correct 238 ms 9248 KB Output is correct
22 Correct 231 ms 9140 KB Output is correct
23 Correct 245 ms 9216 KB Output is correct
24 Correct 243 ms 9132 KB Output is correct
25 Correct 232 ms 9156 KB Output is correct
26 Correct 233 ms 9272 KB Output is correct
27 Correct 240 ms 9324 KB Output is correct
28 Correct 246 ms 9232 KB Output is correct
29 Correct 230 ms 9308 KB Output is correct
30 Correct 238 ms 9352 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 436 KB Output is correct
51 Correct 2 ms 348 KB Output is correct
52 Correct 2 ms 452 KB Output is correct
53 Correct 2 ms 488 KB Output is correct
54 Correct 2 ms 344 KB Output is correct
55 Correct 2 ms 348 KB Output is correct
56 Correct 2 ms 344 KB Output is correct
57 Correct 2 ms 348 KB Output is correct
58 Correct 2 ms 348 KB Output is correct
59 Correct 2 ms 348 KB Output is correct
60 Correct 2 ms 344 KB Output is correct
61 Correct 219 ms 8980 KB Output is correct
62 Correct 220 ms 9352 KB Output is correct
63 Correct 234 ms 9100 KB Output is correct
64 Correct 216 ms 9132 KB Output is correct
65 Correct 227 ms 9396 KB Output is correct
66 Correct 224 ms 9252 KB Output is correct
67 Correct 221 ms 9112 KB Output is correct
68 Correct 228 ms 9136 KB Output is correct
69 Correct 229 ms 9104 KB Output is correct
70 Correct 231 ms 9252 KB Output is correct