Submission #2075190


Source Code Expand

Copy
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int dp[5005][5005];

int main(void) {
  int i,j,k;
  int n,x;
  cin>>n>>x;

  vi t(n+1);
  t[0]=-x;
  rep(i,n)cin>>t[i+1];

  rep(i,n+1)rep(j,n+1)dp[i][j]=-1;

  dp[0][0]=0;
  rep(i,n){
    int ok=n;
    int ng=i;
    rep(k,100){
      int mid=(ok+ng)/2;
      if(t[mid]>=t[i]+x)ok=mid;
      else ng=mid;
    }
    rep(j,n)if(dp[i][j]>=0){
      dp[ok][j+1]=max(dp[ok][j+1],dp[i][j]+min(x,t[ok]-t[i]));
      dp[ok-1][j+1]=max(dp[ok-1][j+1],dp[i][j]+min(x,t[ok-1]-t[i]));
    }
  }

  int ans=0;
  for(j=1;j<=n;j++){
    rep(i,n+1)if(dp[i][j]>=0)ans=max(ans,dp[i][j]);
    cout<<ans<<endl;
  }

}

Submission Info

Submission Time
Task D - すぬけそだて――トレーニング――
User rika0384
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1256 Byte
Status
Exec Time 238 ms
Memory 98048 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt
All 500 / 500 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt 206 ms 98048 KB
02.txt 204 ms 98048 KB
03.txt 207 ms 98048 KB
04.txt 205 ms 98048 KB
05.txt 209 ms 98048 KB
06.txt 210 ms 98048 KB
07.txt 210 ms 98048 KB
08.txt 211 ms 98048 KB
09.txt 209 ms 98048 KB
10.txt 209 ms 98048 KB
11.txt 208 ms 98048 KB
12.txt 209 ms 98048 KB
13.txt 209 ms 98048 KB
14.txt 210 ms 98048 KB
15.txt 212 ms 98048 KB
16.txt 218 ms 98048 KB
17.txt 204 ms 98048 KB
18.txt 149 ms 98048 KB
19.txt 147 ms 98048 KB
20.txt 147 ms 98048 KB
21.txt 221 ms 98048 KB
22.txt 220 ms 98048 KB
23.txt 224 ms 98048 KB
24.txt 224 ms 98048 KB
25.txt 205 ms 98048 KB
26.txt 207 ms 98048 KB
27.txt 207 ms 98048 KB
28.txt 205 ms 98048 KB
29.txt 205 ms 97920 KB
30.txt 146 ms 98048 KB
31.txt 228 ms 98048 KB
32.txt 229 ms 98048 KB
33.txt 238 ms 98048 KB
34.txt 237 ms 98048 KB
35.txt 211 ms 98048 KB
36.txt 212 ms 98048 KB
37.txt 209 ms 98048 KB
38.txt 210 ms 98048 KB
39.txt 148 ms 98048 KB
40.txt 148 ms 98048 KB
41.txt 1 ms 256 KB
42.txt 1 ms 256 KB
43.txt 1 ms 256 KB
44.txt 1 ms 256 KB
s1.txt 1 ms 256 KB
s2.txt 1 ms 256 KB
s3.txt 1 ms 256 KB