답안 #391802

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
391802 2021-04-19T23:32:49 Z maomao90 Feast (NOI19_feast) C++14
100 / 100
180 ms 16304 KB
#include <bits/stdc++.h>
using namespace std;

#define mnto(x, y) x = min(x, (__typeof__(x)) y)
#define mxto(x, y) x = max(x, (__typeof__(x)) y)
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb emplace_back
typedef vector<int> vi;
typedef vector<ii> vii;

#define INF 1000000005
#define LINF 100000000000000005
#define MOD 1000000007
#define MAXN 300005

int n, k;
int a[MAXN];
pll dp[MAXN], g[MAXN];
ll pre[MAXN];
pll check(ll x) {
	// dp[i] = max(g[j] - pre[j]) + pre[i]
	pll curMax = MP(0, 0);
	REP (i, 1, n + 1) {
		dp[i] = MP(curMax.FI + pre[i] - x, curMax.SE + 1);
		g[i] = max(g[i - 1], dp[i]);
		if (g[i].FI - pre[i] > curMax.FI || (g[i].FI - pre[i] == curMax.FI && g[i].SE < curMax.SE)) {
			curMax = MP(g[i].FI - pre[i], g[i].SE);
		}
	}
	return g[n];
}

int main() {
	scanf("%d%d", &n, &k);
	REP (i, 1, n + 1) scanf("%d", &a[i]);
	REP (i, 1, n + 1) {
		pre[i] = a[i] + pre[i - 1];
	}
	ll lo = 0, hi = LINF, mid;
	while (lo < hi) {
		mid = hi + lo >> 1;
		pll temp = check(mid);
		if (temp.SE <= k) {
			hi = mid;
		} else {
			lo = mid + 1;
		}
	}
	pll ans = check(hi);
	printf("%lld\n", ans.FI + k * hi);
	return 0;
}

Compilation message

feast.cpp: In function 'int main()':
feast.cpp:51:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |   mid = hi + lo >> 1;
      |         ~~~^~~~
feast.cpp:44:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |  scanf("%d%d", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~
feast.cpp:45:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |  REP (i, 1, n + 1) scanf("%d", &a[i]);
      |                    ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 15876 KB Output is correct
2 Correct 110 ms 15792 KB Output is correct
3 Correct 107 ms 16088 KB Output is correct
4 Correct 106 ms 15968 KB Output is correct
5 Correct 126 ms 15820 KB Output is correct
6 Correct 106 ms 15556 KB Output is correct
7 Correct 105 ms 15552 KB Output is correct
8 Correct 106 ms 15932 KB Output is correct
9 Correct 104 ms 15580 KB Output is correct
10 Correct 105 ms 15736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 14020 KB Output is correct
2 Correct 97 ms 14324 KB Output is correct
3 Correct 109 ms 13984 KB Output is correct
4 Correct 92 ms 14028 KB Output is correct
5 Correct 115 ms 15544 KB Output is correct
6 Correct 92 ms 13892 KB Output is correct
7 Correct 101 ms 14256 KB Output is correct
8 Correct 105 ms 15940 KB Output is correct
9 Correct 100 ms 15556 KB Output is correct
10 Correct 96 ms 14244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 131 ms 16008 KB Output is correct
2 Correct 128 ms 15884 KB Output is correct
3 Correct 129 ms 15976 KB Output is correct
4 Correct 125 ms 16012 KB Output is correct
5 Correct 125 ms 15940 KB Output is correct
6 Correct 127 ms 16088 KB Output is correct
7 Correct 128 ms 16100 KB Output is correct
8 Correct 124 ms 15968 KB Output is correct
9 Correct 126 ms 16212 KB Output is correct
10 Correct 126 ms 16076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 1 ms 316 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 1 ms 444 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 15876 KB Output is correct
2 Correct 110 ms 15792 KB Output is correct
3 Correct 107 ms 16088 KB Output is correct
4 Correct 106 ms 15968 KB Output is correct
5 Correct 126 ms 15820 KB Output is correct
6 Correct 106 ms 15556 KB Output is correct
7 Correct 105 ms 15552 KB Output is correct
8 Correct 106 ms 15932 KB Output is correct
9 Correct 104 ms 15580 KB Output is correct
10 Correct 105 ms 15736 KB Output is correct
11 Correct 95 ms 14020 KB Output is correct
12 Correct 97 ms 14324 KB Output is correct
13 Correct 109 ms 13984 KB Output is correct
14 Correct 92 ms 14028 KB Output is correct
15 Correct 115 ms 15544 KB Output is correct
16 Correct 92 ms 13892 KB Output is correct
17 Correct 101 ms 14256 KB Output is correct
18 Correct 105 ms 15940 KB Output is correct
19 Correct 100 ms 15556 KB Output is correct
20 Correct 96 ms 14244 KB Output is correct
21 Correct 131 ms 16008 KB Output is correct
22 Correct 128 ms 15884 KB Output is correct
23 Correct 129 ms 15976 KB Output is correct
24 Correct 125 ms 16012 KB Output is correct
25 Correct 125 ms 15940 KB Output is correct
26 Correct 127 ms 16088 KB Output is correct
27 Correct 128 ms 16100 KB Output is correct
28 Correct 124 ms 15968 KB Output is correct
29 Correct 126 ms 16212 KB Output is correct
30 Correct 126 ms 16076 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 308 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 300 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 1 ms 332 KB Output is correct
53 Correct 2 ms 332 KB Output is correct
54 Correct 1 ms 316 KB Output is correct
55 Correct 2 ms 332 KB Output is correct
56 Correct 2 ms 332 KB Output is correct
57 Correct 2 ms 332 KB Output is correct
58 Correct 1 ms 444 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 180 ms 15868 KB Output is correct
62 Correct 167 ms 16304 KB Output is correct
63 Correct 136 ms 15764 KB Output is correct
64 Correct 165 ms 16128 KB Output is correct
65 Correct 168 ms 16124 KB Output is correct
66 Correct 161 ms 16088 KB Output is correct
67 Correct 160 ms 15836 KB Output is correct
68 Correct 129 ms 16068 KB Output is correct
69 Correct 126 ms 15804 KB Output is correct
70 Correct 121 ms 15756 KB Output is correct