답안 #1072477

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1072477 2024-08-23T19:46:37 Z vjudge1 송신탑 (IOI22_towers) C++17
0 / 100
4000 ms 4724 KB
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector <ll>;
using ii = pair <ll, ll>;
using vii = vector <ii>;
using vi = vector <int>;

ll n, k;
vll ve;
void init (int n, vi ve) {
    ::n = n;
    k = 0;
    ::ve = vll(ve.begin(), ve.end());
    while (ve[k] < ve[k+1]) k++;
}

const ll MAXN = 1E5+16;
ll dp[2][MAXN];
ll dpPs[2][MAXN];
// dp[0] low
// dp[1] up
int max_towers (int ql, int qr, int d) {
    // fill(dp+ql, dp+qr+1, 0);
    // cerr << d << '\n';
    // for (ll i = ql; i <= qr; i++) {
    //     ii maxN = { 0, -16 };
    //     dp[i] = 1;
    //     for (ll j = i-1; j >= ql; j--) {
    //         if (ve[i] <= maxN.first-d)
    //             if (ve[j] <= maxN.first-d) {
    //                 dp[i] = max(dp[i], dp[j]+1);
    //             }
    //         maxN = max(maxN, ii{ ve[j], j });
    //     }
    //     // cerr << ve[i] << ": " << dp[i] << '\n';
    // }
    // return *max_element(dp+ql, dp+qr+1);


    // fill(dp+ql, dp+qr+1, 0);
    deque <ii> dqUp, dqDw;
    // dqUp sorted increasing
    // dqDw sorted decreasing
    for (ll i = ql; i <= qr; i++) {
        dp[0][i] = 1;
        dp[1][i] = 0;
        dpPs[0][i] = 1;
        dpPs[1][i] = 0;
        while (dqUp.size() && dqUp.front().first < ve[i]) dqUp.pop_front();
        while (dqDw.size() && dqDw.front().first > ve[i]) dqDw.pop_front();
        // if (j < dq.size()) dp[i] = max(dp[i], dq[j].second+1);
        // cerr << ve[i] << ": " << dp[i] << '\n';
        // cerr << "j " << j << "  ";
        // for (auto [v1, v2] : dqUp) cerr << v1 << ' ' << v2 << "  ";
        // cerr << '\n';
        // for (auto [v1, v2] : dqDw) cerr << v1 << ' ' << v2 << "  ";
        // cerr << '\n';
        // cerr << '\n';
        for (auto [v, j] : dqUp) {
            if (ve[i] > ve[j]-d) continue;
            dp[0][i] = max(dp[0][i], dpPs[1][j]+1);
            break;
        }
        for (auto [v, j] : dqDw) {
            if (ve[i] < ve[j]+d) continue;
            dp[1][i] = max(dp[1][i], dpPs[0][j]+1);
            break;
        }
        dqUp.push_front({ ve[i], i });
        dpPs[1][i] = max(dp[1][i], dpPs[1][dqUp.front().second]);
        dqDw.push_front({ ve[i], i });
        dpPs[0][i] = max(dp[0][i], dpPs[0][dqDw.front().second]);
        // ll j = ll(lower_bound(dqUp.begin(), dqUp.end(), ii{ ve[i]+d, 0 }) - dq.begin())+1;
        // for (ll j = i-1; j >= ql; j--) {
        //     if (ve[i] <= maxN.first-d)
        //         if (ve[j] <= maxN.first-d) dp[i] = max(dp[i], dp[j]+1);
        //     maxN = max(maxN, ii{ ve[j], j });
        // }
    }
    return (*max_element(dp[0]+ql, dp[0]+qr+1)+1)/2;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4051 ms 4544 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB 1st lines differ - on the 1st token, expected: '13', found: '12'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB 1st lines differ - on the 1st token, expected: '13', found: '12'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4008 ms 4724 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4067 ms 3160 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB 1st lines differ - on the 1st token, expected: '13', found: '12'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4051 ms 4544 KB Time limit exceeded
2 Halted 0 ms 0 KB -