# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
50214 |
2018-06-08T10:25:34 Z |
mra2322001 |
Boat (APIO16_boat) |
C++14 |
|
561 ms |
8420 KB |
#include <bits/stdc++.h>
#define f0(i, n) for(int i=(0); i<(n); i++)
#define f1(i, n) for(int i=(1); i<=(n); i++)
#define x first
#define y second
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
const int N = 502;
int n;
pii a[N];
void sub1(){
vector <int> f(n + 3, 0);
f1(i, n){
f[i] = 1;
for(int j = i - 1; j >= 1; j--){
if(a[j].x < a[i].x){
f[i] = (f[i] + f[j])%mod;
}
}
}
int res = 0; /// phai co it nhat 1 tau gui
f1(i, n) res = (res + f[i])%mod;
cout << res;
exit(0);
}
void sub2(){
vector <vector <int> > f;
f.resize(n + 1);
f1(i, n){
f[i].resize((a[i].y - a[i].x + 2), 0);
}
f1(i, n){
int sz = a[i].y - a[i].x + 1;
f0(j, sz){
f[i][j] = 1;
if(j != 0) f[i][j] = (f[i][j] + f[i][j - 1])%mod;
for(int k = i - 1; k >= 1; k--){
int x = a[i].x + j, y = -1;
if(x > a[k].y) y = a[k].y - a[k].x;
else y = x - a[k].x - 1;
f[i][j] = (f[i][j] + f[k][y])%mod;
}
}
}
int res = 0;
f1(i, n){
int sz = a[i].y - a[i].x + 1;
res = (res + f[i][sz - 1])%mod;
}
cout << res;
exit(0);
}
ll d[N*4], cnt = 0;
ll f[N][N*4];
void sub3(){
f1(i, n){
d[++cnt] = a[i].x; d[++cnt] = a[i].y;
d[++cnt] = a[i].x - 1; d[++cnt] = a[i].y + 1;
}
sort(d + 1, d + cnt + 1);
f1(i, n){
f1(j, cnt - 1){
f[i][j] = f[i][j - 1];
if(d[j - 1] >= a[i].x && d[j] <= a[i].y){
if(d[j] + 1 >= a[i].x && d[j + 1] <= a[i].y && d[j] != d[j + 1]){
int vt = lower_bound(d + 1, d + cnt + 1, d[j] + 1) - d;
vt -= 2;
for(int k = i - 1; k >= 1; k--){
if(vt > 0){
f[i][j] = ( f[i][j] + (d[j + 1] - d[j])*1ll*(f[k][vt]))%mod;
}
}
f[i][j] = (f[i][j] + (d[j + 1] - d[j]))%mod;
}
}
else{
if(d[j] >= a[i].x && d[j + 1] <= a[i].y){
int vt = lower_bound(d + 1, d + cnt + 1, d[j]) - d;
vt -= 2;
for(int k = i - 1; k >= 1; k--){
if(vt > 0){
f[i][j] = ( f[i][j] + (d[j + 1] - d[j] + 1)*1ll*(f[k][vt]))%mod;
}
}
f[i][j] = (f[i][j] + (d[j + 1] - d[j] + 1))%mod;
}
}
}
}
int res = 0;
f1(i, n) (res = res + f[i][cnt - 1])%mod;
cout << (res + mod)%mod;
exit(0);
}
main(){
ios_base::sync_with_stdio(0);
bool giong = 1; ll dem = 0;
cin >> n;
f1(i, n){
cin >> a[i].x >> a[i].y;
if(a[i].x != a[i].y) giong = 0;
dem += (a[i].y - a[i].x + 1);
}
if(giong) sub1();
///if(dem <= 1e6 + 560) sub2();
sub3();
}
Compilation message
boat.cpp: In function 'void sub3()':
boat.cpp:98:41: warning: value computed is not used [-Wunused-value]
f1(i, n) (res = res + f[i][cnt - 1])%mod;
^
boat.cpp: At global scope:
boat.cpp:103:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
484 KB |
Output is correct |
3 |
Correct |
4 ms |
484 KB |
Output is correct |
4 |
Correct |
3 ms |
484 KB |
Output is correct |
5 |
Correct |
3 ms |
484 KB |
Output is correct |
6 |
Correct |
4 ms |
484 KB |
Output is correct |
7 |
Correct |
4 ms |
484 KB |
Output is correct |
8 |
Correct |
4 ms |
484 KB |
Output is correct |
9 |
Correct |
4 ms |
520 KB |
Output is correct |
10 |
Correct |
3 ms |
520 KB |
Output is correct |
11 |
Correct |
3 ms |
520 KB |
Output is correct |
12 |
Correct |
4 ms |
520 KB |
Output is correct |
13 |
Correct |
3 ms |
528 KB |
Output is correct |
14 |
Correct |
3 ms |
528 KB |
Output is correct |
15 |
Correct |
3 ms |
656 KB |
Output is correct |
16 |
Correct |
3 ms |
656 KB |
Output is correct |
17 |
Correct |
3 ms |
656 KB |
Output is correct |
18 |
Correct |
3 ms |
656 KB |
Output is correct |
19 |
Correct |
3 ms |
656 KB |
Output is correct |
20 |
Correct |
3 ms |
656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
484 KB |
Output is correct |
3 |
Correct |
4 ms |
484 KB |
Output is correct |
4 |
Correct |
3 ms |
484 KB |
Output is correct |
5 |
Correct |
3 ms |
484 KB |
Output is correct |
6 |
Correct |
4 ms |
484 KB |
Output is correct |
7 |
Correct |
4 ms |
484 KB |
Output is correct |
8 |
Correct |
4 ms |
484 KB |
Output is correct |
9 |
Correct |
4 ms |
520 KB |
Output is correct |
10 |
Correct |
3 ms |
520 KB |
Output is correct |
11 |
Correct |
3 ms |
520 KB |
Output is correct |
12 |
Correct |
4 ms |
520 KB |
Output is correct |
13 |
Correct |
3 ms |
528 KB |
Output is correct |
14 |
Correct |
3 ms |
528 KB |
Output is correct |
15 |
Correct |
3 ms |
656 KB |
Output is correct |
16 |
Correct |
3 ms |
656 KB |
Output is correct |
17 |
Correct |
3 ms |
656 KB |
Output is correct |
18 |
Correct |
3 ms |
656 KB |
Output is correct |
19 |
Correct |
3 ms |
656 KB |
Output is correct |
20 |
Correct |
3 ms |
656 KB |
Output is correct |
21 |
Incorrect |
561 ms |
8420 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
8420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
484 KB |
Output is correct |
3 |
Correct |
4 ms |
484 KB |
Output is correct |
4 |
Correct |
3 ms |
484 KB |
Output is correct |
5 |
Correct |
3 ms |
484 KB |
Output is correct |
6 |
Correct |
4 ms |
484 KB |
Output is correct |
7 |
Correct |
4 ms |
484 KB |
Output is correct |
8 |
Correct |
4 ms |
484 KB |
Output is correct |
9 |
Correct |
4 ms |
520 KB |
Output is correct |
10 |
Correct |
3 ms |
520 KB |
Output is correct |
11 |
Correct |
3 ms |
520 KB |
Output is correct |
12 |
Correct |
4 ms |
520 KB |
Output is correct |
13 |
Correct |
3 ms |
528 KB |
Output is correct |
14 |
Correct |
3 ms |
528 KB |
Output is correct |
15 |
Correct |
3 ms |
656 KB |
Output is correct |
16 |
Correct |
3 ms |
656 KB |
Output is correct |
17 |
Correct |
3 ms |
656 KB |
Output is correct |
18 |
Correct |
3 ms |
656 KB |
Output is correct |
19 |
Correct |
3 ms |
656 KB |
Output is correct |
20 |
Correct |
3 ms |
656 KB |
Output is correct |
21 |
Incorrect |
561 ms |
8420 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |