답안 #1087235

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087235 2024-09-12T10:57:39 Z mispertion Boat (APIO16_boat) C++17
100 / 100
608 ms 11348 KB
#include <bits/stdc++.h>

using namespace std;    
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define int ll
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mispertion ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define F first
#define S second
#define getlast(s) (*s.rbegin())
#define debg cout << "OK\n"

const ld PI = 3.1415926535;
const int N = 2e3 + 10;
const int M = 1e5 + 10;
int mod = 1e9+7;
const int infi = INT_MAX;
const ll infl = 2e18;
const int P = 505319;
const ld eps = 1e-9;

int mult(int a, int b){
    return a * 1LL * b % mod;
}

int sum(int a, int b){
    a %= mod;
    b %= mod;
    if(a + b >= mod)
        return a + b - mod;
    if(a + b < 0)
        return a + b + mod;
    return a + b;
}

int binpow(int a, int n){
    if (n == 0)
        return 1;
    if (n % 2 == 1){
        return mult(binpow(a, n - 1), a);
    }
    else{
        auto b = binpow(a, n / 2);
        return mult(b, b);
    }
}

int n, l[N], r[N], sm[N], f[N], fi[N], dp[N][N];
vector<int> al[N];

int C(int n, int k){
    return mult(f[n], mult(fi[k], fi[n - k]));
}

