답안 #726398

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
726398 2023-04-18T21:03:01 Z vjudge1 Candies (JOI18_candies) C++17
100 / 100
602 ms 164164 KB
/*

   Wei Wai Wei Wai
   Zumigat nan damu dimi kwayt rayt

*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef complex<ld> point;
/*typedef __uint128_t L;
  struct FastMod {
  ull b, m;
  FastMod(ull b) : b(b), m(ull((L(1) << 64) / b)) {}
  ull reduce(ull a) {
  ull q = (ull)((L(m) * a) >> 64);
  ull r = a - q * b; // can be proven that 0 <= r < 2*b
  return r >= b ? r - b : r;
  }
  };
  FastMod FM(2);
  */
void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << H;
	debug_out(T...);
}

#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
#define F first
#define S second

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2e5 + 10;

int n, a[maxn];

vector<ll> dp[maxn << 2][4];

vector<ll> merge(vector<ll> a, vector<ll> b){
	vector<ll> res;
	if (a.empty() || b.empty()) return res;
	res.resize(a.size() + b.size() - 1, 0);
	int pta = 1, ptb = 1;
	for (int i = 1; i < res.size(); i++){
		assert(pta < a.size() || ptb < b.size());
		if (ptb >= b.size() || (pta < a.size() && a[pta] - a[pta-1] > b[ptb] - b[ptb-1])){
			res[i] = res[i-1] + a[pta] - a[pta-1];
			pta++;
		}
		else{
			res[i] = res[i-1] + b[ptb] - b[ptb-1];
			ptb++;
		}
	}
	return res;
}

