Submission #503222

#TimeUsernameProblemLanguageResultExecution timeMemory
503222rainboyMagneti (COCI21_magneti)C11
30 / 110
302 ms460 KiB
#include <stdio.h> #define N 50 #define M 10000 #define MD 1000000007 int max(int a, int b) { return a > b ? a : b; } int vv[M + 1], ff[M + 1], gg[M + 1]; void init() { int i; ff[0] = gg[0] = 1; for (i = 1; i <= M; 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 pp[N], rr[N], n, l, ans; char used[N]; void branch(int i) { if (i == n) { int d = 0; for (i = 1; i < n; i++) d += max(rr[pp[i]], rr[pp[i - 1]]) - 1; ans = (ans + (long long) choose(l - d, n)) % MD; return; } for (pp[i] = 0; pp[i] < n; pp[i]++) if (!used[pp[i]]) used[pp[i]] = 1, branch(i + 1), used[pp[i]] = 0; } int main() { int i; init(); scanf("%d%d", &n, &l); for (i = 0; i < n; i++) scanf("%d", &rr[i]); if (n <= 10) { branch(0); printf("%d\n", ans); } else printf("%lld\n", (long long) choose(l - (rr[0] - 1) * (n - 1), n) * ff[n] % MD); return 0; }

Compilation message (stderr)

Main.c: In function 'main':
Main.c:46:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |  scanf("%d%d", &n, &l);
      |  ^~~~~~~~~~~~~~~~~~~~~
Main.c:48:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   scanf("%d", &rr[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...