답안 #763892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
763892 2023-06-23T02:28:00 Z OrazB 메기 농장 (IOI22_fish) C++17
53 / 100
887 ms 2097152 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
//Dijkstra->set
//set.find_by_order(x) x-position value
//set.order_of_key(x) number of strictly less elements don't need *set.??
#define N 100005
#define wr cout << "Continue debugging\n";
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define pii pair <ll, ll>
#define pb push_back
#define ff first
#define ss second

ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w){
	bool sub1 = 0, sub2 = 0;
	ll sum = 0, sum1 = 0, sum2 = 0;
	vector<pii> col1, col2;
	for (int i = 0; i < m; i++){
		sub1 |= (x[i]%2);
		sub2 |= (x[i]>1);
		sum += w[i];
		if (!x[i]) col1.pb({y[i], w[i]}), sum1 += w[i];
		else col2.pb({y[i], w[i]}), sum2 += w[i];
	}
	if (!sub1) return sum;
	if (!sub2){
		if (n == 2) return max(sum1, sum2);
		sort(all(col1)); sort(all(col2));
		ll mx = sum2;
		int pos = 0;
		for (auto i : col1){
			while(pos < col2.size() and col2[pos].ff <= i.ff){
				sum2 -= col2[pos].ss;
				pos++;
			}
			sum2 += i.ss;
			mx = max(mx, sum2);
		}
		return mx;
	}
	int nn = *max_element(all(y))+1;
	vector<vector<ll>> a(n+2, vector<ll> (nn+2, 0));
	for (int i = 0; i < m; i++){
		a[x[i]+1][y[i]+1] = w[i];
	}
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= nn; j++){
			a[i][j] += a[i][j-1];
		}
	}
	vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(nn+1, vector<ll>(nn+1, 0)));
	vector<vector<ll>> pref(nn+1, vector<ll>(nn+1, 0)), suff(nn+1, vector<ll>(nn+1, 0));
	ll ans = 0;
	for (int i = 2; i <= n; i++){
		for (int j = 0; j <= nn; j++){
			for (int k = 0; k <= nn; k++){
				if (k <= j){
					dp[i][j][k] = max(pref[k][j]+(a[i-1][j]-a[i-1][k]), suff[k][j]);
				}else{
					dp[i][j][k] = max(dp[i][j][k], suff[k][0]+a[i][k]-a[i][j]);
				}
				if (i == n) ans = max(ans, dp[i][j][k]);
			}
		}
		for (int j = 0; j <= nn; j++){
			pref[j][0] = dp[i][j][0];
			for (int k = 1; k <= nn; k++){
				pref[j][k] = max(pref[j][k-1], dp[i][j][k]-(k>j ? a[i][k]-a[i][j] : 0));
			}
			suff[j][nn] = dp[i][j][nn];
			for (int k = nn-1; k >= 0; k--) suff[j][k] = max(suff[j][k+1], dp[i][j][k]);
		}
	}
	return ans;
}

