제출 #1177371

#제출 시각아이디문제언어결과실행 시간메모리
1177371PagodePaiva레지스터 (IOI21_registers)C++20
10 / 100
1 ms744 KiB
#include "registers.h"
#include <bits/stdc++.h>

using namespace std;

/*
void append_move(int t, int y)
void append_store(int t, bool[] v)
void append_and(int t, int x, int y)
void append_or(int t, int x, int y)
void append_xor(int t, int x, int y)
void append_not(int t, int x)
void append_right(int t, int x, int p)
void append_right(int t, int x, int p)
void append_add(int t, int x, int y)*/

const int b = 2000;
vector <bool> v;
vector <bool> even, odd;
int kk;

void build_even(){
    append_and(1, 51, 0);
    append_left(1, 1, kk);
    append_and(2, 50, 0);
    append_right(2, 2, kk);
    append_or(1, 1, 2);
}

void build_odd(){
    append_and(1, 50, 0);
    append_left(1, 1, kk);
    append_and(2, 51, 0);
    append_right(2, 2, kk);
    append_or(1, 1, 2);
}

void construct_instructions(int s, int n, int kkk, int q) {
    kk = kkk;
    for(int i = 0;i < b;i++){
        if((i%kk) == kk-1) v.push_back(true);
        else v.push_back(false);
    }
    for(int i = 0;i < b;i++){
        if((i/kk)%2 == 0){
            even.push_back(true);
            odd.push_back(false);
        }
        else{
            even.push_back(false);
            odd.push_back(true);
        }
    }
    append_store(51, even);
    append_store(50, odd);
    for(int i = 0;i < n;i++){
        if(i%2 == 0) build_even();
        else build_odd();
        int k = kk-1;
        append_and(2, 1, 0);
        append_xor(3, 2, 0);
        append_xor(4, 2, 1);
        append_move(98, 2);
        append_store(97, v);
        k--;
        while(k >= 0){
            // 0 = a
            // 1 = b
            // 2 = p
            append_right(3, 3, 1); // 3 = x
            append_right(4, 4, 1); // 4 = y
            //append_print(3);
            //append_print(4);
            append_xor(5, 3, 4); // 5 = (x^y)
            append_not(6, 5); // 6 = -(x^y)
            append_and(7, 0, 4); // 7 = a and y
            append_and(8, 1, 3); // 8 = b and x
            append_or(9, 8, 7); // 9 = (a and y) or (b and x)
            append_and(10, 9, 5); // 10 = ((x^y)and((a and y) or (b and x)))
            append_and(11, 6, 98); // (-(x^y)) and (a and b)
            append_or(12, 11, 10); // p
            append_right(97, 97, 1);
          //  //append_print(97);
          //  //append_print(12);
            append_and(12, 12, 97); // p_k
            append_or(2, 12, 2); // p = p or p_k
            append_xor(13, 0, 2); // p^a
            append_or(3, 3, 13); // x = x and (p^a)
            append_xor(14, 1, 2); // p^b
            append_or(4, 4, 14); // y = y and (p^b)
            //append_print(2);
            k--;
        }
        append_move(53, 2);
        append_or(2, 1, 0);
        append_xor(3, 2, 0);
        append_xor(4, 2, 1);
        append_move(98, 2);
        append_store(97, v);
        append_and(2, 2, 97);
        k = kk-1;
        k--;
        append_print(0);
        append_print(1);
        while(k >= 0){
            // 0 = a
            // 1 = b
            // 2 = p
            append_right(3, 3, 1); // 3 = x
            append_right(4, 4, 1); // 4 = y
            //append_print(3);
            //append_print(4);
            append_xor(5, 3, 4); // 5 = (x^y)
            append_not(6, 5); // 6 = -(x^y)
            append_and(7, 0, 4); // 7 = a and y
            append_and(8, 1, 3); // 8 = b and x
            append_or(9, 8, 7); // 9 = (a and y) or (b and x)
            append_and(10, 9, 5); // 10 = ((x^y)and((a and y) or (b and x)))
            append_and(11, 6, 98); // (-(x^y)) and (a or b)
            append_or(12, 11, 10); // p
            append_right(97, 97, 1);
          //  //append_print(97);
          //  //append_print(12);
            append_and(12, 12, 97); // p_k
            append_or(2, 12, 2); // p = p or p_k
            append_xor(13, 0, 2); // p^a
            append_or(3, 3, 13); // x = x and (p^a)
            append_xor(14, 1, 2); // p^b
            append_or(4, 4, 14); // y = y and (p^b)
            k--;
        }
        append_move(54, 2);
        // 54 = max, 53 = min, 51 = even, 50 = odd
        append_print(53);
        append_print(54);
        if(i%2 == 0){
            append_and(54, 54, 50);
            append_and(53, 53, 51);     
            append_or(55, 53, 54);    
            if(n%2){
                append_right(56, 55, n*kk);
                append_left(56, 56, (n-1)*kk);
                append_or(0, 55, 56);            
            }   
            else{
                append_move(0, 55);
            
            }
        }
        else{
            append_and(54, 54, 51);
            append_and(53, 53, 50);
            append_or(55, 54, 53);
            if(n%2 == 0){
                append_right(56, 55, n*kk);
                append_left(56, 56, (n-1)*kk);
                append_or(0, 55, 56);            
            }
            else{
                append_move(0, 55);
            }
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...