Submission #1133561

#TimeUsernameProblemLanguageResultExecution timeMemory
1133561KhoaDuyBroken Device (JOI17_broken_device)C++20
100 / 100
38 ms1448 KiB
#include "Annalib.h"
#include<bits/stdc++.h>
using namespace std;
/*#define endl '\n'
string commu="";
void Set(int pos,int bit){
    commu[pos]=(bit+'0');
}*/
void Anna(int n,long long x,int k,int p[]){
    int broke[n]={0};
    for(int i=0;i<k;i++){
        broke[p[i]]=1;
    }
    string s="";
    for(int i=0;i<n;i++){
        s+='0';
    }
    string send="";
    while(x>0){
        send+=('0'+(x%2));
        x/=2;
    }
    while(send.length()<60){
        send+='0';
    }
    reverse(send.begin(),send.end());
    int ptr=0;
    for(int i=0;i<n;i+=3){
        if(broke[i]+broke[i+1]+broke[i+2]>=2||ptr>=send.length()){
            continue;
        }
        string temp="";
        if(broke[i]+broke[i+1]+broke[i+2]==1){
            temp+=send[ptr];
            ptr++;
        }
        else{
            temp+=send[ptr];
            ptr++;
            if(ptr<send.length()){
                temp+=send[ptr];
                ptr++;
            }
        }
        string t="000";
        if(temp=="11"){
            t="111";
        }
        else if(temp=="10"){
            t="110";
        }
        else if(temp=="00"){
            t="011";
        }
        else if(temp=="01"){
            t="001";
        }
        else if(temp=="1"){
            if(broke[i+1]){
                t="101";
            }
            else{
                t="010";
            }
        }
        else{
            if(broke[i]){
                if(ptr<send.length()){
                    temp+=send[ptr];
                    ptr++;
                }
                else{
                    temp+='0';
                }
                if(temp=="00"){
                    t="011";
                }
                else{
                    t="001";
                }
            }
            else{
                t="100";
            }
        }
        for(int j=0;j<3;j++){
            s[i+j]=t[j];
        }
    }
    for(int i=0;i<n;i++){
        Set(i,s[i]-'0');
    }
}
/*signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int q;
    cin >> q;
    while(q--){
        int n,k;
        long long x;
        cin >> n >> x >> k;
        n=150;
        while(commu.length()<n){
            commu+='0';
        }
        while(commu.length()>n){
            commu.pop_back();
        }
        for(int i=0;i<n;i++){
            commu[i]='0';
        }
        int p[k];
        for(int i=0;i<k;i++){
            cin >> p[i];
        }
        Anna(n,x,k,p);
        int a[n];
        for(int i=0;i<n;i++){
            a[i]=commu[i]-'0';
        }
        if(Bruno(n,a)==x){
            cout << "AC" << endl;
        }
        else{
            cout << "WA" << endl;
        }
    }
}*/
#include "Brunolib.h"
#include<bits/stdc++.h>
using namespace std;
/*#define endl '\n'
string commu="";
void Set(int pos,int bit){
    commu[pos]=(bit+'0');
}*/
long long Bruno(int n,int a[]){
    string mess="";
    for(int i=0;i<n;i+=3){
        string t="";
        for(int j=i;j<i+3;j++){
            t+=(a[j]+'0');
        }
        if(t=="111"){
            mess+="11";
        }
        else if(t=="110"){
            mess+="10";
        }
        else if(t=="011"){
            mess+="00";
        }
        else if(t=="001"){
            mess+="01";
        }
        else if(t=="101"||t=="010"){
            mess+="1";
        }
        else if(t=="100"){
            mess+="0";
        }
    }
    assert(mess.length()>=60);
    long long x=0;
    for(int i=0;i<60;i++){
        x=x*2+(mess[i]-'0');
    }
    return x;
}
/*signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int q;
    cin >> q;
    while(q--){
        int n,k;
        long long x;
        cin >> n >> x >> k;
        n=150;
        while(commu.length()<n){
            commu+='0';
        }
        while(commu.length()>n){
            commu.pop_back();
        }
        for(int i=0;i<n;i++){
            commu[i]='0';
        }
        int p[k];
        for(int i=0;i<k;i++){
            cin >> p[i];
        }
        Anna(n,x,k,p);
        int a[n];
        for(int i=0;i<n;i++){
            a[i]=commu[i]-'0';
        }
        if(Bruno(n,a)==x){
            cout << "AC" << endl;
        }
        else{
            cout << "WA" << endl;
        }
    }
}*/
#Verdict Execution timeMemoryGrader output
Fetching results...