QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#561729 | #1830. AND | Nam | WA | 8ms | 3660kb | C++14 | 2.0kb | 2024-09-13 09:39:53 | 2024-09-13 09:39:56 |
Judging History
answer
// #pragma GCC optimize("O3","unroll-loops")
#include <bits/stdc++.h>
using namespace std;
// #define
#define int long long
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define file "file"
#define __lcm(a, b) a * b / __gcd(a, b)
#define R(x) {cout << x << "\n"; return;}
#define coutf(x) cout << fixed << setprecision(x)
#define inter(a) cout << a << "\n"; fflush(stdout)
mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
// declare
const int N = 1e5;
int n;
bool ok;
vector <int> a, v;
void Back(vector <int> a)
{
if (!ok) return;
if (a.empty()) return;
if (a.size() == 1)
{
v.push_back(a.back());
return;
}
for (int i = 1; i < a.size(); ++i)
if ((a[i] & a[0]) != a[0])
{
ok = false;
return;
}
vector <int> x, y;
for (int i = 1; i < a.size(); ++i)
if ((a[i] & a[1]) == a[1]) x.push_back(a[i]);
else
{
y.push_back(a[i]);
if ((y.back() & y[0]) != y[0])
{
ok = false;
break;
}
}
if (!ok) return;
Back(x);
if (!ok) return;
v.push_back(a[0]);
Back(y);
}
void Solve()
{
ok = true;
cin >> n;
v.clear();
a.clear();
for (int i = 1; i <= n; ++i)
{
int x;
cin >> x;
a.push_back(x);
}
sort(all(a));
Back(a);
if (ok)
{
cout << v.size() << "\n";
for (int x : v) cout << x << ' ';
cout << "\n";
}
else cout << -1 << "\n";
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
if (fopen(file ".inp", "r"))
{
freopen (file ".inp", "r", stdin);
freopen (file ".out", "w", stdout);
}
int t = 1;
cin >> t;
while (t--)
Solve();
cerr << "\nTIME: " << 1000 * clock() / CLOCKS_PER_SEC << "ms.";
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3660kb
input:
3 1 5 3 0 1 2 2 1 2
output:
1 5 3 1 0 2 -1
result:
ok answer is correct (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 8ms
memory: 3628kb
input:
20000 5 16 13 5 15 20 5 11 0 13 2 17 5 13 12 8 10 18 5 1 8 16 19 5 5 9 12 3 10 13 5 7 0 14 3 16 5 10 3 9 11 6 5 1 0 4 18 14 5 1 10 5 9 12 5 10 18 16 20 17 5 7 8 19 6 1 5 18 7 4 5 12 5 17 4 6 11 7 5 1 0 12 2 15 5 0 15 7 5 4 5 16 3 4 10 14 5 16 0 2 18 14 5 0 16 20 5 3 5 8 9 10 4 6 5 19 2 12 20 13 5 16...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 5 15 7 5 4 0 -1 5 14 2 18 0 16 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 5 11 3 19 2 6 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 5 5 4 12 0 11 -1 5 10 8 0 18 16 -1 -1 -1 5 7 3 1 0 18 -1 -1 -1 -1 -1 -1 -1 ...
result:
wrong answer the participant did not find the answer for test 2 while jury did it (test case 2)