제출 #684672

#제출 시각아이디문제언어결과실행 시간메모리
684672abysmal캥거루 (CEOI16_kangaroo)C++14
100 / 100
27 ms336 KiB
#include<iostream>
#include<stdio.h>
#include<stdint.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<string>
#include<assert.h>
#include<math.h>
#include<chrono>
#include<random>
#include<bitset>

using namespace std;

const int64_t INF = (int64_t) 1e18 + 5;
const int64_t mINF = (int64_t) 1e5 + 5;
const int64_t MOD = (int64_t) 1e9 + 7;
const int nbit = 30;
const int ndig = 10;
const int nchar = 26;
const int p1 = 31;
const int p2 = 53;
const int D = 4;
int dr[D] = {0, 1, 0, -1};
int dc[D] = {1, 0, -1, 0};
// 0 right // 1 down // 2 left // 3 up

struct Solution
{
    int n;
    int s;
    int t;
    Solution() {}

    void solve()
    {
        cin >> n >> s >> t;

        vector<int> dp(n + 1, 0);
        dp[0] = 1;

        for(int i = 1; i <= n; i++)
        {
            vector<int> new_dp(n + 1, 0);

            if(i == s || i == t)
            {
                for(int j = 1; j <= n; j++)
                {
                    new_dp[j] = modadd(new_dp[j], dp[j]);
                    new_dp[j] = modadd(new_dp[j], dp[j - 1]);
                }
            }
            else
            {
                for(int j = 1; j <= n; j++)
                {
                    int x = j;
                    if(s < i) x--; if(t < i) x--;

                    new_dp[j] = modadd(new_dp[j], modmul(dp[j - 1], x));
                    if(j != n) new_dp[j] = modadd(new_dp[j], modmul(dp[j + 1], j));
                }
            }

            dp = new_dp;
        }

        cout << dp[1] << "\n";
    }

    int modsub(int t1, int t2)
    {
        int64_t res = t1 - t2;
        if(res < 0) res += MOD;

        return res;
    }

    int modadd(int t1, int t2)
    {
        int64_t res = t1 + t2;
        if(res >= MOD) res -= MOD;

        return res;
    }

    int modmul(int t1, int t2)
    {
        int64_t res = 1LL * t1 * t2;
        return (res % MOD);
    }

    bool BIT(int64_t& mask, int& j)
    {
        return (mask & MASK(j));
    }

    int64_t MASK(int j)
    {
        return (1LL << j);
    }

    int64_t Abs(int64_t t1)
    {
        if(t1 < 0) return -t1;
        return t1;
    }
};

void __startup()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
}

int main()
{
    __startup();
    int t = 1;
//    cin >> t;

    for(int i = 1; i <= t; i++)
    {
        Solution().solve();
    }

    return 0;
}

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

kangaroo.cpp: In member function 'void Solution::solve()':
kangaroo.cpp:65:21: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   65 |                     if(s < i) x--; if(t < i) x--;
      |                     ^~
kangaroo.cpp:65:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   65 |                     if(s < i) x--; if(t < i) x--;
      |                                    ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...