답안 #308045

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
308045 2020-09-30T00:41:26 Z ErdosSzekeres Spiderman (COCI20_spiderman) C++14
70 / 70
244 ms 16752 KB
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define mp make_pair
#define ld long double
#define ll long long
#define pii pair<int,int>
#define pll pair<ll, ll>
const int MAXH=1e6+7;
int a[MAXH], ans[MAXH], freq[MAXH];
vector<int> v;
set<int> S;

int main(){
    fastio;
    int n,k; cin>>n>>k;
    for(int i=0; i<n; i++){
        cin >> a[i];
        if(S.find(a[i])==S.end()){
            v.push_back(a[i]);
        }
        freq[a[i]]++;
        S.insert(a[i]);
    }
    for(int i=0; i<(int)v.size(); i++){//mark all numbers congruent to k mod v[i]
        if(k >= v[i])continue;
        for(int j=k; j < MAXH; j+=v[i]){
            int aux = (v[i]==j) ? -1 : 0;
            ans[j] += freq[v[i]] + aux;
        }
    }
    for(int i=0; i<n; i++){
        if(i>0)cout<<" ";
        cout << ans[a[i]];
    }
    cout<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 6656 KB Output is correct
2 Correct 17 ms 5760 KB Output is correct
3 Correct 57 ms 8056 KB Output is correct
4 Correct 110 ms 10712 KB Output is correct
5 Correct 135 ms 14576 KB Output is correct
6 Correct 244 ms 16752 KB Output is correct
7 Correct 118 ms 14576 KB Output is correct
8 Correct 117 ms 14576 KB Output is correct
9 Correct 233 ms 16752 KB Output is correct
10 Correct 232 ms 16624 KB Output is correct