Submission #1033938

#TimeUsernameProblemLanguageResultExecution timeMemory
1033938vjudge1Tents (JOI18_tents)C++17
100 / 100
114 ms70964 KiB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
// #define double long double
 
#define endl '\n'
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define setmin(x, y) x = min((x), (y))
#define setmax(x, y) x = max((x), (y))
#define sqr(x) ((x) * (x))
#define fi first
#define se second
#define all(x) x.begin(), x.end()
 
// mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count());
// int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);}

const int NM = 3e3 + 5;
const int mod = 1e9 + 7;

int w, h, f[NM][NM];

signed main()
{
    fastIO
    if (fopen("in.txt", "r")) 
    {
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    }
    cin >> w >> h;
    for (int i = 0; i <= h; i++)
        f[0][i] = 1;
    for (int i = 1; i <= w; i++)
        for (int j = 0; j <= h; j++)
        {
            f[i][j] = f[i - 1][j - 1] * 4ll * j % mod;
            f[i][j] = (f[i][j] + f[i - 1][j]) % mod;
            if (j > 1 && i)
                f[i][j] = (f[i][j] + f[i - 1][j - 2] * ((j * (j - 1) / 2) % mod) % mod) % mod;
            if (i > 1 && j)
                f[i][j] = (f[i][j] + f[i - 2][j - 1] * j % mod * (i - 1) % mod) % mod;
        }
    cout << (f[w][h] + mod - 1) % mod << endl;
}

Compilation message (stderr)

tents.cpp: In function 'int main()':
tents.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         freopen("in.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
tents.cpp:31:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         freopen("out.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...