답안 #65407

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
65407 2018-08-07T14:14:49 Z Googal Teams (CEOI11_tea) C++14
30 / 100
755 ms 263168 KB
#include <algorithm>
#include <iostream>
#include <memory.h>

using namespace std;

typedef long long ll;
typedef long double lld;

const int NMAX = 1e3 + 1e2;
const int INF = 1e9;

int n;
int ok[NMAX];
int dp[NMAX];
int pr[NMAX];
int opt[NMAX];
int par[NMAX];

pair < int, int > a[NMAX];

bool check(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] = -INF;
    } else {
      dp[i] = pr[i - a[i].first] + 1;

      if(opt[i - a[i].first] >= i - x) {
        ok[i] = 1;
        par[i] = opt[i - a[i].first];
      }
    }

    pr[i] = pr[i - 1];
    opt[i] = opt[i - 1];

    if(ok[i] && pr[i] <= dp[i]) {
      opt[i] = i;
      pr[i] = dp[i];
    }
  }

  return (bool)ok[n];
}

void backtrack(int x) {
  if(x == 0)
    return;

  int p1 = par[x];
  backtrack(p1);

  cout << x - p1 << ' ';

  for(int i = p1 + 1; i <= x; i++)
    cout << a[i].second << ' ';
  cout << '\n';
}

int main()
{
  ios::sync_with_stdio(false);

  cin >> n;
  for(int i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }

  sort(a + 1, a + n + 1);

  int le = 1;
  int ri = n;

  while(le != ri) {
    int mid = (le + ri) / 2;
    if(check(mid) == false)
      le = mid + 1;
    else
      ri = mid;
  }

  check(le);
  cout << dp[n] << '\n';

  backtrack(n);
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 3 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 3 ms 720 KB Output is correct
3 Correct 3 ms 720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 720 KB Output is correct
2 Correct 3 ms 720 KB Output is correct
3 Correct 3 ms 812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 656 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 755 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 263168 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 263168 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 263168 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 263168 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 263168 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -