답안 #172677

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
172677 2020-01-02T10:48:02 Z Ruxandra985 Boat (APIO16_boat) C++14
36 / 100
2000 ms 4548 KB
#include <bits/stdc++.h>
#define DIMN 510
#define MOD 1000000007
using namespace std;
pair <long long,long long> v[DIMN] , tot[2*DIMN];
long long dp[2*DIMN][DIMN] , op[DIMN] , last[DIMN] , fact[DIMN];
long long sum[DIMN][DIMN];
void combinari (long long x , long long y){

    last[0] = 1;
    for (long long i = 1 ; i <= y && i <= x ; i++)
        last[i] = ((long long)last[i-1] * (x - i + 1)) % MOD;

}
long long ridput (long long x , long long y){
    long long sol = 1;

    while (y){

        if (y % 2)
            sol = ((long long) sol * x )%MOD;

        x = ((long long) x * x )%MOD;

        y/=2;
    }

    return sol;

}
int main()
{
    FILE *fin = stdin;
    FILE *fout = stdout;
    long long n , elem , open , i , j , k , left , toput;
    fscanf (fin,"%lld",&n);
    elem = 0;
    fact[0] = 1;
    for (i=1;i<=n;i++){
        fscanf (fin,"%lld%lld",&v[i].first,&v[i].second);
        tot[++elem] = make_pair(v[i].first , i);
        tot[++elem] = make_pair(v[i].second + 1 , -i);
        fact[i] = ((long long) fact[i-1] * i )%MOD;
    }
    tot[++elem] = make_pair(1000000001 , 0);
    sort (tot + 1 , tot + elem + 1);
    dp[0][0] = 1;
    open = 0;
    int ant = 0;
    for (i=1;i<elem;i++){
        dp[i][0] = 1;
        /// vreau sa pun cateva in intervalul tot[i].first ... tot[i+1].first - 1
        if (tot[i].second > 0){ /// incepe ceva
            for (j = open + 1 ; ; j--){
                if (op[j-1] > tot[i].second)
                    op[j] = op[j-1];
                else {
                    op[j] = tot[i].second;
                    break;
                }
            }
            open++;
        }
        else { /// s a terminat ceva
            for (j = 1 ; j<open ; j++){
                if (op[j+1] > -tot[i].second)
                    op[j] = op[j+1];
            }
            op[open] = 0;
            open--;
        }
        if (tot[i+1].first == tot[i].first)
            continue;

        combinari (tot[i+1].first - tot[i].first , open);

        for (j=1;j<=open;j++){
            for (k=1;k<=j;k++){ /// sa pui k dintre j in interval
                sum[j][k] = (sum[j][k-1] + ( (last[k] * ridput(fact[k] , MOD-2))%MOD
                * (fact[j-1] * ridput( ((fact[k-1] * fact[j - k]) % MOD) , MOD-2 )%MOD)%MOD )%MOD )%MOD;
            }
        }

        for (j=1;j<=n;j++)
            dp[i][j] = dp[ant][j];

        /// ai updatat lista de disponibile
        for (j = 1 ; j <= open ; j++){ /// cea mai mare pe care o pun sigur
            left = j;
            for (k = 0 ; k <= op[j] ; k++){

                while (left && k >= op[j - left + 1]) /// sunt o(n) overall
                    left--;


                /// in interv curant pui cv subset intre opant[k] si op[j]
                /// pe k esti 100% sigura ca l ai pus

                toput = min(tot[i+1].first - tot[i].first , left);

                if (!toput)
                    break;

                /// poti sa pui intre 1 si toput in intervalul asta
                /// stii ca tu vrei neaparat sa il pui pe op[j]

                dp[i][op[j]] += dp[ant][k] * sum[left][toput];

                dp[i][op[j]] %= MOD;


            }
        }
        ant = i;
    }
    long long sol = 0;
    for (i=1;i<=n;i++)
        sol = (sol + dp[elem - 1][i])%MOD;
    fprintf (fout,"%lld",sol);
    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:36:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%lld",&n);
     ~~~~~~~^~~~~~~~~~~~~~~
boat.cpp:40:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%lld%lld",&v[i].first,&v[i].second);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4344 KB Output is correct
2 Correct 7 ms 4344 KB Output is correct
3 Correct 7 ms 4344 KB Output is correct
4 Correct 7 ms 4344 KB Output is correct
5 Correct 7 ms 4344 KB Output is correct
6 Correct 7 ms 4344 KB Output is correct
7 Correct 7 ms 4344 KB Output is correct
8 Correct 7 ms 4344 KB Output is correct
9 Correct 7 ms 4348 KB Output is correct
10 Correct 7 ms 4348 KB Output is correct
11 Correct 7 ms 4344 KB Output is correct
12 Correct 7 ms 4344 KB Output is correct
13 Correct 7 ms 4344 KB Output is correct
14 Correct 7 ms 4344 KB Output is correct
15 Correct 7 ms 4344 KB Output is correct
16 Correct 7 ms 4472 KB Output is correct
17 Correct 7 ms 4472 KB Output is correct
18 Correct 7 ms 4472 KB Output is correct
19 Correct 7 ms 4548 KB Output is correct
20 Correct 7 ms 4472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4344 KB Output is correct
2 Correct 7 ms 4344 KB Output is correct
3 Correct 7 ms 4344 KB Output is correct
4 Correct 7 ms 4344 KB Output is correct
5 Correct 7 ms 4344 KB Output is correct
6 Correct 7 ms 4344 KB Output is correct
7 Correct 7 ms 4344 KB Output is correct
8 Correct 7 ms 4344 KB Output is correct
9 Correct 7 ms 4348 KB Output is correct
10 Correct 7 ms 4348 KB Output is correct
11 Correct 7 ms 4344 KB Output is correct
12 Correct 7 ms 4344 KB Output is correct
13 Correct 7 ms 4344 KB Output is correct
14 Correct 7 ms 4344 KB Output is correct
15 Correct 7 ms 4344 KB Output is correct
16 Correct 7 ms 4472 KB Output is correct
17 Correct 7 ms 4472 KB Output is correct
18 Correct 7 ms 4472 KB Output is correct
19 Correct 7 ms 4548 KB Output is correct
20 Correct 7 ms 4472 KB Output is correct
21 Execution timed out 2050 ms 3140 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 1400 KB Output is correct
2 Correct 36 ms 1400 KB Output is correct
3 Correct 46 ms 1404 KB Output is correct
4 Correct 50 ms 1428 KB Output is correct
5 Correct 56 ms 1392 KB Output is correct
6 Correct 116 ms 1528 KB Output is correct
7 Correct 116 ms 1532 KB Output is correct
8 Correct 116 ms 1528 KB Output is correct
9 Correct 116 ms 1552 KB Output is correct
10 Correct 116 ms 1528 KB Output is correct
11 Correct 56 ms 1416 KB Output is correct
12 Correct 38 ms 1328 KB Output is correct
13 Correct 49 ms 1300 KB Output is correct
14 Correct 47 ms 1300 KB Output is correct
15 Correct 55 ms 1360 KB Output is correct
16 Correct 36 ms 1360 KB Output is correct
17 Correct 29 ms 1396 KB Output is correct
18 Correct 31 ms 1400 KB Output is correct
19 Correct 29 ms 1400 KB Output is correct
20 Correct 35 ms 1400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4344 KB Output is correct
2 Correct 7 ms 4344 KB Output is correct
3 Correct 7 ms 4344 KB Output is correct
4 Correct 7 ms 4344 KB Output is correct
5 Correct 7 ms 4344 KB Output is correct
6 Correct 7 ms 4344 KB Output is correct
7 Correct 7 ms 4344 KB Output is correct
8 Correct 7 ms 4344 KB Output is correct
9 Correct 7 ms 4348 KB Output is correct
10 Correct 7 ms 4348 KB Output is correct
11 Correct 7 ms 4344 KB Output is correct
12 Correct 7 ms 4344 KB Output is correct
13 Correct 7 ms 4344 KB Output is correct
14 Correct 7 ms 4344 KB Output is correct
15 Correct 7 ms 4344 KB Output is correct
16 Correct 7 ms 4472 KB Output is correct
17 Correct 7 ms 4472 KB Output is correct
18 Correct 7 ms 4472 KB Output is correct
19 Correct 7 ms 4548 KB Output is correct
20 Correct 7 ms 4472 KB Output is correct
21 Execution timed out 2050 ms 3140 KB Time limit exceeded
22 Halted 0 ms 0 KB -