Submission #645272

# Submission time Handle Problem Language Result Execution time Memory
645272 2022-09-26T15:34:24 Z ghostwriter Skyscraper (JOI16_skyscraper) C++14
100 / 100
139 ms 58772 KB
#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

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 time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1364 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1364 KB Output is correct
7 Correct 1 ms 1236 KB Output is correct
8 Correct 1 ms 1364 KB Output is correct
9 Correct 1 ms 1364 KB Output is correct
10 Correct 1 ms 1104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1364 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 1 ms 1364 KB Output is correct
17 Correct 1 ms 1236 KB Output is correct
18 Correct 1 ms 1364 KB Output is correct
19 Correct 1 ms 1364 KB Output is correct
20 Correct 1 ms 1104 KB Output is correct
21 Correct 5 ms 7248 KB Output is correct
22 Correct 106 ms 35948 KB Output is correct
23 Correct 134 ms 47972 KB Output is correct
24 Correct 126 ms 52296 KB Output is correct
25 Correct 139 ms 47548 KB Output is correct
26 Correct 124 ms 48204 KB Output is correct
27 Correct 68 ms 58676 KB Output is correct
28 Correct 79 ms 58772 KB Output is correct
29 Correct 123 ms 58316 KB Output is correct
30 Correct 136 ms 47280 KB Output is correct