Submission #829352

# Submission time Handle Problem Language Result Execution time Memory
829352 2023-08-18T09:43:25 Z FatihSolak Catfish Farm (IOI22_fish) C++17
0 / 100
53 ms 19080 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;

long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W){
	vector<pair<int,int>> v[N];
	vector<long long>pre[N];
	for(int i = 0;i<M;i++){
		v[X[i]].push_back({Y[i],W[i]});
	}
	for(int i = 0;i<N;i++){
		v[i].push_back({N,0});
		sort(v[i].begin(),v[i].end());
		pre[i].assign(v[i].size(),0);
		for(int j = 0;j<v[i].size();j++){
			pre[i][j] = v[i][j].second + (j?pre[i][j-1]:0);
		}
	}
	vector<pair<int,long long>> smaller = {{-1,0}};
	vector<pair<int,long long>> bigger = {{-1,0}};
	long long oldmaxi = 0;
	long long maxi = 0; 
	for(int i = 0;i<N;i++){
		vector<pair<int,long long>> nwsmaller;
		vector<pair<int,long long>> nwbigger;
		int nwsz = v[i].size();
		int sz = smaller.size();
		for(int j = 0;j<nwsz;j++){
			nwsmaller.push_back({v[i][j-1].first,-1e18});
			nwbigger.push_back({v[i][j-1].first,-1e18});
		}

		//1. operation
		vector<pair<int,long long>> vals;
		int pt = -1;
		for(int j = 0;j<sz;j++){
			while(pt != nwsz - 1 && v[i][pt + 1].first <= smaller[j].first)
				pt++;
			vals.push_back({smaller[j].first,smaller[j].second + (pt == -1?0:pre[i][pt])});
		}
		for(int j = sz-2;j>=0;j--){
			vals[j].second = max(vals[j].second,vals[j+1].second);
		}
		pt = 0;
		for(int j = 0;j < nwsz;j++){
			while(pt != sz && vals[pt].first < nwsmaller[j].first)
				pt++;
			nwsmaller[j].second = max(nwsmaller[j].second,(pt != sz?vals[pt].second:(long long)-1e18) - (j?pre[i][j-1]:0));
		}

		//2. operation
		pt = -1;
		for(int j = 0;j < nwsz;j++){
			while(i  && pt != sz - 1&& v[i-1][pt+1].first <= nwbigger[j].first)
				pt++;
			nwbigger[j].second = max(nwbigger[j].second,oldmaxi + (pt != -1?pre[i-1][pt]:0));
		}

		//3. operation
		vals.clear();
		for(int j = 0;j<sz;j++){
			vals.push_back(smaller[j]);
		}
		for(int j = 1;j<sz;j++){
			vals[j].second = max(vals[j].second,vals[j-1].second);
		}
		pt = -1;
		for(int j = 0;j<nwsz;j++){
			while(pt != sz - 1 && vals[pt + 1].first < nwbigger[j].first)
				pt++;
			nwbigger[j].second = max(nwbigger[j].second,(pt != -1?vals[pt].second:(long long)-1e18));
		}

		//4. operation
		vals.clear();
		pt = -1;
		for(int j = 0;j<sz;j++){
			while(i && pt != sz -1 && v[i-1][pt].first <= bigger[j].first)
				pt++;
			vals.push_back({bigger[j].first,bigger[j].second - (pt != -1?pre[i-1][pt]:0)});
		}
		for(int j = 1;j<sz;j++){
			vals[j].second = max(vals[j].second,vals[j-1].second);
		}
		pt = -1;
		int pt2 = -1;
		for(int j = 0;j<nwsz;j++){
			while(pt != sz - 1 && vals[pt + 1].first < nwbigger[j].first)
				pt++;
			while(i  && pt2 != sz - 1&& v[i-1][pt2+1].first <= nwbigger[j].first)
				pt2++;
			nwbigger[j].second = max(nwbigger[j].second,(pt != -1?vals[pt].second:(long long)-1e18) + (pt2 != -1?pre[i-1][pt2]:0));
		}

		//5. operation
		vals.clear();
		pt = -1;
		for(int j = 0;j<sz;j++){
			while(i && pt != nwsz-1 && v[i][pt].first <= bigger[j].first)
				pt++;
			vals.push_back({bigger[j].first,bigger[j].second + (pt != -1?pre[i][pt]:0)});
		}
		for(int j = sz-2;j>=0;j--){
			vals[j].second = max(vals[j].second,vals[j+1].second);
		}
		pt = 0;
		pt2 = -1;
		for(int j = 0;j<nwsz;j++){
			while(pt != sz && vals[pt].first < nwsmaller[j].first)
				pt++;
			while(pt2 != nwsz -1&& v[i][pt2+1].first <= nwsmaller[j].first)
				pt2++;
			nwbigger[j].second = max(nwbigger[j].second,(pt != sz?vals[pt].second:(long long)-1e18) - (pt2 != -1?pre[i][pt2]:0));
		}

		//operations done

		oldmaxi = maxi;
		smaller = nwsmaller;
		bigger = nwbigger;
		maxi = -1e18;
		for(auto u:smaller){
			maxi = max(maxi,u.second);
		}
		for(auto u:bigger){
			maxi = max(maxi,u.second);
		}
	}
	return maxi;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:15:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |   for(int j = 0;j<v[i].size();j++){
      |                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 53 ms 19080 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '13642859580'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 11264 KB Output is correct
2 Incorrect 22 ms 11200 KB 1st lines differ - on the 1st token, expected: '882019', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 11264 KB Output is correct
2 Incorrect 22 ms 11200 KB 1st lines differ - on the 1st token, expected: '882019', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 53 ms 19080 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '13642859580'
2 Halted 0 ms 0 KB -