// int main ()
// {
// 	int n, m;
// 	cin >> n >> m;
// 	vector<int> x(m), y(m), w(m);
// 	for (int i = 0; i < m; i++) cin >> x[i] >> y[i] >> w[i];
// 	cout << max_weights(n,m,x,y,w);
// }	

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:40:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |    while(pos < col2.size() and col2[pos].ff <= i.ff){
      |          ~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 5704 KB Output is correct
2 Correct 25 ms 6560 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 76 ms 20920 KB Output is correct
6 Correct 86 ms 21308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 50 ms 10044 KB Output is correct
3 Correct 61 ms 11812 KB Output is correct
4 Correct 19 ms 5672 KB Output is correct
5 Correct 24 ms 6572 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 26 ms 5808 KB Output is correct
13 Correct 30 ms 6568 KB Output is correct
14 Correct 25 ms 5228 KB Output is correct
15 Correct 28 ms 5700 KB Output is correct
16 Correct 25 ms 5336 KB Output is correct
17 Correct 34 ms 5692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 25 ms 20656 KB Output is correct
3 Correct 37 ms 21568 KB Output is correct
4 Correct 34 ms 22700 KB Output is correct
5 Correct 50 ms 26144 KB Output is correct
6 Correct 44 ms 25488 KB Output is correct
7 Correct 47 ms 26044 KB Output is correct
8 Correct 48 ms 26100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 300 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 748 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 300 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 748 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 287 ms 218060 KB Output is correct
16 Correct 6 ms 4180 KB Output is correct
17 Correct 281 ms 221308 KB Output is correct
18 Correct 268 ms 221288 KB Output is correct
19 Correct 268 ms 221296 KB Output is correct
20 Correct 273 ms 221304 KB Output is correct
21 Correct 78 ms 58784 KB Output is correct
22 Correct 277 ms 223816 KB Output is correct
23 Correct 256 ms 219236 KB Output is correct
24 Correct 275 ms 220328 KB Output is correct
25 Correct 2 ms 1620 KB Output is correct
26 Correct 268 ms 219244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 300 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 748 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 287 ms 218060 KB Output is correct
16 Correct 6 ms 4180 KB Output is correct
17 Correct 281 ms 221308 KB Output is correct
18 Correct 268 ms 221288 KB Output is correct
19 Correct 268 ms 221296 KB Output is correct
20 Correct 273 ms 221304 KB Output is correct
21 Correct 78 ms 58784 KB Output is correct
22 Correct 277 ms 223816 KB Output is correct
23 Correct 256 ms 219236 KB Output is correct
24 Correct 275 ms 220328 KB Output is correct
25 Correct 2 ms 1620 KB Output is correct
26 Correct 268 ms 219244 KB Output is correct
27 Runtime error 887 ms 2097152 KB Execution killed with signal 9
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 25 ms 20656 KB Output is correct
3 Correct 37 ms 21568 KB Output is correct
4 Correct 34 ms 22700 KB Output is correct
5 Correct 50 ms 26144 KB Output is correct
6 Correct 44 ms 25488 KB Output is correct
7 Correct 47 ms 26044 KB Output is correct
8 Correct 48 ms 26100 KB Output is correct
9 Runtime error 633 ms 2097152 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 5704 KB Output is correct
2 Correct 25 ms 6560 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 76 ms 20920 KB Output is correct
6 Correct 86 ms 21308 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 50 ms 10044 KB Output is correct
9 Correct 61 ms 11812 KB Output is correct
10 Correct 19 ms 5672 KB Output is correct
11 Correct 24 ms 6572 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 26 ms 5808 KB Output is correct
19 Correct 30 ms 6568 KB Output is correct
20 Correct 25 ms 5228 KB Output is correct
21 Correct 28 ms 5700 KB Output is correct
22 Correct 25 ms 5336 KB Output is correct
23 Correct 34 ms 5692 KB Output is correct
24 Correct 1 ms 300 KB Output is correct
25 Correct 25 ms 20656 KB Output is correct
26 Correct 37 ms 21568 KB Output is correct
27 Correct 34 ms 22700 KB Output is correct
28 Correct 50 ms 26144 KB Output is correct
29 Correct 44 ms 25488 KB Output is correct
30 Correct 47 ms 26044 KB Output is correct
31 Correct 48 ms 26100 KB Output is correct
32 Correct 1 ms 296 KB Output is correct
33 Correct 1 ms 300 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 300 KB Output is correct
38 Correct 1 ms 304 KB Output is correct
39 Correct 1 ms 304 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 748 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 596 KB Output is correct
44 Correct 1 ms 300 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 287 ms 218060 KB Output is correct
47 Correct 6 ms 4180 KB Output is correct
48 Correct 281 ms 221308 KB Output is correct
49 Correct 268 ms 221288 KB Output is correct
50 Correct 268 ms 221296 KB Output is correct
51 Correct 273 ms 221304 KB Output is correct
52 Correct 78 ms 58784 KB Output is correct
53 Correct 277 ms 223816 KB Output is correct
54 Correct 256 ms 219236 KB Output is correct
55 Correct 275 ms 220328 KB Output is correct
56 Correct 2 ms 1620 KB Output is correct
57 Correct 268 ms 219244 KB Output is correct
58 Runtime error 887 ms 2097152 KB Execution killed with signal 9
59 Halted 0 ms 0 KB -