#include <iostream> using namespace std; void Zwieksz(int *A, int *M) { A[0]++; if (A[0] == 2) { A[0] = 0; (*M)++; Zwieksz(A+1, M); } } int main() { const int Ai_MAX = 201718; const int Ai_MAX_M = Ai_MAX + 19; int Ai, n, M; int A[Ai_MAX_M]; for (int i = 0; i < Ai_MAX_M; i++) A[i] = 0; cin >> n; cin >> Ai; A[Ai]++; M = Ai; for (int i = 1; i < n; i++) { cin >> Ai; Zwieksz(A+Ai, &Ai); if (Ai > M) M = Ai; } cout << M << endl; /*for (int i = 0; i < n+19; i++) { cerr << A[i] << " "; } cerr << endl;*/ return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #include <iostream> using namespace std; void Zwieksz(int *A, int *M) { A[0]++; if (A[0] == 2) { A[0] = 0; (*M)++; Zwieksz(A+1, M); } } int main() { const int Ai_MAX = 201718; const int Ai_MAX_M = Ai_MAX + 19; int Ai, n, M; int A[Ai_MAX_M]; for (int i = 0; i < Ai_MAX_M; i++) A[i] = 0; cin >> n; cin >> Ai; A[Ai]++; M = Ai; for (int i = 1; i < n; i++) { cin >> Ai; Zwieksz(A+Ai, &Ai); if (Ai > M) M = Ai; } cout << M << endl; /*for (int i = 0; i < n+19; i++) { cerr << A[i] << " "; } cerr << endl;*/ return 0; } |