답안 #844631

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
844631 2023-09-05T15:06:37 Z fanwen Spiderman (COCI20_spiderman) C++17
56 / 70
48 ms 10324 KB
#include <bits/stdc++.h>

using namespace std;

#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }

template <class A, class B> bool minimize(A &a, B b)  { if (a > b) { a = b; return true; } return false; }
template <class A, class B> bool maximize(A &a, B b)  { if (a < b) { a = b; return true; } return false; }

const int MAXN = 3e5 + 5;
const int MAXM = 1e6 + 1;

int N, K, a[MAXN], cnt[MAXM], ans[MAXM];

void you_make_it(void) {
    cin >> N >> K;
    FOR(i, 1, N) cin >> a[i], cnt[a[i]]++;
    FORE(i, K + 1, MAXM) {
    	for (int j = i; j + K < MAXM; j += i) {
    		ans[j + K] += cnt[i];
    	} 
    }
    int sum = 0;
    FOR(i, 1, K) ans[K] += cnt[i];
    ans[K] = N - ans[K];
    FOR(i, 1, N) cout << ans[a[i]] << " \n"[i == N];
}

signed main() {

#ifdef LOCAL
    freopen("TASK.inp", "r", stdin);
    freopen("TASK.out", "w", stdout);
#endif
  	file("spiderman");
    auto start_time = chrono::steady_clock::now();

    cin.tie(0), cout.tie(0) -> sync_with_stdio(0);

    you_make_it();

    auto end_time = chrono::steady_clock::now();

    cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl;

    return (0 ^ 0);
}

// Dream it. Wish it. Do it.

Compilation message

spiderman.cpp: In function 'void you_make_it()':
spiderman.cpp:31:9: warning: unused variable 'sum' [-Wunused-variable]
   31 |     int sum = 0;
      |         ^~~
spiderman.cpp: In function 'int main()':
spiderman.cpp:13:57: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
spiderman.cpp:43:4: note: in expansion of macro 'file'
   43 |    file("spiderman");
      |    ^~~~
spiderman.cpp:13:90: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
spiderman.cpp:43:4: note: in expansion of macro 'file'
   43 |    file("spiderman");
      |    ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 8792 KB Output is correct
2 Correct 11 ms 8796 KB Output is correct
3 Correct 22 ms 9248 KB Output is correct
4 Correct 47 ms 10320 KB Output is correct
5 Incorrect 23 ms 9048 KB Output isn't correct
6 Incorrect 45 ms 10324 KB Output isn't correct
7 Correct 22 ms 9048 KB Output is correct
8 Correct 21 ms 9040 KB Output is correct
9 Correct 46 ms 10004 KB Output is correct
10 Correct 48 ms 10064 KB Output is correct