답안 #1092693

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092693 2024-09-24T18:27:14 Z alexander707070 Boat (APIO16_boat) C++14
31 / 100
2000 ms 325180 KB
#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#define MAXN 507
using namespace std;

const long long mod=1e9+7;

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

pair<int,int> s[MAXN];

long long dp[2][1000007];
long long pref[2][1000007];

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

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

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    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=1;i<=n;i++){
        s[i]={where[a[i]],where[b[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,s[i].first-1,min(f,s[i].second)-1) + dp[1-i%2][f])%mod; 

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

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

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:48:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for(int i=0;i<pos.size();i++)where[pos[i]]=i;
      |                 ~^~~~~~~~~~~
boat.cpp:54:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for(int i=0;i<pos.size();i++){
      |                 ~^~~~~~~~~~~
boat.cpp:59:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         for(int f=0;f<pos.size();f++){
      |                     ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 38 ms 1104 KB Output is correct
22 Correct 39 ms 988 KB Output is correct
23 Correct 37 ms 1108 KB Output is correct
24 Correct 39 ms 984 KB Output is correct
25 Correct 42 ms 992 KB Output is correct
26 Correct 25 ms 856 KB Output is correct
27 Correct 25 ms 860 KB Output is correct
28 Correct 23 ms 916 KB Output is correct
29 Correct 25 ms 860 KB Output is correct
30 Correct 1456 ms 123952 KB Output is correct
31 Correct 1502 ms 121900 KB Output is correct
32 Correct 1483 ms 123952 KB Output is correct
33 Correct 1481 ms 121052 KB Output is correct
34 Correct 1456 ms 122160 KB Output is correct
35 Correct 1268 ms 116940 KB Output is correct
36 Correct 1341 ms 120628 KB Output is correct
37 Correct 1311 ms 121908 KB Output is correct
38 Correct 1290 ms 118392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2090 ms 325180 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 38 ms 1104 KB Output is correct
22 Correct 39 ms 988 KB Output is correct
23 Correct 37 ms 1108 KB Output is correct
24 Correct 39 ms 984 KB Output is correct
25 Correct 42 ms 992 KB Output is correct
26 Correct 25 ms 856 KB Output is correct
27 Correct 25 ms 860 KB Output is correct
28 Correct 23 ms 916 KB Output is correct
29 Correct 25 ms 860 KB Output is correct
30 Correct 1456 ms 123952 KB Output is correct
31 Correct 1502 ms 121900 KB Output is correct
32 Correct 1483 ms 123952 KB Output is correct
33 Correct 1481 ms 121052 KB Output is correct
34 Correct 1456 ms 122160 KB Output is correct
35 Correct 1268 ms 116940 KB Output is correct
36 Correct 1341 ms 120628 KB Output is correct
37 Correct 1311 ms 121908 KB Output is correct
38 Correct 1290 ms 118392 KB Output is correct
39 Execution timed out 2090 ms 325180 KB Time limit exceeded
40 Halted 0 ms 0 KB -