QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#245396#6728. To the ParkgzzzWA 91ms8460kbC++201.3kb2023-11-09 21:24:222023-11-09 21:24:23

Judging History

你现在查看的是最新测评结果

  • [2023-11-09 21:24:23]
  • 评测
  • 测评结果:WA
  • 用时:91ms
  • 内存:8460kb
  • [2023-11-09 21:24:22]
  • 提交

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=fr;i>=1;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";
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 6532kb

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: 91ms
memory: 8460kb

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 5 10 3 6 9 12 2 4 
4 5 10 3 6 9 12 2 4 
5 7 14 5 10 3 6 9 12 2 4 
5 7 14 5 10 3 6 9 12 2 4 
6 7 14 5 10 3 6 9 12 2 4 8 16 
6 7 14 5 10 3 6 9 12 2 4 8 16 
7 7 14 5 10 3 6 9 12 15 18 2 4 8 16 
7 7 14 5...

result:

wrong answer Case #9: Participant has a worse answer