# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
690035 | 2023-01-30T03:34:03 Z | vjudge1 | Boat (APIO16_boat) | C++14 | 3 ms | 340 KB |
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define all(a) a.begin(), a.end() #define pb push_back typedef long long ll; typedef pair<int, int> ii; const int N = 500 + 5; const int mod = 1e9 + 7; void print(){cerr << '\n';} template<typename T1, typename ...T2> void print(const T1 &a, const T2 &...b){cerr << a << ' ', print(b...);} bool ok1 = 1; int n, a[N], b[N]; void fix(int &a) { if(a >= mod) a -= mod; if(a < 0) a += mod; } void sub1() { int f[n + 1]{1}, res = 0; for(int i = 1; i <= n; i++) { for(int j = 0; j < i; j++) if(a[j] < a[i]) f[i] += f[j], fix(f[i]); res += f[i], fix(res); } cout << res; } bool now = 1, lst = 0; int dp[2][1000005], sum[1000005], pre[1000005]; void sub2() { int res = 0; dp[0][0] = 1; sum[0] = 1; for(int i = 1; i <= n; i++) { pre[0] = sum[0]; for(int j = 1; j <= b[i]; j++) pre[j] = pre[j - 1] + sum[j], fix(pre[j]); for(int j = a[i]; j <= b[i]; j++) { dp[now][j] += pre[j - 1]; fix(dp[now][j]); res += dp[now][j]; fix(res); } for(int j = a[i]; j <= b[j]; j++) sum[j] += dp[now][j], fix(sum[j]); swap(now, lst); } cout << res; } void solve() { cin >> n; for(int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; if(a[i] != b[i]) ok1 = 0; } if(ok1) sub1(); else sub2(); } signed main() { #ifndef ONLINE_JUDGE freopen("boat.inp", "r", stdin); freopen("boat.out", "w", stdout); cin.tie(0) -> sync_with_stdio(0); #endif int t = 1; // cin >> t; while(t--) solve(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |