답안 #203612

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
203612 2020-02-21T15:28:46 Z stefdasca 캥거루 (CEOI16_kangaroo) C++14
51 / 100
2000 ms 31736 KB
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n, a, b;
int add(int a, int b)
{
    int x = a+b;
    if(x >= mod)
        x -= mod;
    if(x < 0)
        x += mod;
    return x;
}
int dp[2][2002][2002];
int sp[2][2][2002][2002];
int main()
{
    cin >> n >> a >> b;
    for(int i = 1; i <= n; ++i)
        if(i != a && i != b)
            dp[(a < i)][i - 1 - (a < i)][b - (a < b) - (i < b)] = 1;
    if(n == 2)
    {
        cout << 1;
        return 0;
    }
    int ans = 0;
    for(int sum = n-2; sum >= 1; --sum)
    {
        for(int i = 0; i <= sum; ++i)
            for(int pos = 1; pos <= sum; ++pos)
            {
                int smaller = i;
                int bigger = sum - i;
                if(sum != n-2)
                {
                    dp[0][smaller][pos] = add(sp[0][0][smaller][pos], (smaller > 0) * dp[0][smaller - 1][pos]);
                    dp[1][smaller][pos] = add(sp[0][1][smaller][pos], (smaller > 0) * dp[1][smaller - 1][pos]);
                }
                if(!dp[0][smaller][pos] && !dp[1][smaller][pos])
                    continue;
             //   cout << sum << '\n';
               // cout << smaller << " " << bigger << " " << pos << '\n';
               // cout << dp[0][smaller][bigger][pos] << " " << dp[1][smaller][bigger][pos] << '\n';
                if(sum == 1)
                {
                    if(smaller)
                        ans = add(ans, dp[1][smaller][1]);
                    else
                        ans = add(ans, dp[0][smaller][1]);
                }
                else
                {
                    if(pos <= smaller)
                    {
                        sp[1][0][0][pos - 1] = add(sp[1][0][0][pos - 1], dp[1][smaller][pos]);
                        sp[1][0][pos - 1][pos - 1] = add(sp[1][0][pos - 1][pos - 1], -dp[1][smaller][pos]);

                        sp[1][0][pos][pos] = add(sp[1][0][pos][pos], dp[1][smaller][pos]);
                        sp[1][0][smaller][pos] = add(sp[1][0][smaller][pos], -dp[1][smaller][pos]);

                        sp[1][1][smaller][pos] = add(sp[1][1][smaller][pos], dp[0][smaller][pos]);
                        sp[1][1][sum][pos] = add(sp[1][1][sum][pos], -dp[0][smaller][pos]);
                    }
                    else
                    {
                        sp[1][0][0][pos - 1] = add(sp[1][0][0][pos - 1], dp[1][smaller][pos]);
                        sp[1][0][smaller][pos - 1] = add(sp[1][0][smaller][pos - 1], -dp[1][smaller][pos]);

                        sp[1][1][smaller][pos - 1] = add(sp[1][1][smaller][pos - 1], dp[0][smaller][pos]);
                        sp[1][1][pos - 1][pos - 1] = add(sp[1][1][pos - 1][pos - 1], -dp[0][smaller][pos]);

                        sp[1][1][pos][pos] = add(sp[1][1][pos][pos], dp[0][smaller][pos]);
                        sp[1][1][sum][pos] = add(sp[1][1][sum][pos], -dp[0][smaller][pos]);
                    }
                    /*
                    for(int relpos = 1; relpos <= sum; ++relpos)
                    {
                        if(pos == relpos)
                            continue;
                        if(relpos <= smaller)
                            dp[1][0][relpos - 1][pos - (relpos < pos)] = add(dp[1][0][relpos - 1][pos - (relpos < pos)],
                                                                                        dp[0][1][smaller][pos]);
                        else
                            dp[1][1][relpos - 1][pos - (relpos < pos)] = add(dp[1][1][relpos - 1][pos - (relpos < pos)],
                                                                                        dp[0][0][smaller][pos]);
                    }
                    */
                }
            }
        for(int x = 0; x <= 1; ++x)
            for(int q = 0; q <= sum; ++q)
                for(int p = 0; p <= sum; ++p)
                    sp[0][x][q][p] = sp[1][x][q][p], sp[1][x][q][p] = 0;
    }
    cout << ans;
    return 0;
}

Compilation message

kangaroo.cpp: In function 'int main()':
kangaroo.cpp:34:21: warning: unused variable 'bigger' [-Wunused-variable]
                 int bigger = sum - i;
                     ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 6 ms 1016 KB Output is correct
4 Correct 6 ms 1272 KB Output is correct
5 Correct 5 ms 1272 KB Output is correct
6 Correct 5 ms 1272 KB Output is correct
7 Correct 6 ms 1272 KB Output is correct
8 Correct 5 ms 1272 KB Output is correct
9 Correct 7 ms 1272 KB Output is correct
10 Correct 6 ms 1272 KB Output is correct
11 Correct 6 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 6 ms 1016 KB Output is correct
4 Correct 6 ms 1272 KB Output is correct
5 Correct 5 ms 1272 KB Output is correct
6 Correct 5 ms 1272 KB Output is correct
7 Correct 6 ms 1272 KB Output is correct
8 Correct 5 ms 1272 KB Output is correct
9 Correct 7 ms 1272 KB Output is correct
10 Correct 6 ms 1272 KB Output is correct
11 Correct 6 ms 1272 KB Output is correct
12 Correct 50 ms 6008 KB Output is correct
13 Correct 39 ms 5624 KB Output is correct
14 Correct 24 ms 6008 KB Output is correct
15 Correct 53 ms 6132 KB Output is correct
16 Correct 25 ms 6008 KB Output is correct
17 Correct 58 ms 6008 KB Output is correct
18 Correct 29 ms 5368 KB Output is correct
19 Correct 49 ms 5880 KB Output is correct
20 Correct 52 ms 6008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 6 ms 1016 KB Output is correct
4 Correct 6 ms 1272 KB Output is correct
5 Correct 5 ms 1272 KB Output is correct
6 Correct 5 ms 1272 KB Output is correct
7 Correct 6 ms 1272 KB Output is correct
8 Correct 5 ms 1272 KB Output is correct
9 Correct 7 ms 1272 KB Output is correct
10 Correct 6 ms 1272 KB Output is correct
11 Correct 6 ms 1272 KB Output is correct
12 Correct 50 ms 6008 KB Output is correct
13 Correct 39 ms 5624 KB Output is correct
14 Correct 24 ms 6008 KB Output is correct
15 Correct 53 ms 6132 KB Output is correct
16 Correct 25 ms 6008 KB Output is correct
17 Correct 58 ms 6008 KB Output is correct
18 Correct 29 ms 5368 KB Output is correct
19 Correct 49 ms 5880 KB Output is correct
20 Correct 52 ms 6008 KB Output is correct
21 Correct 1677 ms 26384 KB Output is correct
22 Correct 1935 ms 28660 KB Output is correct
23 Execution timed out 2094 ms 31736 KB Time limit exceeded
24 Halted 0 ms 0 KB -