#include<iostream> #include<vector> #define REP(i, n) for(int i=0; i<(n); i++) using namespace std; int main(void) { vector<char> ww; ww.resize(202000); int n, a, b=0; cin >> n; REP(i, n) { cin >> a; while(ww[a]) { ww[a] = 0; a++; } ww[a] = 1; if (a >= b) { b = a; } } cout << b; 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 | #include<iostream> #include<vector> #define REP(i, n) for(int i=0; i<(n); i++) using namespace std; int main(void) { vector<char> ww; ww.resize(202000); int n, a, b=0; cin >> n; REP(i, n) { cin >> a; while(ww[a]) { ww[a] = 0; a++; } ww[a] = 1; if (a >= b) { b = a; } } cout << b; return 0; } |