Submission #497361

# Submission time Handle Problem Language Result Execution time Memory
497361 2021-12-23T03:45:17 Z PedroBigMan Bit Shift Registers (IOI21_registers) C++17
46 / 100
5 ms 1120 KB
/*
Author of all code: Pedro BIGMAN Dias
Last edit: 15/02/2021
*/
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <list>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
#include <cstring>
#include "registers.h"
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=(ll) a; i<(ll) b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define whole(x) x.begin(),x.end()
#define DEBUG(i) cout<<"Pedro Is The Master "<<i<<endl
#define INF 500000000LL
#define EPS 0.00000001
#define pi 3.14159
#define VV(vvvv,NNNN,xxxx); REP(i,0,NNNN) {vvvv.pb(xxxx);}
ll mod=1000000007LL;

template<class A=ll> 
void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;}

template<class A=ll>
void In(vector<A> &a, ll N) {A cur; REP(i,0,N) {cin>>cur; a.pb(cur);}} 

ll N,M,K,B,S;
vector<bool> lastbit;
vector<bool> all;
vector<bool> firstbit;
ll ava1,ava2,ava3;

void Order(ll a, ll b) //will replace register a with the minimum, register b with the maximum
{
	append_store(ava2,lastbit); append_store(ava3,firstbit);
	append_not(ava1,b); append_add(ava1,ava1,ava3); append_add(ava1,a,ava1); append_and(ava1,ava1,ava2); //now, at ava1, we have 0...01 if a is smaller than b, 0...00 else
	append_right(ava1,ava1,B-1); append_xor(ava1,ava1,ava3); append_store(ava2,all); append_add(ava1,ava1,ava2); //now, at ava1, 1...1 if a is smaller, 0...0 else
	append_and(ava2,a,ava1); //ava2 has a if a is smaller, 0...0 else
	append_not(ava1,ava1); append_and(ava1,b,ava1); //ava1 has b if b is smaller or equal, 0...0 else
	append_add(b,a,b); append_add(a,ava1,ava2); //b has sum of a and b, a has smallest of a,b
	if(S==1) {append_not(ava1,a); append_add(ava1,ava1,ava3); append_add(b,b,ava1);} //a has smallest, b has largest
}

void construct_instructions(int s, int n, int k, int q) 
{
	N = (ll) n; K = (ll) k; M = 100; B = 2000; S = (ll) s;
	VV(lastbit,B,false); lastbit[1999]=true; VV(all,B,true); VV(firstbit,B,false); firstbit[0]=true;
	REP(i,0,N-1) {append_move(i+1,0);} //now first N lines have line 0
	REP(i,0,N)
	{
		if(i==M-4) {continue;}
		append_left(i,i,B-(i+1)*K); append_right(i,i,B-K);
	}
	//now line i has number i
	ava1=M-1; ava2=M-2; ava3=M-3;
	if(S==0)
	{
		REP(i,1,N)
		{
			if(i==M-4)
			{
				ava1=1; ava2=2; ava3=3;
				REP(j,M-3,min(N,M)) {append_move(j,M-4);}
				REP(j,M-4,min(N,M)) {append_left(j,j,B-(j+1)*K); append_right(j,j,B-K);}
			}
			Order(0,i);
		}	
	}
	else
	{
		REP(i,0,N-1)
		{
			REP(j,i+1,N) {Order(i,j);}
		}
		REP(i,1,N) {append_left(i,i,i*K); append_add(0,0,i);}
	}
}

Compilation message

registers.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    5 | #pragma GCC optimization ("O3")
      | 
registers.cpp:6: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    6 | #pragma GCC optimization ("unroll-loops")
      |
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 4 ms 1120 KB Output is correct
3 Correct 3 ms 972 KB Output is correct
4 Correct 5 ms 992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Wrong answer detected in grader
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Incorrect 1 ms 696 KB Wrong answer detected in grader
4 Halted 0 ms 0 KB -