제출 #526892

#제출 시각아이디문제언어결과실행 시간메모리
526892tphuc2908캥거루 (CEOI16_kangaroo)C++14
100 / 100
29 ms14108 KiB
#include<bits/stdc++.h> using namespace std; //#pragma GCC optimize("Ofast") //#pragma GCC target("avx,avx2,fma") //#pragma GCC optimization ("unroll-loops") #define rep(i, x, y) for(int i = x; i <= y; ++i) #define repi(i,x,y) for(int i = x; i >= y; --i) #define ci(x) int x; cin>> x #define TC(t) ci(t); while(t--) #define fi first #define se second #define pb push_back #define all(x) x.begin(), x.end() #define cii(x, y) ci(x); ci(y) #define ciii(x, y, z) ci(x); ci(y); ci(z) #define mp make_pair //#define int long long typedef long long ll; typedef vector<int> vi; const int N = 2e3 + 5; const int NN = 16 + 15; const int mod = 1e9+7; const int mod1 = 1e9 + 9; const int pi = 31; const int inf = 1e9 + 6; const int block = 500; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; void readfile(){ #ifdef ONLINE_JUDGE #else freopen("text.inp", "r", stdin); #endif // ONLINE_JUDGE // freopen("connect.in", "r", stdin); // freopen("connect.out", "w", stdout); } int n, s, t; void inp(){ cin >> n >> s >> t; } int dp[N][N]; int add(int x, int y){ x += y; while(x >= mod) x -= mod; while(x < 0) x += mod; return x; } int mul(int x, int y){ return (x * 1LL * y) % mod; } void process(){ dp[0][0] = 1; for(int i = 0; i < n; ++i){ for(int j = 0; j <= i; ++j){ if(i+1==s || i+1==t){ dp[i+1][j] = add(dp[i+1][j], dp[i][j]); // add vo component dau tien dp[i+1][j+1] = add(dp[i+1][j+1], dp[i][j]); // tao mot component moi ben trai cung } else{ if(i + 1 < s && i + 1 < t){ dp[i+1][j+1] = add(dp[i+1][j+1], mul(dp[i][j], j + 1)); // tao mot component moi, co j + 1 vi tri if(j) dp[i+1][j-1] = add(dp[i+1][j-1], mul(dp[i][j], j-1)); // co j - 1 vi tri de merge } else if((i + 1 >= t && i + 1 < s) || (i + 1 >= s && i + 1 < t)){ dp[i+1][j+1] = add(dp[i+1][j+1], mul(dp[i][j], j)); // tao mot component moi khong duoc o ben trai cung || phai cung, co j vi tri if(j) dp[i+1][j-1] = add(dp[i+1][j-1], mul(dp[i][j], j-1)); // co j - 1 vi tri de merge } else{ dp[i+1][j+1] = add(dp[i+1][j+1], mul(dp[i][j], j-1)); // tao mot component moi khong duoc o ben trai cung && phai cung, co j - 1 vi tri if(j) dp[i+1][j-1] = add(dp[i+1][j-1], mul(dp[i][j], j-1)); // co j - 1 vi tri de merge } } } } cout << dp[n][1]; } int main() { // readfile(); ios_base::sync_with_stdio(0); cin.tie(0); // TC(t){ inp(); process(); // reset(); // } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

kangaroo.cpp: In function 'void readfile()':
kangaroo.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         freopen("text.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...