답안 #772955

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
772955 2023-07-04T13:29:31 Z PoonYaPat 앵무새 (IOI11_parrots) C++14
81 / 100
4 ms 1304 KB
#include "encoder.h"
#include "encoderlib.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> v;

void put(int x) {
  for (int i=0; i<8; ++i) {
    if (x&(1<<i)) v.push_back(1);
    else v.push_back(0);
  }
}

void encode(int N, int M[]) {
  v.clear();
  for (int i=0; i<N; ++i) put(M[i]);
  for (int i=0; i+1<v.size(); i+=2) {
    //consider bit i and i+1
    if (v[i]==v[i+1]) send(i+v[i]);
    else {
      send(i);
      if (v[i]==0) send(i);
      else send(i+1);
    }
  }
}
#include "decoder.h"
#include "decoderlib.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> ans,group[128];

void decode(int N, int len, int X[]) {
  ans.clear();
  for (int i=0; i<128; ++i) group[i].clear();
  for (int i=0; i<len; ++i) group[X[i]/2].push_back(X[i]%2);
  for (int i=0; i<128; ++i) {
    if (group[i].size()==0) break;
    if (group[i].size()==1) {
      ans.push_back(group[i][0]);
      ans.push_back(group[i][0]);
    } else {
      if (group[i][0]==group[i][1]) {
        ans.push_back(0);
        ans.push_back(1);
      } else {
        ans.push_back(1);
        ans.push_back(0);
      }
    }
  }
  for (int i=0; i+7<ans.size(); i+=8) {
    int res=0,mul=1;
    for (int j=0; j<8; ++j) {
      if (ans[i+j]==1) res+=mul;
      mul*=2;
    }
    output(res);
  }
}

Compilation message

encoder.cpp: In function 'void encode(int, int*)':
encoder.cpp:18:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |   for (int i=0; i+1<v.size(); i+=2) {
      |                 ~~~^~~~~~~~~

decoder.cpp: In function 'void decode(int, int, int*)':
decoder.cpp:27:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   for (int i=0; i+7<ans.size(); i+=8) {
      |                 ~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1044 KB Output is correct
2 Correct 2 ms 1044 KB Output is correct
3 Correct 2 ms 1052 KB Output is correct
4 Correct 2 ms 1044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 2 ms 1044 KB Output is correct
3 Correct 3 ms 1040 KB Output is correct
4 Correct 3 ms 1044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1032 KB Output is correct
2 Correct 2 ms 1008 KB Output is correct
3 Correct 3 ms 1056 KB Output is correct
4 Correct 3 ms 1200 KB Output is correct
5 Correct 3 ms 1196 KB Output is correct
6 Correct 4 ms 1304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 2 ms 1044 KB Output is partially correct - P = 6.562500
2 Partially correct 3 ms 1196 KB Output is partially correct - P = 6.218750
3 Incorrect 1 ms 724 KB Error : Bad encoded integer
4 Incorrect 1 ms 628 KB Error : Bad encoded integer
5 Incorrect 1 ms 652 KB Error : Bad encoded integer
6 Incorrect 0 ms 652 KB Error : Bad encoded integer
7 Incorrect 1 ms 652 KB Error : Bad encoded integer