Submission #571470

# Submission time Handle Problem Language Result Execution time Memory
571470 2022-06-02T09:43:21 Z SlavicG Painting Walls (APIO20_paint) C++17
0 / 100
0 ms 212 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long
 
#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
 
#define            pb                push_back
#define          sz(a)               (int)a.size()

int minimumInstructions(int n, int m, int k, vector<int> c, vector<int> a, vector<vector<int>> b) {
    vector<int> p[k + 1];
    map<pair<int, int>, bool> mp;
    for(int i = 0; i < m; ++i) {
        for(auto x: b[i]) {
            p[x].pb(i);
            mp[{i, x}] = 1;
        }
    }
    vector<bool> can(n, false);
    for(int i = 0; i + m - 1 < n; ++i) {
        for(int x: p[i]) {
            int idx = x;
            bool ok = true;
            for(int times = 0; times < m && ok; ++times) {
                if(!mp[{(x + times) % m, c[i + times]}]) ok = false;
            }
            if(ok) {
                can[i] = true;
                break;
            }
        }
    }
    set<int> good;
    forn(i, n) if(can[i]) good.insert(i); 
    int lst = -1e9, ans = 0;
    for(int i = 0; i < n; ++i) {
        if(lst + m - 1 >= i) continue;
        ++ans;
        if(can[i]) {
            lst = i;
        } else {
            auto it = good.lower_bound(i);
            if(it == good.begin()) return -1;
            --it;
            if(*it + m - 1 < i) return -1;
            lst = *it;
        }
    }
    return ans;
}
/*
void solve() {  
    
} 
     
int32_t main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
}
*/

Compilation message

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:25:17: warning: unused variable 'idx' [-Wunused-variable]
   25 |             int idx = x;
      |                 ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -