제출 #23152

#제출 시각아이디문제언어결과실행 시간메모리
23152kdh9949Broken Device (JOI17_broken_device)C++14
100 / 100
46 ms2836 KiB
#include "Annalib.h"

void send(int x, int y){
	for(int t = 0; t < 3; t++, y /= 2) Set(x + 2 - t, y & 1);
}

void Anna(int N, long long X, int K, int P[]){
	int c[150] = {};
	for(int i = 0; i < K; i++) c[P[i]] = 1;
	int x[65] = {}, cnt = 0;
	for(int i = 0; i < 60; i++) x[i] = !!(X & (1LL << i));
	auto b = [](const int &x){ return __builtin_popcount(x); };
	for(int i = 0; i < 150; i += 3){
		int q = c[i] * 4 + c[i + 1] * 2 + c[i + 2];
		if(b(q) == 0){
            if(x[cnt]) send(i, 3 + 4 * x[cnt + 1]);
			else send(i, 4 + x[cnt + 1]);
			cnt += 2;
		}
		else if(b(q) == 1){
            if(q == 2){
				if(x[cnt]){
					send(i, 1);
					cnt++;
				}
                else{
					if(x[cnt + 1]) send(i, 5);
					else send(i, 4);
					cnt += 2;
                }
            }
            else{
				if(x[cnt]) send(i, q == 1 ? 6 : 1);
				else send(i, 2);
				cnt++;
            }
		}
		else send(i, 0);
		if(cnt >= 60) cnt = 60;
	}
}
#include "Brunolib.h"

static int v[8][2] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {0, 0}, {0, 1}, {1, 0}, {1, 1}};
static int c[8] = {0, 1, 1, 2, 2, 2, 1, 2};

long long Bruno( int N, int A[] ){
    long long X = 0;
    int cnt = 0;
    for(int i = 0; i < 150; i += 3){
		int t = A[i] * 4 + A[i + 1] * 2 + A[i + 2];
		for(int j = 0; j < c[t]; j++){
			X += (long long)v[t][j] << (cnt + j);
		}
		cnt += c[t];
    }
    return X;
}
#Verdict Execution timeMemoryGrader output
Fetching results...