Submission #826359

# Submission time Handle Problem Language Result Execution time Memory
826359 2023-08-15T13:27:46 Z tolbi Wiring (IOI17_wiring) C++17
7 / 100
102 ms 262144 KB
#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;
	for (int i = 0; i < r.size()-1; i++){
		ans+=ara(r[i],b[0]);
	}
	for (int i = 1; i < b.size(); i++){
		ans+=ara(b[i],r.back());
	}
	if (r.size()==1 || b.size()==1){
		ans+=ara(r.back(), b[0]);
	}
	return ans;
}
long long min_total_length(std::vector<int> r, std::vector<int> b) {
	if (*max_element(r.begin(), r.end())<*min_element(b.begin(), b.end())) return subtask2(r,b);
	if (r.size()<=200 && b.size()<=200) return subtask1(r,b);
}

Compilation message

wiring.cpp: In function 'long long int subtask2(std::vector<int>&, std::vector<int>&)':
wiring.cpp:35:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |  for (int i = 0; i < r.size()-1; i++){
      |                  ~~^~~~~~~~~~~~
wiring.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |  for (int i = 1; i < b.size(); i++){
      |                  ~~^~~~~~~~~~
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:49:1: warning: control reaches end of non-void function [-Wreturn-type]
   49 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '904', found: '943'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '316', found: '348'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 102 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '904', found: '943'
18 Halted 0 ms 0 KB -