답안 #832961

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832961 2023-08-21T17:14:15 Z CSQ31 Feast (NOI19_feast) C++17
100 / 100
123 ms 9232 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
const int MAXN = 3e5+5;
const ll INF = 1e18;
int n,k;
ll a[MAXN],dp[MAXN];
ll find(ll x){
	for(int i=1;i<=n;i++)dp[i] = INF;
	vector<int>seg(n+1,0);
	dp[0] = 0;
	ll mx = 0;
	int cur = 0;
	for(int i=1;i<=n;i++){
		dp[i] = a[i] + mx - x;
		seg[i] = cur+1;
		
		if(dp[i-1] > dp[i]){
			dp[i] = dp[i-1];
			seg[i] = seg[i-1];
		}
		if(dp[i] - a[i] == mx)cur = max(cur,seg[i]);
		else if(dp[i] - a[i] > mx){
			mx = dp[i] - a[i];
			cur = seg[i];
		}
		
	}
	return seg[n];
}
int main()
{
	owo
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		a[i]+=a[i-1];
	}
	ll l = 0,r = 1e15;
	while(r>l){
		ll m = (l+r+1)/2;
		if(find(m) < k)r = m-1;
		else l = m;
	}
	find(r);
	cout<<dp[n] + k*1LL*r;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 6660 KB Output is correct
2 Correct 57 ms 8920 KB Output is correct
3 Correct 52 ms 9068 KB Output is correct
4 Correct 50 ms 9012 KB Output is correct
5 Correct 51 ms 8908 KB Output is correct
6 Correct 55 ms 8728 KB Output is correct
7 Correct 53 ms 8820 KB Output is correct
8 Correct 50 ms 8984 KB Output is correct
9 Correct 50 ms 8788 KB Output is correct
10 Correct 50 ms 8860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 6180 KB Output is correct
2 Correct 58 ms 7304 KB Output is correct
3 Correct 55 ms 7064 KB Output is correct
4 Correct 49 ms 7184 KB Output is correct
5 Correct 63 ms 8804 KB Output is correct
6 Correct 61 ms 7180 KB Output is correct
7 Correct 50 ms 7332 KB Output is correct
8 Correct 75 ms 8968 KB Output is correct
9 Correct 63 ms 8772 KB Output is correct
10 Correct 48 ms 7236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 6900 KB Output is correct
2 Correct 85 ms 9088 KB Output is correct
3 Correct 80 ms 9024 KB Output is correct
4 Correct 85 ms 9024 KB Output is correct
5 Correct 82 ms 9152 KB Output is correct
6 Correct 80 ms 9164 KB Output is correct
7 Correct 85 ms 9216 KB Output is correct
8 Correct 79 ms 9064 KB Output is correct
9 Correct 89 ms 9160 KB Output is correct
10 Correct 82 ms 9200 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 1 ms 340 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 328 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 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 1 ms 340 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 328 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 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 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 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 1 ms 340 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 328 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 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 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 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 340 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 368 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 6660 KB Output is correct
2 Correct 57 ms 8920 KB Output is correct
3 Correct 52 ms 9068 KB Output is correct
4 Correct 50 ms 9012 KB Output is correct
5 Correct 51 ms 8908 KB Output is correct
6 Correct 55 ms 8728 KB Output is correct
7 Correct 53 ms 8820 KB Output is correct
8 Correct 50 ms 8984 KB Output is correct
9 Correct 50 ms 8788 KB Output is correct
10 Correct 50 ms 8860 KB Output is correct
11 Correct 56 ms 6180 KB Output is correct
12 Correct 58 ms 7304 KB Output is correct
13 Correct 55 ms 7064 KB Output is correct
14 Correct 49 ms 7184 KB Output is correct
15 Correct 63 ms 8804 KB Output is correct
16 Correct 61 ms 7180 KB Output is correct
17 Correct 50 ms 7332 KB Output is correct
18 Correct 75 ms 8968 KB Output is correct
19 Correct 63 ms 8772 KB Output is correct
20 Correct 48 ms 7236 KB Output is correct
21 Correct 81 ms 6900 KB Output is correct
22 Correct 85 ms 9088 KB Output is correct
23 Correct 80 ms 9024 KB Output is correct
24 Correct 85 ms 9024 KB Output is correct
25 Correct 82 ms 9152 KB Output is correct
26 Correct 80 ms 9164 KB Output is correct
27 Correct 85 ms 9216 KB Output is correct
28 Correct 79 ms 9064 KB Output is correct
29 Correct 89 ms 9160 KB Output is correct
30 Correct 82 ms 9200 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 328 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 364 KB Output is correct
56 Correct 1 ms 368 KB Output is correct
57 Correct 1 ms 336 KB Output is correct
58 Correct 1 ms 336 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 344 KB Output is correct
61 Correct 107 ms 9028 KB Output is correct
62 Correct 107 ms 9232 KB Output is correct
63 Correct 90 ms 8996 KB Output is correct
64 Correct 110 ms 9180 KB Output is correct
65 Correct 123 ms 9164 KB Output is correct
66 Correct 110 ms 9144 KB Output is correct
67 Correct 107 ms 8988 KB Output is correct
68 Correct 91 ms 9180 KB Output is correct
69 Correct 83 ms 8968 KB Output is correct
70 Correct 83 ms 8960 KB Output is correct