Submission #847086


Source Code Expand

Copy
#include <bits/stdc++.h>

#define forn(i, n) for(int i = 0; i < (int)(n); ++i)
#define for1(i, n) for(int i = 1; i <= (int)(n); ++i)
#define fore(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; --i)
#define ford1(i, n) for(int i = (int)(n); i>=1; --i)
#define fored(i, a, b) for(int i = (int)(b); i >= (int)(a); --i)
#define sz(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()
#define clr(v) memset(v, 0, sizeof(v))
#define clr1(v) memset(v, 0xFF, sizeof(v))
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef pair<int, int> pii;
typedef vector<pii> vpi;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long i64;
typedef unsigned long long u64;
typedef long double ld;
typedef vector<ld> vld;

typedef vector<i64> vi64;

template<class T> bool uax(T&a, const T& b) { if( a < b ) { a = b; return true; } return false; }
template<class T> bool uin(T&a, const T& b) { if( a > b ) { a = b; return true; } return false; }

const i64 M = 1000000000;

void solve() {
  int n;
  cin >> n;
  vector<i64> a(n);
  forn(i, n) cin >> a[i];
  unordered_map<i64, pair<i64, int> > M;
  unordered_map<i64, int> S;
  for(i64 x: a) S[x] += 1;
  for (const auto& e: S) {
    i64 x = e.fi;
    i64 ca = 1, cb = 1;
    // cerr << x << ": ";
    for (i64 j = 2; j * j * j <= x; ++j) {
      if (x % j == 0) {
        int i = 0;
        while (x % j == 0) { x /= j; i += 1; }
        i %= 3;
        forn(t, i) ca *= j;
        if (i > 0) forn(t, 3 - i) cb *= j;
      }
    }
    if (x > 1) {
      i64 sx = sqrtl((ld)x + 0.5);
      if (sx * sx == x) {
        ca *= x;
        cb *= sx;
      } else {
        ca *= x;
        cb *= x * x;
      }
    }
    // cerr << ca << " " << cb << '\n';
    M[ca].fi = cb;
    M[ca].se += e.se;
    M[cb].fi = ca;
  }
  int r = 0;
  for (const auto& e: M) if (e.fi != 1) {
    // cerr << e.fi << ':' << e.se.fi << ' ' << e.se.se << '\n';
    r += max(e.se.se, M[e.se.fi].se);
    // cerr << r << '\n';
  }
  r /= 2;
  r += min(1, M[1].se);
  cout << r << '\n';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed; cout.precision(15);
  cerr << fixed; cerr.precision(15);
#ifdef HOME
  freopen("input.txt", "r", stdin);
#endif
  solve();
  return 0;
}

Submission Info

Submission Time
Task D - Anticube
User gchebanov
Language C++14 (GCC 5.4.1)
Score 1100
Code Size 2437 Byte
Status AC
Exec Time 1044 ms
Memory 16584 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1100 / 1100
Status
AC × 3
AC × 51
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 1033 ms 16584 KB
02.txt AC 1032 ms 16584 KB
03.txt AC 1033 ms 16584 KB
04.txt AC 1027 ms 16584 KB
05.txt AC 1034 ms 16584 KB
06.txt AC 1040 ms 16584 KB
07.txt AC 1023 ms 16584 KB
08.txt AC 1044 ms 16584 KB
09.txt AC 1034 ms 16584 KB
10.txt AC 1027 ms 16584 KB
11.txt AC 903 ms 6924 KB
12.txt AC 905 ms 6924 KB
13.txt AC 246 ms 7052 KB
14.txt AC 264 ms 7052 KB
15.txt AC 248 ms 7052 KB
16.txt AC 248 ms 7052 KB
17.txt AC 35 ms 1408 KB
18.txt AC 35 ms 1408 KB
19.txt AC 35 ms 1408 KB
20.txt AC 35 ms 1408 KB
21.txt AC 880 ms 10788 KB
22.txt AC 882 ms 10788 KB
23.txt AC 903 ms 10788 KB
24.txt AC 887 ms 10788 KB
25.txt AC 885 ms 10788 KB
26.txt AC 873 ms 10788 KB
27.txt AC 154 ms 14920 KB
28.txt AC 16 ms 1024 KB
29.txt AC 16 ms 1024 KB
30.txt AC 17 ms 1024 KB
31.txt AC 17 ms 1024 KB
32.txt AC 17 ms 1024 KB
33.txt AC 4 ms 256 KB
34.txt AC 26 ms 1024 KB
35.txt AC 25 ms 1024 KB
36.txt AC 4 ms 256 KB
37.txt AC 953 ms 7460 KB
38.txt AC 949 ms 7460 KB
39.txt AC 945 ms 7460 KB
40.txt AC 953 ms 7460 KB
41.txt AC 4 ms 256 KB
42.txt AC 4 ms 256 KB
43.txt AC 4 ms 256 KB
44.txt AC 4 ms 256 KB
45.txt AC 4 ms 256 KB
46.txt AC 4 ms 256 KB
47.txt AC 4 ms 256 KB
48.txt AC 4 ms 256 KB
s1.txt AC 4 ms 256 KB
s2.txt AC 4 ms 256 KB
s3.txt AC 4 ms 256 KB