답안 #258179

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258179 2020-08-05T13:42:59 Z Mercenary Long Distance Coach (JOI17_coach) C++14
100 / 100
177 ms 16492 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <pair<ll,int>,null_type,less<pair<ll,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 2e5 + 5;
const int logn = log2(maxn) + 1;

struct point{
    ll a , b;
    point(ll a = 0 , ll b = 0):a(a),b(b){};
    bool operator < (const point other)const{
        if(a == other.a)return b < other.b;
        return a < other.a;
    }
    point operator + (const point other){
        return point(a + other.a , b + other.b);
    }
    point operator - (const point other){
        return point(a - other.a , b - other.b);
    }
    ll operator * (const point other){
        //turn right.
        return a * other.b - b * other.a;
    }
    ll valat(ll x){
        return a * x + b;
    }
};
int ccw(point a , point b , point c){
    return (a - b) * (c - b) >= 0;
}
void add(vector<point> & a , point b){
    while(a.size() >= 2 && ccw(b,a.back(),a[a.size() - 2]))a.pop_back();
    a.pb(b);
}
vector<point> s;
ll query(ll k){
    ll res = -2e18;
    int l = 0 , r = (int)s.size() - 1;
    while(l <= r){
        int mid = l + r >> 1;
        res = max(res , s[mid].valat(k));
        if(mid + 1 < s.size() && s[mid].valat(k) <= s[mid + 1].valat(k))l = mid + 1;
        else r = mid - 1;
    }
    res = max(res , s[l].valat(k));
    return res;
}
ll X , T , ST[maxn];
int m , n;
int W;
ll tmp[maxn];
pair<ll,int> a[maxn];
ll sum[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> X >> n >> m >> W >> T;
    for(int i = 1 ; i <= n ; ++i)cin >> ST[i];ST[++n] = X;
    for(int i = 1 ; i <= m ; ++i)cin >> a[i].first >> a[i].second;
    sort(a + 1 , a + m + 1);
    sort(ST + 1 , ST + n + 1 , greater<ll>());
    for(int i = 1 ; i <= m ; ++i)sum[i] = sum[i - 1] + a[i].second;
    for(int i = 1 ; i <= n ; ++i){
        tmp[lower_bound(a + 1 , a + m + 1 , mp(ST[i] % T , 0)) - a - 1] = ST[i];
    }
    add(s,point(0,0));
    ll res = 0;
    for(int i = 1 ; i <= m ; ++i){
        res += ((X - a[i].first) / T + 1) * W;
        if(tmp[i]){
            res = min(res , -query(tmp[i] / T * W) + tmp[i] / T * i * W + sum[i]);
        }
        add(s , point(i , sum[i] - res));
    }
    cout << res + (X / T + 1) * W;
}

Compilation message

coach.cpp: In function 'll query(ll)':
coach.cpp:52:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid = l + r >> 1;
                   ~~^~~
coach.cpp:54:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(mid + 1 < s.size() && s[mid].valat(k) <= s[mid + 1].valat(k))l = mid + 1;
            ~~~~~~~~^~~~~~~~~~
coach.cpp: In function 'int main()':
coach.cpp:76:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for(int i = 1 ; i <= n ; ++i)cin >> ST[i];ST[++n] = X;
     ^~~
coach.cpp:76:47: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     for(int i = 1 ; i <= n ; ++i)cin >> ST[i];ST[++n] = X;
                                               ^~
coach.cpp:72:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.cpp:73:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 0 ms 384 KB Output is correct
38 Correct 2 ms 512 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 2 ms 512 KB Output is correct
44 Correct 2 ms 512 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 1 ms 512 KB Output is correct
47 Correct 2 ms 512 KB Output is correct
48 Correct 2 ms 512 KB Output is correct
49 Correct 1 ms 512 KB Output is correct
50 Correct 1 ms 512 KB Output is correct
51 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 0 ms 384 KB Output is correct
38 Correct 2 ms 512 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 2 ms 512 KB Output is correct
44 Correct 2 ms 512 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 1 ms 512 KB Output is correct
47 Correct 2 ms 512 KB Output is correct
48 Correct 2 ms 512 KB Output is correct
49 Correct 1 ms 512 KB Output is correct
50 Correct 1 ms 512 KB Output is correct
51 Correct 2 ms 512 KB Output is correct
52 Correct 156 ms 13724 KB Output is correct
53 Correct 150 ms 13944 KB Output is correct
54 Correct 126 ms 13048 KB Output is correct
55 Correct 152 ms 13208 KB Output is correct
56 Correct 140 ms 13560 KB Output is correct
57 Correct 141 ms 13304 KB Output is correct
58 Correct 137 ms 13816 KB Output is correct
59 Correct 131 ms 13304 KB Output is correct
60 Correct 142 ms 13048 KB Output is correct
61 Correct 142 ms 13220 KB Output is correct
62 Correct 132 ms 13304 KB Output is correct
63 Correct 98 ms 16492 KB Output is correct
64 Correct 118 ms 12408 KB Output is correct
65 Correct 156 ms 13944 KB Output is correct
66 Correct 172 ms 13856 KB Output is correct
67 Correct 151 ms 13944 KB Output is correct
68 Correct 150 ms 13944 KB Output is correct
69 Correct 162 ms 13816 KB Output is correct
70 Correct 173 ms 13688 KB Output is correct
71 Correct 157 ms 13688 KB Output is correct
72 Correct 158 ms 13688 KB Output is correct
73 Correct 163 ms 13832 KB Output is correct
74 Correct 174 ms 13812 KB Output is correct
75 Correct 172 ms 13808 KB Output is correct
76 Correct 159 ms 13944 KB Output is correct
77 Correct 136 ms 13560 KB Output is correct
78 Correct 141 ms 13944 KB Output is correct
79 Correct 167 ms 13340 KB Output is correct
80 Correct 177 ms 13432 KB Output is correct