QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#591040 | #7301. Even Three is Odd | hyfans | WA | 1ms | 5832kb | C++20 | 3.3kb | 2024-09-26 13:46:23 | 2024-09-26 13:46:25 |
Judging History
answer
// @Nullptr_qwq @Nullptr_qwQ @Nullptr_qWq @Nullptr_qWQ @Nullptr_Qwq @Nullptr_QwQ @Nullptr_QWq @Nullptr_QWQ
//File uses UTF-8 encoding.
//By: Luogu@tzl_Dedicatus545(UID:308854) Yuanshen@tzl_Dedicatus(UID:273152640)
//Ayaka bless me!
// #define _TZL_DEBUG_
#if defined(_TZL_DEBUG_) && defined(TZL_MEOW)
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define ull unsigned long long
#define rep(i,x,y,z) for(int i=(x),i##misaka=(y);i<=i##misaka;i+=(z))
#define per(i,x,y,z) for(int i=(x),i##mik0t0=(y);i>=i##mik0t0;i-=(z))
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define i128 __int128
#define _1 first
#define _2 second
#define ld long double
#define cint const int
#define pcnt __builtin_popcountll
#define vint vector<int>
#define vpii vector<pair<int,int> >
using namespace std;
const int inf=(sizeof(int)==4?0x3f3f3f3f:0x3f3f3f3f3f3f3f3f);
const int mod=1e9+7;
const long double EPS=1e-7;
const int maxn=2200;
int gcd(int a,int b){
if(!a || !b) return a+b;
unsigned az=__builtin_ctzll(a),bz=__builtin_ctzll(b);unsigned z=min(az,bz);b>>=bz;
while(a){ a>>=az;int d=a-b;az=__builtin_ctzll(d),b=min(a,b),a=(d<0?-d:d);}
return b<<z;
}
template<typename T>void chkmin(T& x,const T& y){return y<x?(x=y,void()):void();}
template<typename T>void chkmax(T& x,const T& y){return x<y?(x=y,void()):void();}
bool Mbe;
void inc(int &x,int y){ x=(x+y>=mod?x+y-mod:x+y);}
void dec(int &x,int y){ x=(x-y<0?x-y+mod:x-y);}
int mul(vint vec){int ans=1;for(auto x:vec) ans*=x,ans%=mod;return ans;}
int fac[maxn],finv[maxn];
ll fpow(ll x,int y){
ll rt=1;
for(;y;y>>=1,x=1ll*x*x%mod) if(y&1) rt=1ll*rt*x%mod;
return rt;
}int inv(int x){ return fpow(x,mod-2);}
void init(int n){
#if 1
fac[0]=fac[1]=1;finv[0]=finv[1]=1;
rep(i,2,n,1){ fac[i]=1ll*fac[i-1]*i%mod;}finv[n]=inv(fac[n]);
per(i,n-1,1,1){ finv[i]=1ll*finv[i+1]*(i+1)%mod;}
#endif
}int C(int n,int m){
if(n<m || n<0 || m<0) return 0;
return 1ll*fac[n]*finv[m]%mod*finv[n-m]%mod;
}
int w[maxn];
int f[maxn][maxn][3];
int sa[maxn];
bool Med;
signed main()
{ios::sync_with_stdio(0);cin.tie(0);init(maxn-1);cerr<<fixed<<setprecision(3)<<(&Mbe-&Med)/1048576.0<<"MiB"<<endl;
int n;
while(cin>>n){
rep(i,1,n,1) cin>>w[i];
rep(i,0,n,1) rep(j,0,n,1) rep(k,0,2,1) f[i][j][k]=0;
rep(v,1,n,1) f[1][v][0]=w[v],f[1][v][1]=w[v]*(v-1)%mod,f[1][v][2]=w[v]*(v-1)*(v-1)%mod;
rep(i,1,n-2,1){
int pr=0;
rep(v,0,n+1,1) sa[v]=0;
per(v,n,1,1) sa[v]=sa[v+1]+f[i-1][v][0];
rep(v,1,n,1){
if(i!=1){
inc(f[i][v][2],pr);
inc(f[i][v][0],sa[v]);
inc(f[i][v][1],sa[v]*(v-1)%mod);
inc(f[i][v][2],sa[v]*(v-1)*(v-1)%mod);
rep(j,0,2,1) f[i][v][j]*=w[v],f[i][v][j]%=mod;
}
inc(f[i+1][v][0],f[i][v][1]);inc(f[i+1][v][1],f[i][v][2]);
/*
rep(vt,1,n,1){
if(vt<=v){
inc(f[i+1][vt][0],f[i][v][0]%mod);
inc(f[i+1][vt][1],f[i][v][0]*(vt-1)%mod);
}
if(vt<=v) inc(f[i+1][vt][2],f[i][v][0]*(vt-1)*(vt-1));
}
*/
pr+=(f[i-1][v][1]*v+f[i-1][v][2])%mod+f[i-1][v][0]*v*v%mod;pr%=mod;
}
}
int ans=0;
rep(v,1,n,1) inc(ans,f[n-2][v][0]*(v)%mod*(v)%mod),inc(ans,f[n-2][v][1]*(v)%mod),inc(ans,f[n-2][v][2]);
cout<<ans<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3824kb
input:
3 1 2 3 4 1 1 1 1
output:
72 256
result:
ok 2 number(s): "72 256"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3864kb
input:
20 2 1 1 2 1 1 2 2 1 1 1 2 1 2 2 2 2 2 1 1 20 1 1 1 1 1 1 1 2 2 2 2 1 2 1 2 1 1 1 2 2 20 2 1 2 2 1 2 2 1 1 1 2 1 2 1 2 2 1 1 2 1 20 1 1 1 1 1 2 1 1 1 2 1 2 2 1 1 2 2 2 1 2 20 2 2 1 1 2 2 2 1 2 2 1 2 2 2 2 1 2 2 2 2 20 1 1 2 1 2 1 2 2 1 2 2 2 1 2 1 2 2 2 1 1 20 1 2 1 1 1 2 1 1 1 1 1 2 1 2 1 1 2 2 2 1...
output:
319733964 40518147 400924261 38787721 897349820 493064982 759767625 401417778 567673098 202982388 409477312 214563090 608955253 887076718 443657041 235173408 471938201 768115792 934580672 588618862 808662651 462080423 871122184 321300347 413884324 720362807 549790197 780388163 250729956 49025886 263...
result:
ok 100 numbers
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 5832kb
input:
20 983380751 708372152 534389660 854380310 406905313 606185721 941692711 734994736 910390968 900300887 183918461 371552529 798892008 68293780 650769940 547768169 502245417 567965812 623465221 632455730 20 969814296 632645698 353407887 775111974 19835316 622749258 218528404 235697220 677299937 151257...
output:
648349495 309786984 729941155 477210532 906909191 338763940 229310450 295297316 495019857 123498731 999628021 897057082 213644035 845439384 489145021 750276499 460768856 443673849 909615746 996576192 181226793 719987628 806760075 348179257 961660067 787414029 934181454 479955568 509773642 528217296 ...
result:
wrong answer 1st numbers differ - expected: '901128997', found: '648349495'