Submission #965792

# Submission time Handle Problem Language Result Execution time Memory
965792 2024-04-19T07:23:44 Z phoenix0423 Painting Walls (APIO20_paint) C++17
0 / 100
0 ms 348 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)
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#include "paint.h"
const int INF = 1e9 + 7;

int minimumInstructions(
    int n, int m, int k, std::vector<int> c,
    std::vector<int> a, std::vector<std::vector<int>> b) {
    vector<vector<int>> pos(k);
    for(int i = 0; i < n; i++) pos[c[i]].pb(i);
    vector<set<int>> st(n), ed(n);
    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) st[x - i].insert(i);
          if(x + m - i < n) ed[x + m - i].insert(i);
        }
      }
    }
    vector<int> valid(2 * n);
    for(int i = 0; i < n; i++){
      int l = m, r = -1;
      while(ed[i].count(l - 1)) l--;
      while(st[i].count(r + 1)) r++;
      // cout<<i<<" : "<<l<<" "<<r<<"\n";
      int len = r - l + 2;
      if(len <= 0) continue;
      // cout<<"add : ["<<i - r<<" - "<<i - r + len - 1<<"]\n";
      valid[i - r] ++;
      valid[i - r + len] --;
    }
    for(int i = 1; i < n; i++) valid[i] += valid[i - 1];
    // for(int i = 0; i < n; i++) cout<<valid[i]<<" ";
    // cout<<"\n";
    deque<int> dq;
    vector<int> dp(2 * n, INF);
    if(!valid[0]) return -1;
    dq.pb(0), dp[0] = 1;
    for(int i = 1; i < n; i++){
      while(dq.size() && dq[0] < i - m) dq.pop_front();
      if(dq.empty()) break;
      if(!valid[i]) continue;
      // cout<<"ck : "<<i<<" : "<<dq.size()<<"\n";
      // cout<<"top : "<<dq[0]<<" "<<dp[dq[0]]<<"\n";
      dp[i] = dp[dq[0]] + 1;
      while(!dq.empty() && dp[dq.size() - 1] >= dp[i]) dq.pop_back();
      dq.pb(i);
    }
    // for(int i = 0; i < n; i++) cout<<dp[i]<<" ";
    // cout<<"\n";
    int ans = INF;
    for(int i = n - 1; i >= n - m; i--) ans = min(ans, dp[i]);
    return ans < INF ? ans : -1;
}


// int main() {
//   int N, M, K;
//   assert(3 == scanf("%d %d %d", &N, &M, &K));
  
//   std::vector<int> C(N);
//   for (int i = 0; i < N; ++i) {
//     assert(1 == scanf("%d", &C[i]));
//   }

//   std::vector<int> A(M);
//   std::vector<std::vector<int>> B(M);
//   for (int i = 0; i < M; ++i) {
//     assert(1 == scanf("%d", &A[i]));
//     B[i].resize(A[i]);
//     for (int j = 0; j < A[i]; ++j) {
//       assert(1 == scanf("%d", &B[i][j]));
//     }
//   }

//   int minimum_instructions = minimumInstructions(N, M, K, C, A, B);
//   printf("%d\n", minimum_instructions);
  
//   return 0;
// }

/*
8 3 5
3 3 1 3 4 4 2 2
3 0 1 2
2 2 3
2 3 4
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -