이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
#define sz(v) ((int) (v).size())
#define all(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define BIT(x, y) (((x) >> (y)) & 1)
#define clz __builtin_clzll
#define ctz __builtin_ctzll
#define popcount __builtin_popcount
#define lg(x) (63 - clz(x))
template <class X, class Y>
inline bool maximize(X &x, Y y) {
return (x < y ? x = y, true : false);
}
template <class X, class Y>
inline bool minimize(X &x, Y y) {
return (x > y ? x = y, true : false);
}
template <class X>
inline void compress(vector<X> &a) {
sort(all(a)); a.resize(unique(all(a)) - a.begin());
}
const ll oo = (ll) 1e18, inf = (ll) 1e9, mod = (ll) 1e9 + 7;
const int mxn = (int) 2e5 + 5, S = (int) 450, S2 = (int) 450, lg = (int) 17;
void add(ll &x, ll y) {
x += y;
if (x >= mod) x -= mod;
}
void sub(ll &x, ll y) {
x -= y;
if (x < 0) x += mod;
}
ll n;
pair<ll, ll> a[mxn];
ll f[mxn + S];
ll calc[mxn + S][S+1];
void solve() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i].se >> a[i].fi;
}
for (int i = n; i >= 1; --i) {
f[i] = 1;
if (a[i].fi <= S) {
if (a[i].se) {
for (int j = 1; j <= a[i].fi; ++j) {
if (i + j * a[i].se > n) break;
add(f[i], f[i + j * a[i].se]);
}
}
}
else {
if (a[i].se > S) {
for (int j = 1; j <= a[i].fi; ++j) {
if (i + j * a[i].se > n) break;
add(f[i], f[i + j * a[i].se]);
}
}
else {
if (a[i].se) {
add(f[i], calc[i + a[i].se][a[i].se]);
sub(f[i], calc[min(n + 1, i + a[i].se * (a[i].fi + 1))][a[i].se]);
}
}
}
for (int d = 1; d <= S; ++d) {
add(calc[i][d], f[i]);
add(calc[i][d], calc[i + d][d]);
}
// cout << i << ' ' << f[i] << '\n';
}
cout << f[1];
return;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define TASK "task"
if (fopen(TASK".inp", "r")) {
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:104:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
104 | freopen(TASK".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:105:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
105 | freopen(TASK".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |