# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
238362 | 2020-06-10T21:55:18 Z | Sorting | Restore Array (RMI19_restore) | C++14 | 21 ms | 640 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; --cnt; if(!cnt) break; } } if(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 | Incorrect | 5 ms | 384 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 512 KB | Output is correct |
2 | Correct | 21 ms | 640 KB | Output is correct |
3 | Correct | 21 ms | 640 KB | Output is correct |
4 | Incorrect | 9 ms | 512 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 512 KB | Output is correct |
2 | Correct | 21 ms | 640 KB | Output is correct |
3 | Correct | 21 ms | 640 KB | Output is correct |
4 | Incorrect | 9 ms | 512 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Incorrect | 5 ms | 384 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |