Submission #380915

# Submission time Handle Problem Language Result Execution time Memory
380915 2021-03-23T14:54:43 Z SolarSystem Painting Walls (APIO20_paint) C++17
0 / 100
1 ms 492 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <numeric>
#include <iomanip>
#include <unordered_set>
                                                                                                 using namespace std;

vector<vector<bool>> t;                                                                          
bool check(vector<int> s) {
    s.push_back(-1);
    vector<int> pi(s.size() + 2 * t.size());
    pi[0] = 0;

    int m = (int) t.size();

    for (int i = 1; i < (int) pi.size(); i++) {
        int j = pi[i - 1];

        while (j > 0) {
            if (i < (int) s.size() && s[j] != s[i]) {
                j = pi[j - 1];
            } else if (i >= (int) s.size() && !t[(i - (int) s.size()) % m][s[j]]) {
                j = pi[j - 1];
            } else {
                break;
            }
        }

        if (i < (int) s.size() && s[j] == s[i]) {
            j++;
        } else if (i >= (int) s.size() && t[(i - (int) s.size()) % m][s[j]]) {
            j++;
        }                                                                                        
        pi[i] = j;
    }

    for (int u: pi) {
        if (u == (int) s.size() - 1) {
            return true;
        }
    }

    return false;
}

int minimumInstructions(int n, int m, int k1, vector<int> c, vector<int> a, vector<vector<int>> b) {
    t.resize(m);
    for (int i = 0; i < m; i++) {
        t[i].resize(k1);
        for (int j = 0; j < a[i]; j++) {
            t[i][b[i][j]] = true;
        }
    }

    int ans = 0;

    int j = -1, k = -1;

    for (int i = 0; ; i++) {
        vector<int> e;

        if (i + m - 1 < n) {
            for (int j = i; j <= i + m - 1; j++) {
                e.push_back(c[j]);
            }

            if (check(e)) {
                j = i;
            }
        }

        if (i > k) {
            if (j + m - 1 < i) {
                return -1;
            } else {                                                                                             ans++;
                k = j + m - 1;
            }
        }

        if (k == n - 1) {
            return ans;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -