답안 #1106879

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1106879 2024-10-31T08:29:53 Z pit4h 메기 농장 (IOI22_fish) C++17
9 / 100
143 ms 23880 KB
#include "fish.h"

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pi=pair<int,int>;
using vi=vector<int>;
#define mp make_pair
#define eb emplace_back
#define x first
#define y second
#define sz(x)int((x).size())
#define all(x)(x).begin(),(x).end()
#define rep(i,a,b)for(int i=(a);i<(b);i++)
#define per(i,a,b)for(int i=(b)-1;i>=(a);i--)
bool ckmin(auto&a,auto b){return b<a?a=b,1:0;}
bool ckmax(auto&a,auto b){return b>a?a=b,1:0;}
#ifdef LOCAL
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.x<<", "<<p.y<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto&e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X);
#else
#define debug(...){}
#endif

struct Container {
	ll shift=0,best=0;
	void add(ll delta) {
		shift += delta;
		best += delta;
	}
	void ins(ll v) {
		ckmax(best, v);
	}
	ll get() {
		return best;
	}
};

long long max_weights(int N, int M, vector<int> X, vector<int> Y,
                      vector<int> W) {

	vector<vector<pi>> sweep(N + 2);

	rep(i,0,M) {
		sweep[X[i]+1].eb(Y[i],W[i]);
	}

	rep(i,0,N+2) { 
		sweep[i].eb(N,0);
		sort(all(sweep[i]));	
	}

	vector<vector<ll>> dp(N+2);
	vector<ll> best_dp(N+2);

	rep(i,0,N+2) {
		dp[i].resize(sz(sweep[i]));
	}

	ll ans = 0;

	rep(i,1,N+1) {
		debug(i);
		int ptr_l=0,ptr_r=0;
		ll sum_l=0,sum_cur=0,sum_r=0;

		Container best_l;

		rep(j,0,sz(sweep[i])) {
			auto [y,w] = sweep[i][j];

			while (ptr_l < sz(sweep[i-1]) && sweep[i-1][ptr_l].x < y) {
				sum_l+=sweep[i-1][ptr_l].y;
				best_l.ins(dp[i-1][ptr_l]);
				best_l.add(sweep[i-1][ptr_l].y);
				ptr_l++;	
			}

			while (ptr_r < sz(sweep[i+1]) && sweep[i+1][ptr_r].x < y) {
				sum_r+=sweep[i+1][ptr_r].y;
				ptr_r++;
			}

			ckmax(dp[i][j], best_l.get());	

			ckmax(dp[i+1][ptr_r], best_l.get() + sum_r);         // cur takes from left and right
			ckmax(dp[i+1][ptr_r], best_dp[i-1] + sum_r);         // prev does not take any from column i
			ckmax(dp[i+1][ptr_r], best_dp[i] + sum_r - sum_cur); // prev takes unlimited amount from column i 

			sum_cur+=w;
		}
		
		rep(s,0,2) {
			rep(j,0,sz(sweep[i-s])) {
				ckmax(best_dp[i-s], dp[i-s][j]);
			}
		}
		debug(dp);
	}

	rep(i,0,N+2) {
		rep(j,0,sz(dp[i])) {
			ckmax(ans, dp[i][j]);
		}
	}

	return ans;
}

Compilation message

fish.cpp:16:12: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   16 | bool ckmin(auto&a,auto b){return b<a?a=b,1:0;}
      |            ^~~~
fish.cpp:16:19: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   16 | bool ckmin(auto&a,auto b){return b<a?a=b,1:0;}
      |                   ^~~~
fish.cpp:17:12: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   17 | bool ckmax(auto&a,auto b){return b>a?a=b,1:0;}
      |            ^~~~
fish.cpp:17:19: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   17 | bool ckmax(auto&a,auto b){return b>a?a=b,1:0;}
      |                   ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 14012 KB Output is correct
2 Correct 49 ms 16060 KB Output is correct
3 Correct 15 ms 12112 KB Output is correct
4 Correct 18 ms 12112 KB Output is correct
5 Correct 95 ms 23736 KB Output is correct
6 Correct 143 ms 23880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 52 ms 17116 KB Output is correct
3 Correct 73 ms 19892 KB Output is correct
4 Correct 47 ms 14036 KB Output is correct
5 Correct 51 ms 16044 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 13 ms 12112 KB Output is correct
11 Correct 14 ms 12112 KB Output is correct
12 Correct 31 ms 14004 KB Output is correct
13 Correct 45 ms 16068 KB Output is correct
14 Correct 42 ms 14204 KB Output is correct
15 Correct 36 ms 15700 KB Output is correct
16 Correct 37 ms 14016 KB Output is correct
17 Correct 38 ms 15684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 12112 KB Output is correct
2 Correct 25 ms 12112 KB Output is correct
3 Incorrect 40 ms 12276 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '16095792008451'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 12112 KB Output is correct
2 Correct 25 ms 12112 KB Output is correct
3 Incorrect 40 ms 12276 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '16095792008451'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 14012 KB Output is correct
2 Correct 49 ms 16060 KB Output is correct
3 Correct 15 ms 12112 KB Output is correct
4 Correct 18 ms 12112 KB Output is correct
5 Correct 95 ms 23736 KB Output is correct
6 Correct 143 ms 23880 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 52 ms 17116 KB Output is correct
9 Correct 73 ms 19892 KB Output is correct
10 Correct 47 ms 14036 KB Output is correct
11 Correct 51 ms 16044 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 13 ms 12112 KB Output is correct
17 Correct 14 ms 12112 KB Output is correct
18 Correct 31 ms 14004 KB Output is correct
19 Correct 45 ms 16068 KB Output is correct
20 Correct 42 ms 14204 KB Output is correct
21 Correct 36 ms 15700 KB Output is correct
22 Correct 37 ms 14016 KB Output is correct
23 Correct 38 ms 15684 KB Output is correct
24 Correct 16 ms 12112 KB Output is correct
25 Correct 25 ms 12112 KB Output is correct
26 Incorrect 40 ms 12276 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '16095792008451'
27 Halted 0 ms 0 KB -