-
Notifications
You must be signed in to change notification settings - Fork 0
/
20.cpp
101 lines (75 loc) · 1.89 KB
/
20.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <fstream>
#include <iostream>
#include <fmt/core.h>
#include <fmt/ranges.h>
#include <string>
#include <utility>
#include <vector>
typedef std::pair<long, long> point;
int KEY = 811589153;
void mix(std::vector<point> &data) {
for(int i = 0; i < data.size(); ++i) {
int pos = 0;
for (int y = 0; y < data.size(); ++y) {
if (data[y].first == i) {
pos = y;
break;
}
}
auto x = data[pos];
data.erase(data.begin() + pos);
int shift = std::div(x.second + pos, data.size()).rem;
// std::cout << "shift " << x.first << " " << x.second << " " << shift << std::endl;
if (shift > 0)
data.insert(data.begin() + shift, x);
else
data.insert(data.end() + shift, x);
// for (auto l: data)
// std::cout << l.second << " ";
// std::cout << std::endl;
}
}
void result(std::vector<point> &data) {
int pos = 0;
for(int i =0; i < data.size(); ++i ) {
if (data[i].second == 0) {
pos = i;
break;
}
}
long s =0;
for (int x: {1000, 2000, 3000}){
int z = std::div(x + pos, data.size()).rem;
// std::cout << x << " " << z << ": " << data[z].second << std::endl;
s += data[z].second;
}
std::cout << s << std::endl;
}
int main(int argc, char *argv[]) {
if (argc < 2) {
return 1;
}
std::vector<point> data{};
std::ifstream file(argv[1]);
int cnt = 0;
for (std::string line; std::getline(file, line);) {
if (line.empty()) break;
auto x = std::stoi(line);
data.push_back({cnt++, x});
}
auto f = data;
mix(f);
result(f);
auto s = data;
for (int i=0; i < s.size(); ++i) {
s[i] = {s[i].first, s[i].second * KEY};
}
// for (auto l: data)
// std::cout << l.first << " " << l.second << std::endl;
// for (auto l: s)
// std::cout << l.first << " " << l.second << std::endl;
for (int i=0; i < 10; ++i) {
mix(s);
}
result(s);
}