Submission #519277

# Submission time Handle Problem Language Result Execution time Memory
519277 2022-01-26T07:07:42 Z Mukul202 Skyscraper (JOI16_skyscraper) C++17
100 / 100
172 ms 260648 KB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")

#include <bits/stdc++.h>
#define int long long
#define ld long double
#define all(x) x.begin(), x.end()
#define fr(i, n) for (int i = 0; i < (int)n; i++)
#define ff first
#define ss second
#define FILE                        \
  freopen("input.txt", "r", stdin); \
  freopen("output.txt", "w", stdout)
#define pb emplace_back // push_back
#define fio                         \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);
#define ps(x, y) fixed << setprecision(y) << x
const int mod = 1000000007;
#define printclock cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n";
using namespace std;

const int INF = 0x3f3f3f3f3f3f3f3f;

const int N = 1e2 + 5;
#define mod2 998244353

template <typename T>
using min_pq = priority_queue<T, std::vector<T>, greater<T>>;
#define pii pair<int, int>

template<class T,class F>
istream& operator>>(istream& is,pair<T,F>&p){
  is>>p.ff>>p.ss;
  return is;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
  for (auto &it : v)
    is >> it;
  return is;
}
template <typename... Args>
void in(Args &...args)
{
  ((cin >> args), ...);
}

template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> &p)
{
  os << p.ff << " " << p.ss;
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &x)
{
  for (auto &el : x)
    os << el << " ";
  return os;
}
template <typename... Args>
void out(Args... args)
{
  ((cout << args << " "), ...);
  cout << "\n";
}
// template<typename T>void out(T& x){for(auto&el :x)cout<<el<<" ";cout<<"\n";}
template <typename T, typename... Args>
std::string debug_detail(const char *names, T &&var, Args &&...args)
{
  std::stringstream builder;
  const char *end = names;
  while (*end != ',' && *end != '\0')
    ++end;
  (builder).write(names, end - names) << '=' << var;
  if constexpr (sizeof...(Args) > 0)
  {
    (builder << ", ") << debug_detail(end + 1, std::forward<Args>(args)...);
  }
  return builder.str();
}
template <typename... Args>
void debug_entry(const char *names, Args &&...args)
{
  std::stringstream retval;
  retval << "[" << debug_detail(names, std::forward<Args>(args)...) << "]\n";
  std::cout << retval.str();
}
#define deb(...) debug_entry(#__VA_ARGS__, __VA_ARGS__)

int n,k;
vector<int>a;
int dp[N][N][1005][3];

int f(int i,int c,int sum,int ends){
  if(sum>k || ends>2)
    return 0LL;
  if(c==0 && i>1)
    return 0LL;
  if(i==n+1)
    return ends==2 && c==1;
  int& ret=dp[i][c][sum][ends];
  if(ret!=-1LL)
    return ret;
  int ans=0LL;
  int nsum=sum+(a[i]-a[i-1])*(2*c-ends);
  //case merge component
  if(c>=2)
    ans+=1ll*(c-1)*f(i+1,c-1,nsum,ends);
  if(c>=1)//append to one end of any component
    ans+=1ll*(2*c-ends)*f(i+1,c,nsum,ends);
  ans+=1LL*(c+1-ends)*f(i+1,c+1,nsum,ends);//create new component
  if(ends<2)//append to end and create a new component
    ans+=1LL*(2-ends)*f(i+1,c+1,nsum,ends+1);
  if(ends<2)//no need to create a new component
    ans+=1ll*(2-ends)*f(i+1,c,nsum,ends+1);
  ans%=mod;
  return ret=ans;
}

inline void solve()
{ 
  in(n,k);
  a.resize(n+1);
  for(int i=1;i<=n;++i)
    cin>>a[i];
  if(n==1){
    out(1);
    return ;
  }
  sort(all(a));
  memset(dp,-1LL,sizeof(dp));
  out(f(1,0,0,0));
}

inline void solve2()
{
  
}

inline void solve3()
{
  
}

int32_t main()
{
  fio;

  int t = 1;
  // cin >> t;
  fr(j, t)
  {
    // cout<<"Case #"<<j+1<<":  ";
    solve();
  }

  printclock;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 90 ms 260452 KB Output is correct
3 Correct 91 ms 260472 KB Output is correct
4 Correct 90 ms 260420 KB Output is correct
5 Correct 93 ms 260568 KB Output is correct
6 Correct 90 ms 260412 KB Output is correct
7 Correct 91 ms 260416 KB Output is correct
8 Correct 93 ms 260440 KB Output is correct
9 Correct 90 ms 260440 KB Output is correct
10 Correct 94 ms 260424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 260440 KB Output is correct
2 Correct 91 ms 260396 KB Output is correct
3 Correct 93 ms 260416 KB Output is correct
4 Correct 91 ms 260460 KB Output is correct
5 Correct 94 ms 260432 KB Output is correct
6 Correct 92 ms 260420 KB Output is correct
7 Correct 92 ms 260488 KB Output is correct
8 Correct 92 ms 260428 KB Output is correct
9 Correct 94 ms 260420 KB Output is correct
10 Correct 99 ms 260428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 90 ms 260452 KB Output is correct
3 Correct 91 ms 260472 KB Output is correct
4 Correct 90 ms 260420 KB Output is correct
5 Correct 93 ms 260568 KB Output is correct
6 Correct 90 ms 260412 KB Output is correct
7 Correct 91 ms 260416 KB Output is correct
8 Correct 93 ms 260440 KB Output is correct
9 Correct 90 ms 260440 KB Output is correct
10 Correct 94 ms 260424 KB Output is correct
11 Correct 102 ms 260440 KB Output is correct
12 Correct 91 ms 260396 KB Output is correct
13 Correct 93 ms 260416 KB Output is correct
14 Correct 91 ms 260460 KB Output is correct
15 Correct 94 ms 260432 KB Output is correct
16 Correct 92 ms 260420 KB Output is correct
17 Correct 92 ms 260488 KB Output is correct
18 Correct 92 ms 260428 KB Output is correct
19 Correct 94 ms 260420 KB Output is correct
20 Correct 99 ms 260428 KB Output is correct
21 Correct 96 ms 260396 KB Output is correct
22 Correct 172 ms 260492 KB Output is correct
23 Correct 124 ms 260416 KB Output is correct
24 Correct 131 ms 260408 KB Output is correct
25 Correct 127 ms 260380 KB Output is correct
26 Correct 119 ms 260436 KB Output is correct
27 Correct 113 ms 260456 KB Output is correct
28 Correct 116 ms 260648 KB Output is correct
29 Correct 128 ms 260476 KB Output is correct
30 Correct 125 ms 260452 KB Output is correct