Submission #340167

#TimeUsernameProblemLanguageResultExecution timeMemory
340167blueBoat (APIO16_boat)C++11
9 / 100
4 ms364 KiB
#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; for(long long i = 1; i <= N; i++) { // cout << "i = " << i << '\n'; temp = 0; for(long long j = 1; j < 2*N; j++) { if(pos(I[j]) <= pos(i)) temp = (temp + dp[j]) % mod; else if(pos(I[j]) <= pos(-i)) { temp2 = temp; temp = (temp + (pos(I[j]) - pos(I[j-1]))*dp[j]) % mod; if(j > 0) dp[j] = (dp[j] + (pos(I[j]) - pos(I[j-1]))*(temp2 + 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'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...