Submission #640473

# Submission time Handle Problem Language Result Execution time Memory
640473 2022-09-14T18:30:17 Z wiktorlew Catfish Farm (IOI22_fish) C++17
3 / 100
669 ms 110964 KB
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int N = 1e5 + 5;
const int M = 3e5 + 5;
const long long LL = 1e18;
ll ans;
map<ll, ll> dp[N][2];
vector<pair<ll, ll>> pref[N];
vector<int> wys[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]});
		wys[X[i]].pb(Y[i]);
	}
	for(int i = 0; i < n; ++i) {
        wys[i].pb(n);
        wys[i].pb(0);
        sort(wys[i].begin(), wys[i].end());
        wys[i].erase(unique(wys[i].begin(), wys[i].end()), 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 = upper_bound(pref[i-1].begin(), pref[i-1].end(), make_pair(pom-1, 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 = upper_bound(pref[i].begin(), pref[i].end(), make_pair(pom-1, 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 = lower_bound(pref[i-1].begin(), pref[i-1].end(), make_pair(pom, LL));
			tmp1--;
			dp[i][0][pom]=max(dp[i][0][pom], op1->second + tmp1->second);
			auto tmp2 = lower_bound(pref[i].begin(), pref[i].end(), make_pair(pom, 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 222 ms 67408 KB Output is correct
2 Correct 261 ms 74972 KB Output is correct
3 Correct 126 ms 58120 KB Output is correct
4 Correct 118 ms 58104 KB Output is correct
5 Correct 669 ms 108860 KB Output is correct
6 Correct 414 ms 110964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14292 KB Output is correct
2 Incorrect 398 ms 83936 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '40604944491929'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 115 ms 58184 KB Output is correct
2 Incorrect 114 ms 58176 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 Correct 8 ms 14292 KB Output is correct
2 Correct 7 ms 14296 KB Output is correct
3 Correct 7 ms 14292 KB Output is correct
4 Correct 6 ms 14292 KB Output is correct
5 Incorrect 7 ms 14288 KB 1st lines differ - on the 1st token, expected: '8866', found: '7755'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14292 KB Output is correct
2 Correct 7 ms 14296 KB Output is correct
3 Correct 7 ms 14292 KB Output is correct
4 Correct 6 ms 14292 KB Output is correct
5 Incorrect 7 ms 14288 KB 1st lines differ - on the 1st token, expected: '8866', found: '7755'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14292 KB Output is correct
2 Correct 7 ms 14296 KB Output is correct
3 Correct 7 ms 14292 KB Output is correct
4 Correct 6 ms 14292 KB Output is correct
5 Incorrect 7 ms 14288 KB 1st lines differ - on the 1st token, expected: '8866', found: '7755'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 115 ms 58184 KB Output is correct
2 Incorrect 114 ms 58176 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 Correct 222 ms 67408 KB Output is correct
2 Correct 261 ms 74972 KB Output is correct
3 Correct 126 ms 58120 KB Output is correct
4 Correct 118 ms 58104 KB Output is correct
5 Correct 669 ms 108860 KB Output is correct
6 Correct 414 ms 110964 KB Output is correct
7 Correct 7 ms 14292 KB Output is correct
8 Incorrect 398 ms 83936 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '40604944491929'
9 Halted 0 ms 0 KB -