# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
569818 | aryan12 | Painting Walls (APIO20_paint) | C++17 | 1205 ms | 13252 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
int minimumInstructions(int N, int M, int K, vector<int> colors, vector<int> num, vector<vector<int> > likes)
{
vector<vector<int> > dp(2, vector<int> (M, -1e9));
vector<int> likings[K];
for(int contractor = 0; contractor < M; contractor++)
{
for(int j = 0; j < num[contractor]; j++)
{
likings[likes[contractor][j]].push_back(contractor);
}
}
vector<int> start_pos;
for(int i = N - 1; i >= 0; i--)
{
if(i <= N - 3)
{
for(int j = 0; j < likings[colors[i + 2]].size(); j++)
{
dp[i % 2][likings[colors[i + 2]][j]] = -1e9;
}
}
int omk_cur = i % 2, omk_prev = (i + 1) % 2;
bool flag = false;
for(int j = 0; j < likings[colors[i]].size(); j++)
{
int cur = likings[colors[i]][j];
if(i == N - 1 || dp[omk_prev][(cur + 1) % M] == -1e9)
{
dp[omk_cur][cur] = 1;
}
else
{
dp[omk_cur][cur] = dp[omk_prev][(cur + 1) % M] + 1;
}
if(dp[omk_cur][cur] >= M && i <= N - M && !flag)
{
start_pos.push_back(i);
flag = true;
}
}
}
int ans = 0;
int min_x = N;
for(int i = 0; i < start_pos.size(); i++)
{
if(start_pos[i] + M - 1 < min_x - 1)
{
return -1;
}
if(i == start_pos.size() - 1 || start_pos[i + 1] + M - 1 < min_x - 1 || start_pos[i] == 0)
{
min_x = start_pos[i];
ans++;
}
}
if(min_x != 0) return -1;
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |