#include "transfer.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(c) c.begin(), c.end()
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "LINE(" << __LINE__ << ") -> " <<"[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
string bin(int x){
string res;
for(int i = 30;i>=0;--i){
if(x&(1ll<<i))res+='1';
else res+='0';
}
while(!res.empty() && res[0]=='0')res.erase(res.begin());
return res;
}
int power(int x){
// is x a power of 2
while((x%2)==0)x/=2;
if(x==1)return 1;
return 0;
}
std::vector<int> get_attachment(std::vector<int> source) {
int v = 3;
int x = 0;
int cnt0 = count(all(source),0);
int cnt1 = count(all(source),1);
int imp = 1,N = source.size();
if(cnt0 < cnt1 || cnt0==(N+1)/2)imp = 0;
for(int i = 0;i<source.size();++i){
while(power(v))v++;
if(source[i]==imp)x+=v;
v++;
}
string s= bin(x);
vector<int>ret;
for(auto w : s)ret.pb(w-'0');
return ret;
}
/*
1
2 110101100
*/
std::vector<int> retrieve(std::vector<int> data) {
int N = 63;
if(data.size()>100)N = 255;
int cnt0 = 0,cnt1= 1;
for(int i = 0;i<N;++i){
if(data[i])cnt1++;
else cnt0++;
}
int imp = 1;
if(cnt0 < cnt1 || cnt0==(N+1)/2)imp = 0;
int bits = data.size()-N;
vector<int>ret;
if(bits==0){
for(int i = 0;i<data.size();++i)ret.pb(0);
return ret;
}
int v = 3, X = 0, Y = 0;
for(int i = 0;i<N;++i){
while(power(v))v++;
if(data[i]==imp)X+=v;
v++;
}
int pos = 0;
for(int i = data.size()-1;i>=N;--i){
if(data[i])Y+=(1ll<<pos);
pos++;
}
if(X==Y){
for(int i = 0;i<N;++i)ret.pb(data[i]);
return ret;
}
v = 3;
for(int i = 0;i<N;++i){
while(power(v))v++;
int nsum = X;
if(data[i]==imp)nsum-=v;
else nsum+=v;
if(nsum==Y){
for(int j = 0;j<i;++j)ret.pb(data[j]);
ret.pb((data[i]?0:1));
for(int j = i+1;j<N;++j)ret.pb(data[j]);
return ret;
}
v++;
}
for(int i = 0;i<N;++i)ret.pb(data[i]);
return ret;
}
Compilation message
transfer.cpp: In function 'std::vector<int> get_attachment(std::vector<int>)':
transfer.cpp:59:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(int i = 0;i<source.size();++i){
| ~^~~~~~~~~~~~~~
transfer.cpp: In function 'std::vector<int> retrieve(std::vector<int>)':
transfer.cpp:86:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for(int i = 0;i<data.size();++i)ret.pb(0);
| ~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
720 KB |
Output is correct |
2 |
Partially correct |
6 ms |
732 KB |
Partially correct |
3 |
Partially correct |
5 ms |
732 KB |
Partially correct |
4 |
Partially correct |
5 ms |
644 KB |
Partially correct |
5 |
Partially correct |
6 ms |
656 KB |
Partially correct |
6 |
Incorrect |
3 ms |
744 KB |
WA in grader: wrong source retrieval |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
162 ms |
2500 KB |
Output is correct |
2 |
Correct |
165 ms |
2488 KB |
Output is correct |
3 |
Correct |
171 ms |
2456 KB |
Output is correct |
4 |
Partially correct |
175 ms |
2496 KB |
Partially correct |
5 |
Partially correct |
185 ms |
2500 KB |
Partially correct |
6 |
Incorrect |
6 ms |
2500 KB |
WA in grader: wrong source retrieval |
7 |
Halted |
0 ms |
0 KB |
- |