답안 #42799

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
42799 2018-03-04T04:29:59 Z funcsr Aliens (IOI16_aliens) C++14
0 / 100
2 ms 632 KB
#include "aliens.h"
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define INF 1145141919
#define _1 first
#define _2 second
inline void chmin(long long &x, long long v) { if (x > v) x = v; }

long long dp[100010][101];
int L[100010];
long long take_photos(int N, int M, int K, std::vector<int> R, std::vector<int> C) {
  vector<P> ps;
  rep(i, N) {
    int l = R[i], r = C[i];
    if (l > r) swap(l, r);
    ps.pb(P(l, -r));
  }
  sort(all(ps));
  int r = -1;
  vector<P> nps;
  for (P p : ps) {
    if (-p._2 > r) {
      nps.pb(P(p._1, -p._2));
      r = -p._2;
    }
  }
  swap(ps, nps);
  rep(i, M) L[i] = i+1;
  for (P p : ps) {
    int l = p._1, r = p._2;
    for (int i=l; i<=r; i++) L[i] = min(L[i], l);
  }

  /*
  if (K == N) {
    int last_r = -1;
    long long s = 0;
    for (P p : ps) {
      int l = p._1, r = p._2;
      //cout<<"["<<l<<","<<r<<"]\n";
      s += 1LL*(r-l+1)*(r-l+1);
      if (l <= last_r) s -= 1LL*(last_r-l+1)*(last_r-l+1);
      last_r = r;
    }
    return s;
  }
  */
  rep(i, M+1) rep(j, K+1) dp[i][j] = 1LL<<60;
  dp[0][0] = 0;
  rep(i, M+1) {
    rep(k, K) {
      rep(pos, i+1) {
        int l = L[pos];
        assert(i-l+1 >= 0);
        chmin(dp[i+1][k+1], dp[pos][k] + 1LL*(i-l+1)*(i-l+1));
      }
    }
  }
  long long m = 1LL<<60;
  rep(k, K+1) chmin(m, dp[M][K]);
  return m;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 376 KB Correct answer: answer = 4
2 Incorrect 1 ms 376 KB Wrong answer: output = 5, expected = 4
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 428 KB Correct answer: answer = 1
2 Correct 2 ms 628 KB Correct answer: answer = 4
3 Incorrect 2 ms 632 KB Wrong answer: output = 2, expected = 1
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 376 KB Correct answer: answer = 4
2 Incorrect 1 ms 376 KB Wrong answer: output = 5, expected = 4
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 376 KB Correct answer: answer = 4
2 Incorrect 1 ms 376 KB Wrong answer: output = 5, expected = 4
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 376 KB Correct answer: answer = 4
2 Incorrect 1 ms 376 KB Wrong answer: output = 5, expected = 4
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 376 KB Correct answer: answer = 4
2 Incorrect 1 ms 376 KB Wrong answer: output = 5, expected = 4
3 Halted 0 ms 0 KB -