답안 #493944

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
493944 2021-12-13T13:02:04 Z trumchepcode Boat (APIO16_boat) C++14
9 / 100
512 ms 524292 KB
#include <bits/stdc++.h>
using namespace std;
const int N=501;
const int mod=1e9+7;
int n;
long long a[N],b[N],st[4*N+1];
void update(int id,int l,int r,int x,int val)
{
    if(l>r||r<x||l>x) return ;
    if(l==x&&r==x)
    {
        st[id]=val;
        return ;
    }
    int mid=(l+r)/2;
    if(mid>=x) update(id*2,l,mid,x,val);
    else update(id*2+1,mid+1,r,x,val);
    st[id]=(st[id*2+1]+st[id*2])%mod;
}
long long  get(int id,int l,int r,int u,int v)
{
    if(l>r||u>v||r<u||l>v) return 0;
    if(l>=u&&v>=r) return st[id];
    int mid=(l+r)/2;
    return (get(id*2,l,mid,u,v)%mod+get(id*2+1,mid+1,r,u,v)%mod)%mod;
}
vector<int>v;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   // freopen("dut03teams.inp","r",stdin);
   // freopen("dut03teams.out","w",stdout);
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i] >> b[i];
        for(int j=a[i];j<=b[i];j++)
        {
            v.push_back(j);
        }
    }
    sort(v.begin(),v.end());
    int id=1;
    map<int,int>mp;
    for(int i=0;i<v.size();i++)
    {
        if(i==0||v[i]!=v[i-1])
        {
            mp[v[i]]=id++;
        }
    }
    for(int i=1;i<=n;i++)
    {
        a[i]=mp[a[i]];
        b[i]=mp[b[i]];
    }
    vector<long long>dp(id+1,0);
    dp[0]=1;
    update(1,0,n,0,1);
    for(int i=1;i<=n;i++)
    {
        for(int j=b[i];j>=a[i];j--)
        {
            dp[j]=(dp[j]+get(1,0,n,0,j-1))%mod;
            update(1,0,n,j,dp[j]);
        }
    }
    long long ans=0;
    for(int i=1;i<id;i++)
    {
        ans=(ans+dp[i])%mod;
    }
    cout << ans;


}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:47:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for(int i=0;i<v.size();i++)
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Incorrect 47 ms 4548 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 512 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Incorrect 47 ms 4548 KB Output isn't correct
22 Halted 0 ms 0 KB -