제출 #571441

#제출 시각아이디문제언어결과실행 시간메모리
571441Theo830전선 연결 (IOI17_wiring)C++17
0 / 100
1 ms596 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e18+7; const ll MOD = 998244353; typedef pair<ll,ll> ii; #define iii pair<ii,ll> #define ull unsigned ll #define f(i,a,b) for(ll i = a;i < b;i++) #define pb push_back #define vll vector<ll> #define F first #define S second #define all(x) (x).begin(), (x).end() ///I hope I will get uprating and don't make mistakes ///I will never stop programming ///sqrt(-1) Love C++ ///Please don't hack me ///@TheofanisOrfanou Theo830 ///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst) ///Stay Calm ///Look for special cases ///Beware of overflow and array bounds ///Think the problem backwards ///Training #include "wiring.h" ll n,m; vector<int>A,B; ll dp[205][205]; ll minA[205],minB[205]; ll solve(ll i,ll j){ if(i == n && j == m){ return 0; } if(dp[i][j] != -1){ return dp[i][j]; } ll ans = INF; if(i != n && j != m && abs(A[i] - B[j]) == minA[i]){ ans = solve(i + 1,j + 1) + abs(A[i] - B[j]); } if(i != n){ ans = min(ans,solve(i + 1,j) + minA[i]); } if(j != m){ ans = min(ans,solve(i,j + 1) + minB[j]); } return dp[i][j] = ans; } long long min_total_length(std::vector<int> r, std::vector<int> b) { memset(dp,-1,sizeof dp); A = r; B = b; n = A.size(); m = B.size(); ll pos = 0; f(i,0,n){ while(pos < B.size() && B[pos] < A[i]){ pos++; } minA[i] = INF; if(pos != B.size()){ minA[i] = abs(A[i] - B[pos]); } if(pos != 0){ minA[i] = min(minA[i],(ll)abs(A[i] - B[pos - 1])); } } pos = 0; f(i,0,m){ while(pos < A.size() && A[pos] < B[i]){ pos++; } minB[i] = INF; if(pos != A.size()){ minB[i] = abs(B[i] - A[pos]); } if(pos != 0){ minB[i] = min(minB[i],(ll)abs(B[i] - A[pos - 1])); } } return solve(0,0); } /* int main() { int n, m; assert(2 == scanf("%d %d", &n, &m)); vector<int> r(n), b(m); for(int i = 0; i < n; i++) assert(1 == scanf("%d", &r[i])); for(int i = 0; i < m; i++) assert(1 == scanf("%d", &b[i])); long long res = min_total_length(r, b); printf("%lld\n", res); return 0; } 4 5 1 2 3 7 0 4 5 9 10 */

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

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:58:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         while(pos < B.size() && B[pos] < A[i]){
      |               ~~~~^~~~~~~~~~
wiring.cpp:62:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         if(pos != B.size()){
      |            ~~~~^~~~~~~~~~~
wiring.cpp:71:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         while(pos < A.size() && A[pos] < B[i]){
      |               ~~~~^~~~~~~~~~
wiring.cpp:75:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |         if(pos != A.size()){
      |            ~~~~^~~~~~~~~~~
#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...