#include "registers.h"
#include <iostream>
using namespace std;
/*
negative(B) = NOT(B) + 1
A - B = A + negative(B)
sign(A-B) = (A - B) >> b-1
abs(A - B) = {tmp = negative(sign(A - B)); return (A + tmp) ^ tmp}
max(A, A) = A + B + abs(A - B)
tmp = negative(sign(A-B))
A = 00000100 = 4
B = 00001010 = 10
A-B = -(00000110)
= 11111001
sign(A-B) = 00000001
tmp = -sign(A-B) = 11111111
-sign(00000001) = 11111111
-sign(00000000) = 00000000
abs(x) = (x + tmp) ^ tmp
sign(x) = x >> b-1
negative(x) = NOT(x) + 1
A - B = A + negative(B)
tmp = negative(sign(A-B))
abs(A - B) = ((A-B) + tmp) ^ tmp;
max(A, B) = A + B + abs(A - B)
min(A, B) = A ^ B ^ max(A, B)
*/
const int b = 2000;
const int m = 100;
void solve_1_2(int n, int k)
{
int A = 0;
int B = 1;
append_right(B, A, k);
vector<bool> v(b, 1);
for(int i = k; i < 2*k; i++)
v[i] = 0;
int clearnum2 = 2;
append_store(clearnum2, v);
append_and(A, A, clearnum2);
int one = 3;
vector<bool> v2(b, 0);
v2[0] = 1;
append_store(one, v2);
int not_B = 4;
append_not(not_B, B);
int negative_B = 5;
append_add(negative_B, not_B, one);
int A_minus_B = 6;
append_add(A_minus_B, A, negative_B);
int sign_A_minus_B = 7;
append_right(sign_A_minus_B, A_minus_B, b-1);
int not_sign_A_minus_B = 8;
append_not(not_sign_A_minus_B, sign_A_minus_B);
int tmp = 9;
append_add(tmp, not_sign_A_minus_B, one);
int A_minus_B_plus_tmp = 10;
append_add(A_minus_B_plus_tmp, A_minus_B, tmp);
int abs_A_minus_B = 11;
append_xor(abs_A_minus_B, A_minus_B_plus_tmp, tmp);
int A_plus_B = 12;
append_add(A_plus_B, A, B);
int max_A_B_x2 = 13;
append_add(max_A_B_x2, A_plus_B, abs_A_minus_B);
int max_A_B = 14;
append_right(max_A_B, max_A_B_x2, 1);
int A_xor_B = 15;
append_xor(A_xor_B, A, B);
int min_A_B = 16;
append_xor(min_A_B, A_xor_B, max_A_B);
int res = 0;
append_move(res, min_A_B);
}
void solve_3_4(int n, int k)
{
int A = 0;
append_left(A, A, k);
vector<bool> v(b, 0);
for(int i = n*k; i <= b-1; i++)
v[i] = 1;
int add_ones = m-1;
append_store(add_ones, v);
append_or(A, A, add_ones);
for(int bit = 0; bit < 7; bit++)
{
int B = 1;
append_right(B, A, k * (1 << bit));
}
}
//op, numbers, len of number, queries
//s == 0, n == 2
void construct_instructions(int s, int n, int k, int q)
{
if(s == 0 && n == 2 && k <= 2) solve_1_2(n, k);
else if(s == 0) solve_3_4(n, k);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Incorrect min value |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Incorrect min value |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Incorrect sorting |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Incorrect sorting |
2 |
Halted |
0 ms |
0 KB |
- |