답안 #645834

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
645834 2022-09-28T06:57:35 Z ymm 메기 농장 (IOI22_fish) C++17
100 / 100
172 ms 35496 KB
#include "fish.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

const int N = 300'010;
ll dpu[N*2], dpd[N*2];
int n, m;
vector<pii> C[N];

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
	n = N; m = M;
	Loop (i,0,m)
		C[X[i]].push_back({Y[i], i});
	Loop (i,0,n) {
		C[i].push_back({-1, m});
		X.push_back(i);
		Y.push_back(-1);
		++m;
		C[i].push_back({n, m});
		X.push_back(i);
		Y.push_back(n);
		++m;
		sort(C[i].begin(), C[i].end());
	}
	W.resize(m, 0);

	// base
	Loop (i,0,C[0].size())
		dpu[C[0][i].second] = 0;
	dpd[C[0].front().second] = 0;
	Loop (i,1,C[0].size()) {
		int x = C[0][i].second;
		int y = C[0][i-1].second;
		dpd[x] = dpd[y] + W[x];
	}

	// second base
	dpu[C[1].back().second] = 0;
	int p = C[1].size()-1;
	LoopR (i,0,C[1].size()-1) {
		int x = C[1][i].second;
		int y = C[1][i+1].second;
		while (p > 0 && C[0][p-1].first > C[1][i].first)
			--p;
		dpu[x] = max(dpu[y], dpu[C[0][p].second]) + W[x];
	}
	dpd[C[1].front().second] = dpu[C[0].front().second];
	p = 0;
	Loop (i,1,C[1].size()) {
		int x = C[1][i].second;
		int y = C[1][i-1].second;
		while (p+1 < C[0].size() && C[0][p+1].first < C[1][i].first)
			++p;
		dpd[x] = max(dpd[y], dpd[C[0][p].second]) + W[x];
	}

	// update
	Loop (c,2,n) {
		dpu[C[c].back().second] = dpd[C[c-2].back().second];
		p = C[c-1].size()-1;
		LoopR (i,0,C[c].size()-1) {
			int x = C[c][i].second;
			int y = C[c][i+1].second;
			while (p > 0 && C[c-1][p-1].first > C[c][i].first)
				--p;
			dpu[x] = max(dpu[y], dpu[C[c-1][p].second]) + W[x];
		}
		dpd[C[c].front().second] = max(dpu[C[c-1].front().second], dpd[C[c-2].back().second]);
		p = 0;
		Loop (i,1,C[c].size()) {
			int x = C[c][i].second;
			int y = C[c][i-1].second;
			while (p+1 < C[c-1].size() && C[c-1][p+1].first < C[c][i].first)
				++p;
			dpd[x] = max(dpd[y], dpd[C[c-1][p].second]) + W[x];
		}
	}

	// debug
	//Loop (i,0,m) {
	//	cout << "[" << X[i] << ' ' << Y[i] << ' ' << W[i] << "]: " << dpu[i] << ' ' << dpd[i] << '\n';
	//}

	// ans
	ll ans = max(dpu[C[n-1].front().second], dpd[C[n-2].back().second]);
	return ans;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:3:40: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    3 | #define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
      |                                        ^
fish.cpp:34:2: note: in expansion of macro 'Loop'
   34 |  Loop (i,0,C[0].size())
      |  ^~~~
fish.cpp:3:40: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    3 | #define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
      |                                        ^
