Submission #673251

# Submission time Handle Problem Language Result Execution time Memory
673251 2022-12-20T03:27:13 Z abysmal Sightseeing in Kyoto (JOI22_kyoto) C++14
40 / 100
342 ms 1048576 KB
#include<iostream>
#include<stdio.h>
#include<stdint.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<set>
#include<map>
#include<queue>
#include<stack>

using namespace std;

const int64_t INF = 1e18;
const int64_t mINF = 1e9;
const int64_t MOD = 998244353;
const int nbit = 11;
const int ndig = 10;
const int nchar = 26;
const int D = 4;
int dr[D] = {0, 1, 0, -1};
int dc[D] = {1, 0, -1, 0};

struct Monsta
{
    int64_t h;
    int64_t p;

    Monsta(int64_t h_, int64_t p_) : h(h_), p(p_) {}

    bool operator < (const Monsta& o)
    {
        return p < o.p;
    }
};

struct Solution
{
    Solution() {}

    void solve()
    {
        int nr;
        int nc;
        cin >> nr >> nc;

        vector<pair<int64_t, int> > a;
        vector<pair<int64_t, int> > b;
        for(int i = 0; i < nr; i++)
        {
            int64_t val;
            cin >> val;

            int k = a.size();
            while(k > 1)
            {
                int64_t last = a[k - 1].first;
                int64_t prev = a[k - 2].first;

                if(prev <= last && last >= val) a.pop_back();
                else break;
                k--;
            }

            a.push_back(make_pair(val, i));
        }

        for(int i = 0; i < nc; i++)
        {
            int64_t val;
            cin >> val;

            int k = b.size();
            while(k > 1)
            {
                int64_t last = b[k - 1].first;
                int64_t prev = b[k - 2].first;

                if(prev <= last && last >= val) b.pop_back();
                else break;
                k--;
            }

            b.push_back(make_pair(val, i));
        }

        nr = a.size(); nc = b.size();
        vector<vector<int64_t> > dp(nr, vector<int64_t>(nc, INF));
        dp[0][0] = 0;
        for(int i = 0; i < nr; i++)
        {
            for(int j = 0; j < nc; j++)
            {
                if(j < nc - 1)
                {
                    int64_t len =  b[j + 1].second - b[j].second;
                    dp[i][j + 1] = min(dp[i][j + 1], a[i].first * len + dp[i][j]);
                }
                if(i < nr - 1)
                {
                    int64_t len = a[i + 1].second - a[i].second;
                    dp[i + 1][j] = min(dp[i + 1][j], b[j].first * len + dp[i][j]);
                }
            }
        }

        cout << dp[nr - 1][nc - 1] << "\n";
    }

    int modsub(int t1, int t2)
    {
        int res = t1 - t2;
        if(res < 0) res += MOD;

        return res;
    }

    int modadd(int t1, int t2)
    {
        int res = t1 + t2;
        if(res >= MOD) res -= MOD;

        return res;
    }

    int modmul(int t1, int t2)
    {
        int64_t res = 1LL * t1 * t2;
        return (res % MOD);
    }

    bool BIT(int& mask, int& j)
    {
        return (mask & MASK(j));
    }

    int MASK(int j)
    {
        return (1 << j);
    }
};

void __startup()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
}

int main()
{
    __startup();
    int t = 1;
//    cin >> t;

    for(int i = 1; i <= t; i++)
    {
        Solution().solve();
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 10 ms 8136 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 10 ms 8148 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 3 ms 2772 KB Output is correct
4 Correct 6 ms 852 KB Output is correct
5 Correct 8 ms 2604 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 20 ms 1056 KB Output is correct
8 Correct 14 ms 1076 KB Output is correct
9 Correct 16 ms 1984 KB Output is correct
10 Correct 15 ms 1856 KB Output is correct
11 Correct 52 ms 32488 KB Output is correct
12 Correct 15 ms 2244 KB Output is correct
13 Correct 15 ms 2220 KB Output is correct
14 Correct 48 ms 31984 KB Output is correct
15 Correct 13 ms 1208 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 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 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 324 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 316 KB Output is correct
26 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 1 ms 212 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 10 ms 8136 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 10 ms 8148 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 3 ms 2772 KB Output is correct
32 Correct 6 ms 852 KB Output is correct
33 Correct 8 ms 2604 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 20 ms 1056 KB Output is correct
36 Correct 14 ms 1076 KB Output is correct
37 Correct 16 ms 1984 KB Output is correct
38 Correct 15 ms 1856 KB Output is correct
39 Correct 52 ms 32488 KB Output is correct
40 Correct 15 ms 2244 KB Output is correct
41 Correct 15 ms 2220 KB Output is correct
42 Correct 48 ms 31984 KB Output is correct
43 Correct 13 ms 1208 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 0 ms 324 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 316 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 9 ms 1160 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 332 KB Output is correct
58 Correct 4 ms 724 KB Output is correct
59 Correct 23 ms 2216 KB Output is correct
60 Correct 23 ms 2216 KB Output is correct
61 Correct 26 ms 3504 KB Output is correct
62 Correct 25 ms 3648 KB Output is correct
63 Runtime error 342 ms 1048576 KB Execution killed with signal 9
64 Halted 0 ms 0 KB -