QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#245427 | #6728. To the Park | gzzz | WA | 87ms | 8440kb | C++20 | 1.3kb | 2023-11-09 21:50:20 | 2023-11-09 21:50:20 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+10;
int vis[maxn];
bool done[maxn];
vector<int> e[maxn];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
vector<int> zhi;
for(int i=2;i<=1e5;i++){
if(!vis[i]) {
zhi.push_back(i);
}
for(int j=0;j<zhi.size()&&i*zhi[j]<=1e5;j++){
vis[i*zhi[j]]=zhi[j];
if(i%zhi[j]==0) {
break;
}
}
}
int t;cin>>t;
while(t--){
int n;cin>>n;
for(int i=1;i<=n;i++){
e[i].clear();
done[i]=false;
}
int fr=0;
for(int i=1;i<=n;i++){
int tmp=i;
while(vis[tmp]) {
int now=vis[tmp];
fr=max(fr,now);
e[now].push_back(i);
while(tmp%now==0) {
tmp/=now;
}
}
if(tmp!=1) {
e[tmp].push_back(i);
fr=max(fr,tmp);
}
}
vector<pair<int,int> >ans;
for(int i=1;i<=fr;i++){
stack<int> s;
for(int j=0;j<e[i].size();j++){
if(!done[e[i][j]]) {
if(s.empty()){
s.push(e[i][j]);
}
else {
ans.push_back(pair<int,int>(s.top(),e[i][j]));
done[s.top()]=true;
done[e[i][j]]=true;
s.pop();
}
}
}
}
cout<<ans.size()<<" ";
for(int i=0;i<ans.size();i++){
cout<<ans[i].first<<" "<<ans[i].second<<" ";
}
cout<<"\n";
}
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 6272kb
input:
3 1 4 6
output:
0 1 2 4 2 2 4 3 6
result:
ok 4 cases
Test #2:
score: -100
Wrong Answer
time: 87ms
memory: 8440kb
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 2 4 3 6 2 2 4 3 6 2 2 4 6 8 3 2 4 6 8 3 9 4 2 4 6 8 3 9 5 10 4 2 4 6 8 3 9 5 10 4 2 4 6 8 10 12 3 9 4 2 4 6 8 10 12 3 9 5 2 4 6 8 10 12 3 9 7 14 6 2 4 6 8 10 12 3 9 5 15 7 14 6 2 4 6 8 10 12 14 16 3 9 5 15 6 2 4 6 8 10 12 14 16 3 9 5 15 6 2 4 6 8 10 12 14 16 3 9 ...
result:
wrong answer Case #18: Participant has a worse answer