제출 #970843

#제출 시각아이디문제언어결과실행 시간메모리
970843PenguinsAreCute앵무새 (IOI11_parrots)C++17
100 / 100
461 ms19808 KiB
#include "encoder.h" #include "encoderlib.h" #include <bits/stdc++.h> using namespace std; using ll = unsigned long long; // WHY MUST I CODE INT512 struct int512_en { ll a[8]; int512_en() {fill(a,a+8,0);} }; int512_en add_en(int512_en x, int512_en y) { int512_en z; for(int i=0;i<8;i++) { if(x.a[i]+y.a[i]<x.a[i]&&i<7) z.a[i+1]=1; z.a[i]+=(x.a[i]+y.a[i]); if(!z.a[i] && (x.a[i] || y.a[i]) && i<7) z.a[i+1]=1; } return z; } bool small_en(int512_en x, int512_en y) { for(int i=8;i--;) if(x.a[i]!=y.a[i]) return x.a[i]<y.a[i]; return 0; } int512_en neg_en(int512_en x) { int512_en y; for(int i=0;i<8;i++) y.a[i]=(~x.a[i]); int512_en z; z.a[0]=1; return add_en(y,z); } int512_en nck_en[518][256]; void init_en() { nck_en[0][0].a[0]=1; for(int i=1;i<518;i++) for(int j=0;j<256;j++) nck_en[i][j]=add_en(j?nck_en[i-1][j-1]:int512_en(),nck_en[i-1][j]); } void kth_seq_en(int st, int n, int512_en k, vector<int> &v) { if(!n) return; if(small_en(k,nck_en[n-st-1][-st])) {v.push_back(-st); kth_seq_en(st,n-1,k,v);} else kth_seq_en(st+1,n,add_en(k,neg_en(nck_en[n-st-1][-st])),v); } int512_en seq_no_en(int st, int n, int* a) { if(!n) return int512_en(); if(a[0]==-st) return seq_no_en(st,n,a+1); return add_en(seq_no_en(st+1,n,a),nck_en[n-st-1][-st]); } void encode(int N, int M[]) { init_en(); int512_en erm; for(int i=0;i<N;i++) erm.a[i>>3]|=((long long)(M[i])<<((i&7)<<3)); vector<int> v; kth_seq_en(-255,min(5*N,262),erm,v); for(auto i: v) send(i); }
#include "decoder.h" #include "decoderlib.h" #include <bits/stdc++.h> using namespace std; using ll = unsigned long long; // WHY MUST I CODE INT512 struct int512 { ll a[8]; int512() {fill(a,a+8,0);} }; int512 add(int512 x, int512 y) { int512 z; for(int i=0;i<8;i++) { if(x.a[i]+y.a[i]<x.a[i]&&i<7) z.a[i+1]=1; z.a[i]+=(x.a[i]+y.a[i]); if(!z.a[i] && (x.a[i] || y.a[i]) && i<7) z.a[i+1]=1; } return z; } bool small(int512 x, int512 y) { for(int i=8;i--;) if(x.a[i]!=y.a[i]) return x.a[i]<y.a[i]; return 0; } int512 neg(int512 x) { int512 y; for(int i=0;i<8;i++) y.a[i]=(~x.a[i]); int512 z; z.a[0]=1; return add(y,z); } int512 nck[518][256]; void init() { nck[0][0].a[0]=1; for(int i=1;i<518;i++) for(int j=0;j<256;j++) nck[i][j]=add(j?nck[i-1][j-1]:int512(),nck[i-1][j]); } void kth_seq(int st, int n, int512 k, vector<int> &v) { if(!n) return; if(small(k,nck[n-st-1][-st])) {v.push_back(-st); kth_seq(st,n-1,k,v);} else kth_seq(st+1,n,add(k,neg(nck[n-st-1][-st])),v); } int512 seq_no(int st, int n, int* a) { if(!n) return int512(); if(a[0]==st) return seq_no(st,n-1,a+1); return add(seq_no(st+1,n,a),nck[n-st-1][-st]); } void decode(int N, int L, int X[]) { init(); sort(X,X+L,greater<int>()); for(int i=0;i<L;i++) X[i]=-X[i]; int512 hi = seq_no(-255,L,X); for(int i=0;i<N;i++) output((hi.a[i>>3]>>((i&7)<<3))&255); }
#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...