답안 #245820

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
245820 2020-07-07T14:08:49 Z Atill83 Collecting Stamps 3 (JOI20_ho_t3) C++14
15 / 100
202 ms 263672 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;
pii stm[MAXN];
int x[MAXN], t[MAXN];
int 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(0, 0))
            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++){
                int &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);
                }

                int &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 <= 2e9 || rr <= 2e9){
                    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 156 ms 263544 KB Output is correct
2 Correct 160 ms 263520 KB Output is correct
3 Correct 151 ms 263544 KB Output is correct
4 Correct 152 ms 263548 KB Output is correct
5 Correct 157 ms 263544 KB Output is correct
6 Correct 157 ms 263672 KB Output is correct
7 Correct 156 ms 263672 KB Output is correct
8 Correct 150 ms 263544 KB Output is correct
9 Correct 168 ms 263672 KB Output is correct
10 Correct 156 ms 263544 KB Output is correct
11 Correct 159 ms 263544 KB Output is correct
12 Correct 158 ms 263672 KB Output is correct
13 Correct 154 ms 263548 KB Output is correct
14 Correct 153 ms 263672 KB Output is correct
15 Correct 153 ms 263544 KB Output is correct
16 Correct 153 ms 263544 KB Output is correct
17 Correct 151 ms 263544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 156 ms 263544 KB Output is correct
2 Correct 160 ms 263520 KB Output is correct
3 Correct 151 ms 263544 KB Output is correct
4 Correct 152 ms 263548 KB Output is correct
5 Correct 157 ms 263544 KB Output is correct
6 Correct 157 ms 263672 KB Output is correct
7 Correct 156 ms 263672 KB Output is correct
8 Correct 150 ms 263544 KB Output is correct
9 Correct 168 ms 263672 KB Output is correct
10 Correct 156 ms 263544 KB Output is correct
11 Correct 159 ms 263544 KB Output is correct
12 Correct 158 ms 263672 KB Output is correct
13 Correct 154 ms 263548 KB Output is correct
14 Correct 153 ms 263672 KB Output is correct
15 Correct 153 ms 263544 KB Output is correct
16 Correct 153 ms 263544 KB Output is correct
17 Correct 151 ms 263544 KB Output is correct
18 Incorrect 153 ms 263548 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 156 ms 263544 KB Output is correct
2 Correct 160 ms 263520 KB Output is correct
3 Correct 151 ms 263544 KB Output is correct
4 Correct 152 ms 263548 KB Output is correct
5 Correct 157 ms 263544 KB Output is correct
6 Correct 157 ms 263672 KB Output is correct
7 Correct 156 ms 263672 KB Output is correct
8 Correct 150 ms 263544 KB Output is correct
9 Correct 168 ms 263672 KB Output is correct
10 Correct 156 ms 263544 KB Output is correct
11 Correct 159 ms 263544 KB Output is correct
12 Correct 158 ms 263672 KB Output is correct
13 Correct 154 ms 263548 KB Output is correct
14 Correct 153 ms 263672 KB Output is correct
15 Correct 153 ms 263544 KB Output is correct
16 Correct 153 ms 263544 KB Output is correct
17 Correct 151 ms 263544 KB Output is correct
18 Correct 181 ms 263564 KB Output is correct
19 Correct 163 ms 263584 KB Output is correct
20 Correct 157 ms 263544 KB Output is correct
21 Correct 202 ms 263544 KB Output is correct
22 Correct 165 ms 263544 KB Output is correct
23 Correct 157 ms 263544 KB Output is correct
24 Correct 161 ms 263544 KB Output is correct
25 Correct 159 ms 263588 KB Output is correct
26 Correct 162 ms 263548 KB Output is correct
27 Correct 158 ms 263544 KB Output is correct
28 Correct 161 ms 263544 KB Output is correct
29 Correct 160 ms 263544 KB Output is correct
30 Correct 161 ms 263544 KB Output is correct
31 Correct 160 ms 263544 KB Output is correct
32 Correct 154 ms 263544 KB Output is correct
33 Correct 156 ms 263548 KB Output is correct
34 Correct 175 ms 263544 KB Output is correct
35 Correct 163 ms 263576 KB Output is correct
36 Correct 153 ms 263544 KB Output is correct
37 Correct 164 ms 263544 KB Output is correct
38 Correct 163 ms 263544 KB Output is correct
39 Correct 158 ms 263544 KB Output is correct
40 Correct 153 ms 263544 KB Output is correct
41 Correct 174 ms 263672 KB Output is correct
42 Correct 171 ms 263672 KB Output is correct
43 Correct 176 ms 263544 KB Output is correct
44 Correct 167 ms 263672 KB Output is correct
45 Correct 174 ms 263520 KB Output is correct
46 Correct 167 ms 263544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 156 ms 263544 KB Output is correct
2 Correct 160 ms 263520 KB Output is correct
3 Correct 151 ms 263544 KB Output is correct
4 Correct 152 ms 263548 KB Output is correct
5 Correct 157 ms 263544 KB Output is correct
6 Correct 157 ms 263672 KB Output is correct
7 Correct 156 ms 263672 KB Output is correct
8 Correct 150 ms 263544 KB Output is correct
9 Correct 168 ms 263672 KB Output is correct
10 Correct 156 ms 263544 KB Output is correct
11 Correct 159 ms 263544 KB Output is correct
12 Correct 158 ms 263672 KB Output is correct
13 Correct 154 ms 263548 KB Output is correct
14 Correct 153 ms 263672 KB Output is correct
15 Correct 153 ms 263544 KB Output is correct
16 Correct 153 ms 263544 KB Output is correct
17 Correct 151 ms 263544 KB Output is correct
18 Incorrect 153 ms 263548 KB Output isn't correct
19 Halted 0 ms 0 KB -