QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#179188 | #7237. Sort it! | PhantomThreshold# | WA | 38ms | 29348kb | C++20 | 1.6kb | 2023-09-14 19:21:39 | 2023-09-14 19:21:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
ll ksm(ll a,ll x){
ll ret=1;
for (;x;x>>=1,a=a*a%mod) if (x&1) ret=ret*a%mod;
return ret;
}
ll inv(ll a){return ksm(a,mod-2);}
const int maxn=2000;
ll fac[maxn+50];
ll ifac[maxn+50];
void prepare(){
fac[0]=1;
for (int i=1;i<=maxn;i++) fac[i]=fac[i-1]*i%mod;
ifac[maxn]=inv(fac[maxn]);
for (int i=maxn-1;i>=0;i--) ifac[i]=ifac[i+1]*(i+1)%mod;
}
ll C(ll n,ll m){
if (m<0 || m>n) return 0;
return fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
struct BIT{
ll tr[maxn+50];
inline ll lowbit(ll x){return (x&(-x));}
void add(ll pos,ll val){
for (int i=pos;i<=maxn;i+=lowbit(i)) tr[i]+=val;
}
ll query(ll pos){
ll ans=0;
for (int i=pos;i>=1;i-=lowbit(i)) ans+=tr[i];
return ans;
}
};
BIT rec[maxn+50];
ll n;
ll perm[maxn+50];
ll dp[maxn+50][maxn+50];
ll coef[maxn+50];
int main(){
ios_base::sync_with_stdio(false);
prepare();
cin >> n;
for (int i=1;i<=n;i++) cin >> perm[i];
dp[0][0]=1;
rec[0].add(1,1);
for (int i=1;i<=n;i++){
for (int cnt=1;cnt<=n;cnt++){
dp[i][cnt]=rec[cnt-1].query(perm[i]);
}
for (int cnt=1;cnt<=n;cnt++){
rec[cnt].add(perm[i],dp[i][cnt]);
}
}
for (int i=1;i<=n;i++){
for (int j=0;j<=i;j++){
if (j%2==0) coef[i]=(coef[i]+C(i,j)*ksm(i-j,n))%mod;
else coef[i]=(coef[i]+mod-C(i,j)*ksm(i-j,n)%mod)%mod;
}
}
ll ans=0;
for (int sel=1;sel<=n;sel++){
ll sum=0;
for (int i=1;i<=n;i++) sum=(sum+dp[i][sel])%mod;
ans=(ans+sum*coef[sel])%mod;
}
cout << ans << "\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5752kb
input:
2 2 1
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5716kb
input:
3 2 1 3
output:
15
result:
ok 1 number(s): "15"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5744kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5768kb
input:
2 1 2
output:
4
result:
ok 1 number(s): "4"
Test #5:
score: 0
Accepted
time: 1ms
memory: 7756kb
input:
3 1 2 3
output:
27
result:
ok 1 number(s): "27"
Test #6:
score: 0
Accepted
time: 1ms
memory: 5824kb
input:
3 1 3 2
output:
15
result:
ok 1 number(s): "15"
Test #7:
score: 0
Accepted
time: 1ms
memory: 5784kb
input:
3 2 3 1
output:
9
result:
ok 1 number(s): "9"
Test #8:
score: 0
Accepted
time: 1ms
memory: 5768kb
input:
3 3 1 2
output:
9
result:
ok 1 number(s): "9"
Test #9:
score: 0
Accepted
time: 1ms
memory: 5704kb
input:
3 3 2 1
output:
3
result:
ok 1 number(s): "3"
Test #10:
score: 0
Accepted
time: 1ms
memory: 7896kb
input:
8 3 1 2 7 6 8 5 4
output:
149984
result:
ok 1 number(s): "149984"
Test #11:
score: 0
Accepted
time: 1ms
memory: 5796kb
input:
15 15 5 4 9 7 10 3 13 14 1 8 11 2 6 12
output:
600062423
result:
ok 1 number(s): "600062423"
Test #12:
score: -100
Wrong Answer
time: 38ms
memory: 29348kb
input:
894 670 618 579 212 780 557 380 412 672 8 777 117 684 768 99 404 140 122 139 329 623 17 645 18 880 790 625 505 307 747 801 754 783 146 757 263 285 228 719 640 199 193 105 234 847 842 348 159 823 577 466 133 850 851 643 802 819 317 826 55 617 690 604 229 570 254 759 575 498 240 397 736 864 415 751 49...
output:
911337915
result:
wrong answer 1st numbers differ - expected: '333399230', found: '911337915'