Submission #895921

#TimeUsernameProblemLanguageResultExecution timeMemory
895921nightfalWiring (IOI17_wiring)C++14
20 / 100
24 ms2752 KiB
#include "wiring.h"
#include <stdlib.h>
#include <algorithm>
using namespace std;
 
bool isSubtask1(std::vector<int> r, std::vector<int> b) {return r.size()<=200 && b.size()<=200;}
bool isSubtask2(std::vector<int> r, std::vector<int> b) {return r[r.size()-1]<b[0];}
bool isSubtask3(std::vector<int> r, std::vector<int> b) {
  int n=r.size(), m=b.size();
  vector<int> a(n+m);
  for(int i=0, j=0; i<m || j<n;) 
    i==n? a[n+j++]= 0: j==m? a[m+i++] = 1: a[i+j] = r[i]<b[j]? r[i++]:b[j++];
  int cnt = 1;
  for(int k=1; k<n+m; k++) {
    cnt = a[k]==a[k-1]? cnt+1:0;
     if (cnt > 7) return false;
  }
  return true;
}
 
long long subtask1(std::vector<int>, std::vector<int>);
long long subtask2(std::vector<int>, std::vector<int>, int, int, int, int);
 
long long min_total_length(std::vector<int> r, std::vector<int> b) {
  	if (isSubtask1(r,b)) return subtask1(r,b);
  	else if (isSubtask2(r,b)) return subtask2(r,b,0,r.size()-1,0,b.size()-1);
}
 
long long subtask1(std::vector<int> r, std::vector<int> b) {
	int n = r.size(), m = b.size();
    long long dp[n][m];
  	dp[0][0] = abs(r[0]-b[0]);
  	for(int i=1; i<n; i++)
      dp[i][0] = dp[i-1][0] + abs(r[i]-b[0]);
    for(int j=1; j<m; j++)
      dp[0][j] = dp[0][j-1] + abs(r[0]-b[j]);
  	for(int i=1; i<n; i++)  	
      for(int j=1; j<m; j++)
        dp[i][j] = min(min(dp[i-1][j],dp[i][j-1]),dp[i-1][j-1]) + abs(r[i]-b[j]);
	return dp[n-1][m-1];
}
 
long long subtask2(std::vector<int> arr1, std::vector<int> arr2, int s1, int e1, int s2, int e2) {
  long long sum1=0, sum2=0, n = e1-s1+1, m=e2-s2+1;
  for(int i=s1; i<=e1; i++) sum1 += arr1[e1] - arr1[i];
  for(int i=s2; i<=e2; i++) sum2 += arr2[i] - arr2[s2];
  return sum1+sum2+max(n,m)*(arr2[s2]-arr1[e1]);
}

Compilation message (stderr)

wiring.cpp: In function 'bool isSubtask3(std::vector<int>, std::vector<int>)':
wiring.cpp:12:67: warning: operation on 'i' may be undefined [-Wsequence-point]
   12 |     i==n? a[n+j++]= 0: j==m? a[m+i++] = 1: a[i+j] = r[i]<b[j]? r[i++]:b[j++];
      |                                                                  ~^~
wiring.cpp:12:74: warning: operation on 'j' may be undefined [-Wsequence-point]
   12 |     i==n? a[n+j++]= 0: j==m? a[m+i++] = 1: a[i+j] = r[i]<b[j]? r[i++]:b[j++];
      |                                                                         ~^~
wiring.cpp: In function 'long long int subtask1(std::vector<int>, std::vector<int>)':
wiring.cpp:38:7: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   38 |       for(int j=1; j<m; j++)
      |       ^~~
wiring.cpp:40:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   40 |  return dp[n-1][m-1];
      |  ^~~~~~
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:27:1: warning: control reaches end of non-void function [-Wreturn-type]
   27 | }
      | ^
#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...