제출 #172374

#제출 시각아이디문제언어결과실행 시간메모리
172374rama_pangBoat (APIO16_boat)C++14
9 / 100
255 ms2424 KiB
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int power(int n, int x) { if (x == 0) { return 1; } int res = power(n, x / 2); res = (1ll * res * res) % MOD; if (x & 1) { res = (1ll * res * n) % MOD; } return res; } int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int N; cin >> N; vector<int> A(N + 1); vector<int> B(N + 1); vector<int> X; vector<int> L; vector<int> inv(N + 1); // inc[i] = inverse of integer i for (int i = 1; i <= N; i++) { cin >> A[i] >> B[i]; X.emplace_back(A[i]); X.emplace_back(B[i] + 1); inv[i] = power(i, MOD - 2); // Fermatt's Little Theorem } sort(begin(X), end(X)); X.resize(unique(begin(X), end(X)) - begin(X)); for (int i = 1; i <= N; i++) { A[i] = upper_bound(begin(X), end(X), A[i]) - begin(X); B[i] = upper_bound(begin(X), end(X), B[i]) - begin(X); } L.resize(X.size()); for (int i = 1; i < X.size(); i++) { L[i] = X[i] - X[i - 1]; } vector<vector<int>> DP(N + 1, vector<int>(X.size(), 0)); for (int i = 0; i < X.size(); i++) { DP[0][i] = 1; } for (int i = 1; i <= N; i++) { for (int j = A[i]; j <= B[i]; j++) { for (int k = i, cnt = 0, choose = 1; k > 0; k--) { if (A[k] <= j && j <= B[k]) { cnt++; choose = (((1ll * choose * (L[j] - cnt + 1)) % MOD) * inv[cnt]) % MOD; DP[i][j] = (1ll * DP[i][j] + (1ll * choose * DP[k - 1][j - 1]) % MOD) % MOD; } } } DP[i][0] = 1; for (int j = 1; j < X.size(); j++) { DP[i][j] = (1ll * DP[i][j] + DP[i - 1][j] + DP[i][j - 1] - DP[i - 1][j - 1] + MOD) % MOD; } } cout << (DP[N][X.size() - 1] - 1 + MOD) % MOD << "\n"; return 0; }

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

boat.cpp: In function 'int main()':
boat.cpp:46:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1; i < X.size(); i++) {
                     ~~^~~~~~~~~~
boat.cpp:52:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < X.size(); i++) {
                     ~~^~~~~~~~~~
boat.cpp:67:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 1; j < X.size(); j++) {
                         ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...