답안 #966663

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966663 2024-04-20T07:53:12 Z Der_Vlapos Coin Collecting (JOI19_ho_t4) C++17
0 / 100
1 ms 348 KB
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #include <x86intrin.h>

#include <bits/stdc++.h>
#include <chrono>
#include <random>

// @author: Vlapos

namespace operators
{
	template <typename T1, typename T2>
	std::istream &operator>>(std::istream &in, std::pair<T1, T2> &x)
	{
		in >> x.first >> x.second;
		return in;
	}

	template <typename T1, typename T2>
	std::ostream &operator<<(std::ostream &out, std::pair<T1, T2> x)
	{
		out << x.first << " " << x.second;
		return out;
	}

	template <typename T1>
	std::istream &operator>>(std::istream &in, std::vector<T1> &x)
	{
		for (auto &i : x)
			in >> i;
		return in;
	}

	template <typename T1>
	std::ostream &operator<<(std::ostream &out, std::vector<T1> &x)
	{
		for (auto &i : x)
			out << i << " ";
		return out;
	}

	template <typename T1>
	std::ostream &operator<<(std::ostream &out, std::set<T1> &x)
	{
		for (auto &i : x)
			out << i << " ";
		return out;
	}

	template <typename T1>
	std::ostream &operator<<(std::ostream &out, std::multiset<T1> &x)
	{
		for (auto &i : x)
			out << i << " ";
		return out;
	}
}

// name spaces
using namespace std;
using namespace operators;
// end of name spaces

// defines
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
#define uint unsigned int
#define all(vc) vc.begin(), vc.end()
// end of defines

// usefull stuff

void boost()
{
	ios_base ::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

inline int getbit(int &x, int &bt) { return (x >> bt) & 1; }

const int dx4[4] = {-1, 0, 0, 1};
const int dy4[4] = {0, -1, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy8[8] = {-1, -0, 1, -1, 1, -1, 0, 1};

const ll INF = (1e18) + 500;
const int BIG = (1e9) * 2 + 100;
const int MAXN = (1e5) + 5;
const int MOD7 = (1e9) + 7;
const int MOD9 = (1e9) + 9;
const uint MODFFT = 998244353;

#define int ll

struct test
{
	void solve(int testcase)
	{
		boost();

		int n;
		cin >> n;
		vector<vector<int>> a(2, vector<int>(n));

		int res = 0;
		for (int i = 0; i < 2 * n; ++i)
		{
			int x, y;
			cin >> x >> y;
			--x, --y;
			int ID = y > 0;

			res += abs(x - max(0LL, min(x, n - 1))) + abs(y - ID);
			a[ID][max(0LL, min(x, n - 1))]++;
		}
		int c1 = 0, c2 = 0, p1 = 0, p2 = 0;
		vector<multiset<int>> poses(2);
		for (int i = 0; i < n; ++i)
		{
			for (int j = 0; j < 2; ++j)
				while (a[j][i] > 1)
				{
					poses[j].insert(i);
					a[j][i]--;
				}
		}

		poses[0].insert(BIG);
		poses[1].insert(BIG);

		for (int i = 0; i < n; ++i)
		{
			int c1 = a[0][i];
			int c2 = a[1][i];
			if (!c1 and !c2)
			{
				int d1 = min(abs(*poses[0].begin() - i), abs(*poses[1].begin() - i) + 1);
				int d2 = min(abs(*poses[1].begin() - i), abs(*poses[0].begin() - i) + 1);
				if (d1 < d2)
				{
					res += d1;
					if (d1 == abs(*poses[0].begin() - i))
						poses[0].erase(poses[0].begin());
					else
						poses[1].erase(poses[1].begin());
					c1 = 1;
				}
				else
				{
					res += d2;
					if (d2 == abs(*poses[1].begin() - i))
						poses[1].erase(poses[1].begin());
					else
						poses[0].erase(poses[0].begin());
					c2 = 1;
				}
			}


			if (!c1)
			{
				int d1 = min(abs(*poses[0].begin() - i), abs(*poses[1].begin() - i) + 1);
				res += d1;
				if (d1 == abs(*poses[0].begin() - i))
					poses[0].erase(poses[0].begin());
				else
					poses[1].erase(poses[1].begin());
			}
			if (!c2)
			{
				int d2 = min(abs(*poses[1].begin() - i), abs(*poses[0].begin() - i) + 1);
				res += d2;
				if (d2 == abs(*poses[1].begin() - i))
					poses[1].erase(poses[1].begin());
				else
					poses[0].erase(poses[0].begin());
			}
		}
		cout << res << '\n';
	}
};

main()
{
	boost();
	int q = 1;
	// cin >> q;
	for (int i = 0; i < q; i++)
	{
		test t;
		t.solve(i);
	}
	return 0;
}
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]//
//                                                                                    //
//                               Coded by Der_Vlἀpos                                  //
//                                                                                    //
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]//

Compilation message

joi2019_ho_t4.cpp: In member function 'void test::solve(long long int)':
joi2019_ho_t4.cpp:124:7: warning: unused variable 'c1' [-Wunused-variable]
  124 |   int c1 = 0, c2 = 0, p1 = 0, p2 = 0;
      |       ^~
joi2019_ho_t4.cpp:124:15: warning: unused variable 'c2' [-Wunused-variable]
  124 |   int c1 = 0, c2 = 0, p1 = 0, p2 = 0;
      |               ^~
joi2019_ho_t4.cpp:124:23: warning: unused variable 'p1' [-Wunused-variable]
  124 |   int c1 = 0, c2 = 0, p1 = 0, p2 = 0;
      |                       ^~
joi2019_ho_t4.cpp:124:31: warning: unused variable 'p2' [-Wunused-variable]
  124 |   int c1 = 0, c2 = 0, p1 = 0, p2 = 0;
      |                               ^~
joi2019_ho_t4.cpp: At global scope:
joi2019_ho_t4.cpp:191:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  191 | main()
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -