Submission #844348

# Submission time Handle Problem Language Result Execution time Memory
844348 2023-09-05T12:29:21 Z vjudge1 Spiderman (COCI20_spiderman) C++17
56 / 70
1263 ms 25792 KB
#include <bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define int long long
using namespace std;

const int inf = 2e18 + 5;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;

int32_t main(){
  //freopen("in.txt","r", stdin);
  vector<int> abul(N, 1), prime;
  for(int i = 2; i < N; i++){
    if(abul[i] == 1){
        prime.pb(i);
        for(int j = i*2; j < N; j += i) abul[j] = 0;
    }
  }
  int n, k;
  cin>>n>>k;
  vector<pair<int, int> > h(n);
  for(int i = 0; i < n; i++){
    cin>>h[i].first;
    h[i].second = i;
  }
  sort(h.begin(), h.end());
  vector<int> ans(n);
  map<int, int> mp;

  for(int i = 0; i < n; i++){
    if(h[i].first < k){
        ans[h[i].second] = 0;
    }
    else if(h[i].first == k){
        ans[h[i].second] = (n - i - 1);
    }
    else{
        int x = h[i].first - k, cnt = 0;

        for(int j = 1; j * j <= x; j++){
            if(x%j == 0){
                if(j > k) cnt += mp[j];
                if(x/j != j && x/j > k) cnt += mp[x/j];
                //if(x == 6) cout<<j<<" "<<x/j<<" "<<mp[j]<<" "<<mp[x/j]<<" "<<cnt<<endl;
            }
        }

        ans[h[i].second] = cnt;
    }
    mp[h[i].first]++;
  }

  for(int i = 0; i < n; i++){
    cout<<ans[i]<<" ";
  }
  cout<<endl;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 2772 KB Output is correct
2 Correct 9 ms 2520 KB Output is correct
3 Incorrect 300 ms 5412 KB Output isn't correct
4 Correct 858 ms 10608 KB Output is correct
5 Correct 461 ms 14212 KB Output is correct
6 Incorrect 1142 ms 18804 KB Output isn't correct
7 Correct 522 ms 20176 KB Output is correct
8 Correct 522 ms 20224 KB Output is correct
9 Correct 1263 ms 25792 KB Output is correct
10 Correct 1245 ms 25644 KB Output is correct