답안 #257971

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
257971 2020-08-05T06:47:49 Z daniel920712 Boat (APIO16_boat) C++14
9 / 100
2000 ms 7416 KB
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <time.h>

using namespace std;
long long MOD=1e9+7;
long long DP[505][2005];
bool use[505][2005]={0};
long long cha[2005],Con[2005],R[2005];
map < long long , long long > all;
long long N,now=0;
long long a[505],b[505];
map < long long , long long > con,r;
set < long long > have;
long long Pow(long long a,long long b)
{
    if(b==0) return a;
    long long t=Pow(a,b/2);
    t*=t;
    t%=MOD;
    if(b%2) t*=a;
    return t%MOD;
}
long long F(long long x,long long y)
{
    long long i,j,tt;
    if(x==0) return y!=(now);
    if(use[x][y]) return DP[x][y];
    use[x][y]=1;
    DP[x][y]=F(x-1,y);
    for(i=0;i<now;i++)
    {
        //printf("aa %lld %lld %lld %lld %lld\n",x,y,i,cha[i],a[x]);
        if(cha[i]>=a[x]&&R[i]<cha[y]&&R[i]<=b[x])
        {

            tt=1;
            for(j=x;j>=1;j--)
            {
                if(cha[i]>=a[j]&&R[i]<cha[y]&&R[i]<=b[j])
                {

                    tt*=(Con[i]-(x-j));
                    tt%=MOD;
                    tt*=Pow(x-j+1,MOD-2);
                    tt%=MOD;
                    DP[x][y]+=tt*F(j-1,i)%MOD;
                    DP[x][y]%=MOD;

                }
                else break;
            }

        }
    }
    //printf("%lld %lld %lld\n",x,y,DP[x][y]);
    return DP[x][y];
}

int main()
{
    //freopen("3_01.in","rt",stdin);
    //srand(time(NULL));
    long long N,M,i;
    scanf("%lld",&N);
    for(i=1;i<=N;i++)
    {
        scanf("%lld %lld",&a[i],&b[i]);
        have.insert(a[i]);
        have.insert(a[i]+1);
        have.insert(b[i]);
        have.insert(b[i]+1);
    }
    for(auto i:have)
    {
        if(i==*prev(have.end()))
        {
            con[i]=1;
            r[i]=i;
        }
        if(have.lower_bound(i)!=have.begin())
        {
            con[*prev(have.lower_bound(i))]=i-*prev(have.lower_bound(i));
            r[*prev(have.lower_bound(i))]=i-1;
        }
    }
    for(auto i:con)
    {
        cha[now]=i.first;
        Con[now]=i.second;
        R[now]=r[i.first];
        now++;
    }
    cha[now]=1e9+5;
    Con[now]=0;
    R[now]=2e9;
    //for(i=0;i<now;i++) printf("aa %lld %lld %lld %lld\n",i,cha[i],Con[i],R[i]);
    printf("%lld\n",F(N,now));


    return 0;
}
/*
2
32 47
18 78
*/

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:67:17: warning: unused variable 'M' [-Wunused-variable]
     long long N,M,i;
                 ^
boat.cpp:68:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&N);
     ~~~~~^~~~~~~~~~~
boat.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld",&a[i],&b[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 179 ms 7416 KB Output is correct
2 Correct 178 ms 7416 KB Output is correct
3 Correct 186 ms 7416 KB Output is correct
4 Correct 178 ms 7416 KB Output is correct
5 Correct 178 ms 7416 KB Output is correct
6 Correct 221 ms 6392 KB Output is correct
7 Correct 222 ms 6136 KB Output is correct
8 Correct 221 ms 6776 KB Output is correct
9 Correct 217 ms 6648 KB Output is correct
10 Correct 219 ms 6776 KB Output is correct
11 Correct 219 ms 6524 KB Output is correct
12 Correct 225 ms 7100 KB Output is correct
13 Correct 214 ms 6776 KB Output is correct
14 Correct 220 ms 6264 KB Output is correct
15 Correct 221 ms 6776 KB Output is correct
16 Correct 22 ms 4096 KB Output is correct
17 Correct 23 ms 4096 KB Output is correct
18 Correct 20 ms 4096 KB Output is correct
19 Correct 22 ms 4096 KB Output is correct
20 Correct 22 ms 4096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 179 ms 7416 KB Output is correct
2 Correct 178 ms 7416 KB Output is correct
3 Correct 186 ms 7416 KB Output is correct
4 Correct 178 ms 7416 KB Output is correct
5 Correct 178 ms 7416 KB Output is correct
6 Correct 221 ms 6392 KB Output is correct
7 Correct 222 ms 6136 KB Output is correct
8 Correct 221 ms 6776 KB Output is correct
9 Correct 217 ms 6648 KB Output is correct
10 Correct 219 ms 6776 KB Output is correct
11 Correct 219 ms 6524 KB Output is correct
12 Correct 225 ms 7100 KB Output is correct
13 Correct 214 ms 6776 KB Output is correct
14 Correct 220 ms 6264 KB Output is correct
15 Correct 221 ms 6776 KB Output is correct
16 Correct 22 ms 4096 KB Output is correct
17 Correct 23 ms 4096 KB Output is correct
18 Correct 20 ms 4096 KB Output is correct
19 Correct 22 ms 4096 KB Output is correct
20 Correct 22 ms 4096 KB Output is correct
21 Execution timed out 2083 ms 1900 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1745 ms 1736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 179 ms 7416 KB Output is correct
2 Correct 178 ms 7416 KB Output is correct
3 Correct 186 ms 7416 KB Output is correct
4 Correct 178 ms 7416 KB Output is correct
5 Correct 178 ms 7416 KB Output is correct
6 Correct 221 ms 6392 KB Output is correct
7 Correct 222 ms 6136 KB Output is correct
8 Correct 221 ms 6776 KB Output is correct
9 Correct 217 ms 6648 KB Output is correct
10 Correct 219 ms 6776 KB Output is correct
11 Correct 219 ms 6524 KB Output is correct
12 Correct 225 ms 7100 KB Output is correct
13 Correct 214 ms 6776 KB Output is correct
14 Correct 220 ms 6264 KB Output is correct
15 Correct 221 ms 6776 KB Output is correct
16 Correct 22 ms 4096 KB Output is correct
17 Correct 23 ms 4096 KB Output is correct
18 Correct 20 ms 4096 KB Output is correct
19 Correct 22 ms 4096 KB Output is correct
20 Correct 22 ms 4096 KB Output is correct
21 Execution timed out 2083 ms 1900 KB Time limit exceeded
22 Halted 0 ms 0 KB -