Submission #640142

#TimeUsernameProblemLanguageResultExecution timeMemory
640142ghostwriterWiring (IOI17_wiring)C++14
20 / 100
36 ms6720 KiB
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#include "grader.cpp"
#endif
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
    Tran The Bao
    CTL - Da Lat
    Cay ngay cay dem nhung deo duoc cong nhan
*/
const int N = 1e5 + 5;
int n, m, r[N], b[N];
vpi a;
namespace subtask1 {
	const int N = 205;
	int f[N];
	ll d[N][N], rs = 1e18;
	ll solve() {
		if (n > m) {
			swap(n, m);
			swap(r, b);
		}
		FOR(i, 1, m) {
			f[i] = 1e9 + 5;
			FOR(j, 1, n) f[i] = min(f[i], abs(b[i] - r[j]));
		}
		ll sum1 = 0;
		FOR(i, 1, m) {
			d[0][i] = sum1;
			sum1 += f[i];
		}
		FOR(i, 1, n)
		FOR(j, 1, m) {
			d[i][j] = 1e18;
			ll sum = 0;
			FOS(z, j, 1) {
				d[i][j] = min(d[i][j], d[i - 1][z] + sum + abs(r[i] - b[z]));
				if (z != j) sum += f[z];
			}
		}
		ll sum = 0;
		FOS(i, m, 1) {
			rs = min(rs, d[n - 1][i] + sum + abs(r[n] - b[i]));
			sum += f[i];
		}
		return rs;
	}
}
namespace subtask2 {
	ll solve() {
		ll rs = 0;
		FOR(i, 1, n) rs -= r[i];
		FOR(i, 1, m) rs += b[i];
		FOR(i, 1, m - n) rs -= r[n];
		FOR(i, 1, n - m) rs += b[1];
		return rs;
	}
}
namespace subtask3 {
	ll solve() {
		return 0;
	}
}
long long min_total_length(std::vector<int> r, std::vector<int> b) {
	n = sz(r);
	m = sz(b);
	FOR(i, 1, n) ::r[i] = r[i - 1];
	FOR(i, 1, m) ::b[i] = b[i - 1];
	if (n <= 200 && m <= 200) return subtask1::solve();
	if (r[n - 1] < b[0]) return subtask2::solve();
	FOR(i, 0, n - 1) a.pb({r[i], 0});
	FOR(i, 0, m - 1) a.pb({b[i], 1});
	sort(all(a));
	bool sub3 = 1;
	int cntr = 0, cntb = 0;
	FOR(i, 6, n + m - 1) {
		FOR(j, i - 7 + 1, i)
			if (a[j].nd == 0) ++cntr;
			else ++cntb;
		if (!cntr || !cntb) sub3 = 0;
	}
	if (sub3) return subtask3::solve();
	return 0;
}
/*
4 5
1 2 3 7
0 4 5 9 10
*/

Compilation message (stderr)

wiring.cpp: In function 'll subtask1::solve()':
wiring.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
wiring.cpp:50:3: note: in expansion of macro 'FOR'
   50 |   FOR(i, 1, m) {
      |   ^~~
wiring.cpp:26:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
wiring.cpp:52:4: note: in expansion of macro 'FOR'
   52 |    FOR(j, 1, n) f[i] = min(f[i], abs(b[i] - r[j]));
      |    ^~~
wiring.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
wiring.cpp:55:3: note: in expansion of macro 'FOR'
   55 |   FOR(i, 1, m) {
      |   ^~~
wiring.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
wiring.cpp:59:3: note: in expansion of macro 'FOR'
   59 |   FOR(i, 1, n)
      |   ^~~
wiring.cpp:26:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
wiring.cpp:60:3: note: in expansion of macro 'FOR'
   60 |   FOR(j, 1, m) {
      |   ^~~
wiring.cpp:27:31: warning: unnecessary parentheses in declaration of 'z' [-Wparentheses]
   27 | #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
      |                               ^
wiring.cpp:63:4: note: in expansion of macro 'FOS'
   63 |    FOS(z, j, 1) {
      |    ^~~
wiring.cpp:27:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   27 | #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
      |                               ^
wiring.cpp:69:3: note: in expansion of macro 'FOS'
   69 |   FOS(i, m, 1) {
      |   ^~~
wiring.cpp: In function 'll subtask2::solve()':
wiring.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
wiring.cpp:79:3: note: in expansion of macro 'FOR'
   79 |   FOR(i, 1, n) rs -= r[i];
      |   ^~~
wiring.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
wiring.cpp:80:3: note: in expansion of macro 'FOR'
   80 |   FOR(i, 1, m) rs += b[i];
      |   ^~~
wiring.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
wiring.cpp:81:3: note: in expansion of macro 'FOR'
   81 |   FOR(i, 1, m - n) rs -= r[n];
      |   ^~~
wiring.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
wiring.cpp:82:3: note: in expansion of macro 'FOR'
   82 |   FOR(i, 1, n - m) rs += b[1];
      |   ^~~
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
wiring.cpp:94:2: note: in expansion of macro 'FOR'
   94 |  FOR(i, 1, n) ::r[i] = r[i - 1];
      |  ^~~
wiring.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
wiring.cpp:95:2: note: in expansion of macro 'FOR'
   95 |  FOR(i, 1, m) ::b[i] = b[i - 1];
      |  ^~~
wiring.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
wiring.cpp:98:2: note: in expansion of macro 'FOR'
   98 |  FOR(i, 0, n - 1) a.pb({r[i], 0});
      |  ^~~
wiring.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
wiring.cpp:99:2: note: in expansion of macro 'FOR'
   99 |  FOR(i, 0, m - 1) a.pb({b[i], 1});
      |  ^~~
wiring.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
wiring.cpp:103:2: note: in expansion of macro 'FOR'
  103 |  FOR(i, 6, n + m - 1) {
      |  ^~~
wiring.cpp:26:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
wiring.cpp:104:3: note: in expansion of macro 'FOR'
  104 |   FOR(j, i - 7 + 1, i)
      |   ^~~
#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...