답안 #995484

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
995484 2024-06-09T07:14:25 Z 12345678 Trains (BOI24_trains) C++17
34 / 100
110 ms 5280 KB
#include <bits/stdc++.h>

using namespace std;

const int nx=1e5+5, mod=1e9+7, kx=255;

int n, d[nx], x[nx], qs[kx][kx], dp[nx], res, k=250;
vector<int> rem[nx];

void add(int idx)
{
    if (d[idx]==0) return;
    if (d[idx]>k)
    {
        if (idx+d[idx]>n) return;
        for (int i=idx+d[idx], j=0; j<x[idx]&&i<=n; j++, i+=d[idx]) dp[i]=(dp[i]+dp[idx])%mod;
    }
    else
    {
        qs[d[idx]][idx%d[idx]]=(qs[d[idx]][idx%d[idx]]+dp[idx])%mod;
        if (idx+((long long)x[idx])*d[idx]<=n) rem[idx+(long long)x[idx]*d[idx]].push_back(idx); 
    }
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n;
    for (int i=1; i<=n; i++) cin>>d[i]>>x[i];
    dp[1]=1;
    add(1);
    for (int i=2; i<=n; i++)
    {
        for (int j=1; j<=k; j++) dp[i]=(dp[i]+qs[j][i%j])%mod;
        add(i);
        for (auto idx:rem[i]) qs[d[idx]][i%d[idx]]=(((qs[d[idx]][i%d[idx]]-dp[idx])%mod)+mod)%mod;
    }
    for (int i=1; i<=n; i++) res=(res+dp[i])%mod;
    if (res<0) cout<<1/0;
    cout<<res;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:39:23: warning: division by zero [-Wdiv-by-zero]
   39 |     if (res<0) cout<<1/0;
      |                      ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Incorrect 1 ms 2652 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Incorrect 1 ms 2652 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 8 ms 2904 KB Output is correct
3 Correct 6 ms 2652 KB Output is correct
4 Correct 10 ms 2900 KB Output is correct
5 Correct 83 ms 5280 KB Output is correct
6 Correct 106 ms 3848 KB Output is correct
7 Correct 107 ms 4008 KB Output is correct
8 Incorrect 1 ms 2648 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 3164 KB Output is correct
2 Correct 44 ms 3164 KB Output is correct
3 Correct 106 ms 3924 KB Output is correct
4 Correct 76 ms 3476 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 12 ms 2908 KB Output is correct
8 Correct 110 ms 3924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Incorrect 1 ms 2652 KB Output isn't correct
10 Halted 0 ms 0 KB -