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;
deque<pair<int,int>>dq[2][5001];
void addmi(int val,int idx,int z){
while(!dq[0][z].empty()&&dq[0][z].back().first>=val){
dq[0][z].pop_back();
}
dq[0][z].push_back({val,idx});
}
void delmi(int idx,int z){
if(!dq[0][z].empty()&&dq[0][z].front().second==idx)dq[0][z].pop_front();
}
void addma(int val,int idx,int z){
while(!dq[1][z].empty()&&dq[1][z].back().first<=val){
dq[1][z].pop_back();
}
dq[1][z].push_back({val,idx});
}
void delma(int idx,int z){
if(!dq[1][z].empty()&&dq[1][z].front().second==idx)dq[1][z].pop_front();
}
int main() {
long long n,m,k;
cin>>n>>m>>k;
int arr[n];
for(int i = 0;i<n;i++){
cin>>arr[i];
}
long long dp[m+1][n+1];
for(int i = m;i>=0;i--){
for(int j = 0;j<n;j++){
if(i==m){
dp[i][j] = !arr[((j-1)%n+n)%n];
continue;
}
int nex = (j+1)%n;
if(arr[j]==0){
dp[i][j] = dq[0][nex].front().first;
}else{
dp[i][j] = dq[1][nex].front().first;
}
}
for(int j = 0;j<n;j++){
if(i+k<=m){
delmi(i+k,j);
delma(i+k,j);
}
addmi(dp[i][j],i,j);
addma(dp[i][j],i,j);
}
}
for(int i = 0;i<n;i++){
cout<<dp[0][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... |