Submission #846753


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int MAX_N = 100030;    // Change as necessary
const ll  MODD = 1000000009; //

vector<ll> pr;
bool is_prime[MAX_N];

vector<pair<ll,int> > factor(long long x){
  vector<pair<ll,int> > ans;
  for(auto p : pr){
    if(p*p > x) break;
    if(x % p == 0){
      int ctr = 0;
      while(x % p == 0){
        x /= p;
        ctr++;
      }
      
      if(ctr % 3)
        ans.emplace_back(p,ctr%3);
    }
  }
  if(x != 1) ans.emplace_back(x,1);
  return ans;
}

ll A[MAX_N];
map<vector<pair<ll,int> >, int> M;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  pr.push_back(2);
  fill(is_prime,is_prime+MAX_N,true);
  for(int i=3;i*i<MAX_N;i++)
    if(is_prime[i])
      for(int j=i*i;j<MAX_N;j+=i)
        is_prime[j] = false;
  
  for(int i=3;i<MAX_N;i+=2)
    if(is_prime[i])
      pr.push_back(i);
  
  int n; cin >> n;
  for(int i=0;i<n;i++) cin >> A[i];
  
  for(int i=0;i<n;i++)
    M[factor(A[i])]++;
  
  int ans = 0;
  for(const auto& x : M){
    vector<pair<ll,int> > tmp = x.first;
    bool found = false;
    for(auto& p : tmp){
      p.second = (3-p.second)%3;
      found |= p.second;
    }
    
    if(!found) ans+=2;
    else if(M.count(tmp)){
      ans += max((ll)x.second,(ll)M[tmp]);
    } else {
      ans += x.second*2;
    }
  }
  
  cout << ans/2 << endl;
  
  return 0;
}

Submission Info

Submission Time
Task D - Anticube
User MathCrusader
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1459 Byte
Status TLE
Exec Time 5257 ms
Memory 16896 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1100
Status
AC × 3
AC × 45
TLE × 6
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 2238 ms 16896 KB
02.txt AC 2255 ms 16896 KB
03.txt AC 2242 ms 16896 KB
04.txt AC 2224 ms 16896 KB
05.txt AC 2204 ms 16896 KB
06.txt AC 2277 ms 16896 KB
07.txt AC 2221 ms 16896 KB
08.txt AC 2248 ms 16896 KB
09.txt AC 2246 ms 16896 KB
10.txt AC 2215 ms 16896 KB
11.txt TLE 5257 ms 3840 KB
12.txt TLE 5253 ms 3840 KB
13.txt AC 1495 ms 5248 KB
14.txt AC 1502 ms 5248 KB
15.txt AC 1518 ms 5248 KB
16.txt AC 1513 ms 5248 KB
17.txt AC 124 ms 1408 KB
18.txt AC 124 ms 1408 KB
19.txt AC 125 ms 1280 KB
20.txt AC 124 ms 1408 KB
21.txt AC 3964 ms 9088 KB
22.txt AC 3948 ms 9088 KB
23.txt AC 3942 ms 9088 KB
24.txt AC 3944 ms 9088 KB
25.txt AC 4001 ms 9088 KB
26.txt AC 3964 ms 9088 KB
27.txt AC 225 ms 12928 KB
28.txt AC 18 ms 1408 KB
29.txt AC 32 ms 1280 KB
30.txt AC 49 ms 1280 KB
31.txt AC 45 ms 1280 KB
32.txt AC 46 ms 1280 KB
33.txt AC 5 ms 512 KB
34.txt AC 118 ms 1280 KB
35.txt AC 97 ms 1280 KB
36.txt AC 5 ms 512 KB
37.txt TLE 5253 ms 4480 KB
38.txt TLE 5253 ms 4480 KB
39.txt TLE 5253 ms 4352 KB
40.txt TLE 5253 ms 4480 KB
41.txt AC 5 ms 512 KB
42.txt AC 5 ms 512 KB
43.txt AC 5 ms 512 KB
44.txt AC 5 ms 512 KB
45.txt AC 7 ms 512 KB
46.txt AC 5 ms 512 KB
47.txt AC 5 ms 512 KB
48.txt AC 5 ms 512 KB
s1.txt AC 5 ms 512 KB
s2.txt AC 5 ms 512 KB
s3.txt AC 5 ms 512 KB