제출 #1261957

#제출 시각아이디문제언어결과실행 시간메모리
1261957CrabCNHTrains (BOI24_trains)C++20
16 / 100
319 ms253248 KiB
#include <bits/stdc++.h>

#define task     "BriantheCrab"

#define int    long long
#define pii    pair <int, int>
#define fi     first
#define se     second
#define szf    sizeof
#define sz(s)  (int)((s).size())
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

template <class T> void minimize (T &t, T f) {if (t > f) t = f;}
template <class T> void maximize (T &t, T f) {if (t < f) t = f;}

const int maxN = 1e5 + 5;
const int maxB = 320;
const int inf = 1e18 + 7;
const int mod = 1e9 + 7;

// khong tu code thi khong kha len duoc dau
// biet sol roi thi tu lam not di

int d[maxN], x[maxN];
int dp[maxN];
int f[maxN][maxB]; // tong cach de den i voi buoc nhay cuoi = j

void solve () {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i ++) {
        cin >> d[i] >> x[i];
    }
    int bl = sqrt (n);
    dp[1] = 1;
    for (int i = 1; i <= n; i ++) {
        for (int j = 1; j <= bl; j ++) {
            if (i + j <= n) {
                (f[i + j][j] += f[i][j]) %= mod;
            }
            (dp[i] += f[i][j]) %= mod;
        }
        if (d[i] == 0) {
            continue;
        }
        if (d[i] > bl) {
            for (int t = 1; t <= x[i]; t ++) {
                (dp[i + t * d[i]] += dp[i]) %= mod;
            }
        }
        else {
            if (i + d[i] <= n) {
                (f[i + d[i]][d[i]] += dp[i]) %= mod;
            }
            if (i + d[i] * (x[i] + 1) <= n) {
                (f[i + d[i] * (x[i] + 1)][d[i]] += -dp[i] + mod) %= mod;
            }
        }
    }
    int res = 0;
    for (int i = 1; i <= n; i ++) {
        (res += dp[i]) %= mod;
    }
    cout << res;
    return;
}

signed main () {
    cin.tie (nullptr) -> sync_with_stdio (false);
    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;
}
// thfv

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

Main.cpp: In function 'int main()':
Main.cpp:77:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:78:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...