답안 #515952

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
515952 2022-01-20T07:52:29 Z apostoldaniel854 Teams (CEOI11_tea) C++14
70 / 100
410 ms 5556 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1e5;

struct node_info {
    int mx, id;
    node_info(int value = 0, int id = 0) {
        this->mx = value;
        this->id = id;
    }
    node_info operator + (node_info other) const {
        node_info RES;
        if (mx > other.mx)
            RES = {this->mx, this->id};
        else
            RES = other;
        return RES;
    }
};

class SegTree {
private:
    vector <node_info> seg;
public:
    SegTree(int n) {
        seg.resize(1 + 4 * n);
    }
    void update_pos(int node, int lb, int rb, int pos, node_info val) {
        if (lb == rb) {
            seg[node] = val;
            return;
        }
        int mid = (lb + rb) / 2, lnode = node * 2, rnode = node * 2 + 1;
        if (pos <= mid)
            update_pos(lnode, lb, mid, pos, val);
        else
            update_pos(rnode, mid + 1, rb, pos, val);
        seg[node] = seg[lnode] + seg[rnode];
    }
    node_info query_range(int node, int lb, int rb, int ql, int qr) {
        if (lb == ql && rb == qr)
            return seg[node];
        int mid = (lb + rb) / 2, lnode = node * 2, rnode = node * 2 + 1;
        if (ql <= mid && qr <= mid)
            return query_range(lnode, lb, mid, ql, qr);
        else if (mid + 1 <= ql && mid + 1 <= qr)
            return query_range(rnode, mid + 1, rb, ql, qr);
        else
            return query_range(lnode, lb, mid, ql, mid) + query_range(rnode, mid + 1, rb, mid + 1, qr);
    }
};

pair <int, int> a[1 + MAX_N];
int dp[1 + MAX_N];
int from[1 + MAX_N];

int n;


int get_max_teams(int limit_size) {
    SegTree D(n);
    dp[0] = 0;
    from[0] = 0;
    D.update_pos(1, 0, n, 0, node_info(dp[0], 0));
    for (int i = 1; i <= n; i++) {
        if (max(0, i - limit_size) <= i - a[i].first) {
            node_info res = D.query_range(1, 0, n, max(0, i - limit_size), i - a[i].first);
            dp[i] = res.mx + 1;
            from[i] = res.id;
        }
        else {
            dp[i] = -(1 << 30);
            from[i] = -1;
        }
        D.update_pos(1, 0, n, i, node_info(dp[i], i));
    }
    return dp[n];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i].first, a[i].second = i;
    sort(a + 1, a + n + 1);
    int max_teams = get_max_teams(n);
    int lb = 1, rb = n, min_size = n;
    while (lb <= rb) {
        int mid = (lb + rb) / 2;
        if (get_max_teams(mid) == max_teams)
            min_size = mid, rb = mid - 1;
        else
            lb = mid + 1;
    }
    get_max_teams(min_size);
    cout << max_teams << "\n";
    int curr = n;
    while (curr > 0) {
        cout << curr - from[curr] << " ";
        for (int i = curr; i > from[curr]; i--)
            cout << a[i].second << " ";
        cout << "\n";
        curr = from[curr];
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 0 ms 324 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 548 KB Output is correct
2 Correct 14 ms 604 KB Output is correct
3 Correct 14 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 592 KB Output is correct
2 Correct 13 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 290 ms 4920 KB Output is correct
2 Correct 337 ms 4656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 400 ms 5556 KB Output is correct
2 Correct 296 ms 4488 KB Output is correct
3 Correct 410 ms 5528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 2756 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 2752 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 2892 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -