Submission #829355

# Submission time Handle Problem Language Result Execution time Memory
829355 2023-08-18T09:46:33 Z FatihSolak Catfish Farm (IOI22_fish) C++17
0 / 100
148 ms 30612 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].first-1,-1e18});
			nwbigger.push_back({v[i][j].first-1,-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);
		}

		// cout << "HEY:" << i << endl;
		// for(auto u:smaller){
		// 	cout << u.first << ' ' << u.second << endl;
		// }
		// for(auto u:bigger){
		// 	cout << u.first << ' ' << u.second << endl;
		// }
	}
	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 Correct 53 ms 19092 KB Output is correct
2 Correct 62 ms 21828 KB Output is correct
3 Correct 22 ms 11192 KB Output is correct
4 Correct 21 ms 11256 KB Output is correct
5 Correct 148 ms 30612 KB Output is correct
6 Incorrect 145 ms 23072 KB 1st lines differ - on the 1st token, expected: '300000000000000', found: '550484000000000'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 91 ms 26012 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '80900266886893'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 11252 KB Output is correct
2 Correct 21 ms 11252 KB Output is correct
3 Incorrect 42 ms 11352 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '32717839057000'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 11252 KB Output is correct
2 Correct 21 ms 11252 KB Output is correct
3 Incorrect 42 ms 11352 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '32717839057000'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 53 ms 19092 KB Output is correct
2 Correct 62 ms 21828 KB Output is correct
3 Correct 22 ms 11192 KB Output is correct
4 Correct 21 ms 11256 KB Output is correct
5 Correct 148 ms 30612 KB Output is correct
6 Incorrect 145 ms 23072 KB 1st lines differ - on the 1st token, expected: '300000000000000', found: '550484000000000'
7 Halted 0 ms 0 KB -