답안 #48487

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48487 2018-05-14T12:34:02 Z octopuses Boat (APIO16_boat) C++17
100 / 100
1517 ms 17512 KB
#include <bits/stdc++.h>

#define ll long long
#define fr first
#define sc second
#define M (ll)(1e9 + 7)

using namespace std;
const int N = 1020;

ll pw(ll x, ll y)
{
  if(y == 0)
    return 1ll;
  ll ans = pw(x, y / 2);
  ans = (ans * ans) % M;
  if(y % 2 == 1)
    ans = (x * ans) % M;
  return ans;
}

ll F[N];

inline ll cnt(ll n, ll k)
{
  if(n - k < k)
    k = n - k;
  ll s = 1ll;
  for(int i = n; i > n - k; -- i)
    s = (s * i) % M;
  s = (s * F[k]) % M;
  return s;
}

int n, tot;
int x[N], y[N], a[N];
ll C[N][N], A[N][N], S[N];
map < int, int > mp;
vector < int > ar;


int main()
{
  F[0] = 1;
  for(int i = 1; i < N; ++ i)
    F[i] = (F[i - 1] * i) % M;
  for(int i = 0; i < N; ++ i)
    F[i] = pw(F[i], M - 2);
  scanf("%d", &n);
  for(int i = 0; i < n; ++ i)
  {
    scanf("%d %d", &x[i], &y[i]);
    mp[x[i]] = 1;
    mp[y[i] + 1] = 1;
  }
  tot = 0;
  for(map < int, int >::iterator it = mp.begin(); it != mp.end(); ++ it)
  {
    ar.push_back(it -> fr);
    it -> sc = tot ++;
  }
  for(int i = 1; i < tot; ++ i)
    a[i] = ar[i] - ar[i - 1];
  for(int i = 0; i < n; ++ i)
  {
    y[i] = mp[y[i] + 1] + 1;
    x[i] = mp[x[i]] + 1;
  }
  for(int i = 1; i < tot; ++ i)
    for(int j = 1; j <= n; ++ j)
      C[i][j] = cnt(a[i] + j - 1, j);
  S[0] = 1; ll s;
  for(int k = 0; k < n; ++ k)
  {
    s = 0;
    for(int i = 0; i < x[k]; ++ i)
      s = (s + S[i]) % M;
    for(int i = x[k]; i < y[k]; ++ i)
    {
      A[i][0] = s;
      s = (s + S[i]) % M;
      S[i] = 0;
      for(int j = n; j > 0; -- j)
      {
        A[i][j] = A[i][j - 1];
        S[i] = ((A[i][j] * C[i][j]) % M + S[i]) % M;
      }
    }
  }
  s = 0;
  for(int i = 1; i < tot; ++ i)
    s = (s + S[i]) % M;
  cout << s << endl;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ~~~~~^~~~~~~~~~
boat.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &x[i], &y[i]);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 421 ms 12372 KB Output is correct
2 Correct 402 ms 12428 KB Output is correct
3 Correct 398 ms 12444 KB Output is correct
4 Correct 400 ms 12444 KB Output is correct
5 Correct 398 ms 12612 KB Output is correct
6 Correct 399 ms 12636 KB Output is correct
7 Correct 398 ms 12664 KB Output is correct
8 Correct 404 ms 12664 KB Output is correct
9 Correct 399 ms 12664 KB Output is correct
10 Correct 402 ms 12664 KB Output is correct
11 Correct 403 ms 12664 KB Output is correct
12 Correct 403 ms 12664 KB Output is correct
13 Correct 402 ms 12760 KB Output is correct
14 Correct 409 ms 12760 KB Output is correct
15 Correct 403 ms 12776 KB Output is correct
16 Correct 74 ms 12776 KB Output is correct
17 Correct 79 ms 12776 KB Output is correct
18 Correct 76 ms 12776 KB Output is correct
19 Correct 79 ms 12776 KB Output is correct
20 Correct 77 ms 12776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 421 ms 12372 KB Output is correct
2 Correct 402 ms 12428 KB Output is correct
3 Correct 398 ms 12444 KB Output is correct
4 Correct 400 ms 12444 KB Output is correct
5 Correct 398 ms 12612 KB Output is correct
6 Correct 399 ms 12636 KB Output is correct
7 Correct 398 ms 12664 KB Output is correct
8 Correct 404 ms 12664 KB Output is correct
9 Correct 399 ms 12664 KB Output is correct
10 Correct 402 ms 12664 KB Output is correct
11 Correct 403 ms 12664 KB Output is correct
12 Correct 403 ms 12664 KB Output is correct
13 Correct 402 ms 12760 KB Output is correct
14 Correct 409 ms 12760 KB Output is correct
15 Correct 403 ms 12776 KB Output is correct
16 Correct 74 ms 12776 KB Output is correct
17 Correct 79 ms 12776 KB Output is correct
18 Correct 76 ms 12776 KB Output is correct
19 Correct 79 ms 12776 KB Output is correct
20 Correct 77 ms 12776 KB Output is correct
21 Correct 486 ms 15304 KB Output is correct
22 Correct 480 ms 15568 KB Output is correct
23 Correct 476 ms 15568 KB Output is correct
24 Correct 498 ms 15568 KB Output is correct
25 Correct 487 ms 15568 KB Output is correct
26 Correct 629 ms 15568 KB Output is correct
27 Correct 663 ms 15568 KB Output is correct
28 Correct 658 ms 15568 KB Output is correct
29 Correct 640 ms 15568 KB Output is correct
30 Correct 382 ms 16784 KB Output is correct
31 Correct 382 ms 16800 KB Output is correct
32 Correct 388 ms 16836 KB Output is correct
33 Correct 387 ms 16856 KB Output is correct
34 Correct 387 ms 16856 KB Output is correct
35 Correct 379 ms 16868 KB Output is correct
36 Correct 382 ms 16940 KB Output is correct
37 Correct 390 ms 16940 KB Output is correct
38 Correct 391 ms 16940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 16940 KB Output is correct
2 Correct 13 ms 16940 KB Output is correct
3 Correct 18 ms 16940 KB Output is correct
4 Correct 14 ms 16940 KB Output is correct
5 Correct 14 ms 16940 KB Output is correct
6 Correct 15 ms 16940 KB Output is correct
7 Correct 15 ms 16940 KB Output is correct
8 Correct 16 ms 16940 KB Output is correct
9 Correct 15 ms 16940 KB Output is correct
10 Correct 17 ms 16940 KB Output is correct
11 Correct 14 ms 16940 KB Output is correct
12 Correct 13 ms 16940 KB Output is correct
13 Correct 13 ms 16940 KB Output is correct
14 Correct 13 ms 16940 KB Output is correct
15 Correct 14 ms 16940 KB Output is correct
16 Correct 8 ms 16940 KB Output is correct
17 Correct 8 ms 16940 KB Output is correct
18 Correct 8 ms 16940 KB Output is correct
19 Correct 8 ms 16940 KB Output is correct
20 Correct 8 ms 16940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 421 ms 12372 KB Output is correct
2 Correct 402 ms 12428 KB Output is correct
3 Correct 398 ms 12444 KB Output is correct
4 Correct 400 ms 12444 KB Output is correct
5 Correct 398 ms 12612 KB Output is correct
6 Correct 399 ms 12636 KB Output is correct
7 Correct 398 ms 12664 KB Output is correct
8 Correct 404 ms 12664 KB Output is correct
9 Correct 399 ms 12664 KB Output is correct
10 Correct 402 ms 12664 KB Output is correct
11 Correct 403 ms 12664 KB Output is correct
12 Correct 403 ms 12664 KB Output is correct
13 Correct 402 ms 12760 KB Output is correct
14 Correct 409 ms 12760 KB Output is correct
15 Correct 403 ms 12776 KB Output is correct
16 Correct 74 ms 12776 KB Output is correct
17 Correct 79 ms 12776 KB Output is correct
18 Correct 76 ms 12776 KB Output is correct
19 Correct 79 ms 12776 KB Output is correct
20 Correct 77 ms 12776 KB Output is correct
21 Correct 486 ms 15304 KB Output is correct
22 Correct 480 ms 15568 KB Output is correct
23 Correct 476 ms 15568 KB Output is correct
24 Correct 498 ms 15568 KB Output is correct
25 Correct 487 ms 15568 KB Output is correct
26 Correct 629 ms 15568 KB Output is correct
27 Correct 663 ms 15568 KB Output is correct
28 Correct 658 ms 15568 KB Output is correct
29 Correct 640 ms 15568 KB Output is correct
30 Correct 382 ms 16784 KB Output is correct
31 Correct 382 ms 16800 KB Output is correct
32 Correct 388 ms 16836 KB Output is correct
33 Correct 387 ms 16856 KB Output is correct
34 Correct 387 ms 16856 KB Output is correct
35 Correct 379 ms 16868 KB Output is correct
36 Correct 382 ms 16940 KB Output is correct
37 Correct 390 ms 16940 KB Output is correct
38 Correct 391 ms 16940 KB Output is correct
39 Correct 13 ms 16940 KB Output is correct
40 Correct 13 ms 16940 KB Output is correct
41 Correct 18 ms 16940 KB Output is correct
42 Correct 14 ms 16940 KB Output is correct
43 Correct 14 ms 16940 KB Output is correct
44 Correct 15 ms 16940 KB Output is correct
45 Correct 15 ms 16940 KB Output is correct
46 Correct 16 ms 16940 KB Output is correct
47 Correct 15 ms 16940 KB Output is correct
48 Correct 17 ms 16940 KB Output is correct
49 Correct 14 ms 16940 KB Output is correct
50 Correct 13 ms 16940 KB Output is correct
51 Correct 13 ms 16940 KB Output is correct
52 Correct 13 ms 16940 KB Output is correct
53 Correct 14 ms 16940 KB Output is correct
54 Correct 8 ms 16940 KB Output is correct
55 Correct 8 ms 16940 KB Output is correct
56 Correct 8 ms 16940 KB Output is correct
57 Correct 8 ms 16940 KB Output is correct
58 Correct 8 ms 16940 KB Output is correct
59 Correct 1272 ms 17256 KB Output is correct
60 Correct 1259 ms 17280 KB Output is correct
61 Correct 1232 ms 17344 KB Output is correct
62 Correct 1277 ms 17344 KB Output is correct
63 Correct 1285 ms 17344 KB Output is correct
64 Correct 1490 ms 17344 KB Output is correct
65 Correct 1489 ms 17344 KB Output is correct
66 Correct 1510 ms 17444 KB Output is correct
67 Correct 1500 ms 17444 KB Output is correct
68 Correct 1517 ms 17444 KB Output is correct
69 Correct 1248 ms 17444 KB Output is correct
70 Correct 1309 ms 17512 KB Output is correct
71 Correct 1263 ms 17512 KB Output is correct
72 Correct 1268 ms 17512 KB Output is correct
73 Correct 1272 ms 17512 KB Output is correct
74 Correct 175 ms 17512 KB Output is correct
75 Correct 178 ms 17512 KB Output is correct
76 Correct 180 ms 17512 KB Output is correct
77 Correct 175 ms 17512 KB Output is correct
78 Correct 175 ms 17512 KB Output is correct