├── main.tex └── olymp.sty /main.tex: -------------------------------------------------------------------------------- 1 | \documentclass[11pt,a4paper,chinese]{ctexart} 2 | 3 | \usepackage{ctex} 4 | \usepackage{array,lastpage,amsmath,amssymb,mathtools,enumitem,graphicx,multirow,tocbibind,longtable,makecell,varwidth,titlesec,bm,booktabs,comment,qtree,listings,tikz,flowchart,algorithm,algorithmic} 5 | \usepackage{olymp} 6 | \usepackage{fancyhdr} 7 | 8 | \setCJKmainfont[BoldFont=Heiti SC Medium]{Songti SC Light} 9 | 10 | \pagestyle{fancy} 11 | \fancyhf{} 12 | \rhead{\sffamily\normalsize 20yy/mm/dd} 13 | \lhead{\sffamily \normalsize 测试赛} 14 | \renewcommand{\headrulewidth}{.7pt} 15 | \renewcommand{\footrulewidth}{.7pt} 16 | \setlength{\headsep}{15pt} 17 | \cfoot{\sffamily \normalsize Page \thepage \ of \pageref{LastPage}} 18 | 19 | \usepackage{varwidth} 20 | \newenvironment{centerverbatim}{% 21 | \par 22 | \centering 23 | \varwidth{\linewidth}% 24 | \verbatim 25 | }{% 26 | \endverbatim 27 | \endvarwidth 28 | \par 29 | } 30 | 31 | \usepackage[thinlines]{easytable} 32 | \lstset{escapeinside=``, breaklines=true, frame=none, extendedchars=false, basicstyle=\ttfamily, showstringspaces=false} 33 | \setlength{\parindent}{2em} 34 | \setlength{\parskip}{2.0ex} 35 | \linespread{1.15} 36 | \newcommand*{\mat}[1]{\boldsymbol{\mathrm{#1}}} 37 | \renewcommand*{\vec}[1]{\boldsymbol{\mathrm{#1}}} 38 | \usepackage{tikz,flowchart} 39 | \usetikzlibrary{shapes,shapes.geometric,arrows,automata,positioning} 40 | \usepackage{pgfplots} 41 | 42 | \begin{document} 43 | 44 | \input problems/cover.tex 45 | \input problems/kmeans.tex 46 | \input problems/board.tex 47 | \input problems/matrix.tex 48 | \input problems/suffix.tex 49 | 50 | \end{document} 51 | -------------------------------------------------------------------------------- /olymp.sty: -------------------------------------------------------------------------------- 1 | % 2 | % Macros for the contest problems 3 | % for MikTeX: use latex.exe 4 | % License: https://github.com/GassaFM/olymp.sty/blob/master/LICENSE 5 | % Authors: https://github.com/GassaFM/olymp.sty/blob/master/AUTHORS 6 | % 7 | 8 | \ProvidesPackage{olymp} 9 | 10 | \usepackage{verbatim} 11 | 12 | 13 | \newif\if@landscape\@landscapefalse 14 | \newif\if@russian\@russianfalse 15 | \newif\if@ukrainian\@ukrainianfalse 16 | \newif\if@arabic\@arabicfalse 17 | \newif\if@chinese\@chinesefalse 18 | 19 | \DeclareOption{landscape}{ 20 | \@landscapetrue 21 | } 22 | \DeclareOption{russian}{ 23 | \@russiantrue 24 | } 25 | \DeclareOption{ukrainian}{ 26 | \@ukrainiantrue 27 | } 28 | \DeclareOption{arabic}{ 29 | \@arabictrue 30 | } 31 | \DeclareOption{chinese}{ 32 | \@chinesetrue 33 | } 34 | \ProcessOptions\relax 35 | 36 | 37 | % -- Setup margins -- 38 | % 39 | % Tex defines to large margins for our purposes. 40 | % So we redefine this to use paper more efficiently 41 | % 42 | 43 | \newlength{\thelinewidth} 44 | 45 | \if@landscape 46 | \if@twocolumn 47 | \else 48 | \error Landscape is only supported for two column mode 49 | \fi 50 | 51 | \ifcase\@ptsize % 10 pt 52 | \hoffset=-15mm 53 | \voffset=-35mm 54 | \textheight=165mm 55 | \textwidth=272mm 56 | \or % 11 pt 57 | \hoffset=-13mm 58 | \voffset=-36mm 59 | \textheight=166mm 60 | \textwidth=272mm 61 | \or % 12 pt 62 | \hoffset=-12mm 63 | \voffset=-35mm 64 | \textheight=162mm 65 | \textwidth=268mm 66 | \fi 67 | \else 68 | \ifcase\@ptsize % 10 pt 69 | \hoffset=-26.5mm 70 | \voffset=-35mm 71 | \textheight=250mm 72 | \textwidth=175mm 73 | \or % 11 pt 74 | \hoffset=-25mm 75 | \voffset=-37.5mm 76 | \textheight=255mm 77 | \textwidth=175mm 78 | \or % 12 pt 79 | \hoffset=-20mm 80 | \voffset=-35mm 81 | \textheight=245mm 82 | \textwidth=175mm 83 | \fi 84 | 85 | \if@twocolumn 86 | \hoffset=-14.3mm 87 | \voffset=-38mm 88 | \textheight=255mm 89 | \textwidth=188mm 90 | \fi 91 | \fi 92 | 93 | \if@twocolumn 94 | \thelinewidth=0.47\textwidth 95 | \else 96 | \thelinewidth=\textwidth 97 | \fi 98 | 99 | % -- End of setup margins -- 100 | 101 | %---------- From package "lastpage" ------------------ 102 | \def\lastpage@putlabel{\addtocounter{page}{-1}% 103 | \immediate\write\@auxout{\string\newlabel{LastPage}{{}{\thepage}}}% 104 | \addtocounter{page}{1}} 105 | \AtEndDocument{\clearpage\lastpage@putlabel}% 106 | %---------- end of "lastpage" ------------------ 107 | 108 | % -- Setup sizes -- 109 | \newlength{\exmpwidinf} 110 | \newlength{\exmpwidouf} 111 | \newlength{\exmpwidewid} 112 | \newlength{\exmpthreewidinf} 113 | \newlength{\exmpthreewidouf} 114 | \newlength{\exmpthreewidnote} 115 | 116 | \newif\ifintentionallyblankpages 117 | 118 | \exmpwidinf=0.43\thelinewidth 119 | \exmpwidouf=0.43\thelinewidth 120 | \exmpwidewid=0.9\thelinewidth 121 | \exmpthreewidinf=0.28\thelinewidth 122 | \exmpthreewidouf=0.28\thelinewidth 123 | \exmpthreewidnote=0.30\thelinewidth 124 | 125 | \newlength{\afterproblemhead} 126 | \newlength{\afterconstraints} 127 | 128 | \renewcommand{\t}[1]{\ifmmode{\mathtt{#1}}\else{\texttt{#1}}\fi} 129 | \if@russian 130 | \renewcommand{\le}{\leqslant} 131 | \renewcommand{\ge}{\geqslant} 132 | \renewcommand{\leq}{\leqslant} 133 | \renewcommand{\geq}{\geqslant} 134 | \else 135 | \if@ukrainian 136 | \renewcommand{\le}{\leqslant} 137 | \renewcommand{\ge}{\geqslant} 138 | \renewcommand{\leq}{\leqslant} 139 | \renewcommand{\geq}{\geqslant} 140 | \else 141 | \if@chinese 142 | \renewcommand{\le}{\leqslant} 143 | \renewcommand{\ge}{\geqslant} 144 | \renewcommand{\leq}{\leqslant} 145 | \renewcommand{\geq}{\geqslant} 146 | \else 147 | \parindent=0mm 148 | \parskip=1ex 149 | \fi 150 | \fi 151 | \fi 152 | 153 | % -- End of setup sizes -- 154 | 155 | % -- Setup keywords -- 156 | 157 | \if@russian 158 | \def\kw@ProblemTutorial{Разбор задачи} 159 | \def\kw@Problem{Задача} 160 | \def\kw@ProblemAuthor{Автор:} 161 | \def\kw@ProblemDeveloper{Разработчик:} 162 | \def\kw@ProblemOrigin{Источник:} 163 | \def\kw@InputFileName{Имя входного файла:} 164 | \def\kw@OutputFileName{Имя выходного файла:} 165 | \def\kw@TimeLimit{Ограничение по времени:} 166 | \def\kw@MemoryLimit{Ограничение по памяти:} 167 | \def\kw@Feedback{Отображение результатов:} 168 | \def\kw@stdin{стандартный поток ввода} 169 | \def\kw@stdout{стандартный поток вывода} 170 | \def\kw@Specification{Спецификация} 171 | \def\kw@Interaction{Протокол взаимодействия} 172 | \def\kw@Input{Формат входных данных} 173 | \def\kw@Output{Формат выходных данных} 174 | \def\kw@Example{Пример} 175 | \def\kw@Examples{Примеры} 176 | \def\kwExampleNotes{Пояснение} 177 | \def\kw@Explanation{Пояснение к примеру} 178 | \def\kw@Explanations{Пояснения к примерам} 179 | \def\kw@Illustration{Иллюстрация} 180 | \def\kw@Scoring{Система оценки} 181 | \def\kw@Note{Замечание} 182 | \def\kw@Notes{Замечания} 183 | \def\kw@Constraints{Ограничения} 184 | \def\kw@version{версия} 185 | \def\kw@revision{ревизия} 186 | \def\kw@SubtaskOne{Подзадача 1} 187 | \def\kw@SubtaskTwo{Подзадача 2} 188 | \def\kw@SubtaskThree{Подзадача 3} 189 | \def\kw@SubtaskFour{Подзадача 4} 190 | \def\kw@SubtaskFive{Подзадача 5} 191 | \def\kw@SubtaskSix{Подзадача 6} 192 | \def\kw@Subtask{Подзадача} 193 | \def\kw@points{баллы} 194 | \def\kw@Page{Страница} 195 | \def\kw@of{из} 196 | \def\kw@notstated{не указан} 197 | \def\kw@IntentionallyBlankPage{Эта страница специально оставлена пустой} 198 | \def\kw@defaultinputname{тест} 199 | \def\kw@defaultoutputname{ответ} 200 | \else 201 | \if@ukrainian 202 | \def\kw@ProblemTutorial{Розбір задачі} 203 | \def\kw@Problem{Задача} 204 | \def\kw@ProblemAuthor{Автор:} 205 | \def\kw@ProblemDeveloper{Розробник:} 206 | \def\kw@ProblemOrigin{Джерело:} 207 | \def\kw@InputFileName{Назва вхідного файлу:} 208 | \def\kw@OutputFileName{Назва вихідного файлу:} 209 | \def\kw@TimeLimit{Ліміт часу:} 210 | \def\kw@MemoryLimit{Ліміт використання пам'яті:} 211 | \def\kw@Feedback{Відображення результатів:} 212 | \def\kw@stdin{стандартний потік вводу} 213 | \def\kw@stdout{стандартний потік виводу} 214 | \def\kw@Specification{Специфікація} 215 | \def\kw@Interaction{Протокол взаємодії} 216 | \def\kw@Input{Формат вхідних даних} 217 | \def\kw@Output{Формат вихідних даних} 218 | \def\kw@Example{Приклад} 219 | \def\kw@Examples{Приклади} 220 | \def\kwExampleNotes{Пояснення} 221 | \def\kw@Explanation{Пояснення до прикладу} 222 | \def\kw@Explanations{Пояснения до прикладів} 223 | \def\kw@Illustration{Ілюстрація} 224 | \def\kw@Scoring{Система оцінки} 225 | \def\kw@Note{Зауваження} 226 | \def\kw@Notes{Зауваження} 227 | \def\kw@Constraints{Обмеження} 228 | \def\kw@version{версія} 229 | \def\kw@revision{ревізія} 230 | \def\kw@SubtaskOne{Підзадача 1} 231 | \def\kw@SubtaskTwo{Підзадача 2} 232 | \def\kw@SubtaskThree{Підзадача 3} 233 | \def\kw@SubtaskFour{Підзадача 4} 234 | \def\kw@SubtaskFive{Підзадача 5} 235 | \def\kw@SubtaskSix{Підзадача 6} 236 | \def\kw@Subtask{Підзадача} 237 | \def\kw@points{бали} 238 | \def\kw@Page{Сторінка} 239 | \def\kw@of{з} 240 | \def\kw@notstated{не вказано} 241 | \def\kw@IntentionallyBlankPage{Ця сторінка спеціально залишена порожньою} 242 | \def\kw@defaultinputname{тест} 243 | \def\kw@defaultoutputname{відповідь} 244 | \else 245 | \if@chinese 246 | \def\kw@ProblemTutorial{题目解答} 247 | \def\kw@Problem{Problem} 248 | \def\kw@ProblemAuthor{题目作者:} 249 | \def\kw@ProblemDeveloper{题目开发者:} 250 | \def\kw@ProblemOrigin{题目来源:} 251 | \def\kw@InputFileName{输入文件:} 252 | \def\kw@OutputFileName{输出文件:} 253 | \def\kw@TimeLimit{时间限制:} 254 | \def\kw@MemoryLimit{内存限制:} 255 | \def\kw@Feedback{反馈方式:} 256 | \def\kw@stdin{标准输入流} 257 | \def\kw@stdout{标准输出流} 258 | \def\kw@Background{背景知识} 259 | \def\kw@Specification{题目要求} 260 | \def\kw@Interaction{交互} 261 | \def\kw@Input{输入格式} 262 | \def\kw@Output{输出格式} 263 | \def\kw@Example{样例} 264 | \def\kw@Examples{样例} 265 | \def\kwExampleNotes{样例说明} 266 | \def\kw@Explanation{样例解释} 267 | \def\kw@Explanations{样例解释} 268 | \def\kw@Illustration{图表说明} 269 | \def\kw@Scoring{评分} 270 | \def\kw@Note{提示} 271 | \def\kw@Notes{提示} 272 | \def\kw@Constraints{约束} 273 | \def\kw@version{版本} 274 | \def\kw@revision{版本} 275 | \def\kw@SubtaskOne{子任务 1} 276 | \def\kw@SubtaskTwo{子任务 2} 277 | \def\kw@SubtaskThree{子任务 3} 278 | \def\kw@SubtaskFour{子任务 4} 279 | \def\kw@SubtaskFive{子任务 5} 280 | \def\kw@SubtaskSix{子任务 6} 281 | \def\kw@Subtask{子任务} 282 | \def\kw@points{分} 283 | \def\kw@Page{Page} 284 | \def\kw@of{of} 285 | \def\kw@notstated{未说明} 286 | \def\kw@IntentionallyBlankPage{此页故意留白} 287 | \def\kw@defaultinputname{test} 288 | \def\kw@defaultoutputname{answer} 289 | \else 290 | \def\kw@ProblemTutorial{Problem Tutorial} 291 | \def\kw@Problem{Problem} 292 | \def\kw@ProblemAuthor{Author:} 293 | \def\kw@ProblemDeveloper{Developer:} 294 | \def\kw@ProblemOrigin{Origin:} 295 | \def\kw@InputFileName{Input file:} 296 | \def\kw@OutputFileName{Output file:} 297 | \def\kw@TimeLimit{Time limit:} 298 | \def\kw@MemoryLimit{Memory limit:} 299 | \def\kw@Feedback{Feedback:} 300 | \def\kw@stdin{standard input} 301 | \def\kw@stdout{standard output} 302 | \def\kw@Specification{Specification} 303 | \def\kw@Interaction{Interaction Protocol} 304 | \def\kw@Input{Input} 305 | \def\kw@Output{Output} 306 | \def\kw@Example{Example} 307 | \def\kw@Examples{Examples} 308 | \def\kwExampleNotes{Notes} 309 | \def\kw@Explanation{Explanation} 310 | \def\kw@Explanations{Explanations} 311 | \def\kw@Illustration{Illustration} 312 | \def\kw@Scoring{Scoring} 313 | \def\kw@Note{Note} 314 | \def\kw@Notes{Notes} 315 | \def\kw@Constraints{Constraints} 316 | \def\kw@version{version} 317 | \def\kw@revision{revision} 318 | \def\kw@SubtaskOne{Subtask 1} 319 | \def\kw@SubtaskTwo{Subtask 2} 320 | \def\kw@SubtaskThree{Subtask 3} 321 | \def\kw@SubtaskFour{Subtask 4} 322 | \def\kw@SubtaskFive{Subtask 5} 323 | \def\kw@SubtaskSix{Subtask 6} 324 | \def\kw@Subtask{Subtask} 325 | \def\kw@points{points} 326 | \def\kw@Page{Page} 327 | \def\kw@of{of} 328 | \def\kw@notstated{not stated} 329 | \def\kw@IntentionallyBlankPage{This page is intentionally left blank} 330 | \def\kw@defaultinputname{test} 331 | \def\kw@defaultoutputname{answer} 332 | \fi 333 | \fi 334 | \fi 335 | 336 | \afterproblemhead=3mm 337 | \afterconstraints=2mm 338 | 339 | \newcommand{\problemheadfont}{\LARGE} 340 | \newcommand{\problemsectionfont}{\Large} 341 | \newcommand{\problemend}{ 342 | \clearpage 343 | \ifintentionallyblankpages 344 | \ifodd\value{page} 345 | \else 346 | \vspace*{\fill} 347 | \begin{center} 348 | \problemheadfont\kw@IntentionallyBlankPage 349 | \end{center} 350 | \vspace*{\fill} 351 | \clearpage 352 | \fi 353 | \fi 354 | } 355 | \newcommand{\problemtextfont}{\normalsize} 356 | \newcommand{\beforeproblemsectioncaption}{\smallbreak\smallskip} 357 | \newcommand{\afterproblemsectioncaption}{\smallskip} 358 | 359 | \if@twocolumn 360 | \afterproblemhead=1mm 361 | \afterconstraints=1mm 362 | \renewcommand{\problemheadfont}{\large} 363 | \renewcommand{\problemsectionfont}{\normalsize} 364 | \renewcommand{\problemend}{\par\medskip} 365 | \renewcommand{\problemtextfont}{\footnotesize} 366 | \renewcommand{\beforeproblemsectioncaption}{\smallbreak\smallskip} 367 | \renewcommand{\afterproblemsectioncaption}{} 368 | \fi 369 | 370 | % -- End of setup keywords -- 371 | 372 | 373 | % -- Problem sections -- 374 | 375 | \newcommand{\createsection}{\@newsection} 376 | 377 | \def\@newsection#1#2{\DeclareRobustCommand{#1}{ 378 | {\beforeproblemsectioncaption\noindent\bf\problemsectionfont 379 | \textsf{#2}} 380 | \nopagebreak\par\afterproblemsectioncaption} 381 | } 382 | 383 | \newcommand{\createsectionpar}{\@newsectionpar} 384 | 385 | \def\@newsectionpar#1#2{\DeclareRobustCommand{#1}[1]{ 386 | {\beforeproblemsectioncaption\noindent\bf\problemsectionfont 387 | \textsf{#2~##1}} 388 | \nopagebreak\par\afterproblemsectioncaption} 389 | } 390 | 391 | \newcommand{\createsectionpartwo}{\@newsectionpartwo} 392 | 393 | \def\@newsectionpartwo#1#2#3{\DeclareRobustCommand{#1}[2]{ 394 | {\beforeproblemsectioncaption\noindent\problemsectionfont 395 | \textsf{\textbf{#2}~\textbf{##1}~(##2~#3)}} 396 | \nopagebreak\par\afterproblemsectioncaption} 397 | } 398 | 399 | \createsection{\Background}{\kw@Background} 400 | \createsection{\Specification}{\kw@Specification} 401 | \createsection{\Interaction}{\kw@Interaction} 402 | \createsection{\InputFile}{\kw@Input} 403 | \createsection{\OutputFile}{\kw@Output} 404 | \createsection{\Example}{\kw@Example} 405 | \createsection{\Examples}{\kw@Examples} 406 | \createsection{\Explanation}{\kw@Explanation} 407 | \createsection{\Explanations}{\kw@Explanations} 408 | \createsection{\Illustration}{\kw@Illustration} 409 | \createsection{\Scoring}{\kw@Scoring} 410 | \createsection{\Note}{\kw@Note} 411 | \createsection{\Notes}{\kw@Notes} 412 | \createsection{\Constraints}{\kw@Constraints} 413 | \createsection{\SubtaskAll}{\kw@Subtask} 414 | \createsection{\SubtaskOne}{\kw@SubtaskOne} 415 | \createsection{\SubtaskTwo}{\kw@SubtaskTwo} 416 | \createsection{\SubtaskThree}{\kw@SubtaskThree} 417 | \createsection{\SubtaskFour}{\kw@SubtaskFour} 418 | \createsection{\SubtaskFive}{\kw@SubtaskFive} 419 | \createsection{\SubtaskSix}{\kw@SubtaskSix} 420 | \createsectionpar{\Subtask}{\kw@Subtask} 421 | \createsectionpartwo{\SubtaskWithCost}{\kw@Subtask}{\kw@points} 422 | 423 | % -- End of problem sections 424 | 425 | % -- Default limits definition -- 426 | 427 | \if@russian 428 | \def\defaulttimelimit{2 секунды} 429 | \else 430 | \if@ukrainian 431 | \def\defaulttimelimit{2 секунди} 432 | \else 433 | \def\defaulttimelimit{2 seconds} 434 | \fi 435 | \fi 436 | 437 | 438 | 439 | \if@russian 440 | \def\defaultmemorylimit{256 мебибайт} 441 | \else 442 | \if@ukrainian 443 | \def\defaulttimelimit{256 мебібайт} 444 | \else 445 | \def\defaultmemorylimit{256 mebibytes} 446 | \fi 447 | \fi 448 | 449 | % -- End of default limits definition -- 450 | 451 | % -- Problem environment -- 452 | 453 | \def\defaultproblemauthor{\textit{\kw@notstated}} 454 | \gdef\thisproblemauthor{\defaultproblemauthor} 455 | \def\defaultproblemdeveloper{\textit{\kw@notstated}} 456 | \gdef\thisproblemdeveloper{\defaultproblemdeveloper} 457 | \def\defaultproblemorigin{\textit{\kw@notstated}} 458 | \gdef\thisproblemorigin{\defaultproblemorigin} 459 | 460 | \newif\ifdisplayauthor 461 | \newif\ifdisplaydeveloper 462 | \newif\ifdisplayorigin 463 | \newif\ifrevisionsignature 464 | \newif\ifdisplayauthorinfooter 465 | \newif\ifdisplaydeveloperinfooter 466 | 467 | \newcounter{problem} 468 | \newcounter{subtasknum}[problem] 469 | 470 | \newcommand{\SubtaskWithScore}[1]{% 471 | {\addtocounter{subtasknum}{1}% 472 | \beforeproblemsectioncaption\noindent\problemsectionfont% 473 | \textsf{\textbf{\kw@Subtask~\arabic{subtasknum}}}% 474 | \textsf{~(\kw@points:~#1)}% 475 | \nopagebreak\par\afterproblemsectioncaption}% 476 | }% 477 | 478 | \newenvironment{tutorial}[1]{% 479 | \bigskip% 480 | \noindent% 481 | \if@russian% 482 | \textbf{\problemheadfont\textsf{\kw@ProblemTutorial\ <<#1>>}}% 483 | \else% 484 | \if@ukrainian% 485 | \textbf{\problemheadfont\textsf{\kw@ProblemTutorial\ <<#1>>}}% 486 | \else% 487 | \textbf{\problemheadfont\textsf{\kw@ProblemTutorial:\ ``#1''}}% 488 | \fi% 489 | \fi% 490 | \nopagebreak% 491 | \problemtextfont% 492 | } 493 | 494 | \newenvironment{@problem}[6]{ 495 | \global\let\lastproblemauthor\thisproblemauthor 496 | \global\let\lastproblemdeveloper\thisproblemdeveloper 497 | \global\let\lastproblemorigin\thisproblemorigin 498 | 499 | % Hotfix 500 | %\def\@memorylimit{#5} 501 | 502 | %% -- Default memory limit -- 503 | %% :FIXME: 504 | %\def\@t{#5} 505 | % 506 | %\ifx\@t\empty 507 | % \def\@memorylimit{\defaultmemorylimit} 508 | %\else 509 | %%\ifcat\par\@t 510 | %% \def\@memorylimit{\defaultmemorylimit} 511 | %%\else 512 | % \def\@memorylimit{#5} 513 | %%\fi 514 | %\fi 515 | %% -- End of default memory limit -- 516 | 517 | % -- No feedback case -- 518 | % :FIXME: 519 | \def\@t{#6} 520 | 521 | \ifx\@t\empty 522 | \def\@feedback{} 523 | \else 524 | %\ifcat\par\@t 525 | % \def\@feedback{} 526 | %\else 527 | \def\@feedback{\kw@Feedback & #6 \\} 528 | \fi 529 | %\fi 530 | % -- End of no feedback case -- 531 | 532 | { 533 | \noindent 534 | \refstepcounter{problem} 535 | \textbf{\problemheadfont\textsf{% 536 | \ifdefined\ShortProblemTitle\else{\kw@Problem\ \if@arabic\arabic{problem}\else\Alph{problem}\fi. }\fi% 537 | #1% 538 | \ifdefined\DivisionNumber% 539 | \if\DivisionNumber2% 540 | {\ \textit{(Division\ \DivisionNumber)}}% 541 | \fi% 542 | \fi% 543 | }}% 544 | \nopagebreak% 545 | \par\vspace{\afterproblemhead}% 546 | \problemtextfont\parindent=6.5mm% 547 | \vbox{ 548 | \begin{tabular}{l@{\extracolsep{1cm}}l} 549 | \ifdisplayauthor% 550 | \kw@ProblemAuthor & \thisproblemauthor \\ 551 | \fi% 552 | \ifdisplaydeveloper% 553 | \kw@ProblemDeveloper & \thisproblemdeveloper \\ 554 | \fi% 555 | \ifdisplayorigin% 556 | \kw@ProblemOrigin & \thisproblemorigin \\ 557 | \fi% 558 | \ifx&% 559 | \else% 560 | \kw@InputFileName & \texttt{#2} \\ 561 | \fi% 562 | \ifx&% 563 | \else% 564 | \kw@OutputFileName & \texttt{#3} \\ 565 | \fi% 566 | \ifx&% 567 | \else% 568 | \kw@TimeLimit & #4 \\ 569 | \fi% 570 | \ifx&% 571 | \else% 572 | \kw@MemoryLimit & #5 \\ 573 | \fi% 574 | % \kw@MemoryLimit & \@memorylimit \\ 575 | \@feedback 576 | \end{tabular} 577 | } 578 | \nopagebreak 579 | \par\vspace{\afterconstraints} 580 | } 581 | \problemtextfont 582 | 583 | \newcommand{\InputFileName}{\ifx\relax#2\relax{\kw@defaultinputname}\else{#2}\fi} 584 | \newcommand{\OutputFileName}{\ifx\relax#3\relax{\kw@defaultoutputname}\else{#3}\fi} 585 | }{% 586 | \global\let\lastproblemauthor\thisproblemauthor% 587 | \global\let\lastproblemdeveloper\thisproblemdeveloper% 588 | \global\let\lastproblemdorigin\thisproblemorigin% 589 | \gdef\thisproblemauthor{\defaultproblemauthor}% 590 | \gdef\thisproblemdeveloper{\defaultproblemdeveloper}% 591 | \gdef\thisproblemorigin{\defaultproblemorigin}% 592 | \problemend% 593 | } 594 | 595 | \def\s@tm@cr@s{ 596 | \def\widthin##1{\exmpwidinf=##1\relax} 597 | \def\widthout##1{\exmpwidouf=##1\relax} 598 | \def\stretchin##1{\advance\exmpwidinf by ##1\relax} 599 | \def\stretchout##1{\advance\exmpwidouf by ##1\relax} 600 | \@ifstar{ 601 | \error Star must not be used in example environment any more 602 | } 603 | } 604 | 605 | % This is magic, which delete space after verbatiminput 606 | \addto@hook{\every@verbatim}{\topsep=0pt\relax} 607 | 608 | % :FIXME: 609 | \newenvironment{example}[1][]{ 610 | \s@tm@cr@s#1 611 | \ttfamily\obeylines\obeyspaces\frenchspacing 612 | \newcommand{\exmp}[2]{ 613 | \begin{minipage}[t]{\exmpwidinf}\rightskip=0pt plus 1fill\relax##1\medskip\end{minipage}& 614 | \begin{minipage}[t]{\exmpwidouf}\rightskip=0pt plus 1fill\relax##2\medskip\end{minipage}\\ 615 | \hline 616 | } 617 | 618 | \newcommand{\exmpfile}[2]{ 619 | \exmp{ 620 | \verbatiminput{##1} 621 | }{ 622 | \verbatiminput{##2} 623 | }% 624 | } 625 | 626 | 627 | \begin{tabular}{|l|l|} 628 | \hline 629 | \multicolumn{1}{|c|}{\bf\texttt{\InputFileName}}& 630 | \multicolumn{1}{|c|}{\bf\texttt{\OutputFileName}}\\ 631 | \hline 632 | }{ 633 | \end{tabular} 634 | } 635 | 636 | \newenvironment{examplewide}[1][]{% 637 | \s@tm@cr@s#1 638 | \ttfamily\obeylines\obeyspaces\frenchspacing 639 | \newcommand{\exmp}[2]{ 640 | \begin{tabular}{|c|} 641 | \hline 642 | \multicolumn{1}{|c|}{\bf\texttt{\InputFileName}}\\ 643 | \hline 644 | \begin{minipage}[t]{\exmpwidewid}\rightskip=0pt plus 1fill\relax 645 | ##1 646 | \medskip\end{minipage}\\ 647 | \hline 648 | \multicolumn{1}{|c|}{\bf\texttt{\OutputFileName}}\\% 649 | \hline 650 | \begin{minipage}[t]{\exmpwidewid}\rightskip=0pt plus 1fill\relax 651 | ##2 652 | \medskip\end{minipage}\\% 653 | \hline 654 | \end{tabular} 655 | } 656 | \newcommand{\exmpfile}[2]{ 657 | \exmp{ 658 | \verbatiminput{##1} 659 | }{ 660 | \verbatiminput{##2} 661 | }% 662 | } 663 | }{ 664 | } 665 | 666 | \newenvironment{examplethree}[1][]{ 667 | \s@tm@cr@s#1 668 | \ttfamily\obeylines\obeyspaces\frenchspacing 669 | \newcommand{\exmp}[3]{ 670 | \begin{minipage}[t]{\exmpthreewidinf}\rightskip=0pt plus 1fill\relax##1\medskip\end{minipage}& 671 | \begin{minipage}[t]{\exmpthreewidouf}\rightskip=0pt plus 1fill\relax##2\medskip\end{minipage}& 672 | \begin{minipage}[t]{\exmpthreewidnote}\rightskip=0pt plus 1fill\relax##3\medskip\end{minipage}\\ 673 | \hline 674 | } 675 | 676 | \newcommand{\exmpfile}[3]{ 677 | \exmp{ 678 | \verbatiminput{##1} 679 | }{ 680 | \verbatiminput{##2} 681 | }{ 682 | ##3 683 | }% 684 | } 685 | 686 | 687 | \begin{tabular}{|l|l|l|} 688 | \hline 689 | \multicolumn{1}{|c|}{\bf\texttt{\InputFileName}}& 690 | \multicolumn{1}{|c|}{\bf\texttt{\OutputFileName}}& 691 | \multicolumn{1}{|c|}{\bf\texttt{\expandafter\unexpanded{\expandafter\kwExampleNotes}}}\\ 692 | \hline 693 | }{ 694 | \end{tabular} 695 | } 696 | 697 | % -- This is hack to make feedback argument optional 698 | 699 | \newenvironment{problem}[5]{% 700 | \def\@ProblemCommon{\begin{@problem}{#1}{#2}{#3}{#4}{#5}}% 701 | \newcommand\@problemSix[1]{\@ProblemCommon{##1}}% 702 | \newcommand\@problemFive{\@ProblemCommon{}}% 703 | \@ifnextchar\bgroup\@problemSix\@problemFive% 704 | }{% 705 | \end{@problem}% 706 | } 707 | 708 | 709 | % -- End of problem environment -- 710 | 711 | 712 | % -- Declare "shortitems" and "shortnums" environment: it's a "compact itemize" -- 713 | \if@twocolumn 714 | \def\shortitems{\vspace{-1mmplus6mm}\itemize\itemsep-0.618mmplus0.5mm\relax}% 715 | \def\endshortitems{\vspace{-1mmplus6mm}\enditemize}% 716 | \def\shortnums{\vspace{-1mmplus6mm}\enumerate\itemsep-0.618mmplus0.5mm\relax}% 717 | \def\endshortnums{\vspace{-1mmplus6mm}\endenumerate}% 718 | \else 719 | \def\shortitems{\vspace{-3mmplus2mm}\itemize\itemsep-1.618mmplus0.5mm\relax}% 720 | \def\endshortitems{\vspace{-3mmplus2mm}\enditemize}% 721 | \def\shortnums{\vspace{-3mmplus2mm}\enumerate\itemsep-1.618mmplus0.5mm\relax}% 722 | \def\endshortnums{\vspace{-3mmplus2mm}\endenumerate}% 723 | \fi 724 | % -- end of "shortitems" and "shortnums" declaration -- 725 | 726 | \newcommand{\thecontestname}{Olympiad in Informatics} 727 | \newcommand{\thecontestlocation}{Somewhere} 728 | \newcommand{\thecontestdate}{Once upon a time} 729 | \newcommand{\therevision}{undefined} 730 | 731 | \DeclareRobustCommand{\contestname}{\thecontestname\par\thecontestlocation\unskip, \thecontestdate} 732 | 733 | \DeclareRobustCommand{\contest}[3]{ 734 | \renewcommand{\thecontestname}{#1} 735 | \renewcommand{\thecontestlocation}{#2} 736 | \renewcommand{\thecontestdate}{#3} 737 | } 738 | 739 | \DeclareRobustCommand{\revision}[1]{ 740 | \renewcommand{\therevision}{#1} 741 | } 742 | 743 | \makeatletter 744 | 745 | \renewcommand{\@oddhead}{ 746 | \parbox{\textwidth}{ 747 | \sffamily\small 748 | \begin{center} 749 | \protect\contestname 750 | \\[2pt] 751 | \hrule 752 | \end{center} 753 | } 754 | } 755 | 756 | \renewcommand{\@oddfoot}{ 757 | \gdef\problemletter{\if@arabic\arabic{problem}\else\Alph{problem}\fi} 758 | 759 | % Revision signature 760 | \ifrevisionsignature% 761 | %\if@revsign% 762 | {\gdef\rsigfooter{, \kw@revision\ \therevision}}% 763 | \else% 764 | {\gdef\rsigfooter{}}% 765 | \fi% 766 | 767 | \ifdisplayauthorinfooter% 768 | %\if@newfooter% 769 | {\gdef\thefooter% 770 | {~\quad{\kw@Problem\ \problemletter% 771 | \ifdefined\DivisionNumber{ (Div.~\DivisionNumber)}\fi}% 772 | {\hfill}% 773 | {\kw@ProblemAuthor~\lastproblemauthor}% 774 | {\hfill}% 775 | {\kw@Page\ \thepage\ \kw@of\ \pageref{LastPage}\rsigfooter}\quad~}}% 776 | \else% 777 | \ifdisplaydeveloperinfooter% 778 | {\gdef\thefooter% 779 | {~\quad{\kw@Problem\ \problemletter}% 780 | {\hfill}% 781 | {\kw@ProblemDeveloper~\lastproblemdeveloper}% 782 | {\hfill}% 783 | {\kw@Page\ \thepage\ \kw@of\ \pageref{LastPage}\rsigfooter}\quad~}}% 784 | \else% 785 | {\gdef\thefooter% 786 | {{\hfil}\kw@Page\ \thepage\ \kw@of\ \pageref{LastPage}\rsigfooter\hfil}}% 787 | \fi% 788 | \fi% 789 | 790 | \parbox{\textwidth}{ 791 | \hrule 792 | \vspace{6pt} 793 | \sffamily 794 | \thefooter 795 | } 796 | } 797 | 798 | \makeatother 799 | 800 | \headheight=2cm 801 | \headsep=6mm 802 | 803 | \hfuzz=0.5pt 804 | 805 | \sloppy --------------------------------------------------------------------------------