├── .gitignore ├── LICENSE ├── README-img ├── example.gif ├── markdown.png └── render.png ├── README.md ├── code ├── AtCoder │ └── abc371 │ │ ├── a │ │ ├── a.cpp │ │ ├── a_input0.txt │ │ ├── a_input1.txt │ │ ├── a_output0.txt │ │ └── a_output1.txt │ │ ├── b │ │ ├── b.cpp │ │ ├── b_input0.txt │ │ ├── b_input1.txt │ │ ├── b_output0.txt │ │ └── b_output1.txt │ │ ├── c │ │ ├── c.cpp │ │ ├── c_input0.txt │ │ ├── c_input1.txt │ │ ├── c_input2.txt │ │ ├── c_input3.txt │ │ ├── c_input4.txt │ │ ├── c_output0.txt │ │ ├── c_output1.txt │ │ ├── c_output2.txt │ │ ├── c_output3.txt │ │ └── c_output4.txt │ │ ├── d │ │ ├── d.cpp │ │ ├── d_input0.txt │ │ ├── d_input1.txt │ │ ├── d_output0.txt │ │ └── d_output1.txt │ │ ├── e │ │ ├── e.cpp │ │ ├── e_input0.txt │ │ ├── e_input1.txt │ │ ├── e_output0.txt │ │ └── e_output1.txt │ │ ├── f │ │ ├── f.cpp │ │ ├── f_input0.txt │ │ ├── f_input1.txt │ │ ├── f_input2.txt │ │ ├── f_output0.txt │ │ ├── f_output1.txt │ │ └── f_output2.txt │ │ └── g │ │ ├── g.cpp │ │ ├── g_input0.txt │ │ ├── g_input1.txt │ │ ├── g_input2.txt │ │ ├── g_output0.txt │ │ ├── g_output1.txt │ │ └── g_output2.txt ├── cf │ ├── contest │ │ └── 1857 │ │ │ ├── a │ │ │ ├── a.cpp │ │ │ ├── testI1.txt │ │ │ └── testO1.txt │ │ │ ├── b │ │ │ ├── b.cpp │ │ │ ├── testI1.txt │ │ │ └── testO1.txt │ │ │ ├── c │ │ │ ├── c.cpp │ │ │ ├── testI1.txt │ │ │ └── testO1.txt │ │ │ ├── d │ │ │ ├── d.cpp │ │ │ ├── testI1.txt │ │ │ └── testO1.txt │ │ │ ├── e │ │ │ ├── e.cpp │ │ │ ├── testI1.txt │ │ │ └── testO1.txt │ │ │ ├── f │ │ │ ├── f.cpp │ │ │ ├── testI1.txt │ │ │ └── testO1.txt │ │ │ └── g │ │ │ ├── g.cpp │ │ │ ├── testI1.txt │ │ │ └── testO1.txt │ └── gym │ │ └── 101522 │ │ ├── e │ │ ├── e.cpp │ │ ├── testI1.txt │ │ ├── testI2.txt │ │ ├── testI3.txt │ │ ├── testO1.txt │ │ ├── testO2.txt │ │ └── testO3.txt │ │ └── h │ │ ├── h.cpp │ │ ├── testI1.txt │ │ ├── testI2.txt │ │ ├── testO1.txt │ │ └── testO2.txt └── nowcoder │ └── contests │ └── 49259 │ ├── a │ └── a.cpp │ ├── b │ └── b.cpp │ ├── c │ └── c.cpp │ ├── d │ └── d.cpp │ ├── e │ └── e.cpp │ ├── f │ └── f.cpp │ ├── g │ └── g.cpp │ ├── h │ └── h.cpp │ ├── i │ └── i.cpp │ ├── k │ └── k.cpp │ ├── l │ └── l.cpp │ └── m │ └── m.cpp ├── main.py ├── parser ├── __init__.py ├── atcoder.py ├── base.py ├── codeforces.py ├── nowcoder.py └── parser.py └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | #.idea/ 161 | .DS_Store 162 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README-img/example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lanly109/Solution-Markdown-Template-For-Algorithm-Contest/4f0cc5110c99afeac0570020e74e370b93b0d714/README-img/example.gif -------------------------------------------------------------------------------- /README-img/markdown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lanly109/Solution-Markdown-Template-For-Algorithm-Contest/4f0cc5110c99afeac0570020e74e370b93b0d714/README-img/markdown.png -------------------------------------------------------------------------------- /README-img/render.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lanly109/Solution-Markdown-Template-For-Algorithm-Contest/4f0cc5110c99afeac0570020e74e370b93b0d714/README-img/render.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Solution Markdown Template For Algorithm Contest 2 | 3 | [![License](https://img.shields.io/github/license/Lanly109/Solution-Markdown-Template-For-Algorithm-Contest)](LICENSE) 4 | ![Python Version](https://img.shields.io/badge/Python-3.0+-blue) 5 | 6 | 一键生成带有丰富文本的题解的Markdown文件,让你爱上写题解! 7 | 8 | ## 前排提示 9 | 10 | ### 2024.09.22 11 | 12 | 脚本访问`codeforces`会`403`,由于本人很少打,修正可能是很久以后~~也可能不会,欢迎pr~~,不过`atcoder`和`nowcoder`仍可以使用。 13 | 14 | ## 功能介绍 15 | 16 | ![example](README-img/example.gif) 17 | 18 | 一个好的题解,应该不仅包含题目的做法,还应该包含题目链接、题号检索、题目大意、AC代码,这样不仅方便别人阅读,更方便自己以后重温题目、归档代码。 19 | 20 | 但是复制粘贴题目链接、题号、AC代码非常繁琐,特别是一场有13道题的区域赛,其复制粘贴往往非常繁琐,容易消磨写题解的精力,因此本脚本可以帮助你省去这些繁琐的操作,让你专注于`题目大意`和`解题思路`的记录! 21 | 22 | 输入比赛的`url`(支持[atcoder](https://atcoder.jp),[codeforces](https://codeforces.com),[nowcoder](https://ac.nowcoder.com)),该脚本可以一键生成关于该比赛的所有题目的题解模板,包含题目名字、题目链接、自己编写的代码。 23 | 24 | 需要自己填写的用`<++>`标识。这样可以更专注于`题目大意`和`解题思路`的编写,省去了其余的繁琐操作。 25 | 26 | ![markdown](README-img/markdown.png) 27 | 28 | 29 | 生成文件预览(预览样式与采用的渲染引擎有关) 30 | 31 | ![render](README-img/render.png) 32 | 33 | 如果使用`vim`编写,可以在`.vimrc`里添加以下代码 34 | 35 | ```bash 36 | " Press space twice to jump to the next '<++>' and edit it 37 | noremap /<++>:nohlsearchc4l 38 | ``` 39 | 40 | 连续敲两次空格后,光标会自动查找并替换下一个`<++>`,这样可以无间断的书写`题目大意`和`解题思路`部分。 41 | 42 | ## 安装 43 | 44 | ```bash 45 | git clone https://github.com/Lanly109/Solution-Markdown-Template-For-Algorithm-Contest.git 46 | cd Solution-Markdown-Template-For-Algorithm-Contest 47 | pip3 install -r requirements.txt 48 | ``` 49 | 50 | ## 使用 51 | 52 | 修改`parser/atcoder.py,codeforces.py,nowcoder.py`的`code_path`函数返回值为自己代码的根目录。 53 | 54 | 代码存放结构参考[cf-tool](https://github.com/xalanq/cf-tool) 55 | 56 | 对于`atcoder.py`,其代码存放格式为 57 | ```bash 58 | . 59 | ├── abc171 60 | │   ├── a 61 | │   │   └── a.cpp 62 | │   └── f 63 | │   └── f.cpp 64 | ├── abc172 65 | │   ├── e 66 | │   │   └── e.cpp 67 | │   └── f 68 | │   └── f.cpp 69 | └── arc155 70 |    └── a 71 |       └── a.cpp 72 | ``` 73 | 74 | 对于`codeforces.py`,其代码存放格式为 75 | 76 | ```bash 77 | . 78 | ├── contest 79 | │   ├── 1054 80 | │   │   ├── a 81 | │   │   │   └── a.cpp 82 | │   │   ├── b 83 | │   │   │   └── b.cpp 84 | │   └── 1060 85 | │     ├── b 86 | │      │   └── b.cpp 87 | │      ├── d 88 | │      │   └── d.cpp 89 | │      └── e 90 | │         └── e.cpp 91 | └── gym 92 |    ├── 100405 93 |    │   ├── a 94 |    │   │   └── a.cpp 95 |    │   ├── c 96 |    │   │   └── c.cpp 97 |    │   └── f 98 |    │   └── f.cpp 99 |    ├── 100851 100 |    │   ├── a 101 |    │   │   └── a.cpp 102 |    │   └── l 103 |    │   └── l.cpp 104 |    └── 101173 105 |       ├── a 106 |       │   └── a.cpp 107 |       ├── h 108 |       │   └── h.cpp 109 |       └── k 110 |       └── k.cpp 111 | ``` 112 | 113 | 对于`nowcoder.py`,其代码存放格式为 114 | 115 | ```bash 116 | . 117 | ├── 33911 118 | │   ├── a 119 | │   │   └── a.cpp 120 | │   ├── e 121 | │   │   └── e.cpp 122 | │   └── g 123 | │      └── g.cpp 124 | └── 48458 125 |    ├── a 126 |    │   └── a.cpp 127 |    ├── c 128 |    │   └── c.cpp 129 |    └── d 130 |    └── d.cpp 131 | 132 | ``` 133 | 134 | 然后于终端运行 135 | 136 | ```bash 137 | python3 ./main.py 138 | ``` 139 | 140 | 其中`url`可以是`atcoder,codeforces,nowcoder`之间的一个,比如 141 | 142 | ```bash 143 | python3 ./main.py https://atcoder.jp/contests/abc306/tasks 144 | python3 ./main.py https://codeforces.com/contest/1834 145 | python3 ./main.py https://codeforces.com/gym/104010 146 | python3 ./main.py https://ac.nowcoder.com/acm/contest/5157 147 | ``` 148 | 149 | 当然,如果你不喜欢命令行输入`url`,可以修改`main.py`,在代码里写入`url`,然后直接运行。 150 | 151 | ```bash 152 | python3 ./main.py 153 | ``` 154 | 155 | 如有需要,可自行更改`./parser/base.py`里的`header`和`template`函数,适应自己的`hexo`博客或个性化博文样式。 156 | 157 | ## 更新日志 158 | 159 | ### 2024.09.22 160 | 161 | - 新增示例代码文件夹 162 | - 新增【省流版】内容 163 | 164 | ### 2023.06.19 165 | 166 | - 重构代码,发布 167 | 168 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/a/a.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2024-09-14 20:01:20 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | using LL = long long; 9 | #define FOR(i, x, y) \ 10 | for (decay::type i = (x), _##i = (y); i < _##i; ++i) 11 | #define FORD(i, x, y) \ 12 | for (decay::type i = (x), _##i = (y); i > _##i; --i) 13 | 14 | #ifndef ONLINE_JUDGE 15 | #include "debug.h" 16 | #else 17 | #define debug(x...) 18 | #endif 19 | 20 | int main(void) { 21 | ios::sync_with_stdio(false); 22 | cin.tie(0); 23 | cout.tie(0); 24 | string a, b, c; 25 | cin >> a >> b >> c; 26 | array id{}; 27 | iota(id.begin(), id.end(), 0); 28 | map, int> mp; 29 | mp[{0, 1}] = a[0] == '>'; 30 | mp[{1, 0}] = a[0] == '<'; 31 | mp[{0, 2}] = b[0] == '>'; 32 | mp[{2, 0}] = b[0] == '<'; 33 | mp[{1, 2}] = c[0] == '>'; 34 | mp[{2, 1}] = c[0] == '<'; 35 | sort(id.begin(), id.end(), [&](int x, int y) { return mp[{x, y}]; }); 36 | string ans = "ABC"; 37 | cout << ans[id[1]] << '\n'; 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/a/a_input0.txt: -------------------------------------------------------------------------------- 1 | < < < 2 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/a/a_input1.txt: -------------------------------------------------------------------------------- 1 | < < > 2 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/a/a_output0.txt: -------------------------------------------------------------------------------- 1 | B 2 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/a/a_output1.txt: -------------------------------------------------------------------------------- 1 | C 2 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/b/b.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2024-09-14 20:05:18 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | using LL = long long; 9 | #define FOR(i, x, y) \ 10 | for (decay::type i = (x), _##i = (y); i < _##i; ++i) 11 | #define FORD(i, x, y) \ 12 | for (decay::type i = (x), _##i = (y); i > _##i; --i) 13 | 14 | #ifndef ONLINE_JUDGE 15 | #include "debug.h" 16 | #else 17 | #define debug(x...) 18 | #endif 19 | 20 | int main(void) { 21 | ios::sync_with_stdio(false); 22 | cin.tie(0); 23 | cout.tie(0); 24 | int n, m; 25 | cin >> n >> m; 26 | vector tora(n, 0); 27 | while (m--) { 28 | int f; 29 | string s; 30 | cin >> f >> s; 31 | --f; 32 | if (s[0] == 'F' || tora[f]) { 33 | cout << "No" << '\n'; 34 | } else { 35 | tora[f] = 1; 36 | cout << "Yes" << '\n'; 37 | } 38 | } 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/b/b_input0.txt: -------------------------------------------------------------------------------- 1 | 2 4 2 | 1 M 3 | 1 M 4 | 2 F 5 | 2 M 6 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/b/b_input1.txt: -------------------------------------------------------------------------------- 1 | 4 7 2 | 2 M 3 | 3 M 4 | 1 F 5 | 4 F 6 | 4 F 7 | 1 F 8 | 2 M 9 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/b/b_output0.txt: -------------------------------------------------------------------------------- 1 | Yes 2 | No 3 | No 4 | Yes 5 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/b/b_output1.txt: -------------------------------------------------------------------------------- 1 | Yes 2 | Yes 3 | No 4 | No 5 | No 6 | No 7 | No 8 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/c/c.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2024-09-14 20:09:48 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | using LL = long long; 9 | #define FOR(i, x, y) \ 10 | for (decay::type i = (x), _##i = (y); i < _##i; ++i) 11 | #define FORD(i, x, y) \ 12 | for (decay::type i = (x), _##i = (y); i > _##i; --i) 13 | 14 | #ifndef ONLINE_JUDGE 15 | #include "debug.h" 16 | #else 17 | #define debug(x...) 18 | #endif 19 | 20 | int main(void) { 21 | ios::sync_with_stdio(false); 22 | cin.tie(0); 23 | cout.tie(0); 24 | int n; 25 | cin >> n; 26 | array m{}; 27 | array>, 2> edge{vector>(n, vector(n)), 28 | vector>(n, vector(n))}; 29 | for (int k = 0; k < 2; ++k) { 30 | cin >> m[k]; 31 | for (int i = 0; i < m[k]; ++i) { 32 | int u, v; 33 | cin >> u >> v; 34 | --u, --v; 35 | edge[k][u][v] = edge[k][v][u] = 1; 36 | } 37 | } 38 | vector> a(n, vector(n, 0)); 39 | for (int i = 0; i < n; ++i) 40 | for (int j = i + 1; j < n; ++j) { 41 | cin >> a[i][j]; 42 | a[j][i] = a[i][j]; 43 | } 44 | vector id(n); 45 | iota(id.begin(), id.end(), 0); 46 | int ans = 1e9 + 7; 47 | auto solve = [&](vector id) { 48 | int res = 0; 49 | for (int i = 0; i < n; ++i) { 50 | for (int j = i + 1; j < n; ++j) { 51 | if (edge[0][id[i]][id[j]] != edge[1][i][j]) { 52 | res += a[i][j]; 53 | } 54 | } 55 | } 56 | return res; 57 | }; 58 | do { 59 | ans = min(ans, solve(id)); 60 | } while (next_permutation(id.begin(), id.end())); 61 | 62 | cout << ans << '\n'; 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/c/c_input0.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 4 3 | 1 2 4 | 2 3 5 | 3 4 6 | 4 5 7 | 4 8 | 1 2 9 | 1 3 10 | 1 4 11 | 1 5 12 | 3 1 4 1 13 | 5 9 2 14 | 6 5 15 | 3 16 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/c/c_input1.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 3 3 | 1 2 4 | 2 3 5 | 3 4 6 | 4 7 | 1 2 8 | 2 3 9 | 3 4 10 | 4 5 11 | 9 1 1 1 12 | 1 1 1 13 | 1 1 14 | 9 15 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/c/c_input2.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 3 3 | 1 2 4 | 2 3 5 | 3 4 6 | 4 7 | 1 2 8 | 2 3 9 | 3 4 10 | 4 5 11 | 5 4 4 4 12 | 4 4 4 13 | 4 4 14 | 5 15 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/c/c_input3.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 0 3 | 0 4 | 371 5 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/c/c_input4.txt: -------------------------------------------------------------------------------- 1 | 8 2 | 13 3 | 1 8 4 | 5 7 5 | 4 6 6 | 1 5 7 | 7 8 8 | 1 6 9 | 1 2 10 | 5 8 11 | 2 6 12 | 5 6 13 | 6 7 14 | 3 7 15 | 4 8 16 | 15 17 | 3 5 18 | 1 7 19 | 4 6 20 | 3 8 21 | 7 8 22 | 1 2 23 | 5 6 24 | 1 6 25 | 1 5 26 | 1 4 27 | 2 8 28 | 2 6 29 | 2 4 30 | 4 7 31 | 1 3 32 | 7483 1694 5868 3296 9723 5299 4326 33 | 5195 4088 5871 1384 2491 6562 34 | 1149 6326 2996 9845 7557 35 | 4041 7720 1554 5060 36 | 8329 8541 3530 37 | 4652 3874 38 | 3748 39 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/c/c_output0.txt: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/c/c_output1.txt: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/c/c_output2.txt: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/c/c_output3.txt: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/c/c_output4.txt: -------------------------------------------------------------------------------- 1 | 21214 2 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/d/d.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2024-09-14 20:17:37 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | using LL = long long; 9 | #define FOR(i, x, y) \ 10 | for (decay::type i = (x), _##i = (y); i < _##i; ++i) 11 | #define FORD(i, x, y) \ 12 | for (decay::type i = (x), _##i = (y); i > _##i; --i) 13 | 14 | #ifndef ONLINE_JUDGE 15 | #include "debug.h" 16 | #else 17 | #define debug(x...) 18 | #endif 19 | 20 | int main(void) { 21 | ios::sync_with_stdio(false); 22 | cin.tie(0); 23 | cout.tie(0); 24 | int n; 25 | cin >> n; 26 | vector x(n); 27 | for (auto& i : x) 28 | cin >> i; 29 | vector p(n); 30 | for (auto& i : p) 31 | cin >> i; 32 | vector presum(n); 33 | partial_sum(p.begin(), p.end(), presum.begin()); 34 | auto get_sum = [&](int l, int r) { 35 | if (l > r) 36 | return 0ll; 37 | return presum[r] - (l ? presum[l - 1] : 0); 38 | }; 39 | int q; 40 | cin >> q; 41 | while (q--) { 42 | int l, r; 43 | cin >> l >> r; 44 | auto L = lower_bound(x.begin(), x.end(), l) - x.begin(); 45 | auto R = upper_bound(x.begin(), x.end(), r) - x.begin(); 46 | cout << get_sum(L, R - 1) << '\n'; 47 | } 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/d/d_input0.txt: -------------------------------------------------------------------------------- 1 | 4 2 | 1 3 5 7 3 | 1 2 3 4 4 | 4 5 | 1 1 6 | 2 6 7 | 0 10 8 | 2 2 9 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/d/d_input1.txt: -------------------------------------------------------------------------------- 1 | 7 2 | -10 -5 -3 -1 0 1 4 3 | 2 5 6 5 2 1 7 4 | 8 5 | -7 7 6 | -1 5 7 | -10 -4 8 | -8 10 9 | -5 0 10 | -10 5 11 | -8 7 12 | -8 -3 13 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/d/d_output0.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 5 3 | 10 4 | 0 5 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/d/d_output1.txt: -------------------------------------------------------------------------------- 1 | 26 2 | 15 3 | 7 4 | 26 5 | 18 6 | 28 7 | 26 8 | 11 9 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/e/e.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2024-09-14 20:29:08 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | using LL = long long; 9 | #define FOR(i, x, y) \ 10 | for (decay::type i = (x), _##i = (y); i < _##i; ++i) 11 | #define FORD(i, x, y) \ 12 | for (decay::type i = (x), _##i = (y); i > _##i; --i) 13 | 14 | #ifndef ONLINE_JUDGE 15 | #include "debug.h" 16 | #else 17 | #define debug(x...) 18 | #endif 19 | 20 | int main(void) { 21 | ios::sync_with_stdio(false); 22 | cin.tie(0); 23 | cout.tie(0); 24 | int n; 25 | cin >> n; 26 | vector a(n); 27 | for (auto& i : a) { 28 | cin >> i; 29 | --i; 30 | } 31 | vector r(n); 32 | vector pos(n, n); 33 | for (int i = n - 1; i >= 0; --i) { 34 | r[i] = pos[a[i]]; 35 | pos[a[i]] = i; 36 | } 37 | fill(pos.begin(), pos.end(), 0); 38 | LL ans = 0; 39 | for (int i = 0; i < n; ++i) { 40 | int lcnt = i + 1; 41 | int rcnt = r[i] - i; 42 | ans += 1ll * lcnt * rcnt; 43 | } 44 | cout << ans << '\n'; 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/e/e_input0.txt: -------------------------------------------------------------------------------- 1 | 3 2 | 1 2 2 3 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/e/e_input1.txt: -------------------------------------------------------------------------------- 1 | 9 2 | 5 4 2 2 3 2 4 4 1 3 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/e/e_output0.txt: -------------------------------------------------------------------------------- 1 | 8 2 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/e/e_output1.txt: -------------------------------------------------------------------------------- 1 | 111 2 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/f/f.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2024-09-15 10:22:08 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | using LL = long long; 9 | #define FOR(i, x, y) \ 10 | for (decay::type i = (x), _##i = (y); i < _##i; ++i) 11 | #define FORD(i, x, y) \ 12 | for (decay::type i = (x), _##i = (y); i > _##i; --i) 13 | 14 | #ifndef ONLINE_JUDGE 15 | #include "debug.h" 16 | #else 17 | #define debug(x...) 18 | #endif 19 | 20 | struct Block { 21 | int l, r, id; 22 | bool operator<(const Block& b) const { return id < b.id; } 23 | inline int cnt() const { return r - l + 1; } 24 | inline int lid() const { return id; } 25 | inline int rid() const { return id + cnt() - 1; } 26 | bool intersect(const Block& b, int is_right) const { 27 | if (is_right) 28 | return r >= b.l; 29 | else 30 | return l <= b.r; 31 | } 32 | pair cut(int t) const { 33 | int cnt = t - id; 34 | return {{l, l + cnt - 1, id}, {l + cnt, r, id + cnt}}; 35 | } 36 | Block shift(int dis) const { 37 | auto ret = *this; 38 | ret.l += dis; 39 | ret.r += dis; 40 | return ret; 41 | } 42 | Block merge(const Block& b) const { 43 | assert(r + 1 == b.l || b.r + 1 == l); 44 | return {min(l, b.l), max(r, b.r), min(id, b.id)}; 45 | } 46 | }; 47 | 48 | int main(void) { 49 | ios::sync_with_stdio(false); 50 | cin.tie(0); 51 | cout.tie(0); 52 | int n; 53 | cin >> n; 54 | set p; 55 | for (int i = 0; i < n; ++i) { 56 | int x; 57 | cin >> x; 58 | p.insert({x, x, i}); 59 | } 60 | auto get_block = [&](int t) { 61 | auto it = prev(p.upper_bound({0, 0, t})); 62 | return it; 63 | }; 64 | auto get_pos = [&](int t) { 65 | auto it = get_block(t); 66 | int ret = it->l + t - it->id; 67 | return ret; 68 | }; 69 | auto shift_block = [&](int t, int g) { 70 | auto it = *get_block(t); 71 | auto dis = g - get_pos(t); 72 | it.l += dis; 73 | it.r += dis; 74 | return it; 75 | }; 76 | auto solve = [&](int t, int g) { 77 | LL sum = 0; 78 | while (true) { 79 | int pos = get_pos(t); 80 | if (pos == g) 81 | break; 82 | auto it = get_block(t); 83 | if (pos < g) { 84 | if (it->lid() != t) { 85 | auto [lblock, rblock] = it->cut(t); 86 | p.erase(it); 87 | p.insert(lblock); 88 | p.insert(rblock); 89 | } else { 90 | auto sit = shift_block(t, g); 91 | auto nit = next(it); 92 | if (nit == p.end() || !sit.intersect(*nit, true)) { 93 | sum += 1ll * it->cnt() * (g - pos); 94 | p.erase(it); 95 | p.insert(sit); 96 | } else { 97 | auto shift = nit->l - it->r - 1; 98 | sum += 1ll * sit.cnt() * shift; 99 | sit = it->shift(shift); 100 | auto nblock = sit.merge(*nit); 101 | auto tmp = *nit; 102 | p.erase(it); 103 | p.erase(tmp); 104 | p.insert(nblock); 105 | } 106 | } 107 | } else { 108 | if (it->rid() != t) { 109 | auto [lblock, rblock] = it->cut(t + 1); 110 | p.erase(it); 111 | p.insert(lblock); 112 | p.insert(rblock); 113 | } else { 114 | auto sit = shift_block(t, g); 115 | if (it == p.begin() || !sit.intersect(*prev(it), false)) { 116 | sum += 1ll * sit.cnt() * (pos - g); 117 | p.erase(it); 118 | p.insert(sit); 119 | } else { 120 | auto pit = prev(it); 121 | auto shift = it->l - pit->r - 1; 122 | sum += 1ll * sit.cnt() * shift; 123 | sit = it->shift(-shift); 124 | auto nblock = sit.merge(*pit); 125 | auto tmp = *pit; 126 | p.erase(it); 127 | p.erase(tmp); 128 | p.insert(nblock); 129 | } 130 | } 131 | } 132 | } 133 | return sum; 134 | }; 135 | int q; 136 | cin >> q; 137 | LL ans = 0; 138 | while (q--) { 139 | int t, g; 140 | cin >> t >> g; 141 | --t; 142 | LL ret = solve(t, g); 143 | ans += ret; 144 | } 145 | cout << ans << '\n'; 146 | 147 | return 0; 148 | } 149 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/f/f_input0.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 10 20 30 40 50 3 | 4 4 | 3 45 5 | 4 20 6 | 1 35 7 | 2 60 8 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/f/f_input1.txt: -------------------------------------------------------------------------------- 1 | 8 2 | 0 1 2 3 4 5 6 100000000 3 | 6 4 | 1 100000000 5 | 8 0 6 | 1 100000000 7 | 8 4 8 | 1 100000000 9 | 5 21006578 10 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/f/f_input2.txt: -------------------------------------------------------------------------------- 1 | 12 2 | 1558 3536 3755 3881 4042 4657 5062 7558 7721 8330 8542 9845 3 | 8 4 | 9 1694 5 | 7 3296 6 | 12 5299 7 | 5 5195 8 | 5 5871 9 | 1 2491 10 | 8 1149 11 | 8 2996 12 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/f/f_output0.txt: -------------------------------------------------------------------------------- 1 | 239 2 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/f/f_output1.txt: -------------------------------------------------------------------------------- 1 | 4294967297 2 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/f/f_output2.txt: -------------------------------------------------------------------------------- 1 | 89644 2 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/g/g.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2024-09-14 20:40:43 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | using LL = __int128; 9 | #define FOR(i, x, y) \ 10 | for (decay::type i = (x), _##i = (y); i < _##i; ++i) 11 | #define FORD(i, x, y) \ 12 | for (decay::type i = (x), _##i = (y); i > _##i; --i) 13 | 14 | #ifndef ONLINE_JUDGE 15 | #include "debug.h" 16 | #else 17 | #define debug(x...) 18 | #endif 19 | 20 | LL x, y, d; 21 | 22 | void exgcd(LL& x, LL& y, LL a, LL b) { 23 | if (!b) 24 | d = a, x = 1, y = 0; 25 | else 26 | exgcd(y, x, b, a % b), y -= a / b * x; 27 | } 28 | 29 | LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; } 30 | 31 | LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } 32 | 33 | LL a, b, A, B; 34 | 35 | void merge() { 36 | exgcd(x, y, a, A); 37 | LL c = B - b; 38 | assert(c % d == 0); 39 | x = x * c / d % (A / d); 40 | if (x < 0) 41 | x += A / d; 42 | LL mod = lcm(a, A); 43 | b = (a * x + b) % mod; 44 | if (b < 0) 45 | b += mod; 46 | a = mod; 47 | } 48 | 49 | int main(void) { 50 | freopen("input.txt", "r", stdin); 51 | ios::sync_with_stdio(false); 52 | cin.tie(0); 53 | cout.tie(0); 54 | int n; 55 | cin >> n; 56 | vector p(n), v(n); 57 | for (auto& i : p) { 58 | cin >> i; 59 | --i; 60 | } 61 | for (auto& i : v) 62 | cin >> i; 63 | vector> cir; 64 | vector vis(n); 65 | for (int i = 0; i < n; ++i) { 66 | if (vis[i]) 67 | continue; 68 | vector h{i}; 69 | for (int j = p[i]; j != i; j = p[j]) { 70 | vis[j] = 1; 71 | h.push_back(j); 72 | } 73 | cir.push_back(h); 74 | } 75 | a = 1; 76 | b = 0; 77 | for (int i = 0; i < cir.size(); ++i) { 78 | auto& h = cir[i]; 79 | int id = b % h.size(); 80 | vector used(h.size(), 0); 81 | for (int i = id;; i = (i + a) % h.size()) { 82 | if (used[i]) 83 | break; 84 | used[i] = 1; 85 | if (v[h[i]] < v[h[id]]) 86 | id = i; 87 | } 88 | A = h.size(); 89 | B = id; 90 | if (i > 0) 91 | merge(); 92 | else 93 | a = A, b = B; 94 | } 95 | LL step = b % a; 96 | vector ans(n); 97 | for (auto& h : cir) { 98 | for (int i = 0, j = step % h.size(); i < h.size(); 99 | i++, j = (j + 1) % h.size()) { 100 | ans[h[i]] = v[h[j]]; 101 | } 102 | } 103 | for (int i = 0; i < n; ++i) { 104 | cout << ans[i] << " \n"[i == n - 1]; 105 | } 106 | 107 | return 0; 108 | } 109 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/g/g_input0.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 3 1 5 6 2 4 3 | 4 3 1 6 2 5 4 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/g/g_input1.txt: -------------------------------------------------------------------------------- 1 | 8 2 | 3 5 8 7 2 6 1 4 3 | 1 2 3 4 5 6 7 8 4 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/g/g_input2.txt: -------------------------------------------------------------------------------- 1 | 26 2 | 24 14 4 20 15 19 16 11 23 22 12 18 21 3 6 8 26 2 25 7 13 1 5 9 17 10 3 | 15 3 10 1 13 19 22 24 20 4 14 23 7 26 25 18 11 6 9 12 2 21 5 16 8 17 4 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/g/g_output0.txt: -------------------------------------------------------------------------------- 1 | 1 4 2 5 3 6 2 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/g/g_output1.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 6 7 8 2 | -------------------------------------------------------------------------------- /code/AtCoder/abc371/g/g_output2.txt: -------------------------------------------------------------------------------- 1 | 4 1 22 18 20 13 14 6 15 11 3 26 2 12 5 23 9 10 25 24 7 17 16 21 19 8 2 | -------------------------------------------------------------------------------- /code/cf/contest/1857/a/a.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2023-08-08 15:27:02 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | using LL = long long; 9 | #define FOR(i, x, y) \ 10 | for (decay::type i = (x), _##i = (y); i < _##i; ++i) 11 | #define FORD(i, x, y) \ 12 | for (decay::type i = (x), _##i = (y); i > _##i; --i) 13 | 14 | #ifndef ONLINE_JUDGE 15 | #include "debug.h" 16 | #else 17 | #define debug(x...) 18 | #endif 19 | 20 | int main(void) { 21 | ios::sync_with_stdio(false); 22 | cin.tie(0); 23 | cout.tie(0); 24 | int t; 25 | cin >> t; 26 | while (t--) { 27 | int n; 28 | cin >> n; 29 | int odd = 0; 30 | while (n--) { 31 | int a; 32 | cin >> a; 33 | odd += (a & 1); 34 | } 35 | if (odd & 1) 36 | cout << "NO" << '\n'; 37 | else 38 | cout << "YES" << '\n'; 39 | } 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /code/cf/contest/1857/a/testI1.txt: -------------------------------------------------------------------------------- 1 | 7 2 | 8 3 | 1 2 4 3 2 3 5 4 4 | 2 5 | 4 7 6 | 3 7 | 3 9 8 8 | 2 9 | 1 7 10 | 5 11 | 5 4 3 2 1 12 | 4 13 | 4 3 4 5 14 | 2 15 | 50 48 16 | -------------------------------------------------------------------------------- /code/cf/contest/1857/a/testO1.txt: -------------------------------------------------------------------------------- 1 | YES 2 | NO 3 | YES 4 | YES 5 | NO 6 | YES 7 | YES 8 | -------------------------------------------------------------------------------- /code/cf/contest/1857/b/b.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2023-08-08 15:32:30 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | using LL = long long; 9 | #define FOR(i, x, y) \ 10 | for (decay::type i = (x), _##i = (y); i < _##i; ++i) 11 | #define FORD(i, x, y) \ 12 | for (decay::type i = (x), _##i = (y); i > _##i; --i) 13 | 14 | #ifndef ONLINE_JUDGE 15 | #include "debug.h" 16 | #else 17 | #define debug(x...) 18 | #endif 19 | 20 | int main(void) { 21 | ios::sync_with_stdio(false); 22 | cin.tie(0); 23 | cout.tie(0); 24 | int t; 25 | cin >> t; 26 | while (t--) { 27 | string s; 28 | cin >> s; 29 | if (s.front() >= '5') { 30 | string ans = "1" + string(s.size(), '0'); 31 | cout << ans << '\n'; 32 | } else { 33 | int pos = s.size(); 34 | for (int i = s.size() - 1; i >= 1; --i) { 35 | if (s[i] >= '5') { 36 | s[i - 1]++; 37 | s[i] = '0'; 38 | pos = i; 39 | } 40 | } 41 | if (s.front() >= '5') { 42 | string ans = "1" + string(s.size(), '0'); 43 | cout << ans << '\n'; 44 | } else { 45 | cout << s.substr(0, pos) + string(s.size() - pos, '0') << '\n'; 46 | } 47 | } 48 | } 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /code/cf/contest/1857/b/testI1.txt: -------------------------------------------------------------------------------- 1 | 10 2 | 1 3 | 5 4 | 99 5 | 913 6 | 1980 7 | 20444 8 | 20445 9 | 60947 10 | 419860 11 | 40862016542130810467 12 | -------------------------------------------------------------------------------- /code/cf/contest/1857/b/testO1.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 10 3 | 100 4 | 1000 5 | 2000 6 | 20444 7 | 21000 8 | 100000 9 | 420000 10 | 41000000000000000000 11 | -------------------------------------------------------------------------------- /code/cf/contest/1857/c/c.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2023-08-08 15:44:26 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | using LL = long long; 9 | #define FOR(i, x, y) \ 10 | for (decay::type i = (x), _##i = (y); i < _##i; ++i) 11 | #define FORD(i, x, y) \ 12 | for (decay::type i = (x), _##i = (y); i > _##i; --i) 13 | 14 | #ifndef ONLINE_JUDGE 15 | #include "debug.h" 16 | #else 17 | #define debug(x...) 18 | #endif 19 | 20 | int main(void) { 21 | ios::sync_with_stdio(false); 22 | cin.tie(0); 23 | cout.tie(0); 24 | int t; 25 | cin >> t; 26 | while (t--) { 27 | int n; 28 | cin >> n; 29 | vector a(n * (n - 1) / 2); 30 | for (auto& i : a) 31 | cin >> i; 32 | sort(a.begin(), a.end()); 33 | vector ans; 34 | for (int i = 0, len = n - 1; i < a.size(); i += len, --len) { 35 | ans.push_back(a[i]); 36 | } 37 | ans.push_back(a.back()); 38 | for (auto& i : ans) 39 | cout << i << ' '; 40 | cout << '\n'; 41 | } 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /code/cf/contest/1857/c/testI1.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 3 3 | 1 3 1 4 | 2 5 | 10 6 | 4 7 | 7 5 3 5 3 3 8 | 5 9 | 2 2 2 2 2 2 2 2 2 2 10 | 5 11 | 3 0 0 -2 0 -2 0 0 -2 -2 12 | -------------------------------------------------------------------------------- /code/cf/contest/1857/c/testO1.txt: -------------------------------------------------------------------------------- 1 | 1 3 3 2 | 10 10 3 | 7 5 3 12 4 | 2 2 2 2 2 5 | 0 -2 0 3 5 6 | -------------------------------------------------------------------------------- /code/cf/contest/1857/d/d.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2023-08-08 15:54:41 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | using LL = long long; 9 | #define FOR(i, x, y) \ 10 | for (decay::type i = (x), _##i = (y); i < _##i; ++i) 11 | #define FORD(i, x, y) \ 12 | for (decay::type i = (x), _##i = (y); i > _##i; --i) 13 | 14 | #ifndef ONLINE_JUDGE 15 | #include "debug.h" 16 | #else 17 | #define debug(x...) 18 | #endif 19 | 20 | int main(void) { 21 | ios::sync_with_stdio(false); 22 | cin.tie(0); 23 | cout.tie(0); 24 | int t; 25 | cin >> t; 26 | while (t--) { 27 | int n; 28 | cin >> n; 29 | vector a(n), b(n), d(n), id(n); 30 | for (auto& i : a) 31 | cin >> i; 32 | for (auto& i : b) 33 | cin >> i; 34 | for (int i = 0; i < n; ++i) 35 | d[i] = a[i] - b[i]; 36 | iota(id.begin(), id.end(), 0); 37 | sort(id.begin(), id.end(), [&](int a, int b) { return d[a] > d[b]; }); 38 | vector ans; 39 | for (int i = 1; i < n; ++i) { 40 | int cur = id[i], la = id[i - 1]; 41 | ans.push_back(la); 42 | if (d[cur] != d[la]) 43 | break; 44 | if (i == n - 1) 45 | ans.push_back(cur); 46 | } 47 | sort(ans.begin(), ans.end()); 48 | cout << ans.size() << '\n'; 49 | for (auto& i : ans) 50 | cout << i + 1 << ' '; 51 | cout << '\n'; 52 | } 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /code/cf/contest/1857/d/testI1.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 4 3 | 3 1 2 4 4 | 4 3 2 1 5 | 5 6 | 1 2 4 1 2 7 | 5 2 3 3 1 8 | 2 9 | 1 2 10 | 2 1 11 | 3 12 | 0 2 1 13 | 1 3 2 14 | 3 15 | 5 7 4 16 | -2 -3 -6 17 | -------------------------------------------------------------------------------- /code/cf/contest/1857/d/testO1.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 4 3 | 2 4 | 3 5 5 | 1 6 | 2 7 | 3 8 | 1 2 3 9 | 2 10 | 2 3 11 | -------------------------------------------------------------------------------- /code/cf/contest/1857/e/e.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2023-08-08 16:02:15 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | using LL = long long; 9 | #define FOR(i, x, y) \ 10 | for (decay::type i = (x), _##i = (y); i < _##i; ++i) 11 | #define FORD(i, x, y) \ 12 | for (decay::type i = (x), _##i = (y); i > _##i; --i) 13 | 14 | #ifndef ONLINE_JUDGE 15 | #include "debug.h" 16 | #else 17 | #define debug(x...) 18 | #endif 19 | 20 | int main(void) { 21 | ios::sync_with_stdio(false); 22 | cin.tie(0); 23 | cout.tie(0); 24 | int t; 25 | cin >> t; 26 | while (t--) { 27 | int n; 28 | cin >> n; 29 | vector a(n), id(n), ans(n); 30 | for (auto& i : a) 31 | cin >> i; 32 | iota(id.begin(), id.end(), 0); 33 | sort(id.begin(), id.end(), [&](int x, int y) { return a[x] < a[y]; }); 34 | LL val = 0; 35 | int l = 0; 36 | int pos = a[id[0]]; 37 | for (int i = 0; i < n; ++i) { 38 | val += abs(a[i] - a[id[0]] + 1); 39 | } 40 | ans[id[0]] = val; 41 | 42 | for (auto& i : id) { 43 | val += 1ll * (a[i] - pos) * (l - n + l); 44 | ans[i] = val; 45 | l++; 46 | pos = a[i]; 47 | } 48 | for (auto& i : ans) 49 | cout << i << ' '; 50 | cout << '\n'; 51 | } 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /code/cf/contest/1857/e/testI1.txt: -------------------------------------------------------------------------------- 1 | 3 2 | 3 3 | 1 4 3 4 | 5 5 | 1 2 5 7 1 6 | 4 7 | 1 10 100 1000 8 | -------------------------------------------------------------------------------- /code/cf/contest/1857/e/testO1.txt: -------------------------------------------------------------------------------- 1 | 8 7 6 2 | 16 15 18 24 16 3 | 1111 1093 1093 2893 4 | -------------------------------------------------------------------------------- /code/cf/contest/1857/f/f.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2023-08-08 16:20:31 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | using LL = long long; 9 | #define FOR(i, x, y) \ 10 | for (decay::type i = (x), _##i = (y); i < _##i; ++i) 11 | #define FORD(i, x, y) \ 12 | for (decay::type i = (x), _##i = (y); i > _##i; --i) 13 | 14 | #ifndef ONLINE_JUDGE 15 | #include "debug.h" 16 | #else 17 | #define debug(x...) 18 | #endif 19 | 20 | int main(void) { 21 | ios::sync_with_stdio(false); 22 | cin.tie(0); 23 | cout.tie(0); 24 | int t; 25 | cin >> t; 26 | while (t--) { 27 | int n; 28 | cin >> n; 29 | map cnt; 30 | for (int i = 0; i < n; ++i) { 31 | int a; 32 | cin >> a; 33 | cnt[a]++; 34 | } 35 | int q; 36 | cin >> q; 37 | while (q--) { 38 | LL x, y; 39 | cin >> x >> y; 40 | LL delta = x * x - 4 * y; 41 | if (delta < 0) { 42 | cout << 0 << ' '; 43 | continue; 44 | } 45 | LL h = sqrt(delta); 46 | if (h * h != delta) { 47 | cout << 0 << ' '; 48 | continue; 49 | } 50 | if ((x & 1) ^ (h & 1)) { 51 | cout << 0 << ' '; 52 | continue; 53 | } 54 | if (h == 0) { 55 | LL ans = x / 2; 56 | cout << 1ll * cnt[ans] * (cnt[ans] - 1) / 2 << ' '; 57 | } else { 58 | LL ans1 = (x + h) / 2, ans2 = (x - h) / 2; 59 | cout << 1ll * cnt[ans1] * cnt[ans2] << ' '; 60 | } 61 | } 62 | cout << '\n'; 63 | } 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /code/cf/contest/1857/f/testI1.txt: -------------------------------------------------------------------------------- 1 | 3 2 | 3 3 | 1 3 2 4 | 4 5 | 3 2 6 | 5 6 7 | 3 1 8 | 5 5 9 | 4 10 | 1 1 1 1 11 | 1 12 | 2 1 13 | 6 14 | 1 4 -2 3 3 3 15 | 3 16 | 2 -8 17 | -1 -2 18 | 7 12 19 | -------------------------------------------------------------------------------- /code/cf/contest/1857/f/testO1.txt: -------------------------------------------------------------------------------- 1 | 1 1 0 0 2 | 6 3 | 1 1 3 4 | -------------------------------------------------------------------------------- /code/cf/contest/1857/g/g.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2023-08-08 16:43:52 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | using LL = long long; 9 | #define FOR(i, x, y) \ 10 | for (decay::type i = (x), _##i = (y); i < _##i; ++i) 11 | #define FORD(i, x, y) \ 12 | for (decay::type i = (x), _##i = (y); i > _##i; --i) 13 | 14 | #ifndef ONLINE_JUDGE 15 | #include "debug.h" 16 | #else 17 | #define debug(x...) 18 | #endif 19 | 20 | class dsu { 21 | public: 22 | vector p; 23 | vector sz; 24 | int n; 25 | 26 | dsu(int _n) : n(_n) { 27 | p.resize(n); 28 | sz.resize(n); 29 | iota(p.begin(), p.end(), 0); 30 | fill(sz.begin(), sz.end(), 1); 31 | } 32 | 33 | inline int get(int x) { return (x == p[x] ? x : (p[x] = get(p[x]))); } 34 | 35 | inline bool unite(int x, int y) { 36 | x = get(x); 37 | y = get(y); 38 | if (x != y) { 39 | p[x] = y; 40 | sz[y] += sz[x]; 41 | return true; 42 | } 43 | return false; 44 | } 45 | }; 46 | 47 | const LL mo = 998244353; 48 | 49 | long long qpower(long long a, long long b) { 50 | long long qwq = 1; 51 | while (b) { 52 | if (b & 1) 53 | qwq = qwq * a % mo; 54 | a = a * a % mo; 55 | b >>= 1; 56 | } 57 | return qwq; 58 | } 59 | 60 | long long inv(long long x) { return qpower(x, mo - 2); } 61 | 62 | int main(void) { 63 | ios::sync_with_stdio(false); 64 | cin.tie(0); 65 | cout.tie(0); 66 | int t; 67 | cin >> t; 68 | while (t--) { 69 | int n, s; 70 | cin >> n >> s; 71 | vector> edge(n - 1); 72 | for (auto& i : edge) { 73 | cin >> i[0] >> i[1] >> i[2]; 74 | --i[0], --i[1]; 75 | } 76 | vector id(n - 1); 77 | iota(id.begin(), id.end(), 0); 78 | sort(id.begin(), id.end(), 79 | [&](int x, int y) { return edge[x][2] < edge[y][2]; }); 80 | dsu d(n); 81 | LL ans = 1; 82 | for (auto& i : id) { 83 | int u = edge[i][0], v = edge[i][1], w = edge[i][2]; 84 | int fu = d.get(u), fv = d.get(v); 85 | ans = (ans * qpower(s - w + 1, 1ll * d.sz[fu] * d.sz[fv] - 1)) % mo; 86 | d.unite(u, v); 87 | } 88 | cout << ans << '\n'; 89 | } 90 | 91 | return 0; 92 | } 93 | -------------------------------------------------------------------------------- /code/cf/contest/1857/g/testI1.txt: -------------------------------------------------------------------------------- 1 | 4 2 | 2 5 3 | 1 2 4 4 | 4 5 5 | 1 2 2 6 | 2 3 4 7 | 3 4 3 8 | 5 6 9 | 1 2 3 10 | 1 3 2 11 | 3 4 6 12 | 3 5 1 13 | 10 200 14 | 1 2 3 15 | 2 3 33 16 | 3 4 200 17 | 1 5 132 18 | 5 6 1 19 | 5 7 29 20 | 7 8 187 21 | 7 9 20 22 | 7 10 4 23 | -------------------------------------------------------------------------------- /code/cf/contest/1857/g/testO1.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 8 3 | 80 4 | 650867886 5 | -------------------------------------------------------------------------------- /code/cf/gym/101522/e/e.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2023-01-11 18:55:44 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | using namespace std; 10 | using LL = long long; 11 | #define FOR(i, x, y) for (decay::type i = (x), _##i = (y); i < _##i; ++i) 12 | #define FORD(i, x, y) for (decay::type i = (x), _##i = (y); i > _##i; --i) 13 | 14 | #ifndef ONLINE_JUDGE 15 | #include "debug.h" 16 | #else 17 | #define debug(x...) 18 | #endif 19 | 20 | int main(void) { 21 | ios::sync_with_stdio(false); 22 | cin.tie(0); cout.tie(0); 23 | int n, r; 24 | cin >> n >> r; 25 | vector> box(2 * n + 1); 26 | set pos; 27 | int cur = 0; 28 | for(int i = 1; i < r; ++ i){ 29 | int x, y, cx, cy; 30 | cin >> x >> y >> cx >> cy; 31 | box[cx].insert(x); 32 | box[cy].insert(y); 33 | pos.insert(x); 34 | pos.insert(y); 35 | if (cx == cy) 36 | cur = max(cur, cx); 37 | } 38 | double ans1 = 0; 39 | for(int i = n; i >= 1; -- i){ 40 | if (box[i].size() == 2){ 41 | ans1 = max(ans1, 1.0 * i); 42 | } 43 | } 44 | int lar1 = n; 45 | for(; lar1 >= 1; -- lar1){ 46 | if (box[lar1].size() == 1){ 47 | break; 48 | } 49 | } 50 | int unknown = 2 * n - pos.size(); 51 | double single = 1.0 / unknown; 52 | double ans2 = single * lar1 + (1 - single) * cur; 53 | 54 | double two = (2.0 / unknown) * (1.0 / (unknown - 1)); 55 | double ans3 = 0; 56 | int cnt = 0; 57 | for(int i = cur + 1; i <= n; ++ i){ 58 | if (box[i].empty()){ 59 | ans3 += two * i; 60 | ++ cnt; 61 | } 62 | } 63 | ans3 += (1 - cnt * two) * cur; 64 | 65 | double ans = max({ans1, ans2, ans3}); 66 | cout << fixed << setprecision(10) << ans << '\n'; 67 | 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /code/cf/gym/101522/e/testI1.txt: -------------------------------------------------------------------------------- 1 | 3 3 2 | 3 | 1 3 1 3 4 | 5 | 2 4 2 3 6 | -------------------------------------------------------------------------------- /code/cf/gym/101522/e/testI2.txt: -------------------------------------------------------------------------------- 1 | 2 1 2 | -------------------------------------------------------------------------------- /code/cf/gym/101522/e/testI3.txt: -------------------------------------------------------------------------------- 1 | 3 2 2 | 3 | 1 4 2 2 4 | -------------------------------------------------------------------------------- /code/cf/gym/101522/e/testO1.txt: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /code/cf/gym/101522/e/testO2.txt: -------------------------------------------------------------------------------- 1 | 0.5 2 | -------------------------------------------------------------------------------- /code/cf/gym/101522/e/testO3.txt: -------------------------------------------------------------------------------- 1 | 2.166667 2 | -------------------------------------------------------------------------------- /code/cf/gym/101522/h/h.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2023-01-11 18:25:35 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | using namespace std; 10 | using LL = long long; 11 | #define FOR(i, x, y) for (decay::type i = (x), _##i = (y); i < _##i; ++i) 12 | #define FORD(i, x, y) for (decay::type i = (x), _##i = (y); i > _##i; --i) 13 | 14 | #ifndef ONLINE_JUDGE 15 | #include "debug.h" 16 | #else 17 | #define debug(x...) 18 | #endif 19 | 20 | typedef double db; 21 | const db EPS = 1e-9; 22 | 23 | inline int sign(db a) { return a < -EPS ? -1 : a > EPS; } 24 | 25 | inline int cmp(db a, db b){ return sign(a-b); } 26 | 27 | struct P { 28 | db x, y; 29 | P() {} 30 | P(db _x, db _y) : x(_x), y(_y) {} 31 | P operator+(P p) { return {x + p.x, y + p.y}; } 32 | P operator-(P p) { return {x - p.x, y - p.y}; } 33 | P operator*(db d) { return {x * d, y * d}; } 34 | P operator/(db d) { return {x / d, y / d}; } 35 | 36 | bool operator<(P p) const { // 字典序小于 37 | int c = cmp(x, p.x); 38 | if (c) return c == -1; 39 | return cmp(y, p.y) == -1; 40 | } 41 | 42 | bool operator==(P o) const{ // 判断点相等 43 | return cmp(x,o.x) == 0 && cmp(y,o.y) == 0; 44 | } 45 | 46 | db dot(P p) { return x * p.x + y * p.y; } // 点积 47 | db det(P p) { return x * p.y - y * p.x; } // 叉积 48 | 49 | db distTo(P p) { return (*this-p).abs(); } // 两点距离 50 | db alpha() { return atan2(y, x); } // 斜率 51 | void read() { cin>>x>>y; } // 读取 52 | void write() {cout<<"("<= 0); } // 是否在0~179度?点在上半边,极角排序用的 58 | P rot(db an){ return {x*cos(an)-y*sin(an),x*sin(an) + y*cos(an)}; } // 逆时针旋转an度 59 | }; 60 | 61 | int type(P o1,db r1,P o2,db r2){ // 两个圆的关系,0:内含,1:内切,2:相交,3:外切,4:相离 62 | db d = o1.distTo(o2); 63 | if(cmp(d,r1+r2) == 1) return 4; 64 | if(cmp(d,r1+r2) == 0) return 3; 65 | if(cmp(d,abs(r1-r2)) == 1) return 2; 66 | if(cmp(d,abs(r1-r2)) == 0) return 1; 67 | return 0; 68 | } 69 | 70 | vector

