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>
#define f first
#define s second
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
const ll oo = 1e9+7;
const ll N = 5000+2;
int dp[N][N];
int b[N];
int n,m,k;
int Rec(int x,int y)
{
if (y==m) return 0;
if (dp[x][y]<oo) return dp[x][y];
int nx=(x+1)%n;
bool g0=0,g1=0;
for (int i=1; i<=k && i+y<=m; i++)
{
int c=Rec(nx,i+y);
if (c==0) g0=1;
if (c==1) g1=1;
}
if (b[x]==b[nx]) {
if (g1==1) dp[x][y]=1;
else dp[x][y]=0;
}
else {
if (g0==1) dp[x][y]=1;
else dp[x][y]=0;
}
return dp[x][y];
}
int main()
{
cin>>n>>m>>k;
for (int i=0; i<n; i++) cin>>b[i];
m--;
for (int i=0; i<n; i++)
for (int j=0; j<=m; j++) dp[i][j]=oo;
for (int i=0; i<n; i++)
{
cout<<(Rec(i,0)^1^b[i])<<" ";
}
}
# | 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... |
# | 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... |