Submission #642923

#TimeUsernameProblemLanguageResultExecution timeMemory
642923n3rm1nRestore Array (RMI19_restore)C++17
7 / 100
125 ms484 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; const int MAXN = 5005; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int n, m; int a[MAXN]; int dp0[MAXN][MAXN], dp1[MAXN][MAXN]; int p[MAXN]; int used[MAXN]; void check() { memset(p, 0, sizeof(p)); /*for (int i = 1; i <= n; ++ i) cout << used[i] << " "; cout << endl;*/ for (int i = 1; i <= n; ++ i) { p[i] = p[i-1] + used[i]; } int ones, zeros; for (int i = 1; i <= n; ++ i) { for (int j = i; j <= n; ++ j) { ones = p[j] - p[i-1]; zeros = j - i + 1 - ones; if(ones < dp1[i][j] || zeros < dp0[i][j]) { return; } } } for (int i = 1; i <= n; ++ i) cout << used[i] << " "; cout << endl; exit(0); } void gen(int pos) { if(pos > n) { check(); return; } used[pos] = 0; gen(pos+1); used[pos] = 1; gen(pos+1); } void solve() { int l, r, k, val; for (int i = 1; i <= m; ++ i) { cin >> l >> r >> k >> val; l ++; r ++; if(val == 0)dp0[l][r] = max(dp0[l][r], k); else dp1[l][r] = max(dp1[l][r], r - l + 1 - k + 1); // cout << r - l + 1 - k + 1 << endl; } gen(1); cout << -1 << endl; } vector < pair < int, int > > v; void read13() { int l, r, k, val; for (int i = 1; i <= m; ++ i) { cin >> l >> r >> k >> val; if(k == 1 && val == 1) { for (int j = l; j <= r; ++ j) a[j] = 1; } else if(k == 1 && val == 0) { v.push_back(make_pair(l, r)); } } for (int i = 1; i <= n; ++ i) { p[i] = p[i-1] + a[i]; } bool ok = true; for (int i = 0; i < v.size() && false; ++ i) { int l = v[i].first, r = v[i].second; if(p[r] - p[l-1] == r - l + 1)ok = false; } if(!ok)cout << -1 << endl; else { for (int i = 1; i <= n; ++ i) cout << a[i] << " "; cout << endl; } } int main() { speed(); cin >> n >> m; if(n <= 18)solve(); else { read13(); } return 0; }

Compilation message (stderr)

restore.cpp: In function 'void read13()':
restore.cpp:97:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |     for (int i = 0; i < v.size() && false; ++ i)
      |                     ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...