isCC(P o1, db r1, P o2, db r2) { //need to check whether two circles are the same 71 | db d = o1.distTo(o2); 72 | if (cmp(d, r1 + r2) == 1) return {}; 73 | if (cmp(d,abs(r1-r2))==-1) return {}; 74 | d = min(d, r1 + r2); 75 | db y = (r1 * r1 + d * d - r2 * r2) / (2 * d), x = sqrt(r1 * r1 - y * y); 76 | P dr = (o2 - o1).unit(); 77 | P q1 = o1 + dr * y, q2 = dr.rot90() * x; 78 | return {q1-q2,q1+q2};//along circle 1 79 | } 80 | 81 | int main(void) { 82 | ios::sync_with_stdio(false); 83 | cin.tie(0); cout.tie(0); 84 | P p1, p2; 85 | int r1, r2; 86 | p1.read(); 87 | cin >> r1; 88 | p2.read(); 89 | cin >> r2; 90 | int sign = type(p1, r1, p2, r2); 91 | assert(sign != 4); 92 | if (sign == 0 || sign == 1){ 93 | if (r1 < r2) 94 | cout << fixed << setprecision(10) << p1.x << ' ' << p1.y << '\n'; 95 | else 96 | cout << fixed << setprecision(10) << p2.x << ' ' << p2.y << '\n'; 97 | }else{ 98 | auto good = isCC(p1, r1, p2, r2); 99 | cout << fixed << setprecision(10) << good.front().x << ' ' << good.front().y << '\n'; 100 | } 101 | 102 | return 0; 103 | } 104 | -------------------------------------------------------------------------------- /code/cf/gym/101522/h/testI1.txt: -------------------------------------------------------------------------------- 1 | 0 0 3 2 | 3 | 3 4 3 4 | -------------------------------------------------------------------------------- /code/cf/gym/101522/h/testI2.txt: -------------------------------------------------------------------------------- 1 | -7 -9 3 2 | 3 | -4 -4 5 4 | -------------------------------------------------------------------------------- /code/cf/gym/101522/h/testO1.txt: -------------------------------------------------------------------------------- 1 | 1.5 2.5 2 | -------------------------------------------------------------------------------- /code/cf/gym/101522/h/testO2.txt: -------------------------------------------------------------------------------- 1 | -6 -7 2 | -------------------------------------------------------------------------------- /code/nowcoder/contests/49259/a/a.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2022-12-17 13:01:52 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | using LL = long long; 9 | #define FOR(i, x, y) for (decay::type i = (x), _##i = (y); i < _##i; ++i) 10 | #define FORD(i, x, y) for (decay::type i = (x), _##i = (y); i > _##i; --i) 11 | 12 | #ifndef ONLINE_JUDGE 13 | #include "debug.h" 14 | #else 15 | #define debug(x...) 16 | #endif 17 | 18 | int main(void) { 19 | ios::sync_with_stdio(false); 20 | cin.tie(0); cout.tie(0); 21 | int n; 22 | cin >> n; 23 | bool ok = false, haveC = false, haveV = false; 24 | while(n--){ 25 | string s; 26 | cin >> s; 27 | if (s.size() == 4) 28 | ok = true; 29 | else if (s.size() == 6) 30 | ok = false; 31 | else if (ok && s[0] == 'C') 32 | haveC = true; 33 | else if (ok && s[0] == 'V' && haveC) 34 | haveV = true; 35 | } 36 | if (haveV) 37 | cout << "Yes" << '\n'; 38 | else 39 | cout << "No" << '\n'; 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /code/nowcoder/contests/49259/b/b.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2022-12-17 13:20:34 4 | */ 5 | 6 | #include 7 | #include 8 | using namespace std; 9 | using LL = long long; 10 | #define FOR(i, x, y) for (decay::type i = (x), _##i = (y); i < _##i; ++i) 11 | #define FORD(i, x, y) for (decay::type i = (x), _##i = (y); i > _##i; --i) 12 | 13 | #ifndef ONLINE_JUDGE 14 | #include "debug.h" 15 | #else 16 | #define debug(x...) 17 | #endif 18 | 19 | const int N = 1e5 + 8; 20 | int cnt[N], t, k; 21 | 22 | int main(void) { 23 | ios::sync_with_stdio(false); 24 | cin.tie(0); cout.tie(0); 25 | cin >> t >> k; 26 | for(int i = 1; i <= t; ++ i){ 27 | int l, r; 28 | cin >> l >> r; 29 | cnt[l] ++; 30 | cnt[r + 1] --; 31 | } 32 | vector> ans; 33 | int st = 0; 34 | bool ok = true; 35 | int sum = 0; 36 | for(int i = 0; i <= 120; ++ i){ 37 | sum += cnt[i]; 38 | if (ok && sum >= k){ 39 | ans.push_back({st, i - 1}); 40 | ok = false; 41 | }else if (sum < k){ 42 | if (!ok) 43 | st = i; 44 | ok = true; 45 | } 46 | } 47 | if (ok) 48 | ans.push_back({st, 120}); 49 | cout << ans.size() << '\n'; 50 | for(auto &i : ans) 51 | cout << i.first << '-' << i.second << '\n'; 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /code/nowcoder/contests/49259/c/c.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2022-12-17 13:05:54 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | using LL = long long; 9 | #define FOR(i, x, y) for (decay::type i = (x), _##i = (y); i < _##i; ++i) 10 | #define FORD(i, x, y) for (decay::type i = (x), _##i = (y); i > _##i; --i) 11 | 12 | #ifndef ONLINE_JUDGE 13 | #include "debug.h" 14 | #else 15 | #define debug(x...) 16 | #endif 17 | 18 | int main(void) { 19 | ios::sync_with_stdio(false); 20 | cin.tie(0); cout.tie(0); 21 | int s, t; 22 | cin >> s >> t; 23 | int ans = 0; 24 | FOR(i, 0, s + 1) 25 | FOR(j, i, s + 1) 26 | FOR(k, j, s + 1) 27 | ans += (i + j + k <= s && 1ll * i * j * k <= t); 28 | cout << ans << '\n'; 29 | 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /code/nowcoder/contests/49259/d/d.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2022-12-17 13:42:56 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | using LL = long long; 9 | #define FOR(i, x, y) for (decay::type i = (x), _##i = (y); i < _##i; ++i) 10 | #define FORD(i, x, y) for (decay::type i = (x), _##i = (y); i > _##i; --i) 11 | 12 | #ifndef ONLINE_JUDGE 13 | #include "debug.h" 14 | #else 15 | #define debug(x...) 16 | #endif 17 | 18 | int main(void) { 19 | ios::sync_with_stdio(false); 20 | cin.tie(0); cout.tie(0); 21 | cout << "5 Mazige" << '\n'; 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /code/nowcoder/contests/49259/e/e.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2022-12-17 13:43:13 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | using LL = long long; 9 | #define FOR(i, x, y) for (decay::type i = (x), _##i = (y); i < _##i; ++i) 10 | #define FORD(i, x, y) for (decay::type i = (x), _##i = (y); i > _##i; --i) 11 | 12 | #ifndef ONLINE_JUDGE 13 | #include "debug.h" 14 | #else 15 | #define debug(x...) 16 | #endif 17 | 18 | int main(void) { 19 | ios::sync_with_stdio(false); 20 | cin.tie(0); cout.tie(0); 21 | int t; 22 | cin >> t; 23 | while(t--){ 24 | string n, k; 25 | cin >> n >> k; 26 | cout << n.back() << '\n'; 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /code/nowcoder/contests/49259/f/f.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2022-12-17 13:45:37 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | using LL = long long; 9 | #define FOR(i, x, y) for (decay::type i = (x), _##i = (y); i < _##i; ++i) 10 | #define FORD(i, x, y) for (decay::type i = (x), _##i = (y); i > _##i; --i) 11 | 12 | #ifndef ONLINE_JUDGE 13 | #include "debug.h" 14 | #else 15 | #define debug(x...) 16 | #endif 17 | 18 | const LL inf = 1e18 + 7; 19 | 20 | int main(void) { 21 | ios::sync_with_stdio(false); 22 | cin.tie(0); cout.tie(0); 23 | int n; 24 | cin >> n; 25 | map cnt, ans; 26 | for(int i = 0; i < n; ++ i){ 27 | LL x; 28 | cin >> x; 29 | LL cc = 0; 30 | while(x >= 3){ 31 | ans[x] += cc; 32 | cnt[x] ++; 33 | ++ cc; 34 | x /= 3; 35 | } 36 | } 37 | LL val = inf; 38 | for(auto &i : cnt) 39 | if (i.second == n) 40 | val = min(val, ans[i.first]); 41 | if (val == inf) 42 | cout << "Lose" << '\n'; 43 | else 44 | cout << val << '\n'; 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /code/nowcoder/contests/49259/g/g.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2022-12-17 13:55:33 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | using LL = long long; 9 | #define FOR(i, x, y) for (decay::type i = (x), _##i = (y); i < _##i; ++i) 10 | #define FORD(i, x, y) for (decay::type i = (x), _##i = (y); i > _##i; --i) 11 | 12 | #ifndef ONLINE_JUDGE 13 | #include "debug.h" 14 | #else 15 | #define debug(x...) 16 | #endif 17 | 18 | const int N = 200; 19 | int dp[N][N]; 20 | 21 | int solve(int x, int y){ 22 | if (dp[x][y] != -1) 23 | return dp[x][y]; 24 | int v1 = 1, v2 = 1, v3 = 1; 25 | if (x > 0){ 26 | v1 = solve(x - 1, y); 27 | v2 = solve(x - 1, y + 1); 28 | } 29 | if (y > 0){ 30 | v3 = solve(x, y - 1); 31 | } 32 | if (v1 == 0 || v2 == 0 || v3 == 0) 33 | dp[x][y] = 1; 34 | else 35 | dp[x][y] = 0; 36 | return dp[x][y]; 37 | } 38 | 39 | int main(void) { 40 | ios::sync_with_stdio(false); 41 | cin.tie(0); cout.tie(0); 42 | // memset(dp, -1, sizeof(dp)); 43 | // dp[0][0] = 0; 44 | // for(int i = 0; i < N; ++ i) 45 | // for(int j = 0; j < N; ++ j){ 46 | // solve(i, j); 47 | // } 48 | // for(int i = 0; i < N; ++ i){ 49 | // debug(i * 2, dp[i][0]); 50 | // debug(i * 2 + 1, dp[i][1]); 51 | // } 52 | int t; 53 | cin >> t; 54 | while(t--){ 55 | LL n; 56 | cin >> n; 57 | if ((n & 1) || ((n / 2) & 1)){ 58 | cout << "Mazige" << '\n'; 59 | }else{ 60 | cout << "Not Mazige" << '\n'; 61 | } 62 | } 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /code/nowcoder/contests/49259/h/h.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2022-12-17 14:15:51 4 | */ 5 | 6 | #include 7 | #include 8 | using namespace std; 9 | using LL = long long; 10 | #define FOR(i, x, y) for (decay::type i = (x), _##i = (y); i < _##i; ++i) 11 | #define FORD(i, x, y) for (decay::type i = (x), _##i = (y); i > _##i; --i) 12 | 13 | #ifndef ONLINE_JUDGE 14 | #include "debug.h" 15 | #else 16 | #define debug(x...) 17 | #endif 18 | 19 | const LL mo = 1e9 + 7; 20 | 21 | int main(void) { 22 | ios::sync_with_stdio(false); 23 | cin.tie(0); cout.tie(0); 24 | int n, k; 25 | cin >> n >> k; 26 | vector a(n); 27 | for(auto &i : a){ 28 | cin >> i; 29 | } 30 | sort(a.begin(), a.end(), [](LL a, LL b){ 31 | return abs(a) > abs(b); 32 | }); 33 | int kp = -1, kn = -1; 34 | int cnt = 0; 35 | for(int i = 0; i < k; ++ i){ 36 | cnt ^= (a[i] < 0); 37 | if (a[i] > 0) 38 | kp = i; 39 | else if (a[i] < 0) 40 | kn = i; 41 | } 42 | // first k 43 | if (cnt == 0){ 44 | LL ans = 1; 45 | for(int i = 0; i < k; ++ i) 46 | ans = ans * abs(a[i]) % mo; 47 | cout << ans << '\n'; 48 | return 0; 49 | } 50 | int kkp = -1, kkn = -1; 51 | for(int i = k; i < n; ++ i){ 52 | if (kkp == -1 && a[i] > 0) 53 | kkp = i; 54 | if (kkn == -1 && a[i] < 0) 55 | kkn = i; 56 | } 57 | // swap biggest last positive with smallest k neg 58 | if (kkp != -1 && (kkp < kkn || kkn == -1 || kp == -1)){ 59 | LL ans = 1; 60 | for(int i = 0; i < k; ++ i){ 61 | if (i == kn) 62 | continue; 63 | ans = ans * abs(a[i]) % mo; 64 | } 65 | ans = ans * a[kkp] % mo; 66 | cout << ans << '\n'; 67 | return 0; 68 | } 69 | // swap biggest last negative with smallest k positive 70 | if (kkn != -1 && kp != -1){ 71 | LL ans = 1; 72 | for(int i = 0; i < k; ++ i){ 73 | if (i == kp) 74 | continue; 75 | ans = ans * abs(a[i]) % mo; 76 | } 77 | ans = ans * abs(a[kkn]) % mo; 78 | cout << ans << '\n'; 79 | return 0; 80 | } 81 | // ans < 0, last k 82 | LL ans = 1; 83 | for(int i = n - 1; i > n - 1 - k; -- i){ 84 | ans = ans * abs(a[i]) % mo; 85 | } 86 | cout << -ans << '\n'; 87 | 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /code/nowcoder/contests/49259/i/i.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2022-12-17 14:48:25 4 | */ 5 | 6 | #include 7 | #include 8 | using namespace std; 9 | using LL = long long; 10 | #define FOR(i, x, y) for (decay::type i = (x), _##i = (y); i < _##i; ++i) 11 | #define FORD(i, x, y) for (decay::type i = (x), _##i = (y); i > _##i; --i) 12 | 13 | #ifndef ONLINE_JUDGE 14 | #include "debug.h" 15 | #else 16 | #define debug(x...) 17 | #endif 18 | 19 | int main(void) { 20 | ios::sync_with_stdio(false); 21 | cin.tie(0); cout.tie(0); 22 | int n, t; 23 | cin >> n >> t; 24 | vector a(n); 25 | for(auto &i : a) 26 | cin >> i; 27 | while(t--){ 28 | int l, r; 29 | cin >> l >> r; 30 | -- l; 31 | -- r; 32 | int ans = 0; 33 | for(int i = l; i <= r; ++ i) 34 | ans += (a[i] >= a[l]); 35 | cout << ans << '\n'; 36 | } 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /code/nowcoder/contests/49259/k/k.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2022-12-17 16:39:00 4 | */ 5 | 6 | #include 7 | #include 8 | using namespace std; 9 | using LL = long long; 10 | #define FOR(i, x, y) for (decay::type i = (x), _##i = (y); i < _##i; ++i) 11 | #define FORD(i, x, y) for (decay::type i = (x), _##i = (y); i > _##i; --i) 12 | 13 | #ifndef ONLINE_JUDGE 14 | #include "debug.h" 15 | #else 16 | #define debug(x...) 17 | #endif 18 | 19 | const LL inf = 1e18; 20 | 21 | int main(void) { 22 | ios::sync_with_stdio(false); 23 | cin.tie(0); cout.tie(0); 24 | int n; 25 | cin >> n; 26 | vector dp(3001, inf); 27 | dp[0] = 0; 28 | vector> f(n); 29 | for(auto &i : f) 30 | cin >> i.first >> i.second; 31 | sort(f.begin(), f.end(), [](const pair& a, const pair& b){ 32 | return a.first < b.first; 33 | }); 34 | for(int i = 0; i < n; ++ i){ 35 | LL a; 36 | int b; 37 | a = f[i].first; 38 | b = f[i].second; 39 | for(int j = 3000; j >= b; -- j){ 40 | if (a > dp[j - b]) 41 | dp[j] = min(dp[j], dp[j - b] + a); 42 | } 43 | } 44 | int ans = 0; 45 | for(int i = 3000; i >= 0; -- i) 46 | if (dp[i] != inf){ 47 | ans = i; 48 | break; 49 | } 50 | cout << ans << '\n'; 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /code/nowcoder/contests/49259/l/l.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2022-12-17 15:02:23 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | using LL = long long; 9 | #define FOR(i, x, y) for (decay::type i = (x), _##i = (y); i < _##i; ++i) 10 | #define FORD(i, x, y) for (decay::type i = (x), _##i = (y); i > _##i; --i) 11 | 12 | #ifndef ONLINE_JUDGE 13 | #include "debug.h" 14 | #else 15 | #define debug(x...) 16 | #endif 17 | 18 | const LL inf = 1e18; 19 | 20 | int main(void) { 21 | ios::sync_with_stdio(false); 22 | cin.tie(0); cout.tie(0); 23 | LL n, s; 24 | cin >> n >> s; 25 | LL ans = inf; 26 | auto calc = [](LL x, int base){ 27 | LL cnt = 0; 28 | while(x){ 29 | cnt += x % base; 30 | x /= base; 31 | } 32 | return cnt; 33 | }; 34 | for(int i = 2; i <= 100000; ++ i){ 35 | if (calc(n, i) == s){ 36 | ans = i; 37 | break; 38 | } 39 | } 40 | if (ans == inf){ 41 | for(int i = 1; i <= 100000; ++ i){ 42 | LL mod = s - i; 43 | if (n > mod && (n - mod) % i == 0){ 44 | LL p = (n - mod) / i; 45 | if (p != 1){ 46 | ans = min(ans, p); 47 | debug(p, i, mod); 48 | } 49 | } 50 | } 51 | } 52 | 53 | if (ans == inf) 54 | ans = -1; 55 | if (n == s && ans == -1) 56 | ans = n + 1; 57 | cout << ans << '\n'; 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /code/nowcoder/contests/49259/m/m.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Lanly 3 | * Time: 2022-12-17 15:22:56 4 | */ 5 | 6 | #include 7 | #include 8 | using namespace std; 9 | using LL = long long; 10 | #define FOR(i, x, y) for (decay::type i = (x), _##i = (y); i < _##i; ++i) 11 | #define FORD(i, x, y) for (decay::type i = (x), _##i = (y); i > _##i; --i) 12 | 13 | #ifndef ONLINE_JUDGE 14 | #include "debug.h" 15 | #else 16 | #define debug(x...) 17 | #endif 18 | 19 | const long double inf = 1e18; 20 | const long double pi = acos(-1); 21 | const long double sin18 = sin(18.0 / 180 * pi); 22 | const long double sin36 = sin(36.0 / 180 * pi); 23 | const long double sin72 = sin(72.0 / 180 * pi); 24 | const long double sin108 = sin(108.0 / 180 * pi); 25 | const long double cos18 = cos(18.0 / 180 * pi); 26 | const long double cos72 = cos(72.0 / 180 * pi); 27 | const long double cos108 = cos(108.0 / 180 * pi); 28 | const long double tan54 = tan(54.0 / 180 * pi); 29 | const long double eps = 1e-10; 30 | 31 | long double calcB(long double a){ 32 | return 2.0 * a * sin18; 33 | } 34 | 35 | long double hoc(long double a){ 36 | long double b = calcB(a); 37 | return a + a + b; 38 | } 39 | 40 | long double vec(long double a){ 41 | return hoc(a) * cos18; 42 | } 43 | 44 | long double star(long double a){ 45 | return 5.0 * 0.5 * a * a * sin36; 46 | } 47 | 48 | long double wubian(long double b){ 49 | return 5.0 * 0.5 * b * b / 2 * tan54; 50 | } 51 | 52 | 53 | long double area(long double a){ 54 | long double b = calcB(a); 55 | long double s1 = star(a); 56 | long double s2 = wubian(b); 57 | return s1 + s2; 58 | } 59 | 60 | long double solve(long double (*f)(long double), long double up){ 61 | long double l = 0, r = up; 62 | while(l + eps < r){ 63 | long double mid = (l + r) / 2; 64 | if (f(mid) <= up) 65 | l = mid; 66 | else 67 | r = mid; 68 | } 69 | return l; 70 | } 71 | 72 | long double cot(long double x){ 73 | return tan(pi/2-x); 74 | } 75 | 76 | int main(void) { 77 | ios::sync_with_stdio(false); 78 | cin.tie(0); cout.tie(0); 79 | long double x, y; 80 | cin >> x >> y; 81 | cout << 5.0 / 8.0 * (x * x + y * y) * cot(pi / 5) << '\n'; 82 | long double ff = min(x, y); 83 | long double a = sqrt(ff * ff / ((sin72 * sin72 + (1 + cos72) * (1 + cos72)) * sin108 * sin108 * 2 * (1 - cos108))); 84 | long double b = min(solve(hoc, x), solve(vec, y)); 85 | 86 | cout << fixed << setprecision(10) << area(a) << ' ' << area(b) << '\n'; 87 | // cout << fixed << setprecision(10) << area(a) << '\n'; 88 | 89 | return 0; 90 | } 91 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from parser.parser import Parser 2 | import sys 3 | 4 | url = "" 5 | 6 | # url = "https://atcoder.jp/contests/abc371/tasks" 7 | # url = "https://codeforces.com/contest/1857" 8 | # url = "https://codeforces.com/gym/101522" 9 | # url = "https://ac.nowcoder.com/acm/contest/49259" 10 | 11 | if not url and len(sys.argv) < 2: 12 | print(f"python3 {sys.argv[0]} ") 13 | exit(-1) 14 | elif not url: 15 | url = sys.argv[1] 16 | 17 | parser = Parser() 18 | parser.start(url) 19 | -------------------------------------------------------------------------------- /parser/__init__.py: -------------------------------------------------------------------------------- 1 | # nothing 2 | -------------------------------------------------------------------------------- /parser/atcoder.py: -------------------------------------------------------------------------------- 1 | from .base import BaseParser 2 | 3 | class Atcoder(BaseParser): 4 | 5 | @property 6 | def code_path(self) -> str: 7 | return "code/AtCoder" 8 | 9 | @property 10 | def request_cookie(self): # 有时候比赛剩下不会做,想写题解,但由于比赛还没结束,需要登录才能看题,可以F12获取登录cookie 11 | return { 12 | "REVEL_SESSION": "" 13 | } 14 | 15 | @property 16 | def name(self) -> str: 17 | return "atcoder" 18 | 19 | def _title_method(self) -> str: 20 | return self.soup.head.title.get_text().strip("Tasks - ") 21 | 22 | @property 23 | def problem_table(self) -> str: 24 | return "table" 25 | 26 | @property 27 | def contest_id(self) -> str: 28 | return self.url.split('/')[-2] 29 | 30 | -------------------------------------------------------------------------------- /parser/base.py: -------------------------------------------------------------------------------- 1 | from abc import abstractmethod, abstractproperty 2 | import os 3 | import random 4 | from datetime import datetime 5 | import requests 6 | from bs4 import BeautifulSoup 7 | from urllib.parse import urljoin 8 | 9 | class BaseParser(): 10 | 11 | def __init__(self) -> None: 12 | self._log = [] 13 | self._title = "" 14 | self.problem_num = 0 15 | 16 | @abstractproperty 17 | def name(self) -> str: ... 18 | @abstractmethod 19 | def _title_method(self) -> str: ... 20 | @abstractmethod 21 | def problem_url(self, problem_id: str) -> str: ... 22 | 23 | @abstractproperty 24 | def contest_id(self) -> str: ... 25 | @abstractproperty 26 | def code_path(self) -> str: ... 27 | @abstractproperty 28 | def problem_table(self) -> str: 29 | return "" 30 | 31 | @property 32 | def request_header(self): 33 | return {} 34 | 35 | @property 36 | def request_cookie(self): 37 | return {} 38 | 39 | @property 40 | def abbr(self) -> str: 41 | return "" 42 | 43 | @property 44 | def template(self) -> str: 45 | return '''## [{} ({}{} {})]({}) 46 | ### 题目大意 47 | 48 | <++> 49 | 50 | ### 解题思路 51 | 52 | <++> 53 | 54 |

55 | 神奇的代码 56 | 57 | ```cpp 58 | {} 59 | ``` 60 |
61 |
62 | 63 | *** 64 | ''' 65 | 66 | @property 67 | def header(self) -> str: 68 | return f'''--- 69 | title: {self.title()} 70 | categories: 算法题解 71 | description: 我好菜啊 72 | tags: 73 | - {self.name} 74 | cover: /img/chino/vec/chino{random.randint(1,60)}.jpg 75 | katex: true 76 | date: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")} 77 | --- 78 | 79 | ''' 80 | 81 | def brief(self, problem_num: int) -> str: 82 | head = '''
83 | 省流版 84 | 85 | ''' 86 | tail = ''' 87 | 88 |
89 |
90 | ''' 91 | 92 | mid = '\n'.join([f"- {chr(65+i)}. <++>" for i in range(problem_num)]) 93 | 94 | return head + mid + tail 95 | 96 | def get_problem(self) -> list: 97 | table_node = self.soup.find_all("table", class_=self.problem_table) 98 | trs = table_node[0].find_all("tr") 99 | self.problem_num = len(trs) - 1 100 | problems = [] 101 | for i in range(self.problem_num): 102 | tr = trs[i + 1] 103 | tds = tr.find_all("td") 104 | a_tag = tds[1].find('a') 105 | 106 | problem_id = tds[0].get_text().strip() 107 | problem_name = problem_id + " - " + a_tag.get_text().strip() 108 | problem_url = urljoin(self.url, a_tag['href']) 109 | 110 | problems.append((problem_id, problem_name, problem_url)) 111 | 112 | return problems 113 | 114 | def start(self, url: str): 115 | self.url = url 116 | res = self.request(self.url) 117 | res.raise_for_status() 118 | self.soup = BeautifulSoup(res.text, features="html.parser") 119 | self.log(self.header) 120 | 121 | problems = self.get_problem() 122 | self.problem_num = len(problems) 123 | self.log(self.brief(self.problem_num)) 124 | 125 | print(f"find {self.problem_num} problem") 126 | 127 | for problem_id, problem_name, problem_url in problems: 128 | print(f"find [{problem_name}]") 129 | self.log(self.make_problem(problem_id, problem_name, problem_url)) 130 | self.write() 131 | 132 | def request(self, url: str) -> requests.Response: 133 | return requests.get(url, headers=self.request_header, cookies=self.request_cookie) 134 | 135 | def title(self) -> str: 136 | if not self._title: 137 | self._title = self._title_method() 138 | print(f"title: {self._title}") 139 | return self._title 140 | 141 | def get_code(self, problem_id: str) -> str: 142 | p = problem_id.lower() 143 | fp = os.path.join(self.code_path, self.contest_id, p, f"{p}.cpp") 144 | if not os.path.exists(fp): 145 | print(f"{fp} not found!") 146 | return "" 147 | with open(fp, "r") as f: 148 | return f.read() 149 | 150 | def make_problem(self, problem_id: str, problem_name: str, problem_url: str) -> str: 151 | code = self.get_code(problem_id) 152 | return self.template.format(problem_name, self.abbr, self.contest_id, problem_id, problem_url, code) 153 | 154 | def write(self): 155 | with open(f"{self.title()}.md", "w") as f: 156 | f.write('\n'.join(self._log)) 157 | print(f"Save in {self.title()}.md") 158 | 159 | def log(self, text:str): 160 | self._log.append(text) 161 | -------------------------------------------------------------------------------- /parser/codeforces.py: -------------------------------------------------------------------------------- 1 | from .base import BaseParser 2 | 3 | class Codeforces(BaseParser): 4 | 5 | @property 6 | def code_path(self) -> str: 7 | return "code/cf/" + ("contest" if len(self.contest_id) <= 4 else "gym") 8 | 9 | @property 10 | def request_cookie(self): # 有时候有cloudflare,可以F12里的cookie获取这个字段绕过 11 | return { 12 | } 13 | 14 | @property 15 | def name(self) -> str: 16 | return "codeforces" 17 | 18 | @property 19 | def abbr(self) -> str: 20 | return "CF" 21 | 22 | @property 23 | def problem_table(self) -> str: 24 | return "problems" 25 | 26 | def _title_method(self) -> str: 27 | return self.soup.find(attrs="rtable").find(attrs="left").get_text().strip() 28 | 29 | @property 30 | def contest_id(self) -> str: 31 | return self.url.split('/')[-1] 32 | 33 | -------------------------------------------------------------------------------- /parser/nowcoder.py: -------------------------------------------------------------------------------- 1 | from .base import BaseParser 2 | 3 | class Nowcoder(BaseParser): 4 | 5 | @property 6 | def code_path(self) -> str: 7 | return "code/nowcoder/contests" 8 | 9 | @property 10 | def name(self) -> str: 11 | return "nowcoder" 12 | 13 | @property 14 | def abbr(self) -> str: 15 | return "Nowcoder" 16 | 17 | def _title_method(self) -> str: 18 | return self.soup.head.title.get_text().split('_')[0] 19 | 20 | @property 21 | def problem_table(self) -> str: 22 | return "table-hover" 23 | 24 | @property 25 | def contest_id(self) -> str: 26 | return self.url.split('/')[-1] 27 | 28 | def get_problem(self): 29 | res = self.request(f"https://ac.nowcoder.com/acm/contest/problem-list?id={self.contest_id}").json() 30 | problems = [] 31 | for problem in res['data']['data']: 32 | problem_id = problem['index'] 33 | problem_name = problem_id + " - " + problem['title'] 34 | problem_url = self.url + "/" + problem_id 35 | problems.append((problem_id, problem_name, problem_url)) 36 | 37 | return problems 38 | -------------------------------------------------------------------------------- /parser/parser.py: -------------------------------------------------------------------------------- 1 | from .atcoder import Atcoder 2 | from .codeforces import Codeforces 3 | from .nowcoder import Nowcoder 4 | 5 | class Parser(): 6 | 7 | rules = { 8 | "atcoder" : Atcoder, 9 | "codeforces" : Codeforces, 10 | "nowcoder" : Nowcoder 11 | } 12 | 13 | def start(self, url: str): 14 | instance = None 15 | for key, value in self.rules.items(): 16 | if key in url: 17 | instance = value() 18 | if instance is None: 19 | print("Unsupported url!") 20 | return 21 | 22 | instance.start(url) 23 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | beautifulsoup4==4.12.2 2 | requests==2.26.0 3 | --------------------------------------------------------------------------------