# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
386334 | leinad2 | Painting Walls (APIO20_paint) | C++17 | 1569 ms | 16108 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<bits/stdc++.h>
using namespace std;
vector<vector<int> >B;
int f(int a, int m){a%=m;if(a<0)a+=m;return a;}
int minimumInstructions(int N, int M, int K, vector<int>C, vector<int>A, vector<vector<int> >bB)
{
B=bB;
int i, j, k;
vector<int>X;X.resize(N);
vector<vector<int> >S;S.resize(K);
vector<int>cnt;cnt.resize(M);
int chk=0;
for(i=0;i<M;i++)
{
for(j=0;j<A[i];j++)
{
S[B[i][j]].push_back(i);
}
}
for(i=0;i<M;i++)
{
for(j=0;j<S[C[i]].size();j++)
{
int a=f(i-S[C[i]][j], M);
cnt[a]++;
}
}
for(i=0;i<M;i++)if(cnt[i]==M)chk++;
if(chk)X[0]=1;
for(i=1;i<=N-M;i++)
{
for(j=0;j<S[C[i-1]].size();j++)
{
int a=f(i-1-S[C[i-1]][j], M);
cnt[a]--;
if(cnt[a]==M-1)chk--;
}
for(j=0;j<S[C[i+M-1]].size();j++)
{
int a=f(i+M-1-S[C[i+M-1]][j], M);
cnt[a]++;if(cnt[a]==M)chk++;
}
if(chk)X[i]=1;
}
i=0;
if(X[0]==0||X[N-M]==0)return -1;
int ans=0;
while(1)
{
if(i==N-M)return ans+1;
k=-1;
for(j=i+1;j<=i+M;j++)
{
if(X[j])k=j;
}
if(k==-1)return -1;
i=k;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... |