답안 #38130

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
38130 2018-01-02T03:01:06 Z funcsr Skyscraper (JOI16_skyscraper) C++14
15 / 100
1256 ms 181344 KB
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <cassert>
#include <algorithm>
#define rep(i,n) for (int i=0; i<(n); i++)
#define all(x) x.begin(), x.end()
using namespace std;
#define INF 1145141919
#define MOD 1000000007
inline void add(int &x, int v) { x += v; if (x >= MOD) x -= MOD; }
int N, L;
int A[100];
//#define MAX_L 2800
#define MAX_L 1400
int dp[2][1<<14][MAX_L+1];

int main() {
  cin >> N >> L;
  if (N > 14) abort();
  rep(i, N) cin >> A[i];
  sort(A, A+N, greater<int>());
  int lo = A[N-1], hi = A[0];
  if (hi-lo > L) {
    cout << 0 << "\n";
    return 0;
  }
  rep(i, N) A[i] -= lo;
  dp[0][0][0] = 1;
  rep(i, N) {
    rep(j, 1<<N) rep(k, MAX_L+1) dp[1][j][k] = 0;
    rep(S, 1<<N) {
      if (__builtin_popcount(S) != i) continue;
      rep(pos, N) {
        if ((S>>pos)&1) continue;
        int left = 0, right = 0;
        if (pos > 0) left = ((S>>(pos-1))&1) ? -1 : 1;
        if (pos+1 < N) right = ((S>>(pos+1))&1) ? -1 : 1;
        int e = A[i]*(left+right);
        int nS = S|(1<<pos);
        for (int k=max(-e, 0); k+e<=MAX_L; k++) {
          add(dp[1][nS][k+e], dp[0][S][k]);
        }
      }
    }
    swap(dp[0], dp[1]);
  }
  int s = 0;
  rep(i, L+1) add(s, dp[0][(1<<N)-1][i]);
  cout << s << "\n";
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 181344 KB Output is correct
2 Correct 89 ms 181344 KB Output is correct
3 Correct 113 ms 181344 KB Output is correct
4 Correct 243 ms 181344 KB Output is correct
5 Correct 346 ms 181344 KB Output is correct
6 Correct 383 ms 181344 KB Output is correct
7 Correct 0 ms 181344 KB Output is correct
8 Correct 333 ms 181344 KB Output is correct
9 Incorrect 329 ms 181344 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 609 ms 181344 KB Output is correct
2 Correct 1189 ms 181344 KB Output is correct
3 Correct 1109 ms 181344 KB Output is correct
4 Correct 1129 ms 181344 KB Output is correct
5 Correct 1153 ms 181344 KB Output is correct
6 Correct 1126 ms 181344 KB Output is correct
7 Correct 1193 ms 181344 KB Output is correct
8 Correct 1256 ms 181344 KB Output is correct
9 Correct 1159 ms 181344 KB Output is correct
10 Correct 1093 ms 181344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 181344 KB Output is correct
2 Correct 89 ms 181344 KB Output is correct
3 Correct 113 ms 181344 KB Output is correct
4 Correct 243 ms 181344 KB Output is correct
5 Correct 346 ms 181344 KB Output is correct
6 Correct 383 ms 181344 KB Output is correct
7 Correct 0 ms 181344 KB Output is correct
8 Correct 333 ms 181344 KB Output is correct
9 Incorrect 329 ms 181344 KB Output isn't correct
10 Halted 0 ms 0 KB -