답안 #421369

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
421369 2021-06-09T05:50:10 Z juggernaut Tents (JOI18_tents) C++17
100 / 100
463 ms 70760 KB
#include<bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
typedef long long ll;
#define USING_ORDERED_SET 0
#if USING_ORDERED_SET
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#endif
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef IOI2021SG
    #define printl(args...)printf(args)
#else
    #define printl(args...)((void)0)
#endif
ll dp[3005][3005];
ll mod=1e9+7;
inline ll add(ll a,ll b){
    return (a+b)%mod;
}
inline ll mult(ll a,ll b){
    return (a*b)%mod;
}
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    if(n>m)swap(n,m);
    for(int i=0;i<=n;i++)dp[i][0]=1;
    for(int i=0;i<=m;i++)dp[0][i]=1;
    for(int i=1;i<=n;i++)dp[i][1]=4*i+i*(i-1)/2+1;
    for(int i=1;i<=m;i++)dp[1][i]=4*i+i*(i-1)/2+1;
    for(int i=2;i<=n;i++)
    for(int j=2;j<=m;j++){
        dp[i][j]=add(dp[i][j],dp[i-1][j]);
        dp[i][j]=add(dp[i][j],mult(4*j,dp[i-1][j-1]));
        dp[i][j]=add(dp[i][j],mult(dp[i-1][j-2],j*(j-1)/2));
        dp[i][j]=add(dp[i][j],mult(dp[i-2][j-1],j*(i-1)));
    }
    ll ans=dp[n][m];
    if(ans==0)ans=mod-1;
    else ans--;
    printf("%lld",ans);
}

Compilation message

tents.cpp: In function 'void usaco(std::string)':
tents.cpp:5:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tents.cpp:5:66: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tents.cpp: In function 'int main()':
tents.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 2 ms 716 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 3 ms 1100 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 5 ms 2124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 2 ms 716 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 3 ms 1100 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 5 ms 2124 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 290 ms 47816 KB Output is correct
16 Correct 19 ms 3924 KB Output is correct
17 Correct 65 ms 12768 KB Output is correct
18 Correct 79 ms 16960 KB Output is correct
19 Correct 343 ms 52896 KB Output is correct
20 Correct 266 ms 49472 KB Output is correct
21 Correct 179 ms 33732 KB Output is correct
22 Correct 178 ms 32908 KB Output is correct
23 Correct 94 ms 14936 KB Output is correct
24 Correct 463 ms 70760 KB Output is correct
25 Correct 342 ms 60816 KB Output is correct
26 Correct 397 ms 64056 KB Output is correct
27 Correct 438 ms 68948 KB Output is correct