답안 #245821

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
245821 2020-07-07T14:11:32 Z Atill83 Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
329 ms 526968 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 405;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n, l;
pll stm[MAXN];
int x[MAXN], t[MAXN];
ll dp[MAXN][MAXN][205][2];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif

    cin>>n>>l;

    for(int i = 0; i < n; i++) {
        cin>>x[2*i];
        x[2*i + 1] = x[2*i] - l;
    }

    stm[2*n] = {0, 0};
    for(int i = 0; i < n; i++){
        cin>>t[i];
        stm[2*i] = {x[2*i], t[i]};
        stm[2*i + 1] = {x[2*i + 1], t[i]};
    }

    sort(stm, stm + 2*n + 1);
    int idx = 0;
    for(int i = 0; i <= 2*n; i++){
        if(stm[i] == make_pair(0LL, 0LL))
            idx = i;
        //cout<<stm[i].ff<<" "<<stm[i].ss<<endl;
    }
    memset(dp, 0x7f, sizeof(dp));
    dp[idx][idx][0][0] = dp[idx][idx][0][1] = 0;
    int ans = 0;
    for(int i = 2; i <= n + 1; i++){
        for(int j = idx - i + 1; j <= idx; j++){
            dp[j][j + i - 1][0][0] = 2*stm[j + i - 1].ff - stm[j].ff;
            dp[j][j + i - 1][0][1] = -2*stm[j].ff + stm[j + i - 1].ff;
            for(int l = 1; l <= i; l++){
                ll &r = dp[j][j + i - 1][l][0];
                r = min(r, dp[j + 1][j + i - 1][l][0] + stm[j + 1].ff - stm[j].ff);
                r = min(r, dp[j + 1][j + i - 1][l][1] + stm[j + i - 1].ff - stm[j].ff);
                if(stm[j + 1].ff - stm[j].ff + dp[j + 1][j + i - 1][l - 1][0] <= stm[j].ss){
                    r = min(r, stm[j + 1].ff - stm[j].ff + dp[j + 1][j + i - 1][l - 1][0]);
                }
                if(dp[j + 1][j + i - 1][l - 1][1] + stm[j + i - 1].ff - stm[j].ff <= stm[j].ss){
                    r = min(r, dp[j + 1][j + i - 1][l - 1][1] + stm[j + i - 1].ff - stm[j].ff);
                }

                ll &rr = dp[j][j + i - 1][l][1];

                rr = min(rr, dp[j][j + i - 2][l][0] + stm[j + i - 1].ff - stm[j].ff);
                rr = min(rr, dp[j][j + i - 2][l][1] + stm[j + i - 1].ff - stm[j + i - 2].ff);

                if(dp[j][j + i - 2][l - 1][0] + stm[j + i - 1].ff - stm[j].ff <= stm[i + j - 1].ss){
                    rr = min(rr, dp[j][j + i - 2][l - 1][0] + stm[j + i - 1].ff - stm[j].ff);
                }

                if(dp[j][j + i - 2][l - 1][1] + stm[j + i - 1].ff - stm[j + i - 2].ff <= stm[i + j - 1].ss){
                    rr = min(rr, dp[j][j + i - 2][l - 1][1] + stm[j + i - 1].ff - stm[j + i - 2].ff);
                }

                if(r <= 1e18 || rr <= 1e18){
                    ans = max(ans, l);
                }
            }
        }
    }
    ans = min((int)n, ans);
    //cout<<dp[4][5][1][0]<<" "<<dp[4][5][1][1]<<endl;

    cout<<ans<<endl;

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}
# 결과 실행 시간 메모리 Grader output
1 Correct 296 ms 526840 KB Output is correct
2 Correct 298 ms 526968 KB Output is correct
3 Correct 297 ms 526932 KB Output is correct
4 Correct 293 ms 526712 KB Output is correct
5 Correct 292 ms 526896 KB Output is correct
6 Correct 297 ms 526788 KB Output is correct
7 Correct 303 ms 526888 KB Output is correct
8 Correct 299 ms 526712 KB Output is correct
9 Correct 303 ms 526808 KB Output is correct
10 Correct 318 ms 526840 KB Output is correct
11 Correct 297 ms 526712 KB Output is correct
12 Correct 310 ms 526756 KB Output is correct
13 Correct 297 ms 526712 KB Output is correct
14 Correct 295 ms 526836 KB Output is correct
15 Correct 298 ms 526968 KB Output is correct
16 Correct 302 ms 526896 KB Output is correct
17 Correct 295 ms 526840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 296 ms 526840 KB Output is correct
2 Correct 298 ms 526968 KB Output is correct
3 Correct 297 ms 526932 KB Output is correct
4 Correct 293 ms 526712 KB Output is correct
5 Correct 292 ms 526896 KB Output is correct
6 Correct 297 ms 526788 KB Output is correct
7 Correct 303 ms 526888 KB Output is correct
8 Correct 299 ms 526712 KB Output is correct
9 Correct 303 ms 526808 KB Output is correct
10 Correct 318 ms 526840 KB Output is correct
11 Correct 297 ms 526712 KB Output is correct
12 Correct 310 ms 526756 KB Output is correct
13 Correct 297 ms 526712 KB Output is correct
14 Correct 295 ms 526836 KB Output is correct
15 Correct 298 ms 526968 KB Output is correct
16 Correct 302 ms 526896 KB Output is correct
17 Correct 295 ms 526840 KB Output is correct
18 Correct 309 ms 526712 KB Output is correct
19 Correct 294 ms 526760 KB Output is correct
20 Correct 288 ms 526712 KB Output is correct
21 Correct 299 ms 526712 KB Output is correct
22 Correct 294 ms 526712 KB Output is correct
23 Correct 294 ms 526712 KB Output is correct
24 Correct 290 ms 526712 KB Output is correct
25 Correct 299 ms 526840 KB Output is correct
26 Correct 294 ms 526712 KB Output is correct
27 Correct 298 ms 526716 KB Output is correct
28 Correct 292 ms 526840 KB Output is correct
29 Correct 294 ms 526844 KB Output is correct
30 Correct 294 ms 526712 KB Output is correct
31 Correct 292 ms 526840 KB Output is correct
32 Correct 291 ms 526712 KB Output is correct
33 Correct 288 ms 526712 KB Output is correct
34 Correct 294 ms 526712 KB Output is correct
35 Correct 306 ms 526844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 296 ms 526840 KB Output is correct
2 Correct 298 ms 526968 KB Output is correct
3 Correct 297 ms 526932 KB Output is correct
4 Correct 293 ms 526712 KB Output is correct
5 Correct 292 ms 526896 KB Output is correct
6 Correct 297 ms 526788 KB Output is correct
7 Correct 303 ms 526888 KB Output is correct
8 Correct 299 ms 526712 KB Output is correct
9 Correct 303 ms 526808 KB Output is correct
10 Correct 318 ms 526840 KB Output is correct
11 Correct 297 ms 526712 KB Output is correct
12 Correct 310 ms 526756 KB Output is correct
13 Correct 297 ms 526712 KB Output is correct
14 Correct 295 ms 526836 KB Output is correct
15 Correct 298 ms 526968 KB Output is correct
16 Correct 302 ms 526896 KB Output is correct
17 Correct 295 ms 526840 KB Output is correct
18 Correct 322 ms 526840 KB Output is correct
19 Correct 329 ms 526844 KB Output is correct
20 Correct 294 ms 526712 KB Output is correct
21 Correct 300 ms 526712 KB Output is correct
22 Correct 304 ms 526712 KB Output is correct
23 Correct 302 ms 526840 KB Output is correct
24 Correct 292 ms 526816 KB Output is correct
25 Correct 294 ms 526712 KB Output is correct
26 Correct 295 ms 526712 KB Output is correct
27 Correct 294 ms 526712 KB Output is correct
28 Correct 296 ms 526716 KB Output is correct
29 Correct 299 ms 526840 KB Output is correct
30 Correct 303 ms 526840 KB Output is correct
31 Correct 297 ms 526968 KB Output is correct
32 Correct 298 ms 526768 KB Output is correct
33 Correct 307 ms 526712 KB Output is correct
34 Correct 293 ms 526712 KB Output is correct
35 Correct 309 ms 526712 KB Output is correct
36 Correct 301 ms 526840 KB Output is correct
37 Correct 298 ms 526712 KB Output is correct
38 Correct 295 ms 526712 KB Output is correct
39 Correct 296 ms 526856 KB Output is correct
40 Correct 300 ms 526796 KB Output is correct
41 Correct 312 ms 526900 KB Output is correct
42 Correct 307 ms 526840 KB Output is correct
43 Correct 320 ms 526840 KB Output is correct
44 Correct 303 ms 526844 KB Output is correct
45 Correct 323 ms 526840 KB Output is correct
46 Correct 312 ms 526840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 296 ms 526840 KB Output is correct
2 Correct 298 ms 526968 KB Output is correct
3 Correct 297 ms 526932 KB Output is correct
4 Correct 293 ms 526712 KB Output is correct
5 Correct 292 ms 526896 KB Output is correct
6 Correct 297 ms 526788 KB Output is correct
7 Correct 303 ms 526888 KB Output is correct
8 Correct 299 ms 526712 KB Output is correct
9 Correct 303 ms 526808 KB Output is correct
10 Correct 318 ms 526840 KB Output is correct
11 Correct 297 ms 526712 KB Output is correct
12 Correct 310 ms 526756 KB Output is correct
13 Correct 297 ms 526712 KB Output is correct
14 Correct 295 ms 526836 KB Output is correct
15 Correct 298 ms 526968 KB Output is correct
16 Correct 302 ms 526896 KB Output is correct
17 Correct 295 ms 526840 KB Output is correct
18 Correct 309 ms 526712 KB Output is correct
19 Correct 294 ms 526760 KB Output is correct
20 Correct 288 ms 526712 KB Output is correct
21 Correct 299 ms 526712 KB Output is correct
22 Correct 294 ms 526712 KB Output is correct
23 Correct 294 ms 526712 KB Output is correct
24 Correct 290 ms 526712 KB Output is correct
25 Correct 299 ms 526840 KB Output is correct
26 Correct 294 ms 526712 KB Output is correct
27 Correct 298 ms 526716 KB Output is correct
28 Correct 292 ms 526840 KB Output is correct
29 Correct 294 ms 526844 KB Output is correct
30 Correct 294 ms 526712 KB Output is correct
31 Correct 292 ms 526840 KB Output is correct
32 Correct 291 ms 526712 KB Output is correct
33 Correct 288 ms 526712 KB Output is correct
34 Correct 294 ms 526712 KB Output is correct
35 Correct 306 ms 526844 KB Output is correct
36 Correct 322 ms 526840 KB Output is correct
37 Correct 329 ms 526844 KB Output is correct
38 Correct 294 ms 526712 KB Output is correct
39 Correct 300 ms 526712 KB Output is correct
40 Correct 304 ms 526712 KB Output is correct
41 Correct 302 ms 526840 KB Output is correct
42 Correct 292 ms 526816 KB Output is correct
43 Correct 294 ms 526712 KB Output is correct
44 Correct 295 ms 526712 KB Output is correct
45 Correct 294 ms 526712 KB Output is correct
46 Correct 296 ms 526716 KB Output is correct
47 Correct 299 ms 526840 KB Output is correct
48 Correct 303 ms 526840 KB Output is correct
49 Correct 297 ms 526968 KB Output is correct
50 Correct 298 ms 526768 KB Output is correct
51 Correct 307 ms 526712 KB Output is correct
52 Correct 293 ms 526712 KB Output is correct
53 Correct 309 ms 526712 KB Output is correct
54 Correct 301 ms 526840 KB Output is correct
55 Correct 298 ms 526712 KB Output is correct
56 Correct 295 ms 526712 KB Output is correct
57 Correct 296 ms 526856 KB Output is correct
58 Correct 300 ms 526796 KB Output is correct
59 Correct 312 ms 526900 KB Output is correct
60 Correct 307 ms 526840 KB Output is correct
61 Correct 320 ms 526840 KB Output is correct
62 Correct 303 ms 526844 KB Output is correct
63 Correct 323 ms 526840 KB Output is correct
64 Correct 312 ms 526840 KB Output is correct
65 Correct 320 ms 526712 KB Output is correct
66 Correct 312 ms 526832 KB Output is correct
67 Correct 309 ms 526736 KB Output is correct
68 Correct 312 ms 526840 KB Output is correct
69 Correct 318 ms 526712 KB Output is correct
70 Correct 315 ms 526968 KB Output is correct
71 Correct 313 ms 526968 KB Output is correct
72 Correct 317 ms 526712 KB Output is correct
73 Correct 305 ms 526712 KB Output is correct
74 Correct 310 ms 526840 KB Output is correct
75 Correct 322 ms 526764 KB Output is correct
76 Correct 316 ms 526844 KB Output is correct
77 Correct 312 ms 526840 KB Output is correct
78 Correct 306 ms 526712 KB Output is correct
79 Correct 307 ms 526968 KB Output is correct
80 Correct 313 ms 526844 KB Output is correct
81 Correct 309 ms 526840 KB Output is correct
82 Correct 310 ms 526712 KB Output is correct
83 Correct 316 ms 526712 KB Output is correct
84 Correct 314 ms 526840 KB Output is correct
85 Correct 313 ms 526840 KB Output is correct
86 Correct 314 ms 526840 KB Output is correct
87 Correct 319 ms 526776 KB Output is correct
88 Correct 312 ms 526712 KB Output is correct
89 Correct 315 ms 526840 KB Output is correct
90 Correct 319 ms 526840 KB Output is correct
91 Correct 317 ms 526944 KB Output is correct
92 Correct 319 ms 526712 KB Output is correct
93 Correct 326 ms 526836 KB Output is correct