QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#140016 | #1241. Raid | XY_Eleven | WA | 14ms | 6100kb | C++23 | 4.8kb | 2023-08-14 23:09:44 | 2023-08-14 23:09:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize(3)
#define DB double
#define LL long long
#define ULL unsigned long long
#define pii pair<int,int>
#define pil pair<int,LL>
#define mii map<int,int>
#define miig map<int,int,greater<int> >
#define mil map<int,LL>
#define in128 __int128
#define cint const int
#define cLL const LL
#define cDB const DB
#define cchar const char
#define invoid inline void
#define inLL inline LL
#define inlint inline int
#define inbool inline bool
#define inl128 inline __int128
#define inDB inline double
#define For(z,e1,e2) for(int z=(e1);z<=(e2);z++)
#define Rof(z,e1,e2) for(int z=(e2);z>=(e1);z--)
#define For_(z,e1,e2) for(int z=(e1);z<(e2);z++)
#define Rof_(z,e1,e2) for(int z=(e2);z>(e1);z--)
#define inint(e) scanf("%d",&e)
#define inll(e) scanf("%lld",&e)
#define inpr(e1,e2) scanf("%d%d",&e1,&e2)
#define in3(e1,e2,e3) scanf("%d%d%d",&e1,&e2,&e3)
#define outint(e) printf("%d\n",e)
#define outint_(e) printf("%d%c",e," \n"[i==n])
#define outll(e) printf("%lld\n",e)
#define outll_(e) printf("%lld%c",e," \n"[i==n])
#define exc(e) if(e) continue
#define stop(e) if(e) break
#define ret(e) if(e) return
#define ll(e) ((LL)(e))
#define pb push_back
#define ft first
#define sc second
#define clean(e) while(!e.empty()) e.pop()
#define all(ev) ev.begin(),ev.end()
#define x0 x00
#define y1 y11
#define debug(x) cerr<<#x<<'='<<x<<'\n'
#define fout fflush(stdout)
invoid input(int &N_,int A_[],bool F_)
{
if(F_) inint(N_);
For(i,1,N_) inint(A_[i]);
}
template <typename Type>
inline Type md(Type w1,const Type w2)
{
w1%=w2; if(w1<0) w1+=w2;
return w1;
}
template <typename Type>
invoid add(Type &w1,const Type w2,const Type M_)
{ w1=md(w1+w2,M_); }
invoid mul(LL &w1,cLL w2,cLL M_)
{ w1=md(w1*w2,M_); }
inLL gcd(LL X_,LL Y_)
{
LL R_=X_%Y_;
while(R_)
{ X_=Y_; Y_=R_; R_=X_%Y_; }
return Y_;
}
invoid ex_gcd(LL &X_,LL &Y_,LL A_,LL B_)
{
if(!B_)
{
X_=1ll; Y_=0ll;
return ;
}
ex_gcd(Y_,X_,B_,A_%B_);
X_=md(X_,B_); Y_=(1ll-X_*A_)/B_;
}
inLL inv(LL A_,LL B_)
{
LL X_=0ll,Y_=0ll;
ex_gcd(X_,Y_,A_,B_);
return X_;
}
inLL pw(LL X_,LL Y_,LL M_)
{
LL S_=1ll;
while(Y_)
{
if(Y_&1) mul(S_,X_,M_);
Y_>>=1;
mul(X_,X_,M_);
}
return S_;
}
template <typename Type>
invoid get_min(Type &w1,const Type w2)
{ if(w2<w1) w1=w2; }
template <typename Type>
invoid get_max(Type &w1,const Type w2)
{ if(w2>w1) w1=w2; }
//inLL A(cint N_,cint M_)
//{ return (N_>=M_?md(d1[N_]*d2[N_-M_],mod):0ll); }
//inLL C(cint N_,cint M_)
//{ return (N_>=M_?md(d1[N_]*md(d2[M_]*d2[N_-M_],mod),mod):0ll); }
//mt19937 gen(time(NULL));
//mt19937_64 gen(time(NULL));
//cLL base[]={166686661,188868881},mod[]={1686688681,1666868881};
cLL base[]={166686661,188868881},mod[]={1686688681,1666868881},inter=1861;
//cLL mod[]={1e9+7,1e9+9,1e9+21,1e9+33};
//cLL mod=998244353;
cint N=50;
int n;
int a[N],rk[N][N];
unordered_map <LL,pair<int,LL> > dp[N];
unordered_map <LL,vector<int> > mp;
vector <int> c,t;
inLL f()
{
LL d[2]={0ll,0ll},z;
For(k,0,1)
for(auto i:t)
d[k]=(d[k]*base[k]+ll(i)^inter)%mod[k];
z=d[0]^(d[1]<<31);
mp[z]=t;
return z;
}
int main()
{
inint(n);
For(i,1,n) inint(a[i]),a[i]=n-a[i]+1;
// n=40;
// For(i,1,n) a[i]=i,swap(a[i],a[rand()%i+1]);
For(i,1,n) For(j,i,n) For(k,j+1,n)
rk[i][j]+=(a[k]<a[j]);
For(i,0,n) t.pb(0);
dp[0][f()]={0ll,1ll};
int ans=1e9;
LL sum=0ll;
For(v,1,n)
{
// debug(v);
for(auto [x,g]:dp[v-1])
{
exc(g.ft>ans+35);
// puts("start");
t=mp[x];
For(i,n+2-(int)t.size(),n)
{
// debug(i);
c=t; t.clear();
int s=g.ft+c[rk[i][i]];
For_(j,0,rk[i][i])
t.pb(c[j]),
s+=c[j];
// debug(s);
t.pb(c[rk[i][i]]+c[rk[i][i]+1]+1);
int siz=(int)c.size();
For_(j,rk[i][i]+2,siz)
t.pb(c[j]);
LL d=f();
// debug(d);
// debug(t.size());
if(dp[v].find(d)==dp[v].end()||
dp[v][d].ft>s)
dp[v][d]={s,g.sc};
else if(dp[v][d].ft==s)
dp[v][d].sc+=g.sc;
t[rk[i][i]]--;
}
}
ans=1e9;
sum=0ll;
// for(auto [x,g]:dp[v])
// printf("# %d %lld\n",g.ft,g.sc);
for(auto [x,g]:dp[v])
if(g.ft<ans) ans=g.ft,sum=g.sc;
else if(g.ft==ans) sum+=g.sc;
printf("%d %lld\n",ans,sum);
}
return 0;
}
/*
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3768kb
input:
5 5 3 1 4 2
output:
0 5 0 3 1 2 3 1 7 1
result:
ok 10 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
1 1
output:
0 1
result:
ok 2 number(s): "0 1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
2 1 2
output:
0 2 0 1
result:
ok 4 number(s): "0 2 0 1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
3 2 1 3
output:
0 3 0 2 1 1
result:
ok 6 numbers
Test #5:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
4 3 1 2 4
output:
0 4 0 4 0 1 2 1
result:
ok 8 numbers
Test #6:
score: 0
Accepted
time: 1ms
memory: 3764kb
input:
5 1 2 5 4 3
output:
0 5 0 7 0 3 1 3 3 1
result:
ok 10 numbers
Test #7:
score: 0
Accepted
time: 2ms
memory: 3936kb
input:
18 4 11 17 12 2 8 9 16 14 1 15 3 10 7 6 13 5 18
output:
0 18 0 78 0 132 0 104 0 38 0 5 1 2 3 6 5 1 9 8 12 1 17 1 25 4 33 5 41 2 50 1 61 1 75 1
result:
ok 36 numbers
Test #8:
score: 0
Accepted
time: 1ms
memory: 3960kb
input:
18 14 1 15 10 17 2 3 9 16 6 11 7 13 18 5 12 4 8
output:
0 18 0 76 0 141 0 139 0 78 0 24 0 3 1 2 3 3 5 1 10 3 15 1 22 1 30 1 40 1 52 3 64 2 77 1
result:
ok 36 numbers
Test #9:
score: 0
Accepted
time: 0ms
memory: 3932kb
input:
18 18 10 6 12 3 8 1 7 9 11 13 5 2 16 17 4 14 15
output:
0 18 0 86 0 190 0 223 0 154 0 60 0 10 1 12 2 2 4 4 6 1 9 1 15 3 21 1 29 1 39 1 50 1 67 1
result:
ok 36 numbers
Test #10:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
18 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
output:
0 18 0 153 0 816 0 3060 0 8568 0 18564 0 31824 0 43758 0 48620 0 43758 0 31824 0 18564 0 8568 0 3060 0 816 0 153 0 18 0 1
result:
ok 36 numbers
Test #11:
score: 0
Accepted
time: 1ms
memory: 3804kb
input:
18 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
output:
0 18 1 153 3 816 6 3060 10 8568 15 18564 21 31824 28 43758 36 48620 45 43758 55 31824 66 18564 78 8568 91 3060 105 816 120 153 136 18 153 1
result:
ok 36 numbers
Test #12:
score: 0
Accepted
time: 0ms
memory: 4380kb
input:
18 4 6 15 10 1 8 17 12 13 2 18 7 3 16 11 5 14 9
output:
0 18 0 85 0 150 0 115 0 42 0 6 1 9 2 3 4 1 7 1 11 2 16 2 22 2 29 2 37 2 46 2 56 1 68 1
result:
ok 36 numbers
Test #13:
score: 0
Accepted
time: 2ms
memory: 4020kb
input:
18 9 14 4 7 16 11 2 17 12 6 13 18 10 15 5 8 3 1
output:
0 18 0 64 0 89 0 55 0 16 0 2 1 1 3 1 6 1 10 2 15 5 20 1 27 1 35 1 45 1 57 1 72 1 89 1
result:
ok 36 numbers
Test #14:
score: 0
Accepted
time: 2ms
memory: 4020kb
input:
18 5 9 13 1 17 3 14 2 10 18 4 12 7 16 6 11 15 8
output:
0 18 0 88 0 163 0 127 0 43 0 4 1 4 2 1 4 1 7 1 11 2 15 1 20 1 27 1 35 3 43 1 53 1 65 1
result:
ok 36 numbers
Test #15:
score: 0
Accepted
time: 2ms
memory: 3992kb
input:
18 17 7 14 3 10 15 6 16 1 13 9 4 18 2 11 5 12 8
output:
0 18 0 67 0 83 0 36 0 4 1 2 3 2 6 5 9 2 13 3 18 3 24 3 31 3 39 3 48 2 58 1 70 1 86 1
result:
ok 36 numbers
Test #16:
score: 0
Accepted
time: 1ms
memory: 3684kb
input:
18 2 1 3 4 6 5 7 8 10 9 12 11 14 13 16 15 17 18
output:
0 18 0 147 0 720 0 2355 0 5418 0 8989 0 10836 0 9420 0 5760 0 2352 0 576 0 64 1 192 2 240 3 160 4 60 5 12 6 1
result:
ok 36 numbers
Test #17:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
18 1 10 2 11 3 12 4 13 5 14 6 15 7 16 8 17 9 18
output:
0 18 0 117 0 408 0 882 0 1260 0 1218 0 792 0 333 0 82 0 9 1 8 3 7 6 6 10 5 15 4 21 3 28 2 36 1
result:
ok 36 numbers
Test #18:
score: 0
Accepted
time: 0ms
memory: 4120kb
input:
18 17 15 13 11 9 7 5 3 1 18 16 14 12 10 8 6 4 2
output:
0 18 0 45 1 240 2 210 4 504 6 210 9 240 12 45 16 20 20 1 26 2 33 1 42 2 52 1 64 2 77 1 92 2 108 1
result:
ok 36 numbers
Test #19:
score: 0
Accepted
time: 1ms
memory: 3784kb
input:
18 9 14 10 15 11 16 12 17 13 18 2 1 4 3 6 5 8 7
output:
0 18 0 59 0 92 0 71 0 26 0 5 1 4 3 3 6 2 10 1 20 8 30 24 40 32 50 16 61 36 71 3 82 2 94 1
result:
ok 36 numbers
Test #20:
score: 0
Accepted
time: 1ms
memory: 3836kb
input:
18 11 15 12 16 13 17 14 18 2 1 4 3 6 5 8 7 10 9
output:
0 18 0 62 0 108 0 97 0 36 1 83 2 80 3 40 4 10 5 1 15 8 25 22 35 28 45 17 55 4 66 3 78 2 91 1
result:
ok 36 numbers
Test #21:
score: -100
Wrong Answer
time: 14ms
memory: 6100kb
input:
23 9 4 12 20 21 23 1 8 6 10 5 17 15 18 14 3 2 19 13 7 16 22 11
output:
0 23 0 135 0 324 0 384 0 235 0 70 0 8 1 12 2 6 3 1 6 4 9 4 12 1 17 4 22 4 27 1 36 1 46 1 57 2 69 1 85 2 103 2 1000000000 0
result:
wrong answer 43rd numbers differ - expected: '101', found: '103'