제출 #136647

#제출 시각아이디문제언어결과실행 시간메모리
136647liwiPinball (JOI14_pinball)C++11
100 / 100
939 ms39252 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; #define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0) char _; #define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end()) #define all(a) a.begin(),a.end() #define println printf("\n"); #define readln(x) getline(cin,x); #define pb push_back #define endl "\n" #define INT_INF 0x3f3f3f3f #define LL_INF 0x3f3f3f3f3f3f3f3f #define MOD 1000000007 #define mp make_pair #define fastio cin.tie(0); cin.sync_with_stdio(0); #define MAXN 100005 typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef unordered_map<int,int> umii; typedef pair<int,int> pii; typedef pair<double,double> pdd; typedef pair<ll,ll> pll; typedef pair<int,pii> triple; typedef int8_t byte; mt19937 g1(time(0)); int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);} ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);} ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);} ll lcm(ll a, ll b){return a*b/gcd(a,b);} ll fpow(ll b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;} ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;} struct node{ int l,r; ll min; }; int num_rows,num_cols; ll dp[MAXN],res[MAXN],ans=LLONG_MAX/10; pair<pii,pii> segs[MAXN]; node seg[12*MAXN]; vector<int> pos; map<int,int> rev; void build(int l, int r, int rt){ seg[rt].l = l, seg[rt].r = r, seg[rt].min = LLONG_MAX/10; if(l == r) return; int mid = (l+r)/2; build(l,mid,rt<<1); build(mid+1,r,rt<<1|1); } void update(int pos, int rt, ll val){ if(seg[rt].l == seg[rt].r){ seg[rt].min = min(seg[rt].min,val); return; } int mid = (seg[rt].l+seg[rt].r)/2; if(pos <= mid) update(pos,rt<<1,val); else update(pos,rt<<1|1,val); seg[rt].min = min(seg[rt<<1].min,seg[rt<<1|1].min); } ll query(int l, int r, int rt){ if(seg[rt].l == l && seg[rt].r == r) return seg[rt].min; int mid = (seg[rt].l+seg[rt].r)/2; if(r <= mid) return query(l,r,rt<<1); else if(l > mid) return query(l,r,rt<<1|1); return min(query(l,mid,rt<<1),query(mid+1,r,rt<<1|1)); } int main(){ scanf("%d %d",&num_rows,&num_cols); for(int i=1; i<=num_rows; i++){ scanf(" %d %d %d %d",&segs[i].first.first,&segs[i].first.second,&segs[i].second.first,&segs[i].second.second); pos.pb(segs[i].first.first); pos.pb(segs[i].first.second); pos.pb(segs[i].second.first); } sort(all(pos)); complete_unique(pos); for(int i=1; i<=pos.size(); i++) rev[pos[i-1]] = i; for(int i=1; i<=num_rows; i++) dp[i] = LLONG_MAX/10; build(1,(int)pos.size(),1); for(int i=1; i<=num_rows; i++){ if(segs[i].first.first == 1) dp[i] = segs[i].second.second; int l = segs[i].first.first, r = segs[i].first.second, m = segs[i].second.first; ll ndp = query(rev[l],rev[r],1)+segs[i].second.second; dp[i] = min(dp[i],ndp); update(rev[m],1,dp[i]); res[i]+=dp[i]; } for(int i=1; i<=num_rows; i++) dp[i] = LLONG_MAX/10; build(1,(int)pos.size(),1); for(int i=1; i<=num_rows; i++){ if(segs[i].first.second == num_cols) dp[i] = segs[i].second.second; int l = segs[i].first.first, r = segs[i].first.second, m = segs[i].second.first; ll ndp = query(rev[l],rev[r],1)+segs[i].second.second; dp[i] = min(dp[i],ndp); update(rev[m],1,dp[i]); res[i]+=dp[i]; } for(int i=1; i<=num_rows; i++) ans = min(ans,res[i]-segs[i].second.second); if(ans == LLONG_MAX/10) printf("-1\n"); else printf("%lld\n",ans); }

컴파일 시 표준 에러 (stderr) 메시지

pinball.cpp: In function 'int main()':
pinball.cpp:93:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1; i<=pos.size(); i++)
               ~^~~~~~~~~~~~
pinball.cpp:85:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&num_rows,&num_cols);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pinball.cpp:87:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %d %d %d %d",&segs[i].first.first,&segs[i].first.second,&segs[i].second.first,&segs[i].second.second);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...