Submission #1284008

#TimeUsernameProblemLanguageResultExecution timeMemory
1284008nqcTents (JOI18_tents)C++20
100 / 100
94 ms70804 KiB
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define ll long long #define ull unsigned long long #define pii pair<int, int> #define pll pair<ll, ll> #define pli pair<ll, int> #define debug(x) cout << #x << " = " << x << '\n' #define all(a) a.begin(), a.end() #define SZ(a) (int)(a).size() const int N = 3e3 + 5; const int mod = 1e9 + 7; const ll inf64 = 3e18; const int inf32 = 2e9 + 5; ll add(ll a, ll b) { a += b; if(a < 0) a += mod; if(a >= mod) a -= mod; return a; } ll mul(ll a, ll b) { return a * b % mod; } int n, m; ll dp[N][N]; void solve() { cin >> n >> m; // dp[i][j] = so cach xep thoa man doi voi bang i*j dp[0][0] = 1; for(int i = 1; i <= n; i++) dp[i][0] = 1; for(int i = 1; i <= m; i++) dp[0][i] = 1; for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) { dp[i][j] = add(dp[i][j], dp[i - 1][j]); // dat vao 1 cot trong // -> bang con lai la (i-1)*(j-1) if(i - 1 >= 0 && j - 1 >= 0) dp[i][j] = add(dp[i][j], mul(dp[i - 1][j - 1], j * 4)); // dat vao 1 cot da open -> mat 1 cot, 2 dong // -> bang con lai la (i-2)*(j-1) if(i - 2 >= 0 && j - 1 >= 0) dp[i][j] = add(dp[i][j], mul(dp[i - 2][j - 1],(i - 1) * j)); // dat vao 2 cot trong // -> bang con lai la (i-1)*(j-2) if(i - 1 >= 0 && j - 2 >= 0) dp[i][j] = add(dp[i][j], mul(dp[i - 1][j - 2], j * (j - 1) / 2)); // cout << i << ' ' << j << ' ' << dp[i][j] << '\n'; } cout << add(dp[n][m], -1) << '\n'; } int main() { auto start = chrono::steady_clock::now(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen("input.txt", "r")) { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } int test = 1; // cin >> test; while(test--) solve(); chrono::duration<double> elapsed {chrono::steady_clock::now() - start}; cerr << "\n>> Runtime: " << elapsed.count() << "s\n"; }

Compilation message (stderr)

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