Submission #152938

#TimeUsernameProblemLanguageResultExecution timeMemory
152938Mercenary캥거루 (CEOI16_kangaroo)C++14
100 / 100
66 ms14204 KiB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 2e3 + 5;
const int mod = 1e9 + 7;

int n , cs , cf;

int dp[maxn][maxn];

void add(int & x , int y){
    x += y;
    if(x >= mod)x -= mod;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n >> cs >> cf;
    if(cs > cf)swap(cs , cf);
    dp[1][0] = 1;
    for(int i = 1 ; i <= n ; ++i){
        for(int j = 0 ; j <= i ; ++j){
            if(i == cs || i == cf){
                add(dp[i + 1][j] , dp[i][j]);
                if(j > 0)add(dp[i + 1][j - 1] , (ll)dp[i][j] * j % mod);
            }
            else{
                if(i > cs && j > 0){
                    add(dp[i + 1][j - 1] , (ll)dp[i][j] * j % mod);
                }
                if(i > cf && j > 0){
                    add(dp[i + 1][j - 1] , (ll)dp[i][j] * j % mod);
                }
                add(dp[i + 1][j + 1] , dp[i][j]);
                if(j > 1)add(dp[i + 1][j - 1] , (ll)j * (j - 1) % mod * dp[i][j] % mod);
            }
        }
    }
    cout << dp[n][0];
}

Compilation message (stderr)

kangaroo.cpp: In function 'int main()':
kangaroo.cpp:34:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
kangaroo.cpp:35:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "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...