제출 #71428

#제출 시각아이디문제언어결과실행 시간메모리
71428Kmcode전선 연결 (IOI17_wiring)C++14
10 / 100
273 ms192172 KiB
#include<bits/stdc++.h> //#include "books.h" using namespace std; #define MAX 100002 int n; long long int dp[MAX][110]; int pos[MAX]; long long min_total_length(std::vector<int> r, std::vector<int> b) { for(int i=0;i<r.size();i++){ for(int j=0;j<200;j++){ dp[i][j]=LLONG_MAX; } pos[i]=lower_bound(b.begin(),b.end(),r[i])-b.begin(); } int x=50; dp[0][0-pos[0]+x]=abs(r[0]-b[0]); for(int i=0;i<r.size();i++){ for(int j1=0;j1<100;j1++){ int j=pos[i]+j1-x; if(j<0||j>=b.size())continue; if(dp[i][j1]==LLONG_MAX)continue; long long int val=dp[i][j1]; if(i+1<r.size()){ int base=pos[i+1]-x; if(j-base>=0)dp[i+1][j-base]=min(dp[i+1][j-base],val+(long long int)abs(r[i+1]-b[j])); } if(j+1<b.size()){ int base=pos[i]-x; if(j+1-base>=0)dp[i][j+1-base]=min(dp[i][j+1-base],val+(long long int)abs(r[i]-b[j+1])); } if(i+1<r.size()&&j+1<b.size()){ int base=pos[i+1]-x; if(j+1-base>=0)dp[i+1][j+1-base]=min(dp[i+1][j+1-base],val+(long long int)abs(r[i+1]-b[j+1])); } } } return dp[r.size()-1][b.size()-1-pos[r.size()-1]+x]; }

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

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:10:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<r.size();i++){
              ~^~~~~~~~~
wiring.cpp:18:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<r.size();i++){
              ~^~~~~~~~~
wiring.cpp:21:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(j<0||j>=b.size())continue;
            ~^~~~~~~~~~
wiring.cpp:24:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(i+1<r.size()){
       ~~~^~~~~~~~~
wiring.cpp:28:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(j+1<b.size()){
       ~~~^~~~~~~~~
wiring.cpp:32:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(i+1<r.size()&&j+1<b.size()){
       ~~~^~~~~~~~~
wiring.cpp:32:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(i+1<r.size()&&j+1<b.size()){
                     ~~~^~~~~~~~~
wiring.cpp:12:12: warning: iteration 110 invokes undefined behavior [-Waggressive-loop-optimizations]
    dp[i][j]=LLONG_MAX;
            ^
wiring.cpp:11:16: note: within this loop
   for(int j=0;j<200;j++){
               ~^~~~
#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...