void solve(){
    cin >> n;
    vector<int> di = {};
    for(int i = 1; i <= n; i++){
        cin >> l[i] >> r[i];
        di.pb(l[i]);
        di.pb(r[i] + 1);
    }
    di.pb(0);
    sort(all(di));
    di.resize(unique(all(di)) - di.begin());
    sm[0] = 1;
    al[0].pb(1);
    for(int j = 0; j < sz(di) - 1; j++){
        int lr = di[j], rr = di[j + 1] - 1;
        dp[j][0] = 1;
        for(int i = 1; i <= n; i++){
            dp[j][i] = mult(dp[j][i - 1], rr - lr + i);
        }
    }
    for(int i = 1; i <= n; i++){
        int cur = 0;
        for(int j = 0; j < sz(di) - 1; j++){
            int lr = di[j], rr = di[j + 1] - 1;
            if(lr >= l[i] && rr <= r[i]){
                al[j].pb(cur);
                int nsm = 0;
                for(int k = 0; k < sz(al[j]); k++){
                    nsm =sum(nsm, mult(mult(dp[j][sz(al[j]) - k], fi[sz(al[j]) - k]), al[j][k]));
                }
                cur = sum(cur, sm[j]);
                sm[j] = nsm;
            }else{
                cur = sum(cur, sm[j]);
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < sz(di) - 1; i++)
        ans = sum(ans, sm[i]);
    cout << sum(ans, -1) << '\n';
}   

signed main(){
    mispertion;
    f[0] = 1;
    for(int i = 1; i < N; i++)
        f[i] = mult(f[i - 1], i);
    for(int i = 0; i < N; i++){
        fi[i] = binpow(f[i], mod - 2);
    }
    int t = 1;
    //cin >> t;
    while (t--){
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 8536 KB Output is correct
2 Correct 9 ms 8540 KB Output is correct
3 Correct 9 ms 8364 KB Output is correct
4 Correct 8 ms 8540 KB Output is correct
5 Correct 8 ms 8468 KB Output is correct
6 Correct 9 ms 8536 KB Output is correct
7 Correct 9 ms 8320 KB Output is correct
8 Correct 8 ms 8540 KB Output is correct
9 Correct 8 ms 8356 KB Output is correct
10 Correct 9 ms 8540 KB Output is correct
11 Correct 9 ms 8540 KB Output is correct
12 Correct 9 ms 8540 KB Output is correct
13 Correct 9 ms 8536 KB Output is correct
14 Correct 10 ms 8536 KB Output is correct
15 Correct 9 ms 8540 KB Output is correct
16 Correct 3 ms 1880 KB Output is correct
17 Correct 3 ms 1880 KB Output is correct
18 Correct 2 ms 1884 KB Output is correct
19 Correct 3 ms 2112 KB Output is correct
20 Correct 2 ms 1832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 8536 KB Output is correct
2 Correct 9 ms 8540 KB Output is correct
3 Correct 9 ms 8364 KB Output is correct
4 Correct 8 ms 8540 KB Output is correct
5 Correct 8 ms 8468 KB Output is correct
6 Correct 9 ms 8536 KB Output is correct
7 Correct 9 ms 8320 KB Output is correct
8 Correct 8 ms 8540 KB Output is correct
9 Correct 8 ms 8356 KB Output is correct
10 Correct 9 ms 8540 KB Output is correct
11 Correct 9 ms 8540 KB Output is correct
12 Correct 9 ms 8540 KB Output is correct
13 Correct 9 ms 8536 KB Output is correct
14 Correct 10 ms 8536 KB Output is correct
15 Correct 9 ms 8540 KB Output is correct
16 Correct 3 ms 1880 KB Output is correct
17 Correct 3 ms 1880 KB Output is correct
18 Correct 2 ms 1884 KB Output is correct
19 Correct 3 ms 2112 KB Output is correct
20 Correct 2 ms 1832 KB Output is correct
21 Correct 242 ms 9432 KB Output is correct
22 Correct 233 ms 9556 KB Output is correct
23 Correct 204 ms 9296 KB Output is correct
24 Correct 229 ms 9296 KB Output is correct
25 Correct 239 ms 9368 KB Output is correct
26 Correct 524 ms 9808 KB Output is correct
27 Correct 534 ms 10068 KB Output is correct
28 Correct 536 ms 9824 KB Output is correct
29 Correct 516 ms 9796 KB Output is correct
30 Correct 9 ms 8536 KB Output is correct
31 Correct 9 ms 8536 KB Output is correct
32 Correct 9 ms 8540 KB Output is correct
33 Correct 9 ms 8540 KB Output is correct
34 Correct 10 ms 8540 KB Output is correct
35 Correct 10 ms 8548 KB Output is correct
36 Correct 9 ms 8404 KB Output is correct
37 Correct 9 ms 8540 KB Output is correct
38 Correct 10 ms 8436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1628 KB Output is correct
2 Correct 3 ms 1372 KB Output is correct
3 Correct 3 ms 1372 KB Output is correct
4 Correct 4 ms 1628 KB Output is correct
5 Correct 4 ms 1628 KB Output is correct
6 Correct 6 ms 1644 KB Output is correct
7 Correct 6 ms 1628 KB Output is correct
8 Correct 6 ms 1628 KB Output is correct
9 Correct 7 ms 1624 KB Output is correct
10 Correct 6 ms 1624 KB Output is correct
11 Correct 4 ms 1592 KB Output is correct
12 Correct 3 ms 1372 KB Output is correct
13 Correct 3 ms 1372 KB Output is correct
14 Correct 3 ms 1628 KB Output is correct
15 Correct 4 ms 1372 KB Output is correct
16 Correct 2 ms 1064 KB Output is correct
17 Correct 3 ms 1112 KB Output is correct
18 Correct 3 ms 1116 KB Output is correct
19 Correct 2 ms 1068 KB Output is correct
20 Correct 2 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 8536 KB Output is correct
2 Correct 9 ms 8540 KB Output is correct
3 Correct 9 ms 8364 KB Output is correct
4 Correct 8 ms 8540 KB Output is correct
5 Correct 8 ms 8468 KB Output is correct
6 Correct 9 ms 8536 KB Output is correct
7 Correct 9 ms 8320 KB Output is correct
8 Correct 8 ms 8540 KB Output is correct
9 Correct 8 ms 8356 KB Output is correct
10 Correct 9 ms 8540 KB Output is correct
11 Correct 9 ms 8540 KB Output is correct
12 Correct 9 ms 8540 KB Output is correct
13 Correct 9 ms 8536 KB Output is correct
14 Correct 10 ms 8536 KB Output is correct
15 Correct 9 ms 8540 KB Output is correct
16 Correct 3 ms 1880 KB Output is correct
17 Correct 3 ms 1880 KB Output is correct
18 Correct 2 ms 1884 KB Output is correct
19 Correct 3 ms 2112 KB Output is correct
20 Correct 2 ms 1832 KB Output is correct
21 Correct 242 ms 9432 KB Output is correct
22 Correct 233 ms 9556 KB Output is correct
23 Correct 204 ms 9296 KB Output is correct
24 Correct 229 ms 9296 KB Output is correct
25 Correct 239 ms 9368 KB Output is correct
26 Correct 524 ms 9808 KB Output is correct
27 Correct 534 ms 10068 KB Output is correct
28 Correct 536 ms 9824 KB Output is correct
29 Correct 516 ms 9796 KB Output is correct
30 Correct 9 ms 8536 KB Output is correct
31 Correct 9 ms 8536 KB Output is correct
32 Correct 9 ms 8540 KB Output is correct
33 Correct 9 ms 8540 KB Output is correct
34 Correct 10 ms 8540 KB Output is correct
35 Correct 10 ms 8548 KB Output is correct
36 Correct 9 ms 8404 KB Output is correct
37 Correct 9 ms 8540 KB Output is correct
38 Correct 10 ms 8436 KB Output is correct
39 Correct 4 ms 1628 KB Output is correct
40 Correct 3 ms 1372 KB Output is correct
41 Correct 3 ms 1372 KB Output is correct
42 Correct 4 ms 1628 KB Output is correct
43 Correct 4 ms 1628 KB Output is correct
44 Correct 6 ms 1644 KB Output is correct
45 Correct 6 ms 1628 KB Output is correct
46 Correct 6 ms 1628 KB Output is correct
47 Correct 7 ms 1624 KB Output is correct
48 Correct 6 ms 1624 KB Output is correct
49 Correct 4 ms 1592 KB Output is correct
50 Correct 3 ms 1372 KB Output is correct
51 Correct 3 ms 1372 KB Output is correct
52 Correct 3 ms 1628 KB Output is correct
53 Correct 4 ms 1372 KB Output is correct
54 Correct 2 ms 1064 KB Output is correct
55 Correct 3 ms 1112 KB Output is correct
56 Correct 3 ms 1116 KB Output is correct
57 Correct 2 ms 1068 KB Output is correct
58 Correct 2 ms 1116 KB Output is correct
59 Correct 264 ms 10416 KB Output is correct
60 Correct 232 ms 10320 KB Output is correct
61 Correct 222 ms 10068 KB Output is correct
62 Correct 269 ms 10580 KB Output is correct
63 Correct 251 ms 10124 KB Output is correct
64 Correct 600 ms 11080 KB Output is correct
65 Correct 608 ms 11348 KB Output is correct
66 Correct 598 ms 11088 KB Output is correct
67 Correct 595 ms 11108 KB Output is correct
68 Correct 601 ms 11092 KB Output is correct
69 Correct 223 ms 10068 KB Output is correct
70 Correct 227 ms 10132 KB Output is correct
71 Correct 225 ms 10064 KB Output is correct
72 Correct 239 ms 10064 KB Output is correct
73 Correct 240 ms 10068 KB Output is correct
74 Correct 48 ms 2388 KB Output is correct
75 Correct 45 ms 2396 KB Output is correct
76 Correct 48 ms 2396 KB Output is correct
77 Correct 48 ms 2216 KB Output is correct
78 Correct 50 ms 2320 KB Output is correct