Submission #550514

#TimeUsernameProblemLanguageResultExecution timeMemory
550514Jarif_RahmanPainting Walls (APIO20_paint)C++17
40 / 100
1606 ms467516 KiB
#include "paint.h" #include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; int minimumInstructions(int n, int m, int K, vector<int> C, vector<int> A, vector<vector<int>> B){ vector<vector<int>> has_color(K); vector<unordered_map<int, int>> sth(n); vector<vector<int>> liked_by(n); for(int i = 0; i < n; i++) has_color[C[i]].pb(i); for(int i = 0; i < m; i++) for(int x: B[i]) for(int y: has_color[x]) sth[y][i] = 1, liked_by[y].pb(i); vector<bool> p(n, 0); for(int i = n-2; i >= 0; i--){ for(int x: liked_by[i]){ if(sth[i+1].find((x+1)%m) != sth[i+1].end()) sth[i][x] = sth[i+1][(x+1)%m]+1; } } for(int i = 0; i < n; i++) for(int x: liked_by[i]) if(sth[i][x] >= m) p[i] = 1; int ans = 0, ls = -1, c = 0; for(int i = n-1; i >= 0; i--){ c++; if(p[i]) ls = i; if(c == m || i == 0){ if(ls == -1) return -1; ans++; c=ls-i; ls = -1; } } 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...