# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
238363 | 2020-06-10T22:05:49 Z | Sorting | Restore Array (RMI19_restore) | C++14 | 23 ms | 560 KB |
#include <bits/stdc++.h> using namespace std; const int k_N = 5000 + 3; const int k_M = 10000 + 3; struct Constraint{ int l, r, k, value; int cnt; Constraint(){} Constraint(int l, int r, int k, int value){ this->l = l; this->r = r; this->k = k; this->value = value; } void set_cnt(){ if(!value) cnt = k; else cnt = (r - l + 1) - k + 1; } }; int n, m; int a[k_N]; Constraint c[k_M]; int prefix[k_N]; int get_count_ones(int l, int r){ if(l == 0) return prefix[r]; return prefix[r] - prefix[l - 1]; } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for(int i = 0; i < m; ++i){ cin >> c[i].l >> c[i].r >> c[i].k >> c[i].value; c[i].set_cnt(); } for(int i = 0; i < n; ++i) a[i] = -1; sort(c, c + m, [](const Constraint &lvalue, const Constraint &rvalue){ if((lvalue.r - lvalue.l + 1) - lvalue.cnt != (rvalue.r - rvalue.l + 1) - rvalue.cnt) return (lvalue.r - lvalue.l + 1) - lvalue.cnt < (rvalue.r - rvalue.l + 1) - rvalue.cnt; if(lvalue.r - lvalue.l != rvalue.r - rvalue.l) return (lvalue.r - lvalue.l) < (rvalue.r - rvalue.l); return lvalue.l < rvalue.l; }); for(int _ = 0; _ < m; ++_){ auto [l, r, k, value, cnt] = c[_]; //cout << l << " " << r << " " << k << " " << value << " " << cnt << "\n"; int curr_cnt = 0; for(int i = l; i <= r; ++i) if(a[i] == value) ++curr_cnt; if(curr_cnt >= cnt) continue; for(int i = l; i <= r; ++i){ if(a[i] == -1){ a[i] = value; curr_cnt++; if(curr_cnt == cnt) break; } } if(curr_cnt != cnt){ cout << "-1\n"; return 0; } } for(int i = 0; i < n; ++i) a[i] = (a[i] == -1) ? 0 : a[i]; for(int i = 0; i < n; ++i) cout << a[i] << " "; cout << "\n"; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Incorrect | 5 ms | 384 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 512 KB | Output is correct |
2 | Correct | 21 ms | 512 KB | Output is correct |
3 | Correct | 20 ms | 512 KB | Output is correct |
4 | Correct | 22 ms | 512 KB | Output is correct |
5 | Correct | 9 ms | 512 KB | Output is correct |
6 | Correct | 8 ms | 512 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 512 KB | Output is correct |
2 | Correct | 21 ms | 512 KB | Output is correct |
3 | Correct | 20 ms | 512 KB | Output is correct |
4 | Correct | 22 ms | 512 KB | Output is correct |
5 | Correct | 9 ms | 512 KB | Output is correct |
6 | Correct | 8 ms | 512 KB | Output is correct |
7 | Correct | 21 ms | 560 KB | Output is correct |
8 | Correct | 22 ms | 512 KB | Output is correct |
9 | Correct | 22 ms | 512 KB | Output is correct |
10 | Correct | 23 ms | 512 KB | Output is correct |
11 | Correct | 9 ms | 512 KB | Output is correct |
12 | Correct | 9 ms | 512 KB | Output is correct |
13 | Correct | 21 ms | 512 KB | Output is correct |
14 | Correct | 19 ms | 512 KB | Output is correct |
15 | Correct | 17 ms | 512 KB | Output is correct |
16 | Correct | 17 ms | 512 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Incorrect | 5 ms | 384 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |