답안 #46878

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
46878 2018-04-24T13:30:14 Z qoo2p5 Skyscraper (JOI16_skyscraper) C++17
100 / 100
389 ms 130784 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 1e6;
const ll LINF = (ll) 1e18 + 1e9;
const ll MOD = (ll) 1e9 + 7;

#define sz(x) (int) (x).size()
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb(s, t, x) (int) (lower_bound(s, t, x) - s)
#define ub(s, t, x) (int) (upper_bound(s, t, x) - s)
#define rep(i, f, t) for (auto i = f; i < t; ++(i))
#define per(i, f, t) for (auto i = (f); i >= (t); --(i))

ll power(ll x, ll y, ll mod = MOD) {
    if (y == 0) {
        return 1;
    }
    if (y & 1) {
        return power(x, y - 1, mod) * x % mod;
    } else {
        ll tmp = power(x, y / 2, mod);
        return tmp * tmp % mod;
    }
}

template<typename A, typename B> bool mini(A &x, const B &y) {
    if (y < x) {
        x = y;
        return true;
    }
    return false;
}

template<typename A, typename B> bool maxi(A &x, const B &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}

void add(ll &x, ll y) {
    x += y;
    if (x >= MOD) x -= MOD;
    if (x < 0) x += MOD;
}

void run();

#define TASK ""

int main() {
#ifdef LOCAL
    if (strlen(TASK) > 0) {
        cerr << "Reminder: you are using file i/o, filename: " TASK "!" << endl << endl;
    }
#endif
#ifndef LOCAL
    if (strlen(TASK)) {
        freopen(TASK ".in", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    cout << fixed << setprecision(12);
    run();
    return 0;
}

// == SOLUTION == //

const int N = 105;
const int L = 1005;

int n, l;
int a[N];
ll dp[N][N][L][3];

void run() {
	cin >> n >> l;
	if (n == 1) {
		cout << "1\n";
		return;
	}
	rep(i, 0, n) {
		cin >> a[i];
	}
	sort(a, a + n);
	
	dp[0][0][0][0] = 1;
	rep(i, 0, n) {
		int w = (i == 0 ? a[i] : a[i] - a[i - 1]);
		
		rep(j, 0, n) {
			rep(t, 0, l) {
				rep(k, 0, 3) {
					int places = j + 1 - k;
					int to_add = 2 * j - k;
					int cost = t + to_add * w;
					ll cur = dp[i][j][t][k];
					
					if (cost <= l) {
						add(dp[i + 1][j + 1][cost][k], (cur * places) % MOD);
						if (j > 0) {
							add(dp[i + 1][j][cost][k], (cur * to_add) % MOD);
						}
						if (j >= 2) {
							add(dp[i + 1][j - 1][cost][k], (cur * (j - 1)) % MOD);
						}
						
						if (k == 0) {
							add(dp[i + 1][j + 1][cost][1], (cur * 2) % MOD);
							if (j > 0) {
								add(dp[i + 1][j][cost][1], (cur * 2) % MOD);
							}
						} else if (k == 1) {
							add(dp[i + 1][j + 1][cost][2], cur);
							if (j > 0) {
								add(dp[i + 1][j][cost][2], cur);
							}
						}
					}
				}
			}
		}
	}
	
	ll ans = 0;
	rep(i, 0, l + 1) {
		add(ans, dp[n][1][i][2]);
	}
	cout << ans << "\n";
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(TASK ".in", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(TASK ".out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 580 KB Output is correct
4 Correct 2 ms 820 KB Output is correct
5 Correct 8 ms 1700 KB Output is correct
6 Correct 4 ms 1700 KB Output is correct
7 Correct 2 ms 1700 KB Output is correct
8 Correct 2 ms 1700 KB Output is correct
9 Correct 4 ms 1932 KB Output is correct
10 Correct 3 ms 1932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1932 KB Output is correct
2 Correct 3 ms 1932 KB Output is correct
3 Correct 3 ms 1932 KB Output is correct
4 Correct 3 ms 1932 KB Output is correct
5 Correct 3 ms 1932 KB Output is correct
6 Correct 3 ms 1932 KB Output is correct
7 Correct 3 ms 1932 KB Output is correct
8 Correct 3 ms 1932 KB Output is correct
9 Correct 4 ms 1932 KB Output is correct
10 Correct 3 ms 1932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 580 KB Output is correct
4 Correct 2 ms 820 KB Output is correct
5 Correct 8 ms 1700 KB Output is correct
6 Correct 4 ms 1700 KB Output is correct
7 Correct 2 ms 1700 KB Output is correct
8 Correct 2 ms 1700 KB Output is correct
9 Correct 4 ms 1932 KB Output is correct
10 Correct 3 ms 1932 KB Output is correct
11 Correct 3 ms 1932 KB Output is correct
12 Correct 3 ms 1932 KB Output is correct
13 Correct 3 ms 1932 KB Output is correct
14 Correct 3 ms 1932 KB Output is correct
15 Correct 3 ms 1932 KB Output is correct
16 Correct 3 ms 1932 KB Output is correct
17 Correct 3 ms 1932 KB Output is correct
18 Correct 3 ms 1932 KB Output is correct
19 Correct 4 ms 1932 KB Output is correct
20 Correct 3 ms 1932 KB Output is correct
21 Correct 7 ms 4800 KB Output is correct
22 Correct 389 ms 129220 KB Output is correct
23 Correct 321 ms 129220 KB Output is correct
24 Correct 317 ms 129220 KB Output is correct
25 Correct 333 ms 129220 KB Output is correct
26 Correct 303 ms 129220 KB Output is correct
27 Correct 152 ms 129220 KB Output is correct
28 Correct 197 ms 129220 KB Output is correct
29 Correct 327 ms 130784 KB Output is correct
30 Correct 349 ms 130784 KB Output is correct