Submission #36231285


Source Code Expand

#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
typedef long long ll;
using namespace std;
const int maxn = 1005;
int n, a[maxn], b[maxn], c[maxn];

int main() {
#ifdef DEBUG
	freopen("1.in", "r", stdin);
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		while(a[i] % 2 == 0) {
			a[i] /= 2;
			b[i]++;
		}
		while(a[i] % 3 == 0) {
			a[i] /= 3;
			c[i]++;
		}
	}
	for(int i = 2; i <= n; i++) {
		if(a[i] != a[i - 1]) {
			cout << "-1\n";
			return 0;
		}
	}
	int m1 = *min_element(b + 1, b + 1 + n);
	int m2 = *min_element(c + 1, c + 1 + n);
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		ans += b[i] - m1 + c[i] - m2;
	}
	cout << ans << '\n';
	return 0;
}

Submission Info

Submission Time
Task D - Divide by 2 or 3
User yanchengzhi
Language C++ (GCC 9.2.1)
Score 400
Code Size 835 Byte
Status AC
Exec Time 6 ms
Memory 3652 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 41
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_srnd0_00.txt, 01_srnd0_01.txt, 01_srnd0_02.txt, 02_srnd1_00.txt, 02_srnd1_01.txt, 02_srnd1_02.txt, 02_srnd1_03.txt, 02_srnd1_04.txt, 02_srnd1_05.txt, 02_srnd1_06.txt, 02_srnd1_07.txt, 02_srnd1_08.txt, 02_srnd1_09.txt, 03_rnd0_00.txt, 03_rnd0_01.txt, 03_rnd0_02.txt, 04_rnd1_00.txt, 04_rnd1_01.txt, 04_rnd1_02.txt, 04_rnd1_03.txt, 04_rnd1_04.txt, 04_rnd1_05.txt, 04_rnd1_06.txt, 04_rnd1_07.txt, 04_rnd1_08.txt, 04_rnd1_09.txt, 05_same_00.txt, 05_same_01.txt, 05_same_02.txt, 05_same_03.txt, 05_same_04.txt, 05_same_05.txt, 06_max_00.txt, 06_max_01.txt, 07_ng_00.txt, 07_ng_01.txt, 07_ng_02.txt, 07_ng_03.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 6 ms 3532 KiB
00_sample_01.txt AC 2 ms 3496 KiB
00_sample_02.txt AC 2 ms 3504 KiB
01_srnd0_00.txt AC 2 ms 3524 KiB
01_srnd0_01.txt AC 2 ms 3508 KiB
01_srnd0_02.txt AC 2 ms 3528 KiB
02_srnd1_00.txt AC 2 ms 3544 KiB
02_srnd1_01.txt AC 2 ms 3572 KiB
02_srnd1_02.txt AC 2 ms 3584 KiB
02_srnd1_03.txt AC 2 ms 3508 KiB
02_srnd1_04.txt AC 2 ms 3612 KiB
02_srnd1_05.txt AC 2 ms 3504 KiB
02_srnd1_06.txt AC 2 ms 3548 KiB
02_srnd1_07.txt AC 2 ms 3528 KiB
02_srnd1_08.txt AC 2 ms 3548 KiB
02_srnd1_09.txt AC 2 ms 3572 KiB
03_rnd0_00.txt AC 2 ms 3532 KiB
03_rnd0_01.txt AC 2 ms 3552 KiB
03_rnd0_02.txt AC 2 ms 3552 KiB
04_rnd1_00.txt AC 2 ms 3556 KiB
04_rnd1_01.txt AC 2 ms 3652 KiB
04_rnd1_02.txt AC 2 ms 3556 KiB
04_rnd1_03.txt AC 2 ms 3556 KiB
04_rnd1_04.txt AC 2 ms 3556 KiB
04_rnd1_05.txt AC 2 ms 3532 KiB
04_rnd1_06.txt AC 2 ms 3536 KiB
04_rnd1_07.txt AC 3 ms 3536 KiB
04_rnd1_08.txt AC 2 ms 3580 KiB
04_rnd1_09.txt AC 2 ms 3536 KiB
05_same_00.txt AC 2 ms 3508 KiB
05_same_01.txt AC 3 ms 3580 KiB
05_same_02.txt AC 2 ms 3552 KiB
05_same_03.txt AC 2 ms 3568 KiB
05_same_04.txt AC 2 ms 3556 KiB
05_same_05.txt AC 4 ms 3580 KiB
06_max_00.txt AC 2 ms 3552 KiB
06_max_01.txt AC 2 ms 3580 KiB
07_ng_00.txt AC 2 ms 3508 KiB
07_ng_01.txt AC 2 ms 3556 KiB
07_ng_02.txt AC 2 ms 3532 KiB
07_ng_03.txt AC 2 ms 3580 KiB