Submission #920969

# Submission time Handle Problem Language Result Execution time Memory
920969 2024-02-03T08:29:24 Z danikoynov Roller Coaster Railroad (IOI16_railroad) C++14
0 / 100
117 ms 18784 KB
#include "railroad.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll inf = 1e18;

const int maxn = 2e5 + 10;

ll dp[17][(1 << 17)];

pair < int, int > sec[maxn];

int sp[maxn];

long long plan_roller_coaster(std::vector<int> s, std::vector<int> t)
{
    int n = (int) s.size();
    if (false)///if (n <= 17)
    {
        for (int i = 0; i < n; i ++)
            for (int mask = 0; mask < (1 << n); mask ++)
                dp[i][mask] = inf;

        for (int i = 0; i < n; i ++)
            dp[i][(1 << i)] = 0;

        for (ll mask = 0; mask < (1 << n); mask ++)
        {
            for (int i = 0; i < n; i ++)
            {
                if ((mask & (1 << i)) == 0)
                    continue;
                //cout << "state " << i << " " << mask << " " << dp[i][mask] << endl;
                for (int j = 0; j < n; j ++)
                {
                    if ((mask & (1 << j)) != 0)
                        continue;

                    int new_mask = (mask | (1 << j));
                    //cout << "transition " << j << " " << max(0, t[i] - s[j]) << " " << t[i] << " " << s[j] << endl;
                    dp[j][new_mask] = min(dp[j][new_mask], dp[i][mask] + (ll)max(0, t[i] - s[j]));
                }
            }
        }
        ll ans = inf;
        for (int i = 0; i < n; i ++)
            ans = min(ans, dp[i][(1 << n) - 1]);
        return ans;
    }
    else
    {
        for (int i = 0; i < n; i ++)
        {
            sec[i + 1] = {t[i], s[i]};
        }

        sort(sec + 1, sec + n + 1);

        vector < pair < int, int > > ord;
        for (int i = 1; i <= n; i ++)
        {
            ord.push_back({sec[i].second, i});
        }

        sort(ord.begin(), ord.end());
        set < int > act;
        for (int i = 1; i <= n; i ++)
            act.insert(i);

        for (int i = 1; i <= n; i ++)
            sp[i] = i;

        bool start = false;
        for (pair < int, int > cur : ord)
        {
            int lf = 1, rf = n;
            while(lf <= rf)
            {
                int mf = (lf + rf) / 2;
                if (sec[mf].first <= cur.first)
                    lf = mf + 1;
                else
                    rf = mf - 1;
            }

            set < int > :: iterator it = act.lower_bound(lf);
            if (it == act.begin())
            {
                if (start == true)
                    return 1;
                start = true;
            }
            else
            {
                it = prev(it);
                if (*it == sp[cur.second])
                {
                    if (it == act.begin())
                    {
                        if (start == true)
                            return 1;
                        start = true;
                    }
                    else
                    {
                        it = prev(it);
                    }
                }
                sp[*it] = sp[cur.second];
                act.erase(it);
            }
        }
        return 0;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB n = 2
2 Correct 1 ms 2396 KB n = 2
3 Correct 1 ms 2396 KB n = 2
4 Correct 1 ms 2396 KB n = 2
5 Correct 1 ms 2396 KB n = 2
6 Incorrect 1 ms 2396 KB answer is not correct: 1 instead of 523688153
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB n = 2
2 Correct 1 ms 2396 KB n = 2
3 Correct 1 ms 2396 KB n = 2
4 Correct 1 ms 2396 KB n = 2
5 Correct 1 ms 2396 KB n = 2
6 Incorrect 1 ms 2396 KB answer is not correct: 1 instead of 523688153
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 117 ms 18628 KB n = 199999
2 Correct 112 ms 18628 KB n = 199991
3 Correct 94 ms 18628 KB n = 199993
4 Correct 88 ms 13248 KB n = 152076
5 Correct 52 ms 9160 KB n = 93249
6 Incorrect 89 ms 18784 KB answer is not correct: 1 instead of 0
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB n = 2
2 Correct 1 ms 2396 KB n = 2
3 Correct 1 ms 2396 KB n = 2
4 Correct 1 ms 2396 KB n = 2
5 Correct 1 ms 2396 KB n = 2
6 Incorrect 1 ms 2396 KB answer is not correct: 1 instead of 523688153
7 Halted 0 ms 0 KB -