Submission #969275

# Submission time Handle Problem Language Result Execution time Memory
969275 2024-04-24T21:26:40 Z mariaclara Wiring (IOI17_wiring) C++17
13 / 100
26 ms 11840 KB
#include "wiring.h"
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pii;
const int INF = 1e9+10;
const ll LINF = 1e18+10;
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define mk make_pair
#define pb push_back
#define f first 
#define s second

ll min_total_length(vector<int> r, vector<int> b) {
	vector<pii> p;

	r.pb(INF);
	b.pb(INF);
	p.pb({-1,-1});
	for(int i = 0, j = 0; r[i] != b[j];  ) {
		if(r[i] < b[j]) p.pb({r[i],0}), i++;
		else p.pb({b[j],1}), j++;
	}

	int n = sz(p);

	vector<ll> dp(n, LINF), v(n, 0), m(n, 0), prefix(n, 0);

	dp[0] = 0;
	for(int i = 1, last = -1, at = 1; i < n; i++) {
		prefix[i] = prefix[i-1] + p[i].f;
		if(p[i].s != p[i-1].s) last = at, at = i;
		//cout << dp[i-1] << "\n" << at << " " << p[i].f << " " << p[i].s << " ";
		if(at == 1) continue;

		if(i == at) {
			v[at-1] = dp[at-2] + p[at].f - p[at-1].f;
			for(int j = at-2; j >= last; j--)
				v[j] = v[j+1] - p[j].f + p[at].f - dp[j] + dp[j-1];

			m[last] = v[last];
			for(int j = last+1; j < at; j++)
				m[j] = min(m[j-1], v[j]);
			
			dp[at] = m[at-1];
			continue;
		}

		dp[i] = dp[i-1] + p[i].f - p[at-1].f;
		if(at - (i-at+1) >= last) dp[i] = min(dp[i], m[at - (i-at+1)] - (i-at)*p[at].f + prefix[i] - prefix[at]);
	}

	return dp[n-1];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '14340', found: '14694'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 19 ms 9116 KB Output is correct
4 Correct 19 ms 9220 KB Output is correct
5 Correct 18 ms 9220 KB Output is correct
6 Correct 23 ms 11188 KB Output is correct
7 Correct 26 ms 11700 KB Output is correct
8 Correct 23 ms 11580 KB Output is correct
9 Correct 23 ms 11328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 23 ms 11328 KB 3rd lines differ - on the 1st token, expected: '1068938599', found: '1152497305'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 22 ms 11280 KB Output is correct
3 Correct 22 ms 11328 KB Output is correct
4 Correct 21 ms 11840 KB Output is correct
5 Correct 21 ms 11840 KB Output is correct
6 Incorrect 1 ms 344 KB 3rd lines differ - on the 1st token, expected: '42', found: '43'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '14340', found: '14694'
3 Halted 0 ms 0 KB -