This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000000;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
/*
文鳥は数を覚えるほど頭がよくない🐣
最適nCr階乗進数->きつい
1つあたり4つのbit、5羽で行わなければならない
0を3つ、1を5つ 56
0を3つ、1を6つ 84
🐣 0 1 2 3 4 5 6 7
通 1 4 10 20 35 56 84 120
WA 50 70 126
(WAは0ひとつ多い)
うまくするとよさそう
2bit 0を8つ、🐣10
43758 たりないね
4bit 0を16つ、🐣20
7307872110
4294967296に勝利!やったね!
ということで、4つづつに区切るとよさそう
これならllint型に収まった計算ができる
24,30 1e15
R<=4は絶対にひとつ足りない
スペースは16bitで、のこりも同じようにする
*/
void send(int in);
int oku=0;
int oumu[1000]={0};
llint sCb[17][21];//巣C文鳥🐣
array<int,16> buncho(llint num,int bun){
array<int,16>ans={0};
int i;
for(i=0;i<16;i++){
while(num>=sCb[15-i][bun]){num-=sCb[15-i][bun];bun--;ans[i]++;}
//cerr<<"num="<<num<<endl;
}
return ans;
}
void encode(int n,int m[]){
int i,j,k;
for(i=0;i<=16;i++){sCb[i][0]=1;}
for(j=0;j<=20;j++){sCb[0][j]=1;}
for(i=1;i<=16;i++){
for(j=1;j<=20;j++){
sCb[i][j]=sCb[i-1][j]+sCb[i][j-1];
}
}
for(i=0;i<n;i+=4){
llint num=0,tori=0;
for(j=i;j<min(i+4,n);j++){tori+=5;num*=256;num+=m[j];}
auto ret=buncho(num,tori);
for(j=0;j<16;j++){
for(k=0;k<ret[j];k++){send(4*i+j);}
}
}
}
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000000;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
void output(int in);
llint SCB[17][21]={0};
llint piyo(array<int,16> in,int bun){
int i;
llint num=0;
for(i=0;i<16;i++){
while(in[i]>0){in[i]--;num+=SCB[15-i][bun];bun--;}
}
return num;
}
void decode(int n,int L,int X[]){
int i,j,k;
int kta[256]={0};
for(i=0;i<L;i++){kta[X[i]]++;}
for(i=0;i<=16;i++){SCB[i][0]=1;}
for(j=0;j<=20;j++){SCB[0][j]=1;}
for(i=1;i<=16;i++){
for(j=1;j<=20;j++){
SCB[i][j]=SCB[i-1][j]+SCB[i][j-1];
}
}
for(i=0;i<n;i+=4){
array<int,16>in={0};
for(j=0;j<16;j++){in[j]=kta[4*i+j];}
int bro=min(n-i,4);
llint num=piyo(in,bro*5);
while(bro>0){
bro--;
llint me=num/(1LL<<(bro*8));
num-=me*(1LL<<(bro*8));
output(me);
}
}
return;
}
Compilation message (stderr)
decoder.cpp: In function 'void decode(int, int, int*)':
decoder.cpp:64:10: warning: unused variable 'k' [-Wunused-variable]
int i,j,k;
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |