Submission #339954

# Submission time Handle Problem Language Result Execution time Memory
339954 2020-12-26T12:12:30 Z Hazem Spiderman (COCI20_spiderman) C++14
70 / 70
1865 ms 126832 KB
/*
ID: tmhazem1
LANG: C++14
TASK: pprime
*/

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

#define S second
#define F first
#define LL long long
const int N = 1e6 + 10;


LL LINF = 100000000000000000;
LL INF = 1000000000;

vector<int>vec[N];
int freq[N],a[N],pr[N];

int main()
{
    //freopen("out.txt","w",stdout);
    int n,k,mx = 0;
    scanf("%d%d",&n,&k);

    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]),mx = max(mx,a[i]),freq[a[i]]++;

    for(int i=1;i<=mx;i++){
        pr[i] = pr[i-1]+freq[i];
        for(int j=i;j<=mx;j+=i)
            vec[j].push_back(i);
    }

    for(int i=1;i<=n;i++){
        
        int ans = a[i]==k?n-pr[a[i]]:0;
        if(a[i]>k)
        for(auto x:vec[a[i]-k])
            ans += freq[x]*(a[i]%x==k);

        printf("%d ",ans-(!k));
    }
    puts("");
}       

Compilation message

spiderman.cpp: In function 'int main()':
spiderman.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |     scanf("%d%d",&n,&k);
      |     ~~~~~^~~~~~~~~~~~~~
spiderman.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |         scanf("%d",&a[i]),mx = max(mx,a[i]),freq[a[i]]++;
      |         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1619 ms 121196 KB Output is correct
2 Correct 1625 ms 120512 KB Output is correct
3 Correct 1647 ms 122348 KB Output is correct
4 Correct 1756 ms 125284 KB Output is correct
5 Correct 1724 ms 124012 KB Output is correct
6 Correct 1865 ms 126832 KB Output is correct
7 Correct 1727 ms 124084 KB Output is correct
8 Correct 1753 ms 124184 KB Output is correct
9 Correct 1862 ms 126680 KB Output is correct
10 Correct 1645 ms 126552 KB Output is correct