답안 #471320

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

using namespace std;
typedef long long ll;
#define endl '\n'
void solve(){
    int n,k;
    cin>>n>>k;
    vector <int> v(n);
    for(auto &i:v) cin>>i;
    if(k == 0){
        map <int,int> mp;
        for(auto i : v) mp[i] ++;
        int cnt=0;
        vector <int> ans(n);
        for(auto i : v){
            for(int j=1;j*j<=n;j++){
                if(i == j){
                    ans[cnt] += mp[i]-1;
                    if(i == 1){
                        ans[cnt] += mp[i]-1;
                    }
                    else ans[cnt] += mp[1];
                }
                else {
                    if(i % j == 0){
                        ans[cnt] += mp[j];
                        if(i == (i/j)){
                            ans[cnt] += mp[i]-1;
                            if(i == 1){
                                ans[cnt] += mp[i]-1;
                            }
                            else ans[cnt] += mp[1];
                        }
                        else {
                            if(i % (i/j) == 0) ans[cnt] += mp[i/j];
                        }
                    }
                }
            }
            cnt ++;
        }
        for(auto i : ans){
            cout<<i<<" ";
        }
        cout<<endl;
    }
    else {
        set <int> s;
        map <int,int> mp;
        for(auto i : v){
            mp[i] ++;
            s.insert(i);
        }
        vector <int> ans(n);
        int cnt = 0;
        for(auto i : v){
            for(auto j : s){
                if(i != j){
                    if(i%j == k) ans[cnt] += mp[j];
                }
                else {
                    if(i%j == k)ans[cnt] += mp[j]-1;
                }
            }
            cnt ++;
        }
        for(auto i : ans) cout<<i<<" ";
        cout<<endl;
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);      cout.tie(0);
    int t=1;
    while(t--){
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 460 KB Output is correct
2 Correct 21 ms 432 KB Output is correct
3 Execution timed out 2071 ms 1820 KB Time limit exceeded
4 Execution timed out 2083 ms 4552 KB Time limit exceeded
5 Incorrect 554 ms 9164 KB Output isn't correct
6 Execution timed out 2076 ms 11216 KB Time limit exceeded
7 Execution timed out 2087 ms 11052 KB Time limit exceeded
8 Execution timed out 2088 ms 11148 KB Time limit exceeded
9 Execution timed out 2084 ms 12960 KB Time limit exceeded
10 Execution timed out 2072 ms 12948 KB Time limit exceeded