Submission #934640

# Submission time Handle Problem Language Result Execution time Memory
934640 2024-02-27T18:21:49 Z sysia Wiring (IOI17_wiring) C++17
13 / 100
26 ms 7372 KB
//Sylwia Sapkowska
#include <bits/stdc++.h>
#include "wiring.h"
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;

void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << "'" << x << "'";}
void __print(const char *x) {cerr << '"' << x << '"';}
void __print(const string &x) {cerr << '"' << x << '"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef pair<int, int> T;
const long long oo = 1e18, oo2 = 1e9+7;

long long min_total_length(vector<int>a, vector<int>b) {
	vector<T>tab;
	vector<vector<int>>curr(2);
	curr[0] = a;
	curr[1] = b;
	for (int i = 0; i<(int)a.size(); i++) tab.emplace_back(a[i], 0);
	for (int i = 0; i<(int)b.size(); i++) tab.emplace_back(b[i], 1);
	sort(tab.begin(), tab.end());
	vector<int>paired((int)tab.size());
	long long ans = 0;
	vector<stack<int>>s(2);
	for (int i = 0; i<(int)tab.size(); i++){
		auto [pos, what] = tab[i];
		if (s[what^1].empty()){
			s[what].push(i);
		} else {
			ans += (long long)(pos-tab[s[what^1].top()].first);
			paired[s[what^1].top()] = 1;
			paired[i] = 1;
			debug(pos, tab[s[what^1].top()].first);
			s[what^1].pop();
		}
	}
	debug(paired, ans);
	for (int i = 0; i<(int)tab.size(); i++){
		if (paired[i]) continue;
		auto [pos, what] = tab[i];
		long long tmp = oo;
		int p = (int)(lower_bound(curr[what^1].begin(), curr[what^1].end(), pos) - curr[what^1].begin());
		if (p < (int)curr[what^1].size()) tmp = min(tmp, (long long)curr[what^1][p] - pos);
		if (p) tmp = min(tmp, (long long)pos-curr[what^1][p-1]);
		ans += tmp;
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '14340', found: '17422'
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 Correct 18 ms 5744 KB Output is correct
4 Correct 18 ms 5672 KB Output is correct
5 Correct 26 ms 5840 KB Output is correct
6 Correct 23 ms 7368 KB Output is correct
7 Correct 23 ms 7332 KB Output is correct
8 Correct 23 ms 7356 KB Output is correct
9 Correct 23 ms 7372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '17703', found: '19052'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB 3rd lines differ - on the 1st token, expected: '27', found: '30'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '14340', found: '17422'
3 Halted 0 ms 0 KB -