Submission #340157

#TimeUsernameProblemLanguageResultExecution timeMemory
340157blueBoat (APIO16_boat)C++11
0 / 100
3 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 maintain a long range partitioned by points 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] */ int mod = 1e9 + 7; int a[501], b[501]; int pos(int i) //upper acceptable limit of range { if(i > 0) return a[i] - 1; else return b[-i]; } int main() { int N; cin >> N; for(int i = 1; i <= N; i++) cin >> a[i] >> b[i]; int I[2*N]; for(int i = 0; i < N; i++) { I[i] = i+1; I[i+N] = -i-1; } sort(I, I+2*N, [] (int x, int y) { return pos(x) < pos(y); }); int dp[2*N]; //number of streams in between I[i-1] and I[i]. for(int i = 0; i < 2*N; i++) dp[i] = 0; int temp = 0; int temp2; for(int i = 1; i <= N; i++) { // cout << "i = " << i << '\n'; temp = 0; for(int j = 1; j < 2*N; j++) { if(pos(I[j]) <= pos(i)) temp += dp[j]; else if(pos(I[j]) <= pos(-i)) { temp2 = temp; temp += dp[j]; dp[j] += (pos(I[j]) - pos(I[j-1])) * (temp2 + 1); } } // for(int j = 0; j < 2*N; j++) // { // cout << j << ' ' << I[j] << ' ' << pos(I[j]) << ' ' << dp[j] << '\n'; // } // cout << "_________________________\n"; } int res = 0; for(int j = 0; j < 2*N; j++) res += dp[j]; 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...