# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
560682 | ala2 | Painting Walls (APIO20_paint) | C++14 | 44 ms | 10196 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 <vector>
#include <bits/stdc++.h>
#define F first
#define S second
//#define int long long
#define pb push_back
using namespace std;
int a[1001000];
int b[1001000];
int c[1001000];
int big[1001000];
int n,m;
int good(int i)
{
int x=c[i];
int dis=m-x+i;
if(c[dis]!=m)
return 0;
if(big[dis]<m-x+1)
{
return 0;
}
if(x==1)
return 1;
int nw=dis+1;
int bag=nw+x-2;
if(c[nw]!=1)
return 0;
if(c[bag]!=x-1)
return 0;
if(big[bag]<x-1)
return 0;
return 1;
}
vector<int>v;
int minimumInstructions(int N, int M, int K, vector<int> C,vector<int> A, vector<vector<int>> B)
{
n=N;
m=M;
for(int i=0;i<C.size();i++)
{
a[i]=C[i];
}
for(int i=0;i<B.size();i++)
{
for(int j=0;j<B[i].size();j++)
{
b[B[i][j]]=i+1;
}
}
//int bb=0;
// cout<<endl;
for(int i=0;i<n;i++)
{
int x=a[i];
if(b[x]==0)
return -1;
c[i]=b[x];
// cout<<c[i]<<" ";
}
// cout<<endl;
big[0]=1;
// cout<<1<<" ";
for(int i=1;i<n;i++)
{
if(c[i]-c[i-1]==1)
{
big[i]=big[i-1]+1;
}
else big[i]=1;
// cout<<big[1]<<" ";
}
// cout<<endl;
int x=n-m;
for(int i=0;i<=x;i++)
{
if(good(i))
{
v.pb(i);
}
}
sort(v.begin(),v.end());
//for(auto i:v)
// cout<<i<<" ";
// cout<<endl;
int cur=0;
int ans=1;
int bb=0;
if(v.size()==0)
{
return -1;
}
if(v[0]!=0)
{
return -1;
}
for(int i=1; i<v.size(); i++)
{
if(v[i]-v[i-1]>m)
return -1;
}
if(n-v[v.size()-1]>m)
return -1;
if(n==m)
{
return 1;
}
for(int i=1; i<v.size(); i++)
{
if(cur==x)
{
break;
}
if(v[i]==x)
{
ans++;
break;
}
if(i==v.size()-1)
{
if(v[i]==x)
{
ans++;
break;
}
else
{
bb=1;
break;
}
}
if(v[i]-cur>m)
bb=1;
if(v[i+1]-cur>m)
{
ans++;
cur=v[i];
}
}
if(bb)
return -1;
return ans;
}
/*
17
5
6
1 2 3 4 6 1 2 4 6 6 1 2 3 4 6 1 2
1 1
1 2
1 3
1 4
1 6
*/
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... |