Submission #820228

# Submission time Handle Problem Language Result Execution time Memory
820228 2023-08-11T01:47:25 Z alvingogo Bit Shift Registers (IOI21_registers) C++17
100 / 100
1 ms 596 KB
#include "registers.h"
#include <bits/stdc++.h>
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;

const int m=100,b=2000;
void construct_instructions(int s, int n, int k, int q) {
	if(n==1){
		return;
	}
	if(s==0){
		vector<bool> le(b);
		int aw[8]={1,2,4,8,16,32,64,128};
		int p;
		for(int i=0;i<8;i++){
			if(n>aw[i]){
				continue;
			}
			p=i;
			break;
		}
		for(;n<aw[p];n++){
			for(int j=0;j<k;j++){
				le[n*k+j]=1;
			}
		}
		append_store(99,le);
		append_or(0,0,99);
		int w=2*k;
		while(p--){
			vector<bool> v(b),zero(b),one(b);
			for(int j=0;j<n*k;j+=w){
				for(int i=0;i<k;i++){
					v[j+i]=1;
				}
				one[j]=1;
			}
			append_store(98,v);
			append_store(97,one);
			append_right(1,0,w/2);
			append_and(0,0,98);
			append_and(1,1,98);
			append_xor(2,0,1);
			append_xor(1,1,98);
			int f=4;
			append_add(f,0,1);
			append_right(f,f,k);

			append_and(f,f,97);
			append_add(f,f,98);
			append_xor(f,f,98);
			append_and(f,f,2);
			append_xor(0,0,f);
			w<<=1;
		}
	}
	else{
		//freopen("a.txt","w",stdout);
		vector<bool> le(b);
		if(n%2==1){
			for(int i=n*k;i<(n+1)*k;i++){
				le[i]=1;
			}
			n++;
		}
		append_store(99,le);
		append_or(0,0,99);
		vector<bool> v[2],zero(b),one[2],kd(b);
		v[0].resize(b);
		v[1].resize(b);
		one[0].resize(b);
		one[1].resize(b);
		for(int i=0;i<k;i++){
			kd[i]=1;
			kd[n*k-i-1]=1;
		}
		append_store(96,kd);
		for(int j=0;j<n*k;j+=2*k){
			for(int i=0;i<k;i++){
				v[0][j+i]=1;
			}
			one[0][j]=1;
		}
		for(int j=k;j<n*k;j+=2*k){
			for(int i=0;i<k;i++){
				v[1][j+i]=1;
			}
			one[1][j]=1;
		}
		append_store(98,v[0]);
		append_store(97,one[0]);
		append_store(95,v[1]);
		append_store(94,one[1]);
		for(int l=0;l<n;l++){
			if(l%2){
				append_and(96,96,0);
			}
			append_right(1,0,k);
			append_and(0,0,98-(l%2)*3);
			append_and(1,1,98-(l%2)*3);

			append_xor(2,0,1);
			append_xor(3,1,98-(l%2)*3);
			int f=4;
			append_add(f,0,3);
			append_right(f,f,k);

			append_and(f,f,97-(l%2)*3);
			append_add(f,f,98-(l%2)*3);
			append_xor(f,f,98-(l%2)*3);
			append_and(f,f,2);

			append_xor(0,0,f);
			append_xor(1,1,f);
			append_left(1,1,k);
			append_or(0,0,1);
			if(l%2){
				append_or(0,0,96);
				append_store(96,kd);
			}
		}
	}
}

Compilation message

registers.cpp: In function 'void construct_instructions(int, int, int, int)':
registers.cpp:24:14: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   24 |   for(;n<aw[p];n++){
      |          ~~~~^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 536 KB Output is correct
7 Correct 1 ms 468 KB Output is correct