답안 #1092684

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092684 2024-09-24T18:17:55 Z alexander707070 Boat (APIO16_boat) C++17
0 / 100
2000 ms 330700 KB
#include<bits/stdc++.h>
#define MAXN 507
using namespace std;

const int mod=1e9+7;

int n,a[MAXN],b[MAXN];
vector<int> pos;
map<int,bool> mp;
map<int,int> where;

int dp[2][1000007];
int pref[2][1000007];

int sum(int id,int from,int to){
    if(from>to)return 0;

    if(from>0)return (pref[id][to]-pref[id][from-1]+mod)%mod;
    return pref[id][to];
}

int main(){

    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i];

        for(int f=a[i];f<=b[i];f++){
            if(mp[f])continue;

            mp[f]=true;
            pos.push_back(f);
        }
    }

    pos.push_back(0);
    sort(pos.begin(),pos.end());

    for(int i=0;i<pos.size();i++)where[pos[i]]=i;

    for(int i=0;i<pos.size();i++){
        pref[0][i]=i+1; dp[0][i]=1;
    }

    for(int i=1;i<=n;i++){
        for(int f=0;f<pos.size();f++){

            dp[i%2][f]=(sum(1-i%2,where[a[i]]-1,min(f,where[b[i]])-1) + dp[1-i%2][f])%mod; 

            pref[i%2][f]=dp[i%2][f];
            if(f>0)pref[i%2][f]+=pref[1-i%2][f];

            pref[i%2][f]%=mod;
        }
    }

    cout<<dp[n%2][pos.size()-1]-1<<"\n";
 
    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:39:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for(int i=0;i<pos.size();i++)where[pos[i]]=i;
      |                 ~^~~~~~~~~~~
boat.cpp:41:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int i=0;i<pos.size();i++){
      |                 ~^~~~~~~~~~~
boat.cpp:46:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for(int f=0;f<pos.size();f++){
      |                     ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2061 ms 330700 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -