제출 #1002240

#제출 시각아이디문제언어결과실행 시간메모리
1002240Valters07Trains (BOI24_trains)C++17
100 / 100
159 ms127060 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt") #define fio ios_base::sync_with_stdio(0);cin.tie(0); #define en cin.close();return 0; #define ll long long #define fi first #define se second using namespace std; const int N = 1e5+5; const int SQ = sqrt(N)+2; const int mod = 1e9+7; int pf[N][SQ], dp[N]; int sum(int a, int b) { a+=b; if(a>=mod) a-=mod; if(a<0) a+=mod; return a; } int mul(int a, int b) { return 1ll*a*b%mod; } int main() { fio // ifstream cin("in.in"); int n; cin >> n; int sq = sqrt(n), res = 0; dp[1]=1; for(int i = 1;i<=n;i++) { for(int j = 1;j<=sq;j++) { if(i-j>=0) pf[i][j]=sum(pf[i][j],pf[i-j][j]); dp[i]=sum(dp[i],pf[i][j]); } res=sum(res,dp[i]); int d, x; cin >> d >> x; if(!d) continue; if(d>sq) { for(int j = 1;j<=x&&i+j*d<=n;j++) dp[i+j*d]=sum(dp[i+j*d],dp[i]); } else { if(i+d<=n) pf[i+d][d]=sum(pf[i+d][d],dp[i]); if(i+1ll*(x+1)*d<=n) pf[i+(x+1)*d][d]=sum(pf[i+(x+1)*d][d],-dp[i]); } } cout << res; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...