제출 #862997

#제출 시각아이디문제언어결과실행 시간메모리
862997mgl_diamondSkyscraper (JOI16_skyscraper)C++17
100 / 100
32 ms18256 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
 
#define foru(i, l, r) for(int i=(l); i<=(r); ++i)
#define ford(i, l, r) for(int i=(l); i>=(r); --i)
#define fore(x, v) for(auto &x : v)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define file "input"

void setIO() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  if (fopen(file".inp", "r")) {
    freopen(file".inp", "r", stdin);
    freopen(file".out", "w", stdout);
  }
}

const int MOD = 1e9+7;
int n, l, a[101];
int dp[101][101][1010][3];

void ADD(int &a, int b) { a += b; if (a >= MOD) a -= MOD; }
int mul(int a, int b) { return 1LL * a * b % MOD; }

int main() {
  setIO();

  cin >> n >> l;
  foru(i, 1, n) cin >> a[i];
  sort(a+1, a+n+1);

  if (n == 1) {
    cout << 1;
    return 0;
  }

  dp[1][1][0][0] = 1;
  dp[1][1][0][1] = 2;

  foru(i, 1, n-1) {
    int value = a[i+1];

    foru(cc, 0, i) 
      foru(cost, 0, l)
        foru(end, 0, 2) {
          int cur = dp[i][cc][cost][end];
          if (cur == 0) continue;

          // cout << "process " << i << " elements\n";
          // cout << "num cc " << cc << "\n";
          // cout << "cost " << cost << "\n";
          // cout << "endpoint filled " << end << "\n";
          // cout << cur << "\n";
          // cout << "-------\n";

          int nx_cost = cost + (a[i+1] - a[i]) * (cc * 2 - end);
          // cout << nx_cost << "\n";
          if (nx_cost > l) continue;

          // new cc at endpoint
          if (end < 2) ADD(dp[i+1][cc+1][nx_cost][end+1], mul(cur, 2 - end));

          // append cc with endpoint
          if (end < 2 && cc >= 1) ADD(dp[i+1][cc][nx_cost][end+1], mul(cur, 2 - end));

          // place in the middle
          ADD(dp[i+1][cc+1][nx_cost][end], mul(cur, cc + 1 - end));

          // append two cc
          if (cc >= 2) ADD(dp[i+1][cc-1][nx_cost][end], mul(cur, cc-1));

          // place left or right of cc
          if (cc >= 1) ADD(dp[i+1][cc][nx_cost][end], mul(cur, 2*cc-end));
        }
  }

  // cout << dp[2][2][2][1] << "\n";

  int ans = 0;
  foru(i, 0, l) ADD(ans, dp[n][1][i][2]);
  cout << ans;
}

컴파일 시 표준 에러 (stderr) 메시지

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:47:9: warning: unused variable 'value' [-Wunused-variable]
   47 |     int value = a[i+1];
      |         ^~~~~
skyscraper.cpp: In function 'void setIO()':
skyscraper.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen(file".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:20:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     freopen(file".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...