답안 #400058

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
400058 2021-05-07T09:34:45 Z juggernaut Boat (APIO16_boat) C++17
100 / 100
1444 ms 4296 KB
#include<bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
typedef long long ll;
#define USING_ORDERED_SET 0
#if USING_ORDERED_SET
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#endif
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef IOI2021SG
    #define printl(args...)printf(args)
#else
    #define printl(args...)
#endif
#define mod 1000000007
vector<int>aux;
array<int,2>v[505];
ll dp[1005][505],inv[505];
int main(){
    int n,i,j,e;
    scanf("%d",&n);
    aux={-1};
    inv[1]=1;
    for(i=2;i<=n;i++)
        inv[i]=(mod-mod/i)*inv[mod%i]%mod;
    for(i=1;i<=n;i++){
        scanf("%d%d",&v[i][0],&v[i][1]);
        ++v[i][1];
        aux.push_back(v[i][0]);
        aux.push_back(v[i][1]);
    }
    sort(aux.begin(),aux.end());
    aux.resize(unique(aux.begin(),aux.end())-aux.begin());
    int m=aux.size();
    for(i=0;i<m;i++)
        dp[i][0]=1;
    for(i=1;i<=n;i++){
        for(j=m-1;j>=1;j--)
            if (v[i][0]<=aux[j-1] && aux[j]<=v[i][1]){
                int cnt=aux[j]-aux[j-1];
                for(e=min(cnt,i);e>=1;e--)
                    dp[j][e]=(dp[j][e]+dp[j][e-1]*(cnt-e+1)%mod*inv[e])%mod;
            }
        for(j=1;j<=m;j++){
            dp[j][0]=0;
            for(e=0;e<=n;e++)
                dp[j][0]=(dp[j][0]+dp[j-1][e])%mod;
        }
    }
    printf("%lld\n",(dp[m][0]+mod-1)%mod);
}

Compilation message

