Submission #849767

# Submission time Handle Problem Language Result Execution time Memory
849767 2023-09-15T09:58:50 Z CSQ31 Distributing Candies (IOI21_candies) C++17
0 / 100
4184 ms 2097152 KB
#include "candies.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
typedef long long int ll;
vector<int> distribute_candies(vector<int> c,vector<int> l,vector<int> r,vector<int> v) {
    int n = sz(c);
    int q = sz(l);
    vector<vector<ll>>ch(n);
    for(int i=0;i<n;i++)ch[i].pb(0);
    for(int i=0;i<q;i++){
		for(int j=l[i];j<=r[i];j++)ch[j].pb(v[i]);
	}
	vector<int>ans(n);
	for(int i=0;i<n;i++){
		int m = sz(ch[i]);
		for(int j=1;j<m;j++)ch[i][j]+=ch[i][j-1];
		ll mx = -1e18;
		ll mn = 1e18;
		int last = m;
		for(int j=m-1;j>=0;j--){
			if(mn >= ch[i][j] && mx - ch[i][j] <= c[i])last = j;
			if(mx <= ch[i][j] && ch[i][j] - mn <= c[i])last = j;
			
			mn = min(mn,ch[i][j]);
			mx = max(mx,ch[i][j]);
		}
		////for(auto x:ch[i])cout<<x<<" ";
		//cout<<last<<'\n';
		ans[i] = ch[i][m-1] - ch[i][last];
		if(last && ch[i][last] - ch[i][last-1] > 0)ans[i] = c[i] + ans[i];
	}
	return ans;
		
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4184 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -