제출 #1046461

#제출 시각아이디문제언어결과실행 시간메모리
1046461Neco_arc캥거루 (CEOI16_kangaroo)C++17
100 / 100
13 ms23132 KiB
#include <bits/stdc++.h>
#ifdef LOCAL
#include <bits/debug.hpp>
#endif // LOCAL

#define ll long long
#define all(x) x.begin(), x.end()
#define Neco "Kangaroo"
#define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define getbit(x,i) ((x >> i)&1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define cntbit(x) __builtin_popcountll(x)
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define maxn (int) 2e3 + 7

using namespace std;

const ll mod = 1e9 + 7; //972663749
const ll base = 911382323;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
    return uniform_int_distribution<ll> (l, r)(rng);
}

/// dem so hoan vi co a la phan tu dau va b la phan tu cuoi
/// hoan vi phai thoa man theo kieu len xuong : /\/\/\/, ko dc cung xuong hoac cung len
/// connected component dp, vi co dinh dau cuoi nen ko can phai xet den thao tac chen vao ngoai tru luc them dau cuoi :0
/// neu ko co dau cuoi thi bat buoc phai co thao tac chen
/// vi ko co thao tac chen va them cac phan tu theo thu tu tang dan, nen moi tplt ko chua dau cuoi phai tm tinh chat /\/\/\, cai dau phai la len va cai cuoi luon la xuong

int n, st, fn;
ll dp[maxn][maxn]; /// duyet den i va co j tplt

void solve()
{

    cin >> n >> st >> fn;

    dp[1][1] = 1;
    int w = st == 1 || fn == 1;

    fi(i, 2, n) {
        w += i == fn || i == st;
        fi(j, 1, i) {
            if(i == st || i == fn) {
                dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % mod;
            }
            else {
                if(j > w) dp[i][j] = (dp[i][j] + (j - w) * dp[i - 1][j - 1]) % mod;
                dp[i][j] = (dp[i][j] + j * dp[i - 1][j + 1]) % mod;
            }
        }
    }

    cout << dp[n][1];


}


int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    if(fopen(Neco".inp", "r")) {
        freopen(Neco".inp", "r", stdin);
        freopen(Neco".out", "w", stdout);
    }


    int nTest = 1;
//    cin >> nTest;


    while(nTest--)
    {
        solve();
    }


    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

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