Submission #137824

# Submission time Handle Problem Language Result Execution time Memory
137824 2019-07-28T10:04:43 Z SirCeness Safety (NOI18_safety) C++14
5 / 100
167 ms 4328 KB
#include <bits/stdc++.h>

using namespace std;
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define bas(x) #x << ": " << x << " "
#define prarr(x, n) cout << #x << ": "; for (int qsd = 0; qsd < n; qsd++) cout << x[qsd] << " "; cout << endl;
#define prarrv(x) cout << #x << ": "; for (int qsd = 0; qsd < (int)x.size(); qsd++) cout << x[qsd] << " "; cout << endl;
#define ppair(x) "(" << x.first << ", " << x.second << ")"
#define inside sl<=l&&r<=sr
#define outside sr<l||r<sl

typedef long long ll;

int main(){
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);

	ll n, h;
	cin >> n >> h;
	vector<ll> arr(n);
	for (int i = 0; i < n; i++){
		cin >> arr[i];
	}

	vector<ll> a;
	a.pb(arr[0]);
	ll ekle = 0;
	for (int i = 1; i < n; i++){
		if (abs(arr[i] - arr[i-1]) > h){
			a.pb(arr[i] + ekle);
		} else {
			ekle += arr[i-1] - arr[i];
			a.pb(arr[i] + ekle);
		}
	}

	//prarrv(a);

	vector<int> fark(a.size());
	fark[0] = 0;
	for (int i = 1; i < a.size(); i++){
		if (a[i] > a[i-1]) fark[i] = fark[i-1]+h;
		else if (a[i] < a[i-1]) fark[i] = fark[i-1]-h;
		else {
			fark[i] = fark[i-1];
		}
	}
	//prarrv(fark);

	for (int i = 0; i < n; i++) a[i] -= fark[i];
	sort(a.begin(), a.end());
	ll med = a[a.size()/2];
	ll ans = 0;
	for (int i = 0; i < a.size(); i++) ans += abs(a[i] - med);

	cout << ans << endl;

}

Compilation message

safety.cpp: In function 'int main()':
safety.cpp:43:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 1; i < a.size(); i++){
                  ~~^~~~~~~~~~
safety.cpp:56:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < a.size(); i++) ans += abs(a[i] - med);
                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Incorrect 2 ms 376 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 113 ms 3536 KB Output is correct
2 Correct 160 ms 4044 KB Output is correct
3 Correct 167 ms 4328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Incorrect 2 ms 376 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Incorrect 2 ms 376 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Incorrect 2 ms 376 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Incorrect 2 ms 376 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Incorrect 2 ms 376 KB Output isn't correct
7 Halted 0 ms 0 KB -