제출 #1267831

#제출 시각아이디문제언어결과실행 시간메모리
1267831minhmc2019Rabbit Carrot (LMIO19_triusis)C++20
0 / 100
36 ms328 KiB
#include <bits/stdc++.h>
#define FOR(i, l, r, x) for(int i = l; i <= r; i += x)
#define FOD(i, l, r, x) for(int i = l; i >= r; i -= x)
#define debug(x) cout << "[DEBUG]:  " << #x << " = " << x << endl;
#define BIT(x) (1 << (x))
#define int long long
using namespace std;

const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e18;

int n, M, h[N];

inline bool isOn(int mask, int i) {
    return ((mask >> i) & 1LL);
}

namespace sub1 {
    void solve() {
        int ans = 0;

        FOR(mask, 0, BIT(n) - 1, 1) {
            int last_i = -1;
            bool isValid = true;

            FOR(i, 0, n - 1, 1) {
                if (!isOn(mask, i)) continue;

                bool can_move = (h[last_i + 1] + ((i - last_i) * M) >= h[i + 1]);

                if (!can_move) {
                    isValid = false;
                    break;
                }

                last_i = i;
            }

            if (isValid) {
                ans = max(ans, (int)__builtin_popcountll(mask));
            }
        }

        cout << n - ans << endl;
    }
}

namespace sub2 {
    int dp[N] = {};

    inline bool isGreater(const int &i, const int &j) {
        return ((h[j] + abs(i - j) * M) >= h[i]);
    }

    void solve() {
        FOR(i, 1, n, 1) {
            dp[i] = 1;
            FOR(j, 1, i - 1, 1) {
                if (isGreater(i, j)) dp[i] = max(dp[i], dp[j] + 1);
            }
        }

        cout << n - *max_element(dp + 1, dp + n + 1) << endl;
    }
}

namespace sub4 {
    void solve() {

    }
}

void solve() {
    cin >> n >> M;
    FOR(i, 1, n, 1) cin >> h[i];
    h[0] = 0;

//    if (n <= 20 && *max_element(h + 1, h + n + 1) <= 10) {
//        sub1::solve();
//    } else if (n <= 5000) {
        sub2::solve();
//    } else {
//        sub4::solve();
//    }
}

signed main() {
    #define name "task"
    if (ifstream(name".inp")) {
        freopen(name".inp", "r", stdin);
        freopen(name".out", "w", stdout);
    }

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    solve();
}

컴파일 시 표준 에러 (stderr) 메시지

triusis.cpp: In function 'int main()':
triusis.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
triusis.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...