ソースコード 拡げる

Copy
// F.

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstdlib>

using namespace std;

static const int MOD = 1000000007;

struct modll {
long long x;
modll() : x(0) { }
modll(long long _x) : x(_x) { }
operator int() const { return (int)x; }
modll operator+(const modll &r) { return (x + r.x) % MOD; }
modll operator+=(const modll &r) { return x = (x + r.x) % MOD; }
modll operator-(const modll &r) { return (x + MOD - r.x) % MOD; }
modll operator-=(const modll &r) { return x = (x + MOD - r.x) % MOD; }
modll operator*(const modll &r) { return (x * r.x) % MOD; }
modll operator*(int r) { return (x * r) % MOD; }
modll operator*=(const modll &r) { return x = (x * r.x) % MOD; }
modll inverse() {
modll r = 1, a = x;
for (int b = MOD - 2; b; b >>= 1) {
if (b & 1) {
r *= a;
}
a *= a;
}
return r;
}
};

int main(int argc, char *argv[]) {
int N;
cin >> N;
string s;
cin >> s;
modll dp[301][301][301];
dp[0][0][0] = 1;
if (N <= 300) {
for (int i = 0; i < N; ++i) {
for (int j = 0; j <= i; ++j) {
int l = max(0, j - 1);
for (int k = 0; k <= i; ++k) {
if (j == k) {
dp[i + 1][j + 1][k] += dp[i][j][k];
dp[i + 1][j + 1][k + 1] += dp[i][j][k];
dp[i + 1][l][l] += dp[i][j][k];
} else {
dp[i + 1][j + 1][k] += dp[i][j][k] * 2;
dp[i + 1][l][k] += dp[i][j][k];
}
}
}
}
cout << dp[N][s.length()][s.length()] << endl;
} else {
cout << -1 << endl;
}
return 0;
}

#### 提出情報

提出日時 2016-08-13 22:23:11+0900 F - バイナリハック hotpepsi C++14 (GCC 5.4.1) 400 1567 Byte WA 469 ms 213248 KB

#### ジャッジ結果

セット名 Sample Sub1 Sub2

 AC × 2 WA × 1
 AC × 23
 AC × 23 WA × 21
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
0_01 AC 336 ms 213248 KB
0_02 AC 427 ms 213248 KB
0_03 WA 293 ms 213248 KB
1_04 AC 298 ms 213248 KB
1_05 AC 467 ms 213248 KB
1_06 AC 421 ms 213248 KB
1_07 AC 468 ms 213248 KB
1_08 AC 425 ms 213248 KB
1_09 AC 421 ms 213248 KB
1_10 AC 467 ms 213248 KB
1_11 AC 467 ms 213248 KB
1_12 AC 469 ms 213248 KB
1_13 AC 424 ms 213248 KB
1_14 AC 468 ms 213248 KB
1_15 AC 421 ms 213248 KB
1_16 AC 424 ms 213248 KB
1_17 AC 417 ms 213248 KB
1_18 AC 461 ms 213248 KB
1_19 AC 415 ms 213248 KB
1_20 AC 338 ms 213248 KB
1_21 AC 335 ms 213248 KB
1_22 AC 299 ms 213248 KB
1_23 AC 404 ms 213248 KB
1_24 AC 360 ms 213248 KB
2_25 WA 294 ms 213248 KB
2_26 WA 295 ms 213248 KB
2_27 WA 300 ms 213248 KB
2_28 WA 297 ms 213248 KB
2_29 WA 296 ms 213248 KB
2_30 WA 295 ms 213248 KB
2_31 WA 339 ms 213248 KB
2_32 WA 296 ms 213248 KB
2_33 WA 335 ms 213248 KB
2_34 WA 342 ms 213248 KB
2_35 WA 341 ms 213248 KB
2_36 WA 339 ms 213248 KB
2_37 WA 339 ms 213248 KB
2_38 WA 301 ms 213248 KB
2_39 WA 297 ms 213248 KB
2_40 WA 296 ms 213248 KB
2_41 WA 297 ms 213248 KB
2_42 WA 296 ms 213248 KB
2_43 WA 295 ms 213248 KB
2_44 WA 297 ms 213248 KB