Submission #726895

#TimeUsernameProblemLanguageResultExecution timeMemory
726895sochu캥거루 (CEOI16_kangaroo)C++17
0 / 100
2 ms340 KiB
#include <bits/stdc++.h>
//#pragma GCC optimize ("03")
#define FastIO ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
#define FILES freopen("in" , "r" , stdin) , freopen("out" , "w" , stdout)
#define ll long long
#define ull unsigned long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define qwerty1 first
#define qwerty2 second
#define qwerty3 -> first
#define qwerty4 -> second
#define umap unordered_map
#define uset unordered_set
#define pii pair < ll , ll >
#define pq priority_queue
#define dbg(x) cerr << #x << ": " << x << '\n'

namespace FastRead
{
    char __buff[5000];ll __lg = 0 , __p = 0;
    char nc()
    {
        if(__lg == __p){__lg = fread(__buff , 1 , 5000 , stdin);__p = 0;if(!__lg) return EOF;}
        return __buff[__p++];
    }
    template<class T>void read(T&__x)
    {
        T __sgn = 1; char __c;while(!isdigit(__c = nc()))if(__c == '-')__sgn = -1;
        __x = __c - '0';while(isdigit(__c = nc()))__x = __x * 10 + __c - '0';__x *= __sgn;
    }
}

using namespace FastRead;
using namespace std;

const ll N = 2e3 + 10;
const ll M = 1e9 + 7;
const ld PI = acos(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n , cs , cf;
int dp[N][N][4];

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

signed main()
{
	#ifndef ONLINE_JUDGE
		FastIO , FILES;
	#endif

	int i , j;

	cin >> n >> cs >> cf;

    dp[1][1][0] = 1;

    for(i = 2 ; i <= n ; i++)
        for(j = 1 ; j <= i ; j++)
        {
            if(i != cf && i != cs)
            {
                add(dp[i][j][0] , j * dp[i - 1][j + 1][0] % M);
                add(dp[i][j][1] , j * dp[i - 1][j + 1][1] % M);
                add(dp[i][j][2] , j * dp[i - 1][j + 1][2] % M);
                add(dp[i][j][3] , j * dp[i - 1][j + 1][3] % M);
            }

            if(i == cs)
            {
                add(dp[i][j][1] , dp[i - 1][j][0]);
                add(dp[i][j][3] , dp[i - 1][j][2]);
            }
            else if(i == cf)
            {
                add(dp[i][j][2] , dp[i - 1][j][0]);
                add(dp[i][j][3] , dp[i - 1][j][1]);
            }
            else
            {
                ;
            }


            if(i == cs)
            {
                add(dp[i][j][0] , dp[i - 1][j - 1][0]);
                add(dp[i][j][0] , dp[i - 1][j - 1][1]);

                add(dp[i][j][2] , dp[i - 1][j - 1][2]);
                add(dp[i][j][2] , dp[i - 1][j - 1][3]);
            }
            else if(i == cf)
            {
                add(dp[i][j][0] , dp[i - 1][j - 1][0]);
                add(dp[i][j][0] , dp[i - 1][j - 1][2]);

                add(dp[i][j][1] , dp[i - 1][j - 1][1]);
                add(dp[i][j][1] , dp[i - 1][j - 1][3]);
            }
            else
            {
                add(dp[i][j][0] , (j - 2) * dp[i - 1][j - 1][0]);
                add(dp[i][j][1] , (j - 2) * dp[i - 1][j - 1][1]);
                add(dp[i][j][2] , (j - 2) * dp[i - 1][j - 1][2]);
                add(dp[i][j][3] , (j - 2) * dp[i - 1][j - 1][3]);

                if(i < cs)
                {
                    add(dp[i][j][0] , dp[i - 1][j - 1][0]);
                    add(dp[i][j][0] , dp[i - 1][j - 1][1]);

                    add(dp[i][j][2] , dp[i - 1][j - 1][2]);
                    add(dp[i][j][2] , dp[i - 1][j - 1][3]);
                }

                if(i < cf)
                {
                    add(dp[i][j][0] , dp[i - 1][j - 1][0]);
                    add(dp[i][j][0] , dp[i - 1][j - 1][2]);

                    add(dp[i][j][1] , dp[i - 1][j - 1][1]);
                    add(dp[i][j][1] , dp[i - 1][j - 1][3]);
                }
            }
        }

    int ans = 0;

    for(i = 0 ; i < 4 ; i++)
        add(ans , dp[n][1][i]);

    cout << ans;

    return 0;
}

Compilation message (stderr)

kangaroo.cpp: In function 'int main()':
kangaroo.cpp:4:22: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    4 | #define FILES freopen("in" , "r" , stdin) , freopen("out" , "w" , stdout)
      |               ~~~~~~~^~~~~~~~~~~~~~~~~~~~
kangaroo.cpp:55:12: note: in expansion of macro 'FILES'
   55 |   FastIO , FILES;
      |            ^~~~~
kangaroo.cpp:4:52: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    4 | #define FILES freopen("in" , "r" , stdin) , freopen("out" , "w" , stdout)
      |                                             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
kangaroo.cpp:55:12: note: in expansion of macro 'FILES'
   55 |   FastIO , FILES;
      |            ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...