Language: C++



#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
//[?????????¨????????????£??????][???????????????¨??????°][??????????????????£???????????????]
int dp[2][2001][2];
int dp2[2][2001][2];
int tmp[2001][2];
int tmp2[2001][2];
string str;
int sumx[2001];
int sumy[2001];
int n,k;
 
int main(void){
    cin >> str;
    n=str.size();
    scanf("%d",&k);
    for(int i=0;i<=k;i++){
        for(int j=0;j<2;j++){
            dp[0][i][j]=-3000;
            dp2[0][i][j]=3000;
            dp[1][i][j]=-3000;
            dp2[1][i][j]=3000;
        }
    }
    dp[0][0][0]=0;
    dp[1][0][0]=0;
    dp2[0][0][0]=0;
    dp2[1][0][0]=0;
 
    for(int aa=0;aa<n;aa++){
        for(int i=0;i<=k;i++){
            for(int j=0;j<2;j++){
                tmp[i][j]=-3000;
                tmp2[i][j]=3000;
            }
        }
        for(int i=0;i<=k;i++){
            if(str[aa]=='U' || str[aa]=='D'){
                for(int j=0;j<2;j++){
                    tmp[i][j]=max(tmp[i][j],dp[0][i][j]);
                    tmp2[i][j]=min(tmp2[i][j],dp2[0][i][j]);
                }
            }
            if(str[aa]=='L'){
                tmp[i][0]=max(tmp[i][0],dp[0][i][0]-1);
                tmp[i][1]=max(tmp[i][1],dp[0][i][1]+1);
                tmp2[i][0]=min(tmp2[i][0],dp2[0][i][0]-1);
                tmp2[i][1]=min(tmp2[i][1],dp2[0][i][1]+1);
                if(i+1<=k){
                    tmp[i+1][1]=max(tmp[i+1][1],dp[0][i][0]+1);
                    tmp[i+1][0]=max(tmp[i+1][0],dp[0][i][1]-1);
                    tmp2[i+1][1]=min(tmp2[i+1][1],dp2[0][i][0]+1);
                    tmp2[i+1][0]=min(tmp2[i+1][0],dp2[0][i][1]-1);
                }
            }
            if(str[aa]=='R'){
                tmp[i][0]=max(tmp[i][0],dp[0][i][0]+1);
                tmp[i][1]=max(tmp[i][1],dp[0][i][1]-1);
                tmp2[i][0]=min(tmp2[i][0],dp2[0][i][0]+1);
                tmp2[i][1]=min(tmp2[i][1],dp2[0][i][1]-1);
                if(i+1<=k){
                    tmp[i+1][1]=max(tmp[i+1][1],dp[0][i][0]-1);
                    tmp[i+1][0]=max(tmp[i+1][0],dp[0][i][1]+1);
                    tmp2[i+1][1]=min(tmp2[i+1][1],dp2[0][i][0]-1);
                    tmp2[i+1][0]=min(tmp2[i+1][0],dp2[0][i][1]+1);
                }
            }
        }
        for(int i=0;i<=k;i++){
            for(int j=0;j<2;j++){
                dp[0][i][j]=tmp[i][j];
                dp2[0][i][j]=tmp2[i][j];
            }
        }
    }
 
    for(int aa=0;aa<n;aa++){
        for(int i=0;i<=k;i++){
            for(int j=0;j<2;j++){
                tmp[i][j]=-3000;
                tmp2[i][j]=3000;
            }
        }
        for(int i=0;i<=k;i++){
            if(str[aa]=='L' || str[aa]=='R'){
                for(int j=0;j<2;j++){
                    tmp[i][j]=max(tmp[i][j],dp[1][i][j]);
                    tmp2[i][j]=min(tmp2[i][j],dp2[1][i][j]);
                }
            }
            if(str[aa]=='D'){
                tmp[i][0]=max(tmp[i][0],dp[1][i][0]-1);
                tmp[i][1]=max(tmp[i][1],dp[1][i][1]+1);
                tmp2[i][0]=min(tmp2[i][0],dp2[1][i][0]-1);
                tmp2[i][1]=min(tmp2[i][1],dp2[1][i][1]+1);
                if(i+1<=k){
                    tmp[i+1][1]=max(tmp[i+1][1],dp[1][i][0]+1);
                    tmp[i+1][0]=max(tmp[i+1][0],dp[1][i][1]-1);
                    tmp2[i+1][1]=min(tmp2[i+1][1],dp2[1][i][0]+1);
                    tmp2[i+1][0]=min(tmp2[i+1][0],dp2[1][i][1]-1);
                }
            }
            if(str[aa]=='U'){
                tmp[i][0]=max(tmp[i][0],dp[1][i][0]+1);
                tmp[i][1]=max(tmp[i][1],dp[1][i][1]-1);
                tmp2[i][0]=min(tmp2[i][0],dp2[1][i][0]+1);
                tmp2[i][1]=min(tmp2[i][1],dp2[1][i][1]-1);
                if(i+1<=k){
                    tmp[i+1][1]=max(tmp[i+1][1],dp[1][i][0]-1);
                    tmp[i+1][0]=max(tmp[i+1][0],dp[1][i][1]+1);
                    tmp2[i+1][1]=min(tmp2[i+1][1],dp2[1][i][0]-1);
                    tmp2[i+1][0]=min(tmp2[i+1][0],dp2[1][i][1]+1);
                }
            }
        }
        for(int i=0;i<=k;i++){
            for(int j=0;j<2;j++){
                dp[1][i][j]=tmp[i][j];
                dp2[1][i][j]=tmp2[i][j];
            }
        }
    }
 
    for(int i=0;i<2;i++){
        for(int j=1;j<=k;j++){
            for(int l=0;l<2;l++){
                dp[i][j][l]=max(dp[i][j][l],dp[i][j-1][l]);
                dp2[i][j][l]=min(dp2[i][j][l],dp2[i][j-1][l]);
            }
        }
    }
    int res=0;
    for(int i=0;i<=k;i++){
        int lr=max(max(dp[0][i][0],dp[0][i][1]),max(-dp2[0][i][0],-dp2[0][i][1]));
        int ud=max(max(dp[1][k-i][0],dp[1][k-i][1]),max(-dp2[1][k-i][0],-dp2[1][k-i][1]));
        res=max(res,lr+ud);
    }
    printf("%d\n",res);
    return 0;
}
 

 
Compile Error Logs: 

