# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
569177 |
2022-05-26T22:44:18 Z |
mat_v |
Pinball (JOI14_pinball) |
C++14 |
|
1 ms |
340 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int n,duz;
int br = 0;
map<int,int> poj;
ll INF=1e8;
struct prep{
int l,r,x;
ll w;
}niz[100005];
ll dp[100005];
ll sejv[100005];
ll seg[4*300005];
void update(int node, int l, int r, int poz, ll val){
if(l == r){
seg[node] = val;
return;
}
int mid = (l + r) / 2;
if(poz <= mid)update(node*2,l,mid,poz,val);
else update(node*2+1,mid+1,r,poz,val);
seg[node] = min(seg[node * 2 + 1], seg[node * 2]);
}
ll kveri(int node, int l, int r, int levo, int desno){
if(levo > r || l > desno)return INF;
if(l >= levo && r <= desno)return seg[node];
int mid = (l + r) / 2;
return min(kveri(node*2,l,mid,levo,desno), kveri(node*2+1,mid+1,r,levo,desno));
}
void radi(){
update(1,1,duz,1,0);
ff(i,2,duz)update(1,1,duz,i,INF);
ff(i,1,n){
dp[i] = kveri(1,1,duz,niz[i].l,niz[i].r) + niz[i].w;
update(1,1,duz,niz[i].x,min(kveri(1,1,duz,niz[i].l,niz[i].r)+niz[i].w,kveri(1,1,duz,niz[i].x,niz[i].x)));
}
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
INF *= INF;
cin >> n >> duz;
vector<int> svi;
ff(i,1,n){
cin >> niz[i].l >> niz[i].r >> niz[i].x >> niz[i].w;
svi.pb(niz[i].l);
svi.pb(niz[i].r);
svi.pb(niz[i].x);
}
svi.pb(duz);
sort(svi.begin(),svi.end());
int lst = 0;
int br = 0;
for(auto c:svi){
if(c == lst)continue;
br++;
poj[c] = br;
lst = c;
}
duz = poj[duz];
ff(i,1,n)niz[i] = {poj[niz[i].l], poj[niz[i].r], poj[niz[i].x], niz[i].w};
radi();
ff(i,1,n)sejv[i] = dp[i];
ff(i,1,n){
niz[i].l = duz-niz[i].l+1;
niz[i].r = duz-niz[i].r+1;
niz[i].x = duz-niz[i].x+1;
swap(niz[i].r,niz[i].l);
}
radi();
ll ans = INF;
ff(i,1,n){
ans = min(ans, dp[i] + sejv[i] - niz[i].w);
}
if(ans < INF/2)cout << ans << "\n";
else cout << -1 << "\n";
return 0;
}
Compilation message
pinball.cpp: In function 'void radi()':
pinball.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
| ^
pinball.cpp:58:5: note: in expansion of macro 'ff'
58 | ff(i,2,duz)update(1,1,duz,i,INF);
| ^~
pinball.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
| ^
pinball.cpp:59:5: note: in expansion of macro 'ff'
59 | ff(i,1,n){
| ^~
pinball.cpp: In function 'int main()':
pinball.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
| ^
pinball.cpp:73:5: note: in expansion of macro 'ff'
73 | ff(i,1,n){
| ^~
pinball.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
| ^
pinball.cpp:90:5: note: in expansion of macro 'ff'
90 | ff(i,1,n)niz[i] = {poj[niz[i].l], poj[niz[i].r], poj[niz[i].x], niz[i].w};
| ^~
pinball.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
| ^
pinball.cpp:92:5: note: in expansion of macro 'ff'
92 | ff(i,1,n)sejv[i] = dp[i];
| ^~
pinball.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
| ^
pinball.cpp:93:5: note: in expansion of macro 'ff'
93 | ff(i,1,n){
| ^~
pinball.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
| ^
pinball.cpp:101:5: note: in expansion of macro 'ff'
101 | ff(i,1,n){
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |