Submission #1094096

#TimeUsernameProblemLanguageResultExecution timeMemory
1094096AvianshParrots (IOI11_parrots)C++17
81 / 100
12 ms1416 KiB
#include <bits/stdc++.h> #include "encoder.h" #include "encoderlib.h" using namespace std; void encode(int n, int m[]) { int buf = ceil(log2(n)); int bufn = 3; string s=""; for(int i = 0;i<n;i++){ for(int j = 7;j>=0;j--){ if(1<<j&m[i]){ s+='1'; } else{ s+='0'; } } } //cout << "string generated: " << s << "\n"; int ind = 0; int curnum = bufn-1; for(int i = 0;i<(1<<buf)&&ind<s.size();i++){ int cur = i<<(8-buf); int par = 0; for(int i = 0;i<8-buf;i++){ //cout << "adding point at index: " << ind+i << "\n"; if(ind+i>=s.size()) continue; if(s[(ind+i)]=='1'){ par+=(1<<(8-buf-1-i)); } } //cout << "\n"; ind+=8-buf; cur+=par; for(int i = 0;i<(1<<curnum);i++){ //cout << "sending number: " << cur << "\n"; string c = ""; for(int i = 0;i<8;i++){ if(1<<i&cur){ c="1"+c; } else{ c="0"+c; } } //cout << c << "\n"; send(cur); } curnum--; if(curnum==-1){ curnum=bufn-1; i++; } i--; } }
#include <bits/stdc++.h> #include "decoder.h" #include "decoderlib.h" using namespace std; void decode(int n, int l, int x[]) { int buf = ceil(log2(n)); int bufn = 3; sort(x,x+l); string s = ""; map<int,int>mp[1<<buf]; for(int i = 0;i<l;i++){ //cout << "recieved: " << (x[i]>>(7-buf))<< " " << x[i]%(1<<(7-buf)) << "\n"; mp[x[i]>>(8-buf)][x[i]%(1<<(8-buf))]++; } for(int i = 0;i<(1<<(buf));i++){ //cout << "at: " << i << "\n"; for(int lim = bufn-1;lim>=0;lim--){ int mn = 1<<lim; for(pair<int,int>p:mp[i]){ if(p.second>=mn){ string c = ""; for(int i = 0;i<8-buf;i++){ if(1<<i&p.first){ c="1"+c; } else{ c="0"+c; } } s+=c; mp[i][p.first]-=mn; break; } } } //cout << s << "\n"; } //cout << "string found: " << s << "\n"; string curr = ""; int cn = 0; for(int i = 0;i<s.size();i++){ curr+=s[i]; if(i%8==7){ //cout << "geting num: " << curr << "\n"; int num = 0; for(int i = 0;i<8;i++){ if(curr[i]=='1'){ num+=1<<(7-i); } } //cout << "outputting: " << num << "\n"; output(num); cn++; if(cn==n){ return; } curr=""; } } }

Compilation message (stderr)

encoder.cpp: In function 'void encode(int, int*)':
encoder.cpp:25:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int i = 0;i<(1<<buf)&&ind<s.size();i++){
      |                               ~~~^~~~~~~~~
encoder.cpp:30:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |             if(ind+i>=s.size()) continue;
      |                ~~~~~^~~~~~~~~~

decoder.cpp: In function 'void decode(int, int, int*)':
decoder.cpp:44:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for(int i = 0;i<s.size();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...