Submission #288378

#TimeUsernameProblemLanguageResultExecution timeMemory
288378kevleeWiring (IOI17_wiring)C++17
13 / 100
39 ms2304 KiB
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mod 1000000007
#define h1 7897897897897897
#define h2 7897466719774591
#define b1 98762051
#define b2 98765431
#define inf 1000000000
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pii>
#define SET(a, b) memset(a, b, sizeof(a));
#define all(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
int change[100005];
long long min_total_length(vector<int> a, vector<int> b) {
  ll ans = 0;
  int n = a.size(), m = b.size();
  if (n > m) swap(a, b), swap(n, m);
  int cur = n-1;
  FORD(i, m-1, 0) {
    change[i] = cur--;
  }
  cur = 0;
  FOR(i, 0, m-1) {
    if (cur == change[i] || cur == 0) {
      ans += abs(b[i] - a[cur]);
      cur++;
    } else {
      if (abs(b[i] - a[cur]) <= abs(b[i] - a[cur - 1])) {
        ans += abs(b[i] - a[cur]);
        cur++;
      } else {
        ans += abs(b[i] - a[cur - 1]);
      }
    }
    if (cur == n) cur = n-1;
    //cout << cur << endl;
  }
  return ans;
}
#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...