제출 #53193

#제출 시각아이디문제언어결과실행 시간메모리
53193WA_TLE전선 연결 (IOI17_wiring)C++14
100 / 100
104 ms7544 KiB
#include "wiring.h" #include<deque> #include<queue> #include<vector> #include<algorithm> #include<iostream> #include<set> #include<cmath> #include<tuple> #include<string> #include<chrono> #include<functional> #include<iterator> #include<random> #include<unordered_set> #include<array> #include<map> #include<iomanip> #include<assert.h> #include<bitset> using namespace std; typedef long long int llint; typedef long double lldo; #define mp make_pair #define mt make_tuple #define pub push_back #define puf push_front #define pob pop_back #define pof pop_front #define fir first #define sec second #define res resize #define ins insert #define era erase /* cout<<setprecision(20) cin.tie(0); ios::sync_with_stdio(false); */ const llint mod=1e9+7; const llint big=2.19e15+1; const long double pai=3.141592653589793238462643383279502884197; const long double eps=1e-15; template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}} template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}} llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);} //llint lcm(llint a,llint b){return a/gcd(a,b)*b;} template<class T> void SO(T& ve){sort(ve.begin(),ve.end());} template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());} //template<class T>auto LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();} //template<class T>auto UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();} long long min_total_length(std::vector<int> r, std::vector<int> b) { vector<vector<llint>>tow; //色の切り替えが重要 int maec=-1,rg=0,bg=0,i; //for(auto it:r){cout<<it<<" ";}cout<<endl; //for(auto it:b){cout<<it<<" ";}cout<<endl; r.pub(mod);b.pub(mod); while(-1){ if(r[rg]==mod&&b[bg]==mod){break;} if(r[rg]<b[bg]){ if(maec!=0){tow.pub(vector<llint>());} tow.back().pub(r[rg]); rg++;maec=0; }else{ if(maec!=1){tow.pub(vector<llint>());} tow.back().pub(b[bg]); bg++;maec=1; } } llint mapot=-mod; vector<llint>use;//前の使用数 use.pub(0); for(auto ar:tow){ //for(auto it:ar){cout<<it<<" ";}cout<<endl; int n=ar.size(),m=use.size(); //普通のnやmとは全く違うよ!!! vector<llint>kaz(n+1);//手前側にいくつ振り分けますか llint mgpot=ar.back(),hipot=ar[0]; for(i=0;i<n;i++){kaz[0]+=mgpot-ar[i];} for(i=0;i<n;i++){kaz[i+1]=kaz[i]-mgpot-hipot+ar[i]+ar[i];} llint madis=hipot-mapot; if(m<n+1){ vector<llint>aaa(n+1); for(i=0;i<m;i++){aaa[i]=use[i];} for(i=m;i<=n;i++){aaa[i]=big;} m=n+1; use=move(aaa); } //for(auto it:use){cout<<it<<" ";}cout<<endl; for(i=0;i<m;i++){use[i]+=i*madis;} for(i=m-1;i>0;i--){mineq(use[i-1],use[i]);} for(i=0;i<m-1;i++){mineq(use[i+1],use[i]+madis);} //for(auto it:use){cout<<it<<" ";}cout<<endl; vector<llint>nes(n+1); for(i=0;i<=n;i++){nes[n-i]=use[i]+kaz[i];} use=move(nes); //for(auto it:use){cout<<it<<" ";}cout<<endl; mapot=mgpot; } return use[0]; }
#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...