You are not authorized to see the message. 
 
 
Status 
Judge: 32/32  C++  CPU: 00.07 sec  Memory: 3424 KB  Length: 3934 B  2017-03-29 18:24  2017-03-29 18:24  
Results for testcases 
Case # Verdict CPU Time Memory In Out Case Name 
 Case #1: : Accepted  00.00 sec 3244 KB    
 Case #2: : Accepted  00.00 sec 3236 KB    
 Case #3: : Accepted  00.00 sec 3164 KB    
 Case #4: : Accepted  00.00 sec 3240 KB    
 Case #5: : Accepted  00.00 sec 3288 KB    
 Case #6: : Accepted  00.00 sec 3188 KB    
 Case #7: : Accepted  00.00 sec 3248 KB    
 Case #8: : Accepted  00.00 sec 3244 KB    
 Case #9: : Accepted  00.00 sec 3164 KB    
 Case #10: : Accepted  00.00 sec 3156 KB    
 Case #11: : Accepted  00.00 sec 3164 KB    
 Case #12: : Accepted  00.00 sec 3324 KB    
 Case #13: : Accepted  00.00 sec 3192 KB    
 Case #14: : Accepted  00.00 sec 3200 KB    
 Case #15: : Accepted  00.06 sec 3364 KB    
 Case #16: : Accepted  00.03 sec 3224 KB    
 Case #17: : Accepted  00.01 sec 3188 KB    
 Case #18: : Accepted  00.00 sec 3312 KB    
 Case #19: : Accepted  00.00 sec 3304 KB    
 Case #20: : Accepted  00.00 sec 3348 KB    
 Case #21: : Accepted  00.00 sec 3264 KB    
 Case #22: : Accepted  00.02 sec 3208 KB    
 Case #23: : Accepted  00.00 sec 3216 KB    
 Case #24: : Accepted  00.06 sec 3424 KB    
 Case #25: : Accepted  00.01 sec 3264 KB    
 Case #26: : Accepted  00.00 sec 3164 KB    
 Case #27: : Accepted  00.06 sec 3240 KB    
 Case #28: : Accepted  00.06 sec 3236 KB    
 Case #29: : Accepted  00.07 sec 3268 KB    
 Case #30: : Accepted  00.06 sec 3424 KB    
 Case #31: : Accepted  00.07 sec 3356 KB    
 Case #32: : Accepted  00.04 sec 3260 KB    



 < prev | 1 /  32 | next >      : Accepted        00.00 sec        3244 KB 

 

Judge Input #1 ( in1.txt | 16 B)  Judge Output #1 ( out1.txt | 16 B) 

In preparation.

  
In preparation.

 

Comments 
 

 Under Construction. 

 
Categories 
 



 
Free Tags 
 



 



 

Compiler output:
a.cc:169:6: error: stray '#' in program
  169 | Case # Verdict CPU Time Memory In Out Case Name
      |      ^
a.cc:170:7: error: stray '#' in program
  170 |  Case #1: : Accepted  00.00 sec 3244 KB
      |       ^
a.cc:171:7: error: stray '#' in program
  171 |  Case #2: : Accepted  00.00 sec 3236 KB
      |       ^
a.cc:172:7: error: stray '#' in program
  172 |  Case #3: : Accepted  00.00 sec 3164 KB
      |       ^
a.cc:173:7: error: stray '#' in program
  173 |  Case #4: : Accepted  00.00 sec 3240 KB
      |       ^
a.cc:174:7: error: stray '#' in program
  174 |  Case #5: : Accepted  00.00 sec 3288 KB
      |       ^
a.cc:175:7: error: stray '#' in program
  175 |  Case #6: : Accepted  00.00 sec 3188 KB
      |       ^
a.cc:176:7: error: stray '#' in program
  176 |  Case #7: : Accepted  00.00 sec 3248 KB
      |       ^
a.cc:177:7: error: stray '#' in program
  177 |  Case #8: : Accepted  00.00 sec 3244 KB
      |       ^
a.cc:178:7: error: stray '#' in program
  178 |  Case #9: : Accepted  00.00 sec 3164 KB
      |       ^
a.cc:179:7: error: stray '#' in program
  179 |  Case #10: : Accepted  00.00 sec 3156 KB
      |       ^
a.cc:180:7: error: stray '#' in program
  180 |  Case #11: : Accepted  00.00 sec 3164 KB
      |       ^
a.cc:181:7: error: stray '#' in program
  181 |  Case #12: : Accepted  00.00 sec 3324 KB
      |       ^
a.cc:182:7: error: stray '#' in program
  182 |  Case #13: : Accepted  00.00 sec 3192 KB
      |       ^
a.cc:183:7: error: stray '#' in program
  183 |  Case #14: : Accepted  00.00 sec 3200 KB
      |       ^
a.cc:184:7: error: stray '#' in program
  184 |  Case #15: : Accepted  00.06 sec 3364 KB
      |       ^
a.cc:185:7: error: stray '#' in program
  185 |  Case #16: : Accepted  00.03 sec 3224 KB
      |       ^
a.cc:186:7: error: stray '#' in program
  186 |  Case #17: : Accepted  00.01 sec 3188 KB
      |       ^
a.cc:187:7: error: stray '#' in program
  187 |  Case #18: : Accepted  00.00 sec 3312 KB
      |       ^
a.cc:188:7: error: stray '#' in program
  188 |  Case #19: : Accepted  00.00 sec 3304 KB
      |       ^
a.cc:189:7: error: stray '#' in program
  189 |  Case #20: : Accepted  00.00 sec 3348 KB
      |       ^
a.cc:190:7: error: stray '#' in program
  190 |  Case #21: : Accepted  00.00 sec 3264 KB
      |       ^
a.cc:191:7: error: stray '#' in program
  191 |  Case #22: : Accepted  00.02 sec 3208 KB
      |       ^
a.cc:192:7: error: stray '#' in program
  192 |  Case #23: : Accepted  00.00 sec 3216 KB
      |       ^
a.cc:193:7: error: stray '#' in program
  193 |  Case #24: : Accepted  00.06 sec 3424 KB
      |       ^
a.cc:194:7: error: stray '#' in program
  194 |  Case #25: : Accepted  00.01 sec 3264 KB
      |       ^
a.cc:195:7: error: stray '#' in program
  195 |  Case #26: : Accepted  00.00 sec 3164 KB
      |       ^
a.cc:196:7: error: stray '#' in program
  196 |  Case #27: : Accepted  00.06 sec 3240 KB
      |       ^
a.cc:197:7: error: stray '#' in program
  197 |  Case #28: : Accepted  00.06 sec 3236 KB
      |       ^
a.cc:198:7: error: stray '#' in program
  198 |  Case #29: : Accepted  00.07 sec 3268 KB
      |       ^
a.cc:199:7: error: stray '#' in program
  199 |  Case #30: : Accepted  00.06 sec 3424 KB
      |       ^
a.cc:200:7: error: stray '#' in program
  200 |  Case #31: : Accepted  00.07 sec 3356 KB
      |       ^
a.cc:201:7: error: stray '#' in program
  201 |  Case #32: : Accepted  00.04 sec 3260 KB
      |       ^
a.cc:209:13: error: stray '#' in program
  209 | Judge Input #1 ( in1.txt | 16 B)  Judge Output #1 ( out1.txt | 16 B)
      |             ^
a.cc:209:48: error: stray '#' in program
  209 | Judge Input #1 ( in1.txt | 16 B)  Judge Output #1 ( out1.txt | 16 B)
      |                                                ^
a.cc:161:1: error: 'Compile' does not name a type
  161 | Compile Error Logs:
      | ^~~~~~~