AtCoder Grand Contest 003

Submission #1366105

Source codeソースコード

#include <cstdio>
#include <map>
#include <cstdlib>
#include <algorithm>

#define fin stdin
#define fout stdout

#define x first
#define y second

#define ll long long

#define LIM (10LL * 1000 * 1000 * 1000)
#define MAXR 100000
#define MAXC 3200
#define MAX0 452

#define MAXN 100000

struct myc{
    int x;
    ll y;
};

std::map <ll, int> p2;
std::map <ll, myc> mp;

int pr[MAX0 + 1];
bool c[MAXR + 1];

ll t[MAXN + 1];
int k;

inline void add(ll a, ll b){
    if(a > LIM)
        exit(1);
    if(b > LIM)
        exit(2);
    if(b < 0)
        exit(3);

    auto &u = mp[a];
    u.x ++;
    u.y = b;

    if(u.x == 1)
        t[++ k] = a;
}

inline void inmult(ll &a, ll b){
    if(a > 0){
        a *= b;
        if(a > LIM)
            a = -1;
    }
}

int main(){
    for(int i = 2; i * i <= MAXR; i ++)
        if(c[i] == 0)
            for(int j = i * i; j <= MAXR; j += i)
                c[j] = 1;

    for(int i = 2;  i <= MAXC; i ++)
        if(c[i] == 0)
            pr[++ pr[0]] = i;

    //printf("%d", pr[0]);

    for(int i = MAXC + 1; i <= MAXR; i ++)
        if(c[i] == 0)
            p2[1LL * i * i] = i;

    int n;
    fscanf(fin, "%d", &n);

    int ans = 0;
    bool cub = 0;
    for(int i = 1; i <= n; i ++){
        ll x, imag = 1, rev = 1;
        fscanf(fin, "%lld", &x);

        int q = 1;
        while(q <= pr[0] && x != 1){
            int s = 0;
            while(x % pr[q] == 0)
                s ++, x /= pr[q];
            s %= 3;
            if(s > 0){
                for(int j = 0; j < s; j ++)
                    imag *= pr[q];
                for(int j = 0; j < 3 - s; j ++)
                    inmult(rev, pr[q]);
            }
            q ++;
        }

        if(x == 1){
            if(rev == -1) ans ++;
            else if(rev == 1) cub = 1;
            else add(imag, rev);
        }else{
            int u = p2[x];
            if(u == 0){
                if(x <= MAXR){
                    inmult(rev, x);
                    inmult(rev, x);
                    if(rev == -1) ans ++;
                    else add(imag * x, rev);
                }else ans ++;
            }else{
                inmult(rev, u);
                if(rev == -1) ans ++;
                else add(imag * x, rev);
            }
        }
    }

    ans += cub;

    for(int i = 1; i <= k; i ++){
        auto &u = mp[t[i]];
        if(u.x){
            if(t[i] == 1)
                return 4;
            auto &v = mp[u.y];
            ans += std::max(u.x, v.x);
            v.x = 0;
            u.x=0;
        }
    }

    fprintf(fout, "%lld\n", ans);

    return 0;
}

Submission

Task問題 D - Anticube
User nameユーザ名 Alexandru Petrescu
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 1100
Source lengthソースコード長 2738 Byte
File nameファイル名
Exec time実行時間 535 ms
Memory usageメモリ使用量 12416 KB

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:134:32: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 3 has type ‘int’ [-Wformat=]
fprintf(fout, "%lld\n", ans);
^
./Main.cpp:76:26: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
fscanf(fin, "%d", &n);
^
./Main.cpp:82:32: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
fscanf(fin, "%lld", &x);
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - s1.txt,s2.txt,s3.txt
All 1100 / 1100 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01.txt AC 531 ms 5760 KB
02.txt AC 530 ms 5760 KB
03.txt AC 533 ms 5760 KB
04.txt AC 535 ms 5760 KB
05.txt AC 531 ms 5760 KB
06.txt AC 530 ms 5760 KB
07.txt AC 531 ms 5760 KB
08.txt AC 530 ms 5888 KB
09.txt AC 529 ms 5888 KB
10.txt AC 531 ms 5760 KB
11.txt AC 522 ms 2816 KB
12.txt AC 523 ms 2816 KB
13.txt AC 532 ms 3968 KB
14.txt AC 530 ms 3968 KB
15.txt AC 530 ms 3968 KB
16.txt AC 531 ms 3968 KB
17.txt AC 60 ms 896 KB
18.txt AC 60 ms 896 KB
19.txt AC 60 ms 896 KB
20.txt AC 60 ms 896 KB
21.txt AC 424 ms 4864 KB
22.txt AC 422 ms 4864 KB
23.txt AC 423 ms 4864 KB
24.txt AC 425 ms 4864 KB
25.txt AC 421 ms 4864 KB
26.txt AC 422 ms 4864 KB
27.txt AC 298 ms 12416 KB
28.txt AC 10 ms 896 KB
29.txt AC 17 ms 896 KB
30.txt AC 19 ms 896 KB
31.txt AC 19 ms 896 KB
32.txt AC 19 ms 896 KB
33.txt AC 3 ms 896 KB
34.txt AC 57 ms 896 KB
35.txt AC 52 ms 896 KB
36.txt AC 3 ms 896 KB
37.txt AC 513 ms 3456 KB
38.txt AC 514 ms 3456 KB
39.txt AC 514 ms 3456 KB
40.txt AC 514 ms 3456 KB
41.txt AC 3 ms 896 KB
42.txt AC 3 ms 896 KB
43.txt AC 3 ms 896 KB
44.txt AC 3 ms 896 KB
45.txt AC 3 ms 896 KB
46.txt AC 3 ms 896 KB
47.txt AC 3 ms 896 KB
48.txt AC 3 ms 896 KB
s1.txt AC 3 ms 896 KB
s2.txt AC 3 ms 896 KB
s3.txt AC 3 ms 896 KB