LOADING

加载过慢请开启缓存,浏览器默认开启

daily 1

2023/6/24 daily

CF 803E

void solve(){
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  memset(dp,-1,sizeof(dp));
  dp[0][1500]=0;
  for(int i=0;i<n;++i){
    for(int j=1500-k+1;j<=1500+k-1;++j){
        if(dp[i][j]==-1)continue;
        if(s[i]=='W'||s[i]=='?'){
            dp[i+1][j+1]=j;
        }
        if(s[i]=='L'||s[i]=='?'){
            dp[i+1][j-1]=j;
        }
        if(s[i]=='D'||s[i]=='?'){
            dp[i+1][j]=j;
        }
    }
  }
  if(dp[n][1500-k]==-1&&dp[n][1500+k]==-1){
    cout<<"NO\n";
    return;
  }
  int cur=1500+k;
  if(dp[n][1500+k]==-1){
    cur=1500-k;
  }
  for(int i=n-1;i>=0;--i){
    int pre=cur,cur=dp[i+1][cur];
    if(pre-cur==1){
        s[i]='W';
    }
    if(pre-cur==-1){
        s[i]='L';
    }
    if(pre-cur==0){
        s[i]='D';
    }
  }
  cout<<s<<'\n';
  return;
}