Submission #1069620

# Submission time Handle Problem Language Result Execution time Memory
1069620 2024-08-22T07:15:05 Z LittleOrange Bit Shift Registers (IOI21_registers) C++17
35 / 100
1 ms 348 KB
#include "registers.h"
#include<bits/stdc++.h>
using namespace std;
using ll = int;
const ll m = 100, b = 2000;

void construct_instructions(int s, int n, int k, int q) {
	auto get_num = [&](ll t, ll x, ll i){
		append_left(t,x,b-(i+1)*k);
		append_right(t,t,b-k);
		//append_print(t);
	};
	auto create_mask = [&](ll x, ll y){
		vector<bool> ret(b,0);
		ll c = b/(x+y);
		for(ll i = 0;i<b;i++){
			ret[i] = i%(x+y)<x;
		}
		return ret;
	};
	auto create_mask0 = [&](ll x, ll y){
		vector<bool> ret(b,0);
		ll c = b/(x+y);
		for(ll i = 0;i<b;i++){
			ret[i] = i%(x+y)>=x;
		}
		return ret;
	};
	vector<bool> zero(b,0);
	vector<bool> one(b,0);
	one[0] = true;
	if (s==0){
		ll bn = 1<<(__lg(n-1)+1);
		vector<bool> ad(b,0);
		for(ll i = n;i<bn;i++) for(ll j = 0;j<k;j++) ad[i*k+j] = 1;
		append_store(30,ad);
		append_or(0,0,30);
		for(ll h = bn/2;h>0;h/=2){
			append_store(40,create_mask(k*h,k*h+h*2));
			append_right(51,0,k*h);
			append_and(52,51,40);
			append_and(0,0,40);
			append_left(53,52,k*h+h);
			append_or(0,0,53);
		}
		k++;
		for(ll w = k;w<k*bn;w*=2){
			append_store(21,create_mask(w,w));
			append_store(22,create_mask(w*2-1,1));
			append_right(2,0,w);
			append_and(2,21,2);
			append_and(1,0,21);
			if (w==1){
				append_and(0,1,2);
				continue;
			}
			append_not(3,2);
			//append_store(23,create_mask(1,w*2-1));
			append_and(3,3,22);
			//append_add(4,1,2);
			append_add(5,1,3);
			//append_add(5,5,23);
			append_right(6,5,w-1);
			append_and(6,6,21);
			append_right(7,6,1);
			append_or(6,7,6);
			append_not(7,6);
			append_and(2,2,7);
			append_and(1,1,6);
			append_or(0,1,2);
		}
		/*get_num(1,0,0);
		append_store(m-1,one);
		auto neg = [&](ll t, ll x){
			append_not(t,x);
			append_add(t,t,m-1);
		};
		auto abs = [&](ll t, ll x, ll tmp){
			neg(t,x);
			append_right(tmp,x,b-k);
			append_and(tmp,t,tmp);
			append_not(t,x);
			append_right(t,t,b-k);
			append_and(t,t,x);
			append_add(t,t,tmp);
		};
		auto uabs = [&](ll t, ll x, ll tmp){
			neg(t,x);
			append_not(tmp,x);
			append_right(tmp,tmp,b-k*2);
			append_and(tmp,t,tmp);
			append_right(t,x,b-k*2);
			append_and(t,t,x);
			append_add(t,t,tmp);
		};
		for(ll i = 1;i<n;i++){
			get_num(2,0,i);
			neg(3,2);
			append_add(3,1,3);
			uabs(4,3,5);
			//append_print(4);
			//append_print(4);
			append_add(3,1,2);
			//append_print(3);
			append_add(3,3,4);
			//append_print(3);
			append_left(1,3,b-k-1);
			append_right(i+1<n,1,b-k);
		}*/
	}else{
		append_store(m-1,one);
		auto neg = [&](ll t, ll x){
			append_not(t,x);
			append_add(t,t,m-1);
		};
		auto abs = [&](ll t, ll x, ll tmp){
			neg(t,x);
			append_right(tmp,x,b-k);
			append_and(tmp,t,tmp);
			append_not(t,x);
			append_right(t,t,b-k);
			append_and(t,t,x);
			append_add(t,t,tmp);
		};
		auto uabs = [&](ll t, ll x, ll tmp){
			neg(t,x);
			append_not(tmp,x);
			append_right(tmp,tmp,b-k*2);
			append_and(tmp,t,tmp);
			append_right(t,x,b-k*2);
			append_and(t,t,x);
			append_add(t,t,tmp);
		};
		auto ord = [&](ll l, ll r, ll tmp1, ll tmp2){
			neg(tmp1,r);
			append_add(tmp1,tmp1,l);
			append_add(l,l,r);
			abs(tmp2,tmp1,r);
			neg(tmp1,tmp2);
			append_add(r,l,tmp2);
			append_add(l,l,tmp1);
			append_right(l,l,1);
			append_right(r,r,1);
		};
		for(ll i = 0;i<n;i++){
			get_num(i+1,0,i);
			//append_print(i+1);
		}
		for(ll j = n-1;j>0;j--){
			for(ll i = 0;i<j;i++){
				ord(i+1,i+2,m-2,m-3);
				//append_print(i+1);
				//append_print(i+2);
			}
		}
		append_store(0,zero);
		for(ll i = 0;i<n;i++){
			if(i)append_left(i+1,i+1,i*k);
			append_or(0,0,i+1);
		}
	}
}

Compilation message

registers.cpp: In lambda function:
registers.cpp:15:6: warning: unused variable 'c' [-Wunused-variable]
   15 |   ll c = b/(x+y);
      |      ^
registers.cpp: In lambda function:
registers.cpp:23:6: warning: unused variable 'c' [-Wunused-variable]
   23 |   ll c = b/(x+y);
      |      ^
registers.cpp: In function 'void construct_instructions(int, int, int, int)':
registers.cpp:125:8: warning: variable 'uabs' set but not used [-Wunused-but-set-variable]
  125 |   auto uabs = [&](ll t, ll x, ll tmp){
      |        ^~~~
registers.cpp:21:7: warning: variable 'create_mask0' set but not used [-Wunused-but-set-variable]
   21 |  auto create_mask0 = [&](ll x, ll y){
      |       ^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 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 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Wrong answer detected in grader
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Wrong answer detected in grader
4 Halted 0 ms 0 KB -