Submission #241217

# Submission time Handle Problem Language Result Execution time Memory
241217 2020-06-23T10:43:01 Z osaaateiasavtnl Long Distance Coach (JOI17_coach) C++17
71 / 100
2000 ms 32120 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC

const int N = 2007;
int l[N][N];

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int x, n, m, w, t;
    cin >> x >> n >> m >> w >> t;
 
    //first - d, second - c
 
    vector <int> s(n);
    for (int i = 0; i < n; ++i) 
        cin >> s[i];
    sort(all(s));
    s.app(x);
 
    vector <ii> a(m);
    for (int i = 0; i < m; ++i) 
        cin >> a[i].f >> a[i].s;
 
    sort(all(a));
    reverse(all(a));
    a.insert(a.begin(), mp(0, 0));
 
    auto getcnt = [&](int x, int d) {
        //d + k * t <= x
        //k * t <= x - d
 
        if (x < d)
            return 0ll;
 
        int k = (x-d)/t;
        return k + 1;
    };  
    auto get = [&](int i, int j) {
        int di = a[i].f;
        int dj = a[j%a.size()].f;
        if (l[i][j] != -1) {
            int p = l[i][j];
            if (getcnt(s[p], dj) > getcnt(s[p], di) || (getcnt(s[p], dj) == getcnt(s[p], di) && dj > di)) {
                return a[j].s + (getcnt(s[p], dj)-1)*w;
            }
        }
        return -1ll;
    };
    auto save = [&](int i) {
        if (i == a.size())
            return 0ll;
        int cnt = x/t+(a[i].f<=(x%t));
        return cnt * w;
    };
 
    vector <int> last(s.size()), mem(a.size(), s.size());
    for (int i = 0; i < s.size(); ++i) {
        last[i] = 0;
        for (int j = 1; j < a.size(); ++j) {
            if (getcnt(s[i], a[j].f) > getcnt(s[i], a[last[i]].f) || (getcnt(s[i], a[j].f) == getcnt(s[i], a[last[i]].f) && a[j].f > a[last[i]].f)) {
                last[i] = j;
            }   
        }   
        mem[last[i]] = min(mem[last[i]], i);
    }

    for (int i = 0; i < N; ++i) 
        for (int j = 0; j < N; ++j)
            l[i][j] = -1;

    for (int i = 0; i < a.size(); ++i) {
        for (int j = i + 1; j < a.size(); ++j) {

            int lf = l[i][j-1];
            if (mem[j] != -1) {
                if (lf == -1)
                    lf = mem[j];
                else
                    lf = min(lf, mem[j]);
            }
            l[i][j] = lf;
            
        }           
    }   

    vector <int> dp(a.size()+1, -1);
    dp[0] = (x/t+1)*w;
    for (int i = 0; i < a.size(); ++i) {
        int cur = 0;
        for (int j = i + 1; j <= a.size(); ++j) {
            if (j > i + 1) {
                int add = get(i, j - 1);
                if (add == -1)
                    break;
                cur += add;
            }   
            if (dp[j] == -1) {
                dp[j] = dp[i]+cur+save(j);
            }   
            else {
                dp[j] = min(dp[j], dp[i]+cur+save(j));
            }
        }   
    }   
    cout << (int)dp[a.size()] << endl;
}

Compilation message

coach.cpp: In lambda function:
coach.cpp:65:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (i == a.size())
             ~~^~~~~~~~~~~
