Submission #238362

#TimeUsernameProblemLanguageResultExecution timeMemory
238362SortingRestore Array (RMI19_restore)C++14
0 / 100
21 ms640 KiB
#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 (stderr)

restore.cpp: In function 'int main()':
restore.cpp:62:14: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
         auto [l, r, k, value, cnt] = c[_];
              ^
restore.cpp:62:34: warning: unused variable 'k' [-Wunused-variable]
         auto [l, r, k, value, cnt] = c[_];
                                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...