답안 #340169

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
340169 2020-12-27T06:10:26 Z blue Boat (APIO16_boat) C++11
9 / 100
14 ms 388 KB
#include <iostream>
#include <algorithm>
using namespace std;

/*
dp[i][j] = number of valid configurations for schools 1..i but such that i has range a[j] to b[i]

Let us malong longain a long range partitioned by polong longs P[i]
Each section of the range looks like:
A[p] to A[q]-1;
A[p] to B[q]
B[p]+1 to A[q]-1;
B[p]+1 to B[q]
*/

long long mod = 1e9 + 7;

long long a[501], b[501];

long long pos(long long i) //upper acceptable limit of range
{
    if(i > 0) return a[i] - 1;
    else return b[-i];
}

int main()
{
    long long N;
    cin >> N;
    for(long long i = 1; i <= N; i++) cin >> a[i] >> b[i];

    long long I[2*N];
    for(long long i = 0; i < N; i++)
    {
        I[i] = i+1;
        I[i+N] = -i-1;
    }

    sort(I, I+2*N, [] (long long x, long long y)
    {
        return pos(x) < pos(y);
    });

    long long dp[2*N]; //number of streams in between I[i-1] and I[i].
    for(long long i = 0; i < 2*N; i++) dp[i] = 0;

    long long temp = 0;
    long long temp2;
    long long temp_dp;
    for(long long i = 1; i <= N; i++)
    {
         // cout << "i = " << i << '\n';
        temp = 0;
        for(long long j = 1; j < 2*N; j++)
        {
            temp_dp = dp[j];
            int S = pos(I[j]) - pos(I[j-1]);

            if(pos(I[j]) <= pos(i)) temp = (temp + dp[j]) % mod;
            else if(pos(I[j]) <= pos(-i))
            {
                temp2 = temp;
                temp = (temp + dp[j]) % mod;
                if(j > 0) dp[j] = (dp[j]   +   S*temp2  ) % mod;
            }
            int Ssum = (((S-1)*S)/2) % mod;
            dp[j] = (dp[j] + (temp_dp * Ssum) % mod) % mod;
        }
        for(int j = 1; j < 2*N; j++)
        {
            if(pos(i) < pos(I[j]) && pos(I[j]) <= pos(-i))
            {
                dp[j] = (dp[j] + pos(I[j]) - pos(I[j-1])) % mod;
            }
        }
        // for(long long j = 0; j < 2*N; j++)
        // {
        //     cout << j << ' ' << I[j] << ' ' << pos(I[j]) << ' ' << dp[j] << '\n';
        // }
        // cout << "_________________________\n";
    }
    long long res = 0;
    for(long long j = 0; j < 2*N; j++) res = (res + dp[j]) % mod;

    cout << res << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 364 KB Output is correct
2 Correct 11 ms 364 KB Output is correct
3 Correct 11 ms 364 KB Output is correct
4 Correct 12 ms 384 KB Output is correct
5 Correct 12 ms 364 KB Output is correct
6 Correct 11 ms 364 KB Output is correct
7 Correct 11 ms 364 KB Output is correct
8 Correct 11 ms 364 KB Output is correct
9 Correct 12 ms 364 KB Output is correct
10 Correct 12 ms 384 KB Output is correct
11 Correct 11 ms 364 KB Output is correct
12 Correct 12 ms 364 KB Output is correct
13 Correct 11 ms 364 KB Output is correct
14 Correct 11 ms 364 KB Output is correct
15 Correct 11 ms 364 KB Output is correct
16 Correct 12 ms 364 KB Output is correct
17 Correct 13 ms 388 KB Output is correct
18 Correct 12 ms 364 KB Output is correct
19 Correct 13 ms 364 KB Output is correct
20 Correct 12 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 364 KB Output is correct
2 Correct 11 ms 364 KB Output is correct
3 Correct 11 ms 364 KB Output is correct
4 Correct 12 ms 384 KB Output is correct
5 Correct 12 ms 364 KB Output is correct
6 Correct 11 ms 364 KB Output is correct
7 Correct 11 ms 364 KB Output is correct
8 Correct 11 ms 364 KB Output is correct
9 Correct 12 ms 364 KB Output is correct
10 Correct 12 ms 384 KB Output is correct
11 Correct 11 ms 364 KB Output is correct
12 Correct 12 ms 364 KB Output is correct
13 Correct 11 ms 364 KB Output is correct
14 Correct 11 ms 364 KB Output is correct
15 Correct 11 ms 364 KB Output is correct
16 Correct 12 ms 364 KB Output is correct
17 Correct 13 ms 388 KB Output is correct
18 Correct 12 ms 364 KB Output is correct
19 Correct 13 ms 364 KB Output is correct
20 Correct 12 ms 364 KB Output is correct
21 Incorrect 14 ms 364 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 364 KB Output is correct
2 Correct 11 ms 364 KB Output is correct
3 Correct 11 ms 364 KB Output is correct
4 Correct 12 ms 384 KB Output is correct
5 Correct 12 ms 364 KB Output is correct
6 Correct 11 ms 364 KB Output is correct
7 Correct 11 ms 364 KB Output is correct
8 Correct 11 ms 364 KB Output is correct
9 Correct 12 ms 364 KB Output is correct
10 Correct 12 ms 384 KB Output is correct
11 Correct 11 ms 364 KB Output is correct
12 Correct 12 ms 364 KB Output is correct
13 Correct 11 ms 364 KB Output is correct
14 Correct 11 ms 364 KB Output is correct
15 Correct 11 ms 364 KB Output is correct
16 Correct 12 ms 364 KB Output is correct
17 Correct 13 ms 388 KB Output is correct
18 Correct 12 ms 364 KB Output is correct
19 Correct 13 ms 364 KB Output is correct
20 Correct 12 ms 364 KB Output is correct
21 Incorrect 14 ms 364 KB Output isn't correct
22 Halted 0 ms 0 KB -