Submission #826370

#TimeUsernameProblemLanguageResultExecution timeMemory
826370tolbiWiring (IOI17_wiring)C++17
20 / 100
19 ms2620 KiB
#include <bits/stdc++.h> using namespace std; #include "wiring.h" long long ara(long long a, long long b){ if (a>b) return a-b; return b-a; } long long subtask1(vector<int> &r, vector<int> &b){ int n = r.size(); int m = b.size(); vector<vector<long long>> dp(n, vector<long long>(m,-1)); function<long long(int,int)> f; f = [&](int x, int y)->long long{ if (dp[x][y]!=-1) return dp[x][y]; if (x==n-1 && y==m-1){ return ara(r[x],b[y]); } if (x==n-1){ return dp[x][y]=ara(r[x],b[y])+f(x,y+1); } if (y==m-1){ return dp[x][y]=ara(r[x],b[y])+f(x+1,y); } dp[x][y]=ara(r[x],b[y]); long long mava = f(x+1,y+1); mava=min(mava,f(x,y+1)); mava=min(mava,f(x+1,y)); return dp[x][y]+=mava; }; return f(0,0); } long long subtask2(vector<int> &r, vector<int> &b){ long long ans = 0; reverse(r.begin(), r.end()); if (r.size()>b.size()){ for (int i = 0; i < b.size(); i++){ ans+=ara(r[i],b[i]); } for (int i = b.size(); i < r.size(); i++){ ans+=ara(b[0],r[i]); } } else { for (int i = 0; i < r.size(); i++){ ans+=ara(r[i],b[i]); } for (int i = r.size(); i < b.size(); i++){ ans+=ara(r[0],b[i]); } } return ans; } long long min_total_length(std::vector<int> r, std::vector<int> b) { if (r.size()<=200 && b.size()<=200) return subtask1(r,b); if (*max_element(r.begin(), r.end())<*min_element(b.begin(), b.end())) return subtask2(r,b); }

Compilation message (stderr)

wiring.cpp: In function 'long long int subtask2(std::vector<int>&, std::vector<int>&)':
wiring.cpp:37:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   for (int i = 0; i < b.size(); i++){
      |                   ~~^~~~~~~~~~
wiring.cpp:40:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |   for (int i = b.size(); i < r.size(); i++){
      |                          ~~^~~~~~~~~~
wiring.cpp:45:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   for (int i = 0; i < r.size(); i++){
      |                   ~~^~~~~~~~~~
wiring.cpp:48:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |   for (int i = r.size(); i < b.size(); i++){
      |                          ~~^~~~~~~~~~
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:57:1: warning: control reaches end of non-void function [-Wreturn-type]
   57 | }
      | ^
#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...