답안 #844453

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
844453 2023-09-05T13:16:35 Z vjudge1 Spiderman (COCI20_spiderman) C++17
63 / 70
1264 ms 24216 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);
  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;

  if(k > 0){
    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]++;
  }
  }
  else{
    for(int i = 0; i < n; i++) mp[h[i].first]++;

    for(int i = 0; i < n; i++){
      int x = h[i].first - k, cnt = 0;

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

      ans[h[i].second] = cnt - 1;
    }
  }

  for(int i = 0; i < n; i++){
    cout<<ans[i]<<" ";
  }
  cout<<endl;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 860 KB Output is correct
2 Correct 7 ms 856 KB Output is correct
3 Incorrect 308 ms 3628 KB Output isn't correct
4 Correct 870 ms 8984 KB Output is correct
5 Correct 500 ms 12704 KB Output is correct
6 Correct 1248 ms 17204 KB Output is correct
7 Correct 502 ms 18516 KB Output is correct
8 Correct 524 ms 18716 KB Output is correct
9 Correct 1252 ms 23992 KB Output is correct
10 Correct 1264 ms 24216 KB Output is correct