답안 #253253

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
253253 2020-07-27T14:32:11 Z davooddkareshki Boat (APIO16_boat) C++17
58 / 100
2000 ms 12024 KB
#include<bits/stdc++.h>

using namespace std; 

typedef long long ll;
typedef long double ld;

#define F first 
#define S second 
#define pii pair<int,int>
#define mpr make_pair

const int maxn = 1010;
const ll inf = 1e18+10;
const int mod = 1e9+7;
const int N = 2e7+10;

int n;
int dp[maxn][maxn], sum[maxn][maxn], C[maxn][maxn], C2[maxn][maxn], a[maxn], b[maxn], fac[maxn], repo[maxn];
vector<int> ve;

int pw(int a, int b)
{
   if(b == 0) return 1;
   int x = pw(a,b/2); x = (x * 1ll * x) % mod;
   if(b&1) x = (x * 1ll * a) % mod;
   return x;
}

signed main()
{
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

   scanf("%d", &n);
   fac[0] = 1; repo[0] = 1;
   for(int i = 1; i <= n; i++) 
   {
      fac[i] = (fac[i-1] * 1ll * i) % mod;
      repo[i] = pw(fac[i],mod-2);
      
      scanf("%d%d", &a[i], &b[i]);
      ve.push_back(a[i]);
      ve.push_back(b[i]);
   }
   ve.push_back(0);
   sort(ve.begin(), ve.end());
   ve.resize(unique(ve.begin(), ve.end()) - ve.begin());
   int k = ve.size();

   for(int j = 0; j < k; j++)
      for(int x = 0; x <= n+1; x++)
      {
         int T;
         if(j == 0) T = 1;
         else T = ve[j] - ve[j-1];

         int up = 1, dow = 1;
         for(int y = 1; y <= min(x,T); y++)
         {
            up = (up * 1ll * (T-y+1)) % mod;   
            dow = (repo[y-1] * 1ll * repo[x-y]) % mod; 
            dow = (dow * 1ll * repo[y]) % mod;
            (C[j][x] += (((fac[x-1] * 1ll * up) % mod) * 1ll * dow) % mod) %= mod;
         }

         up = 1; dow = 1; T--;
         for(int y = 0; y <= min(x,T); y++)
         {
            if(y) up = (up * 1ll * (T-y+1)) % mod;   
            dow = (repo[y] * 1ll * repo[x-y]) % mod; 
            dow = (dow * 1ll * repo[y]) % mod;
            (C2[j][x] += (((fac[x] * 1ll * up) % mod) * 1ll * dow) % mod) %= mod;
         }
      }

   int ANS = 0;
   for(int i = 0; i <= n; i++)
      for(int j = 0; j < k; j++)
      {
         if(i == 0)
         {
            sum[i][j] = 1;
            dp[i][0] = 1;
            continue;
         }

         if(j == 0)
         {
            dp[i][j] = 1;
            sum[i][j] = 1;
         }
         else 
         {
            int L = ve[j-1]+1, R = ve[j];
            bool X = 0; int nm = 0;
            for(int x = i-1; x >= 0; x--)
            {
               int l = max(L,a[x+1]), r = min(R,b[x+1]);

               nm++;
               if(l > r && x == i-1) break;
               if(l > r) nm--;
               if(l == r) 
               {
                  if(x == i-1) X = 1;
                  nm--;  
               }

               int val = (sum[x][j-1]-1); if(!x) val = 1;
               if(!X)
                  (dp[i][j] += (val * 1ll * C[j][nm]) % mod) %= mod;
               else 
                  (dp[i][j] += ((val * 1ll * C2[j][nm]) % mod)) %= mod;
            }

            sum[i][j] = (sum[i][j-1] + dp[i][j]) % mod;
            (ANS += dp[i][j]) %= mod;
         }
         //cout<< i <<" "<< j <<" "<< dp[i][j] <<"\n";   
      }
   
   printf("%d", ANS);
}



