#include "registers.h"
#include <vector>
using namespace std;
constexpr static int B = 2000;
void construct_instructions(int s, int n, int k, int q) {
// pad with 1
vector<bool> ones_pad(B, false);
for(int i = n*k; i < 128*k; i++) ones_pad[i] = true;
append_store(1, ones_pad);
append_or(2, 0, 1);
int offset = 2;
vector<bool> first_bits_0[11];
for(int i = 1; i <= k; i++) {
first_bits_0[i].resize(B, false);
for(int j = 0; j < 128*k; j++) first_bits_0[i][j] = (j%k >= i);
}
for(int i = 0; (1<<i) < k; i++) append_store(80+(1<<i), first_bits_0[1<<i]);
vector<bool> last_bits_0[11];
for(int i = 1; i <= k; i++) {
last_bits_0[i].resize(B, false);
for(int j = 0; j < 128*k; j++) last_bits_0[i][j] = (j%k < k-i);
}
for(int i = 0; (1<<i) < k; i++) append_store(70+(1<<i), last_bits_0[1<<i]);
for(int j = 0; j < 7; j++) {
// offset holds "input"
// split to 2 parts
append_right(offset+1, offset, k<<(6-j));
append_xor(offset+2, offset, offset+1); // X
// most significant bit of xor
int a = 0;
for(int i = 0; (1<<i) < k; i++, a++) {
append_right(offset+3+3*i, offset+2+3*i, 1<<i);
append_and(offset+4+3*i, 70+(1<<i), offset+3+3*i);
append_or(offset+2+3*(i+1), offset+4+3*i, offset+2+3*i);
}
append_right(offset+3, offset+2+3*a, 1); // X = X ^ (X >> 1)
append_and(offset+4, 71, offset+3);
append_xor(offset+2, offset+4, offset+2+3*a); // X = X ^ (X >> 1)
// concat X+X
vector<bool> v(B, false);
for(int i = 0; i < (k<<(6-j)); i++) v[i] = true;
append_store(offset+3, v);
append_and(offset+4, offset+2, offset+3);
append_left(offset+3, offset+4, k<<(6-j));
append_or(offset+2, offset+3, offset+4); // X+X
append_and(offset+6, offset, offset+2); // B
// expand k-bit chunks of B
a = 0;
for(int i = 0; (1<<i) < k; i++, a++) {
append_left(offset+7+3*i, offset+6+3*i, 1<<i);
append_and(offset+8+3*i, 80+(1<<i), offset+7+3*i);
append_or(offset+6+3*(i+1), offset+8+3*i, offset+6+3*i);
}
for(int i = 0; (1<<i) < k; i++) {
append_right(offset+5+3*(a-i), offset+6+3*(a-i), 1<<i);
append_and(offset+4+3*(a-i), 70+(1<<i), offset+5+3*(a-i));
append_or(offset+6+3*(a-i-1), offset+4+3*(a-i), offset+6+3*(a-i));
}
append_not(offset+7, offset+6);
append_right(offset+8, offset+7, k<<(6-j));
append_not(offset+9, offset+8);
append_and(offset+10, offset, offset+9);
append_and(offset+11, offset+1, offset+8);
append_or(offset, offset+11, offset+10);
}
append_move(0, offset);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Wrong answer detected in grader |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Wrong answer detected in grader |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Incorrect sorting |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Incorrect sorting |
2 |
Halted |
0 ms |
0 KB |
- |