Submission #690503

# Submission time Handle Problem Language Result Execution time Memory
690503 2023-01-30T08:50:28 Z vjudge1 Boat (APIO16_boat) C++14
9 / 100
31 ms 24288 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[i]; 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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Runtime error 31 ms 24288 KB Execution killed with signal 11
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 24 ms 24188 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Runtime error 31 ms 24288 KB Execution killed with signal 11
22 Halted 0 ms 0 KB -