Submission #1307338
Source Code Expand
#include <bits/stdc++.h>
// #include "ane.cpp"
const int INF = 1e9;
const long long INFLL = 1e18;
const int NMAX = 5005;
const int MMAX = 100005;
const int KMAX = 1005;
const int MOD = 1e9 + 7;
using namespace std;
// comment to disable debug functions
// #define DEBUG
// frequently used macros
#if __cplusplus >= 201103L
#define ALL(v) begin(v),end(v)
#define SORT(v) sort(begin(v), end(v))
#define FIND(v,x) find(begin(v), end(v), (x))
#else
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(v.begin(), v.end())
#define FIND(v,x) find(v.begin(), v.end(), (x))
#endif
#define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \
memset((from), 0, sizeof(from)); } while(0)
#ifdef DEBUG
#define DUMP(x) do{ std::cerr << (#x) << ": " << x << std::endl; }while(0)
#else
#define DUMP(x) do{}while(0)
#endif
// frequent used aliases
typedef long long ll;
typedef pair<int, int> p;
typedef pair<ll, int> pl;
typedef pair<ll, ll> pll;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<vec> mat;
typedef vector<vecll> matll;
// frequently used constants
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};
// frequently used structs
struct edge{
int to,cost;
};
// printf for debug
#ifndef DEBUG
void debug(const char* format, ...){}
#else
void debug(const char* format, ...){
va_list arg;
va_start(arg, format);
vprintf(format, arg);
va_end(arg);
}
#endif
// dump vector
#ifdef DEBUG
#define DUMPV(v, c) do{ \
printf("%s: ", #v); \
for (int i = 0; i < (c); ++i) \
{ \
cout << (v)[i] << " "; \
} \
cout << endl; \
} while(0)
#else
#define DUMPV(v,c)
#endif
// std::fill of multi dimensions
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
std::fill( (T*)array, (T*)(array+N), val );
}
// binary search
ll BSearch(ll _begin, ll _end, bool (*f)(int)){
ll mid;
while(_end - _begin > 1LL) {
mid = (_begin + _end) / 2LL;
if(f(mid)) {
debug("BSearch: f(%d) == true\n", mid);
_end = mid;
}
else
{
debug("BSearch: f(%d) == false\n", mid);
_begin = mid;
}
}
return _end;
}
ll N,M,K,A,B,C,D,E;
int dp[NMAX][NMAX] = {};
string S;
vec v;
ll ans = 0;
void solve(){
// main algorithm
// dp
dp[0][0] = 1;
for (int i = 0; i < N; ++i)
{
for (int j = 0; j <= i; ++j)
{
if(!dp[i][j]) continue;
dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j] * 2) % MOD;
if(j > 0) dp[i+1][j-1] = (dp[i+1][j-1] + dp[i][j]) % MOD;
else dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % MOD;
}
}
// ans = dp[M] / 2 ^ M (mod 1000000007)
ans = dp[N][M];
for (int i = 0; i < M; ++i)
{
ans = ans * (ll)(5e8 + 4) % MOD;
}
}
void debug(){
// output debug information
for (int i = 0; i < N + 1; ++i)
{
for (int j = 0; j < i + 1; ++j)
{
cout << dp[i][j] << "\t";
}
cout << endl;
}
}
void answer(){
// output answer
printf("%lld\n", ans);
}
int main(int argc, char const *argv[])
{
// operate inputs
// Fill(dp, -1);
scanf("%lld", &N);
cin >> S;
M = S.size();
solve();
#ifdef DEBUG
debug();
#endif
answer();
return 0;
}
Submission Info
Submission Time
2017-05-26 16:00:51+0900
Task
F - Unhappy Hacking
User
anekawa
Language
C++14 (GCC 5.4.1)
Score
800
Code Size
3413 Byte
Status
AC
Exec Time
69 ms
Memory
96384 KB
Compile Error
./Main.cpp: In function ‘int main(int, const char**)’:
./Main.cpp:154:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &N);
^
Judge Result
Set Name
Sample
Sub1
Sub2
Score / Max Score
0 / 0
400 / 400
400 / 400
Status
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
1 ms
256 KB
0_02
AC
2 ms
4736 KB
0_03
AC
68 ms
96384 KB
1_04
AC
1 ms
256 KB
1_05
AC
2 ms
4736 KB
1_06
AC
2 ms
4736 KB
1_07
AC
2 ms
4736 KB
1_08
AC
2 ms
4736 KB
1_09
AC
2 ms
4736 KB
1_10
AC
2 ms
4736 KB
1_11
AC
2 ms
4736 KB
1_12
AC
2 ms
4736 KB
1_13
AC
2 ms
4736 KB
1_14
AC
2 ms
4736 KB
1_15
AC
2 ms
4736 KB
1_16
AC
2 ms
4736 KB
1_17
AC
2 ms
4736 KB
1_18
AC
2 ms
4736 KB
1_19
AC
2 ms
4736 KB
1_20
AC
1 ms
512 KB
1_21
AC
2 ms
2688 KB
1_22
AC
1 ms
512 KB
1_23
AC
2 ms
4736 KB
1_24
AC
2 ms
4736 KB
2_25
AC
68 ms
96384 KB
2_26
AC
69 ms
96384 KB
2_27
AC
69 ms
96384 KB
2_28
AC
69 ms
96384 KB
2_29
AC
69 ms
96384 KB
2_30
AC
69 ms
96384 KB
2_31
AC
69 ms
96384 KB
2_32
AC
69 ms
96384 KB
2_33
AC
69 ms
96384 KB
2_34
AC
69 ms
96384 KB
2_35
AC
69 ms
96384 KB
2_36
AC
68 ms
96256 KB
2_37
AC
68 ms
96256 KB
2_38
AC
68 ms
96256 KB
2_39
AC
68 ms
96384 KB
2_40
AC
56 ms
86656 KB
2_41
AC
33 ms
62080 KB
2_42
AC
65 ms
94848 KB
2_43
AC
40 ms
70272 KB
2_44
AC
5 ms
12928 KB