제출 #1051933

#제출 시각아이디문제언어결과실행 시간메모리
1051933deeraTrains (BOI24_trains)C++14
100 / 100
179 ms256084 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9+7; int main() { ll n; cin >> n; ll m = n + 100; const ll p = (ll)sqrt(n); vector<ll> dp(m); vector<ll> d(m), x(m); vector<vector<ll>> rest(m, vector<ll>(p, 0)); for (ll i = 1; i <= n; i++) cin >> d[i] >> x[i]; for (ll i = 0; i < dp.size(); i++) dp[i] = 1; for (ll i = n; i >= 1; i--) { ll step = d[i]; ll next = i + step; ll maxd = i + step * (x[i] + 1); if (d[i] != 0) { // it's not broken if (step >= p) { for (ll j = next; j <= n && j <= maxd - step; j+=step) { dp[i] = (dp[j] + dp[i]) % MOD; } } else { if (next <= n) dp[i] += rest[next][step]; if (maxd <= n) dp[i] -= rest[maxd][step]; dp[i] %= MOD; // modding here to avoid moddings negatives } } for (int step = 1; step < p; step++) { ll next = i + step; if (next <= n) rest[i][step] = (dp[i] + rest[next][step]) % MOD; else rest[i][step] = (dp[i]) % MOD; } } dp[1] += MOD; cout << dp[1] % MOD << endl; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:19:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (ll i = 0; i < dp.size(); i++) dp[i] = 1;
      |                    ~~^~~~~~~~~~~
#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...