Submission #38029964


Source Code Expand

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

const int Max = 200005;

long long n, a[Max], flip, x[Max], s, t;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	
	cin >> n >> a[0];
	flip = a[0];
	a[0] = 1;
	
	for (int i = 1; i < n; i++) {
		cin >> a[i];
		a[i] *= flip;
		x[i] = i;
		
		if (a[i] > 0)
			s += x[i];
		else
			t += x[i];
	}
	
	if (s > t) 
		x[0] -= s - t;
	else {
		auto dif = t - s;
		for (int i = n - 1; i >= 0; i--) {
			x[i] += dif;
			if (a[i] > 0)
				s += dif;
			else
				t += dif;
			if (s == t) 
				goto print;
		}
		
		s = t = 0;
		for (int i = 0; i < n; i++) {
			x[i] = i;
			if (a[i] > 0)
				s += x[i];
			else
				t += x[i];
		}
		
		for (int i = 0; i < n; i++) {
			x[i] -= dif;
			if (a[i] > 0)
				s -= dif;
			else
				t -= dif;
			if (s == t)
				goto print;
		}
		
		cout << "No" << endl;
		return 0;
	}
	
	print:
	cout << "Yes" << endl;
	for (int i = 0; i < n; i++) 
		cout << x[i] << ' ';
}

Submission Info

