Submission #261977

# Submission time Handle Problem Language Result Execution time Memory
261977 2020-08-12T08:41:45 Z amoo_safar Boat (APIO16_boat) C++14
58 / 100
2000 ms 14584 KB
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimise ("ofast")
#pragma GCC optimise("unroll-loops")
#define int long long

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 500 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000000000000000;
const ll LOG = 25;

int  dp[2][N * 4][N], ps[N][N * 4], a[N], b[N], inv[N], n, in;
vector<int> T;

inline ll POW(ll x, ll t){
	ll res = 1;
	while(t){
		if (t & 1) res = res * x % MOD;
		t >>= 1;
		x = x * x % MOD;
	}
	return res;
}

inline void calc(){
	for (int i = 0; i < N; i++) inv[i] = POW(i, MOD - 2);
}
vector<pii> TT;

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	calc();
	for (int i = 1; i <= n; i++){
		cin >> a[i] >> b[i];
		b[i] ++; 
		T.pb(a[i]);
		T.pb(b[i]);
	}
	sort(all(T));
	T.resize(unique(all(T)) - T.begin());
	for (int i = 0; i < T.size() - 1; i++){
		if (T[i + 1] - 1 >= T[i]){
			TT.pb({T[i], T[i + 1]});
		}
	}
	bool f = 1;
	in = TT.size();
	for (int i = 0; i < N * 4; i++) ps[0][i] = 1;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= in; j++) for (int k = 1; k <= min(i, TT[j - 1].S - TT[j - 1].F); k++) dp[f][j][k] = 0;
		for (int j = 1; j <= in; j++){
			for (int k = 1; k <= min(i, TT[j - 1].S - TT[j - 1].F); k++){
				dp[f][j][k] = dp[f ^ 1][j][k];
				if (TT[j - 1].F >= b[i] || TT[j - 1].S <= a[i]) continue;
				if (k == 1) dp[f][j][k] += ps[i - 1][j - 1], dp[f][j][k] %= MOD;
				else{
					dp[f][j][k] += dp[f ^ 1][j][k - 1];
					dp[f][j][k] %= MOD;
				}
			}
		}
		ps[i][0] = 1;
		for (int j = 1; j <= in; j++){
			ps[i][j] = ps[i][j - 1];
			ll res = 1;
			ll ted = TT[j - 1].S - TT[j - 1].F;
			for (int k = 1; k <= min(i, TT[j - 1].S - TT[j - 1].F); k++){
				res = res * (ted - k + 1) % MOD;
				res = res * inv[k] % MOD;
				ps[i][j] += dp[f][j][k] * 1ll * res % MOD;
				ps[i][j] %= MOD;
			}
		}
		f ^= 1;
	}
	cout << (((ps[n][in] - 1) % MOD) + MOD) % MOD;


	return 0;
}

Compilation message

boat.cpp:8:0: warning: ignoring #pragma GCC optimise [-Wunknown-pragmas]
 #pragma GCC optimise ("ofast")
 
boat.cpp:9:0: warning: ignoring #pragma GCC optimise [-Wunknown-pragmas]
 #pragma GCC optimise("unroll-loops")
 
boat.cpp: In function 'int32_t main()':
boat.cpp:53:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < T.size() - 1; i++){
                  ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 991 ms 14364 KB Output is correct
2 Correct 964 ms 14328 KB Output is correct
3 Correct 977 ms 14288 KB Output is correct
4 Correct 1006 ms 14388 KB Output is correct
5 Correct 957 ms 14424 KB Output is correct
6 Correct 967 ms 14328 KB Output is correct
7 Correct 978 ms 14328 KB Output is correct
8 Correct 959 ms 14456 KB Output is correct
9 Correct 989 ms 14304 KB Output is correct
10 Correct 972 ms 14396 KB Output is correct
11 Correct 980 ms 14584 KB Output is correct
12 Correct 985 ms 14376 KB Output is correct
13 Correct 1032 ms 14340 KB Output is correct
14 Correct 967 ms 14328 KB Output is correct
15 Correct 972 ms 14328 KB Output is correct
16 Correct 161 ms 4472 KB Output is correct
17 Correct 175 ms 4600 KB Output is correct
18 Correct 166 ms 4472 KB Output is correct
19 Correct 177 ms 4584 KB Output is correct
20 Correct 169 ms 4472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 991 ms 14364 KB Output is correct
2 Correct 964 ms 14328 KB Output is correct
3 Correct 977 ms 14288 KB Output is correct
4 Correct 1006 ms 14388 KB Output is correct
5 Correct 957 ms 14424 KB Output is correct
6 Correct 967 ms 14328 KB Output is correct
7 Correct 978 ms 14328 KB Output is correct
8 Correct 959 ms 14456 KB Output is correct
9 Correct 989 ms 14304 KB Output is correct
10 Correct 972 ms 14396 KB Output is correct
11 Correct 980 ms 14584 KB Output is correct
12 Correct 985 ms 14376 KB Output is correct
13 Correct 1032 ms 14340 KB Output is correct
14 Correct 967 ms 14328 KB Output is correct
15 Correct 972 ms 14328 KB Output is correct
16 Correct 161 ms 4472 KB Output is correct
17 Correct 175 ms 4600 KB Output is correct
18 Correct 166 ms 4472 KB Output is correct
19 Correct 177 ms 4584 KB Output is correct
20 Correct 169 ms 4472 KB Output is correct
21 Correct 85 ms 13372 KB Output is correct
22 Correct 76 ms 13432 KB Output is correct
23 Correct 74 ms 13176 KB Output is correct
24 Correct 76 ms 13176 KB Output is correct
25 Correct 74 ms 13176 KB Output is correct
26 Correct 62 ms 12792 KB Output is correct
27 Correct 66 ms 13048 KB Output is correct
28 Correct 64 ms 12792 KB Output is correct
29 Correct 65 ms 12920 KB Output is correct
30 Correct 945 ms 14320 KB Output is correct
31 Correct 958 ms 14328 KB Output is correct
32 Correct 970 ms 14456 KB Output is correct
33 Correct 952 ms 14584 KB Output is correct
34 Correct 942 ms 14364 KB Output is correct
35 Correct 927 ms 14228 KB Output is correct
36 Correct 912 ms 14332 KB Output is correct
37 Correct 934 ms 14264 KB Output is correct
38 Correct 918 ms 14252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 2560 KB Output is correct
2 Correct 18 ms 2560 KB Output is correct
3 Correct 18 ms 2560 KB Output is correct
4 Correct 18 ms 2560 KB Output is correct
5 Correct 17 ms 2560 KB Output is correct
6 Correct 18 ms 2560 KB Output is correct
7 Correct 18 ms 2560 KB Output is correct
8 Correct 18 ms 2560 KB Output is correct
9 Correct 18 ms 2560 KB Output is correct
10 Correct 18 ms 2560 KB Output is correct
11 Correct 17 ms 2560 KB Output is correct
12 Correct 18 ms 2560 KB Output is correct
13 Correct 19 ms 2552 KB Output is correct
14 Correct 17 ms 2560 KB Output is correct
15 Correct 17 ms 2560 KB Output is correct
16 Correct 8 ms 1792 KB Output is correct
17 Correct 8 ms 1792 KB Output is correct
18 Correct 8 ms 1792 KB Output is correct
19 Correct 8 ms 1792 KB Output is correct
20 Correct 9 ms 1664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 991 ms 14364 KB Output is correct
2 Correct 964 ms 14328 KB Output is correct
3 Correct 977 ms 14288 KB Output is correct
4 Correct 1006 ms 14388 KB Output is correct
5 Correct 957 ms 14424 KB Output is correct
6 Correct 967 ms 14328 KB Output is correct
7 Correct 978 ms 14328 KB Output is correct
8 Correct 959 ms 14456 KB Output is correct
9 Correct 989 ms 14304 KB Output is correct
10 Correct 972 ms 14396 KB Output is correct
11 Correct 980 ms 14584 KB Output is correct
12 Correct 985 ms 14376 KB Output is correct
13 Correct 1032 ms 14340 KB Output is correct
14 Correct 967 ms 14328 KB Output is correct
15 Correct 972 ms 14328 KB Output is correct
16 Correct 161 ms 4472 KB Output is correct
17 Correct 175 ms 4600 KB Output is correct
18 Correct 166 ms 4472 KB Output is correct
19 Correct 177 ms 4584 KB Output is correct
20 Correct 169 ms 4472 KB Output is correct
21 Correct 85 ms 13372 KB Output is correct
22 Correct 76 ms 13432 KB Output is correct
23 Correct 74 ms 13176 KB Output is correct
24 Correct 76 ms 13176 KB Output is correct
25 Correct 74 ms 13176 KB Output is correct
26 Correct 62 ms 12792 KB Output is correct
27 Correct 66 ms 13048 KB Output is correct
28 Correct 64 ms 12792 KB Output is correct
29 Correct 65 ms 12920 KB Output is correct
30 Correct 945 ms 14320 KB Output is correct
31 Correct 958 ms 14328 KB Output is correct
32 Correct 970 ms 14456 KB Output is correct
33 Correct 952 ms 14584 KB Output is correct
34 Correct 942 ms 14364 KB Output is correct
35 Correct 927 ms 14228 KB Output is correct
36 Correct 912 ms 14332 KB Output is correct
37 Correct 934 ms 14264 KB Output is correct
38 Correct 918 ms 14252 KB Output is correct
39 Correct 18 ms 2560 KB Output is correct
40 Correct 18 ms 2560 KB Output is correct
41 Correct 18 ms 2560 KB Output is correct
42 Correct 18 ms 2560 KB Output is correct
43 Correct 17 ms 2560 KB Output is correct
44 Correct 18 ms 2560 KB Output is correct
45 Correct 18 ms 2560 KB Output is correct
46 Correct 18 ms 2560 KB Output is correct
47 Correct 18 ms 2560 KB Output is correct
48 Correct 18 ms 2560 KB Output is correct
49 Correct 17 ms 2560 KB Output is correct
50 Correct 18 ms 2560 KB Output is correct
51 Correct 19 ms 2552 KB Output is correct
52 Correct 17 ms 2560 KB Output is correct
53 Correct 17 ms 2560 KB Output is correct
54 Correct 8 ms 1792 KB Output is correct
55 Correct 8 ms 1792 KB Output is correct
56 Correct 8 ms 1792 KB Output is correct
57 Correct 8 ms 1792 KB Output is correct
58 Correct 9 ms 1664 KB Output is correct
59 Execution timed out 2032 ms 14444 KB Time limit exceeded
60 Halted 0 ms 0 KB -