제출 #1127918

#제출 시각아이디문제언어결과실행 시간메모리
1127918hmmBit Shift Registers (IOI21_registers)C++20
13 / 100
1 ms744 KiB
#include <bits/stdc++.h>
#include "registers.h"

void compare(int reg, int mins, int maxes, int n, int k, int odds = 99, int evens = 98, int ones = 97){ // uses registers [80, 86]
	// using register [80, 96] as temporary registers
	
	append_and( 80, reg, evens);
	append_and( 86, reg, odds);
	append_right(86, 86, k);

	append_not(81, 86); //no need to increment as swapping does not matter when equal
	append_and(81, 81, evens);

	append_add(82, 80, 81);

	append_and(82, 82, odds);
	
	int i;
	int a = 82, b = 83;
	for(i = 1; i <= k; i<<=1){
		append_right(b, a, i);
		append_or(b, b, a);
		a ^= b ^= a ^= b;
	}

	append_and(a, a, evens);
	append_not(b, a);

	append_and(84, 80, b);
	append_and(85, 86, a);
	append_or(mins, 84, 85);

	append_and(84, 80, a);
	append_and(85, 86, b);
	append_or(maxes, 84, 85);

}

void shuffle(int reg, int next, int n, int k, int temp0, int tempmax, int tempmin, int templast, int temp = 87){

	compare(reg, tempmin, tempmax, n, k);
	append_left(temp0, tempmin, 2000-k);
	append_right(temp0, temp0, 2000-k);
	append_right(templast, tempmax, k*(n-2));
	append_left(templast, templast, k*(n-1));

	append_left(tempmax, tempmax, 2000 - k*(n-2));
	append_right(tempmax, tempmax, 2000 - k*(n-2));
	append_right(tempmin, tempmin, k);

	append_or(temp, tempmin, tempmax);

	compare(temp, tempmin, tempmax, n, k);

	append_left(tempmin, tempmin, 1*k);
	append_left(tempmax, tempmax, 2*k);

	append_or(next, tempmin, tempmax);
	append_or(next, next, temp0);
	append_or(next, next, templast);
}

void construct_instructions(int s, int n, int k, int q) {
	std::vector<bool> odds(2000), evens(2000), ones(2000);
	for(int i = 0; i < n*k; i++){
		if( (i/k)%2 == 0 ){
			evens[i] = 1;
		} else {
			odds[i] = 1;
		}
		if( i%k == 0 ) ones[i] = 1;
	}

	append_store(99, odds);
	append_store(98, evens);
	append_store(97, ones);


	if(s == 1){
		for(int i=0; i<n; i++){
			shuffle(0, 0, n, k, 1, 2, 3, 4);
		}
	}

}
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...