답안 #795214

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
795214 2023-07-27T07:33:57 Z Johann 레지스터 (IOI21_registers) C++17
100 / 100
2 ms 468 KB
#include "registers.h"
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<vvpii> vvvpii;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

void construct_instructions(int s, int n, int k, int q)
{

	vb mask;
	// mask for 1
	mask.assign(2000, 0);
	mask[0] = 1;
	append_store(98, mask);

	auto swap = [&](int a, int b, int filter)
	{
		// smaller stuff lands in a
		append_not(2, a);
		append_add(2, 2, 98);
		append_add(2, 2, b); // b - a
		{
			append_xor(3, a, 2);
			append_xor(3, b, 3);
			append_and(95, 3, filter); // filters the carrybits we prepared with the xor
			append_right(96, 95, k);
			append_not(96, 96);
			append_add(96, 96, 98);
			append_add(94, 95, 96); // with filter - (filter >> k) we build filters with k bits
		}
		append_xor(2, a, b);
		append_and(2, 2, 94);
		append_xor(a, a, 2);
		if (s == 1)
			append_xor(b, b, 2);
	};

	if (s == 0)
	{
		int next = 1;
		while (next < n)
			next *= 2;
		mask.assign(2000, 0);
		fill(mask.begin() + n * k, mask.begin() + next * k, 1);
		append_store(99, mask);
		append_or(0, 0, 99);
		while (next > 1)
		{
			append_right(1, 0, (next / 2) * k);
			vb filter;
			filter.assign(2000, 0);
			for (int i = 0; i < next / 2; ++i)
				filter[i * k + k] = 1;
			append_store(97, filter);
			swap(0, 1, 97);
			next >>= 1;
		}
	}
	else
	{
		// fill with large number
		mask.assign(2000, 0);
		fill(mask.begin() + n * k, mask.begin() + (n + 1) * k, 1);
		append_store(80, mask);
		append_or(0, 0, 80);		 // last block set
		append_right(81, 80, n * k); // first block set

		append_right(1, 0, (n / 2) * k);
		mask.assign(2000, 0);
		fill(mask.begin(), mask.begin() + (n / 2) * k, 1);
		append_store(82, mask); // first n/2 values
		append_and(0, 0, 82);	//

		mask.assign(2000, 0);
		for (int i = 0; i < n / 2; ++i)
			mask[i * k + k] = 1;
		append_store(97, mask); // filter

		// bubble sort
		for (int i = 0; i < (n + 1) / 2; ++i)
		{
			swap(1, 0, 97);
			append_and(50, 1, 81); // tmp;
			append_right(1, 1, k);
			swap(0, 1, 97);
			append_left(1, 1, k);
			append_or(1, 1, 50);
		}

		append_print(0);
		append_print(1);
		// reconstruct
		for (int i = 0; i < (n + 1) / 2; ++i)
		{
			append_and(11, 1, 81); // tmp
			append_right(1, 1, k);
			append_left(11, 11, 2 * i * k);
			append_or(10, 10, 11); // res
			append_and(11, 0, 81);
			append_right(0, 0, k);
			append_left(11, 11, 2 * i * k + k);
			append_or(10, 10, 11); // res
		}
		append_move(0, 10);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 424 KB Output is correct
7 Correct 1 ms 468 KB Output is correct