Last active
March 8, 2017 07:46
SRM 513 Div1 Level1 - YetAnotherIncredibleMachine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
class YetAnotherIncredibleMachine { | |
public: | |
int countWays(vector<int> platformMount, vector<int> platformLength, vector<int> balls) { | |
balls.push_back(-100000); | |
balls.push_back(100000); | |
sort(balls.begin(), balls.end()); | |
int ret = 1; | |
for (int i = 0; i + 1 < balls.size(); ++i) { | |
int st = balls[i], ed = balls[i + 1]; | |
for (int j = 0; j < platformMount.size(); ++j) { | |
if (platformMount[j] < st || platformMount[j] > ed) { | |
continue; | |
} | |
int mst = max(st + 1, platformMount[j] - platformLength[j]); | |
int med = min(ed - 1, platformMount[j] + platformLength[j]); | |
int val = max(0, med - mst - platformLength[j] + 1); | |
ret = (long long)ret * val % 1000000009; | |
} | |
} | |
return ret; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment