제출 #966584

#제출 시각아이디문제언어결과실행 시간메모리
966584Amr전선 연결 (IOI17_wiring)C++17
0 / 100
1 ms348 KiB
#include "wiring.h" #include<bits/stdc++.h> using namespace std; #define sz size() typedef long long ll; #define all(x) (x).begin(),(x).end() const int N = 2e5+2; ll a[N]; long long min_total_length(std::vector<int> r, std::vector<int> b) { ll n = r.sz, m = b.sz; for(int i = 0; i < n; i++) a[r[i]] = 1; for(int i = 0; i < m; i++) a[b[i]] = 0; ll newlst = 0,start = 1,ans=0; for(int i = 1; i <= m+n; i++) { if(i==m+n||a[i+1]!=a[i]) { ll en = i; for(int j = start; j <= en; j++) { ll lst = newlst; newlst = 0; ll d1 = j-start , d2 = en-j; if((start!=1)&&lst>0&&(d1<d2||en==n+m)) { lst--; ans+=d1; } else if((start!=1)&&lst==0&&(d1+1<d2||en==n+m)) { ans+=d1+1; } else { newlst++; ans+=d2+1; } } // cout << ans << " "; start = i+1; } } return ans; } //b rrr bb r bb //1 + 2 + 1 + 1 + 1 + 2 // cases //not start! lst > 0 and (d1<d2 or end) //else notstart! lst == 0 (d1+1<D2 or end) //else newlst++; //cases: //d1<d2 //d1+1<d2
#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...