Submission #781751

# Submission time Handle Problem Language Result Execution time Memory
781751 2023-07-13T10:34:38 Z RecursiveCo Semiexpress (JOI17_semiexpress) C++14
100 / 100
33 ms 16976 KB
// CF template, version 3.0

#include <bits/stdc++.h>

using namespace std;

#define improvePerformance ios_base::sync_with_stdio(false); cin.tie(0)
#define getTest int t; cin >> t
#define eachTest for (int _var=0;_var<t;_var++)
#define get(name) int (name); cin >> (name)
#define out(o) cout << (o)
#define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
#define sortl(name) sort((name).begin(), (name).end())
#define rev(name) reverse((name).begin(), (name).end())
#define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
#define decision(b) if (b){out("YES");}else{out("NO");}

#define int long long

signed main() {
    improvePerformance;
    //getTest;

    //eachTest {
        get(n);
        get(m);
        get(k);
        get(a);
        get(b);
        get(c);
        get(t);
        getList(m, stops);
        for (int& el: stops) el--;
        vector<int> els;
        int init = 0;
        forto(m - 1, i) {
            vector<int> cur(k - m + 1, -1);
            int s = stops[i];
            int initial = b * s;
            int rightmost = (t - initial) / a + s;
            int loops = min(k - m, stops[i + 1] - stops[i] - 1);
            if (initial > t) {
                forto(loops, j) els.push_back(0);
            } else {
                if (rightmost >= stops[i + 1] - 1) {
                    init += stops[i + 1] - stops[i];
                    forto(loops, j) els.push_back(0);
                } else {
                    init += rightmost - s + 1;
                    int initsum = rightmost - s + 1;
                    int prev = initsum;
                    forto(loops, _j) {
                        int j = _j + 1;
                        // put j extra stations in the i-th subsegment (bounded by express stations)
                        int pos = rightmost + 1;
                        initial = b * s + c * (pos - s);
                        if (initial > t) {
                            for (int l = j; l < loops; l++) els.push_back(0);
                            break;
                        }
                        rightmost = (t - initial) / a + pos;
                        if (rightmost >= stops[i + 1] - 1) {
                            els.push_back(stops[i + 1] - stops[i] - prev);
                            for (int l = j + 1; l < loops; l++) els.push_back(0);
                            break;
                        }
                        els.push_back(rightmost - s + 1 - prev);
                        prev = rightmost - s + 1;
                    }
                }
            }
        }
        if (stops.back() * b <= t) init++;
        init--;
        sortl(els);
        rev(els);
        forto(k - m, i) init += els[i];
        out(init);
    //}
}

Compilation message

semiexpress.cpp: In function 'int main()':
semiexpress.cpp:10:23: warning: unnecessary parentheses in declaration of 'n' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
semiexpress.cpp:25:9: note: in expansion of macro 'get'
   25 |         get(n);
      |         ^~~
semiexpress.cpp:10:23: warning: unnecessary parentheses in declaration of 'm' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
semiexpress.cpp:26:9: note: in expansion of macro 'get'
   26 |         get(m);
      |         ^~~
semiexpress.cpp:10:23: warning: unnecessary parentheses in declaration of 'k' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
semiexpress.cpp:27:9: note: in expansion of macro 'get'
   27 |         get(k);
      |         ^~~
semiexpress.cpp:10:23: warning: unnecessary parentheses in declaration of 'a' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
semiexpress.cpp:28:9: note: in expansion of macro 'get'
   28 |         get(a);
      |         ^~~
semiexpress.cpp:10:23: warning: unnecessary parentheses in declaration of 'b' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
semiexpress.cpp:29:9: note: in expansion of macro 'get'
   29 |         get(b);
      |         ^~~
semiexpress.cpp:10:23: warning: unnecessary parentheses in declaration of 'c' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
semiexpress.cpp:30:9: note: in expansion of macro 'get'
   30 |         get(c);
      |         ^~~
semiexpress.cpp:10:23: warning: unnecessary parentheses in declaration of 't' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
semiexpress.cpp:31:9: note: in expansion of macro 'get'
   31 |         get(t);
      |         ^~~
semiexpress.cpp:12:40: warning: unnecessary parentheses in declaration of 'stops' [-Wparentheses]
   12 | #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
      |                                        ^
semiexpress.cpp:32:9: note: in expansion of macro 'getList'
   32 |         getList(m, stops);
      |         ^~~~~~~
semiexpress.cpp:10:23: warning: unnecessary parentheses in declaration of 'a' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
semiexpress.cpp:12:76: note: in expansion of macro 'get'
   12 | #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
      |                                                                            ^~~
semiexpress.cpp:32:9: note: in expansion of macro 'getList'
   32 |         getList(m, stops);
      |         ^~~~~~~
semiexpress.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
semiexpress.cpp:36:9: note: in expansion of macro 'forto'
   36 |         forto(m - 1, i) {
      |         ^~~~~
semiexpress.cpp:15:35: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
semiexpress.cpp:43:17: note: in expansion of macro 'forto'
   43 |                 forto(loops, j) els.push_back(0);
      |                 ^~~~~
semiexpress.cpp:15:35: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
semiexpress.cpp:47:21: note: in expansion of macro 'forto'
   47 |                     forto(loops, j) els.push_back(0);
      |                     ^~~~~
semiexpress.cpp:15:35: warning: unnecessary parentheses in declaration of '_j' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
semiexpress.cpp:52:21: note: in expansion of macro 'forto'
   52 |                     forto(loops, _j) {
      |                     ^~~~~
semiexpress.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
semiexpress.cpp:77:9: note: in expansion of macro 'forto'
   77 |         forto(k - m, i) init += els[i];
      |         ^~~~~
# 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 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 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 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 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 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 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 20 ms 8680 KB Output is correct
20 Correct 33 ms 16896 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 5 ms 2508 KB Output is correct
23 Correct 31 ms 16976 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 9 ms 4500 KB Output is correct
30 Correct 5 ms 2508 KB Output is correct