# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1006182 | HishamAlshehri | Data Transfer (IOI19_transfer) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
vector<int> get_attachment(vector<int> source) {
int x = 0, cnt = 0;
for (int i = 0; i < source.size(); i++)
{
if (source[i])
{
x ^= (i + 1);
cnt++;
}
}
vector<int>ans = source;
while (x)
{
ans.push_back(x % 2);
x /= 2;
}
ans.push_back(cnt % 2);
return ans;
}
vector<int> retrieve(vector<int> data) {
int x1 = 0, k = data[data.size() - 1], cnt = 0;
int n = (data.size() > 255 ? 255 : 63);
for (int i = 0; i < n; i++)
{
if (data[i])
{
cnt++;
x1 ^= (i + 1);
}
}
int x2 = 0;
for (int i = n; i < data.size() - 1; i++)
{
x2 += data[i] * (1 << (i - n + 1));
}
if (x1 != x2 && cnt % 2 != k)
data[x2 ^ x1] ^= 1;
return vector<int>(data.begin(), data.begin() + n);
}
int main()
{
int t;
cin >> t;
while (t--)
{
vector<int> b;
int c;
cin >> c;
string s;
cin >> s;
for (int j = 0; j < s.size(); j++) {
b.push_back(int(s[j] - '0'));
}
vector<int>ans = retrieve(get_attachment(b));
for (int i = 0; i < ans.size(); i++)
{
if (ans[i] != b[i])
{
cout << "NO\n";
return 0;
}
}
cout << "YES\n";
}
}