Submission #1146931

#TimeUsernameProblemLanguageResultExecution timeMemory
1146931iah캥거루 (CEOI16_kangaroo)C++20
100 / 100
5 ms328 KiB
#include<bits/stdc++.h> using namespace std; #define NAME "" #define ll long long #define pii pair < int , int > #define fi first #define se second #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i ++) #define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; i --) #define REP(i, n) for (int i = 0, _n = (n); i < _n; i ++) #define bit(x, i) (((x) >> (i)) & 1ll) #define mask(x) (1ll << (x)) #define mem(f, x) memset(f, x, sizeof(f)) #define sz(x) (int32_t) (x.size()) const int nmax = 2000; const int mod = 1e9 + 7; ll dp[2][nmax + 7]; signed main() { for(string s: {NAME, ""}) { if (fopen((s + ".inp").c_str(), "r")) { freopen((s + ".inp").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); break; } } cin.tie(0)->sync_with_stdio(0); int n, cs, cf; cin >> n >> cs >> cf; dp[1][1] = 1; FOR(i, 2, n) { FOR(j, 1, i) { dp[i % 2][j] = 0; } FOR(j, 1, i - 1) { if (i == cs || i == cf) { dp[i % 2][j] += dp[1 - i % 2][j]; dp[i % 2][j] %= mod; dp[i % 2][j + 1] += dp[1 - i % 2][j]; dp[i % 2][j + 1] %= mod; } else if (j + 1 > 0) { dp[i % 2][j + 1] += dp[1 - i % 2][j] * (j + 1 - (i > cs) - (i > cf)); dp[i % 2][j + 1] %= mod; dp[i % 2][j - 1] += dp[1 - i % 2][j] * (j - 1); dp[i % 2][j - 1] %= mod; } } // cout << i << ":\n"; // FOR(j, 1, i) { // cout << j << " " << dp[i % 2][j] << "\n"; // } } cout << dp[n % 2][1]; return 0; }

Compilation message (stderr)

kangaroo.cpp: In function 'int main()':
kangaroo.cpp:24:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |       freopen((s + ".inp").c_str(), "r", stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kangaroo.cpp:25:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |       freopen((s + ".out").c_str(), "w", stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...