Submission #845968


Source Code Expand

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

using namespace std;

int main() {
	long long int n;
	cin >> n;
	vector<long long int> a(n, 0);
	for (long long int i = 0; i < n; i++) {
		cin >> a[i];
	}
	long long int c = 0;
	vector<long long int> b(n, 0);
	for (long long int i = 0; i < n; i++) {
		if (a[i] % 2 == 0 && a[i] >= 2) {
			c += (a[i]-2)/2;
			a[i] = 2;
		} else if (a[i] % 2 == 1) {
			c += a[i]/2;
			a[i] = 1;
		}
		b[i] = a[i];
	}
	long long int aa = 0;
	long long int bb = 0;
	for (long long int i = 0; i < n-1; i++) {
		if (a[i] == 2) {
			a[i] = 0;
			aa++;
		} else if (a[i] == 1 && a[i+1] >= 1) {
			aa++;
			a[i] = 0;
			a[i+1]--;
		}
	}
	if (a[n-1] == 2) {
		aa++;
	}
	for (long long int i = n-1; i > 0; i--) {
		if (b[i] == 2) {
			b[i] = 0;
			bb++;
		} else if (b[i] == 1 && b[i-1] >= 1) {
			bb++;
			b[i] = 0;
			b[i-1]--;
		}
	}
	if (b[0] == 2) {
		bb++;
	}
	cout << c+max(aa, bb) << endl;
	return 0;
}

Submission Info

Submission Time
Task B - Simplified mahjong
User scor
Language C++14 (GCC 5.4.1)
Score 400
Code Size 995 Byte
Status AC
Exec Time 84 ms
Memory 1792 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 24
Set Name Test Cases
Sample s1.txt, s2.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt AC 78 ms 1792 KB
02.txt AC 79 ms 1792 KB
03.txt AC 78 ms 1792 KB
04.txt AC 58 ms 1792 KB
05.txt AC 58 ms 1792 KB
06.txt AC 59 ms 1792 KB
07.txt AC 71 ms 1792 KB
08.txt AC 75 ms 1792 KB
09.txt AC 79 ms 1792 KB
10.txt AC 82 ms 1792 KB
11.txt AC 39 ms 1792 KB
12.txt AC 84 ms 1792 KB
13.txt AC 79 ms 1792 KB
14.txt AC 82 ms 1792 KB
15.txt AC 36 ms 1792 KB
16.txt AC 84 ms 1792 KB
17.txt AC 80 ms 1792 KB
18.txt AC 4 ms 256 KB
19.txt AC 4 ms 256 KB
20.txt AC 4 ms 256 KB
21.txt AC 4 ms 256 KB
22.txt AC 4 ms 256 KB
s1.txt AC 4 ms 256 KB
s2.txt AC 4 ms 256 KB