Submission #1111602

#TimeUsernameProblemLanguageResultExecution timeMemory
1111602justin271828Trains (BOI24_trains)C++14
16 / 100
42 ms3524 KiB
#include <bits/stdc++.h> using namespace std; int main() { long long N; cin >> N; if (N == 1) { cout << 1; return 0; } long long d[N]; long long x[N]; for (long long i = 0; i < N; i++) { cin >> d[i] >> x[i]; } long long diff[N]; memset(diff, 0, sizeof(diff)); diff[0] = 1; diff[1] = -1; long long dsum = 0; for (int i = 0; i < N-1; i++) { dsum += diff[i]; if (dsum < 0) dsum += 1000000007; dsum %= 1000000007; diff[i+1] += dsum; if (diff[i+1] < 0) dsum += 1000000007; diff[i+1] %= 1000000007; if (i+1+x[i] < N) { diff[i+1+x[i]] -= dsum; if (diff[i+1+x[i]] < 0) dsum += 1000000007; diff[i+1+x[i]]%=1000000007; } } long long sum[N]; sum[0] = 1; for (int i = 1; i < N; i++) { sum[i] = sum[i-1]+diff[i]; if (sum[i] < 0) sum[i] += 1000000007; sum[i]%=1000000007; } long long ans = 0; for (long long i: sum) { ans += i; ans %= 1000000007; } cout << ans; 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...