Submission #362229

# Submission time Handle Problem Language Result Execution time Memory
362229 2021-02-02T08:49:50 Z AlexLuchianov Skyscraper (JOI16_skyscraper) C++14
20 / 100
371 ms 2924 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>

using ll = long long ;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 100;
int const lmax = 1000;
int const modulo = 1000000007;

int dp[5 + nmax][5 + lmax][2][2];
int dp2[5 + nmax][5 + lmax][2][2];

int v[1 + nmax];

void norm(int &aux) {
  if(modulo <= aux)
    aux -= modulo;
}

int main() {
  int n, target;
  std::cin >> n >> target;
  for(int i = 1;i <= n; i++)
    std::cin >> v[i];
  std::sort(v + 1, v + n + 1);
  for(int h = 0; h < 2; h++)
    for(int h2 = 0; h2 < 2; h2++)
      dp[0][0][h][h2] = 1;
  
  for(int phase = 2; phase <= n; phase++) {
    for(int i = 0; i <= n; i++)
      for(int j = 0; j <= target; j++)
        for(int h = 0; h < 2; h++)
          for(int h2 = 0; h2 < 2; h2++) {
            int bonus = (i * 2 + h + h2) * (v[phase] - v[phase - 1]);
            if(j + bonus <= target) {
              dp2[i][j + bonus][h][h2] += dp[i][j][h][h2];
              norm(dp2[i][j + bonus][h][h2]);
            }
          }
     for(int i = 0; i <= n; i++)
       for(int j = 0; j <= target; j++)
         for(int h = 0; h < 2; h++)
           for(int h2 = 0; h2 < 2; h2++) {
             dp[i][j][h][h2] = dp2[i][j][h][h2];
             dp2[i][j][h][h2] = 0;
           }

    for(int i = 0; i <= n; i++)
      for(int j = 0; j <= target; j++)
        for(int h = 0; h < 2; h++)
          for(int h2 = 0; h2 < 2; h2++) {
            
            if(0 < i) {
              dp2[i + 1][j][h][h2] += 1LL * dp[i][j][h][h2] * i % modulo;
              norm(dp2[i + 1][j][h][h2]);              
              dp2[i][j][h][h2] += 1LL * dp[i][j][h][h2] * i * 2 % modulo;
              norm(dp2[i][j][h][h2]);
              dp2[i - 1][j][h][h2] += 1LL * dp[i][j][h][h2] * i % modulo;
              norm(dp2[i - 1][j][h][h2]);
            }
            if(h == 1) {
              dp2[i][j][h][h2] += 1LL * dp[i][j][h][h2] % modulo;
              norm(dp2[i][j][h][h2]);
              dp2[i][j][0][h2] += 1LL * dp[i][j][h][h2] % modulo;
              norm(dp2[i][j][0][h2]);
              dp2[i + 1][j][h][h2] += 1LL * dp[i][j][h][h2] % modulo;
              norm(dp2[i + 1][j][h][h2]);
              dp2[i + 1][j][0][h2] += 1LL * dp[i][j][h][h2] % modulo;
              norm(dp2[i + 1][j][h][h2]);
            }
            if(h2 == 1) {
              dp2[i][j][h][h2] += 1LL * dp[i][j][h][h2] % modulo;
              norm(dp2[i][j][h][h2]);
              dp2[i][j][h][0] += 1LL * dp[i][j][h][h2] % modulo;
              norm(dp2[i][j][h][0]);
              dp2[i + 1][j][h][h2] += 1LL * dp[i][j][h][h2] % modulo;
              norm(dp2[i + 1][j][h][h2]);
              dp2[i + 1][j][h][0] += 1LL * dp[i][j][h][h2] % modulo;
              norm(dp2[i + 1][j][h][0]);
            }
          }

     for(int i = 0; i <= n; i++)
       for(int j = 0; j <= target; j++)
         for(int h = 0; h < 2; h++)
           for(int h2 = 0; h2 < 2; h2++) {
             dp[i][j][h][h2] = dp2[i][j][h][h2];
             dp2[i][j][h][h2] = 0;
           }
  }

  int result = 0;
  for(int j = 0; j <= target; j++) {
    result += dp[0][j][0][0];
    if(modulo <= result)
      result -= modulo;
  }
  std::cout << result;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 5 ms 620 KB Output is correct
6 Correct 4 ms 620 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 4 ms 620 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 3 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 5 ms 620 KB Output is correct
6 Correct 4 ms 620 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 4 ms 620 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 3 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 5 ms 748 KB Output is correct
22 Incorrect 371 ms 2924 KB Output isn't correct
23 Halted 0 ms 0 KB -