Submission #289214

#TimeUsernameProblemLanguageResultExecution timeMemory
289214dolphingarlicPainting Walls (APIO20_paint)C++14
100 / 100
547 ms12944 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; int dp[2][50002]; vector<int> good[100002]; bool possible[100002]; int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) { for (int i = 0; i < M; i++) for (int j : B[i]) good[j].push_back(i); for (int i = N - 1; ~i; i--) { for (int j : good[C[i + 2]]) dp[i & 1][j] = 0; for (int j : good[C[i]]) { dp[i & 1][j] = dp[i + 1 & 1][(j + 1) % M] + 1; if (dp[i & 1][j] >= M) possible[i] = true; } } int ans = 0, last_painted = -1; for (int i = 0, best = -M; i < N; i++) { if (possible[i]) best = i; if (i > last_painted) { if (best + M == i) return -1; ans++; last_painted = best + M - 1; } } return ans; }

Compilation message (stderr)

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:16:33: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
   16 |             dp[i & 1][j] = dp[i + 1 & 1][(j + 1) % M] + 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...