Submission #992949


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;

const int mod = 1e9 + 7;

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

int udd(int &x, int y) {
  return x = add(x, y);
}

int sub(int x, int y) {
  return add(x, mod - y);
}

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

const int M = 344;

int n, m;
int d[M][M], h[M][M];

void read() {
  cin >> n >> m;
}

void kill() {
  d[1][n - 1] = 1;
  for (int i = 0; i < m; ++i) {
    
    for (int x = 0; x <= n; ++x)
      for (int y = 0; y <= n; ++y)
        h[x][y] = 0;

    for (int x = 1; x <= n; ++x)
      for (int y = 0; y <= n - x; ++y) {
        int cur = d[x][y];
        udd(h[n - y][y], mul(x, cur));

        if (y > 0) {
          udd(h[x][y - 1], mul(y, cur));
        }

        udd(h[x][y], mul(n - x - y, cur));
      }

    for (int x = 0; x <= n; ++x)
      for (int y = 0; y <= n; ++y)
        d[x][y] = h[x][y];
  }

  cout << d[n][0] << endl;
}

int main() {
#ifdef LOCAL
  assert(freopen("f.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  read();
  kill();

}

Submission Info

Submission Time
Task F - Road of the King
User Arterm
Language C++14 (GCC 5.4.1)
Score 1000
Code Size 1206 Byte
Status AC
Exec Time 136 ms
Memory 1024 KB

Judge Result

Set Name sample all
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 3
AC × 13
Set Name Test Cases
sample sample-01.txt, sample-02.txt, sample-03.txt
all sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt
Case Name Status Exec Time Memory
01-01.txt AC 2 ms 256 KB
01-02.txt AC 2 ms 256 KB
01-03.txt AC 2 ms 256 KB
01-04.txt AC 4 ms 1024 KB
01-05.txt AC 2 ms 256 KB
01-06.txt AC 15 ms 512 KB
01-07.txt AC 127 ms 1024 KB
01-08.txt AC 134 ms 1024 KB
01-09.txt AC 135 ms 1024 KB
01-10.txt AC 136 ms 1024 KB
sample-01.txt AC 2 ms 256 KB
sample-02.txt AC 37 ms 640 KB
sample-03.txt AC 69 ms 1024 KB