Submission #4277854


Source Code Expand

#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;
const LL INF = 1e11;
int N;
map<LL, int> cnt;

const LL L = 2155;
const int M = 100001;
bool is_composite[M];
vector<LL> ps, tris;
map<LL, LL> sq2p, p2sq;

LL Reduce(LL v) {
  for (LL p : tris) {
    while (v%p == 0) v /= p;
  }
  return v;
}

LL Rev(LL v) {
  LL ret = 1;
  for (LL p : ps) {
    int e = 0;
    while (v%p == 0) {
      e++;
      v /= p;
    }

    assert(e <= 2);
    if (e == 1) ret *= p*p;
    else if (e == 2) ret *= p;
  }

  if (1 < v) { 
    assert(v > 2000);
    if (sq2p.count(v)) v = sq2p[v];
    else if (p2sq.count(v)) v = p2sq[v];
    else return -1;
    ret *= v;
  } 

  return ret;
}

int main() {
  reps(i, 2, M) {
    if (is_composite[i]) continue;
    LL p = i;
    if (p < L) {
      ps.eb(p);
      tris.eb(p*p*p);
    } else {
      sq2p[p*p] = p;
      p2sq[p] = p*p;
    }

    for (int j=i+i; j<M; j+=i) {
      is_composite[j] = true;
    }
  }
  //cout << ps.size() << endl;

  scanf("%d", &N);
  rep(i, N) {
    LL s;
    scanf("%lld", &s);
    cnt[Reduce(s)]++;
  }

  int ans = N;
  for (auto &p : cnt) {
    LL v = p.X;
    int a = p.Y;
    //printf("%lld: %d\n", v, a);
    LL r = Rev(v);
    if (!cnt.count(r)) continue;
    int b = cnt[r];
    if (a > b) continue;
    if (a == b && v < r) continue;
    if (a == b && v == r) assert(v == 1);
    //printf("removed (%lld,%d) because of (%lld, %d)\n", v, a, r, b);
    ans -= a;
  }

  if (cnt.count(1)) ans++;
  printf("%d\n", ans);
}

Submission Info

Submission Time
Task D - Anticube
User potetisensei
Language C++14 (GCC 5.4.1)
Score 1100
Code Size 2453 Byte
Status AC
Exec Time 780 ms
Memory 7808 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:87:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &N);
                  ^
./Main.cpp:90:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &s);
                      ^

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 774 ms 7808 KB
02.txt AC 780 ms 7808 KB
03.txt AC 775 ms 7808 KB
04.txt AC 772 ms 7808 KB
05.txt AC 773 ms 7808 KB
06.txt AC 778 ms 7808 KB
07.txt AC 776 ms 7808 KB
08.txt AC 771 ms 7808 KB
09.txt AC 774 ms 7808 KB
10.txt AC 772 ms 7808 KB
11.txt AC 485 ms 3456 KB
12.txt AC 486 ms 3456 KB
13.txt AC 509 ms 3840 KB
14.txt AC 510 ms 3840 KB
15.txt AC 512 ms 3840 KB
16.txt AC 510 ms 3840 KB
17.txt AC 370 ms 1536 KB
18.txt AC 370 ms 1536 KB
19.txt AC 370 ms 1536 KB
20.txt AC 370 ms 1536 KB
21.txt AC 609 ms 5376 KB
22.txt AC 609 ms 5376 KB
23.txt AC 612 ms 5376 KB
24.txt AC 610 ms 5376 KB
25.txt AC 619 ms 5376 KB
26.txt AC 609 ms 5248 KB
27.txt AC 709 ms 6656 KB
28.txt AC 349 ms 1536 KB
29.txt AC 347 ms 1536 KB
30.txt AC 343 ms 1536 KB
31.txt AC 347 ms 1536 KB
32.txt AC 352 ms 1536 KB
33.txt AC 5 ms 1536 KB
34.txt AC 366 ms 1536 KB
35.txt AC 365 ms 1536 KB
36.txt AC 5 ms 1536 KB
37.txt AC 520 ms 3968 KB
38.txt AC 520 ms 3968 KB
39.txt AC 518 ms 3968 KB
40.txt AC 517 ms 3968 KB
41.txt AC 5 ms 1536 KB
42.txt AC 5 ms 1536 KB
43.txt AC 5 ms 1536 KB
44.txt AC 5 ms 1536 KB
45.txt AC 5 ms 1536 KB
46.txt AC 5 ms 1536 KB
47.txt AC 5 ms 1536 KB
48.txt AC 5 ms 1536 KB
s1.txt AC 5 ms 1536 KB
s2.txt AC 5 ms 1536 KB
s3.txt AC 5 ms 1536 KB