Submission #40179

# Submission time Handle Problem Language Result Execution time Memory
40179 2018-01-29T10:50:19 Z leejseo Wiring (IOI17_wiring) C++14
13 / 100
45 ms 3500 KB
#include "wiring.h"

long long abs (long long x){
    if (x > 0) return x;
    return -x;
}

long long max (long long a, long long b){
    if (a > b) return a;
    return b;
}

long long min_total_length(std::vector<int> r, std::vector<int> b) {
    int n, m;
	n = r.size();
	m = b.size();
	if (r[n-1] < b[0]){
        long long ans = 0;
        for (int i=0; i<n; i++){
            ans += r[n-1] - r[i];
        }
        for (int i=0; i<m; i++){
            ans += b[i] - b[0];
        }
        ans += max(n, m) *(b[0] - r[n-1]);
        return ans;
	}
	long long DP[n][m];
	DP[0][0] = b[0] - r[0];
	for (int i=0; i<n; i++){
        for (int j=0; j<m; j++){
            if (i == 0 && j == 0) continue;
            if (i == 0){
                DP[i][j] = DP[i][j-1] + abs(r[i] - b[j]);
                continue;
            }
            if (j == 0){
                DP[i][j] = DP[i-1][j] + abs(r[i] - b[j]);
                continue;
            }
            DP[i][j] = max(max(DP[i-1][j], DP[i][j-1]), DP[i-1][j-1]) + r[i] - b[j];
        }
	}
	return DP[n-1][m-1];
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 1932 KB 3rd lines differ - on the 1st token, expected: '25859', found: '50230'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1932 KB Output is correct
2 Correct 0 ms 1932 KB Output is correct
3 Correct 26 ms 3108 KB Output is correct
4 Correct 37 ms 3108 KB Output is correct
5 Correct 28 ms 3108 KB Output is correct
6 Correct 29 ms 3500 KB Output is correct
7 Correct 34 ms 3500 KB Output is correct
8 Correct 24 ms 3500 KB Output is correct
9 Correct 45 ms 3500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1932 KB Output is correct
2 Incorrect 0 ms 1932 KB 3rd lines differ - on the 1st token, expected: '17703', found: '56684'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 1932 KB 3rd lines differ - on the 1st token, expected: '27', found: '134'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 1932 KB 3rd lines differ - on the 1st token, expected: '25859', found: '50230'
2 Halted 0 ms 0 KB -