Submission #56552

# Submission time Handle Problem Language Result Execution time Memory
56552 2018-07-11T16:44:02 Z ruhanhabib39 Pinball (JOI14_pinball) C++17
100 / 100
994 ms 78256 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXM = 1e5;
const int MX = 4 * MAXM + 10;
const long long INF = 1e18;

struct dat {
   long long a, b, c, d;
};

ostream& operator<<(ostream& os, dat d) {
   return os << "{[" << d.a << ", " << d.b << "] " << d.c << " " << d.d << "}";
}

long long N, M;
dat dt[MAXM + 10];
long long mn[3 * MX + 10];
long long pref[MAXM + 10], suff[MAXM + 10];

void compress() {
   set<int> st;
   for(int i = 1; i <= M; i++) {
      st.insert(dt[i].a);
      st.insert(dt[i].b);
      st.insert(dt[i].c);
   }
   map<int,int> mp;
   int ii = 0;
   for(int x : st) mp[x] = ++ii;
   for(int i = 1; i <= M; i++) {
      dt[i].a = mp[dt[i].a];
      dt[i].b = mp[dt[i].b];
      dt[i].c = mp[dt[i].c];
   }
   if(!st.count(1) || !st.count(N)) {
      printf("-1\n");
      exit(0);
   }
   N = ii;
}

void upd(int i, long long x) {
   i--; // 0-based
   i += N;
   for(mn[i] = min(mn[i], x); i > 1; i >>= 1) {
      mn[i >> 1] = min(mn[i], mn[i ^ 1]);
   }
}

long long get(int l, int r) {
   l--; r--; r++; // now [l, r), 0 based
   long long res = INF;
   for(l += N, r += N; l < r; l >>= 1, r >>= 1) {
      if(l & 1) res = min(res, mn[l++]);
      if(r & 1) res = min(res, mn[--r]);
   }
   return res;
}

void reset() {
   fill(mn, mn + N+N+10, INF);
}

int main() {
   scanf("%lld%lld", &M, &N);
   for(int i = 1; i <= M; i++) {
      scanf("%lld%lld%lld%lld", &dt[i].a, &dt[i].b, &dt[i].c, &dt[i].d);
   }
   compress();
   reset();
   fill(pref, pref + M + 1, INF);
   for(int j = 1; j <= M; j++) {
      if(dt[j].a == 1) pref[j] = 0;
      else pref[j] = min(INF, get(dt[j].a, dt[j].b));
      if(pref[j] < INF) upd(dt[j].c, dt[j].d + pref[j]);
   }

   reset();
   fill(suff, suff + M + 1, INF);
   for(int j = 1; j <= M; j++) {
      if(dt[j].b == N) suff[j] = 0;
      else suff[j] = min(INF, get(dt[j].a, dt[j].b));
      if(suff[j] < INF) upd(dt[j].c, dt[j].d + suff[j]);
   }
   long long res = INF;
   for(int i = 1; i <= M; i++) {
      res = min(res, pref[i] + suff[i] + dt[i].d);
   }
   if(res == INF) res = -1;
   printf("%lld\n", res);
}

Compilation message

pinball.cpp: In function 'int main()':
pinball.cpp:66:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld%lld", &M, &N);
    ~~~~~^~~~~~~~~~~~~~~~~~~~
pinball.cpp:68:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%lld%lld%lld%lld", &dt[i].a, &dt[i].b, &dt[i].c, &dt[i].d);
       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 628 KB Output is correct
3 Correct 2 ms 628 KB Output is correct
4 Correct 3 ms 628 KB Output is correct
5 Correct 3 ms 696 KB Output is correct
6 Correct 2 ms 872 KB Output is correct
7 Correct 4 ms 872 KB Output is correct
8 Correct 3 ms 872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 628 KB Output is correct
3 Correct 2 ms 628 KB Output is correct
4 Correct 3 ms 628 KB Output is correct
5 Correct 3 ms 696 KB Output is correct
6 Correct 2 ms 872 KB Output is correct
7 Correct 4 ms 872 KB Output is correct
8 Correct 3 ms 872 KB Output is correct
9 Correct 3 ms 1064 KB Output is correct
10 Correct 3 ms 1064 KB Output is correct
11 Correct 3 ms 1152 KB Output is correct
12 Correct 3 ms 1152 KB Output is correct
13 Correct 4 ms 1172 KB Output is correct
14 Correct 3 ms 1172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 628 KB Output is correct
3 Correct 2 ms 628 KB Output is correct
4 Correct 3 ms 628 KB Output is correct
5 Correct 3 ms 696 KB Output is correct
6 Correct 2 ms 872 KB Output is correct
7 Correct 4 ms 872 KB Output is correct
8 Correct 3 ms 872 KB Output is correct
9 Correct 3 ms 1064 KB Output is correct
10 Correct 3 ms 1064 KB Output is correct
11 Correct 3 ms 1152 KB Output is correct
12 Correct 3 ms 1152 KB Output is correct
13 Correct 4 ms 1172 KB Output is correct
14 Correct 3 ms 1172 KB Output is correct
15 Correct 2 ms 1172 KB Output is correct
16 Correct 3 ms 1172 KB Output is correct
17 Correct 5 ms 1380 KB Output is correct
18 Correct 4 ms 1380 KB Output is correct
19 Correct 6 ms 1476 KB Output is correct
20 Correct 4 ms 1476 KB Output is correct
21 Correct 4 ms 1476 KB Output is correct
22 Correct 5 ms 1700 KB Output is correct
23 Correct 4 ms 1740 KB Output is correct
24 Correct 6 ms 1800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 628 KB Output is correct
3 Correct 2 ms 628 KB Output is correct
4 Correct 3 ms 628 KB Output is correct
5 Correct 3 ms 696 KB Output is correct
6 Correct 2 ms 872 KB Output is correct
7 Correct 4 ms 872 KB Output is correct
8 Correct 3 ms 872 KB Output is correct
9 Correct 3 ms 1064 KB Output is correct
10 Correct 3 ms 1064 KB Output is correct
11 Correct 3 ms 1152 KB Output is correct
12 Correct 3 ms 1152 KB Output is correct
13 Correct 4 ms 1172 KB Output is correct
14 Correct 3 ms 1172 KB Output is correct
15 Correct 2 ms 1172 KB Output is correct
16 Correct 3 ms 1172 KB Output is correct
17 Correct 5 ms 1380 KB Output is correct
18 Correct 4 ms 1380 KB Output is correct
19 Correct 6 ms 1476 KB Output is correct
20 Correct 4 ms 1476 KB Output is correct
21 Correct 4 ms 1476 KB Output is correct
22 Correct 5 ms 1700 KB Output is correct
23 Correct 4 ms 1740 KB Output is correct
24 Correct 6 ms 1800 KB Output is correct
25 Correct 38 ms 4016 KB Output is correct
26 Correct 181 ms 9792 KB Output is correct
27 Correct 471 ms 19608 KB Output is correct
28 Correct 145 ms 19608 KB Output is correct
29 Correct 252 ms 23184 KB Output is correct
30 Correct 236 ms 23184 KB Output is correct
31 Correct 575 ms 41756 KB Output is correct
32 Correct 574 ms 41756 KB Output is correct
33 Correct 61 ms 41756 KB Output is correct
34 Correct 420 ms 43948 KB Output is correct
35 Correct 484 ms 66616 KB Output is correct
36 Correct 994 ms 70508 KB Output is correct
37 Correct 637 ms 74404 KB Output is correct
38 Correct 650 ms 78256 KB Output is correct