Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
pdp-camp
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Public
pdp-camp
Commits
432785dc
Commit
432785dc
authored
7 months ago
by
Nikolaos S. Papaspyrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some material from day 1
parent
42d059a9
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
219 additions
and
0 deletions
+219
-0
bitsign.cpp
2024/senior/stl-best-practice/bitsign.cpp
+62
-0
break.sh
2024/senior/stl-best-practice/break.sh
+11
-0
genlucky.py
2024/senior/stl-best-practice/genlucky.py
+9
-0
luckyagain-bf.cpp
2024/senior/stl-best-practice/luckyagain-bf.cpp
+32
-0
luckyagain.cpp
2024/senior/stl-best-practice/luckyagain.cpp
+40
-0
stl-overview.pdf
2024/senior/stl-best-practice/stl-overview.pdf
+0
-0
lottery.cpp
2024/senior/tries/lottery.cpp
+65
-0
suffix-array-example.pdf
2024/senior/tries/suffix-array-example.pdf
+0
-0
suffix-array.pdf
2024/senior/tries/suffix-array.pdf
+0
-0
suffix-trees.pdf
2024/senior/tries/suffix-trees.pdf
+0
-0
No files found.
2024/senior/stl-best-practice/bitsign.cpp
0 → 100644
View file @
432785dc
#include <cstdio>
#include <map>
#include <tuple>
#include <vector>
using
namespace
std
;
#define MOD 1000000007
int
N
,
M
;
vector
<
char
>
s
;
vector
<
int
>
g
;
// DP[i, j, r]: in how many different ways we can fill in the '.' in
// s[i:] so that it matches with g[j:], if we must still
// get r '1' from the previous group. With r = 0 we must
// end the group, with r < 0 we have no obligation.
map
<
tuple
<
int
,
int
,
int
>
,
int
>
DP
;
int
dp
(
int
i
,
int
j
,
int
r
)
{
tuple
<
int
,
int
,
int
>
t
(
i
,
j
,
r
);
auto
it
=
DP
.
find
(
t
);
if
(
it
!=
DP
.
end
())
return
it
->
second
;
if
(
i
==
N
)
return
DP
[
t
]
=
(
j
==
M
&&
r
<=
0
);
if
(
r
>
0
)
return
DP
[
t
]
=
(
s
[
i
]
==
'0'
)
?
0
:
dp
(
i
+
1
,
j
,
r
-
1
);
switch
(
s
[
i
])
{
case
'0'
:
DP
[
t
]
=
dp
(
i
+
1
,
j
,
-
1
);
break
;
case
'1'
:
DP
[
t
]
=
(
j
<
M
&&
r
<
0
)
?
dp
(
i
,
j
+
1
,
g
[
j
])
:
0
;
break
;
case
'.'
:
DP
[
t
]
=
dp
(
i
+
1
,
j
,
-
1
);
if
(
j
<
M
&&
r
<
0
)
DP
[
t
]
=
(
DP
[
t
]
+
dp
(
i
,
j
+
1
,
g
[
j
]))
%
MOD
;
break
;
}
return
DP
[
t
];
}
int
solve
()
{
DP
.
clear
();
return
dp
(
0
,
0
,
-
1
);
}
int
main
()
{
#ifdef CONTEST
freopen
(
"bitsign.in"
,
"rt"
,
stdin
);
freopen
(
"bitsign.out"
,
"wt"
,
stdout
);
#endif
int
T
;
scanf
(
"%d"
,
&
T
);
for
(
int
t
=
0
;
t
<
T
;
++
t
)
{
scanf
(
"%d%d
\n
"
,
&
N
,
&
M
);
s
.
resize
(
N
);
g
.
resize
(
M
);
for
(
int
i
=
0
;
i
<
N
;
++
i
)
s
[
i
]
=
getchar
();
for
(
int
i
=
0
;
i
<
M
;
++
i
)
scanf
(
"%d"
,
&
g
[
i
]);
int
result
=
solve
();
printf
(
"%d
\n
"
,
result
);
}
}
This diff is collapsed.
Click to expand it.
2024/senior/stl-best-practice/break.sh
0 → 100755
View file @
432785dc
#!/bin/bash
attempt
=
1
while
true
;
do
printf
"
\r
$attempt
"
./genlucky.py
$*
>
in
./bf <
in
>
out.bf
./opt <
in
>
out.opt
diff out.bf out.opt
||
break
attempt
=
$((
attempt+1
))
done
This diff is collapsed.
Click to expand it.
2024/senior/stl-best-practice/genlucky.py
0 → 100755
View file @
432785dc
#!/usr/bin/env python3
import
random
import
sys
N
=
int
(
sys
.
argv
[
1
])
print
(
N
)
L
=
[
random
.
randrange
(
0
,
1000
)
for
_
in
range
(
N
)]
print
(
*
L
)
This diff is collapsed.
Click to expand it.
2024/senior/stl-best-practice/luckyagain-bf.cpp
0 → 100644
View file @
432785dc
#include <iostream>
#include <string>
#include <vector>
using
namespace
std
;
int
main
()
{
#ifdef CONTEST
freopen
(
"luckyagain.in"
,
"rt"
,
stdin
);
freopen
(
"luckyagain.out"
,
"wt"
,
stdout
);
#endif
int
N
;
cin
>>
N
;
vector
<
string
>
parts
(
N
);
for
(
int
i
=
0
;
i
<
N
;
++
i
)
cin
>>
parts
[
i
];
// O(N^2*D)
int
count
=
0
;
for
(
int
i
=
0
;
i
<
N
;
++
i
)
for
(
int
j
=
0
;
j
<
N
;
++
j
)
{
if
(
i
==
j
)
continue
;
string
ticket
=
parts
[
i
]
+
parts
[
j
];
int
s
=
ticket
.
size
();
if
(
s
%
2
!=
0
)
continue
;
int
first
=
0
;
for
(
int
k
=
0
;
k
<
s
/
2
;
++
k
)
first
+=
ticket
[
k
]
-
'0'
;
int
second
=
0
;
for
(
int
k
=
s
/
2
;
k
<
s
;
++
k
)
second
+=
ticket
[
k
]
-
'0'
;
if
(
first
==
second
)
++
count
;
}
cout
<<
count
<<
endl
;
}
This diff is collapsed.
Click to expand it.
2024/senior/stl-best-practice/luckyagain.cpp
0 → 100644
View file @
432785dc
#include <iostream>
#include <unordered_map>
#include <string>
#include <vector>
using
namespace
std
;
#define MAX_DIGITS 9
// O(N*D)
int
main
()
{
#ifdef CONTEST
freopen
(
"luckyagain.in"
,
"rt"
,
stdin
);
freopen
(
"luckyagain.out"
,
"wt"
,
stdout
);
#endif
int
N
;
cin
>>
N
;
vector
<
unordered_map
<
int
,
long
long
>>
whole
(
1
+
MAX_DIGITS
);
vector
<
unordered_map
<
int
,
long
long
>>
part
(
1
+
MAX_DIGITS
);
for
(
int
i
=
0
;
i
<
N
;
++
i
)
{
string
piece
;
cin
>>
piece
;
int
s
=
piece
.
size
();
vector
<
int
>
prefix
(
s
+
1
);
prefix
[
0
]
=
0
;
for
(
int
k
=
0
;
k
<
s
;
++
k
)
prefix
[
k
+
1
]
=
prefix
[
k
]
+
piece
[
k
]
-
'0'
;
int
sum
=
prefix
[
s
];
++
whole
[
s
][
sum
];
++
part
[
s
][
sum
];
for
(
int
k
=
1
;
2
*
k
<
s
;
++
k
)
{
++
part
[
s
-
2
*
k
][
sum
-
2
*
prefix
[
k
]];
// add to the right
++
part
[
s
-
2
*
k
][
2
*
prefix
[
s
-
k
]
-
sum
];
// add to the left
}
}
long
long
count
=
0
;
for
(
int
length
=
1
;
length
<=
MAX_DIGITS
;
++
length
)
for
(
auto
it
:
whole
[
length
])
count
+=
it
.
second
*
part
[
length
][
it
.
first
];
cout
<<
count
-
N
<<
endl
;
}
This diff is collapsed.
Click to expand it.
2024/senior/stl-best-practice/stl-overview.pdf
0 → 100644
View file @
432785dc
File added
This diff is collapsed.
Click to expand it.
2024/senior/tries/lottery.cpp
0 → 100644
View file @
432785dc
#include <algorithm>
#include <cstdio>
#include <vector>
using
namespace
std
;
#define MOD 1000000007
vector
<
int
>
price
;
struct
trie
{
char
letter
;
int
count
;
vector
<
trie
*>
next
;
trie
(
char
l
)
:
letter
(
l
),
count
(
0
),
next
(
10
,
nullptr
)
{}
~
trie
()
{
for
(
auto
p
:
next
)
delete
p
;
}
void
add_word
(
const
char
*
x
)
{
++
count
;
if
(
x
[
0
]
!=
'\0'
)
{
int
i
=
x
[
0
]
-
'0'
;
if
(
next
[
i
]
==
nullptr
)
next
[
i
]
=
new
trie
(
x
[
0
]);
next
[
i
]
->
add_word
(
x
+
1
);
}
}
pair
<
int
,
int
>
winnings
(
const
char
*
y
,
int
m
=
0
)
{
int
s
=
0
,
w
=
0
;
if
(
y
[
0
]
!=
'\0'
)
{
int
i
=
y
[
0
]
-
'0'
;
if
(
next
[
i
]
!=
nullptr
)
{
auto
p
=
next
[
i
]
->
winnings
(
y
+
1
,
m
+
1
);
s
=
p
.
first
;
w
=
p
.
second
;
}
}
int
n
=
m
>
0
?
count
:
s
;
int
p
=
(
w
+
(
long
long
)
(
count
-
s
)
*
price
[
m
])
%
MOD
;
return
make_pair
(
n
,
p
);
}
};
int
main
()
{
#ifdef CONTEST
freopen
(
"lottery.in"
,
"rt"
,
stdin
);
freopen
(
"lottery.out"
,
"wt"
,
stdout
);
#endif
int
K
,
N
,
Q
;
scanf
(
"%d %d %d
\n
"
,
&
K
,
&
N
,
&
Q
);
for
(
int
i
=
0
,
p
=
1
;
i
<=
K
;
++
i
,
p
=
((
long
long
)
2
*
p
)
%
MOD
)
price
.
push_back
((
p
-
1
)
%
MOD
);
trie
t
(
'$'
);
for
(
int
i
=
0
;
i
<
N
;
++
i
)
{
char
x
[
K
+
1
];
scanf
(
"%s
\n
"
,
x
);
reverse
(
x
,
x
+
K
);
t
.
add_word
(
x
);
}
for
(
int
i
=
0
;
i
<
Q
;
++
i
)
{
char
y
[
K
+
1
];
scanf
(
"%s
\n
"
,
y
);
reverse
(
y
,
y
+
K
);
auto
p
=
t
.
winnings
(
y
);
printf
(
"%d %d
\n
"
,
p
.
first
,
p
.
second
);
}
}
This diff is collapsed.
Click to expand it.
2024/senior/tries/suffix-array-example.pdf
0 → 100644
View file @
432785dc
File added
This diff is collapsed.
Click to expand it.
2024/senior/tries/suffix-array.pdf
0 → 100644
View file @
432785dc
File added
This diff is collapsed.
Click to expand it.
2024/senior/tries/suffix-trees.pdf
0 → 100644
View file @
432785dc
File added
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment