Submission #276484

#TimeUsernameProblemLanguageResultExecution timeMemory
276484sjimedCircus (Balkan15_CIRCUS)C++14
0 / 100
4032 ms5620 KiB
#include "circus.h" #include<bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(false); cin.tie(0); #define fi first #define se second #define em emplace #define eb emplace_back #define all(v) (v).begin(), (v).end() #define mp make_pair typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<int,pii> piii; const int inf = 1e9; const ll INF = 1e18; int n, m; int dp[100010]; bool chk[100010]; vector<int> p; priority_queue<piii, vector<piii>, greater<piii>> pQ; int Min[400010]; int Max[400010]; void update(int node, int s, int e, int i, int x) { if(s == e){ Min[node] = min(Min[node], x); Max[node] = max(Max[node], x); return; } int m = s + e >> 1; if(i <= m) update(node*2, s, m, i, x); else update(node*2+1, m+1, e, i, x); Min[node] = min(Min[node*2], Min[node*2+1]); Max[node] = max(Max[node*2], Max[node*2+1]); } int mx(int node, int s, int e, int l, int r) { if(r < s || e < l) return 0; if(l <= s && e <= r) return Max[node]; return max(mx(node*2, s, (s+e)/2, l, r), mx(node*2+1, (s+e)/2+1, e, l, r)); } int mn(int node, int s, int e, int l, int r) { if(r < s || e < l) return 0; if(l <= s && e <= r) return Min[node]; return min(mn(node*2, s, (s+e)/2, l, r), mn(node*2+1, (s+e)/2+1, e, l, r)); } void init(int N, int M, int P[]){ n = N; m = M; for(int i=0; i<n; i++) p.eb(P[i]); p.eb(0); p.eb(m); sort(all(p)); p.erase(unique(all(p)), p.end()); pQ.em(0, mp(p.size()-1, p.size()-1)); while(pQ.size()) { int cost = pQ.top().fi; int x = pQ.top().se.fi; int par = pQ.top().se.se; pQ.pop(); if(x >= par && x+1 < p.size()) pQ.em(p[x+1] - p[par], mp(x+1, par)); else if(x <= par && x-1 >= 0) pQ.em(p[par] - p[x-1], mp(x-1, par)); if(chk[x]) continue; chk[x] = true; dp[x] = cost; int k = lower_bound(all(p), p[x] + cost) - p.begin(); if(k < p.size()) pQ.em(p[k] - p[x], mp(k, x)); k = upper_bound(all(p), p[x] - cost) - p.begin() - 1; if(k >= 0) pQ.em(p[x] - p[k], mp(k, x)); } for(int i=0; i<p.size(); i++) { if(p[i] - dp[i] >= 0) update(1, 0, m, p[i] - dp[i], p[i]); if(p[i] + dp[i] <= m) update(1, 0, m, p[i] + dp[i], p[i]); } } int minLength(int D) { int ret = m - D; ret = min(ret, mx(1, 0, m, D+1, m) - D); ret = min(ret, D + mn(1, 0, m, 0, D-1)); return ret; }

Compilation message (stderr)

circus.cpp: In function 'void update(int, int, int, int, int)':
circus.cpp:35:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |     int m = s + e >> 1;
      |             ~~^~~
circus.cpp: In function 'void init(int, int, int*)':
circus.cpp:77:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |         if(x >= par && x+1 < p.size()) pQ.em(p[x+1] - p[par], mp(x+1, par));
      |                        ~~~~^~~~~~~~~~
circus.cpp:85:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |         if(k < p.size()) pQ.em(p[k] - p[x], mp(k, x));
      |            ~~^~~~~~~~~~
circus.cpp:91:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |     for(int i=0; i<p.size(); i++) {
      |                  ~^~~~~~~~~
grader.cpp: In function 'int main()':
grader.cpp:14:12: warning: unused variable 'max_code' [-Wunused-variable]
   14 |  long long max_code;
      |            ^~~~~~~~
grader.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |  scanf("%d%d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~
grader.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |   scanf("%d", &P[i]);
      |   ~~~~~^~~~~~~~~~~~~
grader.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |  scanf("%d", &Q);
      |  ~~~~~^~~~~~~~~~
grader.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |   scanf("%d", &d);
      |   ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...