Submission #1349856

#TimeUsernameProblemLanguageResultExecution timeMemory
1349856pandaa73Trains (BOI24_trains)C++20
Compilation error
0 ms0 KiB
>
using namespace std;

#define ff endl
#define lf "\n"
#define fi first
#define se second
#define _ << ' ' <<
#define all(x) begin(x),end(x)
#define rall(x) rbegin(x),rend(x)

#ifdef DEBUG

constexpr bool IS_DEBUG = 1;

#define infor(fmt, ...) do { print(stderr, fmt, ##__VA_ARGS__); } while(0)
#define infof(fmt, ...) do { println(stderr, fmt, ##__VA_ARGS__); } while(0)

#else

constexpr bool IS_DEBUG = 0;

#define infor(fmt, ...)
#define infof(fmt, ...)

#endif

using ll = long long;

using pll = pair<ll, ll>;
using pii = pair<int, int>;

template<typename... Args>
using vec = vector<Args...>;

constexpr int LOG = 20;
constexpr int MOD = 1e9+7;
constexpr int MAXN = 1e5+7;

mt19937 timmy_loves_gambling(73);

int add(int a, int b) {
    int x = a + b;
    return x < MOD ? x : x - MOD;
}

void chadd(int &a, int b) {
    a = add(a, b);
}

int mul(int a, int b) {
    return (ll)a * b % MOD;
}

void chmul(int &a, int b) {
    a = mul(a, b);
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int N; cin >> N;

    vec<int> K(N), R(N);
    for(int i = 0; i < N; ++i) {
        cin >> K[i] >> R[i];

        if(K[i] >= N - i) K[i] = 0;
        if(K[i] == 0) continue;

        R[i] = min(R[i], (N - i - 1) / K[i]);
    }

    vec<int> dp(N, 1);
    vec<map<int, int>> sfx(2 * N);

    auto calc = [&](int i, int k, int r, auto &&calc) -> int {
        if(i >= r) return 0;

        auto it = sfx[i].find(k);
        if(it != sfx[i].end()) return it->se;

        return sfx[i][k] = add(dp[i], calc(i + k, k, r, calc));
    };

    for(int i = N - 1; i >= 0; i--) {
        if(K[i] == 0) continue;

        int l = i + K[i];
        int r = i + K[i] * (R[i] + 1);

        calc(i + K[i], K[i], r, calc);

        chadd(dp[i], add(sfx[l][K[i]], MOD - sfx[r][K[i]]));
    }

    cout << dp[0] << lf;
}

Compilation message (stderr)

Main.cpp:1:1: error: expected unqualified-id before '>' token
    1 | >
      | ^
Main.cpp:30:13: error: 'pair' does not name a type
   30 | using pll = pair<ll, ll>;
      |             ^~~~
Main.cpp:31:13: error: 'pair' does not name a type
   31 | using pii = pair<int, int>;
      |             ^~~~
Main.cpp:34:13: error: 'vector' does not name a type
   34 | using vec = vector<Args...>;
      |             ^~~~~~
Main.cpp:40:1: error: 'mt19937' does not name a type
   40 | mt19937 timmy_loves_gambling(73);
      | ^~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:60:5: error: 'ios' has not been declared
   60 |     ios::sync_with_stdio(0);
      |     ^~~
Main.cpp:61:5: error: 'cin' was not declared in this scope
   61 |     cin.tie(0); cout.tie(0);
      |     ^~~
Main.cpp:61:17: error: 'cout' was not declared in this scope
   61 |     cin.tie(0); cout.tie(0);
      |                 ^~~~
Main.cpp:65:5: error: 'vec' was not declared in this scope
   65 |     vec<int> K(N), R(N);
      |     ^~~
Main.cpp:65:9: error: expected primary-expression before 'int'
   65 |     vec<int> K(N), R(N);
      |         ^~~
Main.cpp:67:16: error: 'K' was not declared in this scope
   67 |         cin >> K[i] >> R[i];
      |                ^
Main.cpp:67:24: error: 'R' was not declared in this scope
   67 |         cin >> K[i] >> R[i];
      |                        ^
Main.cpp:72:16: error: 'min' was not declared in this scope; did you mean 'main'?
   72 |         R[i] = min(R[i], (N - i - 1) / K[i]);
      |                ^~~
      |                main
Main.cpp:75:9: error: expected primary-expression before 'int'
   75 |     vec<int> dp(N, 1);
      |         ^~~
Main.cpp:76:9: error: 'map' was not declared in this scope
   76 |     vec<map<int, int>> sfx(2 * N);
      |         ^~~
Main.cpp:76:13: error: expected primary-expression before 'int'
   76 |     vec<map<int, int>> sfx(2 * N);
      |             ^~~
Main.cpp: In lambda function:
Main.cpp:81:19: error: 'sfx' was not declared in this scope
   81 |         auto it = sfx[i].find(k);
      |                   ^~~
Main.cpp:84:32: error: 'dp' was not declared in this scope
   84 |         return sfx[i][k] = add(dp[i], calc(i + k, k, r, calc));
      |                                ^~
Main.cpp: In function 'int main()':
Main.cpp:88:12: error: 'K' was not declared in this scope
   88 |         if(K[i] == 0) continue;
      |            ^
Main.cpp:90:21: error: 'K' was not declared in this scope
   90 |         int l = i + K[i];
      |                     ^
Main.cpp:91:29: error: 'R' was not declared in this scope
   91 |         int r = i + K[i] * (R[i] + 1);
      |                             ^
Main.cpp:95:15: error: 'dp' was not declared in this scope
   95 |         chadd(dp[i], add(sfx[l][K[i]], MOD - sfx[r][K[i]]));
      |               ^~
Main.cpp:95:26: error: 'sfx' was not declared in this scope
   95 |         chadd(dp[i], add(sfx[l][K[i]], MOD - sfx[r][K[i]]));
      |                          ^~~
Main.cpp:98:13: error: 'dp' was not declared in this scope
   98 |     cout << dp[0] << lf;
      |             ^~