boat.cpp: In function 'void usaco(std::string)':
boat.cpp:5:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
boat.cpp:5:66: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
boat.cpp: In function 'int main()':
boat.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
boat.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   32 |         scanf("%d%d",&v[i][0],&v[i][1]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1144 ms 4260 KB Output is correct
2 Correct 1138 ms 4244 KB Output is correct
3 Correct 1145 ms 4248 KB Output is correct
4 Correct 1140 ms 4244 KB Output is correct
5 Correct 1142 ms 4244 KB Output is correct
6 Correct 1149 ms 4252 KB Output is correct
7 Correct 1142 ms 4248 KB Output is correct
8 Correct 1137 ms 4292 KB Output is correct
9 Correct 1147 ms 4292 KB Output is correct
10 Correct 1138 ms 4252 KB Output is correct
11 Correct 1141 ms 4252 KB Output is correct
12 Correct 1158 ms 4244 KB Output is correct
13 Correct 1145 ms 4244 KB Output is correct
14 Correct 1149 ms 4248 KB Output is correct
15 Correct 1151 ms 4244 KB Output is correct
16 Correct 203 ms 996 KB Output is correct
17 Correct 222 ms 1048 KB Output is correct
18 Correct 209 ms 1092 KB Output is correct
19 Correct 221 ms 1048 KB Output is correct
20 Correct 212 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1144 ms 4260 KB Output is correct
2 Correct 1138 ms 4244 KB Output is correct
3 Correct 1145 ms 4248 KB Output is correct
4 Correct 1140 ms 4244 KB Output is correct
5 Correct 1142 ms 4244 KB Output is correct
6 Correct 1149 ms 4252 KB Output is correct
7 Correct 1142 ms 4248 KB Output is correct
8 Correct 1137 ms 4292 KB Output is correct
9 Correct 1147 ms 4292 KB Output is correct
10 Correct 1138 ms 4252 KB Output is correct
11 Correct 1141 ms 4252 KB Output is correct
12 Correct 1158 ms 4244 KB Output is correct
13 Correct 1145 ms 4244 KB Output is correct
14 Correct 1149 ms 4248 KB Output is correct
15 Correct 1151 ms 4244 KB Output is correct
16 Correct 203 ms 996 KB Output is correct
17 Correct 222 ms 1048 KB Output is correct
18 Correct 209 ms 1092 KB Output is correct
19 Correct 221 ms 1048 KB Output is correct
20 Correct 212 ms 1024 KB Output is correct
21 Correct 1061 ms 3908 KB Output is correct
22 Correct 1062 ms 3956 KB Output is correct
23 Correct 1045 ms 3896 KB Output is correct
24 Correct 1045 ms 3868 KB Output is correct
25 Correct 1054 ms 3908 KB Output is correct
26 Correct 1010 ms 3788 KB Output is correct
27 Correct 1036 ms 3840 KB Output is correct
28 Correct 1025 ms 3784 KB Output is correct
29 Correct 1014 ms 3776 KB Output is correct
30 Correct 1145 ms 4260 KB Output is correct
31 Correct 1155 ms 4256 KB Output is correct
32 Correct 1137 ms 4252 KB Output is correct
33 Correct 1152 ms 4292 KB Output is correct
34 Correct 1132 ms 4244 KB Output is correct
35 Correct 1145 ms 4244 KB Output is correct
36 Correct 1136 ms 4172 KB Output is correct
37 Correct 1152 ms 4296 KB Output is correct
38 Correct 1136 ms 4248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 1100 KB Output is correct
2 Correct 12 ms 1108 KB Output is correct
3 Correct 12 ms 1100 KB Output is correct
4 Correct 12 ms 1100 KB Output is correct
5 Correct 12 ms 1068 KB Output is correct
6 Correct 13 ms 1112 KB Output is correct
7 Correct 14 ms 1100 KB Output is correct
8 Correct 13 ms 1228 KB Output is correct
9 Correct 13 ms 1100 KB Output is correct
10 Correct 13 ms 1100 KB Output is correct
11 Correct 12 ms 1100 KB Output is correct
12 Correct 12 ms 1104 KB Output is correct
13 Correct 12 ms 1112 KB Output is correct
14 Correct 12 ms 1100 KB Output is correct
15 Correct 12 ms 1100 KB Output is correct
16 Correct 7 ms 776 KB Output is correct
17 Correct 7 ms 716 KB Output is correct
18 Correct 7 ms 768 KB Output is correct
19 Correct 7 ms 716 KB Output is correct
20 Correct 7 ms 688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1144 ms 4260 KB Output is correct
2 Correct 1138 ms 4244 KB Output is correct
3 Correct 1145 ms 4248 KB Output is correct
4 Correct 1140 ms 4244 KB Output is correct
5 Correct 1142 ms 4244 KB Output is correct
6 Correct 1149 ms 4252 KB Output is correct
7 Correct 1142 ms 4248 KB Output is correct
8 Correct 1137 ms 4292 KB Output is correct
9 Correct 1147 ms 4292 KB Output is correct
10 Correct 1138 ms 4252 KB Output is correct
11 Correct 1141 ms 4252 KB Output is correct
12 Correct 1158 ms 4244 KB Output is correct
13 Correct 1145 ms 4244 KB Output is correct
14 Correct 1149 ms 4248 KB Output is correct
15 Correct 1151 ms 4244 KB Output is correct
16 Correct 203 ms 996 KB Output is correct
17 Correct 222 ms 1048 KB Output is correct
18 Correct 209 ms 1092 KB Output is correct
19 Correct 221 ms 1048 KB Output is correct
20 Correct 212 ms 1024 KB Output is correct
21 Correct 1061 ms 3908 KB Output is correct
22 Correct 1062 ms 3956 KB Output is correct
23 Correct 1045 ms 3896 KB Output is correct
24 Correct 1045 ms 3868 KB Output is correct
25 Correct 1054 ms 3908 KB Output is correct
26 Correct 1010 ms 3788 KB Output is correct
27 Correct 1036 ms 3840 KB Output is correct
28 Correct 1025 ms 3784 KB Output is correct
29 Correct 1014 ms 3776 KB Output is correct
30 Correct 1145 ms 4260 KB Output is correct
31 Correct 1155 ms 4256 KB Output is correct
32 Correct 1137 ms 4252 KB Output is correct
33 Correct 1152 ms 4292 KB Output is correct
34 Correct 1132 ms 4244 KB Output is correct
35 Correct 1145 ms 4244 KB Output is correct
36 Correct 1136 ms 4172 KB Output is correct
37 Correct 1152 ms 4296 KB Output is correct
38 Correct 1136 ms 4248 KB Output is correct
39 Correct 12 ms 1100 KB Output is correct
40 Correct 12 ms 1108 KB Output is correct
41 Correct 12 ms 1100 KB Output is correct
42 Correct 12 ms 1100 KB Output is correct
43 Correct 12 ms 1068 KB Output is correct
44 Correct 13 ms 1112 KB Output is correct
45 Correct 14 ms 1100 KB Output is correct
46 Correct 13 ms 1228 KB Output is correct
47 Correct 13 ms 1100 KB Output is correct
48 Correct 13 ms 1100 KB Output is correct
49 Correct 12 ms 1100 KB Output is correct
50 Correct 12 ms 1104 KB Output is correct
51 Correct 12 ms 1112 KB Output is correct
52 Correct 12 ms 1100 KB Output is correct
53 Correct 12 ms 1100 KB Output is correct
54 Correct 7 ms 776 KB Output is correct
55 Correct 7 ms 716 KB Output is correct
56 Correct 7 ms 768 KB Output is correct
57 Correct 7 ms 716 KB Output is correct
58 Correct 7 ms 688 KB Output is correct
59 Correct 1346 ms 4272 KB Output is correct
60 Correct 1331 ms 4292 KB Output is correct
61 Correct 1318 ms 4260 KB Output is correct
62 Correct 1335 ms 4260 KB Output is correct
63 Correct 1334 ms 4264 KB Output is correct
64 Correct 1441 ms 4256 KB Output is correct
65 Correct 1444 ms 4260 KB Output is correct
66 Correct 1432 ms 4292 KB Output is correct
67 Correct 1428 ms 4276 KB Output is correct
68 Correct 1422 ms 4260 KB Output is correct
69 Correct 1298 ms 4172 KB Output is correct
70 Correct 1283 ms 4292 KB Output is correct
71 Correct 1315 ms 4256 KB Output is correct
72 Correct 1289 ms 4260 KB Output is correct
73 Correct 1301 ms 4256 KB Output is correct
74 Correct 231 ms 1040 KB Output is correct
75 Correct 231 ms 1052 KB Output is correct
76 Correct 236 ms 1040 KB Output is correct
77 Correct 229 ms 1032 KB Output is correct
78 Correct 227 ms 1024 KB Output is correct