Submission Time
Task C - ± Increasing Sequence
User x_x_
Language C++ (GCC 9.2.1)
Score 600
Code Size 1068 Byte
Status AC
Exec Time 38 ms
Memory 6744 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 76
Set Name Test Cases
Sample 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt
All 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 02_small_1_01.txt, 02_small_1_02.txt, 02_small_1_03.txt, 02_small_1_04.txt, 02_small_1_05.txt, 02_small_1_06.txt, 02_small_1_07.txt, 02_small_1_08.txt, 02_small_1_09.txt, 02_small_1_10.txt, 02_small_1_11.txt, 02_small_1_12.txt, 02_small_1_13.txt, 02_small_1_14.txt, 03_small_2_01.txt, 03_small_2_02.txt, 03_small_2_03.txt, 03_small_2_04.txt, 03_small_2_05.txt, 03_small_2_06.txt, 03_small_2_07.txt, 03_small_2_08.txt, 03_small_2_09.txt, 03_small_2_10.txt, 04_small_zero_01.txt, 04_small_zero_02.txt, 04_small_zero_03.txt, 04_small_zero_04.txt, 05_small_bracket_01.txt, 05_small_bracket_02.txt, 05_small_bracket_03.txt, 05_small_bracket_04.txt, 06_max_rand_01.txt, 06_max_rand_02.txt, 06_max_rand_03.txt, 06_max_rand_04.txt, 06_max_rand_05.txt, 06_max_rand_06.txt, 06_max_rand_07.txt, 06_max_rand_08.txt, 06_max_rand_09.txt, 06_max_rand_10.txt, 07_max_zero_01.txt, 07_max_zero_02.txt, 07_max_zero_03.txt, 07_max_zero_04.txt, 07_max_zero_05.txt, 07_max_zero_06.txt, 07_max_zero_07.txt, 07_max_zero_08.txt, 07_max_zero_09.txt, 07_max_zero_10.txt, 08_max_bracket_01.txt, 08_max_bracket_02.txt, 08_max_bracket_03.txt, 08_max_bracket_04.txt, 08_max_bracket_05.txt, 08_max_bracket_06.txt, 08_max_bracket_07.txt, 08_max_bracket_08.txt, 08_max_bracket_09.txt, 08_max_bracket_10.txt, 09_almost_same_01.txt, 09_almost_same_02.txt, 09_almost_same_03.txt, 09_almost_same_04.txt, 09_almost_same_05.txt, 10_handmade_01.txt, 10_handmade_02.txt, 10_handmade_03.txt, 10_handmade_04.txt, 10_handmade_05.txt, 10_handmade_06.txt
Case Name Status Exec Time Memory
01_sample_01.txt AC 6 ms 3492 KiB
01_sample_02.txt AC 2 ms 3580 KiB
01_sample_03.txt AC 2 ms 3564 KiB
02_small_1_01.txt AC 2 ms 3488 KiB
02_small_1_02.txt AC 2 ms 3540 KiB
02_small_1_03.txt AC 2 ms 3520 KiB
02_small_1_04.txt AC 1 ms 3532 KiB
02_small_1_05.txt AC 2 ms 3488 KiB
02_small_1_06.txt AC 2 ms 3520 KiB
02_small_1_07.txt AC 2 ms 3536 KiB
02_small_1_08.txt AC 2 ms 3492 KiB
02_small_1_09.txt AC 3 ms 3488 KiB
02_small_1_10.txt AC 2 ms 3540 KiB
02_small_1_11.txt AC 2 ms 3580 KiB
02_small_1_12.txt AC 2 ms 3504 KiB
02_small_1_13.txt AC 2 ms 3492 KiB
02_small_1_14.txt AC 2 ms 3540 KiB
03_small_2_01.txt AC 2 ms 3492 KiB
03_small_2_02.txt AC 2 ms 3544 KiB
03_small_2_03.txt AC 2 ms 3540 KiB
03_small_2_04.txt AC 2 ms 3512 KiB
03_small_2_05.txt AC 2 ms 3428 KiB
03_small_2_06.txt AC 2 ms 3540 KiB
03_small_2_07.txt AC 2 ms 3544 KiB
03_small_2_08.txt AC 2 ms 3544 KiB
03_small_2_09.txt AC 2 ms 3512 KiB
03_small_2_10.txt AC 3 ms 3424 KiB
04_small_zero_01.txt AC 3 ms 3512 KiB
04_small_zero_02.txt AC 3 ms 3544 KiB
04_small_zero_03.txt AC 2 ms 3576 KiB
04_small_zero_04.txt AC 2 ms 3504 KiB
05_small_bracket_01.txt AC 2 ms 3492 KiB
05_small_bracket_02.txt AC 3 ms 3572 KiB
05_small_bracket_03.txt AC 3 ms 3520 KiB
05_small_bracket_04.txt AC 2 ms 3560 KiB
06_max_rand_01.txt AC 34 ms 6612 KiB
06_max_rand_02.txt AC 34 ms 6620 KiB
06_max_rand_03.txt AC 36 ms 6640 KiB
06_max_rand_04.txt AC 35 ms 6556 KiB
06_max_rand_05.txt AC 35 ms 6548 KiB
06_max_rand_06.txt AC 35 ms 6700 KiB
06_max_rand_07.txt AC 34 ms 6700 KiB
06_max_rand_08.txt AC 33 ms 6612 KiB
06_max_rand_09.txt AC 35 ms 6652 KiB
06_max_rand_10.txt AC 37 ms 6608 KiB
07_max_zero_01.txt AC 35 ms 6636 KiB
07_max_zero_02.txt AC 35 ms 6704 KiB
07_max_zero_03.txt AC 35 ms 6700 KiB
07_max_zero_04.txt AC 38 ms 6660 KiB
07_max_zero_05.txt AC 34 ms 6608 KiB
07_max_zero_06.txt AC 35 ms 6656 KiB
07_max_zero_07.txt AC 35 ms 6664 KiB
07_max_zero_08.txt AC 35 ms 6628 KiB
07_max_zero_09.txt AC 35 ms 6656 KiB
07_max_zero_10.txt AC 38 ms 6700 KiB
08_max_bracket_01.txt AC 27 ms 6612 KiB
08_max_bracket_02.txt AC 22 ms 6628 KiB
08_max_bracket_03.txt AC 21 ms 6628 KiB
08_max_bracket_04.txt AC 25 ms 6608 KiB
08_max_bracket_05.txt AC 24 ms 6640 KiB
08_max_bracket_06.txt AC 22 ms 6624 KiB
08_max_bracket_07.txt AC 21 ms 6700 KiB
08_max_bracket_08.txt AC 22 ms 6624 KiB
08_max_bracket_09.txt AC 24 ms 6660 KiB
08_max_bracket_10.txt AC 20 ms 6656 KiB
09_almost_same_01.txt AC 34 ms 6664 KiB
09_almost_same_02.txt AC 33 ms 6660 KiB
09_almost_same_03.txt AC 33 ms 6644 KiB
09_almost_same_04.txt AC 34 ms 6668 KiB
09_almost_same_05.txt AC 32 ms 6552 KiB
10_handmade_01.txt AC 33 ms 6700 KiB
10_handmade_02.txt AC 34 ms 6744 KiB
10_handmade_03.txt AC 23 ms 6604 KiB
10_handmade_04.txt AC 17 ms 6612 KiB
10_handmade_05.txt AC 22 ms 6628 KiB
10_handmade_06.txt AC 18 ms 6608 KiB