AtCoder Grand Contest 003

Submission #1366066

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

struct myc{
    int x;
    long long y;
};

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

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

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;
}

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) ans ++;
            else{
                inmult(rev, u);
                if(rev != -1)
                    add(imag * x, rev);
            }
        }
    }

    ans += cub;

    for(auto &u : mp) if(u.y.x){
        if(u.x == 1)
            return 4;
        auto &v = mp[u.y.y];
        ans += std::max(u.y.x, v.x);
        v.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状態 WA
Score得点 0
Source lengthソースコード長 2327 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

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

./Main.cpp: In function ‘int main()’:
./Main.cpp:116: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:68: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:74: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 0 / 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 519 ms 5760 KB
02.txt AC 519 ms 5760 KB
03.txt AC 518 ms 5760 KB
04.txt AC 519 ms 5760 KB
05.txt AC 520 ms 5760 KB
06.txt AC 519 ms 5760 KB
07.txt AC 522 ms 5760 KB
08.txt AC 521 ms 5760 KB
09.txt AC 519 ms 5760 KB
10.txt AC 519 ms 5760 KB
11.txt AC 528 ms 2816 KB
12.txt AC 528 ms 2816 KB
13.txt WA
14.txt WA
15.txt WA
16.txt WA
17.txt AC 61 ms 896 KB
18.txt AC 61 ms 896 KB
19.txt AC 61 ms 896 KB
20.txt AC 61 ms 896 KB
21.txt WA
22.txt WA
23.txt WA
24.txt WA
25.txt WA
26.txt WA
27.txt AC 277 ms 8064 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 59 ms 896 KB
35.txt AC 53 ms 896 KB
36.txt AC 3 ms 896 KB
37.txt WA
38.txt WA
39.txt WA
40.txt WA
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