답안 #1056681

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1056681 2024-08-13T10:36:53 Z tolbi 메기 농장 (IOI22_fish) C++17
0 / 100
120 ms 83644 KB
#include "fish.h"

#include <bits/stdc++.h>
using namespace std;
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
	std::vector<int> W) {
	vector<vector<pair<int,int>>> poses(N);
	for (int i = 0; i < M; ++i)
	{
		poses[X[i]].push_back({Y[i],W[i]});
	}
	for (int i = 0; i < N; ++i)
	{
		if (poses[i].size()==0) poses[i].push_back({0,0});
		sort(poses[i].begin(), poses[i].end());
		poses[i].push_back({M,0});
	}
	vector<vector<vector<int>>> dp(N);
	for (int i = 0; i < N; ++i)
	{
		dp[i].resize(poses[i].size(),vector<int>(3,-1));
	}
	vector<vector<int>> pref(N);
	for (int i = 0; i < N; ++i)
	{
		pref[i].resize(poses[i].size());
		for (int j = 0; j < pref[i].size(); j++){
			pref[i][j]=poses[i][j].second;
			if (j) pref[i][j]+=pref[i][j-1];
		}
	}
	function<int(int,int,int)> query = [&](int node, int l, int r)->int{
		if (l>r) return 0;
		int ans = 0;
		int ilk = lower_bound(poses[node].begin(), poses[node].end(), pair<int,int>{r,0})-poses[node].begin();
		if (ilk==poses[node].size() || poses[node][ilk].first>r) ilk--;
		if (ilk<0) return 0;
		int hh = pref[node][ilk];
		ilk = lower_bound(poses[node].begin(), poses[node].end(), pair<int,int>{l,0})-poses[node].begin()-1;
		if (ilk>=0) hh-=pref[node][ilk];
		return hh;
	};
	function<int(int,int,int)> f = [&](int pos, int node, int flag)->int{
		if (pos==N) return 0;
		if (dp[pos][node][flag]!=-1) return dp[pos][node][flag];
		dp[pos][node][flag]=0;
		if (flag<=1){
			//0 artiyo
			//1 artiyo, arkadan ekleme
			if (node+1<dp[pos].size()){
				//bi yukari git
				int cur = f(pos,node+1,flag);
				if (flag==0 && pos-1>=0){
					cur+=query(pos-1,poses[pos][node].first,poses[pos][node+1].first-1);
				}
				dp[pos][node][flag]=max(dp[pos][node][flag],cur);
			}
		}
		else {
			assert(node>0 && poses[pos][node].first>0);
			cout<<pos<<" "<<node<<endl;
			if (poses[pos][node-1].first>0){
				dp[pos][node][flag]=max(dp[pos][node][flag],f(pos,node-1,flag)+poses[pos][node-1].second);
			}
		}
		if (pos+1<N){
			int buyu = lower_bound(poses[pos+1].begin(),poses[pos+1].end(),pair<int,int>{poses[pos][node].first,0})-poses[pos+1].begin();
			if (flag<=1 && buyu<poses[pos+1].size()){
				dp[pos][node][flag]=max(dp[pos][node][flag],f(pos+1,buyu,0)+query(pos,poses[pos][node].first,poses[pos+1][buyu].first-1));
			}
			if (buyu==poses[pos+1].size() || poses[pos+1][buyu].first!=poses[pos][node].first) buyu--;
			if (buyu>0){
				dp[pos][node][flag]=max(dp[pos][node][flag],f(pos+1,buyu,flag&2))+query(pos+1,poses[pos+1][buyu].first,poses[pos][node].first-1);
			}
		}
		if (pos+2<N){
			dp[pos][node][flag]=max(dp[pos][node][flag],f(pos+2,0,0));
			dp[pos][node][flag]=max(dp[pos][node][flag],f(pos+2,0,1)+query(pos+1,0,poses[pos][node].first-1));
		}
		return dp[pos][node][flag];
	};
	return f(0,0,0);
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:27:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   for (int j = 0; j < pref[i].size(); j++){
      |                   ~~^~~~~~~~~~~~~~~~
fish.cpp: In lambda function:
fish.cpp:36:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |   if (ilk==poses[node].size() || poses[node][ilk].first>r) ilk--;
      |       ~~~^~~~~~~~~~~~~~~~~~~~
fish.cpp:34:7: warning: unused variable 'ans' [-Wunused-variable]
   34 |   int ans = 0;
      |       ^~~
fish.cpp: In lambda function:
fish.cpp:50:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |    if (node+1<dp[pos].size()){
      |        ~~~~~~^~~~~~~~~~~~~~~
fish.cpp:68:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |    if (flag<=1 && buyu<poses[pos+1].size()){
      |                   ~~~~^~~~~~~~~~~~~~~~~~~~
fish.cpp:71:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |    if (buyu==poses[pos+1].size() || poses[pos+1][buyu].first!=poses[pos][node].first) buyu--;
      |        ~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 93 ms 76232 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '2147445428'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 120 ms 83644 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '1931408614'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 52816 KB Output is correct
2 Incorrect 71 ms 52692 KB 1st lines differ - on the 1st token, expected: '882019', found: '0'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 52816 KB Output is correct
2 Incorrect 71 ms 52692 KB 1st lines differ - on the 1st token, expected: '882019', found: '0'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 93 ms 76232 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '2147445428'
2 Halted 0 ms 0 KB -