fish.cpp:37:2: note: in expansion of macro 'Loop'
   37 |  Loop (i,1,C[0].size()) {
      |  ^~~~
fish.cpp:3:40: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    3 | #define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
      |                                        ^
fish.cpp:55:2: note: in expansion of macro 'Loop'
   55 |  Loop (i,1,C[1].size()) {
      |  ^~~~
fish.cpp:58:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |   while (p+1 < C[0].size() && C[0][p+1].first < C[1][i].first)
      |          ~~~~^~~~~~~~~~~~~
fish.cpp:3:40: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    3 | #define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
      |                                        ^
fish.cpp:76:3: note: in expansion of macro 'Loop'
   76 |   Loop (i,1,C[c].size()) {
      |   ^~~~
fish.cpp:79:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |    while (p+1 < C[c-1].size() && C[c-1][p+1].first < C[c][i].first)
      |           ~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 18972 KB Output is correct
2 Correct 63 ms 20568 KB Output is correct
3 Correct 18 ms 15932 KB Output is correct
4 Correct 19 ms 15876 KB Output is correct
5 Correct 135 ms 29976 KB Output is correct
6 Correct 167 ms 31432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 85 ms 22628 KB Output is correct
3 Correct 92 ms 25308 KB Output is correct
4 Correct 49 ms 18872 KB Output is correct
5 Correct 67 ms 20608 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
10 Correct 20 ms 15972 KB Output is correct
11 Correct 19 ms 15964 KB Output is correct
12 Correct 56 ms 18888 KB Output is correct
13 Correct 56 ms 20612 KB Output is correct
14 Correct 47 ms 18896 KB Output is correct
15 Correct 57 ms 20196 KB Output is correct
16 Correct 46 ms 18868 KB Output is correct
17 Correct 66 ms 20160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 15932 KB Output is correct
2 Correct 18 ms 15884 KB Output is correct
3 Correct 38 ms 18252 KB Output is correct
4 Correct 32 ms 18044 KB Output is correct
5 Correct 59 ms 22340 KB Output is correct
6 Correct 60 ms 22976 KB Output is correct
7 Correct 66 ms 23704 KB Output is correct
8 Correct 60 ms 23712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 5 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 3 ms 7252 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7508 KB Output is correct
11 Correct 4 ms 7380 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 3 ms 7252 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 5 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 3 ms 7252 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7508 KB Output is correct
11 Correct 4 ms 7380 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 3 ms 7252 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 3 ms 7380 KB Output is correct
16 Correct 6 ms 7488 KB Output is correct
17 Correct 23 ms 10216 KB Output is correct
18 Correct 24 ms 10564 KB Output is correct
19 Correct 19 ms 10500 KB Output is correct
20 Correct 20 ms 10432 KB Output is correct
21 Correct 19 ms 10436 KB Output is correct
22 Correct 34 ms 13740 KB Output is correct
23 Correct 7 ms 7976 KB Output is correct
24 Correct 20 ms 9556 KB Output is correct
25 Correct 4 ms 7380 KB Output is correct
26 Correct 7 ms 7848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 5 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 3 ms 7252 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7508 KB Output is correct
11 Correct 4 ms 7380 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 3 ms 7252 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 3 ms 7380 KB Output is correct
16 Correct 6 ms 7488 KB Output is correct
17 Correct 23 ms 10216 KB Output is correct
18 Correct 24 ms 10564 KB Output is correct
19 Correct 19 ms 10500 KB Output is correct
20 Correct 20 ms 10432 KB Output is correct
21 Correct 19 ms 10436 KB Output is correct
22 Correct 34 ms 13740 KB Output is correct
23 Correct 7 ms 7976 KB Output is correct
24 Correct 20 ms 9556 KB Output is correct
25 Correct 4 ms 7380 KB Output is correct
26 Correct 7 ms 7848 KB Output is correct
27 Correct 5 ms 7764 KB Output is correct
28 Correct 75 ms 22636 KB Output is correct
29 Correct 113 ms 28476 KB Output is correct
30 Correct 118 ms 28004 KB Output is correct
31 Correct 110 ms 28076 KB Output is correct
32 Correct 104 ms 28840 KB Output is correct
33 Correct 117 ms 28084 KB Output is correct
34 Correct 118 ms 27516 KB Output is correct
35 Correct 45 ms 15048 KB Output is correct
36 Correct 115 ms 26992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 15932 KB Output is correct
2 Correct 18 ms 15884 KB Output is correct
3 Correct 38 ms 18252 KB Output is correct
4 Correct 32 ms 18044 KB Output is correct
5 Correct 59 ms 22340 KB Output is correct
6 Correct 60 ms 22976 KB Output is correct
7 Correct 66 ms 23704 KB Output is correct
8 Correct 60 ms 23712 KB Output is correct
9 Correct 58 ms 23000 KB Output is correct
10 Correct 48 ms 17924 KB Output is correct
11 Correct 102 ms 28896 KB Output is correct
12 Correct 4 ms 7252 KB Output is correct
13 Correct 4 ms 7252 KB Output is correct
14 Correct 4 ms 7348 KB Output is correct
15 Correct 6 ms 7252 KB Output is correct
16 Correct 4 ms 7252 KB Output is correct
17 Correct 3 ms 7252 KB Output is correct
18 Correct 17 ms 15932 KB Output is correct
19 Correct 18 ms 15996 KB Output is correct
20 Correct 18 ms 15908 KB Output is correct
21 Correct 17 ms 15932 KB Output is correct
22 Correct 67 ms 22832 KB Output is correct
23 Correct 98 ms 27280 KB Output is correct
24 Correct 108 ms 29024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 18972 KB Output is correct
2 Correct 63 ms 20568 KB Output is correct
3 Correct 18 ms 15932 KB Output is correct
4 Correct 19 ms 15876 KB Output is correct
5 Correct 135 ms 29976 KB Output is correct
6 Correct 167 ms 31432 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 85 ms 22628 KB Output is correct
9 Correct 92 ms 25308 KB Output is correct
10 Correct 49 ms 18872 KB Output is correct
11 Correct 67 ms 20608 KB Output is correct
12 Correct 4 ms 7252 KB Output is correct
13 Correct 4 ms 7252 KB Output is correct
14 Correct 4 ms 7252 KB Output is correct
15 Correct 4 ms 7252 KB Output is correct
16 Correct 20 ms 15972 KB Output is correct
17 Correct 19 ms 15964 KB Output is correct
18 Correct 56 ms 18888 KB Output is correct
19 Correct 56 ms 20612 KB Output is correct
20 Correct 47 ms 18896 KB Output is correct
21 Correct 57 ms 20196 KB Output is correct
22 Correct 46 ms 18868 KB Output is correct
23 Correct 66 ms 20160 KB Output is correct
24 Correct 18 ms 15932 KB Output is correct
25 Correct 18 ms 15884 KB Output is correct
26 Correct 38 ms 18252 KB Output is correct
27 Correct 32 ms 18044 KB Output is correct
28 Correct 59 ms 22340 KB Output is correct
29 Correct 60 ms 22976 KB Output is correct
30 Correct 66 ms 23704 KB Output is correct
31 Correct 60 ms 23712 KB Output is correct
32 Correct 4 ms 7252 KB Output is correct
33 Correct 4 ms 7252 KB Output is correct
34 Correct 5 ms 7252 KB Output is correct
35 Correct 4 ms 7252 KB Output is correct
36 Correct 4 ms 7252 KB Output is correct
37 Correct 4 ms 7252 KB Output is correct
38 Correct 3 ms 7252 KB Output is correct
39 Correct 4 ms 7252 KB Output is correct
40 Correct 4 ms 7380 KB Output is correct
41 Correct 4 ms 7508 KB Output is correct
42 Correct 4 ms 7380 KB Output is correct
43 Correct 4 ms 7380 KB Output is correct
44 Correct 3 ms 7252 KB Output is correct
45 Correct 4 ms 7380 KB Output is correct
46 Correct 3 ms 7380 KB Output is correct
47 Correct 6 ms 7488 KB Output is correct
48 Correct 23 ms 10216 KB Output is correct
49 Correct 24 ms 10564 KB Output is correct
50 Correct 19 ms 10500 KB Output is correct
51 Correct 20 ms 10432 KB Output is correct
52 Correct 19 ms 10436 KB Output is correct
53 Correct 34 ms 13740 KB Output is correct
54 Correct 7 ms 7976 KB Output is correct
55 Correct 20 ms 9556 KB Output is correct
56 Correct 4 ms 7380 KB Output is correct
57 Correct 7 ms 7848 KB Output is correct
58 Correct 5 ms 7764 KB Output is correct
59 Correct 75 ms 22636 KB Output is correct
60 Correct 113 ms 28476 KB Output is correct
61 Correct 118 ms 28004 KB Output is correct
62 Correct 110 ms 28076 KB Output is correct
63 Correct 104 ms 28840 KB Output is correct
64 Correct 117 ms 28084 KB Output is correct
65 Correct 118 ms 27516 KB Output is correct
66 Correct 45 ms 15048 KB Output is correct
67 Correct 115 ms 26992 KB Output is correct
68 Correct 58 ms 23000 KB Output is correct
69 Correct 48 ms 17924 KB Output is correct
70 Correct 102 ms 28896 KB Output is correct
71 Correct 4 ms 7252 KB Output is correct
72 Correct 4 ms 7252 KB Output is correct
73 Correct 4 ms 7348 KB Output is correct
74 Correct 6 ms 7252 KB Output is correct
75 Correct 4 ms 7252 KB Output is correct
76 Correct 3 ms 7252 KB Output is correct
77 Correct 17 ms 15932 KB Output is correct
78 Correct 18 ms 15996 KB Output is correct
79 Correct 18 ms 15908 KB Output is correct
80 Correct 17 ms 15932 KB Output is correct
81 Correct 67 ms 22832 KB Output is correct
82 Correct 98 ms 27280 KB Output is correct
83 Correct 108 ms 29024 KB Output is correct
84 Correct 144 ms 34188 KB Output is correct
85 Correct 141 ms 33816 KB Output is correct
86 Correct 161 ms 34728 KB Output is correct
87 Correct 172 ms 34616 KB Output is correct
88 Correct 4 ms 7252 KB Output is correct
89 Correct 161 ms 35496 KB Output is correct
90 Correct 135 ms 32912 KB Output is correct
91 Correct 148 ms 32496 KB Output is correct