Submission #1325459

#TimeUsernameProblemLanguageResultExecution timeMemory
1325459adiyerParrots (IOI11_parrots)C++20
0 / 100
4 ms824 KiB
#include "encoder.h"
#include "encoderlib.h"
#include <bits/stdc++.h>

using namespace std;

void encode(int n, int a[]){
    int c[4] = {};
    for(int i = 0; i < n; i++){
        int k = (i << 2);
        int f1 = (a[i] >> 6) % 4;
        int f2 = (a[i] >> 4) % 4;
        int f3 = (a[i] >> 2) % 4;
        int f4 = (a[i] >> 0) % 4;
        c[f1]++, c[f2]++, c[f3]++, c[f4]++;
    }
    for(int i = 0; i < n; i++){
        int k = (i << 2);
        int f1 = (a[i] >> 6) % 4;
        int f2 = (a[i] >> 4) % 4;
        int f3 = (a[i] >> 2) % 4;
        int f4 = (a[i] >> 0) % 4;
        if(c[0] < c[3]){
            if(f1 == 3) f1 = 0;
            else if(f1 == 0) f1 = 3;
            if(f2 == 3) f2 = 0;
            else if(f2 == 0) f2 = 3;
            if(f3 == 3) f3 = 0;
            else if(f3 == 0) f3 = 3;
            if(f4 == 3) f4 = 0;
            else if(f4 == 0) f4 = 3;
        }
        for(int i = 0; i < f1; i++) send((k | 0));
        for(int i = 0; i < f2; i++) send((k | 1));
        for(int i = 0; i < f3; i++) send((k | 2));
        for(int i = 0; i < f4; i++) send((k | 3));
    }
    if(c[0] < c[3]){
        send(255);
        send(255);
        send(255);
        send(255);
    }
}
#include "decoder.h"
#include "decoderlib.h"
#include <bits/stdc++.h>

using namespace std;

void decode(int m, int n, int a[]){
    bool swp = 0;
    vector < int > pos[m];
    for(int i = 0; i < n; i++) pos[(a[i] >> 2)].push_back((a[i] % 4));
    if(m < 64){
        if(!pos[63].empty()) swp = 1;
    }
    else{
        int c[4] = {}; 
        for(int bit : pos[63]) c[bit]++;
        if(c[3] >= 4){ 
            swp = 1;
            sort(pos[63].begin(), pos[63].end());
            pos[63].pop_back(), pos[63].pop_back(), pos[63].pop_back(), pos[63].pop_back();
        }
    }
    for(int i = 0; i < m; i++){
        int out = 0;
        int cnt[4] = {};
        for(int bit : pos[i]) cnt[bit]++;
        for(int bit = 0; bit < 4; bit++){
            if(swp && cnt[bit] == 0) cnt[bit] = 3;
            else if(swp && cnt[bit] == 3) cnt[bit] = 0;
        }
        for(int bit = 0; bit < 4; bit++) out |= (cnt[bit] << (6 - bit * 2));
        output(out);
    }
}
#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...