Submission #761950

#TimeUsernameProblemLanguageResultExecution timeMemory
761950phoebeParrots (IOI11_parrots)C++17
0 / 100
7 ms1240 KiB
#include <bits/stdc++.h>
#include "encoder.h"
#include "encoderlib.h"
using namespace std;

#define ll long long

static const int maxx = 15;
static ll idx, dp[25][16];

ll raw_to_hash(vector<int> &v){
    ll re = 0;
    for (int i = 0; i < v.size(); i++){
        int rem_length = v.size() - i - 1;
        re += v[i] * pow(256, rem_length);
        // cout << re << endl;
    }
    return re;
}

ll cnt_encoded(int i, int x){
    if (dp[i][x] != -1) return dp[i][x];
    if (i == 0) return 1ll;
    ll re = 0;
    for (int y = x; y <= maxx; y++) re += cnt_encoded(i - 1, y);
    dp[i][x] = re;
    return re;
}

void actually_encode(int i, ll rem, int last){
    // cout << i << ' ' << rem << ' ' << last << endl;
    if (i == 0) return;
    for (int y = last; y <= maxx; y++){
        ll cnt = cnt_encoded(i - 1, y);
        if (rem > cnt) rem -= cnt;
        else{
            send(idx + y);
            // cout << y << ' ';
            actually_encode(i - 1, rem, y);
            return;
        }
        // cout << rem << ' ' << cnt << endl;
    }
}

void encode(int N, int M[]){
    fill(&dp[0][0], &dp[0][0] + 25 * 16, -1);
    int angie = 0;
    for (int i = 0; i < N; i += 4){
        idx = angie<<4; angie++;
        vector<int> v;
        for (int j = i; j < min(N, i + 4); j++){
            v.push_back(M[j]);
        }
        // for (auto k : v) cout << k << ' '; cout << endl;
        ll hash = raw_to_hash(v);
        // cout << "encoder hash: " << hash << endl;
        actually_encode(v.size() * 6, hash, 0);
        // cout << endl;
    }
    // cout << endl << endl;
}
#include <bits/stdc++.h>
#include "decoder.h"
#include "decoderlib.h"
using namespace std;

#define ll long long

static const int maxx = 15;
static ll dp[25][16];

ll cnt_decode(int i, int x){
    if (dp[i][x] != -1) return dp[i][x];
    if (i == 0) return 1ll;
    ll re = 0;
    for (int y = x; y <= maxx; y++) re += cnt_decode(i - 1, y);
    dp[i][x] = re;
    return re;
}

void actually_decode(int i, ll rem){
    // ll angie = 0;
    for (int j = 0; j < i; j++){
        int rem_length = i - j - 1;
        ll y = rem / pow(256, rem_length);
        // cout << y << ' ';
        output(y);
        rem %= (ll)pow(256, rem_length);
        // angie += y * pow(256, rem_length);
        // cout << angie << endl;
    }
    return;
    if (i == 0) return;
    for (int y = 0; y <= 255; y++){
        ll cnt = pow(256, i - 1);
        if (rem >= cnt) rem -= cnt;
        else{
            // cout << y << ' ';
            output(y);
            actually_decode(i - 1, rem);
            return;
        }
    }
}

void decode(int N, int L, int X[]){
    fill(&dp[0][0], &dp[0][0] + 25 * 16, -1);
    sort(X, X + L); 
    // for (int i = 0; i < L; i++) cout << X[i] << ' '; cout << endl;
    for (int i = 0; i < L; i += 4 * 6){
        vector<int> v;
        for (int j = i; j < min(L, i + 24); j++){
            v.push_back(X[j] % 16);
        }
        // for (auto k : v) cout << k << ' '; cout << endl;
        ll hash = 1;
        ll angie = 0;
        for (int j = 0; j < v.size(); j++){
            int sz = v.size() - j - 1;
            for (int x = (j == 0 ? 0 : v[j - 1]); x < v[j]; x++){
                hash += cnt_decode(sz, x);
            }
        }
        // cout << "decoder hash: " << hash << endl;
        actually_decode(v.size() / 6, hash);
    }
}

Compilation message (stderr)

encoder.cpp: In function 'long long int raw_to_hash(std::vector<int>&)':
encoder.cpp:13:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for (int i = 0; i < v.size(); i++){
      |                     ~~^~~~~~~~~~

decoder.cpp: In function 'void decode(int, int, int*)':
decoder.cpp:57:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         for (int j = 0; j < v.size(); j++){
      |                         ~~^~~~~~~~~~
decoder.cpp:56:12: warning: unused variable 'angie' [-Wunused-variable]
   56 |         ll angie = 0;
      |            ^~~~~
#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...