답안 #730277

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
730277 2023-04-25T14:46:28 Z abcvuitunggio Boat (APIO16_boat) C++17
9 / 100
342 ms 11092 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1000000007;
int dp[2][1010][501],c[1001][501],n,a[501],b[501],l[1001],r[1001],id,f[501];
vector <pair <int, int>> v;
int pw(int a, int b){
    if (!b)
        return 1;
    int t=pw(a,b>>1);
    t=(t*t)%mod;
    return (b&1?(t*a)%mod:t);
}
int32_t main(){
    ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
    cin >> n;
    f[0]=1;
    for (int i=1;i<=n;i++){
        cin >> a[i] >> b[i];
        v.push_back({a[i],0});
        v.push_back({b[i],1});
        f[i]=f[i-1]*i%mod;
    }
    for (int i=1;i<=n;i++)
        f[i]=pw(f[i],mod-2);
    sort(v.begin(),v.end());
    for (int i=0;i<v.size()-1;i++){
        if (v[i].second&&!v[i+1].second)
            continue;
        id++;
        l[id]=v[i].first+v[i].second;
        r[id]=v[i+1].first-1+v[i+1].second;
        c[id][0]=1;
        for (int j=1;j<=n;j++)
            c[id][j]=c[id][j-1]*(r[id]-l[id]-j+2)%mod;
        for (int j=2;j<=n;j++)
            c[id][j]=c[id][j]*f[j]%mod;
    }
    for (int i=0;i<2;i++)
        for (int k=0;k<=n;k++)
            dp[i][id+1][k]=1;
    for (int j=1;j<=id;j++)
        for (int k=0;k<=n;k++)
            dp[n&1^1][j][k]=(j>id?1:c[j][k]);
    for (int i=n;i>=1;i--)
        for (int j=id;j;j--)
            for (int k=0;k<=n;k++){
                if (k>r[j]-l[j]+1){
                    dp[i&1][j][k]=0;
                    continue;
                }
                dp[i&1][j][k]=dp[i&1^1][j][k]+(dp[i&1][j+1][0]-dp[i&1^1][j+1][0])*c[j][k]+(a[i]<=l[j]&&r[j]<=b[i])*dp[i&1^1][j][k+1];
                dp[i&1][j][k]%=mod;
            }
    dp[1][1][0]=(dp[1][1][0]-1)%mod;
    cout << (dp[1][1][0]+mod)%mod;
}

Compilation message

boat.cpp: In function 'int32_t main()':
boat.cpp:27:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for (int i=0;i<v.size()-1;i++){
      |                  ~^~~~~~~~~~~
boat.cpp:44:17: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   44 |             dp[n&1^1][j][k]=(j>id?1:c[j][k]);
      |                ~^~
boat.cpp:52:35: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   52 |                 dp[i&1][j][k]=dp[i&1^1][j][k]+(dp[i&1][j+1][0]-dp[i&1^1][j+1][0])*c[j][k]+(a[i]<=l[j]&&r[j]<=b[i])*dp[i&1^1][j][k+1];
      |                                  ~^~
boat.cpp:52:68: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   52 |                 dp[i&1][j][k]=dp[i&1^1][j][k]+(dp[i&1][j+1][0]-dp[i&1^1][j+1][0])*c[j][k]+(a[i]<=l[j]&&r[j]<=b[i])*dp[i&1^1][j][k+1];
      |                                                                   ~^~
boat.cpp:52:120: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   52 |                 dp[i&1][j][k]=dp[i&1^1][j][k]+(dp[i&1][j+1][0]-dp[i&1^1][j+1][0])*c[j][k]+(a[i]<=l[j]&&r[j]<=b[i])*dp[i&1^1][j][k+1];
      |                                                                                                                       ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 119 ms 6276 KB Output is correct
2 Correct 117 ms 6276 KB Output is correct
3 Correct 118 ms 6272 KB Output is correct
4 Correct 117 ms 6276 KB Output is correct
5 Correct 116 ms 6272 KB Output is correct
6 Correct 99 ms 6272 KB Output is correct
7 Correct 99 ms 6272 KB Output is correct
8 Correct 98 ms 6272 KB Output is correct
9 Correct 104 ms 6280 KB Output is correct
10 Correct 120 ms 6348 KB Output is correct
11 Correct 106 ms 6228 KB Output is correct
12 Correct 132 ms 6276 KB Output is correct
13 Correct 97 ms 6228 KB Output is correct
14 Correct 100 ms 6292 KB Output is correct
15 Correct 99 ms 6276 KB Output is correct
16 Correct 263 ms 11092 KB Output is correct
17 Correct 222 ms 11036 KB Output is correct
18 Correct 238 ms 11092 KB Output is correct
19 Correct 342 ms 11084 KB Output is correct
20 Correct 249 ms 11064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 119 ms 6276 KB Output is correct
2 Correct 117 ms 6276 KB Output is correct
3 Correct 118 ms 6272 KB Output is correct
4 Correct 117 ms 6276 KB Output is correct
5 Correct 116 ms 6272 KB Output is correct
6 Correct 99 ms 6272 KB Output is correct
7 Correct 99 ms 6272 KB Output is correct
8 Correct 98 ms 6272 KB Output is correct
9 Correct 104 ms 6280 KB Output is correct
10 Correct 120 ms 6348 KB Output is correct
11 Correct 106 ms 6228 KB Output is correct
12 Correct 132 ms 6276 KB Output is correct
13 Correct 97 ms 6228 KB Output is correct
14 Correct 100 ms 6292 KB Output is correct
15 Correct 99 ms 6276 KB Output is correct
16 Correct 263 ms 11092 KB Output is correct
17 Correct 222 ms 11036 KB Output is correct
18 Correct 238 ms 11092 KB Output is correct
19 Correct 342 ms 11084 KB Output is correct
20 Correct 249 ms 11064 KB Output is correct
21 Incorrect 322 ms 10324 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 2260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 119 ms 6276 KB Output is correct
2 Correct 117 ms 6276 KB Output is correct
3 Correct 118 ms 6272 KB Output is correct
4 Correct 117 ms 6276 KB Output is correct
5 Correct 116 ms 6272 KB Output is correct
6 Correct 99 ms 6272 KB Output is correct
7 Correct 99 ms 6272 KB Output is correct
8 Correct 98 ms 6272 KB Output is correct
9 Correct 104 ms 6280 KB Output is correct
10 Correct 120 ms 6348 KB Output is correct
11 Correct 106 ms 6228 KB Output is correct
12 Correct 132 ms 6276 KB Output is correct
13 Correct 97 ms 6228 KB Output is correct
14 Correct 100 ms 6292 KB Output is correct
15 Correct 99 ms 6276 KB Output is correct
16 Correct 263 ms 11092 KB Output is correct
17 Correct 222 ms 11036 KB Output is correct
18 Correct 238 ms 11092 KB Output is correct
19 Correct 342 ms 11084 KB Output is correct
20 Correct 249 ms 11064 KB Output is correct
21 Incorrect 322 ms 10324 KB Output isn't correct
22 Halted 0 ms 0 KB -