結果
| 問題 | No.93 ペガサス |
| コンテスト | |
| ユーザー |
anta
|
| 提出日時 | 2015-09-26 20:29:32 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 49 ms / 5,000 ms |
| コード長 | 4,664 bytes |
| コンパイル時間 | 665 ms |
| コンパイル使用メモリ | 85,012 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-19 10:43:35 |
| 合計ジャッジ時間 | 1,755 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
template<int MOD>
struct ModInt {
static const int Mod = MOD;
unsigned x;
ModInt() : x(0) {}
ModInt(signed sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
ModInt(signed long long sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
int get() const { return (int)x; }
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 = (unsigned long long)x * that.x % MOD; return *this; }
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; }
};
typedef ModInt<1000000007> mint;
struct DP {
int N;
vector<mint> dp;
DP(int N_) : N(N_) { init(); }
void init() {
dp.assign(N * 8, mint());
}
void swap(DP &that) {
dp.swap(that.dp);
}
//lasta: 1つ前のがattackされてるか
//snda: 2つ前のがattackされてるか
//twoc: 1つ前のと2つ前のが隣り合ってるか
//num: 3つより前のattackされてる個数
mint &operator()(int lasta, int snda, int twoc, int num) {
return dp[(lasta * 4 + snda * 2 + twoc) * N + num];
}
};
int main() {
/*
rer(N, 1, 10) {
vi perm(N);
iota(perm.begin(), perm.end(), 0);
int cnt[2][2][2][11] = {};
do {
int lasta = N >= 3 && abs(perm[0] - perm[2]) == 1;
int snda = N >= 4 && abs(perm[1] - perm[3]) == 1;
int twoc = N >= 2 && abs(perm[0] - perm[1]) == 1;
int num = 0;
reu(i, 2, N - 2)
num += abs(perm[i] - perm[i + 2]) == 1;
++ cnt[lasta][snda][twoc][num];
} while(next_permutation(perm.begin(), perm.end()));
rep(lasta, 2) rep(snda, 2) rep(twoc, 2) rer(num, 0, N) {
mint x = cnt[lasta][snda][twoc][num];
if(x.x == 0) continue;
cerr << N << ", " << lasta << ", " << snda << ", " << twoc << ", " << num << ": " << x.get() << endl;
}
int naiveans = cnt[0][0][0][0] + cnt[0][0][1][0];
cerr << N << ": " << naiveans << endl;
}*/
int N;
while(~scanf("%d", &N)) {
DP dp(N), ndp(N);
ndp(0, 0, 0, 0) = 1;
rep(i, N) {
dp.swap(ndp);
ndp.init();
rep(lasta, 2) rep(snda, 2) rep(twoc, 2) rer(num, 0, i) {
mint x = dp(lasta, snda, twoc, num);
if(x.x == 0) continue;
// cerr << i << ", " << lasta << ", " << snda << ", " << twoc << ", " << num << ": " << x.get() << endl;
if(twoc == 0) {
if(i >= 1) {
//1つ前のやつの左右
ndp(0, lasta, 1, num + snda) += x;
ndp(0, 0, 1, num + snda) += x;
}
if(i >= 2) {
//2つ前のやつの左右
ndp(1, lasta, 0, num) += x;
ndp(1, lasta, 0, num + snda) += x;
}
} else {
assert(i >= 2);
//1つ前のやつの隣で、2つ前のじゃないほう
ndp(0, 0, 1, num + snda) += x;
//1つ前のと2つ前のとの間
ndp(1, lasta, 1, num + snda) += x;
//2つ前のやつの隣で、1つ前のじゃないほう
ndp(1, lasta, 0, num) += x;
}
//1つ前の隣でも2つ前の隣でもない場所
int spaces = (i + 1) - (i >= 1 ? 2 : 0) - (i >= 2 ? 2 : 0) + twoc;
//そのうちattackされてるやつらの間
if(num > 0)
ndp(0, lasta, 0, num - 1 + snda) += x * num;
//それ以外
ndp(0, lasta, 0, num + snda) += x * (spaces - num);
}
}
mint ans;
rep(twoc, 2)
ans += ndp(0, 0, twoc, 0);
printf("%d\n", ans.get());
}
return 0;
}
anta