#include "registers.h"
#include <bits/stdc++.h>
using namespace std;
void construct_instructions(int s, int n, int k, int q) {
const int b = 2000;
if(s == 0 && n == 2 && k <= 2) {
if(k == 1) {
append_right(1, 0, 1);
vector<bool> oh(b);
oh[0] = 1;
append_store(2, oh);
append_and(0, 0, 2);
append_and(0, 0, 1);
return;
}
else {
append_right(1, 0, 2);
vector<bool> oh(b);
oh[0] = oh[1] = 1;
append_store(2, oh);
append_and(0, 0, 2);
for(int i=0; i<3; i++) {
append_move(2, 1);
for(int j=0; j<k; j++) {
int tar = (i == 2 && j == k-1 ? 0 : 2);
append_add(tar, 0, 2);
append_right(tar, tar, 1);
}
if(i < 2) append_move(0, 2);
}
return;
}
}
if(s == 0 && q == 4000) {
vector<bool> init2(b);
for(int i=0; i<b; i++) init2[i] = 1;
vector<bool> init(b);
for(int i=0; i<k; i++) init[i] = 1;
append_store(4, init2);
append_store(5, init);
append_move(1, 0);
append_and(1, 1, 5);
append_right(0, 0, k);
for(int i=1; i<n; i++) {
append_move(2, 0);
append_and(2, 2, 5);
append_right(0, 0, k);
append_not(3, 2);
append_add(3, 3, 1);
append_right(3, 3, 1999);
append_add(3, 3, 4);
append_and(2, 2, 3);
append_not(3, 3);
append_and(1, 1, 3);
append_add(1, 1, 2);
}
append_move(0, 1);
return;
}
if(s == 0) {
vector<bool> w(b);
for(int i=0; i<b; i++) w[i] = 0;
for(int i=0; i<n; i++) w[(i+1)*k - 1] = 1;
append_store(2, w);
vector<bool> v(b);
v[0] = 1;
for(int i=1; i<n*k; i++) v[i] = 0;
for(int i=n*k; i<b; i++) v[i] = 1;
append_store(4, v); //r[4] = - (2^nk - 1) forever
vector<bool> c(b);
c[0] = 1;
append_store(6, c); //r[6] = 1 forever
for(int i=k-1; i>=0; i--) {
append_and(1, 0, 2);
if(k-1 > i) append_left(1, 1, k-1 - i);
append_right(3, 1, k-1);
append_not(3, 3);
append_add(5, 1, 3);
append_add(5, 5, 6);
append_or(1, 1, 5);
append_add(7, 1, 4);
append_right(7, 7, 1999);
append_xor(7, 7, 6);
append_left(8, 7, i);
append_add(9, 9, 8);
if(i > 0) {
append_add(1, 1, 7);
append_right(2, 2, 1);
append_or(0, 0, 1);
}
}
append_move(0, 9);
return;
}
vector<bool> r[8];
for(int i=0; i<8; i++) r[i].resize(b);
for(int i=1; i<n; i+=2) {
for(int j=i*k; j<(i+1)*k; j++) {
r[3][j] = '1';
}
}
for(int i=0; i<n; i+=2) {
for(int j=i*k; j<(i+1)*k; j++) {
r[4][j] = '1';
}
}
r[5][0] = '1';
for(int i=1; i<=n; i+=2) {
r[6][i*k] = '1';
}
for(int i=2; i<=n; i+=2) {
r[7][i*k] = '1';
}
for(int i=3; i<=7; i++) {
append_store(i, r[i]);
}
for(int i=0; i<(n+1)/2; i++) {
append_move(1, 0);
append_right(2, 1, k);
append_or(1, 1, 3);
append_and(2, 2, 4);
append_not(2, 2);
append_add(1, 1, 2);
append_add(1, 1, 5);
append_and(1, 1, 6);
append_right(8, 1, k);
append_not(8, 8);
append_add(1, 1, 8);
append_add(1, 1, 5);
append_right(2, 0, k);
append_and(2, 2, 1);
append_xor(0, 0, 2);
append_left(2, 0, k);
append_left(1, 1, k);
append_and(2, 2, 1);
append_xor(0, 0, 2);
append_right(1, 1, k);
append_right(2, 0, k);
append_and(2, 2, 1);
append_xor(0, 0, 2);
append_move(1, 0);
append_right(2, 1, k);
append_or(1, 1, 4);
append_and(2, 2, 3);
append_not(2, 2);
append_add(1, 1, 2);
append_add(1, 1, 5);
append_and(1, 1, 7);
append_right(8, 1, k);
append_not(8, 8);
append_add(1, 1, 8);
append_add(1, 1, 5);
append_right(2, 0, k);
append_and(2, 2, 1);
append_xor(0, 0, 2);
append_left(2, 0, k);
append_left(1, 1, k);
append_and(2, 2, 1);
append_xor(0, 0, 2);
append_right(1, 1, k);
append_right(2, 0, k);
append_and(2, 2, 1);
append_xor(0, 0, 2);
append_print(0);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Correct |
0 ms |
288 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
280 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |