Submission #394450

#TimeUsernameProblemLanguageResultExecution timeMemory
394450MarcoMeijerParrots (IOI11_parrots)C++14
98 / 100
32 ms1344 KiB
#include "encoder.h"
#include "encoderlib.h"
#include <bits/stdc++.h>
using namespace std;

// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e9
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define sz size()
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll getWays(int dif, int len) {
    if(dif == 0) return 0;
    vector<vll> dp;
    dp.assign(len,vll(dif,0));
    RE(i,dif) dp[0][i] = i+1;
    REP(i,1,len) RE(j,dif) {
        if(j) dp[i][j] += dp[i][j-1];
        dp[i][j] += dp[i-1][j];
    }
    return dp[len-1][dif-1];
}
vll encode(int x, int mx, int len) {
    if(len == 0) return {};
    RE1(i,mx) {
        if(getWays(i,len) >= x) {
            vll res = encode(x-getWays(i-1,len), i, len-1);
            res.pb(i);
            return res;
        }
    }
    return {};
}

void encode(int N, int M[]) {
    const int DIF = 5;
    const int LEN = 7;
    RE(i,N) {
        vll v = encode(M[i]+1, DIF, LEN);
        FOR(j,v) j-=2;
        RE(j,7)
            if(v[j] != -1)
                send((i<<2)|v[j]);
    }
}
#include "decoder.h"
#include "decoderlib.h"
#include <bits/stdc++.h>
using namespace std;

// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e9
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define sz size()
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll getWays(int dif, int len) {
    if(dif == 0) return 0;
    vector<vll> dp;
    dp.assign(len,vll(dif,0));
    RE(i,dif) dp[0][i] = i+1;
    REP(i,1,len) RE(j,dif) {
        if(j) dp[i][j] += dp[i][j-1];
        dp[i][j] += dp[i-1][j];
    }
    return dp[len-1][dif-1];
}
int decode(vll v) {
    if(v.empty()) return 1;
    int last = v.back();
    v.pop_back();
    int res = decode(v);
    res += getWays(last-1, v.size()+1);
    return res;
}

void decode(int N, int L, int X[]) {
    vll dif[64];
    RE(i,L) {
        dif[X[i]>>2].pb((X[i]&3)+2);
    }
    RE(i,N) {
        while(dif[i].size() < 7) dif[i].pb(1);
        sort(all(dif[i]));
        output(decode(dif[i])-1);
    }
}
#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...