Submission #642927

# Submission time Handle Problem Language Result Execution time Memory
642927 2022-09-20T20:37:11 Z n3rm1n Restore Array (RMI19_restore) C++17
20 / 100
116 ms 596 KB
#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;
vector < pair < int, int > > t;
void read13()
{
    memset(a, -1, sizeof(a));
    int l, r, k, val;
    bool ok = true;
    for (int i = 1; i <= m; ++ i)
    {
        cin >> l >> r >> k >> val;
        l ++;
        r ++;
        if(k == 1 && val == 1)
        {
            for (int j = l; j <= r && ok; ++ j)
            {
                if(a[j] == -1)a[j] = 1;
                else if(a[j] == 0)ok = false;
            }
        }
        else if(k == 1 && val == 0)
        {
            v.push_back(make_pair(l, r));
        }
        if(k == r - l + 1 && val == 1)
        {
            t.push_back(make_pair(l, r));
        }
        else if(k == r - l + 1 && val == 0)
        {
            for (int j = l; j <= r && ok; ++ j)
            {
                if(a[j] == -1)a[j] = 0;
                else if(a[j] == 1)ok = false;
            }
        }
    }
    for (int i = 1; i <= n; ++ i)
    {
        a[i] = max(a[i], 0);
        p[i] = p[i-1] + a[i];
    }
    for (int i = 0; i < v.size() && ok; ++ i)
    {
        int l = v[i].first, r = v[i].second;
        if(p[r] - p[l-1] == r - l + 1)ok = false;
    }
    for (int i = 0; i < t.size() && ok; ++ i)
    {
        int l = t[i].first, r = t[i].second;
        if(p[r] - p[l-1] == 0)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

restore.cpp: In function 'void read13()':
restore.cpp:117: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]
  117 |     for (int i = 0; i < v.size() && ok; ++ i)
      |                     ~~^~~~~~~~~~
restore.cpp:122: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]
  122 |     for (int i = 0; i < t.size() && ok; ++ i)
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 8 ms 464 KB Output is correct
4 Correct 64 ms 468 KB Output is correct
5 Correct 116 ms 468 KB Output is correct
6 Correct 61 ms 468 KB Output is correct
7 Correct 11 ms 596 KB Output is correct
8 Correct 18 ms 456 KB Output is correct
9 Correct 65 ms 468 KB Output is correct
10 Correct 32 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 468 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 5 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 468 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 5 ms 468 KB Output is correct
7 Incorrect 3 ms 468 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 8 ms 464 KB Output is correct
4 Correct 64 ms 468 KB Output is correct
5 Correct 116 ms 468 KB Output is correct
6 Correct 61 ms 468 KB Output is correct
7 Correct 11 ms 596 KB Output is correct
8 Correct 18 ms 456 KB Output is correct
9 Correct 65 ms 468 KB Output is correct
10 Correct 32 ms 340 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 3 ms 588 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 3 ms 468 KB Output is correct
15 Correct 3 ms 468 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Incorrect 3 ms 468 KB Output isn't correct
18 Halted 0 ms 0 KB -