Submission #844254

# Submission time Handle Problem Language Result Execution time Memory
844254 2023-09-05T11:52:46 Z vjudge1 Spiderman (COCI20_spiderman) C++17
70 / 70
175 ms 17044 KB
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<map>
#include<set>
#include<climits>
#include<numeric>
#include<queue>
#include<unordered_map>
#include<string>
#include<climits>
#include<unordered_set>
#include<bitset>
#include<cstring>
#include<cmath>
#include<stack>
#if 1
#define pb push_back
#define st first
#define nd second
#define endl '\n'
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MAXN ((int)(1e6+23))
#define int long long int
using namespace std;
const int inf = 1e17 + 5;
#endif

void fileio(string s){
    #ifndef ONLINE_JUDGE
        freopen((s+string(".in")).c_str(),"r",stdin);
        freopen((s+string(".out")).c_str(),"w",stdout);
    #endif
}


signed main(){
    //fileio("test");
    //fio; 
    int n, k;
    cin >> n >> k;
    vector<int>v(n + 1);
    map<int, int>m;
    int z = 0;
    for(int i = 1; i <= n; ++i){
        cin >> v[i];
        m[v[i]]++;
        if(v[i] > k)z++;
    }
    vector<int>s(MAXN);
    for(auto& p : m){
        if(p.st <= k)continue;
        for(int i = p.st; i <= MAXN; i += p.st){
            s[i] += p.nd;
        }
    }
    for(int i = 1; i <= n; ++i)v[i] -= k;

    for(int i = 1; i <= n; ++i){
        if(v[i] < 0){
            cout << 0 << ' ';
        }
        else if(v[i] == 0){
            cout << z << ' ';
        }
        else{
            int res = s[v[i]];
            if(!k)res--;
            cout << res << ' ';
        }
    }
    cout << endl;
    

}

Compilation message

spiderman.cpp: In function 'void fileio(std::string)':
spiderman.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         freopen((s+string(".in")).c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
spiderman.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         freopen((s+string(".out")).c_str(),"w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8280 KB Output is correct
2 Correct 7 ms 8280 KB Output is correct
3 Correct 44 ms 9508 KB Output is correct
4 Correct 97 ms 11604 KB Output is correct
5 Correct 94 ms 15444 KB Output is correct
6 Correct 175 ms 17044 KB Output is correct
7 Correct 83 ms 15564 KB Output is correct
8 Correct 76 ms 15440 KB Output is correct
9 Correct 172 ms 16868 KB Output is correct
10 Correct 167 ms 16976 KB Output is correct