Submission #528029

#TimeUsernameProblemLanguageResultExecution timeMemory
528029tphuc2908Skyscraper (JOI16_skyscraper)C++14
20 / 100
2082 ms426312 KiB
#include<bits/stdc++.h> using namespace std; //#pragma GCC optimize("Ofast") //#pragma GCC target("avx,avx2,fma") //#pragma GCC optimization ("unroll-loops") #define rep(i, x, y) for(int i = x; i <= y; ++i) #define repi(i,x,y) for(int i = x; i >= y; --i) #define ci(x) int x; cin>> x #define TC(t) ci(t); while(t--) #define fi first #define se second #define pb push_back #define all(x) x.begin(), x.end() #define cii(x, y) ci(x); ci(y) #define ciii(x, y, z) ci(x); ci(y); ci(z) #define mp make_pair //#define int long long typedef long long ll; typedef vector<int> vi; const int N = 1e2 + 5; const int NN = 16 + 15; const int mod = 1e9+7; const int mod1 = 1e9 + 9; const int pi = 31; const ll inf = 1e15 + 6; const int block = 500; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; void readfile(){ #ifdef ONLINE_JUDGE #else freopen("text.inp", "r", stdin); #endif // ONLINE_JUDGE // freopen("text.inp", "r", stdin); // freopen("template.out", "w", stdout); } int n, L; int a[N]; void inp(){ cin >> n >> L; for(int i = 1; i <= n; ++i) cin >> a[i]; sort(a + 1, a + n + 1); } int add(int x, int y){ x += y; while(x < 0) x += mod; while(x >= mod) x -= mod; return x; } int mul(int x, int y){ return (x * 1LL * y) % mod; } unordered_map<int,int> f[N][N][3]; unordered_set<int> s[N][N][3]; void process(){ f[1][1][0][-2*a[1]] = 1; f[1][1][1][-a[1]] = 2; f[1][1][2][0] = 1; s[1][1][0].insert(-2*a[1]); s[1][1][1].insert(-a[1]); s[1][1][2].insert(0); for(int i = 1; i < n; ++i){ for(int j = 1; j <= i; ++j){ for(int t = 0; t <= 2; ++t){ for(int sum : s[i][j][t]){ if(j >= 2){ // merge two cc f[i + 1][j - 1][t][sum + 2*a[i + 1]] = add(f[i + 1][j - 1][t][sum + 2*a[i + 1]], mul(f[i][j][t][sum], j - 1)); s[i + 1][j - 1][t].insert(sum + 2*a[i + 1]); } if(t==0){ // not having any at the end or beginning // new cc f[i + 1][j + 1][0][sum + -2*a[i + 1]] = add(f[i + 1][j + 1][0][sum + -2*a[i + 1]], mul(f[i][j][t][sum], j + 1)); f[i + 1][j + 1][1][sum + -a[i + 1]] = add(f[i + 1][j + 1][1][sum + -a[i + 1]], mul(f[i][j][t][sum], 2)); // new cc but at the end or beginning s[i + 1][j + 1][0].insert(sum - 2*a[i + 1]); s[i + 1][j + 1][1].insert(sum - a[i + 1]); // attach to existing cc f[i + 1][j][0][sum] = add(f[i + 1][j][0][sum], mul(f[i][j][t][sum], 2*j)); s[i + 1][j][0].insert(sum); f[i + 1][j][1][sum + a[i + 1]] = add(f[i + 1][j][1][sum + a[i + 1]], mul(f[i][j][t][sum], 2)); // increasing one endpoint s[i + 1][j][1].insert(sum + a[i + 1]); } else if(t==1){ // new cc f[i + 1][j + 1][1][sum -2*a[i + 1]] = add(f[i + 1][j + 1][1][sum - 2*a[i + 1]], mul(f[i][j][t][sum], j)); f[i + 1][j + 1][2][sum - a[i + 1]] = add(f[i + 1][j + 1][2][sum - a[i + 1]], f[i][j][t][sum]); // new cc but at one endpoint s[i + 1][j + 1][1].insert(sum - 2*a[i + 1]); s[i + 1][j + 1][2].insert(sum - a[i + 1]); // attach to existing cc f[i + 1][j][1][sum] = add(f[i + 1][j][1][sum], mul(f[i][j][t][sum], 2*j - 1)); f[i + 1][j][2][sum + a[i + 1]] = add(f[i + 1][j][2][sum + a[i + 1]], f[i][j][t][sum]); // increasing one endpoint to two endpoints s[i + 1][j][1].insert(sum); s[i + 1][j][2].insert(sum + a[i + 1]); } else{ if(j >= 2){ // new cc f[i + 1][j + 1][2][sum - 2*a[i + 1]] = add(f[i + 1][j + 1][2][sum - 2*a[i + 1]], mul(f[i][j][t][sum], j - 1)); s[i + 1][j + 1][2].insert(sum - 2*a[i + 1]); // attach to existing cc f[i + 1][j][2][sum] = add(f[i + 1][j][2][sum], mul(f[i][j][t][sum], 2*j - 2)); s[i + 1][j][2].insert(sum); } } } } } } int res = 0; for(int i = 0; i <= L; ++i) res = add(res, f[n][1][2][i]); cout << res; } int main() { //readfile(); ios_base::sync_with_stdio(0); cin.tie(0); inp(); process(); return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'void readfile()':
skyscraper.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         freopen("text.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...