/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 320.0 KiB
#4 Accepted 1ms 532.0 KiB
#5 Accepted 1ms 400.0 KiB
#6 Accepted 2ms 368.0 KiB
#7 Accepted 5ms 564.0 KiB
#8 Accepted 5ms 572.0 KiB
#9 Accepted 40ms 572.0 KiB
#10 Accepted 34ms 532.0 KiB
#11 Accepted 33ms 532.0 KiB
#12 Accepted 33ms 532.0 KiB
#13 Accepted 13ms 568.0 KiB

Code

#include <bits/stdc++.h>
#define int long long
using namespace std;

namespace solve {
  namespace test_case {

    void main() {
      int n; cin >> n;
      vector<int> a(n);
      for (auto &x : a) cin >> x;
      map<int, int> mp;
      int mx = *max_element(a.begin(), a.end());
      for (int i (0); i < n; i++) {
        for (int j (2); j <= mx; j++) {
          if (a[i] % j == 0) mp[j] ++;
        }
      }
      
      vector<pair<int, int>> vec(mp.begin(), mp.end());
      sort(vec.rbegin(), vec.rend());

      for (int i (1); i <= n; i++) {
        bool f = false;
        for (auto &x : vec) {
          if (x.second >= i) {
            f = true;
            cout << x.first << ' ';
            break;
          }
        }
        if (!f) cout << 1 << ' ';
      }
    }
  }

  void main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int t (1); //cin >> t; 
    while (t--) test_case::main();
  }
}

signed main() { solve::main(); }

Information

Submit By
Type
Submission
Problem
P1151 Max gcd group
Language
C++17 (G++ 13.2.0)
Submit At
2025-01-03 10:01:35
Judged At
2025-01-03 10:01:35
Judged By
Score
100
Total Time
40ms
Peak Memory
572.0 KiB