답안 #633405

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
633405 2022-08-22T10:52:53 Z HossamHero7 Spiderman (COCI20_spiderman) C++14
56 / 70
2000 ms 128736 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define endl '\n'
const int N = 1e6+5;
void solve(){
    vector<vector<int>> div(N);
    for(int i=1;i<N;i++){
        for(int j=i;j<N;j+=i) div[i].push_back(j);
    }
    int n,k;
    cin>>n>>k;
    vector<int> v(n);
    for(auto &i:v) cin>>i;
    vector<int> vis(N);
    for(auto i : v) vis[i] ++;
    vector<int> suffix(N);
    suffix[N-1] = vis[N-1];
    for(int i=N-1;i>=0;i--) suffix[i] = suffix[i+1] + vis[i];
    vector<int> ans(N);
    for(int i=0;i<n;i++){
        for(auto j : div[v[i]]){
            if((j+k)%v[i]==k && j+k < N && vis[j+k]){
                ans[j+k] ++;
            }
        }
        if(v[i] == k) ans[v[i]] += suffix[v[i]+1];
    }
    if(k == 0){
        for(auto &i : ans) i --;
    }
    for(int i=0;i<n;i++) cout<<ans[v[i]]<<' ';
    cout<<endl;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);      cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 201 ms 124668 KB Output is correct
2 Correct 209 ms 124772 KB Output is correct
3 Execution timed out 2075 ms 125676 KB Time limit exceeded
4 Execution timed out 2048 ms 127704 KB Time limit exceeded
5 Correct 275 ms 125916 KB Output is correct
6 Correct 531 ms 128736 KB Output is correct
7 Correct 263 ms 125920 KB Output is correct
8 Correct 321 ms 125992 KB Output is correct
9 Correct 517 ms 128640 KB Output is correct
10 Correct 539 ms 128504 KB Output is correct