Submission #493751

# Submission time Handle Problem Language Result Execution time Memory
493751 2021-12-12T19:09:30 Z Cristian Restore Array (RMI19_restore) C++14
20 / 100
16 ms 612 KB
#include <iostream>

using namespace std;
const int NMAX = 10005;
int v[NMAX], sp[NMAX], l[NMAX], r[NMAX], k[NMAX], value[NMAX], SP1[NMAX], SP0[NMAX], set1[NMAX], set0[NMAX], SP[NMAX];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, m, i, ns, b, subtask, ok, j;
    cin >> n >> m;
    subtask = 2;
    for(i = 1; i <= m; i++)
    {
        cin >> l[i] >> r[i] >> k[i] >> value[i];
        l[i]++;
        r[i]++;
        if(k[i] != 1)
            subtask = 3;
    }
    /// Subtask #1
    if(n <= 18 && m <= 200)
    {
        ns = (1 << n);
        for(b = 0; b < ns; b++)
        {
            sp[0] = 0;
            for(i = 1; i <= n; i++)
            {
                sp[i] = sp[i - 1];
                if((1 << (i-1)) & b)
                    sp[i]++;
            }
            ok = 1;
            for(i = 1; i <= m; i++)
            {
                if(value[i] == 0 && sp[r[i]] - sp[l[i] - 1] > r[i] - l[i] - k[i] + 1)
                {
                    ok = 0;
                    break;
                }
                if(value[i] == 1 && sp[r[i]] - sp[l[i] - 1] < r[i] - l[i] - k[i] + 2)
                {
                    ok = 0;
                    break;
                }
            }
            if(ok)
            {
                for(i = 1; i <= n; i++)
                {
                    cout << sp[i] - sp[i-1] << ' ';
                }
                return 0;
            }
        }
        cout << "-1";
        return 0;
    }
    /// Subtask #2
    if(subtask == 2)
    {
        for(i = 1; i <= m; i++)
        {
            if(value[i] == 1)
            {
                SP[r[i] + 1]--;
                SP[l[i]]++;
            }
        }
        for(i = 1; i <= n; i++)
        {
            SP[i] += SP[i-1];
            if(SP[i])
                v[i] = 1;
            else
                v[i] = 0;
            sp[i] = sp[i-1] + v[i];
        }
        ok = 1;
        for(i = 1; i <= m; i++)
        {
            if(value[i] == 0 && sp[r[i]] - sp[l[i] - 1] > r[i] - l[i] - k[i] + 1)
            {
                ok = 0;
                break;
            }
            if(value[i] == 1 && sp[r[i]] - sp[l[i] - 1] < r[i] - l[i] - k[i] + 2)
            {
                ok = 0;
                break;
            }
        }

        if(!ok)
        {
            cout << "-1";
            return 0;
        }
        for(i = 1; i <= n; i++)
            cout << v[i] << ' ';
        return 0;
    }
    if(subtask == 3)
    {
        // k = 1
        for(i = 1; i <= m; i++)
        {
            if(k[i] != 1 || value[i] != 1)
                continue;
            SP1[r[i] + 1]--;
            SP1[l[i]]++;
        }
        for(i = 1; i <= n; i++)
        {
            SP1[i] += SP1[i-1];
            if(SP1[i])
                v[i] = 1;
            else
                v[i] = 0;
            SP1[i-1] = 0;
        }
        SP1[n] = 0;
        // k = r - l + 1 si value == 0
        for(i = 1; i <= m; i++)
        {
            if(k[i] == 1 || value[i] == 1)
                continue;
            SP0[r[i] + 1]--;
            SP0[l[i]]++;
        }
        for(i = 1; i <= n; i++)
        {
            SP0[i] += SP0[i-1];
            if(SP0[i])
                v[i] = -1;
            if(SP0[i] && SP1[i])
            {
                cout << "-1";
                return 0;
            }
            SP0[i-1] = 0;
        }
        SP0[n] = 0;
        // k = r - l + 1 si value = 1
        for(i = 1; i <= n; i++)
        {
            set1[i] = set1[i-1];
            set0[i] = set0[i-1];
            if(v[i] == 1)
                set1[i]++;
            if(v[i] == -1)
                set0[i]++;
        }
        for(i = 1; i <= m; i++)
        {
            if(k[i] == 1 || value[i] == 0)
                continue;
            if(set1[r[i]] - set1[l[i] -1] != 0)
                continue;
            if(set0[r[i]] - set0[l[i] - 1] == r[i] - l[i] + 1)
            {
                cout << "-1";
                return 0;
            }
            for(j = l[i]; j <= r[i]; j++)
                if(v[i] == 0 || v[i] == 1)
                {
                    v[i] = 1;
                    break;
                }
        }
        sp[0] = 0;
        for(i = 1; i <= n; i++)
        {
            sp[i] = sp[i-1];
            if(v[i] == 1)
                sp[i]++;
        }
        ok = 1;
        for(i = 1; i <= m; i++)
        {
            if(k[i] == 1)
            {
                if(value[i] == 0 && sp[r[i]] - sp[l[i] - 1] > r[i] - l[i] - k[i] + 1)
                {
                    ok = 0;
                    break;
                }
                if(value[i] == 1 && sp[r[i]] - sp[l[i] - 1] < r[i] - l[i] - k[i] + 2)
                {
                    ok = 0;
                    break;
                }
            }
            else
            {
                if(value[i] == 1 && sp[r[i]] - sp[l[i] - 1] == 0)
                {
                    ok = 0;
                    break;
                }
                if(value[i] == 1 && sp[r[i]] - sp[l[i] - 1] != 0)
                {
                    ok = 0;
                    break;
                }
            }
        }
        if(!ok)
        {
            cout << "-1";
            return 0;
        }
        for(i = 1; i <= n; i++)
            cout << max(v[i], 0) << ' ';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 4 ms 332 KB Output is correct
4 Correct 4 ms 332 KB Output is correct
5 Correct 16 ms 336 KB Output is correct
6 Correct 11 ms 332 KB Output is correct
7 Correct 4 ms 332 KB Output is correct
8 Correct 3 ms 332 KB Output is correct
9 Correct 15 ms 340 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 460 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
3 Correct 3 ms 460 KB Output is correct
4 Correct 4 ms 524 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 460 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
3 Correct 3 ms 460 KB Output is correct
4 Correct 4 ms 524 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Incorrect 3 ms 612 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 4 ms 332 KB Output is correct
4 Correct 4 ms 332 KB Output is correct
5 Correct 16 ms 336 KB Output is correct
6 Correct 11 ms 332 KB Output is correct
7 Correct 4 ms 332 KB Output is correct
8 Correct 3 ms 332 KB Output is correct
9 Correct 15 ms 340 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 3 ms 460 KB Output is correct
13 Correct 3 ms 460 KB Output is correct
14 Correct 4 ms 524 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Incorrect 3 ms 612 KB Output isn't correct
18 Halted 0 ms 0 KB -