QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#590986 | #9220. Bus Analysis | ttao | RE | 7ms | 7032kb | C++14 | 3.1kb | 2024-09-26 13:28:24 | 2024-09-26 13:28:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using i64=long long;
template<typename T>
T fpow(T x,ll n)
{T res=1,a=x;while(n){if(n&1)res*=a;a*=a;n>>=1;}return res;}
const int P=1e9+7;
int norm(int x){
if(x>=P){
x-=P;
}
if(x<0){
x+=P;
}
return x;
}
struct ModInt{
int x;
int val()const{return x;}
ModInt(int _x=0):x(norm(_x)){}
ModInt inv()const{return fpow(*this,P-2);}
ModInt&operator+=(const ModInt&rhs){
x=norm(x+rhs.x);
return *this;
}
ModInt&operator-=(const ModInt&rhs){
x=norm(x-rhs.x);
return *this;
}
ModInt&operator*=(const ModInt&rhs){
x=i64(x)*rhs.x%P;
return *this;
}
ModInt&operator/=(const ModInt&rhs){
return *this *=rhs.inv();
}
bool operator==(const ModInt&rhs)const{return x==rhs.x;}
bool operator!=(const ModInt&rhs)const{return !(x==rhs.x);}
bool operator==(const int rhs)const{return x==rhs;}
bool operator!=(const int rhs)const{return !(x==rhs);}
friend ModInt operator+(const ModInt&a,const ModInt&b){
ModInt res=a;res+=b;
return res;
}
friend ModInt operator-(const ModInt&a,const ModInt&b){
ModInt res=a;res-=b;
return res;
}
friend ModInt operator*(const ModInt&a,const ModInt&b){
ModInt res=a;res*=b;
return res;
}
friend ModInt operator/(const ModInt&a,const ModInt&b){
ModInt res=a;res/=b;
return res;
}
friend istream&operator>>(istream&is,ModInt&rhs){
i64 v;is>>v;
rhs=ModInt(v);
return is;
}
friend ostream&operator<<(ostream&os,const ModInt&rhs){
os<<rhs.val();
return os;
}
ModInt sqrt();
};
using Z=ModInt;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define drep(i,a,b) for(int i=a;i>=b;i--)
const int maxn=1010;
Z pw[maxn];
Z dp[2][76][76][76];
int t[maxn];
int n;
int cur;
Z ans;
int f[maxn][85];
int cover(int x,int y){
if(f[x][y]) return f[x][y];
int p=x-1;
while(p+1<=n&&t[p+1]-t[x]+1<=y) p++;
return f[x][y]=p-x+1;
}
int cover(int x,int y,int z){
int tmp=cover(x,y);
return tmp+cover(x+tmp,z);
}
int main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>t[i];
cur=1;
ans=0;
pw[0]=1;
for(int i=1;i<maxn;i++) pw[i]=pw[i-1]*2;
dp[0][0][cover(1,20)][cover(1,20,20)]=1;
for(int i=1;i<=n;i++){
// rep(a,0,75)rep(b,0,75)rep(c,0,75)
// int tpa=cover(i,20),tpb=cover(i,20,20),tpc=max(tpb+cover(i,i+tpb,20),cover(i,75));
// rep(a,0,tpc)rep(b,0,tpb)rep(c,0,tpc)
// dp[cur][a][b][c]=0;
memset(dp[cur],0,sizeof(dp[cur]));
rep(a,0,75)rep(b,0,75)rep(c,0,75)
{
dp[cur][max(0,a-1)][max(0,b-1)][max(0,c-1)]+=dp[cur^1][a][b][c];
if(a==0){
ans+=pw[n-i]*dp[cur^1][a][b][c];
int aa=max(cover(i,20)-1,b-1);
int bb=max({cover(i,20,20)-1,aa+cover(i+aa+1,20),c-1});
int cc=max({cover(i,75)-1,bb+cover(i+bb+1,20)});
dp[cur][aa][bb][cc]+=dp[cur^1][a][b][c];
}else{
dp[cur][max(0,a-1)][max(0,b-1)][max(0,c-1)]+=dp[cur^1][a][b][c];
}
}
cur^=1;
}
ans*=2;
cout<<ans<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 7032kb
input:
3 1 8 20
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: 0
Accepted
time: 7ms
memory: 7012kb
input:
5 25 45 65 85 1000000000
output:
156
result:
ok 1 number(s): "156"
Test #3:
score: -100
Runtime Error
input:
1000 2 7 9 12 14 17 18 21 22 28 29 33 34 35 37 38 44 45 46 50 58 59 63 66 71 72 75 76 77 78 80 81 83 84 87 92 100 101 107 108 109 112 114 116 118 123 124 131 142 143 144 145 148 150 151 152 153 155 157 158 165 167 168 169 171 176 182 185 190 192 198 202 204 205 212 213 223 224 225 226 229 231 240 24...