結果

問題 No.93 ペガサス
ユーザー krotonkroton
提出日時 2014-10-28 12:51:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 35 ms / 5,000 ms
コード長 1,585 bytes
コンパイル時間 573 ms
コンパイル使用メモリ 64,112 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 23:12:55
合計ジャッジ時間 1,802 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 6 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 20 ms
4,380 KB
testcase_08 AC 11 ms
4,380 KB
testcase_09 AC 33 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 27 ms
4,376 KB
testcase_13 AC 9 ms
4,376 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 25 ms
4,376 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 35 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7;
ll dp[2][1050][2][2];

void add(ll &a, ll b){
    a = (a + b % MOD) % MOD;
}

ll solve(int n){
    if(n == 1)return 1;
    
    int curr = 0, next = 1;
    memset(dp[curr], 0, sizeof(dp[curr]));
    
    int segs = 3;
    dp[curr][0][0][0] = 2;
    
    for(int i=3;i<=n;i++){
        memset(dp[next], 0, sizeof(dp[next]));
        
        for(int b=0;b<=segs;b++){
            int s = segs - b;
            
            for(int p2=0;p2<=1;p2++)for(int p1=0;p1<=1;p1++){
                int pb = p1 + p2;
                int ps = 3 - pb;
                
                int nb = b - pb;
                int ns = s - ps;
                
                if(nb < 0 || ns < 0)continue;
                
                ll now = dp[curr][b][p2][p1];
                
                add(dp[next][b+1][p1][1], now);
                add(dp[next][b+1-p2][p1][1], now);
                
                add(dp[next][b-p1][0][0], now);
            
                if(nb > 0){
                    add(dp[next][b-1][p1][0], nb * now);
                }
                
                if(ns > 0){
                    add(dp[next][b][p1][0], ns * now);
                }
            }
        }
        
        swap(curr, next);
        ++segs;
    }
    
    return dp[curr][0][0][0];
}


int main(){
    int N;
    cin >> N;
    
    cout << solve(N) << endl;
    return 0;
}
0