답안 #1115513

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1115513 2024-11-20T14:34:08 Z Neco_arc Tents (JOI18_tents) C++17
100 / 100
124 ms 107968 KB
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
#define Neco "flagger"
#define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define getbit(x,i) ((x) >> (i))&1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define cntbit(x) __builtin_popcountll(x)
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define maxn (int) (5e3 + 5)

using namespace std;

const ll mod = 1e9 + 7; //972663749

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
    return uniform_int_distribution<ll> (l, r)(rng);
}

int n, m;
ll f[maxn][maxn];

inline void Add(ll &x, ll y) {
    if((x += y) >= mod) x -= mod;
}

ll C(ll x) { return (x * (x - 1) / 2) % mod; }

void solve()
{

    cin >> n >> m;

    fi(i, 0, n) fi(j, 0, m) {
        if(i == 0 || j == 0) { f[i][j] = 1; continue; };

        ll val = 4ll * j % mod * f[i - 1][j - 1] % mod;
        Add(val, f[i - 1][j]);

        Add(f[i][j], val);

        /// chon cung hang
        if(j >= 2) {
            ll val = 1ll * C(j) * f[i - 1][j - 2] % mod;
            Add(f[i][j], val);
        }

        /// chon cung cot
        if(i >= 2) {
            ll val = 1ll * (i - 1) * j % mod * f[i - 2][j - 1] % mod;
            Add(f[i][j], val);
        }
    }

    cout << (f[n][m] + mod - 1) % mod;

}

int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    if(fopen(Neco".inp", "r")) {
        freopen(Neco".inp", "r", stdin);
        freopen(Neco".out", "w", stdout);
    }

    int nTest = 1;
//    cin >> nTest;

    while(nTest--)
    {
        solve();
    }


    return 0;
}

Compilation message

tents.cpp: In function 'int main()':
tents.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         freopen(Neco".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
tents.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen(Neco".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 2 ms 8528 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 3 ms 10748 KB Output is correct
7 Correct 2 ms 4432 KB Output is correct
8 Correct 2 ms 10576 KB Output is correct
9 Correct 2 ms 6480 KB Output is correct
10 Correct 2 ms 12624 KB Output is correct
11 Correct 2 ms 2384 KB Output is correct
12 Correct 3 ms 12624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 2 ms 8528 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 3 ms 10748 KB Output is correct
7 Correct 2 ms 4432 KB Output is correct
8 Correct 2 ms 10576 KB Output is correct
9 Correct 2 ms 6480 KB Output is correct
10 Correct 2 ms 12624 KB Output is correct
11 Correct 2 ms 2384 KB Output is correct
12 Correct 3 ms 12624 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 10 ms 90604 KB Output is correct
15 Correct 70 ms 87624 KB Output is correct
16 Correct 5 ms 8784 KB Output is correct
17 Correct 17 ms 23632 KB Output is correct
18 Correct 22 ms 39248 KB Output is correct
19 Correct 87 ms 94492 KB Output is correct
20 Correct 66 ms 80492 KB Output is correct
21 Correct 40 ms 53816 KB Output is correct
22 Correct 42 ms 74548 KB Output is correct
23 Correct 31 ms 107968 KB Output is correct
24 Correct 124 ms 98120 KB Output is correct
25 Correct 87 ms 82760 KB Output is correct
26 Correct 98 ms 90696 KB Output is correct
27 Correct 124 ms 94792 KB Output is correct