제출 #1118532

#제출 시각아이디문제언어결과실행 시간메모리
1118532lmToT27Boat (APIO16_boat)C++17
9 / 100
394 ms8344 KiB
#include <bits/stdc++.h> #define all(dataStructure) dataStructure.begin(),dataStructure.end() using namespace std; typedef long long ll; const int MAX = 5e2 + 3; const ll MOD[] = {1000000007, 998244353}; const ll mod = 1e9 + 7; int n, l[MAX], r[MAX]; ll dp[MAX][2 * MAX], C[MAX][2 * MAX]; template <typename dataType> inline void compress(vector <dataType> &x) { sort(all(x)); x.erase(unique(all(x)), x.end()); } ll pw(ll a, ll b) { ll res = 1; for (; b > 0; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } void Solve() { vector <int> val; cin >> n; for (int i = 1; i <= n; i++) { cin >> l[i] >> r[i]; l[i]--; val.push_back(l[i]); val.push_back(r[i]); } compress(val); for (int i = 1; i < (int)val.size(); i++) { int sz = val[i] - val[i - 1]; C[0][i] = sz; for (int j = 1; j <= n; j++) { C[j][i] = C[j - 1][i] * (sz + j - 1) % mod * pw(j, mod - 2) % mod; } dp[0][i] = 1; } dp[0][0] = 1; for (int i = 1; i <= n; i++) { dp[i][0] = 1; for (int j = 1; j < (int)val.size(); j++) { dp[i][j] = dp[i][j - 1]; int cnt = 0; for (int k = i; k >= 1; k--) { if (l[k] < val[j] && val[j] <= r[k]) { cnt++; dp[i][j] += dp[k - 1][j - 1] * C[cnt][j] % mod; dp[i][j] %= mod; } } } } cout << dp[n][(int)val.size() - 1] - 1; } int32_t main() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0); #define TASK "" if (fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); freopen(TASK".OUT", "w", stdout); } if (fopen("TASK.INP", "r")) { freopen("TASK.INP", "r", stdin); freopen("TASK.OUT", "w", stdout); } /* int TEST = 1; cin >> TEST; while (TEST--) */ Solve(); cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n"; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

boat.cpp: In function 'int32_t main()':
boat.cpp:77:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |                 freopen(TASK".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
boat.cpp:78:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |                 freopen(TASK".OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
boat.cpp:82:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |                 freopen("TASK.INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
boat.cpp:83:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |                 freopen("TASK.OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...