답안 #57484

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
57484 2018-07-15T07:20:37 Z 조민규(#2116) Teams (CEOI11_tea) C++11
100 / 100
771 ms 78652 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <functional>
#include <numeric>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <bitset>
#include <map>
#include <set>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;

int n;
pi a[1000005];
int dp[1000005], ok[1000005], pref[1000005], opt[1000005], par[1000005];

int getans(int x){
    memset(ok, 0, sizeof(ok));
    ok[0] = 1;
    for(int i=1; i<=n; i++){
        if(i - a[i].first < 0){
            dp[i] = -1e9;
        }
        else{
            dp[i] = pref[i - a[i].first] + 1;
            if(opt[i - a[i].first] >= i - x) ok[i] = 1, par[i] = opt[i - a[i].first];
        }
        pref[i] = pref[i-1];
        opt[i] = opt[i-1];
        if(ok[i] && pref[i] <= dp[i]){
            opt[i] = i;
            pref[i] = dp[i];
        }
    }
    return ok[n];
}

void track(int x){
    if(x == 0) return;
    int p = par[x];
    track(p);
    printf("%d ",x - p);
    for(int j=p+1; j<=x; j++){
        printf("%d ",a[j].second);
    }
    puts("");
}

int main(){
    cin >> n;
    for(int i=1; i<=n; i++){
        scanf("%d",&a[i].first);
        a[i].second = i;
    }
    sort(a+1, a+n+1);
    int s = 1, e = n;
    while(s != e){
        int m = (s+e)/2;
        if(getans(m)) e = m;
        else s = m+1;
    }
    getans(s);
    printf("%d\n",dp[n]);
    track(n);
}

Compilation message

tea.cpp: In function 'int main()':
tea.cpp:64:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i].first);
         ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4216 KB Output is correct
2 Correct 7 ms 4452 KB Output is correct
3 Correct 6 ms 4452 KB Output is correct
4 Correct 6 ms 4452 KB Output is correct
5 Correct 6 ms 4452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4452 KB Output is correct
2 Correct 6 ms 4468 KB Output is correct
3 Correct 7 ms 4468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4468 KB Output is correct
2 Correct 9 ms 4508 KB Output is correct
3 Correct 7 ms 4508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 4552 KB Output is correct
2 Correct 12 ms 4744 KB Output is correct
3 Correct 12 ms 4764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 4764 KB Output is correct
2 Correct 11 ms 4780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 6876 KB Output is correct
2 Correct 65 ms 7252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 7472 KB Output is correct
2 Correct 41 ms 7472 KB Output is correct
3 Correct 52 ms 8196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 445 ms 28260 KB Output is correct
2 Correct 427 ms 31176 KB Output is correct
3 Correct 477 ms 34640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 631 ms 42148 KB Output is correct
2 Correct 535 ms 78652 KB Output is correct
3 Correct 570 ms 78652 KB Output is correct
4 Correct 665 ms 78652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 501 ms 78652 KB Output is correct
2 Correct 579 ms 78652 KB Output is correct
3 Correct 529 ms 78652 KB Output is correct
4 Correct 771 ms 78652 KB Output is correct