Contest Duration: - (local time) (100 minutes) Back to Home

Submission #3511729

Source Code Expand

Copy
```#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)

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

#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))

using namespace std;

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 ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

const pid_t pid = getpid();
// Problem Specific Parameter:

template<unsigned MOD>  class ModInt {
public:
ModInt(): x(0) {}
ModInt(signed y) : x(y >= 0 ? y % MOD : MOD - (-y) % MOD) {}
ModInt(signed long long y) : x(y >= 0 ? y % MOD : MOD - (-y) % MOD) {}

// Arithmetic Oprators
ModInt &operator+=(ModInt that) {
if ((x += that.x) >= MOD) x -= MOD;
return *this;
}
ModInt &operator-=(ModInt that) {
if ((x += MOD - that.x) >= MOD) x -= MOD;
return *this;
}
ModInt &operator*=(ModInt that) {
x = 1LL * x * that.x % MOD;
return *this;
}
ModInt &operator/=(ModInt that) {
return *this *= ModInt(get<1>(extgcd(that.x, int(MOD))));
}
ModInt &operator%=(ModInt that) {
x %= that.x;
return *this;
}

ModInt &operator+=(const int that) { return *this += ModInt(that);}
ModInt &operator-=(const int that) { return *this -= ModInt(that);}
ModInt &operator*=(const int that) { return *this *= ModInt(that);}
ModInt &operator/=(const int that) { return *this /= ModInt(that);}
ModInt &operator%=(const int that) { return *this %= ModInt(that);}

// Comparators
bool operator <(ModInt that) { return x < that.x; }
bool operator >(ModInt that) { return x > that.x; }
bool operator<=(ModInt that) { return x <= that.x; }
bool operator>=(ModInt that) { return x >= that.x; }
bool operator!=(ModInt that) { return x != that.x; }
bool operator==(ModInt that) { return x == that.x; }

// Utilities
unsigned getval() const { return x;}
ModInt operator+(ModInt that) const { return ModInt(*this) += that;}
ModInt operator-(ModInt that) const { return ModInt(*this) -= that;}
ModInt operator*(ModInt that) const { return ModInt(*this) *= that;}
ModInt operator/(ModInt that) const { return ModInt(*this) /= that;}
ModInt operator%(ModInt that) const { return ModInt(*this) %= that;}
ModInt operator+(const int that) const { return ModInt(*this) += that;}
ModInt operator-(const int that) const { return ModInt(*this) -= that;}
ModInt operator*(const int that) const { return ModInt(*this) *= that;}
ModInt operator/(const int that) const { return ModInt(*this) /= that;}
ModInt operator%(const int that) const { return ModInt(*this) %= that;}
ModInt operator=(const int that) { return *this = ModInt(that);}
friend istream &operator>>(istream& is, ModInt &that) {ll tmp; is >> tmp; that = ModInt(tmp);return is;}
friend ostream &operator<<(ostream& os, const ModInt &that) { return os << that.x; }

ModInt power(ll n) const {
ll b = 1LL, a = x;
while(n){
if(n & 1) b = b * a % MOD;
a = a * a % MOD;
n >>= 1;
}
return ModInt(b);
}
private:
unsigned x;

inline auto extgcd(int a, int b) {
if (b == 0) return make_tuple(a, 1, 0);
tuple<int, int, int> ret = extgcd(b, a % b);
swap(get<1>(ret), get<2>(ret));
get<2>(ret) -= a / b * get<1>(ret);
return ret;
}
};

const int mod = 1000000007;
using mint = ModInt<mod>;
const mint ZERO = mint(0);
const mint ONE = mint(1);
const mint TWO = mint(2);

mint dp[5010][5010];

int main(void){
int n;
cin >> n;
string s;
cin >> s;
const int k = s.size();

dp[0][0] = ONE;
rep(i,n)rep(j,n+1){
if(dp[i][j] == ZERO) continue;
dp[i+1][j+1] += TWO * dp[i][j];
dp[i+1][max(0,j-1)] += dp[i][j];
}

mint cardinality = TWO.power(k);
mint ans = dp[n][k] / cardinality;
cout << ans << endl;

return 0;
}```

#### Submission Info

Submission Time 2018-11-01 02:26:55+0900 F - Unhappy Hacking Hec C++14 (GCC 5.4.1) 800 4638 Byte AC 131 ms 98304 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 30 ms 98304 KB
0_02 AC 31 ms 98304 KB
0_03 AC 131 ms 98304 KB
1_04 AC 30 ms 98304 KB
1_05 AC 31 ms 98304 KB
1_06 AC 31 ms 98304 KB
1_07 AC 31 ms 98304 KB
1_08 AC 31 ms 98304 KB
1_09 AC 31 ms 98304 KB
1_10 AC 31 ms 98304 KB
1_11 AC 31 ms 98304 KB
1_12 AC 31 ms 98304 KB
1_13 AC 31 ms 98304 KB
1_14 AC 31 ms 98304 KB
1_15 AC 31 ms 98304 KB
1_16 AC 31 ms 98304 KB
1_17 AC 31 ms 98304 KB
1_18 AC 31 ms 98304 KB
1_19 AC 31 ms 98304 KB
1_20 AC 30 ms 98304 KB
1_21 AC 30 ms 98304 KB
1_22 AC 30 ms 98304 KB
1_23 AC 31 ms 98304 KB
1_24 AC 30 ms 98304 KB
2_25 AC 130 ms 98304 KB
2_26 AC 131 ms 98304 KB
2_27 AC 131 ms 98304 KB
2_28 AC 131 ms 98304 KB
2_29 AC 131 ms 98304 KB
2_30 AC 131 ms 98304 KB
2_31 AC 131 ms 98304 KB
2_32 AC 131 ms 98304 KB
2_33 AC 131 ms 98304 KB
2_34 AC 131 ms 98304 KB
2_35 AC 130 ms 98304 KB
2_36 AC 131 ms 98304 KB
2_37 AC 130 ms 98304 KB
2_38 AC 130 ms 98304 KB
2_39 AC 131 ms 98304 KB
2_40 AC 110 ms 98304 KB
2_41 AC 71 ms 98304 KB
2_42 AC 125 ms 98304 KB
2_43 AC 82 ms 98304 KB
2_44 AC 32 ms 98304 KB