Submission #936326

#TimeUsernameProblemLanguageResultExecution timeMemory
936326Trisanu_DasBinaria (CCO23_day1problem1)C++17
25 / 25
97 ms21332 KiB
#include <stdio.h> #define N 1000000 #define MD 1000003 int vv[N + 1], ff[N + 1], gg[N + 1]; void init() { int i; ff[0] = gg[0] = 1; for (i = 1; i <= N; i++) { vv[i] = i == 1 ? 1 : (long long) vv[i - MD % i] * (MD / i + 1) % MD; ff[i] = (long long) ff[i - 1] * i % MD; gg[i] = (long long) gg[i - 1] * vv[i] % MD; } } int choose(int n, int k) { return k < 0 || k > n ? 0 : (long long) ff[n] * gg[k] % MD * gg[n - k] % MD; } int main() { static int kk[N]; int n, k, i, r, a, k1, k01; init(); scanf("%d%d", &n, &k); for (i = 0; i + k <= n; i++) scanf("%d", &kk[i]); k01 = k1 = 0; for (r = 0; r < k; r++) { a = -1; for (i = r; i + k < n; i += k) if (kk[i + 1] != kk[i]) { if (kk[i + 1] - kk[i] == 1) a = 0; else if (kk[i + 1] - kk[i] == -1) a = 1; else a = -2; break; } if (a == -2) { printf("0\n"); return 0; } if (a == -1) { k01++; continue; } if (a == 1) k1++; for (i = r; i + k < n; i += k) { a += kk[i + 1] - kk[i]; if (a != 0 && a != 1) { printf("0\n"); return 0; } } } printf("%d\n", choose(k01, kk[0] - k1)); return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |  scanf("%d%d", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |   scanf("%d", &kk[i]);
      |   ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...