-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday16.cpp
More file actions
60 lines (48 loc) · 1.07 KB
/
day16.cpp
File metadata and controls
60 lines (48 loc) · 1.07 KB
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
#include <fstream>
#include <iostream>
#define st 5973857
using namespace std;
ifstream fin("aoc.in");
ofstream fout("aoc.out");
char c[1000];
int v[10000000],w[10000000],n,i,j,cnt,x;
int p[]={0,1,0,-1};
int main(){
fin>>c+1;
for(i=1;c[i]!=0;i++)
v[++n]=c[i]-'0';
/// part 1
for(int t=100;t;t--){
for(i=1;i<=n;i++){
cnt=1; x=0;
for(j=1;j<=n;j++,cnt++){
if(cnt==i)
x=(x+1)%4,cnt=0;
w[i]+=v[j]*p[x];
}
}
for(i=1;i<=n;i++)
v[i]=max(w[i],-w[i])%10,w[i]=0;
}
for(i=1;i<=8;i++)
cout<<v[i];
cout<<"\n";
/// part 2
for(i=0;i<10000;i++)
for(j=1;j<=n;j++)
w[i*n+j]=c[j]-'0';
n*=10000;
for(i=st+1;i<=n;i++)
v[i-st]=w[i];
n=n-st;
for(int t=100;t;t--){
cnt=0;
for(i=n;i;i--){
cnt+=v[i];
v[i]=cnt%10;
}
}
for(i=1;i<=8;i++)
cout<<v[i];
return 0;
}