結果
問題 | No.93 ペガサス |
ユーザー | LayCurse |
提出日時 | 2014-12-07 23:01:34 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 73 ms / 5,000 ms |
コード長 | 3,149 bytes |
コンパイル時間 | 1,175 ms |
コンパイル使用メモリ | 161,284 KB |
実行使用メモリ | 41,772 KB |
最終ジャッジ日時 | 2024-06-11 17:46:15 |
合計ジャッジ時間 | 2,308 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 9 ms
40,988 KB |
testcase_01 | AC | 10 ms
41,128 KB |
testcase_02 | AC | 10 ms
41,188 KB |
testcase_03 | AC | 10 ms
41,772 KB |
testcase_04 | AC | 17 ms
41,176 KB |
testcase_05 | AC | 13 ms
41,476 KB |
testcase_06 | AC | 12 ms
41,632 KB |
testcase_07 | AC | 39 ms
41,252 KB |
testcase_08 | AC | 25 ms
41,060 KB |
testcase_09 | AC | 63 ms
41,116 KB |
testcase_10 | AC | 10 ms
41,124 KB |
testcase_11 | AC | 12 ms
41,180 KB |
testcase_12 | AC | 53 ms
41,192 KB |
testcase_13 | AC | 20 ms
41,204 KB |
testcase_14 | AC | 14 ms
41,688 KB |
testcase_15 | AC | 52 ms
41,252 KB |
testcase_16 | AC | 16 ms
41,092 KB |
testcase_17 | AC | 9 ms
41,112 KB |
testcase_18 | AC | 10 ms
41,060 KB |
testcase_19 | AC | 73 ms
41,128 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; #define REP(i,a,b) for(i=a;i<b;i++) #define rep(i,n) REP(i,0,n) #define mygc(c) (c)=getchar_unlocked() #define mypc(c) putchar_unlocked(c) #define ll long long #define ull unsigned ll void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);} void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);} int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;} template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);} template <class T, class S, class U> void reader(T *x, S *y, U *z){reader(x);reader(y);reader(z);} template <class T, class S, class U, class V> void reader(T *x, S *y, U *z, V *w){reader(x);reader(y);reader(z);reader(w);} void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);} void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);} void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);} void writer(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);} template<class T> void writerLn(T x){writer(x,'\n');} template<class T, class S> void writerLn(T x, S y){writer(x,' ');writer(y,'\n');} template<class T, class S, class U> void writerLn(T x, S y, U z){writer(x,' ');writer(y,' ');writer(z,'\n');} template<class T> void writerArr(T x[], int n){int i;if(!n){mypc('\n');return;}rep(i,n-1)writer(x[i],' ');writer(x[n-1],'\n');} #define MD 1000000007 int brute(int N){ int i, j, k; int d[100]; int res = 0; rep(i,N) d[i] = i; do{ REP(i,1,N) if(d[i]==d[i-1]+2 || d[i]==d[i-1]-2) break; if(i<N) continue; res++; }while(next_permutation(d,d+N)); return res; } int N; ll dp[2][2][1111][1111]; ll solve(int f1, int f2, int num, int dame){ int i, j, k, rest; ll res = 0; if(dp[f1][f2][num][dame] >= 0) return dp[f1][f2][num][dame]; if(num==N){ if(dame==0) res++; return dp[f1][f2][num][dame] = res; } rest = num+1; if(dame) res += (dame-f1-f2) * solve(f2, 0, num+1, dame-1); if(f2==1 && dame) res += solve(0, 0, num+1, dame-1); if(f1==0) res += 2*solve(f2, 1, num+1, dame+1); if(f1==1) res += solve(f2, 1, num+1, dame+1); if(f1==1) res += solve(f2, 1, num+1, dame); res += (num-1+f1-dame) * solve(f2, 0, num+1, dame); return dp[f1][f2][num][dame] = res % MD; } int main(){ int i, j, k, l; ll res = 0; rep(i,2) rep(j,2) rep(k,1010) rep(l,1010) dp[i][j][k][l] = -1; reader(&N); if(N==1) res = 1; else res = 2 * solve(0, 0, 2, 0) % MD; writerLn(res); return 0; }