제출 #430807

#제출 시각아이디문제언어결과실행 시간메모리
430807Belgutei전선 연결 (IOI17_wiring)C++17
100 / 100
53 ms8132 KiB
#include "wiring.h" #include<bits/stdc++.h> using namespace std; #define ll long long #define ff first #define ss second #define pb push_back #define mk make_pair pair<ll,ll> a[200005]; ll sum[200005],cnt; ll dp[200005]; long long min_total_length(std::vector<int> red, std::vector<int> blue) { for(int i=0; i<red.size(); i++){ cnt++; a[cnt].ff=red[i]; a[cnt].ss=0; } for(int i=0; i<blue.size(); i++){ cnt++; a[cnt].ff=blue[i]; a[cnt].ss=1; } sort(a+1,a+cnt+1); for(int i=1; i<=cnt; i++){ sum[i]=sum[i-1]+a[i].ff; } a[0].ff=-1e9; a[0].ss=1-a[1].ss; for(int i=1, p=1; i<=cnt; i++){ int j=i; while(j<cnt && a[j+1].ss==a[i].ss) j++; for(int k=p; k<i; k++){ dp[k]=min(dp[k],dp[k-1]+a[i].ff-a[k].ff); } ll C=0,M=dp[i-1]; for(int k=i; k<=j; k++){ C+=a[k].ff-a[i-1].ff; int x=2*i-k-2; if(x+1>=p){ M=min(M,dp[x]+a[i-1].ff*(i-x-1)-(sum[i-1]-sum[x])); } dp[k]=M+C; } p=i; i=j; } return dp[cnt]; }

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

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:17:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |  for(int i=0; i<red.size(); i++){
      |               ~^~~~~~~~~~~
wiring.cpp:22:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  for(int i=0; i<blue.size(); i++){
      |               ~^~~~~~~~~~~~
#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...