Submission #320955

#TimeUsernameProblemLanguageResultExecution timeMemory
320955prariePainting Walls (APIO20_paint)C++14
100 / 100
1191 ms15512 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; vector<int> col[100005]; // 색 k 를 좋아하는 일꾼의 집합 bool wall[100005]; // 벽 i 를 칠할 수 있는가? int dp[100005]; int con[2][50005]; // 벽 i 를 칠할 수 있을 때 // [0 ... i] 까지 칠하는 최소 횟수 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 < M; i++) { for (auto &m : B[i]) col[m].push_back(i); } for (int i = 0; i < N; i++) { int now = (i & 1), bef = (now ^ 1); for (auto &n : col[C[i]]) { con[now][n] = con[bef][(n - 1 + M) % M] + 1; if (con[now][n] == M) { wall[i] = true; con[now][n] = M - 1; } } memset(con[bef], 0, sizeof(con[bef])); } memset(dp, -0x2f, sizeof dp); deque<pair<int, int>> dq; if (wall[M - 1]) { dp[M - 1] = 1; dq.emplace_back(M - 1, 1); } for (int i = M; i < N; i++) { if (!wall[i]) continue; while (dq.size() && dq.back().first < i - M) dq.pop_back(); if (dq.empty()) break; dp[i] = dq.back().second + 1; while (dq.size() && dq.front().second >= dp[i]) dq.pop_front(); dq.emplace_front(i, dp[i]); } return (dp[N - 1] < 0 ? -1 : dp[N - 1]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...