# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
969283 |
2024-04-24T21:37:16 Z |
mariaclara |
Wiring (IOI17_wiring) |
C++17 |
|
1000 ms |
12620 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;
if(at == 1) continue;
for(int j = at-1; j >= last; j--) {
ll x = prefix[i] - prefix[at-1];
ll y = prefix[at-1] - prefix[j-1];
ll R = x - y;
if(i-at+1 >= at-j) R -= (i-at+1-at+j)*p[at-1].f;
else R += (at-j-i+at-1)*p[at].f;
dp[i] = min(dp[i], R+dp[j-1]);
}
//cout << dp[i] << "\n" << at << " " << p[i].f << " " << p[i].s << " ";
}
return dp[n-1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
440 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 |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
1056 ms |
9548 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Incorrect |
26 ms |
12620 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 |
Execution timed out |
1061 ms |
12088 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
440 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 |
- |