Submission #29160101


Source Code Expand

#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define pb push_back
#define mp make_pair

int n;
priority_queue<int> q0;
priority_queue<int, vector<int>, greater<int>> q1; 
ll ans;

int main() {
	scanf("%d", &n);
	for (int i = 1, t, d, x; i <= n; i++) {
		scanf("%d%d%d", &t, &d, &x);
		if (d == 0) {
			if (x > t) ans += x - t, x = t;
			if (q1.empty() || x <= q1.top() + t) q0.push(x + t);
			else {
				int y = q1.top() + t;
				ans += x - y;
				q0.push(y + t);
				q1.pop(); q1.push(x - t);
			}
		} else {
			if (x < -t) ans += -t - x, x = -t;
			if (q0.empty() || x >= q0.top() - t) q1.push(x - t);
			else {
				int y = q0.top() - t;
				ans += y - x;
				q1.push(y - t);
				q0.pop(); q0.push(x + t);
			} 
		}
	}
	printf("%lld\n", ans);;
	return 0;
}

Submission Info

Submission Time
Task H - Snuketoon
User Flying_Bird
Language C++ (GCC 9.2.1)
Score 600
Code Size 874 Byte
Status AC
Exec Time 70 ms
Memory 4160 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:18:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   18 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
./Main.cpp:20:8: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   20 |   scanf("%d%d%d", &t, &d, &x);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 119
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_n_small_x_small_00.txt, 01_n_small_x_small_01.txt, 01_n_small_x_small_02.txt, 01_n_small_x_small_03.txt, 01_n_small_x_small_04.txt, 01_n_small_x_small_05.txt, 01_n_small_x_small_06.txt, 01_n_small_x_small_07.txt, 01_n_small_x_small_08.txt, 01_n_small_x_small_09.txt, 01_n_small_x_small_10.txt, 01_n_small_x_small_11.txt, 01_n_small_x_small_12.txt, 01_n_small_x_small_13.txt, 01_n_small_x_small_14.txt, 01_n_small_x_small_15.txt, 01_n_small_x_small_16.txt, 01_n_small_x_small_17.txt, 01_n_small_x_small_18.txt, 01_n_small_x_small_19.txt, 02_n_small_x_small_random_00.txt, 02_n_small_x_small_random_01.txt, 02_n_small_x_small_random_02.txt, 02_n_small_x_small_random_03.txt, 02_n_small_x_small_random_04.txt, 02_n_small_x_small_random_05.txt, 02_n_small_x_small_random_06.txt, 02_n_small_x_small_random_07.txt, 02_n_small_x_small_random_08.txt, 02_n_small_x_small_random_09.txt, 02_n_small_x_small_random_10.txt, 02_n_small_x_small_random_11.txt, 02_n_small_x_small_random_12.txt, 02_n_small_x_small_random_13.txt, 02_n_small_x_small_random_14.txt, 02_n_small_x_small_random_15.txt, 02_n_small_x_small_random_16.txt, 02_n_small_x_small_random_17.txt, 02_n_small_x_small_random_18.txt, 02_n_small_x_small_random_19.txt, 03_n_small_00.txt, 03_n_small_01.txt, 03_n_small_02.txt, 03_n_small_03.txt, 03_n_small_04.txt, 03_n_small_05.txt, 03_n_small_06.txt, 03_n_small_07.txt, 03_n_small_08.txt, 03_n_small_09.txt, 04_x_small_random_00.txt, 04_x_small_random_01.txt, 04_x_small_random_02.txt, 04_x_small_random_03.txt, 04_x_small_random_04.txt, 04_x_small_random_05.txt, 04_x_small_random_06.txt, 04_x_small_random_07.txt, 04_x_small_random_08.txt, 04_x_small_random_09.txt, 04_x_small_random_10.txt, 04_x_small_random_11.txt, 04_x_small_random_12.txt, 04_x_small_random_13.txt, 04_x_small_random_14.txt, 04_x_small_random_15.txt, 04_x_small_random_16.txt, 04_x_small_random_17.txt, 04_x_small_random_18.txt, 04_x_small_random_19.txt, 05_max_random_00.txt, 05_max_random_01.txt, 05_max_random_02.txt, 05_max_random_03.txt, 05_max_random_04.txt, 05_max_random_05.txt, 05_max_random_06.txt, 05_max_random_07.txt, 05_max_random_08.txt, 05_max_random_09.txt, 06_d_eq_0_00.txt, 06_d_eq_0_01.txt, 07_d_eq_0_with_noise_00.txt, 07_d_eq_0_with_noise_01.txt, 08_d_eq_1_00.txt, 08_d_eq_1_01.txt, 09_d_eq_1_with_noise_00.txt, 09_d_eq_1_with_noise_01.txt, 10_go_back_and_forth_00.txt, 10_go_back_and_forth_01.txt, 10_go_back_and_forth_02.txt, 10_go_back_and_forth_03.txt, 11_go_back_and_forth_with_noise_00.txt, 11_go_back_and_forth_with_noise_01.txt, 11_go_back_and_forth_with_noise_02.txt, 11_go_back_and_forth_with_noise_03.txt, 12_greedy_hack_00.txt, 12_greedy_hack_01.txt, 12_greedy_hack_02.txt, 12_greedy_hack_03.txt, 13_greedy_hack_with_noise_00.txt, 13_greedy_hack_with_noise_01.txt, 13_greedy_hack_with_noise_02.txt, 13_greedy_hack_with_noise_03.txt, 14_greedy_hack_with_noise_t_small_00.txt, 14_greedy_hack_with_noise_t_small_01.txt, 14_greedy_hack_with_noise_t_small_02.txt, 14_greedy_hack_with_noise_t_small_03.txt, 15_hack_wrong_init_00.txt, 15_hack_wrong_init_01.txt, 15_hack_wrong_init_02.txt, 15_hack_wrong_init_03.txt, 15_hack_wrong_init_04.txt, 15_hack_wrong_init_05.txt, 15_hack_wrong_init_06.txt, 15_hack_wrong_init_07.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 8 ms 3144 KiB
00_sample_01.txt AC 2 ms 3148 KiB
00_sample_02.txt AC 2 ms 3100 KiB
01_n_small_x_small_00.txt AC 5 ms 3148 KiB
01_n_small_x_small_01.txt AC 5 ms 3204 KiB
01_n_small_x_small_02.txt AC 5 ms 3116 KiB
01_n_small_x_small_03.txt AC 4 ms 3196 KiB
01_n_small_x_small_04.txt AC 7 ms 3184 KiB
01_n_small_x_small_05.txt AC 6 ms 3104 KiB
01_n_small_x_small_06.txt AC 5 ms 3152 KiB
01_n_small_x_small_07.txt AC 2 ms 3108 KiB
01_n_small_x_small_08.txt AC 5 ms 3196 KiB
01_n_small_x_small_09.txt AC 5 ms 3200 KiB
01_n_small_x_small_10.txt AC 6 ms 3112 KiB
01_n_small_x_small_11.txt AC 6 ms 3172 KiB
01_n_small_x_small_12.txt AC 4 ms 3244 KiB
01_n_small_x_small_13.txt AC 5 ms 3180 KiB
01_n_small_x_small_14.txt AC 5 ms 3200 KiB
01_n_small_x_small_15.txt AC 4 ms 3140 KiB
01_n_small_x_small_16.txt AC 7 ms 3136 KiB
01_n_small_x_small_17.txt AC 5 ms 3232 KiB
01_n_small_x_small_18.txt AC 2 ms 3152 KiB
01_n_small_x_small_19.txt AC 6 ms 3196 KiB
02_n_small_x_small_random_00.txt AC 4 ms 3188 KiB
02_n_small_x_small_random_01.txt AC 4 ms 3096 KiB
02_n_small_x_small_random_02.txt AC 5 ms 3152 KiB
02_n_small_x_small_random_03.txt AC 6 ms 3104 KiB
02_n_small_x_small_random_04.txt AC 5 ms 3152 KiB
02_n_small_x_small_random_05.txt AC 5 ms 3180 KiB
02_n_small_x_small_random_06.txt AC 5 ms 3124 KiB
02_n_small_x_small_random_07.txt AC 4 ms 3112 KiB
02_n_small_x_small_random_08.txt AC 5 ms 3248 KiB
02_n_small_x_small_random_09.txt AC 5 ms 3152 KiB
02_n_small_x_small_random_10.txt AC 8 ms 3136 KiB
02_n_small_x_small_random_11.txt AC 4 ms 3104 KiB
02_n_small_x_small_random_12.txt AC 5 ms 3148 KiB
02_n_small_x_small_random_13.txt AC 5 ms 3204 KiB
02_n_small_x_small_random_14.txt AC 6 ms 3176 KiB
02_n_small_x_small_random_15.txt AC 7 ms 3200 KiB
02_n_small_x_small_random_16.txt AC 7 ms 3184 KiB
02_n_small_x_small_random_17.txt AC 8 ms 3244 KiB
02_n_small_x_small_random_18.txt AC 6 ms 3176 KiB
02_n_small_x_small_random_19.txt AC 5 ms 3104 KiB
03_n_small_00.txt AC 5 ms 3180 KiB
03_n_small_01.txt AC 5 ms 3196 KiB
03_n_small_02.txt AC 7 ms 3180 KiB
03_n_small_03.txt AC 4 ms 3196 KiB
03_n_small_04.txt AC 6 ms 3176 KiB
03_n_small_05.txt AC 3 ms 3148 KiB
03_n_small_06.txt AC 6 ms 3176 KiB
03_n_small_07.txt AC 5 ms 3100 KiB
03_n_small_08.txt AC 5 ms 3136 KiB
03_n_small_09.txt AC 4 ms 3212 KiB
04_x_small_random_00.txt AC 57 ms 3760 KiB
04_x_small_random_01.txt AC 51 ms 3744 KiB
04_x_small_random_02.txt AC 51 ms 3696 KiB
04_x_small_random_03.txt AC 53 ms 3832 KiB
04_x_small_random_04.txt AC 54 ms 3676 KiB
04_x_small_random_05.txt AC 54 ms 3700 KiB
04_x_small_random_06.txt AC 54 ms 3748 KiB
04_x_small_random_07.txt AC 59 ms 3668 KiB
04_x_small_random_08.txt AC 58 ms 3728 KiB
04_x_small_random_09.txt AC 60 ms 3696 KiB
04_x_small_random_10.txt AC 62 ms 3680 KiB
04_x_small_random_11.txt AC 62 ms 3752 KiB
04_x_small_random_12.txt AC 62 ms 3672 KiB
04_x_small_random_13.txt AC 63 ms 3692 KiB
04_x_small_random_14.txt AC 65 ms 3680 KiB
04_x_small_random_15.txt AC 64 ms 3744 KiB
04_x_small_random_16.txt AC 65 ms 3680 KiB
04_x_small_random_17.txt AC 66 ms 3672 KiB
04_x_small_random_18.txt AC 66 ms 3728 KiB
04_x_small_random_19.txt AC 66 ms 3692 KiB
05_max_random_00.txt AC 68 ms 3660 KiB
05_max_random_01.txt AC 69 ms 3680 KiB
05_max_random_02.txt AC 68 ms 3692 KiB
05_max_random_03.txt AC 67 ms 3700 KiB
05_max_random_04.txt AC 68 ms 3756 KiB
05_max_random_05.txt AC 66 ms 3672 KiB
05_max_random_06.txt AC 66 ms 3672 KiB
05_max_random_07.txt AC 67 ms 3592 KiB
05_max_random_08.txt AC 70 ms 3684 KiB
05_max_random_09.txt AC 69 ms 3756 KiB
06_d_eq_0_00.txt AC 57 ms 3688 KiB
06_d_eq_0_01.txt AC 58 ms 3752 KiB
07_d_eq_0_with_noise_00.txt AC 61 ms 3700 KiB
07_d_eq_0_with_noise_01.txt AC 61 ms 3760 KiB
08_d_eq_1_00.txt AC 57 ms 3752 KiB
08_d_eq_1_01.txt AC 60 ms 3744 KiB
09_d_eq_1_with_noise_00.txt AC 61 ms 3728 KiB
09_d_eq_1_with_noise_01.txt AC 61 ms 3724 KiB
10_go_back_and_forth_00.txt AC 58 ms 3752 KiB
10_go_back_and_forth_01.txt AC 58 ms 3612 KiB
10_go_back_and_forth_02.txt AC 59 ms 3660 KiB
10_go_back_and_forth_03.txt AC 58 ms 3616 KiB
11_go_back_and_forth_with_noise_00.txt AC 57 ms 3736 KiB
11_go_back_and_forth_with_noise_01.txt AC 56 ms 3692 KiB
11_go_back_and_forth_with_noise_02.txt AC 57 ms 3696 KiB
11_go_back_and_forth_with_noise_03.txt AC 58 ms 3700 KiB
12_greedy_hack_00.txt AC 61 ms 3968 KiB
12_greedy_hack_01.txt AC 61 ms 3964 KiB
12_greedy_hack_02.txt AC 65 ms 3996 KiB
12_greedy_hack_03.txt AC 62 ms 3884 KiB
13_greedy_hack_with_noise_00.txt AC 63 ms 4160 KiB
13_greedy_hack_with_noise_01.txt AC 63 ms 3752 KiB
13_greedy_hack_with_noise_02.txt AC 62 ms 4052 KiB
13_greedy_hack_with_noise_03.txt AC 62 ms 3672 KiB
14_greedy_hack_with_noise_t_small_00.txt AC 62 ms 3668 KiB
14_greedy_hack_with_noise_t_small_01.txt AC 63 ms 4100 KiB
14_greedy_hack_with_noise_t_small_02.txt AC 70 ms 3644 KiB
14_greedy_hack_with_noise_t_small_03.txt AC 61 ms 4124 KiB
15_hack_wrong_init_00.txt AC 55 ms 3760 KiB
15_hack_wrong_init_01.txt AC 55 ms 3688 KiB
15_hack_wrong_init_02.txt AC 54 ms 3748 KiB
15_hack_wrong_init_03.txt AC 56 ms 3744 KiB
15_hack_wrong_init_04.txt AC 56 ms 3684 KiB
15_hack_wrong_init_05.txt AC 55 ms 3612 KiB
15_hack_wrong_init_06.txt AC 56 ms 3672 KiB
15_hack_wrong_init_07.txt AC 57 ms 3724 KiB