Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Advent of Code 2024
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Regler
Advent of Code 2024
Commits
76c02c54
Commit
76c02c54
authored
6 months ago
by
Max Nilsson
Browse files
Options
Downloads
Patches
Plain Diff
day 15 max n
parent
09f0901c
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
day 15/day_15_max_n.cpp
+143
-0
143 additions, 0 deletions
day 15/day_15_max_n.cpp
with
143 additions
and
0 deletions
day 15/day_15_max_n.cpp
0 → 100644
+
143
−
0
View file @
76c02c54
#include
<bits/stdc++.h>
#ifdef LOCAL
#include
"./cpp-dump/cpp-dump.hpp"
#define pr(x) cpp_dump(x)
#endif
using
namespace
std
;
#define Mod(x,y) (((x)%(y)+(y))%(y))
#define rep(i, a, b) for(ll (i) = (a); (i) < (b); ++(i))
#define all(x) begin(x), end(x)
#define pb push_back
#define gcd __gcd
#define sz(x) (ll)(x.size())
typedef
long
long
ll
;
typedef
unsigned
long
long
ull
;
typedef
pair
<
ll
,
ll
>
pii
;
typedef
vector
<
ll
>
vi
;
typedef
vector
<
pii
>
vii
;
const
bool
debug
=
false
;
vector
<
string
>
mat
;
int
n
,
m
;
pii
push_hor
(
pii
s
,
pii
ds
)
{
int
i
=
s
.
first
,
j
=
s
.
second
,
di
=
ds
.
first
,
dj
=
ds
.
second
;
int
ni
=
i
+
di
,
nj
=
j
+
dj
;
if
(
mat
[
ni
][
nj
]
==
'#'
)
return
s
;
if
(
mat
[
ni
][
nj
]
==
'['
||
mat
[
ni
][
nj
]
==
']'
)
{
push_hor
(
pii
(
ni
,
nj
),
ds
);
}
if
(
mat
[
ni
][
nj
]
==
'.'
)
{
swap
(
mat
[
i
][
j
],
mat
[
ni
][
nj
]);
return
pii
(
ni
,
nj
);
}
return
s
;
}
pii
push_ver
(
pii
s
,
pii
ds
)
{
int
i
=
s
.
first
,
j
=
s
.
second
,
di
=
ds
.
first
,
dj
=
ds
.
second
;
int
ni
=
i
+
di
,
nj
=
j
+
dj
;
if
(
mat
[
ni
][
nj
]
==
'#'
)
return
s
;
if
(
mat
[
ni
][
nj
]
==
'['
)
{
push_ver
(
pii
(
ni
,
nj
),
ds
);
push_ver
(
pii
(
ni
,
nj
+
1
),
ds
);
if
(
!
(
mat
[
ni
][
nj
]
==
'.'
&&
mat
[
ni
][
nj
+
1
]
==
'.'
))
{
return
s
;
}
}
else
if
(
mat
[
ni
][
nj
]
==
']'
)
{
push_ver
(
pii
(
ni
,
nj
),
ds
);
push_ver
(
pii
(
ni
,
nj
-
1
),
ds
);
if
(
!
(
mat
[
ni
][
nj
]
==
'.'
&&
mat
[
ni
][
nj
-
1
]
==
'.'
))
{
return
s
;
}
}
if
(
mat
[
ni
][
nj
]
==
'.'
)
{
swap
(
mat
[
i
][
j
],
mat
[
ni
][
nj
]);
return
pii
(
ni
,
nj
);
}
return
s
;
}
pii
move
(
pii
s
,
char
c
)
{
int
di
=
0
;
int
dj
=
0
;
if
(
c
==
'^'
)
di
=
-
1
;
if
(
c
==
'>'
)
dj
=
1
;
if
(
c
==
'v'
)
di
=
1
;
if
(
c
==
'<'
)
dj
=
-
1
;
int
i
=
s
.
first
,
j
=
s
.
second
;
assert
(
mat
[
i
][
j
]
==
'@'
);
if
(
c
==
'>'
||
c
==
'<'
)
return
push_hor
(
s
,
pii
(
di
,
dj
));
else
return
push_ver
(
s
,
pii
(
di
,
dj
));
}
void
solve
()
{
string
s
;
while
(
cin
>>
s
)
{
if
(
s
.
size
()
==
0
)
break
;
string
t
;
for
(
char
c
:
s
)
{
if
(
c
==
'#'
)
t
+=
"##"
;
if
(
c
==
'O'
)
t
+=
"[]"
;
if
(
c
==
'.'
)
t
+=
".."
;
if
(
c
==
'@'
)
t
+=
"@."
;
}
mat
.
pb
(
t
);
cin
.
ignore
();
if
(
cin
.
peek
()
==
'\n'
)
break
;
}
n
=
sz
(
mat
);
m
=
sz
(
mat
[
0
]);
s
.
clear
();
string
t
;
while
(
cin
>>
t
)
s
+=
t
;
pii
st
;
rep
(
i
,
0
,
n
)
rep
(
j
,
0
,
m
)
if
(
mat
[
i
][
j
]
==
'@'
)
{
st
=
pii
(
i
,
j
);
}
for
(
char
c
:
s
){
vector
<
string
>
mat2
=
mat
;
pii
st2
=
st
;
st
=
move
(
st
,
c
);
if
(
st2
==
st
)
{
mat
=
mat2
;
}
}
ll
ans
=
0
;
rep
(
i
,
1
,
n
)
rep
(
j
,
1
,
m
)
if
(
mat
[
i
][
j
]
==
'['
)
{
ans
+=
100
*
i
+
j
;
}
pr
(
ans
);
}
int
main
()
{
ios
::
sync_with_stdio
(
0
);
cin
.
tie
(
0
);
cout
<<
setprecision
(
15
)
<<
fixed
;
#ifdef LOCAL
freopen
(
"input.txt"
,
"r"
,
stdin
);
#endif
solve
();
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment