Submission #436582

# Submission time Handle Problem Language Result Execution time Memory
436582 2021-06-24T16:18:31 Z shrimb Distributing Candies (IOI21_candies) C++17
8 / 100
166 ms 8884 KB
#include"bits/stdc++.h"
// #define int long long
#define endl '\n'
using namespace std;

vector<int> distribute_candies (vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
	int n = c.size();
	int q = l.size();

	bool st1 = (n <= 2000 and q <= 2000);
	bool st2 = 1; for (int i = 0 ; i < q ; i++) if (v[i] < 0) st2 = 0;

	// if (st1) {
	// 	vector<int> ret(n, 0);
	// 	for (int i = 0 ; i < q ; i++) {
	// 		for (int j = l[i] ; j <= r[i] ; j++) {
	// 			ret[j] = max(0, min(c[j], ret[j] + v[i]));
	// 		}
	// 	}
	// 	return ret;
	// }
	if (st2) {
		vector<int> ret(n, 0);
		vector<long long> pref(n + 1, 0);
		for (int i = 0 ; i < q ; i++) {
			pref[l[i]] += v[i];
			pref[r[i] + 1] -= v[i];
		}
		for (int i = 1 ; i < n ; i++) pref[i] += pref[i-1];
		for (int i = 0 ; i < n ; i++) ret[i] = min((long long)c[i], pref[i]);
		return ret;
	}

}

Compilation message

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:10:7: warning: unused variable 'st1' [-Wunused-variable]
   10 |  bool st1 = (n <= 2000 and q <= 2000);
      |       ^~~
candies.cpp:34:1: warning: control reaches end of non-void function [-Wreturn-type]
   34 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 166 ms 8884 KB Output is correct
2 Correct 120 ms 8792 KB Output is correct
3 Correct 122 ms 8872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -