제출 #741766

#제출 시각아이디문제언어결과실행 시간메모리
741766MODDI전선 연결 (IOI17_wiring)C++14
0 / 100
0 ms212 KiB
#include "wiring.h" #include <bits/stdc++.h> #define ll long long #define pii pair<int,int> #define pb push_back #define mp make_pair using namespace std; ll min_total_length(vector<int> red, vector<int> blue){ ll ans = 0; int n = red.size(), m = blue.size(); vector<array<int, 2> > arr; for(int i = 0, j = 0; i < n || j < m;){ if(i < n && (j == m || red[i] < blue[j])) arr.pb({red[i++], 0}); else arr.pb({blue[j++],1}); } vector<ll> dp(n + m + 1, 0); dp[0] = 0; for(int i = 0, j = 0, k = 0; j < n + m; i = j, j = k){ while(k < n + m && arr[k][1] == arr[j][1]) k++; for(int p = i; p < j; p++){ dp[p+1] = min(dp[p+1], dp[p] + arr[j][0] - arr[p][0]); } ll sum = 0; for(int p = 0; j + p < k && j - 1 - p >= i; p++){ sum += arr[j+p][0] - arr[j-1-p][0]; dp[j+p+1] = min(dp[j+p+1], dp[j-1-p] + sum); } if(j > 0){ for(int p = j; p < k; p++){ dp[p+1] = min(dp[p+1], dp[p] + arr[p][0] - arr[j-1][0]); } } } return dp[n+m]; }

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

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:10:5: warning: unused variable 'ans' [-Wunused-variable]
   10 |  ll ans = 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...