Submission #598758

# Submission time Handle Problem Language Result Execution time Memory
598758 2022-07-19T01:00:18 Z wiwiho Bit Shift Registers (IOI21_registers) C++17
71 / 100
1 ms 424 KB
#include "registers.h"

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define ef(a) emplace_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define tomax(a, b) ((a) = max((a), (b)))
#define tomin(a, b) ((a) = min((a), (b)))
#define topos(a) ((a) = (((a) % MOD + MOD) % MOD))
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

ll ifloor(ll a, ll b){
    if(b < 0) a *= -1, b *= -1;
    if(a < 0) return (a - b + 1) / b;
    else return a / b;
}

ll iceil(ll a, ll b){
    if(b < 0) a *= -1, b *= -1;
    if(a > 0) return (a + b - 1) / b;
    else return a / b;
}

const int B = 2000;
int s, n, k, q;

void solve0_round(int r){
    append_right(1, 0, (1 << r) * k);
    append_xor(2, 0, 1);
    if(r == 0) append_and(2, 2, 90);
    
    append_print(0);
    append_print(1);
    append_print(2);

    if(k == 1){
        append_move(3, 2);
    }
    for(int i = 1; i < k; i *= 2){
        if(i == 1){
            append_right(80, 2, i * 2 >= k ? k - i : i);
            append_or(3, 2, 80);
        }
        else{
            append_right(80, 3, i * 2 >= k ? k - i : i);
            append_or(3, 3, 80);
        }
        append_print(3);
    }
    
    append_print(3);
    append_add(3, 3, 91);
    append_print(3);
    append_right(3, 3, 1);
    append_print(3);

    append_and(4, 0, 3);
    if(r == 0) append_and(4, 4, 90);

    append_add(5, 4, 90);
    
    append_and(6, 5, 92);
    append_right(7, 6, k - 1);

    append_add(8, 5, 7);

    append_or(9, 8, 4);

    append_and(10, 9, 2);

    for(int i = 0; i <= 10; i++) append_print(i);
    
    append_xor(0, 0, 10);
    
    append_print(0);
}

void solve0(){
    
    /*
        0: S = A
        1: B
        2: A xor B
        3: highbit of 2
        4: A and (3)
        5: (4) + 0000 | 1111 | 0000 | 1111
        6: (5) & 0000 | 1000 | 0000 | 1000
        7: (6) >> (k-1)
        8: (5) + (7)
        9: (8) or (4) // done
        10: (9) and (2)
        ans: A ^ (10)


        90: 0000 | 1111 | 0000 | 1111
        91: 0000 | 0001 | 0000 | 0001
        92: 0000 | 1000 | 0000 | 1000
        
        80: temp

    */
    
    int tn = 1;
    while(tn < n) tn *= 2;
    vector<bool> tmp(B);
    for(int i = n * k; i < tn * k; i++) tmp[i] = true;
    if(tn != n){
        append_store(1, tmp);
        append_or(0, 0, 1);
    }

    fill(iter(tmp), false);
    for(int i = 0; i < tn * k; i++){
        if(i / k % 2 == 0) tmp[i] = true;
    }
    append_store(90, tmp);

    fill(iter(tmp), false);
    for(int i = 0; i < tn; i++){
        if(i % 2 == 0) tmp[i * k] = 1;
    }
    append_store(91, tmp);
    append_left(92, 91, k - 1);

    for(int i = 0; tn > 1; i++, tn /= 2){
        if(i == 1) append_and(0, 0, 90);
        solve0_round(i);
    }

}

int cnt = 0;
void solve1_get(int r, int num){
    cnt++;
    append_xor(3, 1, 2);
    append_and(4, 3, 81);
    
    if(k == 1){
        append_move(5, 4);
    }
    for(int i = 1; i < k; i *= 2){
        if(i == 1){
            append_right(90, 4, i * 2 >= k ? k - i : i);
            append_or(5, 4, 90);
        }
        else{
            append_right(90, 5, i * 2 >= k ? k - i : i);
            append_or(5, 5, 90);
        }
    }
    
    append_add(5, 5, 82);
    append_right(5, 5, 1);
    append_and(5, 5, 81);

    append_and(6, 5, 1);
    append_add(7, 6, 81);
    append_and(8, 7, 83);

    append_right(9, 8, k - 1);
    //append_xor(10, 9, 82);

    append_add(11, 80, 9);
    append_and(12, 11, 3);

    append_xor(1, 1, 12);
    append_xor(2, 2, 12);
    append_print(1);
    append_print(2);

    append_and(13, 1, 81);
    append_left(14, 13, num * k);
    append_or(0, 0, 14);

    append_right(1, 1, k);
    append_print(1);
    append_or(1, 1, 84);
    append_print(1);

    for(int i = 0; i <= 14; i++) append_print(i);
}

void solve1_round(int r){
    
    {
        vector<bool> tmp(B);
        for(int i = 0; i < n * k; i++){
            if(i / k / r % 2 == 0) tmp[i] = true;
        }
        append_store(80, tmp);
    }
    {
        vector<bool> tmp(B);
        for(int i = 0; i < n * k; i++){
            if(i / k % (2 * r) == 0) tmp[i] = true;
        }
        append_store(81, tmp);
        append_left(84, 81, (r - 1) * k);
    }
    {
        vector<bool> tmp(B);
        for(int i = 0; i < n * k; i++){
            if(i % (2 * r * k) == 0) tmp[i] = true;
        }
        append_store(82, tmp);
        append_left(83, 82, k - 1);
    }
    append_print(80);
    
    append_right(2, 0, k * r);
    append_and(1, 0, 80);
    append_and(2, 2, 80);

    append_print(0);
    {
        vector<bool> tmp(B);
        append_store(0, tmp);
    }

    append_print(0);
    append_print(1);
    append_print(2);
    cerr << 2 * r << "\n";
    for(int i = 0; i < 2 * r; i++){
        solve1_get(r, i);
    }
}

void solve1(){

    /*
        0: S
        1: L = S and (80)
        2: R = S >> r and (80)

        iter
        3: L xor R
        4: 3 and (81)

        5: highbit of (4)
        6: (5) and L
        7: (6) + (81)
        8: (7) and (83) // zero

        9: (8) >> (k-1)
        (X) 10: (9) xor (82) // swap
        11: (80) + (9)
        12: (11) and (3)

        new L: L xor (12)
        new R: R xor (12)

        13: L and (81)
        14: (13) << num * k
        new S: S or (14)

        new L: L >> k or (84)

        80: |0000|*r+|1111|*r
        81: |0000|*(2r-1)+|1111|
        82: |0000|*(2r-1)+|0001|
        83: |0000|*(2r-1)+|1000|
        84: |0000|*r+|1111|+|0000|*(r-1)

        90: temp
    */

    vector<bool> tmp(B);
    const int N = 16;
    for(int i = n * k; i < N * k; i++){
        tmp[i] = true;
    }
    append_store(80, tmp);
    append_or(0, 0, 80);
    append_print(0);

    n = N;
    
    for(int i = 1; i < n; i *= 2) solve1_round(i);
    cerr << cnt << "\n";
}

void construct_instructions(int _s, int _n, int _k, int _q){
    s = _s, n = _n, k = _k, q = _q;
    
    if(s == 0) solve0();
    else solve1();

}
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 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
# 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 Incorrect 1 ms 424 KB Incorrect sorting
4 Halted 0 ms 0 KB -