/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 332.0 KiB
#2 Wrong Answer 2ms 332.0 KiB
#3 Accepted 2ms 480.0 KiB
#4 Wrong Answer 2ms 332.0 KiB

Code

#include <bits/stdc++.h>
#define ll long long
#define endl '\n'

using namespace std;

vector<int> getDivisors(int n) {
	vector<int> d;
	for (int i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			d.push_back(i);
			if (i != n / i) d.push_back(n / i);
		}
	}
	return d;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int n, y; cin >> n;
	multiset<int> a;
	for (int i = 0; i < n; i++) {
		cin >> y;
		a.insert(y);
	}

	auto it = a.rbegin();
	int currGCD = *it;
	while (true) {
		vector<int> toRemove;
		for (auto xx : a) {
			if (xx % currGCD == 0) {
				cout << currGCD << ' ';
				toRemove.push_back(xx);
			}
		}

		for (auto x : toRemove) a.erase(a.find(x));
		// for (auto x : a) cout << x << ' ';
		// cout << '\n';

		if (a.empty()) {
			break;
		}

		vector<int> divi(getDivisors(currGCD));
		sort(divi.rbegin(), divi.rend());

		// for (auto x : divi) cout << x << ' ';
		// cout << '\n';

		int v = 0;
		for (auto x : divi) {
			if (v) break;

			// cout << x << ' ';
			for (auto xx : a) {
				if (xx % x == 0) {
					currGCD = x;
					v = 1;
					break;
				}
			}
		}
	}

	return 0;
}

Information

Submit By
Type
Submission
Problem
P1151 Max gcd group
Contest
Happy New Year 2025
Language
C++17 (G++ 13.2.0)
Submit At
2025-01-02 15:52:40
Judged At
2025-01-02 15:52:40
Judged By
Score
5
Total Time
2ms
Peak Memory
480.0 KiB