Submission #109693

#TimeUsernameProblemLanguageResultExecution timeMemory
109693IOrtroiiiTents (JOI18_tents)C++14
100 / 100
159 ms35832 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 3030;
const int mod = 1e9 + 7;

void add(int &x,int y) {
   x += y; if (x >= mod) x -= mod;
}

int mul(int x,int y) {
   return (long long) x * y % mod;
}

int f[N][N];

int main() {
   int n, m; scanf("%d %d", &n, &m);
   f[m][n] = 1;
   for (int i = m; i >= 0; --i) {
      for (int j = n; j >= 0; --j) {
         if (i) {
            add(f[i - 1][j], f[i][j]);
            if (j) add(f[i - 1][j - 1], mul(mul(4, j), f[i][j]));
            if (j > 1) add(f[i - 1][j - 2], mul(mul(j, j - 1), mul(mod + 1 >> 1, f[i][j])));
            if (i > 1 && j) add(f[i - 2][j - 1], mul(mul(j, i - 1), f[i][j]));
         } else if (j) add(f[i][j - 1], f[i][j]);
      }
   }
   printf("%d\n", (f[0][0] + mod - 1) % mod);
}

Compilation message (stderr)

tents.cpp: In function 'int main()':
tents.cpp:26:72: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
             if (j > 1) add(f[i - 1][j - 2], mul(mul(j, j - 1), mul(mod + 1 >> 1, f[i][j])));
                                                                    ~~~~^~~
tents.cpp:19:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int n, m; scanf("%d %d", &n, &m);
              ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...