QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#243243 | #6728. To the Park | Cipherxzc# | WA | 81ms | 23884kb | C++20 | 2.8kb | 2023-11-07 22:52:21 | 2023-11-07 22:52:23 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define LL long long
#define mp make_pair
struct node{
vector<int> num;
int siz;
};
bool operator<(const node &a, const node &b){
return a.siz > b.siz;
}
const int N = 1e5 + 5;
int T, n, tot;
bool notp[N], used[N];
vector<int> p;
node all[N];
void Euler(int lim){
for (int i = 2; i <= lim; i++){
if (!notp[i]){
p.push_back(i);
}
for (int j = 0; j < p.size() && p[j] <= lim / i; j++){
notp[i * p[j]] = true;
if (i % p[j] == 0){
break;
}
}
}
}
// void dfs2(int pos, LL x){
// if (pos == now.size()){
// all[tot].num.push_back(x);
// return;
// }
// while (x * now[pos] <= n){
// x *= now[pos];
// dfs2(pos + 1, x);
// }
// }
void get(int x){
for (int i = x; i <= n; i += x){
all[tot].num.push_back(i);
}
}
void dfs(int pos, LL x, int cnt){
//cout << pos << endl;
if (pos == p.size()){
return;
}
if (x * p[pos] > n){
return;
}
dfs(pos + 1, x, cnt);
tot++;
all[tot].siz = cnt + 1;
x *= p[pos];
get(x);
dfs(pos + 1, x, cnt + 1);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
Euler(1e5);
cin >> T;
while (T--){
cin >> n;
for (int i = 1; i <= tot; i++){
all[i].num.clear();
}
for (int i = 1; i <= n; i++){
used[i] = false;
}
tot = 0;
dfs(0, 1, 0);
sort(all + 1, all + tot + 1);
// for (int i = 1; i <= tot; i++){
// cout << all[i].siz << ' ';
// for (int j: all[i].num){
// cout << j << ' ';
// }
// cout << endl;
// }
vector<pair<int, int>> ans;
vector<int> vec;
for (int i = 1; i <= tot; i++){
vec.clear();
for (int j: all[i].num){
if (!used[j]){
vec.push_back(j);
}
}
for (int j = 0; j + 1 < vec.size(); j += 2){
ans.push_back(mp(vec[j], vec[j + 1]));
used[vec[j]] = used[vec[j + 1]] = true;
}
}
if (ans.size() == 0){
cout << ans.size() << endl;
}else{
cout << ans.size() << ' ';
for (int i = 0; i < ans.size() - 1; i++){
cout << ans[i].first << ' ' << ans[i].second << ' ';
}
cout << ans.back().first << ' ' << ans.back().second;
if (T){
cout << endl;
}
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 6740kb
input:
3 1 4 6
output:
0 1 2 4 2 3 6 2 4
result:
ok 4 cases
Test #2:
score: -100
Wrong Answer
time: 81ms
memory: 23884kb
input:
1007 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101...
output:
0 0 0 1 2 4 1 2 4 2 3 6 2 4 2 3 6 2 4 2 3 6 2 4 2 3 6 2 4 3 5 10 3 6 2 4 3 5 10 3 6 2 4 4 6 12 5 10 3 9 2 4 4 6 12 5 10 3 9 2 4 5 6 12 7 14 5 10 3 9 2 4 5 6 12 7 14 5 10 3 9 2 4 6 6 12 7 14 5 10 3 9 2 4 8 16 6 6 12 7 14 5 10 3 9 2 4 8 16 7 6 12 7 14 5 10 3 9 15 18 2 4 8 16 7 6 12 7 14 5 10 3 9 15 18...
result:
wrong answer Case #9: Participant has a worse answer