제출 #1330352

#제출 시각아이디문제언어결과실행 시간메모리
1330352bradley0927Just Long Neckties 2 (JOI25_ho_t4)C++20
컴파일 에러
0 ms0 KiB
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

// State: counts of each value 1..21, encoded as __int128
// 5 bits per value * 21 values = 105 bits, fits in __int128

const int MAXV = 21;

typedef __int128 State;

State encode(int cnt[]) {
    State s = 0;
    for (int i = MAXV; i >= 1; i--) {
        s = (s << 5) | cnt[i];
    }
    return s;
}

void decode(State s, int cnt[]) {
    for (int i = 1; i <= MAXV; i++) {
        cnt[i] = s & 31;
        s >>= 5;
    }
}

int respond(int cnt[], int x) {
    // find largest tail <= x, replace with x
    for (int v = x; v >= 1; v--) {
        if (cnt[v] > 0) {
            cnt[v]--;
            cnt[x]++;
            return 0; // no new model needed
        }
    }
    // no tail <= x found, need new model starting at 1, set to x
    cnt[x]++;
    return 1; // new model added
}

int countModels(int cnt[]) {
    int total = 0;
    for (int i = 1; i <= MAXV; i++) total += cnt[i];
    return total;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];

    // set of (prev_skipped, state)
    set<pair<int, State>> curr, next;
    
    // initial state: no models, prev not skipped
    int init[MAXV + 1] = {};
    curr.insert({0, encode(init)});

    int ans = INT_MAX;

    for (int i = 0; i < n; i++) {
        next.clear();
        for (auto &[prev, s] : curr) {
            int cnt[MAXV + 1];
            decode(s, cnt);

            // case 1: ignore (only if prev not skipped)
            if (!prev) {
                next.insert({1, s});
            }

            // case 2: respond
            int cnt2[MAXV + 1];
            copy(cnt, cnt + MAXV + 1, cnt2);
            respond(cnt2, v[i]);
            next.insert({0, encode(cnt2)});
        }
        curr = next;
    }

    for (auto &[prev, s] : curr) {
        int cnt[MAXV + 1];
        decode(s, cnt);
        ans = min(ans, countModels(cnt));
    }

    cout << ans << endl;
}

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

Main.cpp: In function 'int main()':
Main.cpp:65:15: error: 'INT_MAX' was not declared in this scope
   65 |     int ans = INT_MAX;
      |               ^~~~~~~
Main.cpp:5:1: note: 'INT_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?
    4 | #include <algorithm>
  +++ |+#include <climits>
    5 | using namespace std;