답안 #626327

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
626327 2022-08-11T11:43:30 Z Antekb 메기 농장 (IOI22_fish) C++17
9 / 100
160 ms 32292 KB
#include "fish.h"
#include <bits/stdc++.h>
#define pb push_back
#define st first
#define nd second
using namespace std;
using ll = long long;
const int INF=1e9+5;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll max_weights(int n, int m, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
	/*n=1e5;
	m=1e5;
	X.resize(m);
	Y.resize(m);
	W.resize(m);
	for(int i=0; i<m; i++){
		X[i]=(rng()%(n/2))*2+2;
		Y[i]=rng()%n;
		W[i]=rng();
	}*/
	for(auto &i:X)i++;
	ll ans=0;
	for(int i:W)ans+=i;
	//return ans;
	vector<pair<int, int> > V[n+2];	
	vector<ll> dp[n+2][2];
	ll dp2[n+2][2];
	for(int i=0; i<=n+1; i++)dp2[i][0]=dp2[i][1]=0;
	for(int i=0; i<m; i++){
		V[X[i]].pb({Y[i], W[i]});
	}
	for(int i=0; i<=n+1; i++){
		V[i].pb({n, INF});
		sort(V[i].begin(), V[i].end());
		dp[i][0].resize(V[i].size());
		dp[i][1].resize(V[i].size());
	}
	dp[0][1][0]=dp[0][0][0]=-1e18;
	for(int i=1; i<=n+1; i++){
		ll s=0;
		int wsk=0;
		for(int j=0; j<V[i-1].size(); j++){
			dp[i-1][0][j]-=s;
			s+=V[i-1][j].nd;
		}
		ll m=dp2[i-1][0];
		dp2[i][0]=max(dp2[i-1][0], dp2[i-1][1]);
		s=0;
		for(int j=0; j<V[i].size(); j++){
			while(wsk<V[i-1].size() && V[i][j].st>V[i-1][wsk].st){
				m=max(m, dp[i-1][0][wsk]);
				s+=V[i-1][wsk].nd;
				wsk++;
			}
			dp[i][0][j]=s+m;
		}
		wsk=V[i-1].size()-1;
		m=dp[i-1][1][wsk];
		for(int j=V[i].size()-2; j>=0; j--){
			while(wsk!=0 && V[i-1][wsk-1].st>=V[i][j].st){
				m=max(m, dp[i-1][1][wsk-1]);
				wsk--;
			}
			dp[i][1][j]=m;
			m+=V[i][j].nd;
		}
		for(int j=0; j<V[i-1].size(); j++)dp2[i][0]=max(dp2[i][0], dp[i-1][1][j]);
		dp2[i][1]=max(m, dp2[i][0]);
		for(int j=0; j<V[i].size(); j++){
			dp[i][0][j]=max(dp[i][0][j], dp2[i-1][1]);
		}
		for(int j=0; j<V[i].size(); j++){
			dp[i][1][j]=max(dp[i][0][j], dp[i][1][j]);
		}
		//cout<<i<<"\n";
		//cout<<dp2[i][0]<<" "<<dp2[i][1]<<" a\n";
		for(int j=0; j<V[i].size(); j++){
			//cout<<dp[i][0][j]<<" "<<dp[i][1][j]<<" b\n";
		}
	}
	//assert(dp2[n+1][0]==ans);
	return dp2[n+1][0];
}

Compilation message

fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:42:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   for(int j=0; j<V[i-1].size(); j++){
      |                ~^~~~~~~~~~~~~~
fish.cpp:49:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |   for(int j=0; j<V[i].size(); j++){
      |                ~^~~~~~~~~~~~
fish.cpp:50:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |    while(wsk<V[i-1].size() && V[i][j].st>V[i-1][wsk].st){
      |          ~~~^~~~~~~~~~~~~~
fish.cpp:67:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |   for(int j=0; j<V[i-1].size(); j++)dp2[i][0]=max(dp2[i][0], dp[i-1][1][j]);
      |                ~^~~~~~~~~~~~~~
fish.cpp:69:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |   for(int j=0; j<V[i].size(); j++){
      |                ~^~~~~~~~~~~~
fish.cpp:72:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |   for(int j=0; j<V[i].size(); j++){
      |                ~^~~~~~~~~~~~
fish.cpp:77:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |   for(int j=0; j<V[i].size(); j++){
      |                ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 20288 KB Output is correct
2 Correct 63 ms 22968 KB Output is correct
3 Correct 26 ms 18296 KB Output is correct
4 Correct 27 ms 18252 KB Output is correct
5 Correct 145 ms 32292 KB Output is correct
6 Correct 160 ms 31824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 82 ms 24064 KB Output is correct
3 Correct 105 ms 27740 KB Output is correct
4 Correct 51 ms 20180 KB Output is correct
5 Correct 62 ms 22984 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 25 ms 18296 KB Output is correct
11 Correct 25 ms 18244 KB Output is correct
12 Correct 53 ms 20216 KB Output is correct
13 Correct 61 ms 22980 KB Output is correct
14 Correct 53 ms 20288 KB Output is correct
15 Correct 58 ms 22540 KB Output is correct
16 Correct 51 ms 20256 KB Output is correct
17 Correct 69 ms 22472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 18260 KB Output is correct
2 Correct 25 ms 18288 KB Output is correct
3 Incorrect 44 ms 17648 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '21208021504361'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 18260 KB Output is correct
2 Correct 25 ms 18288 KB Output is correct
3 Incorrect 44 ms 17648 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '21208021504361'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 20288 KB Output is correct
2 Correct 63 ms 22968 KB Output is correct
3 Correct 26 ms 18296 KB Output is correct
4 Correct 27 ms 18252 KB Output is correct
5 Correct 145 ms 32292 KB Output is correct
6 Correct 160 ms 31824 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 82 ms 24064 KB Output is correct
9 Correct 105 ms 27740 KB Output is correct
10 Correct 51 ms 20180 KB Output is correct
11 Correct 62 ms 22984 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 25 ms 18296 KB Output is correct
17 Correct 25 ms 18244 KB Output is correct
18 Correct 53 ms 20216 KB Output is correct
19 Correct 61 ms 22980 KB Output is correct
20 Correct 53 ms 20288 KB Output is correct
21 Correct 58 ms 22540 KB Output is correct
22 Correct 51 ms 20256 KB Output is correct
23 Correct 69 ms 22472 KB Output is correct
24 Correct 25 ms 18260 KB Output is correct
25 Correct 25 ms 18288 KB Output is correct
26 Incorrect 44 ms 17648 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '21208021504361'
27 Halted 0 ms 0 KB -