제출 #234371

#제출 시각아이디문제언어결과실행 시간메모리
234371Nodir_Bobiev앵무새 (IOI11_parrots)C++14
81 / 100
529 ms262148 KiB
#include "encoder.h" #include "encoderlib.h" #include <algorithm> int* get(int x){ int *cnt = new int[10]; if( __builtin_popcount(x) <= 3 ){ cnt[7] += 2; for( int j = 0; j < 8; j ++ ){ if( (x&(1<<j)) ) cnt[j] ++; } }else{ cnt[0] += 2; for( int j = 0; j < 8; j ++ ){ if( !(x&(1<<j)) ) cnt[j]++; } } return cnt; } void encode(int N, int M[]) { int len = std::min(32,N); for(int i=0; i<len; i++){ int *qnt = get(M[i]); for( int j = 0; j < 8; j ++ ){ while( qnt[j] -- ){ send((i<<3)+j); } } } for(int i=len; i<N; i++){ int *qnt = get(M[i]); for( int j = 0; j < 8; j ++ ){ while(qnt[j]--){ send(((i-32)<<3)+j); } } } }
#include "decoder.h" #include "decoderlib.h" #include <algorithm> int* get(int x){ int *cnt = new int[10]; if( __builtin_popcount(x) <= 3 ){ cnt[7] += 2; for( int j = 0; j < 8; j ++ ){ if( (x&(1<<j)) ) cnt[j] ++; } }else{ cnt[0] += 2; for( int j = 0; j < 8; j ++ ){ if( !(x&(1<<j)) ) cnt[j]++; } } return cnt; } void decode(int N, int L, int X[]) { int cnt[N][10]={}; for( int i = 0; i < L; i ++ ){ int x = X[i]; int y = x % 8; int z = (x / 8); cnt[z][y] ++; } int ans[N] = {}, len = std::min(32, N); for( int i = 0; i < len; i ++ ){ if( N-len > i ){ bool ff = false; for( int x = 0; x <= 255; x ++ ){ if( ff )break; for( int y = 0; y <= 255; y ++ ){ int *qnt1 = get( x ), *qnt2 = get(y); int qnt[10] = {}; for( int j = 0; j < 8; j ++ ){ qnt[j] = qnt1[j] + 2*qnt2[j]; } ff = true; for( int j = 0; j < 8; j ++ ){ if( qnt[j] != cnt[i][j] ) ff = false; } if( ff ){ ans[i] = x; ans[i+len] = x; break; } } } }else{ for( int x = 0; x <= 255; x ++ ){ int *qnt = get(x); bool ff = true; for( int j = 0; j < 8; j ++ ){ if( cnt[i][j] != qnt[j] ) ff = false; } if( ff ){ ans[i] = x; break; } } } } for( int i = 0; i < N; i ++ ){ output(ans[i]); } }
#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...