Submission #965912

# Submission time Handle Problem Language Result Execution time Memory
965912 2024-04-19T07:52:48 Z phoenix0423 Painting Walls (APIO20_paint) C++17
0 / 100
1 ms 2652 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#pragma GCC optimize("Ofast")
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#include "paint.h"
const int INF = 1e9 + 7;
const int maxn = 1e5 + 5;
int st[maxn], ed[maxn], valid[maxn], dp[maxn];
vector<int> pos[maxn];

int minimumInstructions(
    int n, int m, int k, std::vector<int> c,
    std::vector<int> a, std::vector<std::vector<int>> b) {
    for(int i = 0; i < n; i++) pos[c[i]].pb(i);
    for(int i = 0; i < n; i++) st[i] = -1, ed[i] = m;
    for(int i = 0; i < m; i++){
      for(int j = 0; j < a[i]; j++){
        for(auto x : pos[b[i][j]]){
          if(x >= i){
            if(st[x - i] == i - 1) st[x - i] ++;
          }
        }
      }
    }
    for(int i = m - 1; i >= 0; i--){
      for(int j = 0; j < a[i]; j++){
        for(auto x : pos[b[i][j]]){
          if(x + m - i < n){
            if(ed[x + m - i] == i + 1) ed[x + m - i] --;
          }
        }
      }
    }
    for(int i = 0; i < n; i++){
      int l = ed[i], r = st[i];
      int len = r - l + 2;
      if(len <= 0) continue;
      valid[i - (m - l)] ++;
      if(i - (m - l) + len < n) valid[i - (m - l) + len] --;
    }
    for(int i = 1; i < n; i++) valid[i] += valid[i - 1];
    deque<int> dq;
    if(!valid[0]) return -1;
    dq.pb(0), dp[0] = 1;
    for(int i = 1; i < n; i++){
      if(!valid[i]){
        dp[i] = INF;
        continue;
      }
      while(dq.size() && dq[0] < i - m) dq.pop_front();
      if(dq.empty()){
        for(int j = i; j < n; j++) dp[i] = INF;
        break;
      }
      dp[i] = dp[dq[0]] + 1;
      while(!dq.empty() && dp[dq.size() - 1] >= dp[i]) dq.pop_back();
      dq.pb(i);
    }
    int ans = INF;
    for(int i = n - 1; i >= n - m; i--) ans = min(ans, dp[i]);
    return ans < INF ? ans : -1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Incorrect 1 ms 2648 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Incorrect 1 ms 2648 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Incorrect 1 ms 2648 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Incorrect 1 ms 2648 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Incorrect 1 ms 2648 KB Output isn't correct
10 Halted 0 ms 0 KB -