Submission #3244630


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

const int MAX = 100010;
const long long MOD = 1e9+7;
long long dp[MAX], dpsum[MAX];

void add(long long& a, long long b){
    a = (a+b+MOD) % MOD;
}
void mul(long long& a, long long b){
    a = (a*b) % MOD;
}

int main(){
    long long i, j, k;
    long long D, F, T, N;
    long long X[MAX];
    cin >> D >> F >> T >> N;
    X[0] = 0;
    for(i=1; i<=N; i++) scanf("%lld", &X[i]);
    X[N+1] = D;

    long long pow2[MAX];
    pow2[0] = 1;
    for(i=1; i<=N; i++) pow2[i] = pow2[i-1] * 2 % MOD;

    int live = 0, nocharge = 0, nocr = 1;
    while(nocr <= N && X[nocr] <= F-T) nocr++;
    dp[0] = pow2[nocr-1];
    dpsum[0] = dp[0];
    for(i=1; i<=N; i++){
        while(X[i] - X[live] > F) live++;
        while(X[i] - X[nocharge] > F-T) nocharge++;
        while(nocr <= N && X[nocr] - X[i] <= F-T) nocr++;
        dp[i] = dpsum[nocharge-1];
        if(live>0) add(dp[i], -dpsum[live-1]);
        mul(dp[i], pow2[nocr-i-1]);
        dpsum[i] = (dp[i] + dpsum[i-1]) % MOD;
    }
    //for(i=0; i<=N; i++) cout << dp[i] << endl;

    while(D - X[live] > F) live++;
    long long ans = (dpsum[N] - dpsum[live-1] + MOD) % MOD;
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task D - 通勤
User betrue12
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1260 Byte
Status
Exec Time 17 ms
Memory 3328 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:21:45: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     for(i=1; i<=N; i++) scanf("%lld", &X[i]);
                                             ^

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt
All 700 / 700 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt
Case Name Status Exec Time Memory
01.txt 17 ms 3328 KB
02.txt 17 ms 3328 KB
03.txt 16 ms 3328 KB
04.txt 17 ms 3328 KB
05.txt 16 ms 3328 KB
06.txt 17 ms 3328 KB
07.txt 17 ms 3328 KB
08.txt 17 ms 3328 KB
09.txt 17 ms 3328 KB
10.txt 17 ms 3328 KB
11.txt 17 ms 3328 KB
12.txt 1 ms 256 KB
13.txt 1 ms 256 KB
14.txt 1 ms 256 KB
15.txt 1 ms 256 KB
16.txt 17 ms 3328 KB
17.txt 16 ms 3328 KB
18.txt 17 ms 3328 KB
19.txt 16 ms 3328 KB
20.txt 16 ms 3328 KB
21.txt 15 ms 3328 KB
22.txt 10 ms 2176 KB
23.txt 14 ms 3328 KB
24.txt 6 ms 1408 KB
25.txt 6 ms 1408 KB
26.txt 4 ms 896 KB
27.txt 13 ms 2944 KB
28.txt 14 ms 2944 KB
29.txt 13 ms 2944 KB
30.txt 15 ms 2944 KB
sample-01.txt 1 ms 256 KB
sample-02.txt 1 ms 256 KB
sample-03.txt 1 ms 256 KB
sample-04.txt 1 ms 256 KB