-
Notifications
You must be signed in to change notification settings - Fork 0
/
part1.cpp
64 lines (58 loc) · 1.68 KB
/
part1.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "Day20.hpp"
#include <vector>
#include <iostream>
#include <sstream>
#include <limits>
#include <cstring>
// leaderboard, rank 106
/*
Command being timed: "./bin/Release/aoc2016 --day 20 --inputset puzzle1 --part 1"
User time (seconds): 4.04
System time (seconds): 0.85
Percent of CPU this job got: 99%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:04.90
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 4200344
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 1048942
Voluntary context switches: 1
Involuntary context switches: 10
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
*/
Result Day20::solve_p1(){
unsigned length = std::numeric_limits<unsigned int>::max();
bool *ips = new bool[length];
// original (leaderboard) solution had a loop instead of memset()
memset(ips, true, sizeof(bool) * length);
// iterate over input lines
for(string line: this->data){
unsigned start, end;
// ch eats the '-'
char ch;
stringstream stream(line);
stream >> start >> ch >> end;
for(unsigned ii = start; ii <= end && ii < length; ++ii){
ips[ii] = false;
}
}
// END iterate over input lines
for(unsigned ii = 0; ii < length; ++ii){
if( ips[ii] ){
delete ips;
return {true, to_string(ii)};
}
}
delete ips;
return {false, "No valid IP found!"};
}