Submission #384768

#TimeUsernameProblemLanguageResultExecution timeMemory
384768kwongwengPainting Walls (APIO20_paint)C++14
12 / 100
67 ms13164 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; typedef vector<int> vi; typedef long long ll; #define FOR(i, a, b) for(int i = a; i < b; i++) #define ROF(i, a, b) for(int i = a; i >= b; i--) int minimumInstructions(int n, int m, int k, vi c, vi a, vector<vi> b) { int ans = 0; int num[m]; memset(num, 0, sizeof(num)); int check[n]; memset(check, 0, sizeof(check)); vi con[k]; FOR(i, 0, m){ FOR(j, 0, a[i]){ con[b[i][j]].push_back(i); } } FOR(i, 0, m){ for (int j : con[c[i]]){ int l = (j-i+m) % m; num[l]++; } } int cnt = 0; FOR(i, 0, m){ if (num[i] == m) cnt++; } if (cnt > 0) check[0] = 1; FOR(i, 0, n-m){ for (int j : con[c[i]]){ int l = (j-i+m) % m; num[l]--; if (num[l] == m-1) cnt--; } for (int j : con[c[i+m]]){ int l = (j-i+m) % m; num[l]++; if (num[l] == m) cnt++; } if (cnt > 0) check[i+1] = 1; } int r = 0; FOR(i, 0, n-m+1){ if (i < r) continue; if (i > r){ ans = -1; break; } ans++; FOR(j, i+1, i+m+1){ if (check[j] == 1) r = j; } } return ans; }
#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...