Submission #1153592

#TimeUsernameProblemLanguageResultExecution timeMemory
1153592jmyszka2007Skyscraper (JOI16_skyscraper)C++17
0 / 100
1 ms580 KiB
#include <bits/stdc++.h> #include <fstream> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/trie_policy.hpp> using namespace __gnu_pbds; using namespace std; template<class A, class B> ostream& operator<<(ostream& o, const pair<A, B>& p) {return o << '(' << p.first << ", " << p.second << ')';} template<size_t Index = 0, typename... Types> ostream& printTupleElements(ostream& o, const tuple<Types...>& t) {if constexpr (Index < sizeof...(Types)){if(Index > 0){o << ", ";}o << get<Index>(t);printTupleElements<Index + 1>(o, t);}return o;} template<typename... Types> ostream& operator<<(ostream& o, const tuple<Types...>& t){o << "(";printTupleElements(o, t);return o << ")";} template<class T> auto operator<<(ostream& o, const T& x) -> decltype(x.end(), o){o << '{';bool first = true;for (const auto& e : x){if (!first){o << ", ";}o << e;first = false;} return o << '}';} struct custom_hash {static uint64_t splitmix64(uint64_t x) {x += 0x9e3779b97f4a7c15;x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;x = (x ^ (x >> 27)) * 0x94d049bb133111eb;return x ^ (x >> 31);} size_t operator()(uint64_t x) const {static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();return splitmix64(x + FIXED_RANDOM);}}; //#define DEBUG #ifdef DEBUG #define fastio() #define debug(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n' #else #define fastio() ios_base::sync_with_stdio(0); cin.tie(0); #define debug(...) #endif typedef long long ll; #define pi pair<int, int> #define pll pair<ll, ll> #define st first #define nd second #define vi vector<int> #define vll vector<ll> #define eb emplace_back #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; constexpr int MOD = 1e9 + 7; ll dp[102][1002][2][2]; ll ndp[102][1002][2][2]; void solve() { //ifstream cin("nazwa.in"); //ofstream cout("nazwa.out"); int n, L; cin >> n >> L; vi T(n); for(auto &x : T) { cin >> x; } sort(all(T)); debug(T); dp[0][0][0][0] = 1; int pop = 0; for(int i = 0; i < n; i++) { debug(i); for(int j = 0; j <= i; j++) { for(int k = 0; k <= L; k++) { for(auto lft : {0, 1}) { for(auto rgt : {0, 1}) { if(lft + rgt > 2 * j) { continue; } int nxt = k + (T[i] - pop) * (2 * j - lft - rgt); if(nxt >= L) { continue; } if(dp[j][k][lft][rgt]) { debug(j, k, lft, rgt, nxt, dp[j][k][lft][rgt]); } //dolaczam sie z lewej ndp[j][nxt][lft][rgt] = (ndp[j][nxt][lft][rgt] + dp[j][k][lft][rgt] * (j - lft)) % MOD; //dolaczam sie z lewej i jestem pierwszym elementem if(!lft) { ndp[j][nxt][1][rgt] = (ndp[j][nxt][1][rgt] + dp[j][k][lft][rgt] * j) % MOD; } //dolaczam sie z prawej ndp[j][nxt][lft][rgt] = (ndp[j][nxt][lft][rgt] + dp[j][k][lft][rgt] * (j - rgt)) % MOD; //dolaczam sie z prawej i jestem ostatnim elementem if(!rgt) { ndp[j][nxt][lft][1] = (ndp[j][nxt][lft][1] + dp[j][k][lft][rgt] * j) % MOD; } //dolaczam sie w srodku if(j > 1) { ll moz = (j - lft - rgt) * (j - lft - rgt - 1); if(lft) { moz = moz + (j - 1); } if(rgt) { moz = moz + (j - 1); } if(lft && rgt) { moz--; } moz %= MOD; ndp[j - 1][nxt][lft][rgt] = (ndp[j - 1][nxt][lft][rgt] + dp[j][k][lft][rgt] * moz) % MOD; } //tworze nowa spojna ndp[j + 1][nxt][lft][rgt] = (ndp[j + 1][nxt][lft][rgt] + dp[j][k][lft][rgt]) % MOD; //zablokowana z lewej if(!lft) { ndp[j + 1][nxt][1][rgt] = (ndp[j + 1][nxt][1][rgt] + dp[j][k][lft][rgt]) % MOD; } //zablokowana z prawej if(!rgt) { ndp[j + 1][nxt][lft][1] = (ndp[j + 1][nxt][lft][1] + dp[j][k][lft][rgt]) % MOD; } } } } } for(int j = 0; j <= i + 1; j++) { for(int k = 0; k <= L; k++) { for(auto lft : {0, 1}) { for(auto rgt : {0, 1}) { dp[j][k][lft][rgt] = ndp[j][k][lft][rgt]; ndp[j][k][lft][rgt] = 0; } } } } pop = T[i]; } ll ans = 0; for(int j = 0; j <= L; j++) { ans = (ans + dp[1][j][1][1]) % MOD; } cout << ans << '\n'; } int main() { fastio(); int t = 1; //cin >> t; while(t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...