답안 #221865

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
221865 2020-04-11T10:42:20 Z patrikpavic2 Candies (JOI18_candies) C++17
100 / 100
1424 ms 123532 KB
#include <cstdio>
#include <vector>
#include <algorithm>

#define PB push_back
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair < int, int > pii;
typedef vector < ll > vi;

const int N = 4e5 + 500;

vi v[N][4];
int cnt = 0, n, A[N];

vi mrg(vi &A, vi &B){
	if(!A.size()) return B;
	if(!B.size()) return A;
	vi C = {A[0], B[0]};
	for(int i = 1;i < (int)A.size();i++)
		C.PB(A[i] - A[i - 1]);
	for(int i = 1;i < (int)B.size();i++)
		C.PB(B[i] - B[i - 1]);
	sort(C.rbegin(), C.rend());
	for(int i = 1;i < (int)C.size();i++)
		C[i] += C[i - 1];
	return C;
}

vi mks(vi A, vi B){
	if(A.size() < B.size()) swap(A, B);
	vi C = A;
	for(int i = 0;i < (int)B.size();i++)
		C[i] = max(C[i], B[i]);
	return C;
}

int solve(int l,int r){
	if(l == r){
		v[cnt][3].PB(A[l]);
		return cnt++;
	}
	int L = solve(l, (l + r) / 2);
	int R = solve((l + r) / 2 + 1, r);
	for(int i = 0;i < 4;i++){
		for(int j = 0;j < 4;j++){
			if((i&2) && (j&1)) continue;
			v[cnt][(i&1) + (j&2)] = mks(v[cnt][(i&1) + (j&2)], mrg(v[L][i], v[R][j]));
		}
	}
	return cnt++;	
}


int main(){
	scanf("%d", &n);
	for(int i = 0;i < n;i++)
		scanf("%d", A + i); 
	int kraj = solve(0, n - 1);
	vi fin = mks(mks(v[kraj][0], v[kraj][1]), mks(v[kraj][2], v[kraj][3]));
	for(ll x : fin) printf("%lld\n", x);
}











Compilation message

candies.cpp: In function 'int main()':
candies.cpp:60:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
candies.cpp:62:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", A + i); 
   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 38528 KB Output is correct
2 Correct 35 ms 38528 KB Output is correct
3 Correct 31 ms 38528 KB Output is correct
4 Correct 31 ms 38528 KB Output is correct
5 Correct 31 ms 38528 KB Output is correct
6 Correct 33 ms 38528 KB Output is correct
7 Correct 32 ms 38528 KB Output is correct
8 Correct 33 ms 38528 KB Output is correct
9 Correct 31 ms 38528 KB Output is correct
10 Correct 31 ms 38528 KB Output is correct
11 Correct 43 ms 38520 KB Output is correct
12 Correct 41 ms 38520 KB Output is correct
13 Correct 37 ms 38520 KB Output is correct
14 Correct 34 ms 38528 KB Output is correct
15 Correct 34 ms 38520 KB Output is correct
16 Correct 33 ms 38528 KB Output is correct
17 Correct 34 ms 38528 KB Output is correct
18 Correct 34 ms 38520 KB Output is correct
19 Correct 33 ms 38520 KB Output is correct
20 Correct 33 ms 38528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 38528 KB Output is correct
2 Correct 35 ms 38528 KB Output is correct
3 Correct 31 ms 38528 KB Output is correct
4 Correct 31 ms 38528 KB Output is correct
5 Correct 31 ms 38528 KB Output is correct
6 Correct 33 ms 38528 KB Output is correct
7 Correct 32 ms 38528 KB Output is correct
8 Correct 33 ms 38528 KB Output is correct
9 Correct 31 ms 38528 KB Output is correct
10 Correct 31 ms 38528 KB Output is correct
11 Correct 43 ms 38520 KB Output is correct
12 Correct 41 ms 38520 KB Output is correct
13 Correct 37 ms 38520 KB Output is correct
14 Correct 34 ms 38528 KB Output is correct
15 Correct 34 ms 38520 KB Output is correct
16 Correct 33 ms 38528 KB Output is correct
17 Correct 34 ms 38528 KB Output is correct
18 Correct 34 ms 38520 KB Output is correct
19 Correct 33 ms 38520 KB Output is correct
20 Correct 33 ms 38528 KB Output is correct
21 Correct 1407 ms 121484 KB Output is correct
22 Correct 1424 ms 123528 KB Output is correct
23 Correct 1391 ms 123332 KB Output is correct
24 Correct 922 ms 123404 KB Output is correct
25 Correct 909 ms 123284 KB Output is correct
26 Correct 936 ms 123264 KB Output is correct
27 Correct 874 ms 123532 KB Output is correct
28 Correct 867 ms 123368 KB Output is correct
29 Correct 896 ms 123300 KB Output is correct
30 Correct 897 ms 123400 KB Output is correct
31 Correct 887 ms 123488 KB Output is correct
32 Correct 878 ms 123304 KB Output is correct
33 Correct 997 ms 123280 KB Output is correct
34 Correct 1014 ms 123280 KB Output is correct
35 Correct 1014 ms 123252 KB Output is correct
36 Correct 1383 ms 123276 KB Output is correct
37 Correct 1359 ms 123152 KB Output is correct
38 Correct 1383 ms 123284 KB Output is correct
39 Correct 915 ms 123016 KB Output is correct
40 Correct 910 ms 123020 KB Output is correct
41 Correct 905 ms 122992 KB Output is correct
42 Correct 899 ms 123284 KB Output is correct
43 Correct 878 ms 123200 KB Output is correct
44 Correct 865 ms 123284 KB Output is correct
45 Correct 884 ms 123268 KB Output is correct
46 Correct 885 ms 123300 KB Output is correct
47 Correct 882 ms 123260 KB Output is correct
48 Correct 1016 ms 122852 KB Output is correct
49 Correct 1024 ms 123024 KB Output is correct
50 Correct 1002 ms 123028 KB Output is correct