Submission #839079


Source Code Expand

Copy
#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;

using ll=long long;

const ll mod=1000000007LL;

inline ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
inline ll ADD(const ll &a, const ll &b,const ll &mod) { return a+b<mod?a+b:a+b-mod;}
inline ll SUB(const ll &a, const ll &b,const ll &mod) { return a-b>=0?a-b:a-b+mod;}
inline ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
inline ll INV(ll a,ll mod){ll x,y;extgcd(a,mod,x,y);return (x%mod+mod)%mod;}
inline ll DIV(const ll &a, const ll &b,const ll &mod) {return MUL(a,INV(b,mod),mod);}
inline ll POW(ll a,ll n,ll mod){ll b=1LL;for(a%=mod;n;a=MUL(a,a,mod),n>>=1)if(n&1) b=MUL(b,a,mod); return b;}

ll dp[5010][5010];

string s;

int main(void){
	int n;
	cin >> n >> s;

	const int m=s.size();
	dp[0][0]=1LL;
	rep(i,n)rep(j,n+1){
		dp[i+1][j+1]=ADD(dp[i+1][j+1],MUL(2LL,dp[i][j],mod),mod);
		dp[i+1][max(0,j-1)]=ADD(dp[i+1][max(0,j-1)],dp[i][j],mod);
	}

	cout << DIV(dp[n][m],POW(2LL,m,mod),mod) << endl;
	return 0;
}

Submission Info

Submission Time
Task F - Unhappy Hacking
User Hec
Language C++14 (GCC 5.4.1)
Score 800
Code Size 1886 Byte
Status AC
Exec Time 755 ms
Memory 195968 KB

Judge Result

Set Name Sample Sub1 Sub2
Score / Max Score 0 / 0 400 / 400 400 / 400
Status
AC × 3
AC × 23
AC × 44
Set Name Test Cases
Sample 0_01, 0_02, 0_03
Sub1 0_01, 0_02, 1_04, 1_05, 1_06, 1_07, 1_08, 1_09, 1_10, 1_11, 1_12, 1_13, 1_14, 1_15, 1_16, 1_17, 1_18, 1_19, 1_20, 1_21, 1_22, 1_23, 1_24
Sub2 0_01, 0_02, 0_03, 1_04, 1_05, 1_06, 1_07, 1_08, 1_09, 1_10, 1_11, 1_12, 1_13, 1_14, 1_15, 1_16, 1_17, 1_18, 1_19, 1_20, 1_21, 1_22, 1_23, 1_24, 2_25, 2_26, 2_27, 2_28, 2_29, 2_30, 2_31, 2_32, 2_33, 2_34, 2_35, 2_36, 2_37, 2_38, 2_39, 2_40, 2_41, 2_42, 2_43, 2_44
Case Name Status Exec Time Memory
0_01 AC 4 ms 256 KB
0_02 AC 10 ms 2176 KB
0_03 AC 694 ms 195968 KB
1_04 AC 4 ms 256 KB
1_05 AC 10 ms 2176 KB
1_06 AC 10 ms 2176 KB
1_07 AC 11 ms 2176 KB
1_08 AC 9 ms 2176 KB
1_09 AC 9 ms 2176 KB
1_10 AC 11 ms 2176 KB
1_11 AC 10 ms 2176 KB
1_12 AC 11 ms 2176 KB
1_13 AC 10 ms 2176 KB
1_14 AC 9 ms 2176 KB
1_15 AC 9 ms 2176 KB
1_16 AC 9 ms 2176 KB
1_17 AC 9 ms 2048 KB
1_18 AC 10 ms 2048 KB
1_19 AC 9 ms 2048 KB
1_20 AC 5 ms 512 KB
1_21 AC 7 ms 1408 KB
1_22 AC 5 ms 640 KB
1_23 AC 9 ms 2048 KB
1_24 AC 8 ms 1664 KB
2_25 AC 708 ms 195968 KB
2_26 AC 688 ms 195968 KB
2_27 AC 691 ms 195968 KB
2_28 AC 690 ms 195968 KB
2_29 AC 687 ms 195968 KB
2_30 AC 695 ms 195968 KB
2_31 AC 692 ms 195968 KB
2_32 AC 689 ms 195968 KB
2_33 AC 694 ms 195968 KB
2_34 AC 688 ms 195968 KB
2_35 AC 697 ms 195840 KB
2_36 AC 691 ms 195712 KB
2_37 AC 755 ms 195712 KB
2_38 AC 689 ms 195712 KB
2_39 AC 691 ms 195712 KB
2_40 AC 647 ms 172416 KB
2_41 AC 312 ms 91904 KB
2_42 AC 664 ms 190720 KB
2_43 AC 434 ms 115072 KB
2_44 AC 22 ms 5888 KB