# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1043251 | guagua0407 | Trains (BOI24_trains) | C++17 | 144 ms | 8424 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
const int mod=1e9+7;
const int B=350;
int main() {_
int n;
cin>>n;
vector<ll> d(n),x(n);
for(int i=0;i<n;i++){
cin>>d[i]>>x[i];
}
vector<ll> dp(n);
vector<vector<ll>> sum(B,vector<ll>(B));
vector<vector<int>> en(n);
dp[0]=1;
for(int i=0;i<n;i++){
for(int j=1;j<B;j++){
dp[i]=(dp[i]+sum[j][i%j])%mod;
}
if(d[i]>=B){
for(int j=1;j<=x[i] and i+j*d[i]<n;j++){
dp[i+j*d[i]]=(dp[i+j*d[i]]+dp[i])%mod;
}
}
else if(d[i]>0){
sum[d[i]][i%d[i]]=(sum[d[i]][i%d[i]]+dp[i])%mod;
if(i+x[i]*d[i]<n) en[i+x[i]*d[i]].push_back(i);
}
for(auto j:en[i]){
sum[d[j]][j%d[j]]=(sum[d[j]][j%d[j]]-dp[j])%mod;
if(sum[d[j]][j%d[j]]<0) sum[d[j]][j%d[j]]+=mod;
}
}
ll ans=0;
for(int i=0;i<n;i++){
ans=(ans+dp[i])%mod;
}
cout<<ans<<'\n';
return 0;
}
//maybe its multiset not set
//yeeorz
//laborz
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |