Submission #206744

# Submission time Handle Problem Language Result Execution time Memory
206744 2020-03-05T04:00:28 Z wiwiho Spiderman (COCI20_spiderman) C++14
70 / 70
1307 ms 9576 KB
//#define NDEBUG

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define F first
#define S second
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}
#define pii pair<int, int>
#define pll pair<ll, ll>
#define tiii tuple<int, int, int>
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) ((a) / (b) + !!((a) % (b)))

//#define TEST

typedef long long ll;
typedef unsigned long long ull;

using namespace std;
using namespace __gnu_pbds;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}


int main(){
    StarBurstStream

    int n, k;
    cin >> n >> k;

    vector<int> h(n);
    vector<int> cnt(1000001);

    for(int i = 0; i < n; i++){
        cin >> h[i];
        cnt[h[i]]++;
    }

    int tmp = 0;
    for(int i = 0; i < n; i++) if(h[i] > k) tmp++;

    vector<int> ans(n);
    for(int i = 0; i < n; i++){
        if(h[i] == k){
            ans[i] = tmp;
            continue;
        }
        int t = h[i] - k;
        for(int j = 1; j * j <= t; j++) if(t % j == 0){
            if(j > k){
                ans[i] += cnt[j];
                if(j == h[i]) ans[i]--;
            }
            if(t / j > k && t / j != j){
                ans[i] += cnt[t / j];
                if(t / j ==  h[i]) ans[i]--;
            }
        }
    }

    printv(ans, cout);

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 4220 KB Output is correct
2 Correct 14 ms 4216 KB Output is correct
3 Correct 340 ms 6008 KB Output is correct
4 Correct 1002 ms 9464 KB Output is correct
5 Correct 396 ms 6008 KB Output is correct
6 Correct 1149 ms 9576 KB Output is correct
7 Correct 449 ms 6008 KB Output is correct
8 Correct 446 ms 6136 KB Output is correct
9 Correct 1303 ms 9464 KB Output is correct
10 Correct 1307 ms 9264 KB Output is correct