Submission #1058759

# Submission time Handle Problem Language Result Execution time Memory
1058759 2024-08-14T13:24:32 Z pcc Bit Shift Registers (IOI21_registers) C++17
35 / 100
1 ms 604 KB
#include "registers.h"
#include <bits/stdc++.h>
using namespace std;

#define OP_MOVE 0
#define OP_STORE 1
#define OP_AND 2
#define OP_OR 3
#define OP_XOR 4
#define OP_NOT 5
#define OP_LEFT 6
#define OP_RIGHT 7
#define OP_ADD 8
#define OP_MIN 9


const int M = 100;
const int B = 2000;
const int one = 1;
const int mask = 2;

int n,k;

void add_op(int tp,int t,int x,int y = -1);

void append_min(int ans,int a,int b){
	int ta = a,tb = b;
	a = 7,b = 8;
	add_op(OP_MOVE,a,ta);
	add_op(OP_MOVE,b,tb);
	int flag = 5;
	add_op(OP_NOT,flag,a);
	add_op(OP_AND,flag,mask,flag);
	add_op(OP_ADD,flag,b,flag);
	add_op(OP_ADD,flag,one,flag);
	add_op(OP_RIGHT,flag,flag,k);
	add_op(OP_AND,flag,one,flag);
	for(int j = 1;j<k;j<<=1){
		int tmp = 6;
		add_op(OP_LEFT,tmp,flag,j);
		add_op(OP_OR,flag,tmp,flag);
	}
	int rflag = 6;
	add_op(OP_NOT,rflag,flag);
	add_op(OP_AND,b,rflag,b);
	add_op(OP_AND,a,flag,a);
	add_op(OP_OR,ans,a,b);
	return;
}

void add_op(int tp,int t,int x,int y){
	if(tp == OP_MOVE)append_move(t,x);
	else if(tp == OP_AND)append_and(t,x,y);
	else if(tp == OP_OR)append_or(t,x,y);
	else if(tp == OP_XOR)append_xor(t,x,y);
	else if(tp == OP_NOT)append_not(t,x);
	else if(tp == OP_LEFT)append_left(t,x,y);
	else if(tp == OP_RIGHT)append_right(t,x,y);
	else if(tp == OP_ADD)append_add(t,x,y);
	else if(tp == OP_MIN)append_min(t,x,y);
	return;
}

void construct_instructions(int s, int nn, int kk, int q) {
	n = nn,k = kk;
	vector<bool> v(B,0);
	v[0] = 1;
	append_store(one,v);
	for(int i = 0;i<k;i++)v[i] = 1;
	append_store(mask,v);
	if(s == 0){
		int ans = 3;
		add_op(OP_MOVE,ans,0,ans);
		add_op(OP_AND,ans,mask,ans);
		for(int i = 1;i<n;i++){
			int b = 4;
			add_op(OP_RIGHT,b,0,i*k);
			add_op(OP_AND,b,mask,b);
			add_op(OP_MIN,ans,ans,b);
		}
		add_op(OP_MOVE,0,ans);
		return;
	}
	else{
		int head = 10;
		for(int i = 0;i<n;i++){
			add_op(OP_RIGHT,head+i,0,i*k);
			add_op(OP_AND,head+i,mask,head+i);
			append_print(head+i);
		}
		for(int i = 0;i<n;i++){
			for(int j = 0;j+1<n;j++){
				int t1 = 31,t2 = 32;
				add_op(OP_MIN,t1,head+j,head+j+1);
				add_op(OP_XOR,t2,head+j,head+j+1);
				append_print(head+j);
				append_print(head+j+1);
				append_print(t1);
				append_print(t2);
				add_op(OP_MOVE,head+j,t1);
				add_op(OP_XOR,head+j+1,t1,t2);
			}
		}
		add_op(OP_XOR,0,0,0);
		for(int i = 0;i<n;i++)append_print(head+i);
		for(int i = 0;i<n;i++){
			add_op(OP_LEFT,head+i,head+i,i*k);
			add_op(OP_OR,0,head+i,0);
		}
		return;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Wrong answer detected in grader
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Wrong answer detected in grader
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Incorrect 0 ms 348 KB Wrong answer detected in grader
4 Halted 0 ms 0 KB -