제출 #685336

#제출 시각아이디문제언어결과실행 시간메모리
685336Nursik벽 칠하기 (APIO20_paint)C++14
28 / 100
1588 ms32924 KiB
#include "paint.h" #include <vector> #include <iostream> #include <set> #include <map> #include <cmath> using namespace std; #define pb push_back #define f first #define s second #define ll long long const int maxn = 1e6 + 200, maxm = 1e3 + 200, inf = 1e9; int n, m, k; int is[maxn], dp[maxn]; vector<int> g[maxn]; int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) { n = N, m = M, k = K; for (int i = 0; i < m; ++i){ for (auto it : B[i]){ g[it].pb(i); } } for (int i = m - 1; i < n; ++i){ for (auto it : g[C[i]]){ int x = it; int ok = 1; int z = 0; /* if (i == n - 1){ cout << x << '\n'; }*/ while (z < m){ int ok2 = 0; for (auto it2 : B[x]){ if (C[i - z] == it2){ ok2 = 1; break; } } if (ok2 == 0){ ok = 0; break; } x = (x - 1 + m) % m; z += 1; } if (ok == 1){ is[i] = 1; break; } } } for (int i = 0; i < n; ++i){ dp[i] = inf; // cout << is[i] << " "; } // cout << '\n'; if (is[m - 1] > 0){ dp[m - 1] = 1; } for (int i = m - 1; i < n; ++i){ for (int j = i + 1; j < n && j - i <= m; ++j){ if (is[j]){ dp[j] = min(dp[j], dp[i] + 1); } } } if (dp[n - 1] == inf){ dp[n - 1] = -1; } return 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...