coach.cpp: In function 'int main()':
coach.cpp:72:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < s.size(); ++i) {
                     ~~^~~~~~~~~~
coach.cpp:74:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 1; j < a.size(); ++j) {
                         ~~^~~~~~~~~~
coach.cpp:86:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a.size(); ++i) {
                     ~~^~~~~~~~~~
coach.cpp:87:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = i + 1; j < a.size(); ++j) {
                             ~~^~~~~~~~~~
coach.cpp:103:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a.size(); ++i) {
                     ~~^~~~~~~~~~
coach.cpp:105:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = i + 1; j <= a.size(); ++j) {
                             ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 23 ms 31864 KB Output is correct
2 Correct 19 ms 31872 KB Output is correct
3 Correct 20 ms 31872 KB Output is correct
4 Correct 20 ms 31872 KB Output is correct
5 Correct 19 ms 31872 KB Output is correct
6 Correct 19 ms 31872 KB Output is correct
7 Correct 19 ms 31872 KB Output is correct
8 Correct 19 ms 31872 KB Output is correct
9 Correct 21 ms 32000 KB Output is correct
10 Correct 20 ms 31872 KB Output is correct
11 Correct 19 ms 31872 KB Output is correct
12 Correct 19 ms 31872 KB Output is correct
13 Correct 19 ms 31872 KB Output is correct
14 Correct 19 ms 31872 KB Output is correct
15 Correct 20 ms 31872 KB Output is correct
16 Correct 19 ms 31872 KB Output is correct
17 Correct 19 ms 31872 KB Output is correct
18 Correct 19 ms 31872 KB Output is correct
19 Correct 19 ms 31872 KB Output is correct
20 Correct 19 ms 31872 KB Output is correct
21 Correct 19 ms 31872 KB Output is correct
22 Correct 19 ms 31872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 31864 KB Output is correct
2 Correct 19 ms 31872 KB Output is correct
3 Correct 20 ms 31872 KB Output is correct
4 Correct 20 ms 31872 KB Output is correct
5 Correct 19 ms 31872 KB Output is correct
6 Correct 19 ms 31872 KB Output is correct
7 Correct 19 ms 31872 KB Output is correct
8 Correct 19 ms 31872 KB Output is correct
9 Correct 21 ms 32000 KB Output is correct
10 Correct 20 ms 31872 KB Output is correct
11 Correct 19 ms 31872 KB Output is correct
12 Correct 19 ms 31872 KB Output is correct
13 Correct 19 ms 31872 KB Output is correct
14 Correct 19 ms 31872 KB Output is correct
15 Correct 20 ms 31872 KB Output is correct
16 Correct 19 ms 31872 KB Output is correct
17 Correct 19 ms 31872 KB Output is correct
18 Correct 19 ms 31872 KB Output is correct
19 Correct 19 ms 31872 KB Output is correct
20 Correct 19 ms 31872 KB Output is correct
21 Correct 19 ms 31872 KB Output is correct
22 Correct 19 ms 31872 KB Output is correct
23 Correct 19 ms 31872 KB Output is correct
24 Correct 20 ms 31872 KB Output is correct
25 Correct 20 ms 31872 KB Output is correct
26 Correct 20 ms 31872 KB Output is correct
27 Correct 20 ms 31872 KB Output is correct
28 Correct 20 ms 31872 KB Output is correct
29 Correct 20 ms 31872 KB Output is correct
30 Correct 21 ms 31872 KB Output is correct
31 Correct 20 ms 31872 KB Output is correct
32 Correct 21 ms 31872 KB Output is correct
33 Correct 20 ms 31872 KB Output is correct
34 Correct 20 ms 31872 KB Output is correct
35 Correct 21 ms 31872 KB Output is correct
36 Correct 20 ms 31872 KB Output is correct
37 Correct 20 ms 31872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 31864 KB Output is correct
2 Correct 19 ms 31872 KB Output is correct
3 Correct 20 ms 31872 KB Output is correct
4 Correct 20 ms 31872 KB Output is correct
5 Correct 19 ms 31872 KB Output is correct
6 Correct 19 ms 31872 KB Output is correct
7 Correct 19 ms 31872 KB Output is correct
8 Correct 19 ms 31872 KB Output is correct
9 Correct 21 ms 32000 KB Output is correct
10 Correct 20 ms 31872 KB Output is correct
11 Correct 19 ms 31872 KB Output is correct
12 Correct 19 ms 31872 KB Output is correct
13 Correct 19 ms 31872 KB Output is correct
14 Correct 19 ms 31872 KB Output is correct
15 Correct 20 ms 31872 KB Output is correct
16 Correct 19 ms 31872 KB Output is correct
17 Correct 19 ms 31872 KB Output is correct
18 Correct 19 ms 31872 KB Output is correct
19 Correct 19 ms 31872 KB Output is correct
20 Correct 19 ms 31872 KB Output is correct
21 Correct 19 ms 31872 KB Output is correct
22 Correct 19 ms 31872 KB Output is correct
23 Correct 19 ms 31872 KB Output is correct
24 Correct 20 ms 31872 KB Output is correct
25 Correct 20 ms 31872 KB Output is correct
26 Correct 20 ms 31872 KB Output is correct
27 Correct 20 ms 31872 KB Output is correct
28 Correct 20 ms 31872 KB Output is correct
29 Correct 20 ms 31872 KB Output is correct
30 Correct 21 ms 31872 KB Output is correct
31 Correct 20 ms 31872 KB Output is correct
32 Correct 21 ms 31872 KB Output is correct
33 Correct 20 ms 31872 KB Output is correct
34 Correct 20 ms 31872 KB Output is correct
35 Correct 21 ms 31872 KB Output is correct
36 Correct 20 ms 31872 KB Output is correct
37 Correct 20 ms 31872 KB Output is correct
38 Correct 112 ms 31980 KB Output is correct
39 Correct 133 ms 31992 KB Output is correct
40 Correct 179 ms 31992 KB Output is correct
41 Correct 116 ms 31992 KB Output is correct
42 Correct 116 ms 32120 KB Output is correct
43 Correct 99 ms 31992 KB Output is correct
44 Correct 150 ms 31996 KB Output is correct
45 Correct 115 ms 31992 KB Output is correct
46 Correct 140 ms 31996 KB Output is correct
47 Correct 141 ms 32028 KB Output is correct
48 Correct 137 ms 31992 KB Output is correct
49 Correct 127 ms 31992 KB Output is correct
50 Correct 111 ms 31992 KB Output is correct
51 Correct 116 ms 31992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 31864 KB Output is correct
2 Correct 19 ms 31872 KB Output is correct
3 Correct 20 ms 31872 KB Output is correct
4 Correct 20 ms 31872 KB Output is correct
5 Correct 19 ms 31872 KB Output is correct
6 Correct 19 ms 31872 KB Output is correct
7 Correct 19 ms 31872 KB Output is correct
8 Correct 19 ms 31872 KB Output is correct
9 Correct 21 ms 32000 KB Output is correct
10 Correct 20 ms 31872 KB Output is correct
11 Correct 19 ms 31872 KB Output is correct
12 Correct 19 ms 31872 KB Output is correct
13 Correct 19 ms 31872 KB Output is correct
14 Correct 19 ms 31872 KB Output is correct
15 Correct 20 ms 31872 KB Output is correct
16 Correct 19 ms 31872 KB Output is correct
17 Correct 19 ms 31872 KB Output is correct
18 Correct 19 ms 31872 KB Output is correct
19 Correct 19 ms 31872 KB Output is correct
20 Correct 19 ms 31872 KB Output is correct
21 Correct 19 ms 31872 KB Output is correct
22 Correct 19 ms 31872 KB Output is correct
23 Correct 19 ms 31872 KB Output is correct
24 Correct 20 ms 31872 KB Output is correct
25 Correct 20 ms 31872 KB Output is correct
26 Correct 20 ms 31872 KB Output is correct
27 Correct 20 ms 31872 KB Output is correct
28 Correct 20 ms 31872 KB Output is correct
29 Correct 20 ms 31872 KB Output is correct
30 Correct 21 ms 31872 KB Output is correct
31 Correct 20 ms 31872 KB Output is correct
32 Correct 21 ms 31872 KB Output is correct
33 Correct 20 ms 31872 KB Output is correct
34 Correct 20 ms 31872 KB Output is correct
35 Correct 21 ms 31872 KB Output is correct
36 Correct 20 ms 31872 KB Output is correct
37 Correct 20 ms 31872 KB Output is correct
38 Correct 112 ms 31980 KB Output is correct
39 Correct 133 ms 31992 KB Output is correct
40 Correct 179 ms 31992 KB Output is correct
41 Correct 116 ms 31992 KB Output is correct
42 Correct 116 ms 32120 KB Output is correct
43 Correct 99 ms 31992 KB Output is correct
44 Correct 150 ms 31996 KB Output is correct
45 Correct 115 ms 31992 KB Output is correct
46 Correct 140 ms 31996 KB Output is correct
47 Correct 141 ms 32028 KB Output is correct
48 Correct 137 ms 31992 KB Output is correct
49 Correct 127 ms 31992 KB Output is correct
50 Correct 111 ms 31992 KB Output is correct
51 Correct 116 ms 31992 KB Output is correct
52 Execution timed out 2091 ms 13912 KB Time limit exceeded
53 Halted 0 ms 0 KB -