답안 #771813

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
771813 2023-07-03T09:41:48 Z marvinthang 레지스터 (IOI21_registers) C++17
100 / 100
1 ms 468 KB
/*************************************
*    author: marvinthang             *
*    created: 03.07.2023 11:51:54    *
*************************************/

#include "registers.h"
#include <bits/stdc++.h>

using namespace std;

#define                  fi  first
#define                  se  second
#define                left  ___left
#define               right  ___right
#define                TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define             MASK(i)  (1LL << (i))
#define           BIT(x, i)  ((x) >> (i) & 1)
#define  __builtin_popcount  __builtin_popcountll
#define              ALL(v)  (v).begin(), (v).end()
#define           REP(i, n)  for (int i = 0, _n = (n); i < _n; ++i)
#define          REPD(i, n)  for (int i = (n); i--; )
#define        FOR(i, a, b)  for (int i = (a), _b = (b); i < _b; ++i) 
#define       FORD(i, b, a)  for (int i = (b), _a = (a); --i >= _a; ) 
#define       FORE(i, a, b)  for (int i = (a), _b = (b); i <= _b; ++i) 
#define      FORDE(i, b, a)  for (int i = (b), _a = (a); i >= _a; --i) 
#define        scan_op(...)  istream & operator >> (istream &in, __VA_ARGS__ &u)
#define       print_op(...)  ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#ifdef LOCAL
    #include "debug.h"
#else
    #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
    #define DB(...) 23
    #define db(...) 23
    #define debug(...) 23
#endif

template <class U, class V> scan_op(pair <U, V>)  { return in >> u.first >> u.second; }
template <class T> scan_op(vector <T>)  { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class U, class V> print_op(pair <U, V>)  { return out << '(' << u.first << ", " << u.second << ')'; }
template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")";  else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); }
template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); }
template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; }

// end of template

const int B = 2000;
const int M = 100;

void construct_instructions(int s, int n, int k, int q) {
	vector <bool> r_rem(B);
	fill(n * k + ALL(r_rem), true);
	append_store(1, r_rem);
	append_or(0, 0, 1);
	if (!s) {
		for (int i = 0; MASK(i) < n; ++i) {
			int cur = 2;
			int dist = MASK(i) * k;
			vector <bool> r_odd(B), r_even(B), r_full(B), r_x1(B);
			REP(i, B) {
				int t = (i / dist) & 1;
				r_odd[i] = t;
				r_even[i] = !t;
				t = i % (2 * dist);
				r_full[i] = t < k;
				r_x1[i] = t == k;
			}
			int odd = cur++, even = cur++;
			append_store(odd, r_odd);
			append_and(odd, 0, odd);
			append_right(odd, odd, dist);
	 
			append_store(even, r_even);
			append_and(even, 0, even);
	 
			int full = cur++;
			append_store(full, r_full);
			int not_odd = cur++;
			append_xor(not_odd, odd, full);
			append_add(not_odd, not_odd, even);
			int x1 = cur++;
			append_store(x1, r_x1);
			append_and(not_odd, not_odd, x1);
			append_right(not_odd, not_odd, k);
			append_add(not_odd, not_odd, full);
	 
			append_and(even, even, not_odd);
			append_not(not_odd, not_odd);
			append_and(odd, odd, not_odd);
	 
			append_or(0, odd, even);
		}
		return;
	}
	vector <bool> r_podd(B), r_peven(B), r_full(B), r_x1(B), r_first(B);
	REP(i, B) {
		r_first[i] = i < k;
		int t = (i / k) & 1;
		r_podd[i] = t;
		r_peven[i] = !t;
		t = i % (2 * k);
		r_full[i] = t < k;
		r_x1[i] = t == k;
	}
	int podd = 1, peven = 2, full = 3, x1 = 4, first = 5;
	append_store(podd, r_podd);
	append_store(peven, r_peven);
	append_store(full, r_full);
	append_store(x1, r_x1);
	append_store(first, r_first);
	REP(love, n) {
		int cur = 6;
		int odd = cur++, even = cur++;
		append_and(odd, 0, podd);
		append_right(odd, odd, k);

		append_and(even, 0, peven);
		if (love & 1) append_right(even, even, 2 * k);

		int not_odd = cur++;
		append_xor(not_odd, odd, full);
		append_add(not_odd, not_odd, even);
		append_and(not_odd, not_odd, x1);
		append_right(not_odd, not_odd, k);
		append_add(not_odd, not_odd, full);

		int xor_ov = cur++;
		append_xor(xor_ov, odd, even);

		append_and(even, even, not_odd);
		append_not(not_odd, not_odd);
		append_and(odd, odd, not_odd);
		int mi = cur++;
		append_or(mi, odd, even);
		int ma = cur++; 
		append_xor(ma, mi, xor_ov);
		append_left(ma, ma, k);
		append_or(mi, mi, ma);
		if (love & 1) {
			append_and(0, 0, first);
			append_left(mi, mi, k);
			append_or(0, 0, mi);
		} else append_move(0, mi);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 432 KB Output is correct
7 Correct 1 ms 468 KB Output is correct