답안 #957722

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
957722 2024-04-04T08:48:46 Z Erfan1386Y Zapina (COCI20_zapina) C++14
110 / 110
200 ms 3420 KB
#include <bits/stdc++.h>
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define fast_io ios::sync_with_stdio(false);cin.tie(0);
#define what(x) cerr << #x << " is " << x << '\n';
#define kill(x) {cout << x << '\n'; return;}
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define pb push_back
#define ll long long
#define F first
#define S second
const ll inf = 1e16, mod = 1e9 + 7, delta = 1e9 + 9, SQ = 350, P = 6065621;

using namespace std;

const int N = 360, LG = 21;
ll fac[N], inv[N], pw[N][N];
ll dp[N][N], pd[N][N];

ll poww (ll a, ll b) {
  if (!b) return 1;
  if (b & 1) return a * poww(a * a % mod, b / 2) % mod;
  return poww(a * a % mod, b / 2);
}

ll C(int n, int r) {
  if (r > n || r < 0) return 0;
  if (r == n || r == 0) return 1;
  return fac[n] * inv[r] % mod * inv[n - r] % mod;
}

int main () {
  fast_io;
  fac[0] = 1;
  for (int i = 1; i < N; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = poww(fac[i], mod - 2);
  }
  pw[0][0] = 1;
  for (int i = 1; i < N; i++) {
    pw[i][0] = 1;
    for (int j = 1; j < N; j++) {
      pw[i][j] = pw[i][j - 1] * i % mod;
    }
  }
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 0; k <= j; k++) {
        if (k == i) {
          dp[i][j] += C(j, k) * (pw[i - 1][j - k]) % mod;
          dp[i][j] %= mod;
        }
        else {  
          dp[i][j] += C(j, k) * dp[i - 1][j - k] % mod;
          dp[i][j] %= mod;
        }
      }
    }
  } 
  cout << dp[n][n] << '\n'; 
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3164 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
3 Correct 2 ms 3164 KB Output is correct
4 Correct 1 ms 3164 KB Output is correct
5 Correct 2 ms 3164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3164 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
3 Correct 2 ms 3164 KB Output is correct
4 Correct 1 ms 3164 KB Output is correct
5 Correct 2 ms 3164 KB Output is correct
6 Correct 1 ms 3164 KB Output is correct
7 Correct 1 ms 3164 KB Output is correct
8 Correct 1 ms 3164 KB Output is correct
9 Correct 1 ms 3164 KB Output is correct
10 Correct 1 ms 3164 KB Output is correct
11 Correct 1 ms 3164 KB Output is correct
12 Correct 1 ms 3164 KB Output is correct
13 Correct 1 ms 3160 KB Output is correct
14 Correct 2 ms 3420 KB Output is correct
15 Correct 1 ms 3164 KB Output is correct
16 Correct 2 ms 3160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3164 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
3 Correct 2 ms 3164 KB Output is correct
4 Correct 1 ms 3164 KB Output is correct
5 Correct 2 ms 3164 KB Output is correct
6 Correct 1 ms 3164 KB Output is correct
7 Correct 1 ms 3164 KB Output is correct
8 Correct 1 ms 3164 KB Output is correct
9 Correct 1 ms 3164 KB Output is correct
10 Correct 1 ms 3164 KB Output is correct
11 Correct 1 ms 3164 KB Output is correct
12 Correct 1 ms 3164 KB Output is correct
13 Correct 1 ms 3160 KB Output is correct
14 Correct 2 ms 3420 KB Output is correct
15 Correct 1 ms 3164 KB Output is correct
16 Correct 2 ms 3160 KB Output is correct
17 Correct 81 ms 3296 KB Output is correct
18 Correct 2 ms 3164 KB Output is correct
19 Correct 18 ms 3328 KB Output is correct
20 Correct 3 ms 3164 KB Output is correct
21 Correct 109 ms 3292 KB Output is correct
22 Correct 13 ms 3164 KB Output is correct
23 Correct 2 ms 3164 KB Output is correct
24 Correct 24 ms 3164 KB Output is correct
25 Correct 16 ms 3164 KB Output is correct
26 Correct 31 ms 3164 KB Output is correct
27 Correct 149 ms 3300 KB Output is correct
28 Correct 152 ms 3160 KB Output is correct
29 Correct 158 ms 3304 KB Output is correct
30 Correct 158 ms 3160 KB Output is correct
31 Correct 200 ms 3164 KB Output is correct
32 Correct 171 ms 3296 KB Output is correct
33 Correct 166 ms 3304 KB Output is correct
34 Correct 171 ms 3164 KB Output is correct
35 Correct 170 ms 3300 KB Output is correct
36 Correct 177 ms 3300 KB Output is correct
37 Correct 173 ms 3304 KB Output is correct