void solve(int v, int l, int r){
	if (l + 1 == r){
		dp[v][0].push_back(0);
		dp[v][3].push_back(0);
		dp[v][3].push_back(a[l]);
		return;
	}
	int mid = (l + r) >> 1;
	int lc = v << 1;
	int rc = lc | 1;
	solve(lc, l, mid);
	solve(rc, mid, r);
	for (int i = 0; i < 4; i++){
		int sz = (r - l == 2? (i&1) + ((i>>1)&1) - (i == 3) * 2: (r - l == 3? max(1, (i&1) + ((i>>1)&1)): (r - l - 2 - (i&1) - ((i>>1)&1) + 1) / 2 + (i&1) + ((i>>1)&1))) + 1;
		dp[v][i].resize(sz, 0);
		for (int j = 0; j < 3; j++){
			vector<ll> tmp = merge(dp[lc][(i&2)+(j&1)], dp[rc][(j&2)+(i&1)]);
			for (int k = 0; k < tmp.size(); k++){
				dp[v][i][k] = max(dp[v][i][k], tmp[k]);
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);

	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	solve(1, 1, n+1);
	for (int i = 1; i <= (n+1)/2; i++){
		ll res = 0;
		for (int j = 0; j < 4; j++){
			if (dp[1][j].size() > i) res = max(res, dp[1][j][i]);
		}
		cout << res << '\n';
	}

	return 0;
}

Compilation message

candies.cpp: In function 'std::vector<long long int> merge(std::vector<long long int>, std::vector<long long int>)':
candies.cpp:56:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |  for (int i = 1; i < res.size(); i++){
      |                  ~~^~~~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from candies.cpp:8:
candies.cpp:57:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   assert(pta < a.size() || ptb < b.size());
      |          ~~~~^~~~~~~~~~
candies.cpp:57:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   assert(pta < a.size() || ptb < b.size());
      |                            ~~~~^~~~~~~~~~
candies.cpp:58:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |   if (ptb >= b.size() || (pta < a.size() && a[pta] - a[pta-1] > b[ptb] - b[ptb-1])){
      |       ~~~~^~~~~~~~~~~
candies.cpp:58:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |   if (ptb >= b.size() || (pta < a.size() && a[pta] - a[pta-1] > b[ptb] - b[ptb-1])){
      |                           ~~~~^~~~~~~~~~
candies.cpp: In function 'void solve(int, int, int)':
candies.cpp:87:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |    for (int k = 0; k < tmp.size(); k++){
      |                    ~~^~~~~~~~~~~~
candies.cpp: In function 'int main()':
candies.cpp:103:24: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  103 |    if (dp[1][j].size() > i) res = max(res, dp[1][j][i]);
      |        ~~~~~~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 76108 KB Output is correct
2 Correct 42 ms 76112 KB Output is correct
3 Correct 41 ms 76032 KB Output is correct
4 Correct 41 ms 76040 KB Output is correct
5 Correct 40 ms 76044 KB Output is correct
6 Correct 40 ms 76032 KB Output is correct
7 Correct 44 ms 76148 KB Output is correct
8 Correct 41 ms 76108 KB Output is correct
9 Correct 40 ms 76104 KB Output is correct
10 Correct 41 ms 76108 KB Output is correct
11 Correct 42 ms 76164 KB Output is correct
12 Correct 45 ms 76244 KB Output is correct
13 Correct 41 ms 76116 KB Output is correct
14 Correct 44 ms 76228 KB Output is correct
15 Correct 42 ms 76104 KB Output is correct
16 Correct 43 ms 76156 KB Output is correct
17 Correct 40 ms 76112 KB Output is correct
18 Correct 41 ms 76148 KB Output is correct
19 Correct 45 ms 76148 KB Output is correct
20 Correct 43 ms 76072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 76108 KB Output is correct
2 Correct 42 ms 76112 KB Output is correct
3 Correct 41 ms 76032 KB Output is correct
4 Correct 41 ms 76040 KB Output is correct
5 Correct 40 ms 76044 KB Output is correct
6 Correct 40 ms 76032 KB Output is correct
7 Correct 44 ms 76148 KB Output is correct
8 Correct 41 ms 76108 KB Output is correct
9 Correct 40 ms 76104 KB Output is correct
10 Correct 41 ms 76108 KB Output is correct
11 Correct 42 ms 76164 KB Output is correct
12 Correct 45 ms 76244 KB Output is correct
13 Correct 41 ms 76116 KB Output is correct
14 Correct 44 ms 76228 KB Output is correct
15 Correct 42 ms 76104 KB Output is correct
16 Correct 43 ms 76156 KB Output is correct
17 Correct 40 ms 76112 KB Output is correct
18 Correct 41 ms 76148 KB Output is correct
19 Correct 45 ms 76148 KB Output is correct
20 Correct 43 ms 76072 KB Output is correct
21 Correct 526 ms 163892 KB Output is correct
22 Correct 602 ms 163936 KB Output is correct
23 Correct 524 ms 163944 KB Output is correct
24 Correct 494 ms 163792 KB Output is correct
25 Correct 475 ms 163876 KB Output is correct
26 Correct 488 ms 163756 KB Output is correct
27 Correct 492 ms 164132 KB Output is correct
28 Correct 520 ms 163956 KB Output is correct
29 Correct 491 ms 163972 KB Output is correct
30 Correct 498 ms 164012 KB Output is correct
31 Correct 492 ms 164096 KB Output is correct
32 Correct 487 ms 164164 KB Output is correct
33 Correct 515 ms 163740 KB Output is correct
34 Correct 539 ms 163732 KB Output is correct
35 Correct 537 ms 163888 KB Output is correct
36 Correct 532 ms 163936 KB Output is correct
37 Correct 519 ms 163984 KB Output is correct
38 Correct 522 ms 164116 KB Output is correct
39 Correct 479 ms 163720 KB Output is correct
40 Correct 482 ms 163812 KB Output is correct
41 Correct 486 ms 163840 KB Output is correct
42 Correct 490 ms 164004 KB Output is correct
43 Correct 492 ms 163988 KB Output is correct
44 Correct 501 ms 164012 KB Output is correct
45 Correct 493 ms 163988 KB Output is correct
46 Correct 498 ms 163992 KB Output is correct
47 Correct 497 ms 163916 KB Output is correct
48 Correct 503 ms 163792 KB Output is correct
49 Correct 498 ms 163860 KB Output is correct
50 Correct 534 ms 163772 KB Output is correct