feat: new problem formatted

This commit is contained in:
2026-06-25 19:56:11 -03:00
parent bd94e27fad
commit 10ac9a7b32
63 changed files with 567453 additions and 0 deletions

View File

@@ -56,6 +56,7 @@ Repositório com a formatação de problemas que exploram variadas técnicas de
- [Pique Pega](./pique-pega/)
- [Lazy Jumping Frog](./ra-preguicosa/)
- [Rede Anel Estelar](./rede-anel-estelar/)
- [SMS](./sms)
---

97
sms/Makefile Normal file
View File

@@ -0,0 +1,97 @@
# Normal directories
SRC_DIR := src
BIN_DIR := bin
DBG_DIR := bin/debug
# Grader directories
GRADER := $(wildcard $(SRC_DIR)/grader.cpp)
GRADER_DIR := $(SRC_DIR)/grader
HANDLER_DIR := $(SRC_DIR)/handler
GRADER_SRC := $(wildcard $(GRADER_DIR)/*.cpp)
GRADER_BIN := $(patsubst $(GRADER_DIR)/%.cpp, $(BIN_DIR)/%, $(GRADER_SRC))
GRADER_DBG := $(patsubst $(GRADER_DIR)/%.cpp, $(DBG_DIR)/%, $(GRADER_SRC))
# Change CPP source directories if grader is defined
ifdef GRADER
SRC := $(wildcard $(HANDLER_DIR)/*.cpp)
BIN := $(patsubst $(HANDLER_DIR)/%.cpp, $(BIN_DIR)/%, $(SRC))
DBG := $(patsubst $(HANDLER_DIR)/%.cpp, $(DBG_DIR)/%, $(SRC))
else
SRC := $(wildcard $(SRC_DIR)/*.cpp)
BIN := $(patsubst $(SRC_DIR)/%.cpp, $(BIN_DIR)/%, $(SRC))
DBG := $(patsubst $(SRC_DIR)/%.cpp, $(DBG_DIR)/%, $(SRC))
endif
SRC_C := $(wildcard $(SRC_DIR)/*.c)
BIN_C := $(patsubst $(SRC_DIR)/%.c, $(BIN_DIR)/%, $(SRC_C))
DBG_C := $(patsubst $(SRC_DIR)/%.c, $(DBG_DIR)/%, $(SRC_C))
SRC_JAVA := $(wildcard $(SRC_DIR)/*.java)
BIN_JAVA := $(patsubst $(SRC_DIR)/%.java, $(BIN_DIR)/%.class, $(SRC_JAVA))
DBG_JAVA := $(patsubst $(SRC_DIR)/%.java, $(DBG_DIR)/%.class, $(SRC_JAVA))
CHECKER := $(wildcard $(SRC_DIR)/checker.cpp)
C := gcc
CPP := g++
CXX_FLAGS := -Wall -O2
DEBUG_FLAGS := -Wall -g
BOCA_FLAGS := -static -DBOCA_SUPPORT
JV = javac
JV_DEBUG = -g
JV_DIR = -d bin
JV_DBG_DIR = -d bin/debug
.PHONY: all debug release checker clean
all: debug release checker
debug: $(DBG) $(DBG_C) $(DBG_JAVA) $(GRADER_DBG)
release: $(BIN) $(BIN_C) $(BIN_JAVA) $(GRADER_BIN)
ifdef CHECKER
checker: $(DBG_DIR)/checker-boca $(BIN_DIR)/checker-boca
endif
$(BIN): $(BIN_DIR)/% : $(SRC_DIR)/%.cpp | $(BIN_DIR)
$(CPP) $(CXX_FLAGS) $^ -o $@
$(DBG): $(DBG_DIR)/% : $(SRC_DIR)/%.cpp | $(DBG_DIR)
$(CPP) $(DEBUG_FLAGS) $^ -o $@
$(BIN_C): $(BIN_DIR)/% : $(SRC_DIR)/%.c | $(BIN_DIR)
$(C) $(CXX_FLAGS) $^ -o $@
$(DBG_C): $(DBG_DIR)/% : $(SRC_DIR)/%.c | $(DBG_DIR)
$(C) $(DEBUG_FLAGS) $^ -o $@
$(BIN_JAVA): $(BIN_DIR)/%.class : $(SRC_DIR)/%.java | $(BIN_DIR)
$(JV) $(JV_DIR) $^
$(DBG_JAVA): $(DBG_DIR)/%.class : $(SRC_DIR)/%.java | $(DBG_DIR)
$(JV) $(JV_DEBUG) $(JV_DBG_DIR) $^
$(GRADER_BIN): $(BIN_DIR)/% : $(GRADER_DIR)/%.cpp $(GRADER) $(GRADER_DIR)/*.h
$(CPP) $(CXX_FLAGS) $^ -o $@
$(GRADER_DBG): $(DBG_DIR)/% : $(GRADER_DIR)/%.cpp $(GRADER) $(GRADER_DIR)/*.h
$(CPP) $(DEBUG_FLAGS) $^ -o $@
$(BIN_DIR):
mkdir -p $@
$(DBG_DIR):
mkdir -p $@
$(BIN_DIR)/checker-boca: $(SRC_DIR)/checker.cpp
$(CPP) $(CXX_FLAGS) $(BOCA_FLAGS) $^ -o $@
$(DBG_DIR)/checker-boca: $(SRC_DIR)/checker.cpp
$(CPP) $(DEBUG_FLAGS) $(BOCA_FLAGS) $^ -o $@
clean:
@echo Cleaning problem files
rm -rf bin

BIN
sms/image.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 KiB

6
sms/input/1 Normal file
View File

@@ -0,0 +1,6 @@
5 5
1 2
1 3
1 4
2 3
5 4

92
sms/input/10 Normal file
View File

@@ -0,0 +1,92 @@
14 91
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 12
2 13
2 14
3 4
3 5
3 6
3 7
3 8
3 9
3 10
3 11
3 12
3 13
3 14
4 5
4 6
4 7
4 8
4 9
4 10
4 11
4 12
4 13
4 14
5 6
5 7
5 8
5 9
5 10
5 11
5 12
5 13
5 14
6 7
6 8
6 9
6 10
6 11
6 12
6 13
6 14
7 8
7 9
7 10
7 11
7 12
7 13
7 14
8 9
8 10
8 11
8 12
8 13
8 14
9 10
9 11
9 12
9 13
9 14
10 11
10 12
10 13
10 14
11 12
11 13
11 14
12 13
12 14
13 14

87
sms/input/11 Normal file
View File

@@ -0,0 +1,87 @@
44 86
1 25
1 39
2 5
2 19
2 35
3 15
3 18
3 19
4 23
4 38
5 25
5 27
6 26
6 27
7 29
7 32
7 36
7 43
8 10
8 21
8 23
8 27
9 11
9 32
9 34
10 11
10 15
10 16
10 19
10 27
10 40
10 42
11 13
11 19
11 33
11 41
12 17
12 19
12 31
13 18
13 24
13 34
14 17
14 22
14 30
14 36
14 41
15 23
15 26
15 29
15 33
16 17
17 26
17 39
18 20
18 35
19 20
19 21
20 38
20 40
21 23
21 38
22 28
22 29
22 41
23 34
23 41
24 36
24 40
25 27
26 31
26 35
26 44
27 29
28 31
28 32
30 33
30 40
31 44
32 33
33 36
33 40
34 44
36 44
37 40
37 42

189
sms/input/12 Normal file
View File

@@ -0,0 +1,189 @@
77 188
1 5
1 7
1 8
1 18
1 31
1 33
1 72
2 7
2 10
2 11
2 71
3 24
3 36
3 51
3 55
3 57
4 16
4 45
4 55
4 77
5 45
5 49
5 58
6 15
6 29
7 38
7 58
7 69
7 73
8 20
8 46
8 51
8 54
9 11
9 19
9 30
10 12
10 62
10 71
11 40
11 55
11 58
11 59
11 68
11 70
12 29
12 36
12 46
12 52
12 73
13 29
13 30
14 16
14 38
14 49
14 73
15 16
15 33
15 34
15 64
15 68
16 39
16 52
17 38
17 47
17 66
17 71
18 26
18 36
18 44
18 48
18 56
18 74
19 36
19 61
19 74
19 76
20 22
20 40
20 64
20 76
21 27
21 55
21 60
22 26
22 38
22 62
22 64
23 32
23 33
23 55
24 27
24 28
24 37
24 45
24 47
25 32
25 49
25 50
26 60
27 29
27 42
27 44
27 45
28 30
28 35
28 48
28 71
29 36
29 46
29 47
29 77
30 40
30 52
30 59
31 42
31 55
31 56
32 60
32 73
33 56
34 39
34 60
34 73
35 41
35 46
35 47
35 67
36 40
36 48
36 64
36 76
37 64
38 40
38 65
39 43
39 64
39 65
40 52
40 58
40 77
41 44
41 45
41 47
42 43
42 72
42 75
43 47
43 73
43 74
44 52
44 67
45 51
45 56
46 70
46 77
48 62
49 62
49 73
49 76
50 73
51 53
51 60
51 75
52 59
53 73
54 65
54 67
55 59
55 63
55 66
55 68
55 73
56 74
57 61
57 63
57 64
61 67
61 70
61 72
63 75
64 70
65 67
66 68
66 72
68 69
70 72
71 75

12196
sms/input/13 Normal file

File diff suppressed because it is too large Load Diff

7672
sms/input/14 Normal file

File diff suppressed because it is too large Load Diff

13279
sms/input/15 Normal file

File diff suppressed because it is too large Load Diff

12484
sms/input/16 Normal file

File diff suppressed because it is too large Load Diff

6676
sms/input/17 Normal file

File diff suppressed because it is too large Load Diff

200001
sms/input/18 Normal file

File diff suppressed because it is too large Load Diff

200001
sms/input/19 Normal file

File diff suppressed because it is too large Load Diff

3
sms/input/2 Normal file
View File

@@ -0,0 +1,3 @@
4 2
1 2
3 4

100000
sms/input/20 Normal file

File diff suppressed because it is too large Load Diff

127
sms/input/3 Normal file
View File

@@ -0,0 +1,127 @@
54 126
1 23
1 31
1 40
1 48
1 53
2 7
2 10
2 11
2 18
2 22
3 23
3 41
4 10
4 11
4 13
4 22
4 42
4 51
5 27
5 46
5 49
5 54
6 36
6 39
7 13
7 17
7 21
7 35
7 38
7 43
8 33
8 34
8 45
8 53
9 15
9 36
9 38
9 40
9 41
9 46
10 28
10 37
10 44
10 48
10 54
11 24
11 34
11 50
12 38
12 39
12 52
13 18
13 28
13 35
13 39
13 51
15 16
15 25
15 38
16 34
16 41
16 44
16 53
17 18
17 24
17 52
18 30
18 48
19 24
19 47
20 24
20 32
20 33
20 38
20 53
21 33
22 49
22 52
23 53
24 32
24 38
24 43
24 45
25 29
25 33
25 44
25 47
26 41
27 39
27 50
28 30
28 32
28 52
30 34
30 35
30 52
31 41
32 33
32 34
32 37
32 39
33 41
33 43
33 47
33 54
34 38
34 44
34 54
35 36
35 47
36 50
36 51
37 41
38 51
38 53
39 48
39 50
41 45
41 46
41 48
41 51
42 49
42 50
42 52
44 46
45 53

100
sms/input/4 Normal file
View File

@@ -0,0 +1,100 @@
22 99
1 2
1 7
1 11
1 12
1 14
1 15
1 16
2 4
2 6
2 8
2 9
2 10
2 12
2 14
2 15
2 21
3 5
3 6
3 7
3 8
3 11
3 14
3 15
3 16
3 22
4 8
4 9
4 11
4 12
4 13
4 16
4 21
4 22
5 7
5 8
5 9
5 16
5 19
5 20
6 8
6 9
6 10
6 11
6 18
6 20
6 21
7 11
7 14
7 16
7 18
7 19
7 20
7 21
8 10
8 11
8 18
8 19
8 20
8 21
8 22
9 22
10 11
10 15
10 17
10 18
10 19
10 22
11 12
11 13
11 14
11 17
11 20
11 21
12 14
12 15
12 16
13 14
13 16
13 18
13 19
13 20
14 15
14 16
14 22
15 17
15 18
15 19
15 20
15 22
16 17
16 20
16 21
16 22
17 19
17 21
18 20
19 20
19 21
19 22

85
sms/input/5 Normal file
View File

@@ -0,0 +1,85 @@
78 84
1 55
2 11
2 53
2 69
3 55
3 71
4 27
5 78
6 16
6 26
6 51
7 12
7 19
8 42
8 45
8 78
9 16
9 40
10 33
11 27
11 43
11 50
12 26
12 35
13 20
13 40
14 67
14 75
15 45
15 51
15 66
16 21
16 40
16 49
17 69
18 48
19 65
20 29
20 31
20 40
22 35
23 69
25 29
26 66
29 57
30 41
32 44
32 66
33 59
33 64
33 74
34 38
34 68
35 52
35 76
36 44
36 72
37 45
37 59
37 76
38 73
39 43
41 43
41 61
41 67
44 68
45 59
46 49
49 62
51 73
51 77
52 56
52 62
53 71
54 60
57 60
57 63
59 61
63 74
63 78
64 68
67 69
75 78
76 77

46
sms/input/6 Normal file
View File

@@ -0,0 +1,46 @@
10 45
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
3 4
3 5
3 6
3 7
3 8
3 9
3 10
4 5
4 6
4 7
4 8
4 9
4 10
5 6
5 7
5 8
5 9
5 10
6 7
6 8
6 9
6 10
7 8
7 9
7 10
8 9
8 10
9 10

134
sms/input/7 Normal file
View File

@@ -0,0 +1,134 @@
18 133
1 2
1 3
1 4
1 5
1 7
1 8
1 9
1 10
1 11
1 13
1 14
1 15
1 16
1 18
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 12
2 13
2 14
2 15
2 17
2 18
3 4
3 5
3 6
3 7
3 8
3 9
3 13
3 14
3 15
3 16
3 17
3 18
4 5
4 7
4 8
4 9
4 10
4 11
4 13
4 15
4 16
4 17
4 18
5 6
5 8
5 9
5 10
5 11
5 12
5 13
5 14
5 15
5 16
5 18
6 7
6 8
6 9
6 11
6 12
6 13
6 14
6 15
6 16
6 17
6 18
7 8
7 10
7 11
7 12
7 13
7 14
7 15
7 16
7 17
7 18
8 9
8 10
8 11
8 12
8 14
8 15
8 16
8 17
8 18
9 10
9 12
9 13
9 14
9 15
9 16
9 17
9 18
10 11
10 12
10 14
10 15
10 16
10 17
10 18
11 12
11 13
11 15
11 16
11 17
11 18
12 13
12 14
12 15
12 16
12 17
13 14
13 15
13 16
13 17
13 18
14 15
14 16
14 17
15 16
15 17
15 18
16 17
16 18
17 18

91
sms/input/8 Normal file
View File

@@ -0,0 +1,91 @@
91 90
1 83
2 90
3 11
3 70
4 42
4 90
5 39
6 24
6 30
6 82
7 19
7 43
7 77
7 78
7 84
8 12
9 44
10 58
10 80
11 19
11 31
11 50
12 52
12 88
13 30
13 67
14 68
15 32
16 18
16 80
17 90
20 53
20 58
21 84
22 43
22 55
23 32
23 88
24 40
25 33
25 54
26 37
26 51
26 71
27 52
27 66
28 32
29 42
30 73
30 76
30 89
31 68
34 47
34 75
35 43
36 85
36 88
37 77
38 54
38 55
38 87
39 40
41 61
42 77
44 77
45 49
46 66
46 80
47 86
48 64
48 91
49 73
50 83
51 64
54 59
56 74
56 79
57 77
60 78
61 85
62 67
63 72
63 90
65 66
66 69
73 74
74 83
76 80
80 86
81 87

129
sms/input/9 Normal file
View File

@@ -0,0 +1,129 @@
68 128
1 9
1 17
1 33
1 54
2 30
2 44
2 45
2 67
3 31
3 47
3 55
3 62
4 44
5 9
5 23
5 31
5 37
5 58
5 67
6 28
6 33
6 52
7 34
7 47
8 10
8 15
8 21
8 25
8 34
9 18
9 20
9 51
9 52
9 55
9 59
10 25
10 33
10 36
10 55
11 50
11 53
11 55
11 61
12 26
12 29
12 47
12 57
12 59
13 40
13 55
13 61
13 66
14 18
15 17
15 18
15 19
15 41
15 56
16 37
16 66
17 21
17 35
17 58
17 63
18 66
19 28
21 39
21 41
21 56
22 54
22 62
22 65
23 55
24 42
24 45
24 46
24 55
24 60
25 32
25 52
27 31
27 53
27 59
27 67
28 64
29 47
29 58
30 39
31 40
31 42
31 50
32 44
32 64
32 66
33 39
34 49
34 62
36 45
36 46
36 56
37 57
38 61
38 65
39 40
40 45
42 64
43 62
43 67
44 62
45 46
45 58
45 63
46 56
48 50
49 60
50 51
51 53
51 58
55 66
55 68
56 59
57 67
58 59
59 64
60 62
61 67
64 67
65 67

188
sms/maratona.cls Normal file
View File

@@ -0,0 +1,188 @@
\ProvidesPackage{maratona}
\LoadClass[11pt]{article}
% remove page numbers
\pagenumbering{gobble}
\RequirePackage{fancyhdr}
\RequirePackage{tabularx,colortbl}
%\RequirePackage{arial}
\RequirePackage{ifpdf}
\RequirePackage[T1]{fontenc}
\RequirePackage[utf8]{inputenc}
\RequirePackage[portuguese]{babel}
\RequirePackage{graphics}
\RequirePackage{graphicx}
\RequirePackage{amssymb,amsmath,wrapfig}
\RequirePackage{xcolor,colortbl}
\RequirePackage{xcolor}
\RequirePackage{ifthen}
\oddsidemargin 0cm
\evensidemargin -2cm
\topmargin -1cm
\textwidth 16cm
\textheight 23cm
\ifpdf
\RequirePackage[pdftex]{hyperref}
\else
\RequirePackage[hypertex]{hyperref}
\fi
\newcommand{\var}[1]{\ensuremath{{#1}}}
\hypersetup{
letterpaper,
colorlinks=true,
linkcolor=blue,
urlcolor=blue,
pdfpagemode=none,
pdftitle={IV Maratona de Programação do IFB \today},
pdfauthor={},
pdfsubject={Caderno de problemas da IV Maratona de Programação do IFB },
pdfkeywords={maratona, programação, IFB}
}
\DeclareGraphicsExtensions{png}
\lhead{DS Contest Tools}
\pagestyle{fancy}
% Capa
\newenvironment{Maratona}[3]
{
\begin{titlepage}
\begin{center}
\vspace{1cm}
\Large{\textbf{#1}} \\
\vspace{1cm}
{\textbf{Caderno de Problemas}} \\
\vspace{1cm}
\begin{small}
\textsl{#2}
\end{small} \\
\begin{figure}[htp]
\begin{center}
\includegraphics[scale=1]{logos/logo-maratona.png}
\end{center}
\end{figure}
{(Este caderno contém {#3} problemas)} \\
\vspace{1cm}
}
{
\vfill
\begin{small}
{QNM 40, Área Especial nº 01,
Taguatinga/DF, 72146-000 ,
Brasil } \\
{Telefone (61) 2103-2200 \\http://www.ifb.edu.br/taguatinga} \\
\end{small}
\end{center}
\end{titlepage}
}
\newcommand{\Organizacao}[2]{
{\small \vfill
\begin{center}
\textbf{Comissão Organizadora:} \\
{#1} \\
\bigskip
\textbf{Apoio:}\\
{#2}
\end{center}
}
\vfill
}
% Problema
\newcounter{problem}
\newenvironment{Problema}[4]{
\stepcounter{problem}
\newpage
\begin{center}
\Large{\ifthenelse{\equal{#1}{}}{\textbf{{#2}}}{\textbf{Problema {#1} -- {#2} }}}{\\\footnotesize \textbf{Limite de tempo: {#3}s}}{\\[-0.1cm]\footnotesize \textbf{Limite de memória: {#4}MB}}
\end{center}
}
\newcounter{problemAutor}
\newenvironment{ProblemaAutor}[5]{
\stepcounter{problemAutor}
\newpage
\begin{center}
\Large{\ifthenelse{\equal{#1}{}}{\textbf{{#2}}}{\textbf{Problema {#1} -- {#2} }}}{\\\footnotesize \textbf{Limite de tempo: {#3}s}}{\\[-0.1cm]\footnotesize \textbf{Limite de memória: {#4}MB\\}}{
\footnotesize Autor: {#5}
}
\end{center}
}
% Código-fonte
\newcommand{\codigofonte}[1]{Nome do arquivo fonte: {#1}}
% Entrada
\newcommand{\Entrada}{
\bigskip
\begin{large}
\textbf{Entrada} \\
\end{large}
}
% Saida
\newcommand{\Saida}{
\bigskip
\begin{large}
\textbf{Saída} \\
\end{large}
}
\newcommand{\Interacao}{
\bigskip
\begin{large}
\textbf{Interação} \\
\end{large}
}
\newcommand{\Notas}{
\bigskip
\begin{large}
\textbf{Notas} \\
\end{large}
}
% Exemplo
\newenvironment{Exemplo}
{
\tabularx{\textwidth}{XX}
% {@{\extracolsep{\fill}}|l|l|}
% {|l|l@{\extracolsep{\fill}|}}
\hline
Entrada & Saída \\\hline
}
{
\hline
\endtabularx
}
% Exemplo de Entrada
\newenvironment{ExemploEntrada}
{
\bigskip
\begin{large}
\textbf{Exemplo} \\
\end{large}
}
{
}
% Sample Output

2
sms/output/1 Normal file
View File

@@ -0,0 +1,2 @@
3
1 4 5

2
sms/output/10 Normal file
View File

@@ -0,0 +1,2 @@
2
1 14

2
sms/output/11 Normal file
View File

@@ -0,0 +1,2 @@
5
1 39 17 26 44

2
sms/output/12 Normal file
View File

@@ -0,0 +1,2 @@
4
1 8 46 77

2
sms/output/13 Normal file
View File

@@ -0,0 +1,2 @@
3
1 283 1206

2
sms/output/14 Normal file
View File

@@ -0,0 +1,2 @@
189
1 4467 5410 6679 1840 786 101 5620 1938 5158 7110 1033 913 5537 3073 1411 5375 2507 6165 1793 5469 3470 278 2830 1926 3686 839 5223 1084 2400 3650 3034 5332 2422 565 3766 5386 6874 6883 522 4295 1354 3122 3937 5755 6132 4629 6052 1291 6952 1130 1015 1089 695 3285 3455 6592 3200 7132 1397 2187 501 2685 1448 7358 5661 5613 5888 6126 5181 5134 6038 7270 5967 3354 5042 7278 5731 1017 3921 7644 599 4199 3640 5773 5121 4317 6856 1318 6876 3483 3928 812 4722 5317 120 2806 6828 4250 6143 5997 1090 6677 7619 1956 4126 1282 3446 4687 989 5294 5196 6510 4377 5968 1814 1363 7097 2785 794 2379 488 890 7042 3591 4834 366 2810 974 1548 536 7202 3476 7591 5108 2632 170 6801 5502 7427 5063 7645 3634 5741 177 5598 3548 7622 1209 4730 3147 1936 3008 7035 7082 939 7094 2975 553 6602 6374 6625 4135 3036 3202 2833 5445 5656 4581 498 3632 5561 6765 6398 5118 5354 2285 3458 212 5688 2003 7005 104 4988 4183 3366 4937 6474 7672

2
sms/output/15 Normal file
View File

@@ -0,0 +1,2 @@
10
1 397 4049 3075 547 2073 7430 5834 2449 7654

2
sms/output/16 Normal file
View File

@@ -0,0 +1,2 @@
3
1 777 1008

2
sms/output/17 Normal file
View File

@@ -0,0 +1,2 @@
10
1 1574 3100 2185 3493 2817 471 3506 1466 3580

2
sms/output/18 Normal file
View File

@@ -0,0 +1,2 @@
8
1 77597 15444 50864 48466 57828 41595 100000

2
sms/output/19 Normal file
View File

@@ -0,0 +1,2 @@
9
1 78336 81706 15174 83249 83454 18396 48330 100000

1
sms/output/2 Normal file
View File

@@ -0,0 +1 @@
-1

2
sms/output/20 Normal file
View File

@@ -0,0 +1,2 @@
231
1 50771 45089 91183 31876 59616 11749 81649 23663 14747 57830 89836 8513 620 20257 23045 24017 34207 68727 19359 47416 19778 71470 28515 96589 58548 31256 88968 25316 85371 4286 48117 88761 43788 86094 87868 83908 81015 80359 1513 71478 78698 92655 94511 1176 37236 93896 81434 57961 3714 41038 32144 35730 25282 35244 2405 28332 37229 81288 49400 19414 84708 64674 69287 29889 1776 9577 47894 28272 70421 45642 46889 23435 85004 16780 40288 27344 7194 53970 80178 71776 93624 39605 12914 19169 49578 41688 27529 87461 19235 93864 62739 79500 58655 80904 12937 43542 45027 94198 36578 59989 14884 35516 80745 42447 48283 69635 73130 7301 91779 32551 77881 52857 63135 39712 18943 86144 10384 30365 46047 31342 2260 47130 71053 78148 36883 14215 84312 85708 37989 96971 33510 94691 5646 88510 9284 83621 79718 14539 88198 67387 4522 53487 4568 66912 32809 82415 76278 53879 73807 80427 18695 36824 62425 33649 49935 79842 78097 12662 29304 57564 25755 62736 31153 15794 55054 91498 17382 6906 93958 89850 88138 36163 50174 45020 48276 59688 42452 92160 88260 42949 60644 51755 75283 55203 67615 30560 14079 21663 42609 88211 32072 89975 46491 34260 32351 27119 81595 91737 70113 23037 90902 51807 44697 39655 69101 16665 17080 29266 83349 90713 71337 27091 60294 40000 70934 61094 97763 5239 91677 26382 19525 69744 43109 93073 59347 30341 91744 66680 18279 100000

2
sms/output/3 Normal file
View File

@@ -0,0 +1,2 @@
4
1 48 10 54

2
sms/output/4 Normal file
View File

@@ -0,0 +1,2 @@
3
1 14 22

2
sms/output/5 Normal file
View File

@@ -0,0 +1,2 @@
11
1 55 3 71 53 2 69 67 14 75 78

2
sms/output/6 Normal file
View File

@@ -0,0 +1,2 @@
2
1 10

2
sms/output/7 Normal file
View File

@@ -0,0 +1,2 @@
2
1 18

2
sms/output/8 Normal file
View File

@@ -0,0 +1,2 @@
13
1 83 50 11 19 7 77 37 26 51 64 48 91

2
sms/output/9 Normal file
View File

@@ -0,0 +1,2 @@
4
1 9 55 68

68
sms/problem.json Normal file
View File

@@ -0,0 +1,68 @@
{
"version": "1.0",
"problem": {
"title": "SMS",
"event": "",
"time_limit": 1.0,
"memory_limit_mb": 512,
"input_file": "stdin",
"output_file": "stdout",
"interactive": false,
"grader": false,
"subject": {
"en_us": [
"graphs",
"bfs",
"breadth-first-search"
],
"pt_br": [
"grafos",
"bfs",
"busca-em-largura"
],
"es": [
""
]
}
},
"author": {
"name": "Arthur Andrade D'Olival",
"affiliation": "",
"country": "",
"email": ""
},
"build": {
"run_generator": true,
"run_validator": true,
"produce_outputs": true,
"run_checker": true,
"run_all_solutions": true,
"run_specific_solution": "",
"generate_io_only": false,
"generate_pdf_only": false,
"cpu_count": 1,
"build_pdf": true,
"pdf_format": "ds",
"io_samples": 1
},
"solutions": {
"main-ac": "ac.cpp",
"alternative-ac": ["alternative-ac.py"],
"wrong-answer": [],
"time-limit": [],
"time-limit-or-ac": [],
"time-limit-or-memory-limit": [],
"memory-limit": [],
"presentation-error": [],
"runtime-error": []
},
"polygon_config": {
"id": ""
},
"boca_config": {
"time_limit": 1,
"number_of_repetitions": 1,
"maximum_memory_mb": 512,
"maximum_output_size_kb": 24096
}
}

BIN
sms/sms-tutorial.pdf Normal file

Binary file not shown.

23
sms/sms-tutorial.tex Normal file
View File

@@ -0,0 +1,23 @@
\documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{fullpage}
\usepackage{url}
\pagenumbering{gobble}
\usepackage{hyperref}
\title{ Tutorial: SMS}
\author{Arthur Andrade D'Olival}
\date{}
\begin{document}
\maketitle
O problema pede o caminho mais curto (em número de arestas) entre o vértice $1$ e o vértice $n$ em um grafo não direcionado sem pesos.
Isso pode ser resolvido utilizando uma Busca em Largura (BFS). Durante a BFS, podemos armazenar não apenas a distância até cada vértice, mas também qual foi o vértice anterior (o "pai") no caminho mais curto.
Se ao final da BFS o vértice $n$ não foi visitado, não há rota possível. Caso contrário, podemos reconstruir o caminho mais curto partindo de $n$ e seguindo os "pais" até chegar em $1$. A rota reconstruída deve ser invertida antes de ser impressa.
\textbf{Complexidade de tempo:} $O(n + m)$
\textbf{Complexidade de espaço:} $O(n + m)$
\end{document}

BIN
sms/sms.pdf Normal file

Binary file not shown.

50
sms/sms.tex Normal file
View File

@@ -0,0 +1,50 @@
\documentclass{maratona}
\begin{document}
\begin{ProblemaAutor}{}{SMS}{1}{512}{Arthur Andrade D'Olival}
Beto finalmente conseguiu o número do telefone de Ana, mas percebeu que está sem créditos para enviar um SMS diretamente! Por sorte, ele e seus amigos bolaram um esquema: eles vão repassar a mensagem de celular em celular utilizando Bluetooth, até que ela chegue ao destino.
A rede de amigos de Beto é formada por $n$ pessoas e $m$ conexões de proximidade. Como a bateria dos celulares está acabando e cada envio consome um pouco de energia, a mensagem deve ser repassada pelo menor número possível de pessoas.
Sua tarefa é descobrir se é possível que o SMS de Beto chegue até Ana e, se for possível, qual é o número mínimo de aparelhos (incluindo o de Beto e o de Ana) por onde a mensagem precisará passar.
\Entrada
A primeira linha da entrada contém dois inteiros $n$ e $m$ ($2 \le n \le 10^5, 1 \le m \le 2 \cdot 10^5$), indicando o número de pessoas na rede de amigos e o número de conexões de proximidade possíveis. As pessoas são numeradas de $1$ a $n$. Beto é a pessoa de número $1$ e Ana é a pessoa de número $n$.
As próximas $m$ linhas descrevem as conexões. Cada linha contém dois inteiros $a$ e $b$ ($1 \le a, b \le n, a \neq b$), indicando que há uma conexão de proximidade entre a pessoa $a$ e a pessoa $b$, permitindo a troca de mensagens Bluetooth.
É garantido que todas as conexões são bidirecionais e existe no máximo uma conexão entre qualquer par de pessoas.
\Saida
Se for possível que o SMS chegue até Ana, primeiro imprima $k$: o número mínimo de pessoas em uma rota válida. Depois disso, imprima um exemplo dessa rota com $k$ inteiros. Você pode imprimir qualquer rota válida com tamanho $k$.
Se não for possível encontrar nenhuma rota, imprima \texttt{-1}.
\ExemploEntrada
\begin{Exemplo}
\texttt{5~5} & \texttt{3}\\
\texttt{1~2} & \texttt{1~4~5}\\
\texttt{1~3} & \\
\texttt{1~4} & \\
\texttt{2~3} & \\
\texttt{5~4} & \\
\end{Exemplo}
\Notas
\vspace{0.5cm}
O primeiro caso de teste pode ser visualizado como o grafo representado abaixo, onde o vértice com a seta vermelha representa Beto e o vértice com a seta azul representa Ana.
\begin{figure}[h]
\centering
\includegraphics[width=1\textwidth]{image.png}
\end{figure}
\vspace{0.5cm}\end{ProblemaAutor}
\end{document}

59
sms/src/ac.cpp Normal file
View File

@@ -0,0 +1,59 @@
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m; cin >> n >> m;
vector<vector<int>> adj(n + 1);
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
vector<int> dist(n + 1, -1);
vector<int> parent(n + 1, -1);
queue<int> q;
dist[1] = 0;
q.push(1);
while (!q.empty()) {
int u = q.front();
q.pop();
if (u == n) break;
for (int v : adj[u]) {
if (dist[v] == -1) {
dist[v] = dist[u] + 1;
parent[v] = u;
q.push(v);
}
}
}
if (dist[n] == -1) {
cout << -1 << "\n";
} else {
vector<int> path;
int curr = n;
while (curr != -1) {
path.push_back(curr);
curr = parent[curr];
}
reverse(path.begin(), path.end());
cout << path.size() << "\n";
for (size_t i = 0; i < path.size(); i++) {
cout << path[i] << (i + 1 == path.size() ? "" : " ");
}
cout << "\n";
}
return 0;
}

53
sms/src/alternative-ac.py Normal file
View File

@@ -0,0 +1,53 @@
import sys
from collections import deque
def main():
input_data = sys.stdin.read().split()
if not input_data:
return
n = int(input_data[0])
m = int(input_data[1])
adj = [[] for _ in range(n + 1)]
idx = 2
for _ in range(m):
u = int(input_data[idx])
v = int(input_data[idx+1])
adj[u].append(v)
adj[v].append(u)
idx += 2
dist = [-1] * (n + 1)
parent = [-1] * (n + 1)
q = deque()
q.append(1)
dist[1] = 0
while q:
u = q.popleft()
if u == n:
break
for v in adj[u]:
if dist[v] == -1:
dist[v] = dist[u] + 1
parent[v] = u
q.append(v)
if dist[n] == -1:
print(-1)
else:
path = []
curr = n
while curr != -1:
path.append(curr)
curr = parent[curr]
path.reverse()
print(len(path))
print(" ".join(map(str, path)))
if __name__ == '__main__':
main()

65
sms/src/checker.cpp Normal file
View File

@@ -0,0 +1,65 @@
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
void check_path(InStream& in, int len, int n, const vector<set<int>>& adj) {
vector<int> path(len);
for (int i = 0; i < len; i++) {
path[i] = in.readInt(1, n, "path_vertex");
}
if (path[0] != 1) {
in.quitf(_wa, "Path must start at 1");
}
if (path.back() != n) {
in.quitf(_wa, "Path must end at n");
}
for (int i = 0; i < len - 1; i++) {
int u = path[i];
int v = path[i + 1];
if (!adj[u].count(v)) {
in.quitf(_wa, "No edge between %d and %d", u, v);
}
}
}
int main(int argc, char *argv[]) {
registerTestlibCmd(argc, argv);
int n = inf.readInt();
int m = inf.readInt();
vector<set<int>> adj(n + 1);
for (int i = 0; i < m; i++) {
int u = inf.readInt();
int v = inf.readInt();
adj[u].insert(v);
adj[v].insert(u);
}
int j_ans = ans.readInt();
int p_ans = ouf.readInt();
if (j_ans == -1) {
if (p_ans == -1) {
quitf(_ok, "Both reported -1");
} else {
quitf(_wa, "Jury says -1, but participant found a path");
}
}
if (p_ans == -1) {
quitf(_wa, "Participant says -1, but jury found a path");
}
if (p_ans != j_ans) {
quitf(_wa, "Expected path of length %d, but got %d", j_ans, p_ans);
}
check_path(ans, j_ans, n, adj);
check_path(ouf, p_ans, n, adj);
quitf(_ok, "Valid shortest path found");
}

94
sms/src/generator.cpp Normal file
View File

@@ -0,0 +1,94 @@
#include "jngen.h"
#include <bits/stdc++.h>
using namespace std;
const int MIN_N = 2;
const int MAX_N = 100000;
const int MAX_M = 200000;
template <typename T> void append(vector<T> &dest, const vector<T> &orig) {
dest.insert(dest.end(), orig.begin(), orig.end());
}
string output_graph(int n, int m, const vector<pair<int, int>>& edges) {
ostringstream oss;
oss << n << " " << m << "\n";
for (auto e : edges) {
oss << e.first + 1 << " " << e.second + 1 << "\n";
}
return oss.str();
}
string generate_random_tc(int n, int m) {
long long max_edges = 1LL * n * (n - 1) / 2;
m = min((long long)m, max_edges);
m = max((long long)m, (long long)n - 1);
Graph g = Graph::random(n, m).connected();
return output_graph(n, g.m(), g.edges());
}
string generate_random_disconnected_tc(int n, int m) {
long long max_edges = 1LL * n * (n - 1) / 2;
m = min((long long)m, max_edges);
Graph g = Graph::random(n, m);
return output_graph(n, g.m(), g.edges());
}
string generate_line_tc(int n) {
Graph g = Graph::random(n, n - 1).connected();
return output_graph(n, g.m(), g.edges());
}
vector<string> generate_sample_tests() {
vector<string> tests;
ostringstream sample;
sample << "5 5\n1 2\n1 3\n1 4\n2 3\n5 4\n";
tests.push_back(sample.str());
return tests;
}
vector<string> generate_manual_tests() {
vector<string> tests;
ostringstream imp;
imp << "4 2\n1 2\n3 4\n";
tests.push_back(imp.str());
return tests;
}
vector<string> generate_random_tests() {
vector<string> tests;
for (int i = 0; i < 5; i++) {
tests.push_back(generate_random_disconnected_tc(rnd.next(10, 100), rnd.next(10, 200)));
}
for (int i = 0; i < 5; i++) {
tests.push_back(generate_random_tc(rnd.next(10, 100), rnd.next(10, 200)));
}
for (int i = 0; i < 5; i++) {
tests.push_back(generate_random_tc(rnd.next(1000, 10000), rnd.next(1000, 20000)));
}
return tests;
}
vector<string> generate_extreme_tests(){
vector<string> tests;
tests.push_back(generate_random_tc(MAX_N, MAX_M));
tests.push_back(generate_random_disconnected_tc(MAX_N, MAX_M));
tests.push_back(generate_line_tc(MAX_N));
return tests;
}
int main(int argc, char *argv[]) {
registerGen(argc, argv, 1);
vector<string> tests;
size_t test = 0;
append(tests, generate_sample_tests());
append(tests, generate_manual_tests());
append(tests, generate_random_tests());
append(tests, generate_extreme_tests());
for (const auto &t : tests) {
startTest(++test);
cout << t;
}
return 0;
}

7293
sms/src/jngen.h Normal file

File diff suppressed because it is too large Load Diff

1
sms/src/script.sh Normal file
View File

@@ -0,0 +1 @@
generator

5963
sms/src/testlib.h Normal file

File diff suppressed because it is too large Load Diff

29
sms/src/validator.cpp Normal file
View File

@@ -0,0 +1,29 @@
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
registerValidation(argc, argv);
int n = inf.readInt(2, 100000, "n");
inf.readSpace();
int m = inf.readInt(1, 200000, "m");
inf.readEoln();
set<pair<int, int>> edges;
for (int i = 0; i < m; i++) {
int u = inf.readInt(1, n, "u");
inf.readSpace();
int v = inf.readInt(1, n, "v");
inf.readEoln();
ensuref(u != v, "Self-loop found");
if (u > v) swap(u, v);
ensuref(edges.count({u, v}) == 0, "Multiple edges found");
edges.insert({u, v});
}
inf.readEof();
return 0;
}

View File

@@ -0,0 +1,5 @@
Beto finalmente conseguiu o número do telefone de Ana, mas percebeu que está sem créditos para enviar um SMS diretamente! Por sorte, ele e seus amigos bolaram um esquema: eles vão repassar a mensagem de celular em celular utilizando Bluetooth, até que ela chegue ao destino.
A rede de amigos de Beto é formada por $n$ pessoas e $m$ conexões de proximidade. Como a bateria dos celulares está acabando e cada envio consome um pouco de energia, a mensagem deve ser repassada pelo menor número possível de pessoas.
Sua tarefa é descobrir se é possível que o SMS de Beto chegue até Ana e, se for possível, qual é o número mínimo de aparelhos (incluindo o de Beto e o de Ana) por onde a mensagem precisará passar.

5
sms/statement/input.tex Normal file
View File

@@ -0,0 +1,5 @@
A primeira linha da entrada contém dois inteiros $n$ e $m$ ($2 \le n \le 10^5, 1 \le m \le 2 \cdot 10^5$), indicando o número de pessoas na rede de amigos e o número de conexões de proximidade possíveis. As pessoas são numeradas de $1$ a $n$. Beto é a pessoa de número $1$ e Ana é a pessoa de número $n$.
As próximas $m$ linhas descrevem as conexões. Cada linha contém dois inteiros $a$ e $b$ ($1 \le a, b \le n, a \neq b$), indicando que há uma conexão de proximidade entre a pessoa $a$ e a pessoa $b$, permitindo a troca de mensagens Bluetooth.
É garantido que todas as conexões são bidirecionais e existe no máximo uma conexão entre qualquer par de pessoas.

10
sms/statement/notes.tex Normal file
View File

@@ -0,0 +1,10 @@
\vspace{0.5cm}
O primeiro caso de teste pode ser visualizado como o grafo representado abaixo, onde o vértice com a seta vermelha representa Beto e o vértice com a seta azul representa Ana.
\begin{figure}[h]
\centering
\includegraphics[width=1\textwidth]{image.png}
\end{figure}
\vspace{0.5cm}

3
sms/statement/output.tex Normal file
View File

@@ -0,0 +1,3 @@
Se for possível que o SMS chegue até Ana, primeiro imprima $k$: o número mínimo de pessoas em uma rota válida. Depois disso, imprima um exemplo dessa rota com $k$ inteiros. Você pode imprimir qualquer rota válida com tamanho $k$.
Se não for possível encontrar nenhuma rota, imprima \texttt{-1}.

View File

View File

@@ -0,0 +1,9 @@
O problema pede o caminho mais curto (em número de arestas) entre o vértice $1$ e o vértice $n$ em um grafo não direcionado sem pesos.
Isso pode ser resolvido utilizando uma Busca em Largura (BFS). Durante a BFS, podemos armazenar não apenas a distância até cada vértice, mas também qual foi o vértice anterior (o "pai") no caminho mais curto.
Se ao final da BFS o vértice $n$ não foi visitado, não há rota possível. Caso contrário, podemos reconstruir o caminho mais curto partindo de $n$ e seguindo os "pais" até chegar em $1$. A rota reconstruída deve ser invertida antes de ser impressa.
\textbf{Complexidade de tempo:} $O(n + m)$
\textbf{Complexidade de espaço:} $O(n + m)$