Submission #838673

# Submission time Handle Problem Language Result Execution time Memory
838673 2023-08-27T14:44:37 Z tch1cherin Gap (APIO16_gap) C++17
100 / 100
46 ms 3060 KB
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;

long long findGap(int T, int N) {
  if (T == 1) {
		long long Min = -1, Max = 1e18l + 1;
		vector<long long> front, back;
		for (int i = 0; i < (N + 1) / 2; i++) {
			MinMax(Min + 1, Max - 1, &Min, &Max);
			if (Min != Max) {
				front.push_back(Min);
			}
			back.push_back(Max);
		}
		reverse(back.begin(), back.end());
		vector<long long> A;
		for (auto v : front) {
			A.push_back(v);
		}
		for (auto v : back) {
			A.push_back(v);
		}
		long long gap = 0;
		for (int i = 0; i < N - 1; i++) {
			gap = max(gap, A[i + 1] - A[i]);
		}
		return gap;
  } else {
    long long x, y;
    MinMax(0, 1e18, &x, &y);
    long long size = (y - x - 1) / (N - 1) + 1;
    long long left = x + 1;
    long long gap = 0, max_pos = x;
    while (left < y) {
      long long right = min(y - 1, left + size - 1);
      long long Min, Max;
      MinMax(left, right, &Min, &Max);
      if (Min != -1) {
        gap = max(gap, Min - max_pos);
        max_pos = Max; 
      }
      left += size;
    }
    return max(gap, y - max_pos);
  }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 368 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 10 ms 1168 KB Output is correct
17 Correct 9 ms 1168 KB Output is correct
18 Correct 9 ms 1148 KB Output is correct
19 Correct 7 ms 1168 KB Output is correct
20 Correct 6 ms 1104 KB Output is correct
21 Correct 29 ms 3052 KB Output is correct
22 Correct 29 ms 2920 KB Output is correct
23 Correct 36 ms 3008 KB Output is correct
24 Correct 29 ms 3004 KB Output is correct
25 Correct 32 ms 2992 KB Output is correct
26 Correct 29 ms 3060 KB Output is correct
27 Correct 29 ms 2924 KB Output is correct
28 Correct 31 ms 3052 KB Output is correct
29 Correct 30 ms 3060 KB Output is correct
30 Correct 24 ms 2968 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 10 ms 464 KB Output is correct
17 Correct 10 ms 520 KB Output is correct
18 Correct 10 ms 464 KB Output is correct
19 Correct 10 ms 464 KB Output is correct
20 Correct 5 ms 464 KB Output is correct
21 Correct 40 ms 1084 KB Output is correct
22 Correct 39 ms 1104 KB Output is correct
23 Correct 40 ms 1080 KB Output is correct
24 Correct 40 ms 976 KB Output is correct
25 Correct 38 ms 1088 KB Output is correct
26 Correct 42 ms 1060 KB Output is correct
27 Correct 39 ms 992 KB Output is correct
28 Correct 39 ms 1080 KB Output is correct
29 Correct 46 ms 1080 KB Output is correct
30 Correct 22 ms 1104 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct