# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
342021 | 2021-01-01T05:49:34 Z | thecodingwizard | Boat (APIO16_boat) | C++11 | 419 ms | 6380 KB |
#include <bits/stdc++.h> using namespace std; using ll = long long; #define ii pair<int, int> #define f first #define s second #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define F0R(i, n) for (int i = 0; i < n; i++) #define FOR(i, a, b) for (int i = a; i < b; i++) #define inf 1000000010 const int mod = 1e9+7; int main() { cin.tie(0)->sync_with_stdio(0); int n; cin >> n; ii A[n]; map<int, int> compress; set<int> setValues; setValues.insert(0); setValues.insert(1); F0R(i, n) { cin >> A[i].f >> A[i].s; A[i].s++; setValues.insert(A[i].f); setValues.insert(A[i].s); } int idx = 0; vector<int> values; for (auto x : setValues) { compress[x] = idx; values.pb(x); idx++; } F0R(i, n) { A[i].f = compress[A[i].f]; A[i].s = compress[A[i].s]; } int ct[values.size()][n+1]; F0R(i, values.size()-1) { F0R(j, n+1) { if (j == 0) ct[i][j] = 1; else { int len = values[i+1]-values[i]; ct[i][j] = (ll)ct[i][j-1]*(len-(j-1))/j%mod; } } FOR(j, 2, n+1) { ct[i][j] = (ct[i][j] + ct[i][j-1]) % mod; } ct[i][0] = 0; } int dp[n][values.size()]; int dpSum[n][values.size()]; F0R(i, n) { F0R(j, values.size()-1) { if (j == 0) { dp[i][j] = 1; continue; } dp[i][j] = 0; int num = 0; for (int k = i-1; k >= -1; k--) { if (A[k+1].f <= j && A[k+1].s > j) { num++; //cout << (k>=0?dpSum[k][j-1]:1) << " " << j << " " << num << endl; dp[i][j] = (dp[i][j] + (ll)(k>=0?dpSum[k][j-1]:1)*ct[j][num])%mod; } } //cout << "dp[" << i << "][" << j << "]: " << dp[i][j] << endl; } F0R(j, values.size()-1) { dpSum[i][j] = ((j?dpSum[i][j-1]:0)+dp[i][j])%mod; } } ll ans = 0; FOR(j, 1, values.size()-1) { ans = (ans + dp[n-1][j]) % mod; } cout << ans << endl; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 290 ms | 6380 KB | Output is correct |
2 | Correct | 289 ms | 6380 KB | Output is correct |
3 | Correct | 288 ms | 6380 KB | Output is correct |
4 | Correct | 282 ms | 6380 KB | Output is correct |
5 | Correct | 283 ms | 6332 KB | Output is correct |
6 | Correct | 177 ms | 6380 KB | Output is correct |
7 | Correct | 171 ms | 6380 KB | Output is correct |
8 | Correct | 177 ms | 6380 KB | Output is correct |
9 | Correct | 186 ms | 6380 KB | Output is correct |
10 | Correct | 173 ms | 6380 KB | Output is correct |
11 | Correct | 181 ms | 6380 KB | Output is correct |
12 | Correct | 182 ms | 6380 KB | Output is correct |
13 | Correct | 178 ms | 6380 KB | Output is correct |
14 | Correct | 166 ms | 6380 KB | Output is correct |
15 | Correct | 179 ms | 6380 KB | Output is correct |
16 | Correct | 62 ms | 1644 KB | Output is correct |
17 | Correct | 60 ms | 1516 KB | Output is correct |
18 | Correct | 62 ms | 1516 KB | Output is correct |
19 | Correct | 61 ms | 1516 KB | Output is correct |
20 | Correct | 62 ms | 1516 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 290 ms | 6380 KB | Output is correct |
2 | Correct | 289 ms | 6380 KB | Output is correct |
3 | Correct | 288 ms | 6380 KB | Output is correct |
4 | Correct | 282 ms | 6380 KB | Output is correct |
5 | Correct | 283 ms | 6332 KB | Output is correct |
6 | Correct | 177 ms | 6380 KB | Output is correct |
7 | Correct | 171 ms | 6380 KB | Output is correct |
8 | Correct | 177 ms | 6380 KB | Output is correct |
9 | Correct | 186 ms | 6380 KB | Output is correct |
10 | Correct | 173 ms | 6380 KB | Output is correct |
11 | Correct | 181 ms | 6380 KB | Output is correct |
12 | Correct | 182 ms | 6380 KB | Output is correct |
13 | Correct | 178 ms | 6380 KB | Output is correct |
14 | Correct | 166 ms | 6380 KB | Output is correct |
15 | Correct | 179 ms | 6380 KB | Output is correct |
16 | Correct | 62 ms | 1644 KB | Output is correct |
17 | Correct | 60 ms | 1516 KB | Output is correct |
18 | Correct | 62 ms | 1516 KB | Output is correct |
19 | Correct | 61 ms | 1516 KB | Output is correct |
20 | Correct | 62 ms | 1516 KB | Output is correct |
21 | Incorrect | 419 ms | 5868 KB | Output isn't correct |
22 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 620 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 290 ms | 6380 KB | Output is correct |
2 | Correct | 289 ms | 6380 KB | Output is correct |
3 | Correct | 288 ms | 6380 KB | Output is correct |
4 | Correct | 282 ms | 6380 KB | Output is correct |
5 | Correct | 283 ms | 6332 KB | Output is correct |
6 | Correct | 177 ms | 6380 KB | Output is correct |
7 | Correct | 171 ms | 6380 KB | Output is correct |
8 | Correct | 177 ms | 6380 KB | Output is correct |
9 | Correct | 186 ms | 6380 KB | Output is correct |
10 | Correct | 173 ms | 6380 KB | Output is correct |
11 | Correct | 181 ms | 6380 KB | Output is correct |
12 | Correct | 182 ms | 6380 KB | Output is correct |
13 | Correct | 178 ms | 6380 KB | Output is correct |
14 | Correct | 166 ms | 6380 KB | Output is correct |
15 | Correct | 179 ms | 6380 KB | Output is correct |
16 | Correct | 62 ms | 1644 KB | Output is correct |
17 | Correct | 60 ms | 1516 KB | Output is correct |
18 | Correct | 62 ms | 1516 KB | Output is correct |
19 | Correct | 61 ms | 1516 KB | Output is correct |
20 | Correct | 62 ms | 1516 KB | Output is correct |
21 | Incorrect | 419 ms | 5868 KB | Output isn't correct |
22 | Halted | 0 ms | 0 KB | - |