/*
3
1 2  
5 10 
100 100

3
1 2
2 3
3 4
*/

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:34:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &n);
    ~~~~~^~~~~~~~~~
boat.cpp:41:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d%d", &a[i], &b[i]);
       ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1638 ms 8244 KB Output is correct
2 Correct 1648 ms 8312 KB Output is correct
3 Correct 1537 ms 8396 KB Output is correct
4 Correct 1496 ms 8496 KB Output is correct
5 Correct 1496 ms 8696 KB Output is correct
6 Correct 1505 ms 8436 KB Output is correct
7 Correct 1498 ms 8568 KB Output is correct
8 Correct 1480 ms 8452 KB Output is correct
9 Correct 1505 ms 8564 KB Output is correct
10 Correct 1449 ms 8544 KB Output is correct
11 Correct 1466 ms 8392 KB Output is correct
12 Correct 1494 ms 8448 KB Output is correct
13 Correct 1482 ms 8440 KB Output is correct
14 Correct 1529 ms 8372 KB Output is correct
15 Correct 1473 ms 8460 KB Output is correct
16 Correct 270 ms 5008 KB Output is correct
17 Correct 300 ms 5112 KB Output is correct
18 Correct 281 ms 5172 KB Output is correct
19 Correct 294 ms 5112 KB Output is correct
20 Correct 274 ms 5112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1638 ms 8244 KB Output is correct
2 Correct 1648 ms 8312 KB Output is correct
3 Correct 1537 ms 8396 KB Output is correct
4 Correct 1496 ms 8496 KB Output is correct
5 Correct 1496 ms 8696 KB Output is correct
6 Correct 1505 ms 8436 KB Output is correct
7 Correct 1498 ms 8568 KB Output is correct
8 Correct 1480 ms 8452 KB Output is correct
9 Correct 1505 ms 8564 KB Output is correct
10 Correct 1449 ms 8544 KB Output is correct
11 Correct 1466 ms 8392 KB Output is correct
12 Correct 1494 ms 8448 KB Output is correct
13 Correct 1482 ms 8440 KB Output is correct
14 Correct 1529 ms 8372 KB Output is correct
15 Correct 1473 ms 8460 KB Output is correct
16 Correct 270 ms 5008 KB Output is correct
17 Correct 300 ms 5112 KB Output is correct
18 Correct 281 ms 5172 KB Output is correct
19 Correct 294 ms 5112 KB Output is correct
20 Correct 274 ms 5112 KB Output is correct
21 Correct 405 ms 11768 KB Output is correct
22 Correct 402 ms 11712 KB Output is correct
23 Correct 380 ms 11512 KB Output is correct
24 Correct 386 ms 11640 KB Output is correct
25 Correct 371 ms 11384 KB Output is correct
26 Correct 417 ms 11384 KB Output is correct
27 Correct 432 ms 11384 KB Output is correct
28 Correct 412 ms 11260 KB Output is correct
29 Correct 418 ms 11256 KB Output is correct
30 Correct 1429 ms 12024 KB Output is correct
31 Correct 1431 ms 11900 KB Output is correct
32 Correct 1502 ms 11768 KB Output is correct
33 Correct 1468 ms 11892 KB Output is correct
34 Correct 1465 ms 11948 KB Output is correct
35 Correct 1395 ms 8440 KB Output is correct
36 Correct 1445 ms 8452 KB Output is correct
37 Correct 1421 ms 8428 KB Output is correct
38 Correct 1419 ms 8400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 2808 KB Output is correct
2 Correct 29 ms 2808 KB Output is correct
3 Correct 30 ms 2808 KB Output is correct
4 Correct 28 ms 2808 KB Output is correct
5 Correct 30 ms 2808 KB Output is correct
6 Correct 30 ms 2812 KB Output is correct
7 Correct 29 ms 2808 KB Output is correct
8 Correct 29 ms 2816 KB Output is correct
9 Correct 30 ms 2808 KB Output is correct
10 Correct 30 ms 2816 KB Output is correct
11 Correct 28 ms 2808 KB Output is correct
12 Correct 28 ms 2728 KB Output is correct
13 Correct 30 ms 2808 KB Output is correct
14 Correct 30 ms 2808 KB Output is correct
15 Correct 31 ms 2808 KB Output is correct
16 Correct 13 ms 1920 KB Output is correct
17 Correct 13 ms 1792 KB Output is correct
18 Correct 14 ms 1920 KB Output is correct
19 Correct 14 ms 1792 KB Output is correct
20 Correct 16 ms 1920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1638 ms 8244 KB Output is correct
2 Correct 1648 ms 8312 KB Output is correct
3 Correct 1537 ms 8396 KB Output is correct
4 Correct 1496 ms 8496 KB Output is correct
5 Correct 1496 ms 8696 KB Output is correct
6 Correct 1505 ms 8436 KB Output is correct
7 Correct 1498 ms 8568 KB Output is correct
8 Correct 1480 ms 8452 KB Output is correct
9 Correct 1505 ms 8564 KB Output is correct
10 Correct 1449 ms 8544 KB Output is correct
11 Correct 1466 ms 8392 KB Output is correct
12 Correct 1494 ms 8448 KB Output is correct
13 Correct 1482 ms 8440 KB Output is correct
14 Correct 1529 ms 8372 KB Output is correct
15 Correct 1473 ms 8460 KB Output is correct
16 Correct 270 ms 5008 KB Output is correct
17 Correct 300 ms 5112 KB Output is correct
18 Correct 281 ms 5172 KB Output is correct
19 Correct 294 ms 5112 KB Output is correct
20 Correct 274 ms 5112 KB Output is correct
21 Correct 405 ms 11768 KB Output is correct
22 Correct 402 ms 11712 KB Output is correct
23 Correct 380 ms 11512 KB Output is correct
24 Correct 386 ms 11640 KB Output is correct
25 Correct 371 ms 11384 KB Output is correct
26 Correct 417 ms 11384 KB Output is correct
27 Correct 432 ms 11384 KB Output is correct
28 Correct 412 ms 11260 KB Output is correct
29 Correct 418 ms 11256 KB Output is correct
30 Correct 1429 ms 12024 KB Output is correct
31 Correct 1431 ms 11900 KB Output is correct
32 Correct 1502 ms 11768 KB Output is correct
33 Correct 1468 ms 11892 KB Output is correct
34 Correct 1465 ms 11948 KB Output is correct
35 Correct 1395 ms 8440 KB Output is correct
36 Correct 1445 ms 8452 KB Output is correct
37 Correct 1421 ms 8428 KB Output is correct
38 Correct 1419 ms 8400 KB Output is correct
39 Correct 29 ms 2808 KB Output is correct
40 Correct 29 ms 2808 KB Output is correct
41 Correct 30 ms 2808 KB Output is correct
42 Correct 28 ms 2808 KB Output is correct
43 Correct 30 ms 2808 KB Output is correct
44 Correct 30 ms 2812 KB Output is correct
45 Correct 29 ms 2808 KB Output is correct
46 Correct 29 ms 2816 KB Output is correct
47 Correct 30 ms 2808 KB Output is correct
48 Correct 30 ms 2816 KB Output is correct
49 Correct 28 ms 2808 KB Output is correct
50 Correct 28 ms 2728 KB Output is correct
51 Correct 30 ms 2808 KB Output is correct
52 Correct 30 ms 2808 KB Output is correct
53 Correct 31 ms 2808 KB Output is correct
54 Correct 13 ms 1920 KB Output is correct
55 Correct 13 ms 1792 KB Output is correct
56 Correct 14 ms 1920 KB Output is correct
57 Correct 14 ms 1792 KB Output is correct
58 Correct 16 ms 1920 KB Output is correct
59 Execution timed out 2071 ms 5904 KB Time limit exceeded
60 Halted 0 ms 0 KB -