답안 #699559

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
699559 2023-02-17T11:55:03 Z Abrar_Al_Samit Boat (APIO16_boat) C++17
36 / 100
2000 ms 3744 KB
#include<bits/stdc++.h>
using namespace std;

const int nax = 503;
const int mod = 1e9 + 7;

vector<int>ind[nax*2];
int a[nax], b[nax];
int n, m;
int dp[nax*2][nax];
vector<int>imp;

int add(int a, int b) {
  a += b;
  if(a>=mod) a -= mod;
  return a;
}
int mul(int a, int b) {
  return (a * 1LL * b) % mod;
}
int quickpow(int a, int b) {
  int ret = 1;
  while(b) {
    if(b&1) ret = mul(ret, a);
    a = mul(a, a);
    b >>= 1;
  }
  return ret;
}

map<pair<int,int>,int>table;
int C(int n, int r) {
  int& ret = table[{n, r}];
  if(ret==0) {
    ret = 1;
    for(int i=n-r+1; i<=n; ++i) {
      ret = mul(ret, i);
    }
    for(int i=1; i<=r; ++i) {
      ret = mul(ret, quickpow(i, mod-2));
    }
  }
  return ret;
}
int solve(int i, int prv) {
  if(i==m-1) return prv>0;
  int &ret = dp[i][prv];
  if(ret!=-1) return ret;
  ret = 0;

  ret = solve(i+1, prv);
  int len = imp[i+1]-imp[i];

  for(int mx=0, cur_op=0; mx<ind[i].size(); ++mx) {
    if(ind[i][mx]<=prv) continue;

    int cur = solve(i+1, ind[i][mx]);
    for(int take=0; take<=min(cur_op, len-1); ++take) {
      ret = add(ret, mul(cur, mul(C(cur_op, take), C(len, take+1))));
    }
    cur_op++;
  }
  return ret;
}
void PlayGround() {
  cin>>n;
  set<int>pts;
  for(int i=1; i<=n; ++i) {
    cin>>a[i]>>b[i];
    pts.insert(a[i]);
    pts.insert(b[i]+1);
  }

  for(int x : pts) {
    imp.push_back(x);
  } 
  m = imp.size();
  for(int i=0; i<m; ++i) {
    for(int j=1; j<=n; ++j) {
      if(imp[i]>=a[j] && imp[i]<=b[j]) {
        ind[i].push_back(j);
      }
    }
  }

  memset(dp, -1, sizeof dp);
  cout<<solve(0, 0)<<'\n';


  // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  PlayGround();
  return 0;
}

Compilation message

boat.cpp: In function 'int solve(int, int)':
boat.cpp:54:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for(int mx=0, cur_op=0; mx<ind[i].size(); ++mx) {
      |                           ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2516 KB Output is correct
2 Correct 8 ms 2520 KB Output is correct
3 Correct 9 ms 2516 KB Output is correct
4 Correct 8 ms 2516 KB Output is correct
5 Correct 9 ms 2532 KB Output is correct
6 Correct 8 ms 2516 KB Output is correct
7 Correct 8 ms 2476 KB Output is correct
8 Correct 8 ms 2516 KB Output is correct
9 Correct 8 ms 2516 KB Output is correct
10 Correct 7 ms 2524 KB Output is correct
11 Correct 8 ms 2516 KB Output is correct
12 Correct 8 ms 2516 KB Output is correct
13 Correct 7 ms 2516 KB Output is correct
14 Correct 7 ms 2516 KB Output is correct
15 Correct 8 ms 2412 KB Output is correct
16 Correct 4 ms 2260 KB Output is correct
17 Correct 4 ms 2260 KB Output is correct
18 Correct 4 ms 2260 KB Output is correct
19 Correct 5 ms 2376 KB Output is correct
20 Correct 5 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2516 KB Output is correct
2 Correct 8 ms 2520 KB Output is correct
3 Correct 9 ms 2516 KB Output is correct
4 Correct 8 ms 2516 KB Output is correct
5 Correct 9 ms 2532 KB Output is correct
6 Correct 8 ms 2516 KB Output is correct
7 Correct 8 ms 2476 KB Output is correct
8 Correct 8 ms 2516 KB Output is correct
9 Correct 8 ms 2516 KB Output is correct
10 Correct 7 ms 2524 KB Output is correct
11 Correct 8 ms 2516 KB Output is correct
12 Correct 8 ms 2516 KB Output is correct
13 Correct 7 ms 2516 KB Output is correct
14 Correct 7 ms 2516 KB Output is correct
15 Correct 8 ms 2412 KB Output is correct
16 Correct 4 ms 2260 KB Output is correct
17 Correct 4 ms 2260 KB Output is correct
18 Correct 4 ms 2260 KB Output is correct
19 Correct 5 ms 2376 KB Output is correct
20 Correct 5 ms 2260 KB Output is correct
21 Execution timed out 2085 ms 3744 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 368 ms 2772 KB Output is correct
2 Correct 203 ms 2764 KB Output is correct
3 Correct 320 ms 2840 KB Output is correct
4 Correct 345 ms 2856 KB Output is correct
5 Correct 397 ms 2900 KB Output is correct
6 Correct 1257 ms 3320 KB Output is correct
7 Correct 1237 ms 3396 KB Output is correct
8 Correct 1216 ms 3196 KB Output is correct
9 Correct 1273 ms 3400 KB Output is correct
10 Correct 1347 ms 3260 KB Output is correct
11 Correct 473 ms 2908 KB Output is correct
12 Correct 310 ms 2720 KB Output is correct
13 Correct 364 ms 2812 KB Output is correct
14 Correct 360 ms 2760 KB Output is correct
15 Correct 461 ms 2964 KB Output is correct
16 Correct 168 ms 2604 KB Output is correct
17 Correct 122 ms 2528 KB Output is correct
18 Correct 163 ms 2612 KB Output is correct
19 Correct 120 ms 2580 KB Output is correct
20 Correct 181 ms 2604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2516 KB Output is correct
2 Correct 8 ms 2520 KB Output is correct
3 Correct 9 ms 2516 KB Output is correct
4 Correct 8 ms 2516 KB Output is correct
5 Correct 9 ms 2532 KB Output is correct
6 Correct 8 ms 2516 KB Output is correct
7 Correct 8 ms 2476 KB Output is correct
8 Correct 8 ms 2516 KB Output is correct
9 Correct 8 ms 2516 KB Output is correct
10 Correct 7 ms 2524 KB Output is correct
11 Correct 8 ms 2516 KB Output is correct
12 Correct 8 ms 2516 KB Output is correct
13 Correct 7 ms 2516 KB Output is correct
14 Correct 7 ms 2516 KB Output is correct
15 Correct 8 ms 2412 KB Output is correct
16 Correct 4 ms 2260 KB Output is correct
17 Correct 4 ms 2260 KB Output is correct
18 Correct 4 ms 2260 KB Output is correct
19 Correct 5 ms 2376 KB Output is correct
20 Correct 5 ms 2260 KB Output is correct
21 Execution timed out 2085 ms 3744 KB Time limit exceeded
22 Halted 0 ms 0 KB -