Submission #219855

# Submission time Handle Problem Language Result Execution time Memory
219855 2020-04-06T14:42:08 Z MKopchev Boat (APIO16_boat) C++14
0 / 100
20 ms 9088 KB
#include<bits/stdc++.h>
using namespace std;
const int nmax=1e3+42,mod=1e9+7;

int my_pow(long long a,int b)
{
    long long ret=1;
    while(b)
    {
        if(b%2)ret=ret*a%mod;
        a=a*a%mod;
        b=b/2;
    }
    return ret;
}

int n;
pair<int,int> inp[nmax];

set< pair<int,int> > seen;

pair<int,int> groups[nmax];
int pointer=0;

int inv[nmax];

int dp[nmax][nmax][2];

int rec(int which_number,int last_used_group,bool can_place_zero)
{
    if(which_number>n)return 1;//properly chosen
    if(last_used_group==pointer)return can_place_zero;//skipped too much

    if(dp[which_number][last_used_group][can_place_zero]!=-1)return dp[which_number][last_used_group][can_place_zero];

    long long ret=0;

    //place zero
    if(can_place_zero)ret=(ret+rec(which_number+1,last_used_group,1))%mod;

    //place non-zero for other group
    ret=(ret+rec(which_number,last_used_group+1,0));//ignore this group

    //place non-zero
    long long mult=1;
    for(int use=which_number;use<=n;use++)
        if(inp[use].first<=groups[last_used_group+1].first&&groups[last_used_group+1].second<=inp[use].second)
        {
            int nums=use-which_number+1,cur_sz=groups[last_used_group+1].second-groups[last_used_group+1].first+1;

            mult=mult*(cur_sz-nums+1)%mod*inv[nums]%mod;

            if(mult==0)break;

            ret=(ret+mult*rec(use+1,last_used_group+1,1))%mod;

            //cout<<"which_number= "<<which_number<<" last_used_group= "<<last_used_group<<" use= "<<use<<" mult= "<<mult<<" finish= "<<rec(use+1,last_used_group+1,1)<<endl;
        }
        else break;
    dp[which_number][last_used_group][can_place_zero]=ret;

    //cout<<which_number<<" "<<last_used_group<<" "<<can_place_zero<<" -> "<<ret<<endl;

    return ret;
}
int main()
{
    memset(dp,-1,sizeof(dp));

    scanf("%i",&n);

    for(int i=1;i<nmax;i++)inv[i]=my_pow(i,mod-2);

    int prv=1e9;
    for(int i=1;i<=n;i++)
    {
        scanf("%i%i",&inp[i].first,&inp[i].second);

        seen.insert({inp[i].first,-1});
        seen.insert({inp[i].second,0});

        prv=min(prv,inp[i].first);
        prv=min(prv,inp[i].second);
    }

    for(auto k:seen)
    {
        int other=k.first+k.second;
        if(prv<=other)
        {
            pointer++;
            groups[pointer]={prv,other};
            prv=other+1;
        }
    }

    //for(int i=1;i<=pointer;i++)cout<<groups[i].first<<" "<<groups[i].second<<endl;

    int out=rec(1,0,1);

    out=(out-1+mod)%mod;

    printf("%i\n",out);
    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i",&n);
     ~~~~~^~~~~~~~~
boat.cpp:77:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i%i",&inp[i].first,&inp[i].second);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 20 ms 9088 KB Output is correct
2 Correct 20 ms 9088 KB Output is correct
3 Correct 20 ms 9088 KB Output is correct
4 Correct 19 ms 9088 KB Output is correct
5 Correct 19 ms 8960 KB Output is correct
6 Correct 19 ms 8960 KB Output is correct
7 Correct 20 ms 9088 KB Output is correct
8 Correct 18 ms 9088 KB Output is correct
9 Correct 18 ms 8960 KB Output is correct
10 Correct 19 ms 8960 KB Output is correct
11 Correct 19 ms 9088 KB Output is correct
12 Correct 19 ms 9088 KB Output is correct
13 Correct 18 ms 8960 KB Output is correct
14 Correct 18 ms 8960 KB Output is correct
15 Correct 19 ms 8960 KB Output is correct
16 Correct 11 ms 8960 KB Output is correct
17 Correct 12 ms 8960 KB Output is correct
18 Incorrect 11 ms 8960 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 9088 KB Output is correct
2 Correct 20 ms 9088 KB Output is correct
3 Correct 20 ms 9088 KB Output is correct
4 Correct 19 ms 9088 KB Output is correct
5 Correct 19 ms 8960 KB Output is correct
6 Correct 19 ms 8960 KB Output is correct
7 Correct 20 ms 9088 KB Output is correct
8 Correct 18 ms 9088 KB Output is correct
9 Correct 18 ms 8960 KB Output is correct
10 Correct 19 ms 8960 KB Output is correct
11 Correct 19 ms 9088 KB Output is correct
12 Correct 19 ms 9088 KB Output is correct
13 Correct 18 ms 8960 KB Output is correct
14 Correct 18 ms 8960 KB Output is correct
15 Correct 19 ms 8960 KB Output is correct
16 Correct 11 ms 8960 KB Output is correct
17 Correct 12 ms 8960 KB Output is correct
18 Incorrect 11 ms 8960 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 8832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 9088 KB Output is correct
2 Correct 20 ms 9088 KB Output is correct
3 Correct 20 ms 9088 KB Output is correct
4 Correct 19 ms 9088 KB Output is correct
5 Correct 19 ms 8960 KB Output is correct
6 Correct 19 ms 8960 KB Output is correct
7 Correct 20 ms 9088 KB Output is correct
8 Correct 18 ms 9088 KB Output is correct
9 Correct 18 ms 8960 KB Output is correct
10 Correct 19 ms 8960 KB Output is correct
11 Correct 19 ms 9088 KB Output is correct
12 Correct 19 ms 9088 KB Output is correct
13 Correct 18 ms 8960 KB Output is correct
14 Correct 18 ms 8960 KB Output is correct
15 Correct 19 ms 8960 KB Output is correct
16 Correct 11 ms 8960 KB Output is correct
17 Correct 12 ms 8960 KB Output is correct
18 Incorrect 11 ms 8960 KB Output isn't correct
19 Halted 0 ms 0 KB -