제출 #581089

#제출 시각아이디문제언어결과실행 시간메모리
581089Koosha_mv전선 연결 (IOI17_wiring)C++14
100 / 100
437 ms23704 KiB
#include <bits/stdc++.h> using namespace std; #define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl #define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl #define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl #define eror(x) cout<<#x<<'='<<(x)<<endl #define f_(i,a,b) for(int i=a;i>=b;i--) #define f(i,a,b) for(int i=a;i<b;i++) #define nb(x) __builtin_popcount(x) #define all(v) v.begin(),v.end() #define bit(n,k) (((n)>>(k))&1) #define Add(x,y) x=(x+y)%mod #define maxm(a,b) a=max(a,b) #define minm(a,b) a=min(a,b) #define lst(x) x[x.size()-1] #define sz(x) int(x.size()) #define mp make_pair #define ll long long #define pb push_back #define S second #define F first #include "wiring.h" const int N=2e5+99; const ll inf=1e15+99; int n; ll last[2],st[2],dp[N],seg[N<<2],lz[N<<2]; vector<pair<ll,ll>> A; vector<pair<pair<ll,ll>,ll>> op; void shift(int id){ seg[id*2+0]+=lz[id]; seg[id*2+1]+=lz[id]; lz[id*2+0]+=lz[id]; lz[id*2+1]+=lz[id]; lz[id]=0; } void add(int L,int R,ll val,int id=1, int l=1,int r=n+1){ if(r<=L || R<=l) return ; if(L<=l && r<=R){ lz[id]+=val; seg[id]+=val; return ; } int mid=(l+r)>>1; shift(id); add(L,R,val,id*2+0,l,mid); add(L,R,val,id*2+1,mid,r); seg[id]=min(seg[id*2+0],seg[id*2+1]); } void clear(){ for(auto p : op){ add(p.F.F,p.F.S,p.S); } op.clear(); } void addseg(int l,int r,ll val){ op.pb({{l,r},val}); add(l,r,val); } ll query(int L,int R,int id=1,int l=1,int r=n+1){ if(r<=L || R<=l) return inf; if(L<=l && r<=R){ return seg[id]; } shift(id); int mid=(l+r)>>1; return min(query(L,R,id*2+0,l,mid),query(L,R,id*2+1,mid,r)); } ll solve1(vector<pair<int,int>> now){ if(now[0].S==now.back().S) return inf; int cnt=0,ans=0,t0=0,t1; f(i,0,now.size()){ if(now[i].S==now[0].S) ans-=now[i].F; else ans+=now[i].F; if(i+1<now.size() && now[i].S!=now[i+1].S){ cnt++; t0=i+1; } } t1=now.size()-t0; if(cnt>1) return inf; if(t0>=t1){ ans+=(t0-t1)*now[t0].F; } else{ ans+=(t0-t1)*now[t0-1].F; } return ans; } void Print(){ f(i,1,n+1) cout<<query(i,i+1)<<" "; cout<<'\n'; } ll min_total_length(vector<int> r,vector<int> b){ last[0]=-inf,last[1]=-inf; for(auto x : r) A.pb({x,0}); for(auto x : b) A.pb({x,1}); A.pb({-1,-1}); sort(all(A)); n=A.size()-1; f(i,1,n+1){ //cout<<i<<" -----> "<<endl; dp[i]=inf; if(A[i].S!=A[i-1].S){ st[A[i].S]=i; clear(); f_(j,i-1,1){ if(A[j].S==A[i].S) break; addseg(1,j+1,A[i].F-A[j].F); } } if(i-st[A[i].S]<st[A[i].S]-st[A[i].S^1] && st[A[i].S]!=1){ ll len=A[i].F-A[st[A[i].S]].F,prt=i-st[A[i].S]; addseg(st[A[i].S^1],i-prt-prt,len); dp[i]=query(st[A[i].S^1],i-prt-prt); } //Print(); maxm(last[A[i].S],1ll*A[i].F); minm(dp[i],dp[i-1]+A[i].F-last[A[i].S^1]); ll res=0; f_(j,i-1,1){ if(A[j].S==A[i].S) break; res+=A[i].F-A[j].F; minm(dp[i],dp[j-1]+res); } /*vector<pair<int,int>> now; f_(j,i-1,0){ now.pb(A[j+1]); sort(all(now)); minm(dp[i],dp[j]+solve1(now)); }*/ //eror(dp[i]); if(i!=n){ add(i+1,i+2,dp[i]); } //Print(); //eror(dp[i]); } return dp[A.size()-1]; } /* int32_t main(){ ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0); vector<pair<int,int>> now; //now.pb({1,0}); //now.pb({2,0}); //now.pb({3,1}); //now.pb({4,1}); //eror(solve1(now)); //cout<<min_total_length({1,2},{3,4}); cout<<min_total_length({1,2,3,7},{0,4,5,9,10}); }*/

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

wiring.cpp: In function 'long long int solve1(std::vector<std::pair<int, int> >)':
wiring.cpp:8:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define f(i,a,b) for(int i=a;i<b;i++)
......
   75 |  f(i,0,now.size()){
      |    ~~~~~~~~~~~~~~              
wiring.cpp:75:2: note: in expansion of macro 'f'
   75 |  f(i,0,now.size()){
      |  ^
wiring.cpp:78:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |   if(i+1<now.size() && now[i].S!=now[i+1].S){
      |      ~~~^~~~~~~~~~~
wiring.cpp: In function 'void Print()':
wiring.cpp:8:18: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    8 | #define f(i,a,b) for(int i=a;i<b;i++)
      |                  ^~~
wiring.cpp:94:2: note: in expansion of macro 'f'
   94 |  f(i,1,n+1) cout<<query(i,i+1)<<" "; cout<<'\n';
      |  ^
wiring.cpp:94:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   94 |  f(i,1,n+1) cout<<query(i,i+1)<<" "; cout<<'\n';
      |                                      ^~~~
#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...