# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
318617 |
2020-11-02T14:01:17 Z |
MetB |
Safety (NOI18_safety) |
C++14 |
|
2000 ms |
12364 KB |
#include <bits/stdc++.h>
#define N 2000001
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
const ll INF = 1e18, MOD = 998244353, MOD2 = 1e6 + 3;
ll d[2][501*1000], a[500], n, h;
vector <ll> srt;
struct window : deque < pair <ll, ll> > {
void append (ll x, ll v) {
while (!empty () && back ().second > v) pop_back ();
emplace_back (x, v);
}
void erase (ll x) {
if (front().first == x) pop_front ();
}
};
int main () {
//cin >> n >> h;
n = 500;
h = 1;
for (int i = 0; i < n; i++) {
//cin >> a[i];
a[i] = rand () % 1000000000;
srt.push_back (a[i]);
for (int j = 1; j <= n; j++) {
srt.push_back (a[i] + j * h);
srt.push_back (a[i] - j * h);
}
}
sort (srt.begin(), srt.end());
srt.erase (unique (srt.begin(), srt.end()), srt.end ());
int sz = srt.size ();
cout << sz << endl;
for (int i = 0; i < sz; i++) {
d[0][i] = abs (srt[i] - a[0]);
//cout << d[0][i] << ' ' << srt[i] << endl;
}
for (int i = 1; i < n; i++) {
int k = i % 2;
int l = 0, r = 0;
window wd;
for (int j = 0; j < sz; j++) {
while (r < sz && srt[r] <= srt[j] + h) { wd.append (r, d[!k][r]); r++; };
while (l < r && srt[l] < srt[j] - h) { wd.erase (l); l++; };
d[k][j] = abs (srt[j] - a[i]) + wd.front ().second;
//cout << i << ' ' << srt[j] << ' ' << srt[l] << ' ' << srt[r-1] << ' ' << *ms.begin () << endl;
}
}
cout << *min_element (d[n-1], d[n-1] + sz);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2065 ms |
12232 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2083 ms |
12232 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2045 ms |
12364 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2082 ms |
12232 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2065 ms |
12232 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2065 ms |
12232 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2065 ms |
12232 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2065 ms |
12232 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2065 ms |
12232 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |