답안 #1091683

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1091683 2024-09-21T19:41:02 Z akim9905 Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
759 ms 516756 KB
#include <bits/stdc++.h>
using namespace std;

#define fileio() freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define fio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define allr(x) x.rbegin(), x.rend()
#define cmprs(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define endl "\n"
#define sp " "
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define rz resize
#define sz(a) (int)(a.size())
#define clr(a) a.clear()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef tuple<int, int, int> tpi;
typedef tuple<ll, ll, ll> tpl;
typedef pair<double, ll> pdl;
typedef pair<double, int> pdi;

const int dx[] = {1,-1,0,0,1,1,-1,-1};
const int dy[] = {0,0,1,-1,1,-1,1,-1};
const ll MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MAX = 404; // PLZ CHK!

int N,L,X[MAX],T[MAX];
int D[MAX][MAX][2][MAX];

int go(int l, int r, int p, int s) {
    if (l==N+1 && r==N+1 && s==0) return 0;
    if (l>=r) return INF;

    int &ret=D[l][r][p][s];
    if (ret!=-1) return ret;

    ret=INF;
    if (p) {
        ret=min(ret, go(l,r-1,1,s)+abs(X[r]-X[r-1]));
        ret=min(ret, go(l,r-1,0,s)+abs(X[r]-X[l]));
        if (s-1>=0) {
            int t1=go(l,r-1,1,s-1)+abs(X[r]-X[r-1]);
            int t2=go(l,r-1,0,s-1)+abs(X[r]-X[l]);
            if (t1<=T[r]) ret=min(ret, t1);
            if (t2<=T[r]) ret=min(ret, t2);
        }
    }
    else {
        ret=min(ret, go(l+1,r,0,s)+abs(X[l]-X[l+1]));
        ret=min(ret, go(l+1,r,1,s)+abs(X[l]-X[r]));
        if (s-1>=0) {
            int t1=go(l+1,r,0,s-1)+abs(X[l]-X[l+1]);
            int t2=go(l+1,r,1,s-1)+abs(X[l]-X[r]);
            if (t1<=T[l]) ret=min(ret, t1);
            if (t2<=T[l]) ret=min(ret, t2);
        }
    }

    return ret;
}

int main() {
    fio();
    memset(D,-1,sizeof D);

    cin>>N>>L;
    for (int i=1; i<=N; i++) cin>>X[i];
    for (int i=1; i<=N; i++) cin>>T[i];    

    X[N+1]=L;
    for (int i=N+2; i<=2*N+1; i++) X[i]=X[i-N-1]+L, T[i]=T[i-N-1];

    int ans=0;
    for (int l=1,r=N+1; l<=N+1; l++,r++) {
        for (int s=0; s<=N; s++) {
            if (go(l,r,0,s)<INF) ans=max(ans,s);
            if (go(l,r,1,s)<INF) ans=max(ans,s);
        }
    }
    
    cout<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 266 ms 516436 KB Output is correct
2 Correct 230 ms 516436 KB Output is correct
3 Correct 239 ms 516432 KB Output is correct
4 Correct 233 ms 516436 KB Output is correct
5 Correct 233 ms 516636 KB Output is correct
6 Correct 229 ms 516436 KB Output is correct
7 Correct 241 ms 516436 KB Output is correct
8 Correct 226 ms 516436 KB Output is correct
9 Correct 230 ms 516436 KB Output is correct
10 Correct 229 ms 516756 KB Output is correct
11 Correct 229 ms 516436 KB Output is correct
12 Correct 233 ms 516560 KB Output is correct
13 Correct 230 ms 516436 KB Output is correct
14 Correct 216 ms 516492 KB Output is correct
15 Correct 207 ms 516436 KB Output is correct
16 Correct 225 ms 516356 KB Output is correct
17 Correct 212 ms 516432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 266 ms 516436 KB Output is correct
2 Correct 230 ms 516436 KB Output is correct
3 Correct 239 ms 516432 KB Output is correct
4 Correct 233 ms 516436 KB Output is correct
5 Correct 233 ms 516636 KB Output is correct
6 Correct 229 ms 516436 KB Output is correct
7 Correct 241 ms 516436 KB Output is correct
8 Correct 226 ms 516436 KB Output is correct
9 Correct 230 ms 516436 KB Output is correct
10 Correct 229 ms 516756 KB Output is correct
11 Correct 229 ms 516436 KB Output is correct
12 Correct 233 ms 516560 KB Output is correct
13 Correct 230 ms 516436 KB Output is correct
14 Correct 216 ms 516492 KB Output is correct
15 Correct 207 ms 516436 KB Output is correct
16 Correct 225 ms 516356 KB Output is correct
17 Correct 212 ms 516432 KB Output is correct
18 Correct 206 ms 516436 KB Output is correct
19 Correct 206 ms 516460 KB Output is correct
20 Correct 216 ms 516436 KB Output is correct
21 Correct 213 ms 516400 KB Output is correct
22 Correct 207 ms 516600 KB Output is correct
23 Correct 213 ms 516432 KB Output is correct
24 Correct 207 ms 516600 KB Output is correct
25 Correct 205 ms 516436 KB Output is correct
26 Correct 226 ms 516560 KB Output is correct
27 Correct 232 ms 516736 KB Output is correct
28 Correct 215 ms 516440 KB Output is correct
29 Correct 234 ms 516464 KB Output is correct
30 Correct 240 ms 516432 KB Output is correct
31 Correct 217 ms 516432 KB Output is correct
32 Correct 235 ms 516436 KB Output is correct
33 Correct 238 ms 516432 KB Output is correct
34 Correct 237 ms 516348 KB Output is correct
35 Correct 226 ms 516440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 266 ms 516436 KB Output is correct
2 Correct 230 ms 516436 KB Output is correct
3 Correct 239 ms 516432 KB Output is correct
4 Correct 233 ms 516436 KB Output is correct
5 Correct 233 ms 516636 KB Output is correct
6 Correct 229 ms 516436 KB Output is correct
7 Correct 241 ms 516436 KB Output is correct
8 Correct 226 ms 516436 KB Output is correct
9 Correct 230 ms 516436 KB Output is correct
10 Correct 229 ms 516756 KB Output is correct
11 Correct 229 ms 516436 KB Output is correct
12 Correct 233 ms 516560 KB Output is correct
13 Correct 230 ms 516436 KB Output is correct
14 Correct 216 ms 516492 KB Output is correct
15 Correct 207 ms 516436 KB Output is correct
16 Correct 225 ms 516356 KB Output is correct
17 Correct 212 ms 516432 KB Output is correct
18 Correct 613 ms 516688 KB Output is correct
19 Correct 400 ms 516604 KB Output is correct
20 Correct 296 ms 516552 KB Output is correct
21 Correct 357 ms 516532 KB Output is correct
22 Correct 438 ms 516432 KB Output is correct
23 Correct 255 ms 516480 KB Output is correct
24 Correct 248 ms 516432 KB Output is correct
25 Correct 255 ms 516696 KB Output is correct
26 Correct 217 ms 516392 KB Output is correct
27 Correct 261 ms 516432 KB Output is correct
28 Correct 236 ms 516604 KB Output is correct
29 Correct 272 ms 516500 KB Output is correct
30 Correct 276 ms 516440 KB Output is correct
31 Correct 276 ms 516436 KB Output is correct
32 Correct 249 ms 516452 KB Output is correct
33 Correct 283 ms 516492 KB Output is correct
34 Correct 237 ms 516692 KB Output is correct
35 Correct 277 ms 516436 KB Output is correct
36 Correct 239 ms 516400 KB Output is correct
37 Correct 279 ms 516372 KB Output is correct
38 Correct 249 ms 516436 KB Output is correct
39 Correct 296 ms 516436 KB Output is correct
40 Correct 229 ms 516536 KB Output is correct
41 Correct 711 ms 516436 KB Output is correct
42 Correct 475 ms 516436 KB Output is correct
43 Correct 723 ms 516536 KB Output is correct
44 Correct 476 ms 516516 KB Output is correct
45 Correct 758 ms 516616 KB Output is correct
46 Correct 508 ms 516696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 266 ms 516436 KB Output is correct
2 Correct 230 ms 516436 KB Output is correct
3 Correct 239 ms 516432 KB Output is correct
4 Correct 233 ms 516436 KB Output is correct
5 Correct 233 ms 516636 KB Output is correct
6 Correct 229 ms 516436 KB Output is correct
7 Correct 241 ms 516436 KB Output is correct
8 Correct 226 ms 516436 KB Output is correct
9 Correct 230 ms 516436 KB Output is correct
10 Correct 229 ms 516756 KB Output is correct
11 Correct 229 ms 516436 KB Output is correct
12 Correct 233 ms 516560 KB Output is correct
13 Correct 230 ms 516436 KB Output is correct
14 Correct 216 ms 516492 KB Output is correct
15 Correct 207 ms 516436 KB Output is correct
16 Correct 225 ms 516356 KB Output is correct
17 Correct 212 ms 516432 KB Output is correct
18 Correct 206 ms 516436 KB Output is correct
19 Correct 206 ms 516460 KB Output is correct
20 Correct 216 ms 516436 KB Output is correct
21 Correct 213 ms 516400 KB Output is correct
22 Correct 207 ms 516600 KB Output is correct
23 Correct 213 ms 516432 KB Output is correct
24 Correct 207 ms 516600 KB Output is correct
25 Correct 205 ms 516436 KB Output is correct
26 Correct 226 ms 516560 KB Output is correct
27 Correct 232 ms 516736 KB Output is correct
28 Correct 215 ms 516440 KB Output is correct
29 Correct 234 ms 516464 KB Output is correct
30 Correct 240 ms 516432 KB Output is correct
31 Correct 217 ms 516432 KB Output is correct
32 Correct 235 ms 516436 KB Output is correct
33 Correct 238 ms 516432 KB Output is correct
34 Correct 237 ms 516348 KB Output is correct
35 Correct 226 ms 516440 KB Output is correct
36 Correct 613 ms 516688 KB Output is correct
37 Correct 400 ms 516604 KB Output is correct
38 Correct 296 ms 516552 KB Output is correct
39 Correct 357 ms 516532 KB Output is correct
40 Correct 438 ms 516432 KB Output is correct
41 Correct 255 ms 516480 KB Output is correct
42 Correct 248 ms 516432 KB Output is correct
43 Correct 255 ms 516696 KB Output is correct
44 Correct 217 ms 516392 KB Output is correct
45 Correct 261 ms 516432 KB Output is correct
46 Correct 236 ms 516604 KB Output is correct
47 Correct 272 ms 516500 KB Output is correct
48 Correct 276 ms 516440 KB Output is correct
49 Correct 276 ms 516436 KB Output is correct
50 Correct 249 ms 516452 KB Output is correct
51 Correct 283 ms 516492 KB Output is correct
52 Correct 237 ms 516692 KB Output is correct
53 Correct 277 ms 516436 KB Output is correct
54 Correct 239 ms 516400 KB Output is correct
55 Correct 279 ms 516372 KB Output is correct
56 Correct 249 ms 516436 KB Output is correct
57 Correct 296 ms 516436 KB Output is correct
58 Correct 229 ms 516536 KB Output is correct
59 Correct 711 ms 516436 KB Output is correct
60 Correct 475 ms 516436 KB Output is correct
61 Correct 723 ms 516536 KB Output is correct
62 Correct 476 ms 516516 KB Output is correct
63 Correct 758 ms 516616 KB Output is correct
64 Correct 508 ms 516696 KB Output is correct
65 Correct 692 ms 516436 KB Output is correct
66 Correct 630 ms 516612 KB Output is correct
67 Correct 585 ms 516456 KB Output is correct
68 Correct 556 ms 516724 KB Output is correct
69 Correct 670 ms 516576 KB Output is correct
70 Correct 607 ms 516436 KB Output is correct
71 Correct 620 ms 516436 KB Output is correct
72 Correct 625 ms 516436 KB Output is correct
73 Correct 580 ms 516612 KB Output is correct
74 Correct 567 ms 516432 KB Output is correct
75 Correct 630 ms 516612 KB Output is correct
76 Correct 716 ms 516560 KB Output is correct
77 Correct 701 ms 516432 KB Output is correct
78 Correct 590 ms 516576 KB Output is correct
79 Correct 561 ms 516436 KB Output is correct
80 Correct 697 ms 516432 KB Output is correct
81 Correct 543 ms 516440 KB Output is correct
82 Correct 584 ms 516600 KB Output is correct
83 Correct 722 ms 516432 KB Output is correct
84 Correct 642 ms 516420 KB Output is correct
85 Correct 688 ms 516432 KB Output is correct
86 Correct 670 ms 516436 KB Output is correct
87 Correct 625 ms 516432 KB Output is correct
88 Correct 758 ms 516436 KB Output is correct
89 Correct 759 ms 516616 KB Output is correct
90 Correct 633 ms 516688 KB Output is correct
91 Correct 733 ms 516684 KB Output is correct
92 Correct 742 ms 516424 KB Output is correct
93 Correct 709 ms 516440 KB Output is correct