# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
925397 | bachhoangxuan | Ancient Machine (JOI21_ancient_machine) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;
namespace{
int F[50];
}
int bit_to_fib(string s){
int total=0,pos=39;
while(pos>=0){
if(s[pos]=='1') total+=F[pos],pos-=2;
else pos--;
}
return total;
}
void Anna(int N, std::vector<char> S) {
F[0]=1;F[1]=2;
for(int i=0;i<=40;i++) F[i]=(F[i-1]+F[i-2]);
int f=-1,lst=-1;
string res;
for(int i=0;i<N;i++){
if(f==-1){
if(S[i]=='X') f=i;
res+='0';
}
else if(S[i]=='Z'){
if(S[i-1]=='Z') res.back()='0';
res+='1';
}
else res+='0';
}
while(N%40!=0) res+='0',N++;
if(f==-1) f=(1<<17)-1;
for(int i=0;i<17;i++) Send(f>>i&1);
for(int i=0;i<N;i+=40){
string cur;
for(int j=0;j<40;j++) cur+=S[i+j];
int total=bit_to_fib(cur);
for(int i=0;i<28;i++) Send(total>>i&1);
}
}
#include "Bruno.h"
#include<bits/stdc++.h>
using namespace std;
/*
namespace{
int F[50];
}
*/
string fib_to_bit(int total){
string res;
int pos=39;
while(pos>=0){
if(total>=F[pos]) res+="10",total-=F[pos],pos-=2;
else res+='0',pos--;
}
if((int)res.length()>40) res.pop_back();
reverse(res.begin(),res.end());
return res;
}
void Bruno(int N, int L,vector<int> A) {
F[0]=1;F[1]=2;
for(int i=2;i<=40;i++) F[i]=F[i-1]+F[i-2];
int f=0;
for(int i=0;i<17;i++) f+=A[i]<<i;
if(f>=N){
for(int i=0;i<N;i++) Remove(i);
return;
}
string s;
for(int i=0;i<(int)A.size()-17;i+=28){
int total=0;
for(int j=0;j<28;j++) total+=A[17+i+j]<<j;
s+=fib_to_bit(total);
}
while((int)s.length()>N) s.pop_back();
for(int i=0;i<f;i++) Remove(i);
int lst=f;
for(int i=f+1;i<N;i++){
if(s[i]=='1'){
for(int j=i-1;j>lst;j--) Remove(j);
Remove(i);lst=i;
}
}
for(int i=lst+1;i<N;i++) Remove(i);
Remove(f);
}