Submission #197952

# Submission time Handle Problem Language Result Execution time Memory
197952 2020-01-24T12:03:41 Z model_code Spiderman (COCI20_spiderman) C++17
70 / 70
882 ms 6364 KB
#include <bits/stdc++.h>

using namespace std;

#define TRACE(x) cerr << #x << " " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<

typedef long long llint;

const int MAXN = 3e5 + 10;
const int MAXH = 1e6 + 10;

int n, k, gtk;
int h[MAXN], cnt[MAXH];

int main(void) {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &h[i]);
    cnt[h[i]]++;
    gtk += h[i] > k;
  }

  for (int i = 0; i < n; ++i) {
    int ret = 0;
    if (h[i] < k) {
      printf("0 ");
      continue;
    }
    if (h[i] == k) {
      printf("%d ", gtk);
      continue;
    }
    for (int j = 1; j * j <= h[i] - k; ++j) {
      if ((h[i] - k) % j != 0) continue;
      if (h[i] % j == k) ret += cnt[j];
      if (j * j != h[i] - k && h[i] % ((h[i] - k) / j) == k)
        ret += cnt[(h[i] - k) / j];
    }
    if (k == 0) --ret;
    printf("%d ", ret);
  }

  printf("\n");

  return 0;
}

Compilation message

spiderman.cpp: In function 'int main()':
spiderman.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &n, &k);
   ~~~~~^~~~~~~~~~~~~~~~
spiderman.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &h[i]);
     ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 2680 KB Output is correct
2 Correct 8 ms 1784 KB Output is correct
3 Correct 229 ms 3576 KB Output is correct
4 Correct 663 ms 4964 KB Output is correct
5 Correct 275 ms 5128 KB Output is correct
6 Correct 789 ms 6364 KB Output is correct
7 Correct 309 ms 4968 KB Output is correct
8 Correct 306 ms 4856 KB Output is correct
9 Correct 882 ms 6260 KB Output is correct
10 Correct 878 ms 6136 KB Output is correct