제출 #1197607

#제출 시각아이디문제언어결과실행 시간메모리
1197607sitingfakeSkyscraper (JOI16_skyscraper)C++20
15 / 100
6 ms5192 KiB
#include<bits/stdc++.h>
using namespace std;

// define

#define execute cerr << " Time: " << fixed << setprecision(6) << (1.0 * clock() / CLOCKS_PER_SEC) << "s\n";
#define ll long long
#define int long long
#define ld double
#define ii pair<int,int>
#define se second
#define fi first
#define iii pair<int,ii>
#define all(v) v.begin(),v.end()
#define bit(x,i) (((x)>>(i))&1LL)
#define flip(x,i) ((x)^(1LL<<(i)))
#define ms(d,x) memset(d,x,sizeof(d))
#define sitingfake 1
#define orz 1

//constant

const ll mod = 1e9 + 7;
const long long linf = 4557430888798830399;
const int inf = 1061109567;
const int maxarr = 1e6 + 5;
const int dx[] = {0,1,-1,0};
const int dy[] = {1,0,0,-1};

template<typename T> bool maximize(T &a, const T &b)
{
    if(a < b) {a = b; return 1;}
    return 0;
}

template<typename T> bool minimize(T &a, const T &b)
{
    if(a > b) {a = b; return 1;}
    return 0;
}

inline void Plus(ll & a ,ll b)
{
    b %= mod;
    a += b;
    if(a >= mod) a -= mod;
    if(a < 0) a += mod;
    return;
}

inline void Mul(ll & a, ll b)
{
    a %= mod; b %= mod;
    a *= b;
    a %= mod;
    return;
}

//code

const int maxn = 200;

int a[maxn];

ll dp[2][105][1010][3];

int n , L;


void solve(void)
{
    cin >> n >> L;

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

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

    a[n + 1] = 10000;

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

    for(int i = 1; i <= n ;i++)
    {
        int cur = i & 1;
        int pre = ! cur;
        ms(dp[cur] , 0);

        for(int j = 1; j <= i ; j++)
        {
            for(int k = 0 ; k <= L ; k++)
            {
                for(int m = 0 ; m <= 2 ; m++)
                {
                    int diff = (2 * j - m) * (a[i+1] - a[i]);
                    if(diff > k) continue;

                    Plus(dp[cur][j][k][m] , dp[pre][j-1][k - diff][m]);

                    if(m > 0)
                    {
                        Plus(dp[cur][j][k][m] , dp[pre][j-1][k - diff][m - 1] * (3 - m));
                    }

                    Plus(dp[cur][j][k][m] , dp[pre][j][k - diff][m] * (2 * j - m));

                    if(m == 1)
                    {
                        Plus(dp[cur][j][k][m] , dp[pre][j][k - diff][m - 1] * (2 * j));
                    }
                    if(m == 2)
                    {
                        if(i == n)
                        {
                            // when j = 1 note that all components merged into one when i != n we can not
                            // we cannot append it because when we create a new one and merge it later, it
                            //'s paradoxical
                            Plus(dp[cur][j][k][m] , dp[pre][j][k - diff][m - 1]);
                        }
                        else if(j > 1)
                        {
                            Plus(dp[cur][j][k][m] , dp[pre][j][k - diff][m - 1] * (j - 1));
                        }
                    }

                    if(m == 2)
                    {
                        if(i == n)// we can only merge two end of permutation when i = n && j = 1
                        {
                            Plus(dp[cur][j][k][m] , dp[pre][j + 1][k - diff][m]);
                        }
                        else
                        {
                            Plus(dp[cur][j][k][m] , dp[pre][j + 1][k - diff][m] * (j * (j - 1)));
                        }
                    }
                    else if(m == 1)
                    {
                        Plus(dp[cur][j][k][m] , dp[pre][j + 1][k - diff][m] * j * j);
                    }
                    else
                    {
                        Plus(dp[cur][j][k][m] , dp[pre][j + 1][k - diff][m] * j * (j + 1));
                    }

                }
            }
        }
    }
    ll ans = 0;

    for(int i = 0; i <= L ; i++)
    {
        Plus(ans , dp[n & 1][1][i][2]);
    }

    cout << ans;

}
/**
**/
signed main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   #define task ""

   if(fopen(task".inp","r"))
   {
       freopen(task".inp","r",stdin);
       freopen(task".out","w",stdout);
   }

   int tc; tc = 1;

   while(tc--) solve();

   //execute;
}


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

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:174:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  174 |        freopen(task".inp","r",stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:175:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  175 |        freopen(task".out","w",stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...