# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
495644 | 2021-12-19T17:27:52 Z | Amer | Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) | C++14 | 3000 ms | 81040 KB |
#include <iostream> #include<map> #include<vector> #include<queue> #include<stack> using namespace std; class mem { public: int maxCombination = 0; int maxNumber = 0; int lastIndex = 0; }; struct CompareMem { bool operator()(mem const& a, mem const& b) { // return "true" if "p1" is ordered // before "p2", for example: return a.lastIndex > b.lastIndex; } }; const int maxN = 1000005; int arr[maxN]; map<int, priority_queue<mem, vector<mem>, CompareMem>> memorisation; int solve(int start, int finish, int mood) { bool possible = true; mem now; now.lastIndex = finish; now.maxNumber = arr[start - 1]; now.maxCombination = 0; for (int i = start; i < finish; i++) { stack<mem> temp; if (memorisation[i].size() != 0) { for (int j = 0; j < memorisation[i].size(); j++) { if (memorisation[i].top().lastIndex < finish) { if (memorisation[i].top().maxCombination > mood) { return false; } } else { break; } temp.push(memorisation[i].top()); memorisation[i].pop(); } while (!temp.empty()) { memorisation[i].push(temp.top()); temp.pop(); } } if (now.maxNumber > arr[i]) { if (arr[i] + now.maxNumber > mood) { possible = false; } if (arr[i] + now.maxNumber > now.maxCombination) { now.maxCombination = arr[i] + now.maxNumber; } } else { now.maxNumber = arr[i]; } } memorisation[start].push(now); return possible; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int i = 0; i < m; i++) { int start, finish, mood; cin >> start >> finish >> mood; cout << solve(start, finish, mood)<<endl; } } /* 5 2 3 5 1 8 2 1 3 6 2 5 3 */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 308 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 2 ms | 332 KB | Output is correct |
7 | Correct | 2 ms | 332 KB | Output is correct |
8 | Correct | 9 ms | 332 KB | Output is correct |
9 | Correct | 4 ms | 332 KB | Output is correct |
10 | Correct | 4 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 308 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 2 ms | 332 KB | Output is correct |
7 | Correct | 2 ms | 332 KB | Output is correct |
8 | Correct | 9 ms | 332 KB | Output is correct |
9 | Correct | 4 ms | 332 KB | Output is correct |
10 | Correct | 4 ms | 332 KB | Output is correct |
11 | Correct | 11 ms | 460 KB | Output is correct |
12 | Correct | 26 ms | 740 KB | Output is correct |
13 | Correct | 24 ms | 720 KB | Output is correct |
14 | Correct | 28 ms | 744 KB | Output is correct |
15 | Correct | 39 ms | 744 KB | Output is correct |
16 | Correct | 970 ms | 740 KB | Output is correct |
17 | Correct | 435 ms | 688 KB | Output is correct |
18 | Correct | 279 ms | 708 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3077 ms | 81040 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3049 ms | 8664 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 308 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 2 ms | 332 KB | Output is correct |
7 | Correct | 2 ms | 332 KB | Output is correct |
8 | Correct | 9 ms | 332 KB | Output is correct |
9 | Correct | 4 ms | 332 KB | Output is correct |
10 | Correct | 4 ms | 332 KB | Output is correct |
11 | Correct | 11 ms | 460 KB | Output is correct |
12 | Correct | 26 ms | 740 KB | Output is correct |
13 | Correct | 24 ms | 720 KB | Output is correct |
14 | Correct | 28 ms | 744 KB | Output is correct |
15 | Correct | 39 ms | 744 KB | Output is correct |
16 | Correct | 970 ms | 740 KB | Output is correct |
17 | Correct | 435 ms | 688 KB | Output is correct |
18 | Correct | 279 ms | 708 KB | Output is correct |
19 | Execution timed out | 3079 ms | 16700 KB | Time limit exceeded |
20 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 308 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 2 ms | 332 KB | Output is correct |
7 | Correct | 2 ms | 332 KB | Output is correct |
8 | Correct | 9 ms | 332 KB | Output is correct |
9 | Correct | 4 ms | 332 KB | Output is correct |
10 | Correct | 4 ms | 332 KB | Output is correct |
11 | Correct | 11 ms | 460 KB | Output is correct |
12 | Correct | 26 ms | 740 KB | Output is correct |
13 | Correct | 24 ms | 720 KB | Output is correct |
14 | Correct | 28 ms | 744 KB | Output is correct |
15 | Correct | 39 ms | 744 KB | Output is correct |
16 | Correct | 970 ms | 740 KB | Output is correct |
17 | Correct | 435 ms | 688 KB | Output is correct |
18 | Correct | 279 ms | 708 KB | Output is correct |
19 | Execution timed out | 3077 ms | 81040 KB | Time limit exceeded |
20 | Halted | 0 ms | 0 KB | - |