-
Notifications
You must be signed in to change notification settings - Fork 0
/
0041_First_Missing_Positive.cpp
42 lines (40 loc) · 1.15 KB
/
0041_First_Missing_Positive.cpp
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
#pragma GCC optimize("Ofast","inline","ffast-math","unroll-loops","no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native","f16c")
int speedUp = []
{std::ios::sync_with_stdio(0); std::cin.tie(0); return 0; }();
bool has[100002];
int digit(char c)
{
return c & 15;
}
bool isDigit(char c)
{
return '0' <= c && c <= '9';
}
int init = [] {
std::ofstream out("user.out");
std::cout.rdbuf(out.rdbuf());
for (string s; std::getline(std::cin, s); std::cout << '\n') {
int n = count(s.begin(), s.end(), ',') + 3;
memset(has, 0, n);
for (int _i = 1, _n = s.length(); _i < _n; ++_i) {
if (s[_i] == '-')for (_i += 2; isDigit(s[_i]); ++_i);
else {
int v = s[_i++] & 15;
while (isDigit(s[_i])) v = v * 10 + digit(s[_i++]);
if (0 < v && v < n) has[v] = true;
}
}
for (int i = 1;; ++i)
if (!has[i]) {
std::cout << i;
break;
}
}
exit(0);
return 0;
}();
class Solution {
public:
int firstMissingPositive(vector<int>) { return 0; }
};