답안 #471321

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
471321 2021-09-08T11:23:35 Z HossamHero7 Spiderman (COCI20_spiderman) C++14
28 / 70
2000 ms 11084 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<=i;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(j == (i/j)) continue;
                        if(i == (i/j)){
                            ans[cnt] += mp[i]-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 45 ms 460 KB Output is correct
2 Correct 22 ms 332 KB Output is correct
3 Execution timed out 2065 ms 1248 KB Time limit exceeded
4 Execution timed out 2073 ms 2752 KB Time limit exceeded
5 Correct 753 ms 8516 KB Output is correct
6 Correct 1957 ms 10308 KB Output is correct
7 Execution timed out 2080 ms 10476 KB Time limit exceeded
8 Execution timed out 2058 ms 10436 KB Time limit exceeded
9 Execution timed out 2065 ms 11084 KB Time limit exceeded
10 Execution timed out 2091 ms 11060 KB Time limit exceeded