Submission #640783

# Submission time Handle Problem Language Result Execution time Memory
640783 2022-09-15T08:13:58 Z wiktorlew Catfish Farm (IOI22_fish) C++17
3 / 100
733 ms 110964 KB
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int N = 1e5 + 5;
const long long LL = 1e18;
ll ans;
map<ll, ll> dp[N][2];
vector<pair<ll, ll>> pref[N];
vector<int> wys[N];
bool ok[N];
ll max_weights(int n, int m, vector<int>X, vector<int>Y, vector<int>Z){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		pref[X[i]].pb({Y[i], Z[i]});
		if(Y[i]==0) ok[X[i]]=true;
		wys[X[i]].pb(Y[i]);
	}
	for(int i = 0; i < n; ++i) {
        wys[i].pb(n);
        if(!ok[i]) wys[i].pb(0);
        sort(wys[i].begin(), wys[i].end());
    }
	for(int i=0;i<n;i++){
		sort(pref[i].begin(), pref[i].end());
		ll suma=0;
		for(int j=0;j<(int)pref[i].size();j++) {
            suma+=pref[i][j].second;
            pref[i][j].second = suma;
        }
        pref[i].insert(pref[i].begin(), make_pair(-1, 0));
	}
	for(int i=1;i<n;i++){
		vector<pair<ll, ll>> spr1, spr2;
		for(ll pom : wys[i-1]){
			dp[i][0][0]=max({dp[i][0][0], dp[i-1][0][pom], dp[i-1][1][pom]});
			dp[i][1][0]=max({dp[i][1][0], dp[i-1][0][pom], dp[i-1][1][pom]});
			ll res=0;
			if(!spr1.empty()) res=spr1.back().second;
			auto it = lower_bound(pref[i-1].begin(), pref[i-1].end(), make_pair(pom, LL));
			it--;
			res=max(res, dp[i-1][0][pom]-it->second);
			spr1.pb({pom, res});
		}
		reverse(wys[i-1].begin(), wys[i-1].end());
		for(ll pom : wys[i-1]){
			ll res=0;
			if(!spr2.empty()) res=spr2.back().second;
			auto it = lower_bound(pref[i].begin(), pref[i].end(), make_pair(pom, LL));
			it--;
			res = max(res, dp[i - 1][0][pom] + it->second);
            res = max(res, dp[i - 1][1][pom] + it->second);
            spr2.pb({pom, res});
		}
		reverse(spr2.begin(), spr2.end());
		for(ll pom : wys[i]){
			auto op1 = upper_bound(spr1.begin(), spr1.end(), make_pair(pom, LL));
			op1--;
			auto op2 = lower_bound(spr2.begin(), spr2.end(), make_pair(pom, -LL));
			auto tmp1 = upper_bound(pref[i-1].begin(), pref[i-1].end(), make_pair(pom-1, LL));
			tmp1--;
			dp[i][0][pom]=max(dp[i][0][pom], op1->second + tmp1->second);
			auto tmp2 = upper_bound(pref[i].begin(), pref[i].end(), make_pair(pom-1, LL));
			tmp2--;
			dp[i][1][pom]=max(dp[i][1][pom], op2->second - tmp2->second);
		}
	}
	for(int i=0;i<=n;i++){
		ans = max({ans, dp[n-1][0][i], dp[n-1][1][i]});
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 218 ms 67536 KB Output is correct
2 Correct 274 ms 74948 KB Output is correct
3 Correct 116 ms 58176 KB Output is correct
4 Correct 112 ms 58124 KB Output is correct
5 Correct 733 ms 109032 KB Output is correct
6 Correct 408 ms 110964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 14292 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 123 ms 58132 KB Output is correct
2 Correct 116 ms 58200 KB Output is correct
3 Incorrect 144 ms 56488 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '26722445760742'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 14292 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 7 ms 14292 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 7 ms 14292 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 123 ms 58132 KB Output is correct
2 Correct 116 ms 58200 KB Output is correct
3 Incorrect 144 ms 56488 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '26722445760742'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 218 ms 67536 KB Output is correct
2 Correct 274 ms 74948 KB Output is correct
3 Correct 116 ms 58176 KB Output is correct
4 Correct 112 ms 58124 KB Output is correct
5 Correct 733 ms 109032 KB Output is correct
6 Correct 408 ms 110964 KB Output is correct
7 Incorrect 6 ms 14292 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
8 Halted 0 ms 0 KB -