QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#85167 | #2020. 微信步数 | zombie462 | 100 ✓ | 323ms | 79844kb | C++23 | 2.6kb | 2023-03-07 02:12:53 | 2023-03-07 02:12:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 2000999
int n,k,w[SZ],c[SZ],d[SZ],mi[11],mx[11],wd[SZ][11],po[222];
ll rv[222];
const int MOD=1e9+7;
ll qp(ll a,ll b)
{
ll x=1;a%=MOD;
while(b)
{
if(b&1) x=x*a%MOD;
a=a*a%MOD; b>>=1;
}
return x;
}
ll ap[233][33],rt[233]; int an=0;
int main()
{
// FO(walk)
scanf("%d%d",&n,&k);
for(int i=1;i<=k;++i) scanf("%d",w+i);
for(int i=1;i<=n;++i) scanf("%d%d",c+i,d+i);
for(int i=1;i<=n*2;++i) c[i+n]=c[i],d[i+n]=d[i];
for(int i=1;i<=n*3;++i)
{
po[c[i]]+=d[i];
for(int j=1;j<=k;++j)
mi[j]=min(mi[j],po[j]),
mx[j]=max(mx[j],po[j]);
for(int j=1;j<=k;++j)
wd[i][j]=mx[j]-mi[j];
}
{
int w=k+2;
for(int j=0;j<w;++j)
{
ll p=1;
for(int k=0;k<w;++k)if(j!=k)p=p*(j-k)%MOD;
rv[j]=qp(p,MOD-2);
}
}
ll ans=1;
map<ll,int> id;
for(int i=1;i<=k;++i) ans=ans*w[i]%MOD;
for(int i=1;i<=n+n;++i)
{
int dx[14],dt[14];
ll f[14];
ll f1=1;
for(int j=1;j<=k;++j)
f1=f1*(dx[j]=max(w[j]-wd[i][j],0))%MOD;
if(!f1) continue;
if(i<=n)
{
ans+=f1;ans%=MOD;
continue;
}
bool eq=1;
for(int j=1;j<=k;++j)
{
eq&=wd[i][j]==wd[i+n][j],
dt[j]=wd[i+n][j]-wd[i][j];
}
if(eq&&f1)
{
puts("-1");
return 0;
}
//sum u prod (dx[j]-dt[j]*u)
//apparently it's a polynomial
int mx=2e9;
for(int j=1;j<=k;++j)
if(dt[j]) mx=min(mx,dx[j]/dt[j]);
int&ig=id[mx];
if(!ig) ig=++an,rt[an]=mx;
int w=k+2;
ll su=0;
for(int j=0;j<w;++j)
{
ll p=1;
for(int t=k;t;--t)
p=p*(dx[t]-dt[t]*j)%MOD;
// cout<<p<<",";
(su+=p)%=MOD; (ap[ig][j]+=su)%=MOD;
}
}
for(int i=1;i<=an;++i)
{
int mx=rt[i],w=k+2;
ll qz[15],hz[15];
qz[0]=1;
for(int p=0;p<w;++p)
qz[p+1]=qz[p]*(mx-p)%MOD;
hz[w]=1;
for(int p=w;p;--p)
hz[p-1]=hz[p]*(mx-p+1)%MOD;
for(int j=0;j<w;++j)
(ans+=ap[i][j]*rv[j]%MOD*qz[j]%MOD*hz[j+1])%=MOD;
}
ans=(ans%MOD+MOD)%MOD;
cout<<ans<<"\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 1ms
memory: 3520kb
input:
5 5 2 2 1 3 3 1 1 2 -1 1 1 5 -1 5 1
output:
63
result:
ok 1 number(s): "63"
Test #2:
score: 5
Accepted
time: 2ms
memory: 3516kb
input:
5 5 2 2 2 3 2 5 -1 5 1 2 1 2 1 5 1
output:
108
result:
ok 1 number(s): "108"
Test #3:
score: 5
Accepted
time: 2ms
memory: 3472kb
input:
5 5 3 3 1 3 2 4 1 4 -1 1 -1 3 -1 2 1
output:
150
result:
ok 1 number(s): "150"
Test #4:
score: 5
Accepted
time: 2ms
memory: 3584kb
input:
100 3 8 7 6 1 1 1 -1 3 1 3 -1 3 1 3 -1 3 1 3 -1 1 1 1 -1 1 1 1 -1 2 1 2 -1 1 1 1 -1 2 1 2 -1 3 1 3 -1 3 1 3 -1 3 1 3 -1 2 1 2 -1 3 1 3 -1 3 1 3 -1 1 1 1 -1 1 1 1 -1 3 1 3 -1 3 1 3 -1 1 1 1 -1 1 1 1 -1 2 1 2 -1 1 1 1 -1 2 1 2 -1 2 1 2 -1 2 1 2 -1 3 1 3 -1 1 1 1 -1 3 1 3 -1 3 1 3 -1 3 1 3 -1 3 1 3 -1 ...
output:
-1
result:
ok 1 number(s): "-1"
Test #5:
score: 5
Accepted
time: 2ms
memory: 3540kb
input:
100 3 6 7 5 1 1 2 1 3 1 2 -1 2 -1 3 -1 3 -1 2 -1 3 1 2 -1 2 -1 2 1 1 -1 1 1 2 -1 2 -1 2 1 3 -1 3 -1 1 -1 2 1 3 -1 3 -1 1 -1 3 1 3 1 1 1 3 -1 1 1 1 1 1 -1 1 1 3 1 2 -1 2 1 2 1 1 -1 2 1 1 -1 2 1 3 -1 2 -1 1 -1 3 1 1 -1 2 1 2 -1 1 -1 2 1 2 -1 3 -1 1 1 3 -1 1 1 1 -1 3 1 1 1 2 1 3 1 2 1 2 1 2 -1 2 1 3 1 ...
output:
1445
result:
ok 1 number(s): "1445"
Test #6:
score: 5
Accepted
time: 1ms
memory: 3536kb
input:
100 3 5 7 6 3 1 1 1 2 -1 2 -1 2 1 2 1 1 1 1 -1 2 1 2 -1 3 1 2 1 3 -1 2 -1 1 1 1 -1 1 -1 3 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 3 -1 3 1 3 1 3 1 2 1 3 1 3 -1 3 -1 3 1 2 1 1 -1 1 1 1 1 3 -1 1 -1 3 -1 3 -1 2 1 2 1 3 -1 2 -1 2 -1 3 -1 1 1 1 -1 1 -1 3 1 2 -1 2 1 3 -1 1 -1 2 1 2 -1 1 -1 1 -1 2 1 3 -1 1 1 3 1...
output:
1823
result:
ok 1 number(s): "1823"
Test #7:
score: 5
Accepted
time: 25ms
memory: 18800kb
input:
100000 1 84020 1 -1 1 -1 1 1 1 -1 1 1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 1 1 -1 1 1 1 -1 1 1 1 1 1 1 1 -1 1 -1 1 1 1 1 1 -1 1 1 1 -1 1 -1 1 1 1 1 1 -1 1 1 1 1 1 1 1 -1 1 1 1 1 1 -1 1 -1 1 1 1 -1 1 1 1 -1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 -1 1 -1 1 1 1 1 1 -1 1 1 1 1 1 -1 1 -1 1 1 1 -1 1 1 1 1 1...
output:
333173136
result:
ok 1 number(s): "333173136"
Test #8:
score: 5
Accepted
time: 15ms
memory: 18884kb
input:
100000 1 74078 1 -1 1 1 1 1 1 -1 1 -1 1 -1 1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 -1 1 -1 1 -1 1 -1 1 1 1 1 1 -1 1 -1 1 -1 1 1 1 1 1 -1 1 -1 1 1 1 -1 1 1 1 1 1 1 1 -1 1 -1 1 1 1 -1 1 1 1 1 1 -1 1 1 1 -1 1 -1 1 -1 1 -1 1 -1 1 1 1 1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 -1 1 -1 1 1 1 1 1 1 1 -1 1 1 1 -1 1 -1 1 1 ...
output:
453472675
result:
ok 1 number(s): "453472675"
Test #9:
score: 5
Accepted
time: 10ms
memory: 18752kb
input:
100000 2 788727 548098 1 -1 2 1 2 -1 2 1 1 -1 1 1 2 -1 2 -1 1 -1 2 1 2 -1 2 1 2 -1 1 -1 2 -1 2 1 1 -1 2 1 1 -1 1 -1 1 1 1 -1 1 -1 2 -1 1 1 1 -1 2 1 2 1 1 -1 1 1 1 -1 1 1 2 -1 2 -1 1 -1 2 -1 2 1 2 -1 2 -1 2 -1 1 -1 2 -1 2 1 2 1 1 1 1 1 2 1 1 -1 2 -1 2 1 1 -1 1 -1 1 -1 2 -1 1 1 1 -1 1 1 2 1 2 1 1 1 1 ...
output:
433871022
result:
ok 1 number(s): "433871022"
Test #10:
score: 5
Accepted
time: 18ms
memory: 18748kb
input:
100000 2 851838 526074 1 1 1 1 1 1 1 -1 2 -1 2 -1 1 1 2 1 2 1 2 1 2 1 1 1 1 -1 2 1 1 1 2 1 1 -1 2 -1 1 -1 2 1 2 1 2 -1 1 -1 2 -1 2 -1 2 -1 1 -1 2 -1 2 1 2 -1 2 1 2 -1 2 -1 2 1 2 1 2 -1 2 -1 1 -1 2 -1 1 -1 1 -1 1 -1 2 1 1 -1 1 1 2 -1 2 -1 1 1 2 1 2 -1 2 1 1 -1 2 -1 1 1 2 1 2 -1 1 -1 1 -1 1 1 2 -1 2 1...
output:
635878930
result:
ok 1 number(s): "635878930"
Test #11:
score: 5
Accepted
time: 20ms
memory: 18832kb
input:
100000 2 936902 869936 1 -1 1 -1 1 -1 2 -1 2 1 1 -1 2 1 2 1 2 -1 1 1 2 -1 2 -1 1 -1 2 -1 1 -1 1 -1 1 -1 2 -1 2 1 2 1 2 -1 2 -1 2 1 1 1 1 -1 1 -1 2 -1 1 -1 2 -1 1 -1 2 -1 1 -1 2 1 2 -1 1 -1 2 1 2 1 1 1 1 -1 1 1 2 -1 2 1 2 -1 2 -1 1 -1 2 1 1 1 1 1 1 1 1 -1 2 1 2 1 1 -1 1 -1 2 -1 2 -1 2 1 1 1 2 -1 1 -1...
output:
442317474
result:
ok 1 number(s): "442317474"
Test #12:
score: 5
Accepted
time: 22ms
memory: 18804kb
input:
100000 2 696105 696736 2 1 1 -1 1 -1 1 1 1 1 1 -1 1 -1 2 1 2 -1 2 -1 1 -1 1 1 1 -1 2 1 2 -1 1 1 2 -1 1 -1 1 -1 1 1 1 -1 2 -1 1 1 2 1 1 1 1 -1 1 1 1 -1 2 1 1 -1 2 1 1 1 1 1 2 -1 1 -1 2 1 1 1 1 -1 2 1 1 -1 2 1 2 1 1 -1 1 -1 1 -1 2 1 2 1 2 1 1 -1 1 1 2 1 2 -1 2 -1 2 -1 2 -1 2 -1 2 1 1 1 2 1 2 -1 1 -1 1...
output:
564885404
result:
ok 1 number(s): "564885404"
Test #13:
score: 5
Accepted
time: 74ms
memory: 79648kb
input:
500000 10 755576 503368 607237 931815 889701 742191 594456 676526 704905 569952 9 1 9 -1 8 1 8 -1 4 1 4 -1 7 1 7 -1 3 1 3 -1 1 1 1 -1 6 1 6 -1 1 1 1 -1 10 1 10 -1 2 1 2 -1 1 1 1 -1 2 1 2 -1 5 1 5 -1 4 1 4 -1 3 1 3 -1 7 1 7 -1 3 1 3 -1 4 1 4 -1 6 1 6 -1 7 1 7 -1 4 1 4 -1 1 1 1 -1 2 1 2 -1 5 1 5 -1 6 ...
output:
-1
result:
ok 1 number(s): "-1"
Test #14:
score: 5
Accepted
time: 314ms
memory: 79740kb
input:
500000 10 843479 559917 806296 766435 965493 781368 889933 632099 689781 934269 3 1 10 1 3 1 3 -1 6 1 7 -1 8 1 9 1 4 1 2 -1 5 1 2 -1 5 1 8 -1 4 -1 10 -1 8 -1 7 -1 1 -1 3 -1 5 1 6 1 3 -1 6 -1 3 1 10 -1 5 1 4 1 2 1 10 -1 5 -1 4 1 5 -1 4 -1 5 -1 4 1 3 -1 8 1 5 1 3 -1 1 -1 5 1 2 -1 8 1 5 1 9 -1 4 -1 10 ...
output:
212475448
result:
ok 1 number(s): "212475448"
Test #15:
score: 5
Accepted
time: 323ms
memory: 79696kb
input:
500000 10 564550 662731 907937 653446 887637 552698 501487 502890 574491 689451 8 -1 2 1 2 -1 10 -1 5 -1 10 1 9 1 8 1 6 1 6 1 2 -1 2 -1 9 -1 1 -1 9 -1 7 -1 8 1 9 -1 9 1 9 -1 6 1 10 1 1 -1 8 -1 10 -1 10 1 7 1 4 1 6 1 1 -1 2 -1 2 1 5 -1 2 -1 7 1 5 -1 8 -1 5 1 7 -1 2 -1 3 1 9 1 3 -1 7 1 8 1 5 -1 1 1 6 ...
output:
27023740
result:
ok 1 number(s): "27023740"
Test #16:
score: 5
Accepted
time: 300ms
memory: 79636kb
input:
500000 10 918488 957499 964399 900665 976079 674192 501308 980114 958902 545155 6 1 1 -1 1 1 9 1 1 1 5 -1 4 1 1 -1 9 -1 6 1 1 -1 6 1 10 1 5 -1 8 1 10 1 2 1 7 1 5 -1 6 -1 10 -1 1 -1 4 -1 6 -1 4 1 10 -1 10 -1 6 -1 4 -1 7 -1 4 1 6 1 6 -1 10 1 9 1 4 -1 4 1 3 -1 7 -1 1 -1 5 1 8 1 10 1 2 1 2 -1 2 1 3 1 6 ...
output:
128050940
result:
ok 1 number(s): "128050940"
Test #17:
score: 5
Accepted
time: 109ms
memory: 79660kb
input:
500000 3 826619243 796070724 841056572 3 1 2 1 3 -1 1 -1 2 1 2 -1 1 -1 1 1 1 -1 3 1 1 -1 2 -1 3 -1 3 1 1 -1 1 1 3 -1 2 1 2 1 3 -1 2 1 2 1 1 -1 1 1 1 1 1 -1 2 1 3 -1 2 -1 2 1 3 1 1 1 1 -1 3 1 2 -1 1 -1 2 1 2 1 2 -1 3 -1 1 -1 1 -1 2 -1 3 -1 1 -1 3 -1 2 1 2 -1 3 1 1 -1 1 1 1 1 1 1 1 1 3 -1 1 1 3 1 2 1 ...
output:
953829771
result:
ok 1 number(s): "953829771"
Test #18:
score: 5
Accepted
time: 122ms
memory: 79648kb
input:
500000 3 956491428 866109891 631435277 2 1 1 -1 1 -1 3 -1 3 1 2 -1 2 1 1 -1 2 1 2 -1 1 -1 2 1 2 1 2 -1 1 1 3 1 3 -1 1 -1 1 1 1 1 3 -1 2 -1 1 1 1 1 2 -1 2 1 2 -1 2 -1 2 1 3 1 1 -1 2 -1 1 -1 2 1 3 1 1 1 3 -1 1 -1 2 -1 3 1 2 1 3 1 3 1 2 1 3 -1 1 -1 3 -1 2 1 1 1 2 1 3 -1 3 1 1 -1 3 -1 1 1 2 -1 2 -1 2 1 ...
output:
286394049
result:
ok 1 number(s): "286394049"
Test #19:
score: 5
Accepted
time: 115ms
memory: 79844kb
input:
500000 3 816766322 779617142 794227651 3 1 2 1 1 1 3 -1 2 1 2 -1 1 1 1 1 1 1 3 -1 1 -1 2 1 3 1 1 -1 1 -1 1 1 3 1 3 1 1 -1 3 -1 2 1 1 -1 2 1 3 1 1 1 2 -1 3 -1 2 -1 1 -1 3 -1 1 1 3 -1 3 1 1 -1 3 1 2 -1 2 -1 1 -1 3 1 3 1 2 -1 3 1 3 -1 1 1 1 -1 3 1 1 1 2 1 2 1 1 1 2 1 1 -1 2 1 2 -1 2 1 3 -1 3 1 1 1 3 -1...
output:
950925221
result:
ok 1 number(s): "950925221"
Test #20:
score: 5
Accepted
time: 126ms
memory: 79688kb
input:
500000 3 600925621 781710332 540983402 1 -1 1 1 2 1 3 1 1 1 1 1 3 1 3 1 2 -1 3 -1 3 1 1 -1 1 1 2 -1 1 -1 1 -1 3 -1 2 1 1 1 1 -1 1 -1 1 1 3 -1 2 -1 2 -1 3 1 1 1 1 -1 3 1 2 1 1 -1 2 1 1 -1 3 -1 3 -1 2 -1 3 -1 2 1 3 -1 1 1 2 1 2 1 3 -1 2 1 1 1 1 1 3 1 2 -1 1 1 3 1 2 -1 3 -1 3 1 2 -1 3 -1 1 1 1 1 1 -1 3...
output:
370329204
result:
ok 1 number(s): "370329204"
Extra Test:
score: 0
Extra Test Passed