답안 #94850

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
94850 2019-01-24T12:25:11 Z popovicirobert Teams (CEOI11_tea) C++14
50 / 100
332 ms 31384 KB
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44

using namespace std;

const int INF = 1e9;
const int MAXN = (int) 1e6;

pair <int, int> arr[MAXN + 1];
int dp[MAXN + 1], from[MAXN + 1];
int last[MAXN + 1];

inline int check(int n, int len) {
    int mx = 0;
    for(int i = 1; i <= n; i++) {
        if(i - arr[i].first < 0) {
            dp[i] = -INF;
        }
        else {
            if(i - last[i - arr[i].first] <= len) {
                dp[i] = dp[last[i - arr[i].first]] + 1;
                from[i] = last[i - arr[i].first];
            }
            else {
                dp[i] = -INF;
            }
            if(dp[i] < mx) {
                dp[i] = -INF;
            }
        }
        last[i] = last[i - 1];
        if(dp[i] > -INF) {
            last[i] = i;
        }
        mx = max(mx, dp[i]);
    }
    return dp[n];
}

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    for(i = 1; i <= n; i++) {
        cin >> arr[i].first;
        arr[i].second = i;
    }
    sort(arr + 1, arr + n + 1);
    int ans = check(n, n);
    int res = arr[n].first - 1;
    for(int step = 1 << 20; step; step >>= 1) {
        if(res + step <= n && check(n, res + step) < ans) {
            res += step;
        }
    }
    check(n, res + 1);
    cout << ans << "\n";
    int pos = n;
    while(pos > 0) {
        cout << pos - from[pos] << " ";
        for(i = from[pos] + 1; i <= pos; i++) {
            cout << arr[i].second << " ";
        }
        cout << "\n";
        pos = from[pos];
    }
    //cin.close();
    //cout.close();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 1 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Integer -1000000000 violates the range [1, 100]
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Integer -1000000000 violates the range [1, 200]
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Incorrect 3 ms 504 KB Integer -1000000000 violates the range [1, 5000]
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 508 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 2808 KB Output is correct
2 Correct 23 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 3064 KB Output is correct
2 Correct 21 ms 2460 KB Output is correct
3 Correct 28 ms 3140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 233 ms 21496 KB Output is correct
2 Correct 244 ms 21880 KB Output is correct
3 Correct 241 ms 21384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 317 ms 27804 KB Output is correct
2 Correct 309 ms 31384 KB Output is correct
3 Correct 313 ms 28280 KB Output is correct
4 Incorrect 321 ms 25020 KB Integer -1000000000 violates the range [1, 879000]
# 결과 실행 시간 메모리 Grader output
1 Correct 322 ms 26324 KB Output is correct
2 Correct 206 ms 24056 KB Output is correct
3 Correct 332 ms 28148 KB Output is correct
4 Incorrect 332 ms 28160 KB Integer -1000000000 violates the range [1, 1000000]