Submission #421349

# Submission time Handle Problem Language Result Execution time Memory
421349 2021-06-09T05:24:43 Z juggernaut Tents (JOI18_tents) C++17
0 / 100
16 ms 296 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 mod=1e9+7;
ll fact[3005];
ll n,m;
ll mult(ll a,ll b){
    return a*b%mod;
}
ll pw(ll a,ll b){
    if(!b)return 1ll;
    if(b&1)return mult(a,pw(a,b^1));
    ll x=pw(a,b>>1);
    return mult(x,x);
}
ll divv(ll a,ll b){
    return a*pw(b,mod-2)%mod;
}
ll add(ll a,ll b){
    return (a+b)%mod;
}
int main(){
    scanf("%lld%lld",&n,&m);
    if(n>m)swap(n,m);
    fact[0]=1;
    for(int i=1;i<=m;i++)fact[i]=mult(i,fact[i-1]);
    ll ans=-1;
    for(int x=0;x<=n;x++)
    for(int y=0;x+2*y<=n&&2*x+y<=m;y++)
    for(int z=0;x+2*y+z<=n&&2*x+y+z<=m;z++){
        ll pivot=1;
        ll divis=1;
        pivot=mult(pivot,fact[n]);
        pivot=mult(pivot,fact[m]);
        pivot=mult(pivot,pw(4,z));

        divis=mult(divis,fact[n-x-2*y-z]);
        divis=mult(divis,fact[m-2*x-y-z]);
        divis=mult(divis,fact[x]);
        divis=mult(divis,fact[z]);
        divis=mult(divis,pw(2,x+y));

        pivot=divv(pivot,divis);
        ans=add(ans,pivot);
        //cout<<x<<" "<<y<<" "<<z<<" "<<n-x-y-z<<" "<<pivot<<endl;
    }
    printf("%lld",ans);
}
/*
pivot=mult(pivot,divv(fact[n],mult(fact[x],fact[n-x])));
pivot=mult(pivot,divv(fact[m],mult(pw(2,x),fact[m-2*x])));
pivot=mult(pivot,divv(fact[n-x],mult(fact[n-x-2*y],pw(2,y))));
pivot=mult(pivot,divv(fact[m-2*x],fact[m-2*x-y]));
pivot=mult(pivot,pw(4,z));
pivot=mult(pivot,divv(fact[n-x-2*y],mult(fact[z],fact[n-x-2*y-z])));
pivot=mult(pivot,divv(fact[m-2*x-y],mult(fact[z],fact[m-2*x-y-z])));
pivot=mult(pivot,fact[z]);
*/

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:39:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     scanf("%lld%lld",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Incorrect 16 ms 296 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Incorrect 16 ms 296 KB Output isn't correct
6 Halted 0 ms 0 KB -