Submission #645272

#TimeUsernameProblemLanguageResultExecution timeMemory
645272ghostwriterSkyscraper (JOI16_skyscraper)C++14
100 / 100
139 ms58772 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <debug.h> #endif #define ft front #define bk back #define st first #define nd second #define ins insert #define ers erase #define pb push_back #define pf push_front #define _pb pop_back #define _pf pop_front #define lb lower_bound #define ub upper_bound #define mtp make_tuple #define bg begin #define ed end #define all(x) (x).bg(), (x).ed() #define sz(x) (int)(x).size() typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef string str; template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i)) #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i)) #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i)) #define FSN(i, n) for (int (i) = (n) - 1; (i) >= 0; --(i)) #define EACH(i, x) for (auto &(i) : (x)) #define WHILE while #define file "TEST" mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); } /* ---------------------------------------------------------------- END OF TEMPLATE ---------------------------------------------------------------- Tran The Bao - ghostwriter Training for VOI23 gold medal ---------------------------------------------------------------- MAI YEU CHUYEN BAO LOC ---------------------------------------------------------------- */ const int M = 1e9 + 7; const int N = 102; const int L = 1e3 + 2; int n, l, a[N], d[N][N][3][L], rs = 0; signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); // freopen(file".inp", "r", stdin); // freopen(file".out", "w", stdout); cin >> n >> l; FOR(i, 1, n) cin >> a[i]; a[n + 1] = L; sort(a + 1, a + 1 + n); if (n == 1) { cout << 1; return 0; } d[0][0][0][0] = 1; FOR(i, 1, n) FOR(j, 1, i) FOR(z, 0, 2) FOR(x, 0, l) { int &rs = d[i][j][z][x]; int newx = x - (2 * j - z) * (a[i + 1] - a[i]); if (newx < 0) continue; rs = (rs + d[i - 1][j - 1][z][newx]) % M; if (z) rs = (rs + 1LL * (3 - z) * d[i - 1][j - 1][z - 1][newx] % M) % M; rs = (rs + 1LL * (2 * j - z) * d[i - 1][j][z][newx] % M) % M; if (z) { if (z == 1) rs = (rs + 2LL * j * d[i - 1][j][z - 1][newx] % M) % M; else if (j == 1) { if (i == n) rs = (rs + d[i - 1][j][z - 1][newx]) % M; } else rs = (rs + 1LL * (j - 1) * d[i - 1][j][z - 1][newx] % M) % M; } if (j) { if (z == 0) rs = (rs + 1LL * j * (j + 1) % M * d[i - 1][j + 1][z][newx]) % M; else if (z == 1) rs = (rs + 1LL * j * j % M * d[i - 1][j + 1][z][newx] % M) % M; else { if (i == n) rs = (rs + d[i - 1][j + 1][z][newx]) % M; else rs = (rs + 1LL * j * (j - 1) % M * d[i - 1][j + 1][z][newx] % M) % M; } } } FOR(i, 0, l) rs = (rs + d[n][1][2][i]) % M; cout << rs; return 0; } /* 4 10 3 6 2 9 ---------------------------------------------------------------- From Benq: stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH ---------------------------------------------------------------- */

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:30:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
skyscraper.cpp:58:5: note: in expansion of macro 'FOR'
   58 |     FOR(i, 1, n) cin >> a[i];
      |     ^~~
skyscraper.cpp:30:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
skyscraper.cpp:66:5: note: in expansion of macro 'FOR'
   66 |     FOR(i, 1, n)
      |     ^~~
skyscraper.cpp:30:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
skyscraper.cpp:67:5: note: in expansion of macro 'FOR'
   67 |     FOR(j, 1, i)
      |     ^~~
skyscraper.cpp:30:31: warning: unnecessary parentheses in declaration of 'z' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
skyscraper.cpp:68:5: note: in expansion of macro 'FOR'
   68 |     FOR(z, 0, 2)
      |     ^~~
skyscraper.cpp:30:31: warning: unnecessary parentheses in declaration of 'x' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
skyscraper.cpp:69:5: note: in expansion of macro 'FOR'
   69 |     FOR(x, 0, l) {
      |     ^~~
skyscraper.cpp:30:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
skyscraper.cpp:92:5: note: in expansion of macro 'FOR'
   92 |     FOR(i, 0, l) rs = (rs + d[n][1][2][i]) % M;
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...