이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "encoder.h"
#include "encoderlib.h"
#ifndef EVAL
#include "grader.cpp"
#endif
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;
void encode(int N, int M[]){
int res = 0, ind = -1;
vector <int> ans, vec;
for(int i = 0; i < N; i++){
ans.pb(M[i]);
vec.pb(M[i]);
for(int bit = 0; bit < 4; bit++)
if(M[i]&(1<<bit))
res++;
for(int bit = 0; bit < 4; bit++)
if(M[i]&(1<<(bit+4)))
res += 2;
}
for(int k = 0; k < 256; k++){
for(auto &to : vec) to ^= k;
int cnt = 0;
for(int i = 0; i < N; i++){
for(int bit = 0; bit < 4; bit++)
if(vec[i]&(1<<bit))
cnt++;
for(int bit = 0; bit < 4; bit++)
if(vec[i]&(1<<(bit+4)))
cnt += 2;
}
if(cnt < res){
ind = k;
res = cnt;
ans = vec;
}
for(auto &to : vec) to ^= k;
}
vector <int> one;
for(int i = 0; i < N; i++){
int num = i;
for(int bit = 0; bit < 4; bit++){
if(ans[i]&(1<<bit)){
if(!bit) one.pb(num);
else if(bit == 1) one.pb(num+64);
else if(bit == 2) one.pb(num+128);
else one.pb(num+192);
}
}
for(int bit = 0; bit < 4; bit++){
if(ans[i]&(1<<(bit+4))){
if(!bit){
one.pb(num);
one.pb(num);
}
else if(bit == 1){
one.pb(num+64);
one.pb(num+64);
}
else if(bit == 2){
one.pb(num+128);
one.pb(num+128);
}
else{
one.pb(num+192);
one.pb(num+192);
}
}
}
}
for(auto to : one) send(to);
if(ind == -1){
for(int i = 0; i < 5; i++)
send(0);
}
else{
for(int i = 0; i < 4; i++){
send(ind);
}
}
}
#include "decoder.h"
#include "decoderlib.h"
#ifndef EVAL
#include "grader.cpp"
#endif
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;
void decode(int N, int L, int X[]){
vector <int> cnt(256), ans(N);
int flag = 1, xr;
for(int i = 0; i < L; i++){
cnt[X[i]]++;
}
if(cnt[0] > 4){
flag = 0;
cnt[0] -= 5;
}
else{
for(int i = 0; i < 256; i++){
if(cnt[i] > 3){
cnt[i] -= 4;
xr = i;
break;
}
}
}
for(int i = 0; i < 256; i++){
if(cnt[i] > 1){
cnt[i] -= 2;
int ind = 0, which = 0;
for(int bit = 0; bit < 6; bit++){
if(i&(1<<bit)) ind |= (1<<bit);
}
if((i&(1<<6)) && (i&(1<<7))) which = 7;
else if(i&(1<<7)) which = 6;
else if(i&(1<<6)) which = 5;
else which = 4;
ans[ind] |= (1<<which);
}
if(cnt[i]){
cnt[i]--;
int ind = 0, which = 0;
for(int bit = 0; bit < 6; bit++){
if(i&(1<<bit)) ind |= (1<<bit);
}
if((i&(1<<6)) && (i&(1<<7))) which = 3;
else if(i&(1<<7)) which = 2;
else if(i&(1<<6)) which = 1;
else which = 0;
ans[ind] |= (1<<which);
}
}
for(auto &to : ans){
if(flag) to ^= xr;
}
for(auto to : ans) output(to);
}
/*
8
0 0 1 1 0 0 1 0
6
1 255 13 26 49 216
*/
컴파일 시 표준 에러 (stderr) 메시지
decoder.cpp: In function 'void decode(int, int, int*)':
decoder.cpp:74:21: warning: 'xr' may be used uninitialized in this function [-Wmaybe-uninitialized]
74 | if(flag) to ^= xr;
| ~~~^~~~~
# | 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... |