이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define M 100005
#define MAX 1e18
typedef long long ll;
using namespace std;
ll m,n,L,R,ans=MAX;
ll a[M],b[M];
ll c[M],d[M];
unordered_map<ll,bool>vis[2];
unordered_map<ll,ll>mn[2];
void update(bool type,ll up,ll id=1,ll l=1,ll r=n){
if(r<L || R<l) return;
if(L<=l && r<=R){
if(vis[type][id]){
mn[type][id]=min(mn[type][id],up);
}
else mn[type][id]=up;
vis[type][id]=1;
return;
}
ll m=l+r>>1;
update(type,up,id*2,l,m);
update(type,up,id*2+1,m+1,r);
if(!vis[type][id*2+1]){
mn[type][id]=mn[type][id*2];
vis[type][id]=1;
return;
}
if(!vis[type][id*2]){
mn[type][id]=mn[type][id*2+1];
vis[type][id]=1;
return;
}
mn[type][id]=min(mn[type][id*2],mn[type][id*2+1]);
vis[type][id]=1;
}
ll query(bool type,ll id=1,ll l=1,ll r=n){
if(r<L | R<l) return MAX;
if(L<=l && r<=R){
if(vis[type][id]) return mn[type][id];
else return MAX;
}
ll m=l+r>>1;
return min(query(type,id*2,l,m),query(type,id*2+1,m+1,r));
}
int main(){
cin >> m >> n;
for(int i=1;i<=m;i++){
cin >> a[i] >> b[i];
cin >> c[i] >> d[i];
}
L=R=1;
update(0,0);
L=R=n;
update(1,0);
for(int i=1;i<=m;i++){
L=a[i],R=b[i];
ll cost1=query(0);
ll cost2=query(1);
if(cost1!=MAX && cost2!=MAX){
ans=min(ans,cost1+cost2+d[i]);
}
L=R=c[i];
if(cost1!=MAX){
update(0,cost1+d[i]);
}
if(cost2!=MAX){
update(1,cost2+d[i]);
}
}
if(ans==MAX) cout << -1;
else cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
pinball.cpp: In function 'void update(bool, ll, ll, ll, ll)':
pinball.cpp:27:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
27 | ll m=l+r>>1;
| ~^~
pinball.cpp: In function 'll query(bool, ll, ll, ll)':
pinball.cpp:45:6: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
45 | if(r<L | R<l) return MAX;
| ~^~
pinball.cpp:50:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
50 | ll m=l+r>>1;
| ~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |