question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p01331 |
<h1><font color="#000">Problem K:</font> ã¯ãŒãããŒã«</h1>
<p>20XX幎ãé ãé¢ããå Žæã«å¯Ÿããå¹ççãªç©è³ªè»¢éæ¹åŒã確ç«ããã人é¡ã®å®å®ãžã®é²åºã¯ãŸããŸãå éãããããšã«ãªã£ãããã®è»¢éæ¹åŒã¯ãããé ãã«ç©è³ªã転éããããšãããšãååçã«ãã倧ããªç©è³ªã®è»¢éãå¯èœã«ãªãç¹ã§é©æ°çã§ãã£ããè»¢éæ¹åŒã®è©³çŽ°ãæ¬¡ã«èšãã</p>
<p>ãŸã転é察象ãšãªãç©è³ªã¯ãã¹ã¿ãŒã座æš(1, 1)ã«ãŠåäœè³ªéæ¯ã®ããŒãã£ã¯ã«ã«åå²ããããåããŒãã£ã¯ã«ã«ã¯ãåã
ç°ãªãæ³¢åãšãã«ã®ãŒãäžããããªããã°ãªããªããæ³¢åãšãã«ã®ãŒã¯ã<i>V</i>ãš<i>H</i>ãããªãä»»æã®é·ãã®æååã§è¡šçŸãããããŒãã£ã¯ã«ã®å®å®ç©ºéã«ãããæŒãæ¹ãèŠå®ããã<i>V</i>ã¯åº§æšäž(+1, 0)ã®ç§»åãæå³ãã<i>H</i>ã¯(0, +1)ã®ç§»åãæå³ãããäŸãã°ã<i>VHHV</i>ãšããæ³¢åãšãã«ã®ãŒãäžããããããŒãã£ã¯ã«ã¯ã(2, 1), (2, 2), (2, 3) ãšããè»è·¡ã§å®å®ãæŒã£ãåŸã座æš(3, 3)ã«èŸ¿ãçãã</p>
<p>ãŸããå®å®ç©ºéã«ã¯è€æ°ã®ã¯ãŒãããŒã«ãååšããããŒãã£ã¯ã«ã®è»è·¡ã«åœ±é¿ãäžãããã¯ãŒãããŒã«ã«ã¯å
¥å£ãšåºå£ããããããŒãã£ã¯ã«ãã¯ãŒãããŒã«ã®å
¥å£ã«ç§»åããå Žåãå¿
ãåºå£ã®åº§æšã«ã¯ãŒãããããšã«ãªããiçªç®ã®ã¯ãŒãããŒã«ã®å
¥å£ãšåºå£ã®åº§æšã(a<sub>i</sub>, b<sub>i</sub>), (c<sub>i</sub>, d<sub>i</sub>)ãšãããšãa<sub>i</sub> ≤ c<sub>i</sub>, b<sub>i</sub> ≤ d<sub>i</sub>, (a<sub>i</sub>, b<sub>i</sub>) ≠ (c<sub>i</sub>, d<sub>i</sub>)ã®æ¡ä»¶ãæºããããŠãããã¯ãŒãããŒã«ã®å
¥å£ã¯ãä»ã®ã¯ãŒãããŒã«ã®å
¥å£ãšåã座æšãã(1, 1)ã«ã¯ååšããªãããšãä¿èšŒãããŠããããã ããè€æ°ã®åºå£ãåãå Žæã«ãã£ãããããã¯ãŒãããŒã«ã®åºå£ã«å¥ã®ã¯ãŒãããŒã«ã®å
¥å£ãããå Žåã¯ãã(ãã®å Žåã¯é£ç¶ã§ã¯ãŒããã)ã</p>
<p>äŸãã°ã(1, 2)ãå
¥å£ãšãã(3, 2)ãåºå£ãšããã¯ãŒãããŒã«ãååšããå Žåã<i>HH</i>ãšæ³¢åãšãã«ã®ãŒãäžããããããŒãã£ã¯ã«ã¯ã(1, 2)ãžç§»ååŸã(3, 2)ãžã¯ãŒããã (3, 3)ãžãšèŸ¿ãçãã</p>
<p>ããŒãã£ã¯ã«ã¯æ³¢åãšãã«ã®ãŒãäžãããããšäžç¬ã§ããã«åŸã£ãŠç§»åãããå
šãŠã®ããŒãã£ã¯ã«ãåæã«ç®çå°ç¹ãžèŸ¿ãçããšãèªåçã«å
ã®ç©è³ªãžãšåæ§æãããã</p>
<p>ããªãã¯å®å®éçºæ©æ§ã®ããã°ã©ãã§ããã転éã®ç®çåº§æš (N, M) ãš K åã®ã¯ãŒãããŒã«ã®åº§æšå¯Ÿãäžããããã®ã§ãäžåºŠã«è»¢éå¯èœãªç©è³ªã®æå€§è³ªéãæ±ããããã°ã©ã ãæžããŠã»ãããçãã¯éåžžã«å€§ããæ°ã«ãªãå¯èœæ§ãããããã1,000,000,007ã§å²ã£ãäœããåºåããã</p>
<h2>Input</h2>
<pre>
N M K
a<sub>1</sub> b<sub>1</sub> c<sub>1</sub> d<sub>1</sub>
...
a<sub>K</sub> b<sub>K</sub> c<sub>K</sub> d<sub>K</sub></pre>
<p>1 ≤ N,M ≤ 10<sup>5</sup>, 0 ≤ K ≤ 10<sup>3</sup> ãæºããããŸãã
ä»»æã® 1 ≤ i ≤ K ã«å¯Ÿã㊠a<sub>i</sub> ≤ c<sub>i</sub>, b<sub>i</sub> ≤ d<sub>i</sub>, (a<sub>i</sub>, b<sub>i</sub>) ≠ (c<sub>i</sub>, d<sub>i</sub>) ãæºããã</p>
<h2>Output</h2>
<p>æå€§è³ªéã 1,000,000,007 ã§å²ã£ãããŸãã1è¡ã§åºåããã
</p>
<h2>Notes on Test Cases</h2>
<p>
äžèšå
¥å圢åŒã§è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã«å¯ŸããŠäžèšåºå圢åŒã§åºåãè¡ãããã°ã©ã ãäœæããŠäžããã
</p>
<p>
N, M, K ããã¹ãŠ 0 ã®ãšãå
¥åã®çµããã瀺ããŸãã
</p>
<!--
<h2>Sample Input 1</h2>
<pre>4 4 1
2 2 3 3
</pre>
<h2>Output for Sample Input 1</h2>
<pre>12
</pre>
<h2>Sample Input 2</h2>
<pre>1 4 1
1 2 1 3
</pre>
<h2>Output for Sample Input 2</h2>
<pre>1
</pre>
<h2>Sample Input 3</h2>
<pre>5 5 2
2 2 3 4
3 3 5 3
</pre>
<h2>Output for Sample Input 3</h2>
<pre>26
</pre>
<h2>Sample Input 4</h2>
<pre>5 5 3
4 4 5 5
2 2 3 3
3 3 4 4
</pre>
<h2>Output for Sample Input 4</h2>
<pre>18
</pre>
<h2>Sample Input 5</h2>
<pre>100000 100000 1
2 2 99999 99999
</pre>
<h2>Output for Sample Input 5</h2>
<pre>615667476
</pre>
<h2>Sample Input 6</h2>
<pre>1 1 0
</pre>
<h2>Output for Sample Input 6</h2>
<pre>1
</pre>
-->
<h2>Sample Input</h2>
<pre>
4 4 1
2 2 3 3
1 4 1
1 2 1 3
5 5 2
2 2 3 4
3 3 5 3
5 5 3
4 4 5 5
2 2 3 3
3 3 4 4
100000 100000 1
2 2 99999 99999
1 1 0
0 0 0
</pre>
<h2>Output for Sample Input</h2>
<pre>
12
1
26
18
615667476
1
</pre>
|
p01624 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<!--
<h3><u>Ononokomachi's Edit War</u></h3>
-->
<!-- end en only -->
<!-- begin ja only -->
<h1><u>å°éå°çºã®ç·šéåæŠ</u></h1>
<!-- end ja only -->
<!-- begin en only -->
<!--
<p>
English text is not available in this practice contest.
</p>
-->
<!-- end en only -->
<!-- begin ja only -->
<p>
è¿æã«äœãç§ç°å士ã¯åšéã®æŽå²ç ç©¶å®¶ã§ãã, æè¿å°éå°çºã«é¢ããæ°ããªå€ææžãçºèŠããããã .
</p>
<p>
å°éå°çºã亀éãæãæ·±èå°å°ã«100倿¬ ãããéãç¶ããããšãæ¡ä»¶ã«åºãããšããäŒèª¬ã¯åºãç¥ãããŠããã, 圌ã®äž»åŒµã«ãããš, ãã®çºèŠã«ããæ°ãã«, 2äººã¯æ¯æ©ãšããã²ãŒã ãããŠããããšãããã£ããšãã.
</p>
<p>
ãã®ã«ãŒã«ã¯ä»¥äžã®éãã§ãã.
</p>
<ul>
<li>æåã«å¬äœ¿ãç·šéåæ°ãšæå¹ãªæ°åŒã決ãã</li>
<li>æ·±èå°å°, å°éå°çº, æ·±èå°å°, å°éå°çº,... ãšããé ã«äº€äºã«æ°åŒãç·šéãã</li>
<li>æ·±èå°å°ãšå°éå°çºãåãããŠå¬äœ¿ã決ããåæ°ã®ç·šéãè¡ããšã²ãŒã ã¯çµäºãã</li>
<li>1åã®æ°åŒã®ç·šéã«ãããŠ, æ°åŒã« 1 æå远å , ãŸãã¯æ°åŒãã 1 æååé€ã®ãããããã§ãã</li>
<li>æ°åŒãç¡å¹ã«ãªããããªç·šéãããŠã¯ãªããªã</li>
</ul>
<p>
æå¹ãªæ°åŒã®è©³ããå®çŸ©ã¯äžèšãèŠãŠã»ãã.
</p>
<p>
ãã®ã²ãŒã ã«ãããŠ, æçµçãªæ°åŒã®èšç®çµæã倧ããã»ã©,
æ·±èå°å°ã®éãã¹ãæ¥æ°ãæžãããŠãããããšã«ãªã£ãŠããããã.
ããªãã¡, æ·±èå°å°ã¯çµæãæå€§åãããããšãç®çã§ãã,
å°éå°çºã¯æå°åãããããšãç®çã§ãã.
</p>
<p>
ãšããã§, 倿æžã«ã¯å¬äœ¿ã決ããç·šéåæ°ãšæ°åŒã«ã€ããŠã¯èšé²ãæ®ã£ãŠããã®ã§ããã,
èå¿ã®çµæã®æ¹ã¯è«é£ãã«ããèªããªããªã£ãŠããŸã£ãŠãã.
å士ã¯çµæã«èå³ãæã¡, èªåã§èšç®ããŠã¿ãããšæã£ããã®ã®, ã²ãŒã çè«ãåŸæã§ãªã圌ã«ã¯é£ãããããã, ãšããããè¿æã®ããªãã«å©ããæ±ããŠããããã .
ããã§ããªãã¯ããã°ã©ã ãæžããŠåœŒã«ååããããšã«ãã.
</p>
<p>
平宿代ã«çŸä»£çãªæ°åŒããã£ããšããããšã«è¡æ£èããæãããããããªãã, è¿æä»ãåããšãã倧矩ã®åã«, ãã®ãããªäºäºãæ°ã«ããã¹ãã§ã¯ãªãã®ã .
</p>
<h3>
æå¹ãªæ°åŒã®å®çŸ©
</h3>
<p>
ãã®ã²ãŒã ã«ãããæå¹ãªæ°åŒãšã¯, "(", ")", "*", "+", "-", "&", "^", "|", "0" - "9" ã® 18 çš®é¡ã®æåã®ã¿ãããªã空ã§ãªãæååã§ãã,
ããã«, æéåã®é
ã2é
æŒç®åã§çµåãããã®ã§ãã.
æžãäžããš,
</p>
<pre>
[é
][2é
æŒç®å][é
][2é
æŒç®å]...[2é
æŒç®å][é
]
</pre>
<p>
ã®ããã«ãªã.
</p>
<p>
é
ãšã¯, "("[æå¹ãªæ°åŒ]")" ã®ããã«ã«ãã³ã§æãŸããæå¹ãªæ°åŒ, ãŸãã¯æ£ã®æŽæ°ã§ãã.
æ£ã®æŽæ°ã¯, å
é ã« "0" ãæããªã, æ°åã®ã¿ãããªãæååã§ãã.
</p>
<p>
æåŸã«, 2é
æŒç®åãšã¯, "*", "+", "-", "&", "^", "|" ã®ããããã¡ããã© 1 æåã§ãã.
詳ããå®çŸ©ã¯äžèšãèŠãŠã»ãã.
</p>
<p>
以äžã®èŠåãã,
</p>
<ul>
<li>"1+-1" ã®ããã«2æåããã®ã§æå¹ãª2é
æŒç®åã§ãªããã®,</li>
<li>"+1" ã®ããã«é
ã2é
æŒç®åã§çµåãããã®ã§ãªããã®,</li>
<li>"2)", "(3" ã®ããã«ã«ãã³ã®å¯Ÿå¿ããšããŠããªãã®ã§æå¹ãªé
ã§ãªããã®,</li>
<li>"0", "01" ã®ããã« 0 ã§å§ãŸãæå¹ãªæ£ã®æŽæ°ã®è¡šçŸã§ãªããã®</li>
</ul>
<p>
ãªã©ã¯, ç¡å¹ãªæ°åŒã§ãããšã¿ãªããã.
</p>
<p>
äžæ¹ã§,
</p>
<ul>
<li>"(1+2)" ã®ããã«æãå€åŽã«ã«ãã³ãä»ããŠãããã®,</li>
<li>"((1+2))*3" ã®ããã«2éã«ã«ãã³ãä»ããŠãããã®,</li>
<li>"(1)+3" ã®ããã«æ¬åŒ§å
ã«æ°ãããªããã®,</li>
<li>"(1*2)+3" ã®ããã«2é
æŒç®åã®åªå
é äœãšåãã«ãªããã®,</li>
</ul>
<p>
ãªã©ã¯, åé·ã§ã¯ããã, äžã®èŠåã®äžã§ã¯åçãã, æå¹ãªæ°åŒãšã¿ãªãããããšã«æ³šæããŠã»ãã.
</p>
<h3>
2é
æŒç®åã®çš®é¡
</h3>
<p>
ãã®ã²ãŒã ã«ãããŠ, 2é
æŒç®å㯠"*", "+", "-", "&", "^", "|" ã® 6 çš®é¡ããã.
ãããã, ä¹ç®, å ç®, æžç®, ãããããšã®è«çç©, ãããããšã®æä»çè«çå, ãããããšã®è«çåã§ãã.
ãªã, ãããæŒç®ãèãããšã, è² ã®æ°ã¯åå倧ããªæ¡æ°ã®2ã®è£æ°ã§è¡šçŸãããŠãããšèŠãªããã. ããªãã¡, æ®éã®ç¬Šå·ä»ãæŽæ°åã§èšç®ãããšèããŠããã.
</p>
<p>
ãŸã, åªå
é äœã¯é«ãæ¹ãã,
</p>
<ol>
<li>*</li>
<li>+, -</li>
<li>&</li>
<li>^</li>
<li>|</li>
</ol>
<p>
ã®é ã§ãã.
</p>
<p>
ãªã, + ãã * ã®æ¹ãåªå
é äœãé«ããšã¯,
</p>
<pre>
2*4+3*5
</pre>
<p>
ã®ãããªåŒã«ãã㊠* ã®ã»ããå
ã«èšç®ããããšããæå³ã§ãã, èšãæãããš,
</p>
<pre>
(2*4)+(3*5)
</pre>
<p>
ãšãªããšããããšã§ãã.
</p>
<p>
ãŸã, ãã¹ãŠã®2é
æŒç®åã¯å·Šçµåã§ãããšãã.
ããã¯,
</p>
<pre>
2^4^3^5
</pre>
<p>
ã®ãããªåŒã«ãããŠå·Šããé ã«èšç®ãããšããæå³ã§ãã, èšãæãããš,
</p>
<pre>
((2^4)^3)^5
</pre>
<p>
ãšãªããšããããšã§ãã.
</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ããããæ§æããã. åããŒã¿ã»ããã¯1åã®ã²ãŒã ã§å¬äœ¿ã決ããç·šéåæ°ãšæ°åŒã衚ã, ãã®åœ¢åŒã¯ä»¥äžã®éãã§ãã.
</p>
<pre>
<var>N</var> <var>Expression</var>
</pre>
<p>
<var>N</var> ã¯å¬äœ¿ã決ããç·šéåæ°ã§ãã, 1 ≤ <var>N</var> ≤ 11 ãšä»®å®ããŠãã.
ãŸã, <var>Expression</var> ã¯å¬äœ¿ã決ããæ°åŒã§ãã, "(", ")", "*", "+", "-", "&", "^", "|", "0" - "9" ã® 18 çš®é¡ã®æåã®ã¿ãããªã, 7 æå以äžã®ç©ºã§ãªãæååãšããŠäžãããã.
ãªã, äžã§å®çŸ©ããæå¹ãªæ°åŒã®ã¿ãäžããã, ç¡å¹ãªæ°åŒãäžããããããšã¯ãªããšä»®å®ããŠãã.
</p>
<p>
å
¥åã®çµããã¯,
</p>
<pre>
<var>0</var> <var>#</var>
</pre>
<p>
ã§è¡šããã.
</p>
<p>
ãªã, ããŒã¿ã»ãã㯠99 å以äžã§ãããšä»®å®ããŠãã.
</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>
åããŒã¿ã»ããã«å¯ŸããŠ, äž¡è
ãæåãå°œããããšãã®æçµçãªæ°åŒã®èšç®çµæã 1 è¡ã§åºåãã.
ãã以å€ã®äœèšãªæåãåºåããŠã¯ãªããªã.
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>
1 1
2 2
3 1+2*3-4
3 1|2^3&4
3 (1+2)*3
3 1-1-1-1
0 #
</pre>
<!-- begin ja only -->
<!-- end ja only -->
<h3>Output for Sample Input</h3>
<pre>
91
2
273
93
279
88
</pre>
<!-- begin ja only -->
<!-- end ja only -->
|
p03619 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In the city of Nevermore, there are <var>10^8</var> streets and <var>10^8</var> avenues, both numbered from <var>0</var> to <var>10^8-1</var>.
All streets run straight from west to east, and all avenues run straight from south to north.
The distance between neighboring streets and between neighboring avenues is exactly <var>100</var> meters.</p>
<p>Every street intersects every avenue. Every intersection can be described by pair <var>(x, y)</var>, where <var>x</var> is avenue ID and <var>y</var> is street ID.</p>
<p>There are <var>N</var> fountains in the city, situated at intersections <var>(X_i, Y_i)</var>.
Unlike normal intersections, there's a circle with radius <var>10</var> meters centered at the intersection, and there are no road parts inside this circle.</p>
<p>The picture below shows an example of how a part of the city with roads and fountains may look like.</p>
<div style="text-align: center;">
<img alt="1f931bf0c98ec6f07e612b0282cdb094.png" src="https://img.atcoder.jp/agc019/1f931bf0c98ec6f07e612b0282cdb094.png">
</img></div>
<p>City governors don't like encountering more than one fountain while moving along the same road.
Therefore, every street contains at most one fountain on it, as well as every avenue.</p>
<p>Citizens can move along streets, avenues and fountain perimeters.
What is the shortest distance one needs to cover in order to get from intersection <var>(x_1, y_1)</var> to intersection <var>(x_2, y_2)</var>?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 \leq x_1, y_1, x_2, y_2 < 10^8</var></li>
<li><var>1 \leq N \leq 200,000</var></li>
<li><var>0 \leq X_i, Y_i < 10^8</var></li>
<li><var>X_i \neq X_j</var> for <var>i \neq j</var></li>
<li><var>Y_i \neq Y_j</var> for <var>i \neq j</var></li>
<li>Intersections <var>(x_1, y_1)</var> and <var>(x_2, y_2)</var> are different and don't contain fountains.</li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>x_1</var> <var>y_1</var> <var>x_2</var> <var>y_2</var>
<var>N</var>
<var>X_1</var> <var>Y_1</var>
<var>X_2</var> <var>Y_2</var>
<var>:</var>
<var>X_N</var> <var>Y_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the shortest possible distance one needs to cover in order to get from intersection <var>(x_1, y_1)</var> to intersection <var>(x_2, y_2)</var>, in meters.
Your answer will be considered correct if its absolute or relative error doesn't exceed <var>10^{-11}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 1 6 5
3
3 2
5 3
2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>891.415926535897938
</pre>
<p>One possible shortest path is shown on the picture below. The path starts at the blue point, finishes at the purple point and follows along the red line.</p>
<div style="text-align: center;">
<img alt="c49e52b9b79003f61b8a6efa5dad8ba3.png" src="https://img.atcoder.jp/agc019/c49e52b9b79003f61b8a6efa5dad8ba3.png"/>
</div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 5 6 4
3
3 2
5 3
2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>400.000000000000000
</pre>
<div style="text-align: center;">
<img alt="f9090ab734c89424c413f3b583376990.png" src="https://img.atcoder.jp/agc019/f9090ab734c89424c413f3b583376990.png"/>
</div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 2 2 2
3
3 2
5 3
2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>211.415926535897938
</pre>
<div style="text-align: center;">
<img alt="4b76416161f27cad20333a9ac636e00f.png" src="https://img.atcoder.jp/agc019/4b76416161f27cad20333a9ac636e00f.png"/>
</div></section>
</div>
</span> |
p00936 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
</script>
<h2>Problem B
Squeeze the Cylinders</h2>
<p>
Laid on the flat ground in the stockyard are a number of heavy metal cylinders with (possibly) different diameters but with the same length. Their ends are aligned and their axes are oriented to exactly the same direction.
</p>
<p>
We'd like to minimize the area occupied. The cylinders are too heavy to lift up, although rolling them is not too difficult. So, we decided to push the cylinders with two high walls from both sides.
</p>
<p>
Your task is to compute the minimum possible distance between the two walls when cylinders are squeezed as much as possible. Cylinders and walls may touch one another. They cannot be lifted up from the ground, and thus their order cannot be altered.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2015_SqueezeTheCylinders_1"><br>
<p>
Figure B.1. Cylinders between two walls
</p>
</center>
<h3>Input</h3>
<p>
The input consists of a single test case. The first line has an integer $N$ $(1 \leq N \leq 500)$, which is the number of cylinders. The second line has $N$ positive integers at most 10,000. They are the radii of cylinders from one side to the other.
</p>
<h3>Output</h3>
<p>
Print the distance between the two walls when they fully squeeze up the cylinders. The number should not contain an error greater than 0.0001.
</p>
<h3>Sample Input 1</h3>
<pre>2
10 10</pre>
<h3>Sample Output 1</h3>
<pre>40.00000000</pre>
<h3>Sample Input 2</h3>
<pre>2
4 12</pre>
<h3>Sample Output 2</h3>
<pre>29.85640646</pre>
<h3>Sample Input 3</h3>
<pre>5
1 10 1 10 1</pre>
<h3>Sample Output 3</h3>
<pre>40.00000000</pre>
<h3>Sample Input 4</h3>
<pre>3
1 1 1</pre>
<h3>Sample Output 4</h3>
<pre>6.00000000</pre>
<h3>Sample Input 5</h3>
<pre>2
5000 10000</pre>
<h3>Sample Output 5</h3>
<pre>29142.13562373</pre>
<p>
The following figures correspond to the Sample 1, 2, and 3.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2015_SqueezeTheCylinders_2">
</center>
|
p01274 |
<H1><font color="#000">Problem B:</font> Magic Slayer</H1>
<p>
You are in a fantasy monster-ridden world. You are a slayer fighting against the monsters with magic
spells.
</p>
<p>
The monsters have <i>hit points</i> for each, which represent their vitality. You can decrease their hit points
by your magic spells: each spell gives certain points of <i>damage</i>, by which monsters lose their hit points,
to either one monster or all monsters in front of you (depending on the spell). Monsters are defeated
when their hit points decrease to less than or equal to zero. On the other hand, each spell may consume
a certain amount of your <i>magic power</i>. Since your magic power is limited, you want to defeat monsters
using the power as little as possible.
</p>
<p>
Write a program for this purpose.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset has the following format:
</p>
<p>
<i>N</i><br>
<i>HP</i><sub>1</sub><br>
<i>HP</i><sub>2</sub><br>
...<br>
<i>HP</i><sub><i>N</i></sub><br>
<i>M</i><br>
<i>Name</i><sub>1</sub> <i>MP</i><sub>1</sub> <i>Target</i><sub>1</sub> <i>Damage</i><sub>1</sub><br>
<i>Name</i><sub>2</sub> <i>MP</i><sub>2</sub> <i>Target</i><sub>2</sub> <i>Damage</i><sub>2</sub><br>
...<br>
<i>Name</i><sub><i>M</i></sub> <i>MP</i><sub><i>M</i></sub> <i>Target</i><sub><i>M</i></sub> <i>Damage</i><sub><i>M</i></sub><br>
</p>
<p>
<i>N</i> is the number of monsters in front of you (1 ≤ <i>N</i> ≤ 100); <i>HP<sub>i</sub></i> is the hit points of the <i>i</i>-th monster
(1 ≤ <i>HP<sub>i</sub></i> ≤ 100000); <i>M</i> is the number of available magic spells (1 ≤ <i>M</i> ≤ 100); <i>Name<sub>j</sub></i> is the name
of the <i>j</i>-th spell, consisting of up to 16 uppercase and lowercase letters; <i>MP<sub>j</sub></i> is the amount of magic
power consumed by the <i>j</i>-th spell (0 ≤ <i>MP<sub>j</sub></i> ≤ 99); <i>Target<sub>j</sub></i> is either "<span>Single</span>" or "<span>All</span>", where these
indicate the <i>j</i>-th magic gives damage just to a single monster or to all monsters respectively; <i>Damage<sub>j</sub></i> is
the amount of damage (per monster in case of "<span>All</span>") made by the <i>j</i>-th magic (0 ≤ <i>Damage<sub>j</sub></i> ≤ 999999).
</p>
<p>
All the numbers in the input are integers. There is at least one spell that gives non-zero damage to
monsters.
</p>
<p>
The last dataset is followed by a line containing one zero. This line is not a part of any dataset and should not be processed.
</p>
<H2>Output</H2>
<p>
For each dataset, Print in a line the minimum amount of magic power consumed to defeat all the monsters in the input.
</p>
<H2>Sample Input</H2>
<pre>
3
8000 15000 30000
3
Flare 45 Single 8000
Meteor 62 All 6000
Ultimate 80 All 9999
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
232
</pre>
|
p03249 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a sequence <var>D_1, D_2, ..., D_N</var> of length <var>N</var>.
<strong>The values of <var>D_i</var> are all distinct.</strong>
Does a tree with <var>N</var> vertices that satisfies the following conditions exist?</p>
<ul>
<li>The vertices are numbered <var>1,2,..., N</var>.</li>
<li>The edges are numbered <var>1,2,..., N-1</var>, and Edge <var>i</var> connects Vertex <var>u_i</var> and <var>v_i</var>.</li>
<li>For each vertex <var>i</var>, the sum of the distances from <var>i</var> to the other vertices is <var>D_i</var>, assuming that the length of each edge is <var>1</var>.</li>
</ul>
<p>If such a tree exists, construct one such tree.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 100000</var></li>
<li><var>1 \leq D_i \leq 10^{12}</var></li>
<li><var>D_i</var> are all distinct.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>D_1</var>
<var>D_2</var>
<var>:</var>
<var>D_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If a tree with <var>n</var> vertices that satisfies the conditions does not exist, print <code>-1</code>.</p>
<p>If a tree with <var>n</var> vertices that satisfies the conditions exist, print <var>n-1</var> lines.
The <var>i</var>-th line should contain <var>u_i</var> and <var>v_i</var> with a space in between.
If there are multiple trees that satisfy the conditions, any such tree will be accepted.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7
10
15
13
18
11
14
19
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1 2
1 3
1 5
3 4
5 6
6 7
</pre>
<p>The tree shown below satisfies the conditions.</p>
<p><img alt="" src="https://img.atcoder.jp/arc103/92920696862ead4cacf3755c3c8135e0.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
1
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>15
57
62
47
45
42
74
90
75
54
50
66
63
77
87
51
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1 10
1 11
2 8
2 15
3 5
3 9
4 5
4 10
5 15
6 12
6 14
7 13
9 12
11 13
</pre></section>
</div>
</span> |
p02008 | <h1>Problem E. Magic Triangles</h1>
<!--
Time Limit: 2 sec
Memory Limit: 512 MB
-->
<p>
Fallen angel Yohane plans to draw a magic symbol composed of triangles on the earth. By casting some magic spell on the symbol, she will obtain magic power; this is the purpose for which she will draw a magic symbol. The magic power yielded from the magic symbol is determined only by the common area of all the triangles. Suppose the earth is a two-dimensional plane and the vertices of the triangles are points on the plane. Yohane has already had a design of the magic symbol, i.e. the positions, sizes, shapes of the triangles. However, she does not know how much magic power will be obtained from the symbol. Your task as a familiar of the fallen angel is to write a program calculating the common area of given triangles on a two-dimensional plane.
</p>
<h2>Input</h2>
<p>
The input consists of a single test case in the following format.
</p>
<pre>
$N$
$x_{1,1}$ $y_{1,1}$ $x_{1,2}$ $y_{1,2}$ $x_{1,3}$ $y_{1,3}$
$...$
$x_{N,1}$ $y_{N,1}$ $x_{N,2}$ $y_{N,2}$ $x_{N,3}$ $y_{N,3}$
</pre>
<p>
The first line contains an integer $N$, which is the number of triangles ($1 \leq N \leq 10^5$). The $i$-th line of the following $N$ lines contains six integers $x_{i,1}$, $y_{i,1}$, $x_{i,2}$, $y_{i,2}$, $x_{i,3}$, and $y_{i,3}$, where ($x_{i,j}, y_{i,j}$)is the coordinate of the $j$-th vertex of the $i$-th triangle ($-1,000 \leq x_{i,j}, y_{i,j} \leq 1,000$).
</p>
<p>
You can assume the followings:
</p>
<ul>
<li>Every triangle has a positive area.</li>
<li>The vertices of every triangle are in the counter-clockwise order.</li>
</ul>
<h2>Output</h2>
<p>
Output the common area of given triangles in a line. The output can contain an absolute or relative error no more than $10^{-6}$.
</p>
<h2>Examples</h2>
<h2>Sample Input 1</h2>
<pre>
2
0 0 2 0 0 2
0 1 2 1 0 3
</pre>
<h2>Output for Sample Input 1</h2>
<pre>
0.5
</pre>
<h2>Sample Input 2</h2>
<pre>
2
0 0 100 0 50 100
50 -50 100 50 0 50
</pre>
<h2>Output for Sample Input 2</h2>
<pre>
3125
</pre>
<h2>Sample Input 3</h2>
<pre>
5
0 0 1 0 0 1
0 0 2 0 0 2
0 0 3 0 0 3
0 0 4 0 0 4
0 0 5 0 0 5
</pre>
<h2>Output for Sample Input 3</h2>
<pre>
0.5
</pre>
|
p00035 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>åžïŒ</H1>
<p>
å¹³é¢äžã®ç°ãªã 4 ç¹ã$A (x_a, y_a)$, $B (x_b, y_b)$, $C (x_c, y_c)$, $D(x_d, y_d)$ ã®åº§æšãèªã¿èŸŒãã§ãããã 4 ç¹ãé ç¹ãšããåè§åœ¢ $ABCD$ ã«å¹ã¿ããªããã° YESãå¹ã¿ãããã° NO ãšåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<p>
å¹ã¿ã®ããåè§åœ¢ãšã¯å³ 1 ã®ãããªåè§åœ¢ã§ãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_isConvex">
</center>
<br/>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã®åœ¢åŒã¯ä»¥äžã®ãšããã§ãã<br/>
<br/>
$x_a$,$y_a$,$x_b$,$y_b$,$x_c$,$y_c$,$x_d$,$y_d$
</p>
<p>
$x_a$, $y_a$, $x_b$, $y_b$, $x_c$, $y_c$, $x_d$, $y_d$ ã¯ãããã -100 ä»¥äž 100 以äžã§ããã宿°ã§äžããããŸãã
</p>
<p>
1 çŽç·äžã« 3 ã€ä»¥äžç¹ã䞊ã¶ããšã¯ãªããã®ãšããŸãããŸããå
¥åé ã«ç¹ãçµãã§ããã°ãåè§åœ¢ã«ãªãé çªã«ç¹ã®åº§æšãå
¥åããããã®ãšããŸããïŒã€ãŸããå³ 2 ã®ãããªåœ¢ã«ãªãé çªã§ç¹ãäžããããããšã¯ãããŸããã)
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
åããŒã¿ã»ããããšã«ãYES ãŸã㯠NO ãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0
0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
p02458 | <h1>Multi-Set</h1>
<p>
For a set $S$ of integers, perform a sequence of the following operations. Note that <u>multiple elements can have equivalent values in $S$</u>.
</p>
<ul>
<li>insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation.</li>
<li>find($x$): Report the number of $x$ in $S$.</li>
<li>delete($x$): Delete all $x$ from $S$.</li>
<li>dump($L$, $R$): Print elements $x$ in $S$ such that $L \leq x \leq R$.</li>
</ul>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$q$
$query_1$
$query_2$
:
$query_q$
</pre>
<p>
Each query $query_i$ is given by
</p>
<pre>
0 $x$
</pre>
<p>or</p>
<pre>
1 $x$
</pre>
<p>or</p>
<pre>
2 $x$
</pre>
<p>or</p>
<pre>
3 $L$ $R$
</pre>
<p>
where the first digits <span>0</span>, <span>1</span>, <span>2</span> and <span>3</span> represent insert, find, delete and dump operations respectively.
</p>
<h2>Output</h2>
<p>
For each insert operation, print the number of elements in $S$.<br>
For each find operation, print the number of specified elements in $S$.<br>
For each dump operation, print the corresponding elements in ascending order. Print an element in a line.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq q \leq 200,000$</li>
<li>$0 \leq x \leq 1,000,000,000$</li>
<li>The total number of elements printed by dump operations does not exceed $1,000,000$</li>
<li>The sum of numbers printed by find operations does not exceed $2,000,000$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
10
0 1
0 1
0 2
0 3
2 2
1 1
1 2
1 3
0 4
3 1 4
</pre>
<h2>Sample Output 1</h2>
<pre>
1
2
3
4
2
0
1
4
1
1
3
4
</pre>
|
p00465 |
<H1> èªèšŒã¬ãã« </H1>
<h2>åé¡</h2>
<p>
ããªã㯠Just Odd Inventions 瀟ãç¥ã£ãŠããã ããã? ãã®äŒç€Ÿã®æ¥åã¯ããã å¥åŠãªçºæ (just odd inventions)ããããããšã§ãã.ããã§ã¯ç¥ã㊠JOI 瀟ãšåŒã¶.
</p>
<p>
JOI 瀟ã«ã¯ 2 ã€ã®äºåæããã,ããããåã倧ããã®æ£æ¹åœ¢ã®éšå±ããã¹ç®ç¶ã«äžŠãã§ã§ããŠãã.èŸºã§æ¥ããŠãããã¹ãŠã®éšå±ã®éã«,身å蚌ã«ããèªèšŒæ©èœã®ä»ããæããã.JOI 瀟ã§ã¯æ§ã
ãªã¬ãã«ã®æ©å¯æ
å ±ãæ±ã£ãŠãããã,éšå±ããšã«æ©å¯ã¬ãã«ãšããæ£ã®æŽæ°ãèšå®ãããŠãã,身å蚌ã®äºåæããšã«å®ããããéè² æŽæ°ã®èªèšŒã¬ãã«ã,æ©å¯ã¬ãã«ä»¥äžã§ãªããšãã®éšå±ã«å
¥å®€ããããšãã§ããªã.åäºåæã®åºå
¥ãå£ã¯å¯äžãããšã¬ããŒã¿ãŒããŒã«ã®ã¿ã§,ãšã¬ããŒã¿ãŒããŒã«ã®éšå±ã®æ©å¯ã¬ãã«ã¯æäœã® 1 ã§ãã.ãã®äºåæã«ã€ããŠã®èªèšŒã¬ãã«ã 0 ã®ãšãã¯ãšã¬ããŒã¿ãŒããŒã«ã«å
¥ãããšããã§ããªã.
</p>
<p>
JOI 瀟ã§ã¯,瀟é·ã®çªçºçãªææ¡ã§,äžè¬ã®äººã«ç€Ÿå
ãèŠåŠããŠããããã¢ãŒã宿œããããšã«ãªã£ã.ããªãã¯èŠåŠè
ã«æž¡ã身å蚌ã®èªèšŒã¬ãã«ã®çµã¿åãããæ±ºããå¿
èŠããã.èŠåŠè
ã¯éããããæãèŠã€ãããšå¿
ãéããŠäžã«å
¥ã (åãéšå±ãäœåºŠã蚪ããããšãå¯èœã§ãã).ãã®ãã,å¿
èŠä»¥äžã«èŠåŠè
ã®èº«å蚌ã®èªèšŒã¬ãã«ãé«ããããã¯ãªã.ããã,ãã¢ãŒã«é
åãæããããã,ãã¢ãŒã§ã¯ãšã¬ããŒã¿ãŒããŒã«ã®éšå±ãå«ã 2 ã€ã®äºåæã§ããã㊠R å以äžã®éšå±ã蚪ããããšãã§ããããã«ããå¿
èŠããã.身å蚌ã®èªèšŒã¬ãã«ãäœããããããš,ãã®æ¡ä»¶ãæºããããšãã§ããªããããããªã.
</p>
<p>
JOI 瀟ã«ã¯äºåæã 2 åãã,第 <i>k</i> äºåæ (<i>k</i> = 1, 2) ã®éšå±ã¯æ±è¥¿æ¹åã« <i>W<sub>k</sub></i> å,ååæ¹åã« <i>H<sub>k</sub></i> å䞊ãã§ãã,å
šéšã§ <i>W<sub>k</sub></i> × <i>H<sub>k</sub></i> åãã. 西ãã <i>i</i> çªç®,åãã <i>j</i> çªç®ã®éšå±ã (<i>i</i>, <i>j</i>)<sub><i>k</i></sub> ã§è¡šãããšã«ãã.
</p>
<p>
<i>W<sub>k</sub></i> ãš <i>H<sub>k</sub></i> ãš <i>R</i> ã®å€,ãšã¬ããŒã¿ãŒããŒã«ã®äœçœ® (<i>X<sub>k</sub></i>, <i>Y<sub>k</sub></i> )<sub><i>k</i></sub> ,åéšå±ã®æ©å¯ã¬ãã«ãäžãããããšã,èŠåŠè
ã 2 ã€ã®äºåæã§ããã㊠<i>R</i> å以äžã®éšå±ã蚪ããããšãã§ããããã®,èŠåŠè
ã®èº«å蚌ã®èªèšŒã¬ãã«ã®åã®æå°å€ãæ±ããããã°ã©ã ãäœæãã.
</p>
<p>
ãªã,JOI 瀟ãããã å¥åŠãªçºæããããããšã§ã©ããã£ãŠå©çãåŸãŠãããã¯,瀟å
ã§ãæé«æ©å¯ã§ãã瀟é·ä»¥å€ã®èª°ãç¥ããªã.
</p>
<h2>å
¥å</h2>
<p>
<!-- å
¥åãã¡ã€ã«ã®ãã¡ã€ã«å㯠input.txt ã§ãã.<br>-->
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ
</p>
<p>
1 è¡ç®ã«ã¯æ£æŽæ° R (1 ≤ <i>R</i> ≤ 100000) ãæžãããŠãã.2 è¡ç®ä»¥éã«ã¯,2 ã€ã®äºåæã®ããŒã¿ãé ã«äžãããã.
</p>
<p>
äºåæã®ããŒã¿ã¯,æåã®è¡ã«æ£æŽæ° <i>W<sub>k</sub></i>, <i>H<sub>k</sub></i>, <i>X<sub>k</sub></i>, <i>Y<sub>k</sub></i> (1 ≤ <i>X<sub>k</sub></i> ≤ <i>W<sub>k</sub></i> ≤ 500, 1 ≤ <i>Y<sub>k</sub></i> ≤ <i>H<sub>k</sub></i> ≤ 500), ç¶ã <i>H<sub>k</sub></i> è¡ã® <i>j</i> è¡ç®ã® <i>i</i> çªç®ã«, éšå± (<i>i</i>, <i>j</i>)<sub><i>k</i></sub> ã®æ©å¯ã¬ãã«ãè¡šãæŽæ° <i>L<sub>k, i,j</sub></i> (1 ≤ <i>L<sub>k,i,j</sub></i> < 100000000 = 10<sup>8</sup>) ãšããŠäžãããã.
</p>
<p>
ãŸã, <i>R</i> ≤ <i>W</i><sub>1</sub> × <i>H</i><sub>1</sub> + <i>W</i><sub>2</sub> × <i>H</i><sub>2</sub> ãæºãã.
</p>
<p>
æ¡ç¹çšããŒã¿ã®ãã¡, é
ç¹ã® 30% åã«ã€ããŠã¯, <i>R</i>, <i>W<sub>k</sub></i>, <i>H<sub>k</sub></i> ≤ 100 ãæºãã.
</p>
<p>
<i>R</i> ã 0 ã®ãšãå
¥åã®çµäºã瀺ã.ãããŒã¿ã»ããã®æ°ã¯ 10 ãè¶
ããªãïŒ
</p>
<h2>åºå</h2>
<p>
<!--åºåãã¡ã€ã«ã®ãã¡ã€ã«å㯠output.txt ã§ãã.-->
ããŒã¿ã»ããããšã«,æ±ãã身å蚌ã®èªèšŒã¬ãã«ã®åã®æå°å€ã 1 è¡ã«åºåãã.
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ</h3>
<pre>
5
2 2 1 2
9 5
1 17
3 2 2 1
6 1 20
8 18 3
8
5 4 1 3
5 5 4 5 5
8 2 1 9 7
1 1 3 5 1
7 2 7 1 3
6 5 6 2
2 3 5 8 2 7
1 6 9 4 5 1
2 4 5 4 2 2
5 4 2 5 3 3
7 1 5 1 5 6
6
3 3 2 2
2 9 2
9 1 9
2 9 2
2 2 1 1
1 3
5 7
0
</pre>
<h3>åºåäŸ</h3>
<pre>
15
4
9
</pre>
<p>
1ã€ç®ã®äŸ ã§ã¯,èŠåŠè
ã«æž¡ã身å蚌ã®èªèšŒã¬ãã«ã,äºåæ 1 ã®èªèšŒã¬ãã«ã 9,äºåæ 2 ã®èªèšŒã¬ãã«ã 6 ãšãªãããã«èšå®ãããš,èŠåŠè
㯠5 åã®éšå± (äºåæ 1 ã®éšå± (1, 1)<sub>1</sub> , (1, 2)<sub>1</sub> , (2, 1)<sub>1</sub> ãš,äºåæ 2 ã®éšå± (1, 1)<sub>2</sub> , (2, 1)<sub>2</sub> ) ã蚪ããããšãã§ãã.ãã®ãšã,èªèšŒã¬ãã«ã®å㯠15 ãšãªã.ãããåèš 5 å以äžã®éšå±ã蚪ããããšãã§ããããã®èªèšŒã¬ãã«ã®åã®æå°å€ã§ãã.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_authentication1">
</center>
<br>
<p>
ïŒã€ç®ã®äŸ ã§ã¯,èŠåŠè
ã«æž¡ã身å蚌ã®èªèšŒã¬ãã«ã,äºåæ 1 ã®èªèšŒã¬ãã«ã 9,äºåæ 2 ã®èªèšŒã¬ãã«ã 0 ãšãªãããã«èšå®ãããš,èŠåŠè
㯠9 åã®éšå± (äºåæ 1 ã®éšå± (1, 1)<sub>1</sub>, (1, 2)<sub>1</sub>, (1, 3)<sub>1</sub>, (2, 1)<sub>1</sub>, (2, 2)<sub>1</sub>, (2, 3)<sub>1</sub>, (3, 1)<sub>1</sub>, (3, 2)<sub>1</sub>, (3, 3)<sub>1</sub> ) ã蚪ããããšãã§ãã.äºåæ 2 ã®éšå±ã¯ 1 åã蚪ããããšãã§ããªã.(ãšã¬ããŒã¿ãŒããŒã« (1, 1)<sub>2</sub>ã«ããå
¥ãããšãã§ããªã.) ãã®ãšã,èªèšŒã¬ãã«ã®å㯠9 ãšãªã.ãããåèš 6 å以äžã®éšå±ã蚪ããããšãã§ããããã®èªèšŒã¬ãã«ã®åã®æå°å€ã§ãã.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_authentication2">
</center>
<br>
<div class="source">
<p class="source">
äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p01960 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }});
</script>
<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"></script>
<H1>
Tree Separator
</H1>
<p>
You are given a tree $T$ and an integer $K$. You can choose arbitrary distinct two vertices $u$ and $v$ on $T$. Let $P$ be the simple path between $u$ and $v$. Then, remove vertices in $P$, and edges such that one or both of its end vertices is in $P$ from $T$. Your task is to choose $u$ and $v$ to maximize the number of connected components with $K$ or more vertices of $T$ after that operation.
</p>
<H2>Input</H2>
<p>
The input consists of a single test case formatted as follows.
</p>
<pre>
$N$ $K$
$u_1$ $v_1$
:
$u_{N-1}$ $v_{N-1}$
</pre>
<p>
The first line consists of two integers $N, K$ ($2 \leq N \leq 100,000, 1 \leq K \leq N$). The following $N-1$ lines represent the information of edges. The ($i+1$)-th line consists of two integers $u_i, v_i$ ($1 \leq u_i, v_i \leq N$ and $u_i \ne v_i $ for each $i$). Each $\{u_i, v_i\}$ is an edge of $T$. It's guaranteed that these edges form a tree.
</p>
<H2>Output</H2>
<p>
Print the maximum number of connected components with $K$ or more vertices in one line.
</p>
<H2>Sample Input 1</H2>
<pre>
2 1
1 2
</pre>
<H2>Output for Sample Input 1</H2>
<pre>
0
</pre>
<H2>Sample Input 2</H2>
<pre>
7 3
1 2
2 3
3 4
4 5
5 6
6 7
</pre>
<H2>Output for Sample Input 2</H2>
<pre>
1
</pre>
<H2>Sample Input 3</H2>
<pre>
12 2
1 2
2 3
3 4
4 5
3 6
6 7
7 8
8 9
6 10
10 11
11 12
</pre>
<H2>Output for Sample Input 3</H2>
<pre>
4
</pre>
<H2>Sample Input 4</H2>
<pre>
3 1
1 2
2 3
</pre>
<H2>Output for Sample Input 4</H2>
<pre>
1
</pre>
<H2>Sample Input 5</H2>
<pre>
3 2
1 2
2 3
</pre>
<H2>Output for Sample Input 5</H2>
<pre>
0
</pre>
<H2>Sample Input 6</H2>
<pre>
9 3
1 2
1 3
1 4
4 5
4 6
4 7
7 8
7 9
</pre>
<H2>Output for Sample Input 6</H2>
<pre>
2
</pre>
|
p00672 |
<h1>Problem D: Dimensional Analysis</h1>
<p>
éã®æ¬¡å
ãšã¯ãçžç°ãªãéã®éã®é¢ä¿åŒããå
·äœçæ°å€ãç¡èŠããŠéã®çš®é¡ãšãã®ã¹ãä¹ã ãã«çç®ããæŠå¿µã§ãããå
·äœçã«ã¯å®æ°ä¿æ°ãç¡èŠããçåŒãšããŠã次å
ã®é¢ä¿åŒã衚ããããªãã¡ãé q ã®æ¬¡å
ã[ q ]ãšè¡šãã°ã以äžã®ãããªããã€ãã®æ¬¡å
ã®é¢ä¿åŒãäŸç€ºã§ããã</p>
<ul>
<li>[é¢ç©] = [é·ã]<sup>2</sup></li>
<li>[äœç©] = [é·ã]<sup>3</sup></li>
<li>[éã] = [é·ã][æé]<sup>-1</sup></li>
<li>[å é床] = [é·ã][æé]<sup>-2</sup></li>
<li>[å] = [質é][é·ã][æé]<sup>-2</sup></li>
<li>[ä»äº] = [質é][é·ã]<sup>2</sup>[æé]<sup>-2</sup></li>
</ul>
<p>
(Wikipedia ãéãããæç² URL http://ja.wikipedia.org/wiki/%E9%87%8F)
<p>
éã¯åºæ¬éãšçµã¿ç«ãŠéã«åé¡ãããã
ãã®åé¡ã§ã¯nåã®åºæ¬éãšmåã®çµç«éãäžããããã
äžããããmåã®çµç«éã®æ¬¡å
ã¯ãã¹ãŠnåã®åºæ¬éã®æ¬¡å
ã®ç©ã§è¡šãããšãã§ããã
ãŸãåºæ¬éã®æ¬¡å
ã®ç©ã§ïŒã€ã®æ¬¡å
ã衚ãããšããååºæ¬éã®ææ°ããã¹ãŠäžèŽããã°ãã®äºã€ã®æ¬¡å
ã¯çãããšèšããã
</p>
<p>
åŒãšå€æ°ã®éãšéã®æ¬¡å
ã«ã€ããŠã®æ
å ±ãäžããããã®ã§ã
åŒãè§£æããã®æ¬¡å
ã衚ãéã®åç§°ãåºåããã
åç§°ãå®çŸ©ãããŠãªãå Žåã¯undefinedãšåºåããã
ãŸããèšç®éçšã§ç°ãªãäºã€ã®æ¬¡å
ã®å ç®ãããã¯æžç®ãããããªæŒç®ã®ããšãâäžæ£ãªæŒç®âã®å®çŸ©ããã
âäžæ£ãªæŒç®âãããã°errorãšåºåããã
äžããããåŒã¯ä»¥äžãæºããã
<ol>
<li>ãã¹ãŠã®å€æ°ã¯çµç«éã®æ¬¡å
ã«å²ãåœãŠãããŠããã</li>
<li>åŒã¯ååæŒç®+, -, /, *ãšã«ãã³ïŒïŒãšå€æ°ã®ã¿ãå«ãã</li>
<li>ååæŒç®ã¯ããç¥ãããŠãããã®ã§ãæ£ããèšè¿°ãããŠãããã®ãšãããå³å¯ã«ã¯ä»¥äžã®BNFã«åŸãã ãŸãåé
æŒç®åã¯äœ¿çšãããªãã(x * (-a))ãªã©ã¯ååšããªãã</li>
</ol>
<pre>
<formula>::=<term>|<formula>+<term>|<formula>-<term>
<term>::=<factor>|<term>*<factor>|<term>/<factor>
<factor>::=<variable>|(<formula>)
<variable>::=<string>
<string>::=<char>|<string><char>
<char>::=a~z|A~Z
<formula>ãåŒã衚ãã<variable>ã倿°åã衚ãã
</pre>
<h2>Input</h2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ããã§æ§æãããŠããã
ããŒã¿ã»ããã®æ°ã¯1,000åãè¶
ããªãã
ããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
n m p
derived<sub>1</sub>
d<sub>1,1</sub> d<sub>1,2</sub> d<sub>1,3</sub>.... d<sub>1,n</sub>
derived<sub>2</sub>
d<sub>2,1</sub> d<sub>2,2</sub> d<sub>2,3</sub>.... d<sub>2,n</sub>
...
derived<sub>m</sub>
d<sub>m,1</sub> d<sub>m,2</sub> d<sub>m,3</sub>.... d<sub>m,n</sub>
formula
v<sub>1</sub> D<sub>1</sub>
v<sub>2</sub> D<sub>2</sub>
...
v<sub>p</sub> D<sub>p</sub>
</pre>
<p>
n(1≤n≤5)ã¯åºæ¬éã®æ° m(1≤m≤10) ã¯çµç«éã®æ°ãp(1≤p≤15)ã¯å€æ°ã®çš®é¡æ°ã瀺ãã
derived<sub>i</sub>ã¯içªç®ã®çµç«éã®ååã§ãããã¢ã«ãã¡ããã倧æåãå°æåããæ§æããé·ãã¯20æåãè¶
ããªãã
d<sub>i,j</sub>(-10≤d<sub>i,j</sub>≤10)ã¯içªç®ã®çµç«éã®jçªç®ã®åºæ¬éã®æ¬¡å
ã衚ã(1≤i≤m, 1≤j≤n)ã
åãçµç«éã®åç§°ã¯è€æ°åçŸããªãã
åãæ¬¡å
ã®çµç«éãè€æ°åçŸããããšããããããã®å Žåã¯æåŸã«å®çŸ©ãããåç§°ããã®çµç«éã®åç§°ãšãªãã
formulaã¯è§£æãè¡ãæ°åŒã衚ããé·ãã¯100æåãè¶
ããªãã
v<sub>i</sub>ã¯å€æ°åã衚ããã¢ã«ãã¡ããã倧æåãå°æåããæ§æããé·ãã¯20æåãè¶
ããªãã
D<sub>i</sub>ã¯v<sub>i</sub>ã®æ¬¡å
ã®åç§°ã衚ãããã§ã«äžããããçµç«éã®åç§°ã§ããããšãä¿èšŒãããŠããã
å
¥åäžã®æ°ïŒn, m, p, dïŒã¯ãã¹ãп޿°ã§ããã
å
¥åã®çµããã¯ã3åã®0ãããããäžæåã®ç©ºçœã§åºåãããäžè¡ã§ç€ºãããã
</p>
<h2>Output</h2>
<p>
äžè¡ã«åŒãè§£æããã®æ¬¡å
ã®åç§°ãåºåããã
åç§°ãå®çŸ©ãããŠãªãå Žåã¯undefinedãšåºåããã
ãŸããäžæ£ãªæŒç®ãå«ãŸããå Žåã¯errorãšåºåããã
</p>
<h2>Sample Input</h2>
<pre>
2 3 2
length
1 0
time
0 1
speed
1 -1
a/b
a length
b time
2 3 3
length
1 0
time
0 1
speed
1 -1
a/b+c
a length
b time
c speed
2 3 3
length
1 0
time
0 1
speed
1 -1
a/b+c
a length
b time
c time
2 3 2
length
1 0
time
0 1
speed
1 -1
a/b/b
a length
b time
3 6 6
speed
1 -1 0
acceleration
1 -2 0
force
1 -2 1
length
1 0 0
time
0 1 0
weight
0 0 1
((v+l/t)+a*t)/(t*t)*w*t+f+w*a
v speed
l length
a acceleration
t time
w weight
f force
0 0 0
</pre>
<h2>Sample Output</h2>
<pre>
speed
speed
error
undefined
force
</pre> |
p00388 | <h1>Design of a Mansion</h1>
<p>
Our master carpenter is designing a condominium called Bange Hills Mansion. The condominium is constructed by stacking up floors of the same height. The height of each floor is designed so that the total height of the stacked floors coincides with the predetermined height of the condominium. The height of each floor can be adjusted freely with a certain range.
</p>
<p>
The final outcome of the building depends on clever height allotment for each floor. So, he plans to calculate possible combinations of per-floor heights to check how many options he has.
</p>
<p>
Given the height of the condominium and the adjustable range of each floorâs height, make a program to enumerate the number of choices for a floor.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$H$ $A$ $B$
</pre>
<p>
The input line provides the height of the condominium $H$ ($1 \leq H \leq 10^5$) and the upper and lower limits $A$ and $B$ of the height adjustable range for one floor ($1 \leq A \leq B \leq H$). All data are given as integers.
</p>
<h2>Output</h2>
<p>
Output the number of possible height selections for each floor in a line.
</p>
<h2>Sample Input 1</h2>
<pre>
100 2 4
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<h2>Sample Input 2</h2>
<pre>
101 3 5
</pre>
<h2>Sample Output 2</h2>
<pre>
0
</pre>
|
p00222 |
<H1>åã€åçŽ æ°</H1>
<p>
(<var>a, a+2, a+6, a+8</var>) ã®ããã«äžŠãã 4 ã€ã®çŽ æ°ã®çµãåã€åçŽ æ°ãšãããŸããåã€åçŽ æ°ãæ§æããåã€ã®çŽ æ°ã®ãã¡ãæå€§ã®æ°ããã®åã€åçŽ æ°ã®å€§ãããšåŒã³ãŸããäŸãã°ãæãå°ãã倧ããã®åã€åçŽ æ°ã¯ã(5, 7, 11, 13) ã®çµã§ããããã®å€§ãã㯠13 ã§ããæ¬¡ã«å€§ããåã€åçŽ æ°ã¯ã(11, 13, 17, 19) ã®çµã§ããã®å€§ãã㯠19 ã§ãã
</p>
<p>
æŽæ° <var>n</var> (13 ≤ <var>n</var> ≤ 10,000,000) ãå
¥åãšãã倧ããã <var>n</var> 以äžã«ãªããããªåã€åçŽ æ°ã®ãã¡ãæå€§ãšãªããã®ã®å€§ãããåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã
åããŒã¿ã»ãããšããŠïŒã€ã®æŽæ° <var>n</var> ãïŒè¡ã«äžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 2000 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
å
¥åããŒã¿ã»ããããšã«ãæå€§ãšãªãåã€åçŽ æ°ã®å€§ããã1è¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
13
14
15
16
17
18
19
20
10000
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
13
13
13
13
13
13
19
19
9439
</pre>
|
p01063 |
<h1>Rubik Dungeon</h1>
<h2>Problem</h2>
<p>
ããªãã¯<var>n</var> à <var>n</var> à <var>n</var>ã®ç«æ¹äœã®ã«ãŒããã¯ãã¥ãŒãåã®ãã³ãžã§ã³ã«ãã£ãŠããã<br>
ããªãã¯çŸåš(<var>x<sub>1</sub></var>,<var>y<sub>1</sub></var>,<var>z<sub>1</sub></var>)ã®éšå±ã«ããã<br>
ç®æšã®å®ã¯(<var>x<sub>2</sub></var>,<var>y<sub>2</sub></var>,<var>z<sub>2</sub></var>)ã®éšå±ã«ããã<br>
ããªãã¯é£æ¥ããŠããååŸå·Šå³äžäžã®éšå±ã«åäœæéã§ç§»åããããšãã§ããã
</p>
<left>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_UAPC2016Spring_E1" width="200"><br>
</left>
<p>
åéšå±ã«ã¯6ã€ã®ãã¿ã³ããããããããã®ãã¿ã³ãæŒãããšã«ãããåäœæéã§ãã«ãŒããã¯ãã¥ãŒãã®ããã«ä»¥äžã®æäœãè¡ãããšãã§ããïŒ<br>
</p>
<ul>
<li>çŸåšããéšå±ãš<var>x</var>座æšã®å€ãåãå
šãŠã®éšå±ãæèšãŸãã¯åæèšåšãã«90床å転ããããšãã§ãã</li>
</ul>
<left>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_UAPC2016Spring_E2" width="360"><br>
</left>
<ul>
<li>çŸåšããéšå±ãš<var>y</var>座æšã®å€ãåãå
šãŠã®éšå±ãæèšãŸãã¯åæèšåšãã«90床å転ããããšãã§ãã</li>
</ul>
<left>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_UAPC2016Spring_E3" width="360"><br>
</left>
<ul>
<li>çŸåšããéšå±ãš<var>z</var>座æšã®å€ãåãå
šãŠã®éšå±ãæèšãŸãã¯åæèšåšãã«90床å転ããããšãã§ãã</li>
</ul>
<left>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_UAPC2016Spring_E4" width="360" ><br>
</left>
<p>
å転ããŠããéäžã§ä»ã®éšå±ã«ç§»åããããšã¯ã§ããªãã<br>
å®ã®ããéšå±ãŸã§æçã§ç§»åããå Žåã®æéãæ±ããã<br>
</p>
<h2>Input</h2>
<pre>
<var>n</var>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>z<sub>1</sub></var>
<var>x<sub>2</sub></var> <var>y<sub>2</sub></var> <var>z<sub>2</sub></var>
</pre>
<p>
å
¥åã¯å
šãп޿°ã§äžããããã<br>
1è¡ç®ã«<var>n</var>ãäžããããã<br>
2è¡ç®ã«çŸåšå°ã®åº§æš(<var>x<sub>1</sub></var>,<var>y<sub>1</sub></var>,<var>z<sub>1</sub></var>)ã3è¡ç®ã«å®ã®ããéšå±ã®åº§æš(<var>x<sub>2</sub></var>,<var>y<sub>2</sub></var>,<var>z<sub>2</sub></var>)ã空çœåºåãã§äžããããã
</p>
<h2>Constraints</h2>
<ul>
<li>2 ≤ n ≤ 10<sup>5</sup></li>
<li>0 ≤ <var>x<sub>1</sub></var>,<var>y<sub>1</sub></var>,<var>z<sub>1</sub></var>,<var>x<sub>2</sub></var>,<var>y<sub>2</sub></var>,<var>z<sub>2</sub></var> ≤ <var>n</var>−1</li>
<li>(<var>x<sub>1</sub></var>,<var>y<sub>1</sub></var>,<var>z<sub>1</sub></var>) ≠ (<var>x<sub>2</sub></var>,<var>y<sub>2</sub></var>,<var>z<sub>2</sub></var>)</li>
</ul>
<h2>Output</h2>
<p>
æçã®æéãåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
3
0 0 0
1 2 2
</pre>
<h2>Sample Output 1</h2>
<pre>
3
</pre>
<h2>Sample Input 2</h2>
<pre>
3
0 0 0
0 0 2
</pre>
<h2>Sample Output 2</h2>
<pre>
2
</pre>
<p>
å転ããããšå®ãç§»åããŠããŸãã®ã§ãå転ãããã«ç§»åããã
</p> |
p01599 |
<h2>Problem I: Train King</h2>
<p>Roland has been given a mission of dangerous material transfer by Train
King. The material is stored in the station A and subject to being transferred
to the station B. He will bring it by direct trains between A and B, one (or
zero) unit per ride.</p>
<p>Your task is to write a program to find out the most optimal way of his
bringing. Your program will receive the timetable of trains on the mission day
and should report how many units of material can be transferred at the end. Be
aware that there can be trains which can go to the past time or the same time
which train leaved the station.</p>
<p>Each train consists of one or more cars. Roland is disallowed to ride the
same car of the same train multiple times. This restriction avoids time paradox.
He is still allowed to get on a different car, though. You can assume he can
change trains instantly.</p>
<h2>Input</h2>
<p>The first line contains two integers <var>N</var><sub>AB</sub> and <var>N</var><sub>BA</sub>
(0 <= <var>N</var><sub>AB</sub>, 0 <= <var>N</var><sub>BA</sub> and <var>N</var><sub>AB</sub>
+ <var>N</var><sub>BA</sub> <= 50). <var>N</var><sub>AB</sub> denotes the number
of trains from A to B; <var>N</var><sub>BA</sub> denotes the number from B to A.</p>
<p>The next <var>N</var><sub>AB</sub> lines describe the information about
trains from A to B. Each line gives the information of one train with three
integers <var>C<sub>i</sub></var>, <var>D<sub>i</sub></var> and <var>A<sub>i</sub></var>
(1 <= <var>C<sub>i</sub></var> <= 10, 0 <= <var>D<sub>i</sub></var>, <var>A<sub>i</sub></var>
< 86400) : the number of cars, the departure time, and the arrival time.</p>
<p>The next <var>N</var><sub>BA</sub> lines describe the information about
trains from B to A. The information is given in the same format.</p>
<h2>Output</h2>
<p>Print the maximum amount, in units, of dangerous material that can be
transferred.</p>
<h2>Sample Input 1</h2>
<pre>
1 1
10 100 0
10 100 0
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>10</pre>
<h2>Sample Input 2</h2>
<pre>
5 5
10 0 100
10 200 300
10 400 500
10 600 700
10 800 900
10 100 200
10 300 400
10 500 600
10 700 800
10 900 1000
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>5</pre> |
p01433 |
<script type="text/javascript" src="./varmath.js" charset="UTF-8"></script>
<h2>å顿</h2>
<p>
人éã®é女 KLARISSA ã¯ã³ã³ãµãŒãããŒã«ã®äžã§åšããæ¥ã®æåã倢èŠã€ã¥ããŠããïŒåœŒå¥³ã®éåœã®è»èŒªã¯å
·çŸåãïŒã³ã³ãµãŒãããŒã«ã®äžã§è»¢ããç¶ããŠããïŒ
</p>
<p>
<i>äœåæå</i>ã¯ãã®éåœã®è»èŒªãåã§ã¯ãªãã«ã©ãã«ãªæ£æ¹åœ¢ã§ããããšã«æ°ãã€ããïŒéåœã®è»èŒªã¯ã³ã³ãµãŒãããŒã«ã®è¥¿ããæ±ãžè»¢ããããšããŠããïŒ<i>äœåæå</i>ã¯éåœã®è»èŒªãããæãŸã§è»¢ãã£ããšãã«ãã®äžã«é£ã³ç§»ãããšã«ããïŒããã§é£ã³ç§»ãã¹ãé¢ã®è²ãç¥ãïŒé£ã³ç§»ãã¿ã€ãã³ã°ãèŠèšããããïŒ
<p>
ããã§ã¯è»èŒªã <var>2</var> 次å
å¹³é¢ã«ããã <var>1</var> 蟺ã®é·ãã <var>1</var> ã®æ£æ¹åœ¢ãšèŠãªãïŒè¥¿ããæ±ãžåããæ¹åã <var>x</var> è»žã®æ£åãïŒéçŽäžæ¹åã <var>y</var> è»žã®æ£åããšããïŒ
ä»ïŒéåœã®è»èŒªã®äžé¢ãåºã«å¯ŸããŠæ¥å°ããŠããïŒåºãšå察ã®é¢ãèµ€è²ïŒæ±åŽã®é¢ãç·è²ïŒåºãšæ¥å°ããŠããé¢ãéè²ïŒè¥¿åŽã®é¢ãçœè²ã«ãªã£ãŠããïŒçŸåšæ¥å°ããŠããé¢ã®ãã¡æã西ã®ç¹ã® <var>x</var> 座æšã <var>x=A</var> ã§ãããšããïŒéåœã®è»èŒªããã¹ãããšãªãåºã«å¯ŸããŠè»¢ããç¶ãïŒããäžé¢ãåºã«æ¥å°ããæã§ïŒèšçœ®ããŠããé¢ã®ãã¡æãæ±ã®ç¹ã® <var>x</var> 座æšã <var>x=B</var> ãåããŠè¶
ãããšãïŒåºã«å¯ŸããŠè¡šåãã«ãªã£ãŠããé¢ã¯äœè²ã«ãªãããæ±ããïŒ
<h2>å
¥å圢åŒ</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ
</p>
<pre><var>
N\ A\ B\\
x_1\ y_1\\
x_2\ y_2\\
...\\
x_N\ y_N\\
</var></pre>
<p>
ã³ã³ãµãŒãããŒã«ã®åºã¯äžã«åžãªæãç·ãšããŠäžããããïŒ<var>N</var> ã¯æãç·ã®ç«¯ç¹ãšããŠäžããããç¹ã®åæ°ã§ããïŒ<var>A</var> ã¯è»èŒªã®åæã®x座æšïŒ<var>B</var> ã¯è»èŒªã®ç®æšäœçœ®ã®x座æšã衚ãïŒ
</p>
<p>
<var>(x_i, y_i)</var> ã¯æãç·ã®æ
å ±ã§ããïŒ
ã³ã³ãµãŒãããŒã«ã®åºã¯ç¹ <var>(x_1, y_1)</var> ãšç¹ <var>(x_2, y_2)</var> ãçµã¶ç·åïŒç¹ <var>(x_2, y_2)</var> ãšç¹ <var>(x_3, y_3)</var> ãçµã¶ç·åïŒ...ïŒç¹ <var>(x_{N-1}, y_{N-1})</var> ãšç¹ <var>(x_N, y_N)</var> ãçµã¶ç·åã«ãã£ãŠã§ããŠãããã®ãšããïŒ
</p>
<h2>åºå圢åŒ</h2>
<p>
è²ã1è¡ã«åºåããïŒèµ€è²ãªã <code>Red</code>ïŒç·è²ãªã <code>Green</code>ïŒéè²ãªã <code>Blue</code>ïŒçœè²ãªã <code>White</code> ãšåºåããããšïŒ
</p>
<h2>å¶çŽ</h2>
<ul>
<li><var>2 ≤ N ≤ 30</var></li>
<li><var>0 ≤ A ≤ 200</var></li>
<li><var>0 ≤ B ≤ 200</var></li>
<li><var>A < B</var></li>
<li><var>0 ≤ x_i ≤ 200, 0 ≤ y_i ≤ 200 (1 ≤ i ≤ N)</var></li>
<li>å
¥åå€ã¯ãã¹ãп޿°ã§ããïŒ</li>
<li><var>x_i</var> ã¯ç矩å調å¢å ã§ããïŒããªãã¡ïŒ<var>x_i < x_{i+1}</var></li>
<li><var>x_1 < A < x_2 - 1</var></li>
<li><var>x_{N-1}+1 < B < x_N</var></li>
<li>åºã¯äžã«åžã§ããïŒããªãã¡ïŒ<var>(y_{i+1} - y_{i}) / (x_{i+1} - x_{i}) < (y_{i+2} - y_{i+1}) / (x_{i+2} - x_{i+1})</var> ãæºããããŠããïŒ</li>
<li>å転ãããããããã®æ®µéã«ãããŠïŒè»èŒªã®é ç¹ã® <var>x</var> 座æšã <var>B</var> ãã <var>10^{-5}</var> 以å
ã®å€ã«ãªãããšã¯ãªãïŒ</li>
<li>è»èŒªã® <var>1</var> 蟺ã®é·ãã <var>\pm 10^{-6}</var> ã ãå€åãããŠãç®æšäœçœ®ã«éãããŸã§ã«èŠããè»èŒªã®åè»¢åæ°ã¯å€åããïŒãŸãå€åãããªãã£ãç¶æ
ãã <var>x</var> 座æšã¯é«ã
<var>10^{-3}</var> ããå€åããªãïŒ</li>
</ul>
<h2>泚é</h2>
å¶çŽããïŒæ¬¡ã®ããšãä¿èšŒãããïŒ
<ul>
<li>åæç¶æ
ã«ãããŠïŒè»èŒªãåºã«ãã蟌ãã§ããããšã¯ãªãïŒ</li>
<li>è»èŒªãç®æšäœçœ®ãåããŠè¶ããŠå転ãçµãã£ããšãïŒå¿
ãè»èŒªã®ãã 1 é¢ãåºã«æ¥å°ããŠããïŒ</li>
</ul>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
4 5 25
0 10
10 0
20 0
30 10
</pre>
<h3>åºåäŸ1</h3>
<pre>Red</pre>
<h3>å
¥åäŸ 2</h3>
<pre>
6 2 18
0 30
6 6
9 2
12 1
15 5
20 18
</pre>
<h3>åºåäŸ 2</h3>
<pre>Green</pre>
<h3>å
¥åäŸ 3</h3>
<pre>3 2 9
0 23
7 6
10 25</pre>
<h3>åºåäŸ 3</h3>
<pre>White</pre>
<hr>
<address>Problem Setter: Flat35</address> |
p01126 |
<h1>Amida, the City of Miracle</h1>
<p>
å¥è·¡ã®éœåžã¢ããïŒAmida, the City of MiracleïŒã®åžé·ã¯ä»ã®åžã®ããã«éžæã§éžã¶ã®ã§ã¯ãªãïŒãã€ãŠé·ãæ¿æš©éäºãšå€©å€å°ç°ã«ããç²åŒãããã®éœåžã¯ïŒåè£è
å
šå¡ãå
¬å¹³ã«éžã³ïŒãã€å¹žéã®æã®äžã«çãŸããè
ãåžé·ã«ããããã«ïŒåè£è
å
šå¡ã®éåœãããã«ãã ããããšã«ããã®ã§ããïŒåŸã«ãã¿ã ãããšåŒã°ããããã§ããïŒ
</p>
<p>
éžæã¯ä»¥äžã®ããã«è¡ãããïŒåè£è
æ°ãšåæ°ã®é·ã瞊ç·ãåŒããïŒããã«ããã€ãã®æšªç·ãããã«åŒãããïŒæšªç·ã¯é£æ¥ãã瞊ç·ã®éäžå士ãçµã¶ããã«åŒãããïŒããããã®çžŠç·ã®äžã«ã¯ãåœéžããšæžãããŠããïŒã©ã®çžŠç·ãåœéžã§ãããã¯åè£è
ããããããªãããã«é ãããïŒããããã®åè£è
ã¯çžŠç·ã 1 ã€éžæããïŒå
šãŠã®åè£è
ã®éžæãçµãããšïŒååè£è
ã¯ç·ãäžããäžã«åãã£ãŠãã©ãïŒãã ãïŒç§»åéäžã«æšªç·ãèŠã€ãã£ããšãã¯ïŒæšªç·ã®æ¥ç¶ãããå察åŽã®çžŠç·ã«ç§»ãïŒãŸãäžã«åãã£ãŠãã©ãïŒçžŠç·ã®äžçªäžãŸã§ãã©ãçãããšãã«ïŒããã«ãåœéžããšæžãããŠããè
ãåœéžããŠïŒæ¬¡æåžé·ãšãªãïŒ
</p>
<p>
ãã®æ¹æ³ã¯ããŸããã£ãïŒå¹žéãªåžé·ã®äžã«ïŒäºããçœå®³ãå°ãªãå¹³åãªæä»£ãç¶ããïŒãããè¿å¹ŽïŒäººå£å¢å ã®ããã«ãã®ææ³ã«éçãèŠããŠããïŒåè£è
ãå¢ããããïŒãã¿ã ãããå€§èŠæš¡ã«ãªãïŒæäœæ¥ã«ããéèšã§ã¯éåžžã«æéããããããã«ãªã£ãã®ã§ããïŒããã§åžã§ã¯ïŒåžåœ¹æã®ããã°ã©ããŒã§ããããªãã«ãã¿ã ããã®é»ç®åãäŸé ŒããïŒ
</p>
<p>
ããªãã®ä»äºã¯ïŒãã¿ã ããã®æ§é ãšïŒéžæããã瞊ç·ã®äœçœ®ãäžãããããšãã«ïŒæçµçã«ã©ã®çžŠç·ã«ãã©ãçãããæ±ããããã°ã©ã ãæžãããšã§ããïŒ
</p>
<p>
以äžã®å³ã¯ïŒãµã³ãã«ãšããŠäžããå
¥åããã³åºåã®å
容ã瀺ãããã®ã§ããïŒ
</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida">
<h3>Input</h3>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒ1 ã€ã®ããŒã¿ã»ããã¯ä»¥äžã®ããã«äžããããïŒ
<blockquote>
<i>n</i> <i>m</i> <i>a</i><br>
暪ç·1<br>
暪ç·2<br>
暪ç·3<br>
...<br>
暪ç·<i>m</i><br>
</blockquote>
<i>n</i> ïŒ<i>m</i> ïŒ<i>a</i> ã¯ãããã 2 <= <i>n</i> <= 100, 0 <= <i>m</i> <= 1000, 1 <= <i>a</i> <= <i>n</i> ãã¿ããæŽæ°ã§ããïŒãããã瞊ç·ã®æ¬æ°ïŒæšªç·ã®æ¬æ°ïŒèª¿ã¹ã瞊ç·ã®çªå·ã衚ãïŒ
</p>
<p>
暪ç·ã®ããŒã¿ã¯ä»¥äžã®ããã«äžããããïŒ
<blockquote>
<i>h</i> <i>p</i> <i>q</i>
</blockquote>
<i>h</i> ïŒ<i>p</i> ïŒ<i>q</i> ã¯ãããã 1 <= <i>h</i> <= 1000, 1 <= <i>p</i> < <i>q</i> <= <i>n</i>, ãæºããæŽæ°ã§ããïŒ<i>h</i> ã¯ãã®æšªç·ã®é«ãïŒ<i>p</i> ïŒ<i>q</i> ã¯ãã®æšªç·ã«ã€ãªãã£ãŠãã 2 æ¬ã®çžŠç·ã®çªå·ã衚ãïŒ
</p>
<p>
1 ã€ã®çžŠç·ã®åãé«ãã«ïŒç°ãªã暪ç·ã 2 ã€ä»¥äžã€ãããšã¯ãªãïŒ
</p>
<p>
å
¥åã®çµããã«ã¯ïŒç©ºçœã§åºåããã 3 ã€ã®ãŒãã®ã¿ãããªãè¡ãããã
</p>
<h3>Output</h3>
<p>
ããããã®ããŒã¿ã»ããã«å¯Ÿã㊠1 è¡ãã€ïŒçžŠç· a ã®äžç«¯ãããã©ã£ããšãã®äžç«¯ã«ããã瞊ç·ã®çªå·ãåºåããªããïŒ
</p>
<h3>Sample Input</h3>
<pre>
4 4 1
3 1 2
2 2 3
3 3 4
1 3 4
0 0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
4
</pre>
|
p01576 |
<H1><font color="#000">Problem F:</font> Exciting Bicycle</H1>
<p>
You happened to get a special bicycle. You can run with it incredibly fast because it has a turbo engine. You can't wait to try it off road to enjoy the power.
</p>
<p>
You planned to go straight. The ground is very rough with ups and downs, and can be seen as a series of slopes (line segments) when seen from a lateral view. The bicycle runs on the ground at a constant speed of <i>V</i>. Since running very fast, the bicycle jumps off the ground every time it comes to the beginning point of a slope slanting more downward than the previous, as illustrated below. It then goes along a parabola until reaching the ground, affected by the gravity with the acceleration of 9.8m/s<sup>2</sup>.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_excitingBicycle">
</center>
<p>
It is somewhat scary to ride the bicycle without any preparations - you might crash into rocks or fall into pitfalls. So you decided to perform a computer simulation of the ride.
</p>
<p>
Given a description of the ground, calculate the trace you will run on the ground by the bicycle. For simplicity, it is sufficient to output its length.
</p>
<H2>Input</H2>
<p>
The first line of the input has two integers <i>N</i> (2 ≤ <i>N</i> ≤ 10000) and <i>V</i> (1 ≤ <i>V</i> ≤ 10000), separated by a space. It is followed by <i>N</i> lines. The <i>i</i>-th line has two integers <i>X<sub>i</sub></i> and <i>Y<sub>i</sub></i> (0 ≤ <i>X<sub>i</sub></i>, <i>Y<sub>i</sub></i> ≤ 10000). <i>V</i>[m/s] is the ground speed of the bicycle. The (<i>i</i> - 1) line segments (<i>X<sub>i</sub></i>, <i>Y<sub>i</sub></i>)-(<i>X</i><sub><i>i</i>+1</sub>, <i>Y</i><sub><i>i</i>+1</sub>) form the slopes on the ground, with the sky in the positive direction of the <i>Y</i> axis. Each coordinate value is measured in meters.
</p>
<p>
The start is at (<i>X</i><sub>1</sub>, <i>Y</i><sub>1</sub>), and the goal is at (<i>X<sub>N</sub></i>, <i>Y<sub>N</sub></i>). It is guaranteed that <i>X<sub>i</sub></i> < <i>X</i><sub><i>i</i>+1</sub> for 1 ≤ <i>i</i> ≤ <i>N</i> - 1.
</p>
<p>
You may assume that the distance of <i>x</i>-coordinate between the falling point and any endpoint (except for the jumping point) is not less than 10<sup>-5</sup>m.
</p>
<H2>Output</H2>
<p>
Output the length you will run on the ground with the bicycle, in meters. The value may be printed with any number of digits after the decimal point, should have the absolute or relative error not greater than 10<sup>-8</sup>.
</p>
<H2>Sample Input 1</H2>
<pre>
5 10
0 0
10 10
20 0
30 10
40 0
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
22.22335598
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
2 10
0 0
10000 0
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
10000.00000000
</pre>
<br/>
<H2>Sample Input 3</H2>
<pre>
4 10000
0 0
1 1
9999 0
10000 10000
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>
11.21323169
</pre>
<br/>
<H2>Sample Input 4</H2>
<pre>
4 50
0 10000
1 10000
2 0
10000 0
</pre>
<H2>Output for the Sample Input 4</H2>
<pre>
7741.23024274
</pre>
<br/>
|
p03818 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has decided to play a game using cards.
He has a deck consisting of <var>N</var> cards. On the <var>i</var>-th card from the top, an integer <var>A_i</var> is written.</p>
<p>He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, <var>N</var> is odd, which guarantees that at least one card can be kept.</p>
<p>Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 ⊠N ⊠10^{5}</var></li>
<li><var>N</var> is odd.</li>
<li><var>1 ⊠A_i ⊠10^{5}</var></li>
<li><var>A_i</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> <var>A_3</var> ... <var>A_{N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
1 2 1 3 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>One optimal solution is to perform the operation once, taking out two cards with <var>1</var> and one card with <var>2</var>. One card with <var>1</var> and another with <var>2</var> will be eaten, and the remaining card with <var>1</var> will be returned to deck. Then, the values written on the remaining cards in the deck will be pairwise distinct: <var>1</var>, <var>3</var> and <var>7</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>15
1 3 5 2 1 3 2 8 8 6 2 6 11 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>7
</pre></section>
</div>
</span> |
p01825 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
</script>
<h2>Problem H:
Laser Cutter
</h2>
<p>
Ciel is going to do woodworking. Ciel wants to make a cut in a wooden board using a laser
cutter.
</p>
<p>
To make it simple, we assume that the board is a two-dimensional plane. There are several
segments on the board along which Ciel wants to cut the board. Each segment has a direction
and Ciel must cut those segments along their directions. Those segments are connected when
you ignore the directions, that is, any two points on the segments are directly or indirectly
connected by the segments.
</p>
<p>
While the laser cutter is powered on, it emits a laser which hits the board at a point and cuts
the board along its trace. The laser initially points to $(x, y)$. Ciel can conduct the following two
operations:
</p>
<ul>
<li> Move the laser cutter with its power on and cut (a part of) a segment along its direction,
or</li>
<li> Move the laser cutter to any position with its power off. Ciel should not necessarily cut
the whole segment at a time; she can start or stop cutting a segment at any point on the
segments.</li>
</ul>
<p>
Ciel likes to be efficient, so she wants to know the shortest route such that the laser cutter cuts
the whole parts of all the segments and then move back to the initial point. Your task is to
write a program that calculates the minimum total moving distance of the laser cutter.
</p>
<h3>Input</h3>
<p>
The first line of the input contains an integer $n$ ($1 \leq n \leq 300$), the number of segments. The
next line contains two integers $x$ and $y$ ($-1,000 \leq x, y \leq 1,000$), which is the initial position
$(x, y)$ of the laser. The $i$-th of the following $n$ lines contains four integers $sx_i$, $sy_i$, $tx_i$ and $ty_i$ ($-1,000 \leq sx_i, sy_i, tx_i, ty_i \leq 1,000$), which indicate that they are the end points of the $i$-th
segment, and that the laser cutter can cut the board in the direction from $(sx_i, sy_i)$ to $(tx_i, ty_i)$.
The input satisfies the following conditions: For all $i$ ($1 \leq i \leq n$), $(sx_i, sy_i) \ne (tx_i, ty_i)$. The
initial point $(x, y)$ lies on at least one of the given segments. For all distinct $i, j$ ($1 \leq i, j \leq n$),
the $i$-th segment and the $j$-th segment share at most one point.
</p>
<h3>Output</h3>
<p>
Output a line containing the minimum total moving distance the laser cutter needs to travel to
cut all the segments and move back to the initial point. The absolute error or the relative error
should be less than $10^{-6}$.
</p>
<h3>Sample Input</h3>
<pre>
3
0 1
0 0 0 1
0 1 0 2
0 2 0 3
</pre>
<h3>Output for the Sample Input</h3>
<pre>
6.0000000000000000
</pre>
<h3>Sample Input</h3>
<pre>
2
0 1
0 0 0 2
-1 1 1 1
</pre>
<h3>Output for the Sample Input</h3>
<pre>
6.8284271247461900
</pre>
<h3>Sample Input</h3>
<pre>
5
0 0
0 0 1 0
1 1 -1 1
-1 1 -1 -1
-1 -1 1 -1
1 -1 1 1
</pre>
<h3>Output for the Sample Input</h3>
<pre>
10.0000000000000000
</pre> |
p00737 |
<h1><font color="#000000">Problem D:</font> Twirling Robot </h1>
<!-- end en only -->
<!-- begin en only -->
<p>
Let's play a game using a robot on a rectangular board
covered with a square mesh (Figure D-1).
The robot is initially set at the start square in the northwest corner
facing the east direction.
The goal of this game is to lead the robot
to the goal square in the southeast corner.
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2008D1"><br><br>
<!-- begin en only -->
Figure D-1: Example of a board
<!-- end en only -->
</center>
<!-- begin en only -->
<p>
The robot can execute the following five types of commands.
<dl>
<dt> "Straight":</dt>
<dd> Keep the current direction of the robot, and move forward to the next square.</dd>
<dt> "Right":</dt>
<dd> Turn right with 90 degrees from the current direction, and move forward to the next square.</dd>
<dt> "Back":</dt>
<dd> Turn to the reverse direction, and move forward to the next square.</dd>
<dt> "Left":</dt>
<dd> Turn left with 90 degrees from the current direction, and move forward to the next square.</dd>
<dt> "Halt":</dt>
<dd> Stop at the current square to finish the game.</dd>
</dl>
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Each square has one of these commands assigned as shown in Figure D-2.
The robot executes the command assigned to the square where it resides,
unless the player gives another command to be executed instead.
Each time the player gives an explicit command,
the player has to pay the cost that depends on the command type.
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2008D2"><br><br>
<!-- begin en only -->
Figure D-2: Example of commands assigned to squares
<!-- end en only -->
</center>
<!-- begin en only -->
<p>
The robot can visit the same square several times during a game.
The player loses the game when the robot goes out of the board
or it executes a "Halt" command before arriving at the goal square.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Your task is to write a program that calculates the minimum cost to lead the robot
from the start square to the goal one.
</p>
<!-- end en only -->
<h3>Input</h3>
<!-- begin en only -->
<p>
The input is a sequence of datasets.
The end of the input is indicated by a line containing two zeros separated by a space.
Each dataset is formatted as follows.
</p>
<!-- end en only -->
<p>
<blockquote>
<i>w h</i><br>
<i>s</i>(1,1) ... <i>s</i>(1,<i>w</i>)<br>
<i>s</i>(2,1) ... <i>s</i>(2,<i>w</i>)<br>
...<br>
<i>s</i>(<i>h</i>,1) ... <i>s</i>(<i><i>h</i></i>,<i>w</i>)<br>
<i>c</i><sub>0</sub> <i>c</i><sub>1</sub> <i>c</i><sub>2</sub> <i>c</i><sub>3</sub>
</blockquote>
</p>
<!-- begin en only -->
<p>
The integers <i>h</i> and <i>w</i> are the numbers of rows and columns of the board,
respectively.
You may assume 2 ≤ <i>h</i> ≤ 30 and 2 ≤ <i>w</i> ≤ 30.
Each of the following <i>h</i> lines consists of <i>w</i> numbers delimited by a space.
The number <i>s</i>(<i>i</i>, <i>j</i>) represents the command assigned to the square
in the <i>i</i>-th row and the <i>j</i>-th column as follows.
<ul>
<li> 0: "Straight"</li>
<li> 1: "Right"</li>
<li> 2: "Back"</li>
<li> 3: "Left"</li>
<li> 4: "Halt"</li>
</ul>
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
You can assume that a "Halt" command is assigned to the goal square.
Note that "Halt" commands may be assigned to other squares, too.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The last line of a dataset contains four integers
<i>c</i><sub>0</sub>, <i>c</i><sub>1</sub>, <i>c</i><sub>2</sub>, and <i>c</i><sub>3</sub>, delimited by a space,
indicating the costs that the player has to pay
when the player gives
"Straight", "Right", "Back", and "Left" commands
respectively.
The player cannot give "Halt" commands.
You can assume that all the values of
<i>c</i><sub>0</sub>, <i>c</i><sub>1</sub>, <i>c</i><sub>2</sub>, and <i>c</i><sub>3</sub>
are between 1 and 9, inclusive.
</p>
<!-- end en only -->
<h3>Output</h3>
<!-- begin en only -->
<p>
For each dataset, print a line only having a decimal integer indicating the minimum cost
required to lead the robot to the goal.
No other characters should be on the output line.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>
8 3
0 0 0 0 0 0 0 1
2 3 0 1 4 0 0 1
3 3 0 0 0 0 0 4
9 9 1 9
4 4
3 3 4 0
1 2 4 4
1 1 1 0
0 2 4 4
8 7 2 1
2 8
2 2
4 1
0 4
1 3
1 0
2 1
0 3
1 4
1 9 3 1
0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
1
11
6
</pre>
|
p00367 | <!--<H1>Breakfast, Lunch and Supper</H1>-->
<h1>Three Meals</h1>
<p>
You are running a restaurant that serves dishes only three times a day. Each of your customer has his/her own separate time zones for eating breakfast, lunch and supper. Thus, your customer enjoys your dish only when he/she visits your restaurant to meet your serving time settings. Your wish is to modify your serving time arrangement so that as many as possible of your customers can enjoy your meals three times a day.
</p>
<p>
Write a program to enable as many as possible of customers can enjoy your service three times a day, i.e. breakfast, lunch, and supper. A list of customers eating time zones is given, which you cannot change. Settings of your service time are your option. Coincidence between your service time and either edge of customerâs time zone (start or end time) does not hinder you to provide your service.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>N</var>
<var>ast_1</var> <var>aet_1</var> <var>hst_1</var> <var>het_1</var> <var>bst_1</var> <var>bet_1</var>
<var>ast_2</var> <var>aet_2</var> <var>hst_2</var> <var>het_2</var> <var>bst_2</var> <var>bet_2</var>
:
<var>ast_N</var> <var>aet_N</var> <var>hst_N</var> <var>het_N</var> <var>bst_N</var> <var>bet_N</var>
</pre>
<p>
The first line provides the number of customers <var>N</var>(1≤<var>N</var>≤50). Each of subsequent <var>N</var> lines provides time zone information of <var>i</var>-th customer: start and end time of breakfast zone (<var>ast_i</var>, <var>aet_i</var>), those of lunch zone (<var>hst_i</var>, <var>het_i</var>) and those of supper zone (<var>bst_i</var>, <var>bet_i</var>). The end time must be later in time as the start time. Time zones do not overlap, i.e. <var>hst_i</var> is later in time than <var>aet_i</var>, and so on. Each time settings must not cross 0:00 midnight.
</p>
<pre>
<var>h</var> <var>m</var>
</pre>
<p>
Each time information is given by hour <var>h</var> (0≤<var>h</var>≤23) and minute <var>m</var>(0≤<var>m</var>≤59).
</p>
<h2>Output</h2>
<p>
Output the maximum number of customers that can be served all three meals (breakfast, lunch, and supper).
</p>
<h2>Sample Input 1</h2>
<pre>
5
1 0 2 0 3 30 4 30 6 0 7 0
2 30 3 0 4 0 5 0 5 30 6 30
1 30 2 30 4 30 5 0 6 30 7 0
2 30 3 0 5 0 6 0 6 30 7 0
1 0 2 0 3 0 3 30 4 0 5 0
</pre>
<h2>Sample Output 1</h2>
<pre>
3
</pre>
|
p03398 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let <var>X = 10^{100}</var>. Inaba has <var>N</var> checker pieces on the number line, where the <var>i</var>-th checker piece is at coordinate <var>X^{i}</var> for all <var>1 \leq i \leq N</var>.</p>
<p>Every second, Inaba chooses two checker pieces, <var>A</var> and <var>B</var>, and move <var>A</var> to the symmetric point of its current position with respect to <var>B</var>. After that, <var>B</var> is removed. (It is possible that <var>A</var> and <var>B</var> occupy the same position, and it is also possible for <var>A</var> to occupy the same position as another checker piece after the move).</p>
<p>After <var>N - 1</var> seconds, only one checker piece will remain. Find the number of distinct possible positions of that checker piece, modulo <var>10^{9} + 7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 50</var></li>
<li><var>N</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of distinct possible positions of the final checker piece, modulo <var>10^{9} + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>There are <var>3</var> checker pieces, positioned at <var>10^{100}, 10^{200}, 10^{300}</var> respectively. Call them <var>A, B, C</var> respectively.</p>
<p>Here are two (of the <var>12</var>) possible sequence of moves :</p>
<ul>
<li>
<p>Let <var>A</var> jump over <var>B</var> in the first second, and let <var>A</var> jump over <var>C</var> in the second second. The final position of <var>A</var> is <var>2 \times 10^{300} - 2 \times 10^{200} + 10^{100}</var>.</p>
</li>
<li>
<p>Let <var>C</var> jump over <var>A</var> in the first second, and let <var>B</var> jump over <var>C</var> in the second second. The final position of <var>B</var> is <var>-2 \times 10^{300} - 10^{200} + 4 \times 10^{100}</var>.</p>
</li>
</ul>
<p>There are a total of <var>3 \times 2 \times 2 = 12</var> possible sequence of moves, and the final piece are in different positions in all of them.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>84
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>22
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>487772376
</pre>
<p>Remember to output your answer modulo <var>10^{9} + 7</var>.</p></section>
</div>
</span> |
p03662 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Fennec and Snuke are playing a board game.</p>
<p>On the board, there are <var>N</var> cells numbered <var>1</var> through <var>N</var>, and <var>N-1</var> roads, each connecting two cells. Cell <var>a_i</var> is adjacent to Cell <var>b_i</var> through the <var>i</var>-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree.</p>
<p>Initially, Cell <var>1</var> is painted black, and Cell <var>N</var> is painted white. The other cells are not yet colored.
Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell.
More specifically, each player performs the following action in her/his turn:</p>
<ul>
<li>Fennec: selects an uncolored cell that is adjacent to a <strong>black</strong> cell, and paints it <strong>black</strong>.</li>
<li>Snuke: selects an uncolored cell that is adjacent to a <strong>white</strong> cell, and paints it <strong>white</strong>.</li>
</ul>
<p>A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10^5</var></li>
<li><var>1 \leq a_i, b_i \leq N</var></li>
<li>The given graph is a tree.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>b_1</var>
<var>:</var>
<var>a_{N-1}</var> <var>b_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If Fennec wins, print <code>Fennec</code>; if Snuke wins, print <code>Snuke</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7
3 6
1 2
3 1
7 4
5 7
1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Fennec
</pre>
<p>For example, if Fennec first paints Cell <var>2</var> black, she will win regardless of Snuke's moves.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 4
4 2
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Snuke
</pre></section>
</div>
</span> |
p02970 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> apple trees in a row. People say that one of them will bear golden apples.</p>
<p>We want to deploy some number of inspectors so that each of these trees will be inspected.</p>
<p>Each inspector will be deployed under one of the trees. For convenience, we will assign numbers from <var>1</var> through <var>N</var> to the trees. An inspector deployed under the <var>i</var>-th tree <var>(1 \leq i \leq N)</var> will inspect the trees with numbers between <var>i-D</var> and <var>i+D</var> (inclusive).</p>
<p>Find the minimum number of inspectors that we need to deploy to achieve the objective.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 20</var></li>
<li><var>1 \leq D \leq 20</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>D</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of inspectors that we need to deploy to achieve the objective.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We can achieve the objective by, for example, placing an inspector under Tree <var>3</var> and Tree <var>4</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>14 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>20 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3
</pre></section>
</div>
</span> |
p03232 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> blocks arranged in a row, numbered <var>1</var> to <var>N</var> from left to right.
Each block has a weight, and the weight of Block <var>i</var> is <var>A_i</var>.
Snuke will perform the following operation on these blocks <var>N</var> times:</p>
<ul>
<li>Choose one block that is still not removed, and remove it.
The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself).
Here, two blocks <var>x</var> and <var>y</var> ( <var>x \leq y</var> ) are <em>connected</em> when, for all <var>z</var> ( <var>x \leq z \leq y</var> ), Block <var>z</var> is still not removed.</li>
</ul>
<p>There are <var>N!</var> possible orders in which Snuke removes the blocks.
For all of those <var>N!</var> orders, find the total cost of the <var>N</var> operations, and calculate the sum of those <var>N!</var> total costs.
As the answer can be extremely large, compute the sum modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>For all of the <var>N!</var> orders, find the total cost of the <var>N</var> operations, and print the sum of those <var>N!</var> total costs, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>9
</pre>
<p>First, we will consider the order "Block <var>1</var> -> Block <var>2</var>".
In the first operation, the cost of the operation is <var>1+2=3</var>, as Block <var>1</var> and <var>2</var> are connected.
In the second operation, the cost of the operation is <var>2</var>, as only Block <var>2</var> remains.
Thus, the total cost of the two operations for this order is <var>3+2=5</var>.</p>
<p>Then, we will consider the order "Block <var>2</var> -> Block <var>1</var>".
In the first operation, the cost of the operation is <var>1+2=3</var>, as Block <var>1</var> and <var>2</var> are connected.
In the second operation, the cost of the operation is <var>1</var>, as only Block <var>1</var> remains.
Thus, the total cost of the two operations for this order is <var>3+1=4</var>.</p>
<p>Therefore, the answer is <var>5+4=9</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>212
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
1 2 4 8 16 32 64 128 256 512
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>880971923
</pre></section>
</div>
</span> |
p02589 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Limak can repeatedly remove one of the first two characters of a string,
for example <var>abcxyx \rightarrow acxyx \rightarrow cxyx \rightarrow cyx</var>.</p>
<p>You are given <var>N</var> different strings <var>S_1, S_2, \ldots, S_N</var>.
Among <var>N \cdot (N-1) / 2</var> pairs <var>(S_i, S_j)</var>,
in how many pairs could Limak obtain one string from the other?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 200\,000</var></li>
<li><var>S_i</var> consists of lowercase English letters <code>a</code>-<code>z</code>.</li>
<li><var>S_i \neq S_j</var></li>
<li><var>1 \leq |S_i|</var></li>
<li><var>|S_1| + |S_2| + \ldots + |S_N| \leq 10^6</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format.</p>
<pre><var>N</var>
<var>S_1</var>
<var>S_2</var>
<var>\vdots</var>
<var>S_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of unordered pairs <var>(S_i, S_j)</var>
where <var>i \neq j</var> and Limak can obtain one string from the other.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
abcxyx
cyx
abc
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>The only good pair is <var>(abcxyx, cyx)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6
b
a
abc
c
d
ab
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
<p>There are five good pairs: <var>(b, abc)</var>, <var>(a, abc)</var>, <var>(abc, c)</var>, <var>(b, ab)</var>, <var>(a, ab)</var>.</p></section>
</div>
</span> |
p02073 | <style type="text/css">
blockquote {
font-family: Menlo, Monaco, "Courier New", monospace;
display: block;
margin: 10px 0 10px 30px;
font-size: 16px;
line-height: 18px;
white-space: pre;
white-space: pre-wrap;
word-break: break-all;
word-wrap: break-word;
}
table.ioexample {
width: 100%;
border-collapse: collapse;
}
table.ioexample td {
width: 50%;
border: 1px solid rgba(0, 0, 0, 0.15);
vertical-align: top;
padding: 5px;
}
.no-page-break {
page-break-inside: avoid;
}
.page-break {
page-break-before: always;
}
</style>
<h3>Problem Statement</h3>
<p>You have a grid with $H$ rows and $W$ columns. Each cell contains one of the following 11 characters: an addition operator <code>+</code>, a multiplication operator <code>*</code>, or a digit between $1$ and $9$. </p>
<p>There are paths from the top-left cell to the bottom-right cell by moving right or down $H+W-2$ times. Let us define the value of a path by the evaluation result of the mathematical expression you can obtain by concatenating all the characters contained in the cells on the path in order.
Your task is to compute the sum of values of any possible paths. Since the sum can be large, find it modulo $M$.</p>
<p>It is guaranteed the top-left cell and the bottom-right cell contain digits. Moreover, if two cells share an edge, at least one of them contains a digit. In other words, each expression you can obtain from a path is mathematically valid.</p>
<hr />
<h3>Input</h3>
<p>The input consists of a single test case in the format below.</p>
<blockquote>$H$ $W$ $M$
$a_{1,1}$ $\cdots$ $a_{1,W}$
$\ldots$
$a_{H,1}$ $\cdots$ $a_{H,W}$</blockquote>
<p>The first line consists of three integers $H$, $W$ and $M$ ($1 \le H,W \le 2 000$, $2 \le M \le 10^{9}$).The following $H$ lines represent the characters on the grid. $a_{i,j}$ represents the character contained in the cell at the $i$-th row and $j$-th column. Each $a_{i,j}$ is either <code>+</code>, <code>*</code>, or a digit between $1$ and $9$. $a_{1,1}$ and $a_{H,W}$ are both digits. If two cells share an edge, at least one of them contain a digit.</p>
<h3>Output</h3>
<p>Print the sum of values of all possible paths modulo $M$.</p>
<p><div class="no-page-break"><h3>Examples</h3><table class="ioexample"><tr><th>Input</th><th>Output</th></tr><tr><td><pre>2 3 1000
3*1
+27
</pre></td><td><pre>162
</pre></td></tr><tr><td><pre>4 4 3000000
24+7
*23*
9+48
*123
</pre></td><td><pre>2159570
</pre></td></tr></table></div></p>
|
p02423 | <h1>Bit Operation I</h1>
<p>
Given a non-negative decimal integer $x$, convert it to binary representation $b$ of 32 bits. Then, print the result of the following operations to $b$ respecitvely.
</p>
<ul>
<li>Inversion: change the state of each bit to the opposite state</li>
<li>Logical left shift: shift left by 1</li>
<li>Logical right shift: shift right by 1</li>
</ul>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$x$
</pre>
<h2>Output</h2>
<p>
Print the given bits, results of inversion, left shift and right shift in a line respectively.
</p>
<h2>Constraints</h2>
<ul>
<li>$0 \leq x \leq 2^{32} - 1$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
8
</pre>
<h2>Sample Output 1</h2>
<pre>
00000000000000000000000000001000
11111111111111111111111111110111
00000000000000000000000000010000
00000000000000000000000000000100
</pre>
<h2>Sample Input 2</h2>
<pre>
13
</pre>
<h2>Sample Output 2</h2>
<pre>
00000000000000000000000000001101
11111111111111111111111111110010
00000000000000000000000000011010
00000000000000000000000000000110
</pre>
|
p02136 | <h1>Problem M: Manhattan Bomb</h1>
<h2>Problem</h2>
<p>
2次å
å¹³é¢äžã«$n$åã®ç匟ããããç匟ã«ã¯ãããã1ãã$n$ãŸã§ã®çªå·ãå²ãæ¯ãããŠããã$i$çªç®ã®ç匟ã¯åº§æš$(x_i,y_i)$ã«ååšããŠããã<br>
ãªããã©ã®ç匟ãåç¹ããã®ãã³ããã¿ã³è·é¢ãçããããšãåãã£ãŠããã<br>
$i$çªç®ã®ç匟ãççºãããšãã座æš$(x_i,y_i)$ããã®ãã³ããã¿ã³è·é¢ã$r_i$以å
ã®åº§æšã«ååšããŠããç匟ãé£éçã«ççºããã<br>
$n$åã®ç匟ããããã«ã€ããŠããã®ç匟ã®ã¿ã«çç«ããå Žåã«ãççºããã«æ®ãç匟ã®åæ°ãæ±ããã
</p>
<h2>Input</h2>
<pre>
$n$
$x_1$ $y_1$ $r_1$
$x_2$ $y_2$ $r_2$
...
$x_n$ $y_n$ $r_n$
</pre>
<p>
å
¥åã¯ãã¹ãп޿°ã§äžããããã<br>
1è¡ç®ã«ç匟ã®åæ°$n$ãäžããããã
ç¶ã$n$è¡ã®ãã¡$i$è¡ç®ã«ã¯$i$çªç®ã®çåŒŸã®æ
å ±ã衚ã$x_i,y_i,r_i$ã空çœåºåãã§äžããããã
</p>
<h2>Constraints</h2>
<p>
å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã
</p>
<ul>
<li>$2$ ≤ $n$ ≤ $2 \times 10^5$</li>
<li>$-10^9$ ≤ $x_i,y_i$ ≤ $10^9$</li>
<li>$1$ ≤ $r_i$ ≤ $10^9$</li>
<li>$|x_i|+|y_i| = |x_j|+|y_j|$ $( 1 ≤ i , j ≤ n )$</li>
<li>åã座æšã«è€æ°ã®ç匟ãååšããããšã¯ãªã</li>
</ul>
<h2>Output</h2>
<p>
$i$è¡ç®ã«ã¯$i$çªç®ã®ç匟ã®ã¿ã«çç«ããå Žåã«ãççºããã«æ®ãç匟ã®åæ°ãåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
2
-1 -1 10
1 1 1
</pre>
<h2>Sample Output 1</h2>
<pre>
0
1
</pre>
<h2>Sample Input 2</h2>
<pre>
3
3 2 2
4 -1 4
1 -4 7
</pre>
<h2>Sample Output 2</h2>
<pre>
2
1
0
</pre>
|
p02566 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string of length <var>N</var>. Calculate the number of distinct substrings of <var>S</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 500,000</var></li>
<li><var>S</var> consists of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>abcbcba
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>21
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>mississippi
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>53
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>ababacaca
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>33
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>aaaaa
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>5
</pre></section>
</div>
</span> |
p03727 | <span class="lang-en">
<p>Score : <var>1400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a tree with <var>N</var> vertices numbered <var>1</var> through <var>N</var>.
The <var>i</var>-th of the <var>N-1</var> edges connects vertices <var>a_i</var> and <var>b_i</var>.</p>
<p>Initially, each edge is painted blue.
Takahashi will convert this blue tree into a red tree, by performing the following operation <var>N-1</var> times:</p>
<ul>
<li>Select a simple path that consists of only blue edges, and remove one of those edges.</li>
<li>Then, span a new red edge between the two endpoints of the selected path.</li>
</ul>
<p>His objective is to obtain a tree that has a red edge connecting vertices <var>c_i</var> and <var>d_i</var>, for each <var>i</var>.</p>
<p>Determine whether this is achievable.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 †N †10^5</var></li>
<li><var>1 †a_i,b_i,c_i,d_i †N</var></li>
<li><var>a_i â b_i</var></li>
<li><var>c_i â d_i</var></li>
<li>Both input graphs are trees.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>b_1</var>
:
<var>a_{N-1}</var> <var>b_{N-1}</var>
<var>c_1</var> <var>d_1</var>
:
<var>c_{N-1}</var> <var>d_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <code>YES</code> if the objective is achievable; print <code>NO</code> otherwise.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 2
2 3
1 3
3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p>The objective is achievable, as below:</p>
<ul>
<li>First, select the path connecting vertices <var>1</var> and <var>3</var>, and remove a blue edge <var>1-2</var>. Then, span a new red edge <var>1-3</var>.</li>
<li>Next, select the path connecting vertices <var>2</var> and <var>3</var>, and remove a blue edge <var>2-3</var>. Then, span a new red edge <var>2-3</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
1 2
2 3
3 4
4 5
3 4
2 4
1 4
1 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>YES
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
1 2
3 5
4 6
1 6
5 1
5 3
1 4
2 6
4 3
5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>NO
</pre></section>
</div>
</span> |
p02835 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are three integers <var>A_1</var>, <var>A_2</var>, and <var>A_3</var>.</p>
<p>If <var>A_1+A_2+A_3</var> is greater than or equal to <var>22</var>, print <code>bust</code>; otherwise, print <code>win</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq A_i \leq 13 \ \ (i=1,2,3)</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A_1</var> <var>A_2</var> <var>A_3</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If <var>A_1+A_2+A_3</var> is greater than or equal to <var>22</var>, print <code>bust</code>; otherwise, print <code>win</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 7 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>win
</pre>
<p><var>5+7+9=21</var>, so print <code>win</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>13 7 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>bust
</pre>
<p><var>13+7+2=22</var>, so print <code>bust</code>.</p></section>
</div>
</span> |
p00808 |
<H1><font color="#000">Problem F:</font> Young, Poor and Busy</H1>
<p>
Ken and Keiko are young, poor and busy. Short explanation: they are students, and ridden with part-time jobs. To make things worse, Ken lives in Hakodate and Keiko in Tokyo. They want to meet, but since they have neither time nor money, they have to go back to their respective jobs immediately after, and must be careful about transportation costs. Help them find the most economical meeting point.
</p>
<p>
Ken starts from Hakodate, Keiko from Tokyo. They know schedules and fares for all trains, and can choose to meet anywhere including their hometowns, but they cannot leave before 8am and must be back by 6pm in their respective towns. Train changes take no time (one can leave the same minute he/she arrives), but they want to meet for at least 30 minutes in the same city.
</p>
<p>
There can be up to 100 cities and 2000 direct connections, so you should devise an algorithm clever enough for the task.
</p>
<H2>Input</H2>
<p>
The input is a sequence of data sets.
</p>
<p>
The first line of a data set contains a single integer, the number of connections in the timetable. It is not greater than 2000.
</p>
<p>
Connections are given one on a line, in the following format.
</p>
<pre>
<i>Start_city HH</i>:<i>MM Arrival_city HH</i>:<i>MM price</i>
</pre>
<p>
<i>Start_city</i> and <i>Arrival_city</i> are composed of up to 16 alphabetical characters, with only the first one in upper case. Departure and arrival times are given in hours and minutes (two digits each, separated by ":") from 00:00 to 23:59. Arrival time is strictly after departure time. The <i>price</i> for one connection is an integer between 1 and 10000, inclusive. Fields are separated by spaces.
</p>
<p>
The end of the input is marked by a line containing a zero.
</p>
<H2>Output</H2>
<p>
The output should contain one integer for each data set, the lowest cost possible. This is the total fare of all connections they use.
</p>
<p>
If there is no solution to a data set, you should output a zero.
</p>
<p>
The solution to each data set should be given in a separate line.
</p>
<H2>Sample Input</H2>
<pre>
5
Hakodate 08:15 Morioka 12:30 2500
Morioka 14:05 Hakodate 17:30 2500
Morioka 15:30 Hakodate 18:00 3000
Morioka 14:30 Tokyo 17:50 3000
Tokyo 08:30 Morioka 13:35 3000
4
Hakodate 08:15 Morioka 12:30 2500
Morioka 14:04 Hakodate 17:30 2500
Morioka 14:30 Tokyo 17:50 3000
Tokyo 08:30 Morioka 13:35 3000
18
Hakodate 09:55 Akita 10:53 3840
Hakodate 14:14 Akita 16:09 1920
Hakodate 18:36 Akita 19:33 3840
Hakodate 08:00 Morioka 08:53 3550
Hakodate 22:40 Morioka 23:34 3550
Akita 14:23 Tokyo 14:53 2010
Akita 20:36 Tokyo 21:06 2010
Akita 08:20 Hakodate 09:18 3840
Akita 13:56 Hakodate 14:54 3840
Akita 21:37 Hakodate 22:35 3840
Morioka 09:51 Tokyo 10:31 2660
Morioka 14:49 Tokyo 15:29 2660
Morioka 19:42 Tokyo 20:22 2660
Morioka 15:11 Hakodate 16:04 3550
Morioka 23:03 Hakodate 23:56 3550
Tokyo 09:44 Morioka 11:04 1330
Tokyo 21:54 Morioka 22:34 2660
Tokyo 11:34 Akita 12:04 2010
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
11000
0
11090
</pre>
|
p03377 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are a total of <var>A + B</var> cats and dogs.
Among them, <var>A</var> are known to be cats, but the remaining <var>B</var> are not known to be either cats or dogs.</p>
<p>Determine if it is possible that there are exactly <var>X</var> cats among these <var>A + B</var> animals.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq A \leq 100</var></li>
<li><var>1 \leq B \leq 100</var></li>
<li><var>1 \leq X \leq 200</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is possible that there are exactly <var>X</var> cats, print <code>YES</code>; if it is impossible, print <code>NO</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 5 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p>If there are one cat and four dogs among the <var>B = 5</var> animals, there are <var>X = 4</var> cats in total.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 2 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre>
<p>Even if all of the <var>B = 2</var> animals are cats, there are less than <var>X = 6</var> cats in total.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>NO
</pre>
<p>Even if all of the <var>B = 3</var> animals are dogs, there are more than <var>X = 2</var> cats in total.</p></section>
</div>
</span> |
p03459 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>AtCoDeer the deer is going on a trip in a two-dimensional plane.
In his plan, he will depart from point <var>(0, 0)</var> at time <var>0</var>, then for each <var>i</var> between <var>1</var> and <var>N</var> (inclusive), he will visit point <var>(x_i,y_i)</var> at time <var>t_i</var>.</p>
<p>If AtCoDeer is at point <var>(x, y)</var> at time <var>t</var>, he can be at one of the following points at time <var>t+1</var>: <var>(x+1,y)</var>, <var>(x-1,y)</var>, <var>(x,y+1)</var> and <var>(x,y-1)</var>.
Note that <strong>he cannot stay at his place</strong>.
Determine whether he can carry out his plan.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1</var> <var>â€</var> <var>N</var> <var>â€</var> <var>10^5</var></li>
<li><var>0</var> <var>â€</var> <var>x_i</var> <var>â€</var> <var>10^5</var></li>
<li><var>0</var> <var>â€</var> <var>y_i</var> <var>â€</var> <var>10^5</var></li>
<li><var>1</var> <var>â€</var> <var>t_i</var> <var>â€</var> <var>10^5</var></li>
<li><var>t_i</var> <var><</var> <var>t_{i+1}</var> (<var>1</var> <var>â€</var> <var>i</var> <var>â€</var> <var>N-1</var>)</li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>t_1</var> <var>x_1</var> <var>y_1</var>
<var>t_2</var> <var>x_2</var> <var>y_2</var>
<var>:</var>
<var>t_N</var> <var>x_N</var> <var>y_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If AtCoDeer can carry out his plan, print <code>Yes</code>; if he cannot, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
3 1 2
6 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>For example, he can travel as follows: <var>(0,0)</var>, <var>(0,1)</var>, <var>(1,1)</var>, <var>(1,2)</var>, <var>(1,1)</var>, <var>(1,0)</var>, then <var>(1,1)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
2 100 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>It is impossible to be at <var>(100,100)</var> two seconds after being at <var>(0,0)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
5 1 1
100 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre></section>
</div>
</span> |
p01464 |
<H1>Sunny Graph</H1>
<p>
The Sun is a great heavenly body.
The Sun is worshiped by various religions.
Bob loves the Sun and loves any object that is similar to the Sun.
He noticed that he can find the shape of the Sun in certain graphs.
He calls such graphs "Sunny".
</p>
<p>
We define the property "Sunny" mathematically.
A graph <var>G=(V,E)</var> with a vertex <var>v \in V</var> is called "Sunny" when there exists a subgraph <var>G'=(V,E'), E' \subseteq E</var> that has the following two properties.
(Be careful, the set of vertices must be the same.)
</p>
<p>
1. The connected component containing <var>v</var> is a cycle that consists of three or more vertices.
</p>
<p>
2. Every other component has exactly two vertices.
</p>
<p>
The following picture is an example of a subgraph <var>G'=(V,E')</var> that has the above property.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_sunny">
</center>
<p>
Given a simple graph (In each edge, two end points are different. Every pair of vertices has one or no edge.) <var>G=(V,E)</var>,
write a program that decides whether the given graph with the vertex <var>1</var> is "Sunny" or not.
</p>
<H2>Input</H2>
<p>
The first line contains two integers <var>N</var> (odd, <var>1 \leq N \leq 200</var>) and <var>M</var> (<var>0 \leq M \leq 20,000</var>), separated by a single space.
<var>N</var> is the number of the vertices and <var>M</var> is the number of the edges.
</p>
<p>
The following <var>M</var> lines describe the edges. Each line contains two integers <var>v_i</var> and <var>u_i</var> (<var>1 \leq u_i, v_i \leq N</var>).
(<var>u_i, v_i</var>) indicates the edge that connects the two vertices <var>u_i</var> and <var>v_i</var>.
<var>u_i</var> and <var>v_i</var> are different, and every pair <var>(u_i,v_i)</var> are different.
</p>
<H2>Output</H2>
<p>
Print a line containing "Yes" when the graph is "Sunny". Otherwise, print "No".
</p>
<H2>Sample Input 1</H2>
<pre>
5 5
1 2
2 3
3 4
4 5
1 3
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
Yes
</pre>
<H2>Sample Input 2</H2>
<pre>
5 5
1 2
2 3
3 4
4 5
1 4
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
No
</pre>
|
p03009 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> squares arranged in a row, numbered <var>1</var> to <var>N</var> from left to right. Takahashi will stack building blocks on these squares, on which there are no blocks yet.</p>
<p>He wants to stack blocks on the squares evenly, so he will repeat the following operation until there are <var>H</var> blocks on every square:</p>
<ul>
<li>Let <var>M</var> and <var>m</var> be the maximum and minimum numbers of blocks currently stacked on a square, respectively. Choose a square on which <var>m</var> blocks are stacked (if there are multiple such squares, choose any one of them), and add a positive number of blocks on that square so that there will be at least <var>M</var> and at most <var>M + D</var> blocks on that square.</li>
</ul>
<p>Tell him how many ways there are to have <var>H</var> blocks on every square by repeating this operation. Since there can be extremely many ways, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10^6</var></li>
<li><var>1 \leq D \leq H \leq 10^6</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>H</var> <var>D</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways to have <var>H</var> blocks on every square, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>The possible transitions of (the number of blocks on Square <var>1</var>, the number of blocks on Square <var>2</var>) are as follows:</p>
<ul>
<li>
<p><var>(0, 0)</var> -> <var>(0, 1)</var> -> <var>(1, 1)</var> -> <var>(1, 2)</var> -> <var>(2, 2)</var></p>
</li>
<li>
<p><var>(0, 0)</var> -> <var>(0, 1)</var> -> <var>(1, 1)</var> -> <var>(2, 1)</var> -> <var>(2, 2)</var></p>
</li>
<li>
<p><var>(0, 0)</var> -> <var>(0, 1)</var> -> <var>(2, 1)</var> -> <var>(2, 2)</var></p>
</li>
<li>
<p><var>(0, 0)</var> -> <var>(1, 0)</var> -> <var>(1, 1)</var> -> <var>(1, 2)</var> -> <var>(2, 2)</var></p>
</li>
<li>
<p><var>(0, 0)</var> -> <var>(1, 0)</var> -> <var>(1, 1)</var> -> <var>(2, 1)</var> -> <var>(2, 2)</var></p>
</li>
<li>
<p><var>(0, 0)</var> -> <var>(1, 0)</var> -> <var>(1, 2)</var> -> <var>(2, 2)</var></p>
</li>
</ul>
<p>Thus, there are six ways to have two blocks on every square.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 30 15
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>94182806
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>31415 9265 3589
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>312069529
</pre>
<p>Be sure to print the number modulo <var>10^9+7</var>.</p></section>
</div>
</span> |
p01034 | <h1>Problem H: Yu-kun Likes a Directed Graph</h1>
<h2>Background</h2>
<p>
äŒæŽ¥å€§åŠä»å±å¹Œçšåã¯ããã°ã©ãã³ã°ã倧奜ããªåäŸãéãŸã幌çšåã§ãããåå
ã®äžäººã§ããããåã¯ãããã°ã©ãã³ã°ãšåãããããçµµæãã倧奜ãã ã
ãããŸã§ããåã¯ãäžžãšç¢å°ã§æ²¢å±±çµµãæžããŠãããç¢å°ã¯å¿
ãäžžãšäžžãçµã¶ããã«ããŠæããŠãããããæ¥ããåã¯ãããã®çµµãã°ã©ãã§ããããšãç¥ãã
</p>
<p>
äžžã¯é ç¹ãšåŒã°ããç¢å°ã¯èŸºãšåŒã°ããŠããããããæŽã«ããåã¯ãç¢å°ãæãéã«ãå¿
ããã®äžã«ïŒã€æ£ã®æŽæ°ãæžããŠããããã®ããã«ã蟺ã«éã¿ãããæåãªèŸºãããªãã°ã©ãã¯éã¿ä»ãæåã°ã©ããšåŒã°ããã
</p>
<p>
仿¥ããåã¯ãæ°ãã«éè·¯ãšããèšèãç¥ã£ããéè·¯ãšã¯ãé£çµãã蟺ã®åã§ãããããã«å«ãŸããã©ã®é ç¹ãé«ã
1床ããçŸããªããã®ã§ãæåã®é ç¹ãšæåŸã®é ç¹ãåãã§ãããããªãã®ããããéè·¯ã®èŸºã®éã¿ã®ç·åãè² ã«ãªãå Žåããã®ãããªéè·¯ã¯è² ã®éè·¯ãšåŒã°ããã
</p>
<p>
æ°ããªèšèãæ²¢å±±ç¥ã£ãããåã¯äžã€ã®åé¡ãæãã€ããã
</p>
<h2>Problem</h2>
<p>
éè·¯ãæããªãéã¿ä»ãæåã°ã©ããäžããããã
ç°ãªãïŒã€ã®é ç¹ <var>i</var>, <var>j</var> ãéžã³ã<var>i</var> ãã <var>j</var> ã«éã¿ <var>w</var> ( <var>w</var> < 0 ) ã®æåãªèŸºã1æ¬è¿œå ããã
ããã«ãã£ãŠã°ã©ãå
ã«è² ã®éè·¯ãã§ãããã㪠<var>i</var>ã <var>j</var> ãã¿ã€ãããã®è² ã®éè·¯ã«å±ãã蟺ã®éã¿ã®ç·åã®æå€§å€ãæ±ããã
ãã®ãã㪠<var>i</var>, <var>j</var> ãååšããªãå Žåã¯"NA"ãšåºåããããšã
</p>
<h2>Input</h2>
<pre>
<var>V</var> <var>E</var> <var>w</var>
<var>s<sub>0</sub></var> <var>t<sub>0</sub></var> <var>c<sub>0</sub></var>
<var>s<sub>1</sub></var> <var>t<sub>1</sub></var> <var>c<sub>1</sub></var>
...
<var>s<sub>(E-1)</sub></var> <var>t<sub>(E-1)</sub></var> <var>c<sub>(E-1)</sub></var>
</pre>
<p>ïŒè¡ç®ã«é ç¹ã®æ° <var>V</var>, èŸºã®æ° <var>E</var>, 远å ãã蟺ã®éã¿ <var>w</var> ã空çœåºåãã§äžããããã</p>
<p>ç¶ã <var>E</var> è¡ã«æåãªèŸºã®æ
å ±ã <var>s<sub>i</sub></var> <var>t<sub>i</sub></var> <var>c<sub>i</sub></var> ãšããŠäžããããã ( 0 ≤ <var>i</var> ≤ <var>E-1</var> )</p>
<p>ããã¯ã <var>s<sub>i</sub></var> ãã <var>t<sub>i</sub></var> ã«åããŠéã¿ <var>c<sub>i</sub></var> ã®æåãªèŸºãååšããããšã衚ãã</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>2 ≤ <var>V</var> ≤ 100000</li>
<li>1 ≤ <var>E</var> ≤ 500000</li>
<li>-100 ≤ <var>w</var> < 0</li>
<li>0 ≤ <var>c<sub>i</sub></var> ≤ 100 ( 0 ≤ <var>i</var> ≤ <var>E-1</var> )</li>
<li>0 ≤ <var>s<sub>i</sub></var>, <var>t<sub>i</sub></var> ≤ <var>V-1</var> ( 0 ≤ <var>i</var> ≤ <var>E-1</var> )</li>
<li>å
¥åäžã«åã <var>s<sub>i</sub></var> ãš <var>t<sub>i</sub></var> ã®ãã¢ãçŸããããšã¯ãªã</li>
<li><var>s<sub>i</sub></var> ãš <var>t<sub>i</sub></var> ã¯ç°ãªã</li>
</ul>
<h2>Output</h2>
<p>
éã¿ <var>w</var> ã®æåãªèŸºã远å ããããšã§åºæ¥ãè² ã®éè·¯ã«å±ãã蟺ã®éã¿ã®ç·åã®æå€§å€ãïŒè¡ã«åºåããã
ã©ãã«èŸºã远å ããŠãè² ã®éè·¯ãäœããªãå Žåã¯"NA"ãšåºåããããšã
</p>
<h2>Sample Input 1</h2>
<pre>
3 2 -3
0 1 1
0 2 5
</pre>
<h2>Sample Output 1</h2>
<pre>
-2
</pre>
<h2>Sample Input 2</h2>
<pre>
3 2 -1
0 1 1
0 2 5
</pre>
<h2>Sample Output 2</h2>
<pre>
NA
</pre>
<h2>Sample Input 3</h2>
<pre>
7 8 -8
0 1 5
0 4 3
1 2 10
1 3 1
3 6 6
4 3 1
4 5 2
4 6 2
</pre>
<h2>Sample Output 3</h2>
<pre>
-1
</pre>
<h2>Sample Input 4</h2>
<pre>
5 4 -30
0 1 1
1 3 15
1 4 4
2 1 3
</pre>
<h2>Sample Output 4</h2>
<pre>
-12
</pre>
|
p00275 |
<H1>åäž»ãããã®çµæ«</H1>
<p>
çŸäººäžéŠã®æã䜿ã£ã鿝ã®ïŒã€ã«ããåäž»ãããããšãããã®ããããŸããçµµæã ãã䜿ãç°¡åãªéæ¯ãªã®ã§åºã楜ããŸããŠããŸããããŸãã«ã¯æ§ã
ãªæŽŸçåããããŸãããããã§èããåäž»ãããã¯N人ã®åå è
ã§ã以äžã®ãããªã«ãŒã«ã§è¡ããŸãã
</p>
<ul>
<li> ïŒïŒæã®ãç·ããïŒïŒæã®ãåäž»ããïŒïŒæã®ãå§«ããèšïŒïŒïŒæã®æã䜿ãã</li>
<li> çµµãèŠããªãããã«æãè£ãããã«ããŠããæ··ãããæå±±ããã€ããã</li>
<li> åå è
ã®äžäººç®ããé çªã«ïŒæãã€æå±±ã®æãåŒããN人ç®ã®æ¬¡ã¯ããŸãäžäººç®ããç¹°ãè¿ãã
<ul>
<li> åŒããæãç·ãªããåŒãã人ã¯ãã®æãæã«å
¥ããã</li>
<li> åŒããæãåäž»ãªããåŒãã人ã¯ãã®æãå«ããæã£ãŠããæããã¹ãŠãå Žãã«åºãã</li>
<li> åŒããæãå§«ãªããåŒãã人ã¯ãã®æãå«ããå Žã«ããæããã¹ãŠæã«å
¥ããã</li>
</ul>
</li>
<li> æå±±ã®æããªããªã£ããçµäºã§ãäžçªå€ãã®æãæã£ãŠãã人ã®åã¡ã</li>
</ul>
<p>
åå è
æ°ãšæå±±ã«ç©ãŸããæã®é çªãäžãããããšãã鿝ãçµäºããæç¹ã§ååå è
ãæã£ãŠããææ°ãæé ã§äžŠã¹ããã®ãšãå Žã«æ®ã£ãŠããææ°ãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããå
¥åã®çµããã¯ãŒãäžã€ã®è¡ã§ç€ºããããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>c<sub>1</sub>c<sub>2</sub> ... c<sub>100</sub>
</pre>
<p>
åããŒã¿ã»ããã¯2è¡ã§ããã1è¡ç®ã«åå è
æ°ãè¡šãæŽæ°<var>N</var>(2 ≤ <var>N</var> ≤ 10)ãäžãããããç¶ã1è¡ã«æå±±ã«ç©ãŸããæã®äžŠã³ã衚ãæååãäžãããããæå<var>c<sub>i</sub></var>ã¯<var>i</var>çªç®ã«åŒãããæã衚ããŠãããMãç·ãSãåäž»ãLãå§«ã®æã衚ããåæåã®éã«ç©ºçœã¯ç¡ãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯100ãè¶
ããªãã
</p>
<h2>åºå</h2>
<p>
ããŒã¿ã»ããããšã«ã鿝ãçµäºããæç¹ã§ã®ææ°ã®äžŠã³ãïŒè¡ã«åºåãããææ°ã®äžŠã³ãšããŠãååå è
ãæã£ãŠããæã®ææ°ãæé ã«äžŠã¹ã ãã®ã®åŸã«ãå Žã«æ®ã£ãŠããæã®ææ°ãåºåãããåææ°ã®éã¯ç©ºçœïŒã€ã§åºåããè¡ã®çµããã«ã¯ç©ºçœãåºåããªãã
</p>
<h2>å
¥åäŸ</h2>
<pre>
2
SSSSSSSSSSSSSSSLLLLLLLLLLLLLLLLLLLLLMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
2
SSSSSSSSSSSSSSLLLLLLLLLLLLLLLLLLLLMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMSL
5
MMMMMMSLSLLMMMSMMSLMMMLMMMMLSLLLLMLSMMLMMLLMSSSLMMMMLMLSMLMSMMMMMMMSMMMMMMLMMMMMSMMMLMMLMMMMMMMMMSSM
0
</pre>
<h2>åºåäŸ</h2>
<pre>
42 58 0
0 100 0
0 0 3 10 59 28
</pre> |
p02248 |
<H1>String Search</H1>
<p>
Find places where a string <var>P</var> is found within a text <var>T</var>.
Print all indices of <var>T</var> where <var>P</var> found. The indices of <var>T</var> start with 0.
</p>
<H2>Input</H2>
<p>
In the first line, a text <var>T</var> is given. In the second line, a string <var>P</var> is given.
</p>
<H2>Output</H2>
<p>
Print an index of <var>T</var> where <var>P</var> found in a line. Print the indices in ascending order.
</p>
<H2>Constraints</H2>
<ul>
<li> 1 ≤ length of <var>T</var> ≤ 1000000 </li>
<li> 1 ≤ length of <var>P</var> ≤ 10000 </li>
<li>The input consists of alphabetical characters and digits</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
aabaaa
aa
</pre>
<H2>Sample Output 1</H2>
<pre>
0
3
4
</pre>
<H2>Sample Input 2</H2>
<pre>
xyzz
yz
</pre>
<H2>Sample Output 2</H2>
<pre>
1
</pre>
<H2>Sample Input 3</H2>
<pre>
abc
xyz
</pre>
<H2>Sample Output 3</H2>
<pre>
</pre>
<p>
The output should be empty.
</p>
|
p01937 |
<!-- - - - - - begin nicebody - - - - - -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]} });
</script>
<script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<h1>G: Cryptex</h1>
<h2>åé¡</h2>
<p>AORã€ã«ã¡ããã¯èªåã®å®ç®±ã«ãã€ã€ã«åŒã®éµããããŠããã</p>
<p>éµã«ã¯ $N$ åã®ã·ãªã³ããŒãã€ããŠããã ãããããèšå®ããŠããã $N$ åã®æ°ã®äžŠã³ãããªãæèšŒçªå· $T$ ãšãã·ãªã³ããŒãç€ºãæ°åãåãã§ããã°éé ããããšãã§ããã</p>
<p>ã·ãªã³ããŒã«ã¯ã $0$ ãã $M-1$ ãŸã§ã® $M$ çš®é¡ã®æ°ãåãåãã«é ã«å»ãŸããŠãããæåã¯ãã¹ãŠã®ã·ãªã³ããŒã $0$ ã瀺ããŠããã</p>
<p>éµã¯ç¹å¥è£œã§ãããã·ãªã³ããŒãäžã€ãã€åãããšãã§ããªããä»»æã®ã·ãªã³ããŒãäºã€éžã³ãããããåæã«åãããªããã°ãªããªãã</p>
<p>äžåã·ãªã³ããŒãåããšã¯ã以äžã®ããã«å®çŸ©ãããã</p>
<ol>
<li>ã·ãªã³ããŒãäºã€éžã¶ããã ããåãã·ãªã³ããŒã¯éžã¹ãªãã</li>
<li>éžãã ã·ãªã³ããŒãäºã€ãšãé æ¹åããããã¯äºã€ãšãéæ¹åã«åããé æ¹åã«åããšã¯æ°ã $1$ å¢ããããšã§ãããéæ¹åã«åããšã¯æ°ã $1$ æžããããšã§ããããã ãã $0$ ã瀺ããŠããç¶æ
ã§éæ¹åã«åããš $M - 1$ ã瀺ãã $M - 1$ ã瀺ããŠããç¶æ
ã§é æ¹åã«åããš $0$ ã瀺ãã</li>
</ol>
<p>AORã€ã«ã¡ããã®ããã«ãéµãéããããã«å¿
èŠãªã·ãªã³ããŒã®æå°ã®å転æ°ãæ±ããããã ããéããããšãã§ããªãå Žå㯠$-1$ ãåºåããã</p>
<h2>å¶çŽ</h2>
<ul>
<li>$2 \le N \le 3 \times 10^2$</li>
<li>$2 \le M \le 10^5$</li>
<li>$0 \le T_i \lt M$</li>
<li>å
¥åã¯å
šãп޿°ã§äžããããã</li>
</ul>
<h2>å
¥å圢åŒ</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<p>$N \ M$<br>$T_1 \ T_2 \ T_3 \dots T_N$</p>
<h2>åºå</h2>
<p>éµãéããããã«å¿
èŠãªã·ãªã³ããŒã®æå°ã®å転æ°ãåºåããããã ããéããããšãã§ããªãå Žå㯠$-1$ ãåºåããããŸããæ«å°Ÿã«æ¹è¡ãåºåããã</p>
<h2>ãµã³ãã«</h2>
<h3>ãµã³ãã«å
¥å 1</h3>
<pre>2 3
0 1
</pre>
<h3>ãµã³ãã«åºå 1</h3>
<pre>-1
</pre>
<h3>ãµã³ãã«å
¥å 2</h3>
<pre>3 6
0 4 4
</pre>
<h3>ãµã³ãã«åºå 2</h3>
<pre>2
</pre>
<h3>ãµã³ãã«å
¥å 3</h3>
<pre>3 6
2 4 2
</pre>
<h3>ãµã³ãã«åºå 3</h3>
<pre>4
</pre>
<h3>ãµã³ãã«å
¥å 4</h3>
<pre>15 56
19 32 40 34 4 10 30 15 4 18 52 28 18 8 4
</pre>
<h3>ãµã³ãã«åºå 4</h3>
<pre>110
</pre>
<!-- - - - - - end nicebody - - - - - --> |
p00625 |
<H1><font color="#000000">Problem E:</font> Frisbee Dogs</H1>
<p>
ã¯ã¬ã€ã³ã¯, åœŒå¥³ã®æç¬ã§ãã Jack ãããªã¹ããŒããã°å€§äŒã«åºå ŽãããããšããŠãã. ããã, 圌女㯠Jack ãããæçžŸãåãããèªä¿¡ãç¡ã. 圌女ã®ããã«, 倧äŒãã·ãã¥ã¬ãŒãã㊠Jack ã®æçžŸãèŠç©ããããã°ã©ã ãäœæããŠã»ãã.
</p>
<p>
ãã®å€§äŒã¯, 2次å
å¹³é¢äžã«ãã N å¹ã®ç¬ã«ãã£ãŠè¡ããã. 倧äŒã®éå§æç¹ã«ãããŠ, <i>i</i> çªç®ã®ç¬ã¯ (<i>D<sub>i</sub>x</i>, <i>D<sub>i</sub>y</i>) ã®äœçœ®ã«ãã. <i>i</i> çªç®ã®ç¬ã¯ <i>V<sub>i</sub></i> [m/s] ã§èµ°ãããšãã§ã, å
šãŠã®ç¬ã¯ååå°ããã®ã§ç¹ãšã¿ãªãã. ããæå»ã«, 2 å¹ä»¥äžã®ç¬ãåãäœçœ®ã«ããŠãæ§ããªã.
</p>
<p>
1æç®ã®ããªã¹ããŒã®çºå°ããã£ãŠå€§äŒã¯éå§ã, ãã®ç¬éããç¬ãã¡ã¯åãããšãèš±ããã. ããªã¹ããŒããŸãç¹ãšã¿ãªãããšãã§ã, <i>i</i> æç®ã®ããªã¹ããŒã¯ (<i>FP<sub>i</sub>x</i>, <i>FP<sub>i</sub>y</i>) ã®äœçœ®ãã (<i>FV<sub>i</sub>x</i>, <i>FV<sub>i</sub>y</i>) [m/s] ã®é床ãã¯ãã«ã§çºå°ãã, çéçŽç·éåãç¶ãã. ããç¬ã®äœçœ®ãšããªã¹ããŒã®äœçœ®ãçãããªã£ããšã, ãã®ç¬ã¯ããªã¹ããŒãååŸããããšãã§ãã.
</p>
<p>
1æç®ã®ããªã¹ããŒãããããã®ç¬ã«ååŸãããç¬é, 2æç®ã®ããªã¹ããŒãçºå°ããã. 2æç®ã®ããªã¹ããŒãååŸãããç¬é3æç®ãçºå°ãã, 以äžåæ§ã«ããªã¹ããŒãååŸãããçŽåŸã«æ¬¡ã®ããªã¹ããŒãçºå°ããã. M æç®ã®ããªã¹ããŒãååŸããããšå€§äŒã¯çµäºãã.
</p>
<p>
èšããŸã§ããªã, ç¬ãã¡ã®ç®æšã¯ããå€ãã®ããªã¹ããŒãååŸããããšã§ãã. ç¬ãã¡ã¯, 以äžã®ãããªæŠç¥ããšã.
</p>
<p>
ããªã¹ããŒãçºå°ããããšã, ç¬ã¯å¯èœãªéãæ©ãæå»ã«ãããååŸã§ããããã«ç§»åã, ããªã¹ããŒãååŸãã. ãã ã, ããªã¹ããŒãååŸã§ããªããšãã¯çŸåšããå Žæã«åŸ
æ©ãã.
</p>
<p>
ããç¬ãããªã¹ããŒãååŸã§ãããã©ããã®å€æã¯, ä»ã®ç¬ã®è¡åã«é¢ä¿ãªãè¡ããã. ã€ãŸã, ããç¬ãããªã¹ããŒãååŸããããã«ç§»åãããã®ã®, ä»ã®ç¬ã«å
ã«ååŸãããŠããŸãããšãæããã. ããããã®ç¬ãããªã¹ããŒãååŸãæ°ããªããªã¹ããŒãçºå°ãããç¬é, ç¬ãã¡ã¯æ°ããããªã¹ããŒã«å¯ŸããŠäžèšã®æŠç¥ããšã.
</p>
<p>
ããªãã®äœæããããã°ã©ã ã¯ãããããã®ç¬ãååŸããããªã¹ããŒã®æ°ãåºåããªããã°ãªããªã.
</p>
<H2>Input</H2>
<p>
å
¥åãã¡ã€ã«ã¯, è€æ°ã®ããŒã¿ã»ããããæ§æããã.
</p>
<p>
ããŒã¿ã»ããã®1è¡ç®ã«ã¯, ç¬ã®æ° N (1 ≤ N ≤ 10) ãšããªã¹ããŒã®æ° M (1 ≤ M ≤ 1000)ãäžãããã.
</p>
<p>
ç¶ã N è¡ã«ã¯, ç¬ã®åæäœçœ®ãšé床 <i>D<sub>i</sub>x</i>, <i>D<sub>i</sub>y</i>, <i>V<sub>i</sub></i> ã1ã€ã®ç©ºçœåºåãã§äžãããã.
</p>
<p>
ç¶ã M è¡ã«ã¯, ããªã¹ããŒã®çºå°äœçœ®ãšé床 <i>FP<sub>i</sub>x</i>, <i>FP<sub>i</sub>y</i>, <i>FV<sub>i</sub>x</i>, <i>FV<sub>i</sub>y</i> ã1ã€ã®ç©ºçœæååºåãã§äžãããã.
</p>
<p>
äžãããã座æšå€ã¯å®æ°ã§ããããã®çµ¶å¯Ÿå€ã¯ 1000 ãè¶ããªã. äžããããé床ã¯å®æ°ã§ãã 1 ≤ <i>DV<sub>i</sub></i> ≤ 100, -25 ≤ <i>FV<sub>i</sub>x</i>, <i>FV<sub>i</sub>y</i> ≤ 25 ã§ãã. ã©ã®ç¬ã«ãååŸã§ããªãããªã¹ããŒã¯ãªããšä»®å®ããŠãã.
</p>
<p>
ä»»æã®ããªã¹ããŒãããç¬ã«æå» <i>t</i> ã§ååŸããããšããæå» <i>t</i> + 1e-6 以åã«ãããååŸã§ããç¬ã¯ããªã.
</p>
<p>
ã·ãã¥ã¬ãŒã·ã§ã³ã®é, ç¬ã® <i>x</i> 座æš, <i>y</i> 座æšã®çµ¶å¯Ÿå€ã¯ 1e+8 ãè¶ããªã.
</p>
<p>
N, M ããšãã« 0 ã®ãšãå
¥åã®çµããã瀺ã.
</p>
<H2>Output</H2>
<p>
ããããã®ç¬ãååŸããããªã¹ããŒã®æ°ã, ç©ºçœæåã§åºåã£ãŠ1è¡ã«åºåãã. åºåããé çªã¯, å
¥åã§äžããããé çªãšçãããªããã°ãªããªã.
</p>
<H2>Sample Input</H2>
<pre>
2 1
12 5 3
0 17 3
0 0 2 2
2 3
2 0 2
100 100 2
0 0 -1 0
-2 -5 0 3
100 100 1 1
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1 0
2 1
</pre>
|
p02618 | <span class="lang-en">
<div class="part">
<section>
<h3>Problem Statement</h3><p>AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for <var>D</var> days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows.</p>
<ul>
<li>The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative.</li>
<li>Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type <var>i</var> on day <var>d</var> will increase the satisfaction by <var>s_{d,i}</var>.</li>
<li>If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type <var>i</var> has an integer <var>c_i</var>, and at the end of each day <var>d=1,2,...,D</var>, the satisfaction decreases as follows. Let <var>\mathrm{last}(d,i)</var> be the last day before day <var>d</var> (including <var>d</var>) on which a contest of type <var>i</var> was held. If contests of type <var>i</var> have never been held yet, we define <var>\mathrm{last}(d,i)=0</var>. At the end of day <var>d</var>, the satisfaction decreases by <var>\sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i))</var>.</li>
</ul>
<p>Please schedule contests on behalf of AtCoder.
If the satisfaction at the end of day <var>D</var> is <var>S</var>, you will get a score of <var>\max(10^6 + S, 0)</var>.
There are 50 test cases, and the score of a submission is the total scores for each test case.
You can make submissions multiple times, and the highest score among your submissions will be your score.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>D = 365</var></li>
<li>Each <var>c_i</var> is an integer satisfying <var>0\leq c_i \leq 100</var>.</li>
<li>Each <var>s_{d,i}</var> is an integer satisfying <var>0\leq s_{d,i} \leq 20000</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>D</var>
<var>c_1</var> <var>c_2</var> <var>\cdots</var> <var>c_{26}</var>
<var>s_{1,1}</var> <var>s_{1,2}</var> <var>\cdots</var> <var>s_{1,26}</var>
<var>\vdots</var>
<var>s_{D,1}</var> <var>s_{D,2}</var> <var>\cdots</var> <var>s_{D,26}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Let <var>t_d</var> (<var>1\leq t_d \leq 26</var>) be the type of the contest that will be held at day <var>d</var>.
Print <var>D</var> integers <var>t_d</var> to Standard Output in the following format:</p>
<pre><var>t_1</var>
<var>t_2</var>
<var>\vdots</var>
<var>t_D</var>
</pre>
<p>Any output that does not follow the above format may result in <s>0 points</s><b>WA</b> for that test case.</p>
</section>
</div>
<div class="part">
<section>
<h3>Input Generation</h3><p>Each integer <var>c_i</var> and <var>s_{d,i}</var> is generated independently and uniformly at random from the integers in the range described in the problem statement.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
17
13
14
13
</pre>
<p>Note that this example is a small one for checking the problem specification. It does not satisfy the constraint <var>D=365</var> and is never actually given as a test case. The final satisfaction with this output is 79325, so the score is 1079325.</p>
<p><a href="https://img.atcoder.jp/intro-heuristics/6f4c9d0cfda6a311fea2d9cf23e4f032.zip">Input generator, score calculator, and visualizer</a></p>
</section>
</div>
<div class="part">
<section>
<h3>Beginner's Guide</h3><p>If you don't know what to do, proceed to problem B or C.</p></section>
</div>
</span> |
p00330 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>ã¯ãŒã</H1>
<p>
ã³ã³ãã¥ãŒã¿ã§æ±ãããããŒã¿ã®æå°åäœãããã(bit)ãšåŒã³ãè€æ°ã®ãããããŸãšããŠè¡šããæ
å ±éãã¯ãŒã(word)ãšåŒã³ãŸããçŸåšãå€ãã®ã³ã³ãã¥ãŒã¿ã§ã¯ïŒã¯ãŒããïŒïŒããããšããŠåŠçããŠããŸãã
</p>
<p>
ïŒã¯ãŒããïŒïŒãããã§è¡šãã³ã³ãã¥ãŒã¿ã«ã€ããŠãã¯ãŒãåäœã§äžããããããŒã¿é <var>W</var> ããããåäœã§åºåããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>W</var>
</pre>
<p>
å
¥åã¯ïŒè¡ãããªããããŒã¿é <var>W</var> (0 ≤ <var>W</var> ≤ 100) ãäžããããã
</p>
<h2>Output</h2>
<p>
ãããåäœã®å€ãïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
4
</pre>
<h2>Sample Output 1</h2>
<pre>
128
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
3
</pre>
<h2>Sample Output 2</h2>
<pre>
96
</pre> |
p01872 |
<h2>A: ãã€ãã³ã㌠- My Number -</h2>
<h3>åé¡</h3>
<p>ãã£ããªãŒãïŒé
å»é
å»ïŒ</p>
<p>ãã£ïŒç§ã仿¥ããæ§ãã®ãã®äŒç€Ÿã§åãããšã«ãªã£ããã ïŒ</p>
<p>ãããªã®ã«ã忥ããå¯åã ãªããŠâŠïŒïŒ</p>
<p>仿¥ã¯äŒç€Ÿã«ãã€ãã³ããŒãæããªããã°ãªããªã倧åãªæ¥ãªã®ã«âŠïŒ</p>
<p>ã¿ããªç¥ã£ãŠãããšæãããã©ãäžå¿ãã€ãã³ããŒã®èª¬æããããïŒ</p>
<p>ãã€ãã³ããŒã¯è¡æ¿æç¶ãã«ãããå人ãèå¥ããããã«çšãããã <var>12</var> æ¡ãããªãæ°åå (<var>P_{11} P_{10} P_{9}</var> ... <var>P_{1} P_{0}</var>) ã§ããã</p>
<p>æ«å°Ÿã® <var>P_{0}</var> ã¯ãã§ãã¯ãã£ãžãããšåŒã°ãã
<a href="http://www.soumu.go.jp/main_content/000327387.pdf">ç·åç什第å
«åäºå·ç¬¬äºç« </a>
ã«å®ããããŠããããã«ã次åŒã§å®çŸ©ãããã</p>
<ul>
<li><var>11 − ( ({\rm Σ}_{n = 1}^{11} P_{n} × Q_{n}) ã 11 ã§é€ããäœã )</var></li>
<li>ãã ãã <var>( ({\rm Σ}_{n = 1}^{11} P_{n} × Q_{n}) ã 11 ã§é€ããäœã ) \≤ 1</var> ã®å Žå㯠<var>0</var> ãšããã</li>
</ul>
<p>ããã§ã <var>Q_{n}</var> (<var>n = 1, 2, </var>...<var>, 11</var>) ã¯æ¬¡ã®ããã«å®çŸ©ãããã</p>
<ul>
<li><var>1 \≤ n \≤ 6</var> ã®ãšã <var>n + 1</var></li>
<li><var>7 \≤ n \≤ 11</var> ã®ãšã <var>n − 5</var></li>
</ul>
<p>åãã£ãããªïŒ</p>
<p>ã§ãã<var>12</var>æ¡ã®æ°ååãªããŠèŠããããªããããå®¶ãåºãçŽåã«ãã€ãã³ããŒã®éç¥æžã®åçãæ®ã£ããã ïŒ</p>
<p>ã»ããç§ã®ãã€ãã³ããŒãã£ãããã§ããïŒ</p>
<p>âŠã£ãŠããïŒ</p>
<p>ãªãã§ãã€ãã³ããŒã®äžã«çŽè±ã®ç²ãä¹ã£ãŠããã®ïŒïŒ</p>
<p>ãããããã<var>1</var>æ¡ã ãåãããªããŠãã€ãã³ããŒãæããããªããïŒ</p>
<p>ç§ãããããã©ããªã£ã¡ããã®âŠïŒïŒ</p>
<p>ããã ïŒ</p>
<p>ãã§ãã¯ãã£ãžããã®å®çŸ©ã«ççŸããªããããªæ°åãèŠã€ããã°ãããã ïŒ</p>
<p>ã§ãèšç®é£ããâŠ</p>
<p>ãããç§ã®åæ¥ã倱æããªãããã«ãåãããªãæ°åãèŠã€ããã®ãæäŒã£ãŠïŒïŒ</p>
<p>ãã£ïŒ</p>
<p>äœãèšã£ãŠãããåããã«ããã£ãã£ãŠïŒ</p>
<p>ãã£ãŠã»ããããšã¯èŠããã«ã</p>
<p>1æ¡ã ãæ°åãäžæãª<var>12</var>æ¡ã®ãã€ãã³ããŒãäžããããã®ã§ããã§ãã¯ãã£ãžããã®å®çŸ©ã«ççŸããªãããã«ãäžæãªæ¡ã®æ°åãæ±ããã</p>
<p>ãã ãããã®ãããªæ°åãè€æ°ãããšãã«ã¯ âMULTIPLEâ ãšåºåããã</p>
<p>ãšããããšã ãïŒ</p>
<p>ãããããã£ïŒ</p>
<h3>å
¥å圢åŒ</h3>
<p>
å
¥åã¯ã12æåã®æåå <var>S = P_{11} P_{10} P_{9} </var> ... <var> P_{1} P_{0}</var> ãš1åã®æ¹è¡ããã®é çªã«äžããããã
<var>P</var> ã®æ·»åãéé ã«ä»ããããŠããããšã«æ³šæããã
ãã®æååã®åæå㯠â0â, â1â, â2â, â3â, â4â, â5â, â6â, â7â, â8â, â9â, â?â ã®ããããã§ããã
â?â ã¯äžæãªæ¡ã衚ããä»ã®æåã¯ãã€ãã³ããŒã®æ°åã衚ãã
ãŸãã â?â 㯠<var>S</var> ã®äžã§ã¡ããã©1åã ãçŸããã
ãªããå
¥åã«ãããŠãäžæãªæ¡ã«å
¥ãæ°åã§ããã§ãã¯ãã£ãžããã®å®çŸ©ã«ççŸããªããããªãã®ã1ã€ä»¥äžååšããããšãä¿èšŒãããã
</p>
<h3>åºå圢åŒ</h3>
<p>
äžæãªæ¡ã«å
¥ãæ°åã§ããã§ãã¯ãã£ãžããã®å®çŸ©ãççŸããªããããªãã®ãå¯1ã€ã«å®ãŸããšãã¯ããã®æ°åãåºåããã
ççŸããªããããªæ°åãè€æ°ååšãããšãã«ã¯ã âMULTIPLEâ ãšåºåããã
ãããã®å ŽåããæåŸã«1床ã ãæ¹è¡ããã
</p>
<h3>å
¥åäŸ1</h3>
<pre>?12345678901</pre>
<h3>åºåäŸ1</h3>
<pre>4</pre>
<p>ãã§ãã¯ãã£ãžããã®å®çŸ©ãã â?â ã <var>4</var> 以å€ã«ãªãããšã¯ããåŸãŸããã</p>
<h3>å
¥åäŸ2</h3>
<pre>2016030810?0</pre>
<h3>åºåäŸ2</h3>
<pre>MULTIPLE</pre>
<p>â?â ã <var>0</var>, <var>6</var> ã®ãããã®å Žåã§ããã§ãã¯ãã£ãžããã®å®çŸ©ãæºãããŸãã</p>
<h3>å
¥åäŸ3</h3>
<pre>20160308100?</pre>
<h3>åºåäŸ3</h3>
<pre>0</pre>
<h3>å
¥åäŸ4</h3>
<pre>0012300?0450</pre>
<h3>åºåäŸ4</h3>
<pre>8</pre> |
p00760 |
<h1>Millennium</h1>
<p>
A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1. Each year consists of 10 months, from month 1 through month 10, and starts from a <i>big month</i>. A common year shall start with a big month, followed by <i>small months</i> and big months one after another. Therefore the first month is a big month, the second month is a small month, the third a big month, ..., and the 10th and last month a small one. A big month consists of 20 days and a small month consists of 19 days. However years which are multiples of three, that are year 3, year 6, year 9, and so on, shall consist of 10 big months and no small month."</p>
<p>Many years have passed since the calendar started to be used. For celebration of the millennium day (the year 1000, month 1, day 1), a royal lottery is going to be organized to send gifts to those who have lived as many days as the number chosen by the lottery. Write a program that helps people calculate the number of days since their birthdate to the millennium day.
</p>
<!-- end en only -->
<h3>Input</h3>
<!-- begin en only -->
<p>
The input is formatted as follows.
</p>
<!-- end en only -->
<blockquote>
<i>n</i><br>
<i>Y<sub>1</sub> M<sub>1</sub> D<sub>1</sub></i><br>
<i>Y<sub>2</sub> M<sub>2</sub> D<sub>2</sub></i><br>
...<br>
<i>Y<sub>n</sub> M<sub>n</sub> D<sub>n</sub></i>
</blockquote>
<p>
Here, the first line gives the number of datasets as a positive integer <i>n</i>, which is less than or equal to 100. It is followed by <i>n</i> datasets. Each dataset is formatted in a line and gives three positive integers, <i>Y<sub>i</sub></i> (< 1000), <i>M<sub>i</sub></i> (≤ 10), and <i>D<sub>i</sub></i> (≤ 20), that correspond to the year, month and day, respectively, of a person's birthdate in the king's calendar. These three numbers are separated by a space.
</p>
<h3>Output</h3>
<!-- begin en only -->
<p>
For the birthdate specified in each dataset, print in a line the number of days from the birthdate, inclusive, to the millennium day, exclusive. Output lines should not contain any character other than this number.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>
8
1 1 1
344 3 1
696 5 1
182 9 5
998 8 7
344 2 19
696 4 19
999 10 20
</pre>
<h3>Output for the Sample Input</h3>
<pre>
196470
128976
59710
160715
252
128977
59712
1
</pre> |
p01521 |
<h1>B - ç°¡æãªã»ã</h1>
<h2>å顿</h2>
<p>
Båã¯ãªã»ãã倧奜ãã§ãã (ãªã»ãã®ã«ãŒã«ã«ã€ããŠã¯<a href="http://ja.wikipedia.org/wiki/%E3%82%AA%E3%82%BB%E3%83%AD_(%E9%81%8A%E6%88%AF)">Wikipediaã®ãªã»ãã®ããŒãž</a>ãåç
§ããïŒããã¹ãã«ã€ããŠã Wikipedia ã«æžãããŠãããšããïŒé§ãæã€ããšãã§ããªãå Žåã®ã¿ãã¹ã§ãããã®ãšãïŒãã¹ã®åæ°ã«å¶éã¯ç¡ããã®ãšããïŒ)
Båã¯é§ã®åæé
眮ã«ãã£ãŠã²ãŒã ã®çµæãã©ã®ããã«å€ããã®ãã«èå³ãããïŒ
ããããããªã 2 次å
ã®ç€é¢ã§èããã®ã¯é£ããã®ã§ïŒã²ãšãŸã㯠1 次å
ã®ç€é¢ã§èããããšã«ããïŒ
ããªãã¡ïŒãã®åé¡ã§ã¯ç€é¢ã¯çžŠå¹
1ïŒæšªå¹
ç¡éã®ãã¹ç®ã§ãããšèŠãªãïŒ
ãŸãïŒãªã»ãã®é§ã¯ã¢ã«ãã¡ãããå°æåã® <code>o</code> ãš <code>x</code> ã«ãã£ãŠè¡šãããšã«ããïŒ
</p>
<p>
Båã¯ãã®ç€é¢äžã®ãªã»ãã®åæé
眮ãšã㊠<var>N</var> åã®é§ãé£ç¶ãããŠäžŠã¹ïŒå·Šãã <var>i</var> çªç®ã®é§ã <var>c<sub>i</sub></var> ∈ {<code>o</code>, <code>x</code>} ãšãããã®ãèããããšã«ããïŒ
å
æã®é§ã <code>o</code> ãšãããšãïŒäž¡æ¹ã®ãã¬ã€ã€ãŒãæåãå°œãããæã«åå©è
ãã©ã¡ãã«ãªãããæ±ããŠæ¬²ããïŒ
</p>
<h2>å
¥å圢åŒ</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ
<pre>
<var>c<sub>1</sub>c<sub>2</sub>...c<sub>N</sub></var>
</pre>
<p><var>c<sub>i</sub></var> ã¯åæé
眮ã«ãããå·Šãã <var>i</var> çªç®ã®é§ã衚ãïŒ</p>
<h2>åºå圢åŒ</h2>
<p>åå©è
ã®é§ãåºåããïŒãªãïŒãã®ã²ãŒã ã¯åŒãåãã«ã¯ãªããªãããšãä¿èšŒãããŠããïŒ</p>
<h2>å¶çŽ</h2>
<ul>
<li>å
¥åã®æååã®é·ãã <var>N</var> ãšããŠïŒ<var>1 ≤ N ≤ 50</var> ã§ããïŒ</li>
<li><var>c<sub>i</sub></var> ∈ {<code>o</code>, <code>x</code>}</li>
</ul>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
oxxoxoo
</pre>
<h3>åºåäŸ 1</h3>
<pre>
o
</pre>
<p>
æå㯠<code>o</code> ã®çªã§ãããïŒæãŠããã¹ãååšããªãã®ã§ãã¹ãããïŒ
ç¶ã㊠<code>x</code> ã®çªã«ãªãïŒå·Šç«¯ãšå³ç«¯ã®ã©ã¡ããã«æã€ããšãã§ããïŒãããïŒ<code>x</code> ãã©ã¡ãã«æã£ããšããŠã <code>o</code> ã«åã€ããšã¯ã§ããªãïŒ
</p>
<h3>å
¥åäŸ 2</h3>
<pre>
xxxooxxox
</pre>
<h3>åºåäŸ 2</h3>
<pre>
x
</pre>
<hr>
<address>Writer: æ¥ æ¬å
ïŒå°æµç¿å€ªé</address>
<address>Tester: ç°æåç¯</address> |
p01171 |
<H1><font color="#000">Problem A:</font> Everlasting...?</H1>
<p>
Everlasting Sa-Ga, a new, hot and very popular role-playing game, is out on October 19, 2008.
Fans have been looking forward to a new title of Everlasting Sa-Ga.
</p>
<p>
Little Jimmy is in trouble. He is a seven-year-old boy, and he obtained the Everlasting Sa-Ga
and is attempting to reach the end of the game before his friends. However, he is facing difficulty
solving the riddle of the first maze in this game -- Everlasting Sa-Ga is notorious in extremely
hard riddles like Neverending Fantasy and Forever Quest.
</p>
<p>
The riddle is as follows. There are two doors on the last floor of the maze: the door to the
treasure repository and the gate to the hell. If he wrongly opens the door to the hell, the game
is over and his save data will be deleted. Therefore, he should never open the wrong door.
</p>
<p>
So now, how can he find the door to the next stage? There is a positive integer given for each
door -- it is a great hint to this riddle. The door to the treasure repository has the integer that
gives the larger <i>key numbe</i>r. The key number of a positive integer <i>n</i> is the largest prime factor
minus the total sum of any other prime factors, where the prime factors are the prime numbers
that divide into <i>n</i> without leaving a remainder. Note that each prime factor should be counted
only once.
</p>
<p>
As an example, suppose there are doors with integers 30 and 20 respectively. Since 30 has three
prime factors 2, 3 and 5, its key number is 5 - (2 + 3) = 0. Similarly, since 20 has two prime
factors 2 and 5, its key number 20 is 5 - 2 = 3. Jimmy therefore should open the door with 20.
</p>
<p>
Your job is to write a program to help Jimmy by solving this riddle.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets. Each dataset consists of a line that contains two integers <i>a</i>
and <i>b</i> separated by a space (2 ≤ <i>a</i>, <i>b</i> ≤ 10<sup>6</sup> ). It is guaranteed that key numbers of these integers
are always different.
</p>
<p>
The input is terminated by a line with two zeros. This line is not part of any datasets and thus
should not be processed.
</p>
<H2>Output</H2>
<p>
For each dataset, print in a line âaâ (without quotes) if the door with the integer <i>a</i> is connected
to the treasure repository; print âbâ otherwise. No extra space or character is allowed.
</p>
<H2>Sample Input</H2>
<pre>
10 15
30 20
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
a
b
</pre>
|
p02474 | <h2>Multiplication of Big Integers</h2>
<p>
Given two integers $A$ and $B$, compute the product, $A \times B$.
</p>
<h3>Input</h3>
<p>
Two integers $A$ and $B$ separated by a space character are given in a line.
</p>
<h3>Output</h3>
<p>
Print the product in a line.
</p>
<h3>Constraints</h3>
<ul>
<li>$-1 \times 10^{1000} \leq A, B \leq 10^{1000}$</li>
</ul>
<h3>Sample Input 1</h3>
<pre>
5 8
</pre>
<h3>Sample Output 1</h3>
<pre>
40
</pre>
<h3>Sample Input 2</h3>
<pre>
100 25
</pre>
<h3>Sample Output 2</h3>
<pre>
2500
</pre>
<h3>Sample Input 3</h3>
<pre>
-1 0
</pre>
<h3>Sample Output 3</h3>
<pre>
0
</pre>
<h3>Sample Input 4</h3>
<pre>
12 -3
</pre>
<h3>Sample Output 4</h3>
<pre>
-36
</pre>
|
p00449 |
<H1>è¹æ
</H1>
<h2>åé¡</h2>
<p>
JOIåœã«ã¯ïŒn å³¶ã®å³¶ãããïŒåå³¶ã«ã¯ 1 ãã n ãŸã§ã®çªå·ãä»ããããŠããïŒçŸåšïŒJOIåœã§ã¯åå³¶ã®éãçµã¶èªè·¯ç¶²ã®æŽåãé²ãã§ããïŒ
</p>
<p>
ããªãã¯ïŒè¹è¶ã®åç¬Šãæ±ã£ãŠãããã±ããã»ã³ã¿ãŒã«å€åããŠããïŒJOIåœã«ã¯è¹è¶ã䜿ã£ãŠïŒã§ããéãå®äŸ¡ã«ïŒå³¶ãšå³¶ã®éãæ
è¡ããããšèããŠããäººãæ²¢å±±ããïŒåœŒãã¯ïŒåºçºå°ãšç®çå°ã泚æç¥šã«èšå
¥ããŠïŒããªãã®ãšããã«éã£ãŠããïŒ
</p>
<p>
ããªãã®ä»äºã¯ïŒå®¢ããæ³šæç¥šãåãåã£ããããã«ïŒããã€ãã®è¹è¶ãä¹ãç¶ãã§ïŒåºçºå°ãšç®çå°ãçµã¶èªè·¯ã®äžã§ïŒãã£ãšãå®äŸ¡ãªéè³ãèšç®ãïŒå®¢ã«äŒããããšã§ããïŒ
ãã ãïŒæ
çšã«ãã£ãŠã¯ïŒè¹è¶ã䜿ã£ãŠæ
è¡ããããšãåºæ¥ãªãå ŽåãããïŒãã®ãšãã¯ãè¹è¶ã䜿ã£ãŠæ
è¡ããããšãåºæ¥ãªãããšå®¢ã«äŒããå¿
èŠãããïŒãŸãïŒJOIåœã§ã¯ïŒå³¶ãšå³¶ã®éãçµã¶æ°ããè¹è¶ãïŒæ¬¡ã
ãšéèªãéå§ããŠããïŒããªãã«ã¯ïŒãã®æ
å ±ãéæäŒããããïŒå®¢ã«è¿äºãããéã«ã¯ïŒææ°ã®æ
å ±ã«çæããªããã°ãªããªãïŒ
</p>
<p>
å
¥åãšããŠïŒå®¢ã®æ³šæç¥šãæ°ãã«éèªãéå§ããè¹è¶ã®éèªæ
å ±ãäžãããããšãã«ïŒå®¢ãžã®è¿äºãæ±ããããã°ã©ã ãäœæããïŒ
</p>
<p>
ãªãïŒå
¥åäŸïŒãšåºåäŸïŒã«å¯Ÿããå®è¡ç¶æ³ãïŒå³ïŒãšããŠå³ç€ºããŠããïŒ
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ
</p>
<p>
å
¥åã® 1 è¡ç®ã«ã¯2ã€ã®æŽæ° n, k (1 ≤ n ≤ 100, 1 ≤ k ≤ 5000) ãæžãããŠããïŒããã¯ïŒå³¶ã®æ°ã n å³¶ã§ïŒå
¥åã k + 1 è¡ãããªãããšã衚ãïŒ
i + 1 è¡ç® (1 ≤ i ≤ k) ã«ã¯ïŒ 3 åãŸã㯠4 åã®æŽæ°ã空çœãåºåããšããŠæžãããŠããïŒ
</p>
<ul>
<li> æåã®æ°åã 0 ã®ãšãïŒãã®è¡ã¯å®¢ã®æ³šæç¥šã衚ãïŒ<br>
ãã®è¡ã«ã¯3åã®æŽæ° 0, a, b (1 ≤ a ≤ n, 1 ≤ b ≤ n, a ≠ b) ã空çœãåºåããšããŠæžãããŠããïŒ
ããã¯ïŒå®¢ãïŒå³¶ a ãåºçºå°ãšãå³¶ b ãç®çå°ãšãããããªæ³šæç¥šãéã£ãŠããããšã衚ãïŒ
</li>
<li> æåã®æ°åã 1 ã®ãšãïŒãã®è¡ã¯æ°ãã«éèªãéå§ããè¹è¶ã®éèªæ
å ±ã衚ãïŒ<br>
ãã®è¡ã«ã¯ 4 åã®æŽæ° 1, c, d, e (1 ≤ c ≤ n, 1 ≤ d ≤ n, c ≠ d, 1 ≤ e ≤ 1000000) ãæžãããŠããïŒ<br>
ããã¯å³¶ c ãšå³¶ d ãåŸåŸ©ããè¹è¶ãæ°ãã«éèªãéå§ãïŒãã®è¹è¶ã®å³¶ c ããå³¶ d ãžã®éè³ãšïŒå³¶ d ããå³¶ c ãžã®éè³ãïŒå
±ã« e ã§ããããšã衚ãïŒ<br>
ãã®è¡ä»¥éã®æ³šæç¥šã«å¯ŸããŠã¯ïŒãã®è¹è¶ãèæ
®ããŠè¿äºãããªããã°ãªããªãïŒ
</li>
</ul>
<p>
æåã®æ®µéã§ã¯ïŒè¹è¶ã¯äžé»ãéèªããŠããªããã®ãšããïŒå
¥åã®ãã¡ïŒè¹è¶ã®éèªæ
å ±ã衚ãè¡ã¯ 1000 è¡ä»¥äžã§ããïŒãŸãïŒå³¶ãšå³¶ã®éã«ïŒè€æ°ã®è¹è¶ãéèªããããšãããããšã«æ³šæããïŒ
</p>
<p>
n, k ããšãã« 0 ã®ãšãå
¥åã®çµäºã瀺ã. ããŒã¿ã»ããã®æ°ã¯ 5 ãè¶
ããªãïŒ
</p>
<h2>åºå</h2>
<p>
ããŒã¿ã»ããããšã«ä»¥äžã®åœ¢åŒã§åºåããïŒ
</p>
<p>
å
¥åã®ãã¡ïŒæ³šæç¥šã衚ãè¡ã®æ°ã m ãšããïŒ
<!--æåºããåºåãã¡ã€ã«--> åããŒã¿ã»ããã®åºå㯠m è¡ãããªãïŒ i è¡ç®(1 ≤ i ≤ m)ã«ã¯ïŒ i çªç®ã®æ³šæç¥šã«å¯Ÿããè¿äºãè¡šãæŽæ°ãæžãïŒ
ããªãã¡ïŒ i çªç®ã®æ³šæç¥šã®åºçºå°ãšç®çå°ã®éãïŒããã€ãã®è¹è¶ãä¹ãç¶ãã§æ
è¡ããããšãå¯èœãªãã°ïŒãã®éè³ã®åèšã®æå°å€ãæžãïŒæ
è¡ããããšãäžå¯èœãªãã°ïŒ-1 ãåºåããïŒ
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ</h3>
<pre>
3 8
1 3 1 10
0 2 3
1 2 3 20
1 1 2 5
0 3 2
1 1 3 7
1 2 1 9
0 2 3
5 16
1 1 2 343750
1 1 3 3343
1 1 4 347392
1 1 5 5497
1 2 3 123394
1 2 4 545492
1 2 5 458
1 3 4 343983
1 3 5 843468
1 4 5 15934
0 2 1
0 4 1
0 3 2
0 4 2
0 4 3
0 5 3
0 0
</pre>
<h3>åºåäŸ</h3>
<pre>
-1
15
12
5955
21431
9298
16392
24774
8840
</pre>
<div class="source">
<p class="source">
äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p02024 | <h2>J: éœ (City)</h2>
<p>ãµã³ã¿ã¯ããéœã«ãã¬ãŒã³ããå±ããããšã«ããã</p>
<p>ãã®éœã¯åå $H$ åºç» à æ±è¥¿ $W$ åºç»ã«åããããé·æ¹åœ¢ã®åœ¢ãããŠãããååºç»ã«ãã¬ãŒã³ããå±ããå®¶ã 1 ã€ãã€ããã</p>
<p>åããæ°ã㊠$X$ çªç®ã西ããæ°ã㊠$Y$ çªç®ã®åºç»ã $(X, Y)$ ã§è¡šãã</p>
<p>ãµã³ã¿ã¯æ¬¡ã®æ¡ä»¶ã§ç§»åããã</p>
<ul>
<li>ã¯ããã«åºç» $(S, T)$ ã«éãããã®å Žæããã¹ã¿ãŒãããã</li>
<li>1 åã®ç§»åã§æ±è¥¿ååã«é£ãåãåºç»ã«ç§»åã§ããè¡ã®å€ã«ã¯ç§»åã§ããªãã</li>
<li>1 床蚪ããåºç»ã«ã¯ã2 床ãšå
¥ããªãã</li>
</ul>
<p>ãµã³ã¿ãéœã«ãããã¹ãŠã®å®¶ã蚪ããããšãã§ãããå€å®ããã</p>
<h3>å
¥å</h3>
<p>$H, W, S, T$ã空çœåºåãã§äžããããã</p>
<h3>åºå</h3>
<p>ãµã³ã¿ãéœã«ãããã¹ãŠã®å®¶ã蚪ããããå Žå㯠"Yes"ãããã§ãªãå Žå㯠"No" ãšåºåããã</p>
<h3>å¶çŽ</h3>
<ul>
<li>$H, W$ 㯠$2$ ä»¥äž $1 \ 000 \ 000 \ 000$ 以äžã®æŽæ°</li>
<li>$S$ 㯠$1$ ä»¥äž $H$ 以äžã®æŽæ°</li>
<li>$T$ 㯠$1$ ä»¥äž $W$ 以äžã®æŽæ°</li>
</ul>
<h3>å
¥åäŸ1</h3>
<pre>
4 5 2 3
</pre>
<h3>åºåäŸ1</h3>
<pre>
Yes
</pre>
<p>äŸãã°ãå³ã®è¡ãæ¹ãããã°è¯ãã</p>
<div align="center">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/paken_camp_2018_day1_j_city_1"/>
</div>
<h3>å
¥åäŸ2</h3>
<pre>
3 3 1 2
</pre>
<h3>åºåäŸ2</h3>
<pre>
No
</pre>
|
p00019 |
<H1>Factorial</H1>
<p>
Write a program which reads an integer <var>n</var> and prints the factorial of <var>n</var>. You can assume that <var>n</var> ≤ 20.
</p>
<H2>Input</H2>
<p>
An integer <var>n</var> (1 ≤ <var>n</var> ≤ 20) in a line.
</p>
<H2>Output</H2>
<p>
Print the factorial of <var>n</var> in a line.
</p>
<H2>Sample Input</H2>
<pre>
5
</pre>
<H2>Output for the Sample Input</H2>
<pre>
120
</pre>
|
p01258 |
<H1><font color="#000">Problem I:</font> Memory Match</H1>
<p>
Memory match is a single-player game which employs a set of 2<i>M</i> cards. Each card is labeled with a
number between 1 and <i>M</i> on its face. For each number <i>i</i> (1 ≤ <i>i</i> ≤ <i>M</i>), there are exactly two cards which
have the number <i>i</i>. At the start of the game, all cards are shuffled and laid face down on a table. In each
turn you choose two cards and turn them face up. If two numbers on the cards are the same, they are
removed from the table. Otherwise, they are turned face down again (this is called a mismatch). When
you choose cards, you do not have to turn two cards simultaneously; you can choose the second card
after you see the number of the first card. The objective of the game is to remove all the cards with as
few mismatches as possible.
</p>
<p>
Royce A. Mitchell has extraordinary memory, so he can remember all the positions and the numbers of
the cards that he has already turned face up. Your task is to write a program that calculates the expected
number of mismatches, on average, when he plays the game optimally.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets.
</p>
<p>
Each dataset consists of one even number <i>N</i> (2 ≤ <i>N</i> ≤ 1000) which denotes the number of cards in the
set.
</p>
<p>
The end of input is indicated by a line that contains a single zero. This is not part of the input and you
may not treat this line as a dataset.
</p>
<H2>Output</H2>
<p>
For each dataset, print the expected number of mismatches. Each output value may have an arbitrary
number of fractional digits, provided that the error is within 10<sup>-6</sup>.
</p>
<H2>Sample Input</H2>
<pre>
2
4
6
8
10
52
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0.0000000000
0.6666666667
1.3333333333
1.9238095238
2.5523809524
15.4435236099
</pre>
|
p03265 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a square in the <var>xy</var>-plane. The coordinates of its four vertices are <var>(x_1,y_1),(x_2,y_2),(x_3,y_3)</var> and <var>(x_4,y_4)</var> in counter-clockwise order.
(Assume that the positive <var>x</var>-axis points right, and the positive <var>y</var>-axis points up.)</p>
<p>Takahashi remembers <var>(x_1,y_1)</var> and <var>(x_2,y_2)</var>, but he has forgot <var>(x_3,y_3)</var> and <var>(x_4,y_4)</var>.</p>
<p>Given <var>x_1,x_2,y_1,y_2</var>, restore <var>x_3,y_3,x_4,y_4</var>. It can be shown that <var>x_3,y_3,x_4</var> and <var>y_4</var> uniquely exist and have integer values.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>|x_1|,|y_1|,|x_2|,|y_2| \leq 100</var></li>
<li><var>(x_1,y_1)</var> â <var>(x_2,y_2)</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>x_1</var> <var>y_1</var> <var>x_2</var> <var>y_2</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>x_3,y_3,x_4</var> and <var>y_4</var> as integers, in this order.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>0 0 0 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>-1 1 -1 0
</pre>
<p><var>(0,0),(0,1),(-1,1),(-1,0)</var> is the four vertices of a square in counter-clockwise order.
Note that <var>(x_3,y_3)=(1,1),(x_4,y_4)=(1,0)</var> is not accepted, as the vertices are in clockwise order.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 3 6 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3 10 -1 7
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>31 -41 -59 26
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>-126 -64 -36 -131
</pre></section>
</div>
</span> |
p01608 |
<h2>1</h2>
<h2>Problem Statement</h2>
<p>é·ã<var>n</var>ã®ãããåãããïŒ</p>
<p>å·Šãã<var>i</var>çªç®ã®ãããã1ã®ãšãïŒã¹ã³ã¢ã<var>a_i</var>ç¹åŸãããïŒ<br />
å·Šãã<var>i</var>çªç®ã®ããããäžå¿ã«è·é¢<var>w</var>以å
ã«ãã1ã®åæ°(<var>=|\{j \in \{1,...,n\}â©\{i-w,...,i+w\} | å·Šãã</var>j<var>çªç®ã®ãããã1\}|</var>)ã奿°ã®ãšãïŒã¹ã³ã¢ã<var>b_i</var>ç¹åŸãããïŒ</p>
<p>ã¹ã³ã¢ãæãå€ãåŸããããããªãããåãæ±ããïŒ</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã«åŸãïŒäžããããæ°ã¯å
šãп޿°ã§ããïŒ</p>
<pre><var>n</var> <var>w</var>
<var>a_1</var> <var>...</var> <var>a_n</var>
<var>b_1</var> <var>...</var> <var>b_n</var></pre>
<h2>Constraints</h2>
<ul class="list1" style="padding-left:16px;margin-left:16px"><li><var>1âŠnâŠ1,000</var></li>
<li><var>1âŠwâŠ1,000</var></li>
<li><var>0âŠa_iâŠ10^5</var></li>
<li><var>0âŠb_iâŠ10^5</var></li></ul>
<h2>Output</h2>
<p>æãå€ãã¹ã³ã¢ãåŸããããããåã1è¡ã«åºåããïŒ<br />
ãã®ãããªè§£ãè€æ°ããå Žåã¯ã©ããåºåããŠãããïŒ</p>
<h2>Sample Input 1</h2>
<pre>4 1
3 1 2 7
13 8 25 9</pre>
<h2>Output for the Sample Input 1</h2>
<pre>1001</pre>
<p>3+7+13+8+25+9=65ç¹ãåŸãããïŒ</p>
<h2>Sample Input 2</h2>
<pre>2 1
1 1
3 3</pre>
<h2>Output for the Sample Input 2</h2>
<pre>10</pre>
<p>01ãšåºåããŠãããïŒ</p>
|
p03635 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In <em>K-city</em>, there are <var>n</var> streets running east-west, and <var>m</var> streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 †n, m †100</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>n</var> <var>m</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of blocks in K-city.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>There are six blocks, as shown below:</p>
<div style="text-align: center;">
<img alt="9179be829dc9810539213537d4c7398c.png" src="https://atcoder.jp/img/abc069/9179be829dc9810539213537d4c7398c.png">
</img></div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>There are one block, as shown below:</p>
<div style="text-align: center;">
<img alt="997bfafa99be630b54d037225a5c68ea.png" src="https://atcoder.jp/img/abc069/997bfafa99be630b54d037225a5c68ea.png">
</img></div></section>
</div>
</span> |
p02927 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Today is August <var>24</var>, one of the five Product Days in a year.</p>
<p>A date <var>m</var>-<var>d</var> (<var>m</var> is the month, <var>d</var> is the date) is called a Product Day when <var>d</var> is a two-digit number, and all of the following conditions are satisfied (here <var>d_{10}</var> is the tens digit of the day and <var>d_1</var> is the ones digit of the day):</p>
<ul>
<li><var>d_1 \geq 2</var></li>
<li><var>d_{10} \geq 2</var></li>
<li><var>d_1 \times d_{10} = m</var></li>
</ul>
<p>Takahashi wants more Product Days, and he made a new calendar called Takahashi Calendar where a year consists of <var>M</var> month from Month <var>1</var> to Month <var>M</var>, and each month consists of <var>D</var> days from Day <var>1</var> to Day <var>D</var>.</p>
<p>In Takahashi Calendar, how many Product Days does a year have?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq M \leq 100</var></li>
<li><var>1 \leq D \leq 99</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>M</var> <var>D</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of Product Days in a year in Takahashi Calender.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>15 40
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
</pre>
<p>There are <var>10</var> Product Days in a year, as follows (<var>m</var>-<var>d</var> denotes Month <var>m</var>, Day <var>d</var>):</p>
<ul>
<li><var>4</var>-<var>22</var></li>
<li><var>6</var>-<var>23</var></li>
<li><var>6</var>-<var>32</var></li>
<li><var>8</var>-<var>24</var></li>
<li><var>9</var>-<var>33</var></li>
<li><var>10</var>-<var>25</var></li>
<li><var>12</var>-<var>26</var></li>
<li><var>12</var>-<var>34</var></li>
<li><var>14</var>-<var>27</var></li>
<li><var>15</var>-<var>35</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>12 31
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p03320 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let <var>S(n)</var> denote the sum of the digits in the decimal notation of <var>n</var>.
For example, <var>S(123) = 1 + 2 + 3 = 6</var>.</p>
<p>We will call an integer <var>n</var> a <strong>Snuke number</strong> when, for all positive integers <var>m</var> such that <var>m > n</var>, <var>\frac{n}{S(n)} \leq \frac{m}{S(m)}</var> holds.</p>
<p>Given an integer <var>K</var>, list the <var>K</var> smallest Snuke numbers.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq K</var></li>
<li>The <var>K</var>-th smallest Snuke number is not greater than <var>10^{15}</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>K</var> lines. The <var>i</var>-th line should contain the <var>i</var>-th smallest Snuke number.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
2
3
4
5
6
7
8
9
19
</pre></section>
</div>
</span> |
p03770 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke arranged <var>N</var> colorful balls in a row.
The <var>i</var>-th ball from the left has color <var>c_i</var> and weight <var>w_i</var>.</p>
<p>He can rearrange the balls by performing the following two operations any number of times, in any order:</p>
<ul>
<li>Operation <var>1</var>: Select two balls with the same color. If the total weight of these balls is at most <var>X</var>, swap the positions of these balls.</li>
<li>Operation <var>2</var>: Select two balls with different colors. If the total weight of these balls is at most <var>Y</var>, swap the positions of these balls.</li>
</ul>
<p>How many different sequences of colors of balls can be obtained? Find the count modulo <var>10^9 + 7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N †2 à 10^5</var></li>
<li><var>1 †X, Y †10^9</var></li>
<li><var>1 †c_i †N</var></li>
<li><var>1 †w_i †10^9</var></li>
<li><var>X, Y, c_i, w_i</var> are all integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var> <var>Y</var>
<var>c_1</var> <var>w_1</var>
<var>:</var>
<var>c_N</var> <var>w_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 7 3
3 2
4 3
2 1
4 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<ul>
<li>The sequence of colors <var>(2,4,3,4)</var> can be obtained by swapping the positions of the first and third balls by operation <var>2</var>.</li>
<li>It is also possible to swap the positions of the second and fourth balls by operation <var>1</var>, but it does not affect the sequence of colors.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 1 1
1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>21 77 68
16 73
16 99
19 66
2 87
2 16
7 17
10 36
10 68
2 38
10 74
13 55
21 21
3 7
12 41
13 88
18 6
2 12
13 87
1 9
2 27
13 15
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>129729600
</pre></section>
</div>
</span> |
p02862 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a knight - the chess piece - at the origin <var>(0, 0)</var> of a two-dimensional grid.</p>
<p>When the knight is at the square <var>(i, j)</var>, it can be moved to either <var>(i+1,j+2)</var> or <var>(i+2, j+1)</var>.</p>
<p>In how many ways can the knight reach the square <var>(X, Y)</var>?</p>
<p>Find the number of ways modulo <var>10^9 + 7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq X \leq 10^6</var></li>
<li><var>1 \leq Y \leq 10^6</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>X</var> <var>Y</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways for the knight to reach <var>(X, Y)</var> from <var>(0, 0)</var>, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>There are two ways: <var>(0,0) \to (1,2) \to (3,3)</var> and <var>(0,0) \to (2,1) \to (3,3)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>The knight cannot reach <var>(2,2)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>999999 999999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>151840682
</pre>
<p>Print the number of ways modulo <var>10^9 + 7</var>.</p></section>
</div>
</span> |
p02161 | <h1>Problem M: 1333</h1>
<h2>Problem</h2>
<p>
é·ã$N$ã®æåå$S$ãäžããããã
以äžã®ã¯ãšãªã$Q$ååŠçããã<br>
<br>ã¯ãšãª<br>
$S[L: R]$ã$S$ã®$L$æåç®ãã$R$æåç®ãŸã§ïŒäž¡ç«¯ãå«ãïŒãããªãæååãšããã<br>
$ S[L: R] $ãé©åœãªæåå$A,B,C,X$ãçšããŠ$AXBXCX(1 \leq |A|,|B|,|C|,|X|)$ ãšè¡šãããšãèãããã®ãããª$X$ã®äžã§æé·ã®ãã®ã®é·ããåºåããã<br>
ãã ãããã®ãããª$X$ãååšããªãå Žåã¯ä»£ããã«0ãåºåããã<br>
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
$N$ $Q$
$S$
$L_1$ $R_1$
$L_2$ $R_2$
$\vdots$
$L_Q$ $R_Q$
</pre>
<p>
$N,Q,L,R$ã¯ãã¹ãп޿°ã§äžããããã<br>
1è¡ç®ã«$N$, $Q$ã空çœåºåãã§äžããããã<br>
2è¡ç®ã«æåå$S$ãäžããããã<br>
2+$i(1\leq i \leq Q)$è¡ç®ã«$L_i$, $R_i$ã空çœåºåãã§äžããããããããã¯$i$çªç®ã®ã¯ãšãªã«ããã$L,R$ã衚ãã<br>
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>$1 \leq N, Q\leq 2 \times 10^5 $</li>
<li>$S$ã®åæåã¯å°æåã¢ã«ãã¡ããããããªã</li>
<li>$1 \leq L_i \leq R_i \leq N $</li>
</ul>
<h2>Output</h2>
<p>
åã¯ãšãªã«ã€ããŠãæé·ã®$X$ã®é·ããäžè¡ã«åºåããã<br>
</p>
<h2>Sample Input 1</h2>
<pre>
12 3
itisansansan
1 12
5 12
6 7
</pre>
<h2>Sample Output 1</h2>
<pre>
2
1
0
</pre>
<p>
äžã€ç®ã®ã¯ãšãªã«ãããŠã$A=itis, B=s, C=s, X=an$ãšãããšã$S[1:12]=AXBXCX$ãšãªãã
</p>
<h2>Sample Input 2</h2>
<pre>
20 2
sensanbyakusanjuusan
1 20
1 14
</pre>
<h2>Sample Output 2</h2>
<pre>
3
1
</pre>
<h2>Sample Input 3</h2>
<pre>
21 6
aaaabaaaabaaaaaaaaaab
1 21
10 21
10 18
4 16
11 21
1 6
</pre>
<h2>Sample Output 3</h2>
<pre>
4
0
2
2
0
1
</pre>
|
p00633 |
<H1><font color="#000000">Problem 07:</font> Crop Circle</H1>
<p>
ã¢ã«ãŒã³ãã³ã®åºå€§ãªèŸ²å°ã«çªåŠãã¹ããªãŒãµãŒã¯ã«ãåºæ²¡ããããã¹ããªãŒãµãŒã¯ã«ã¯éãªã£ãŠãããã®ãããã³ãšãããã®ã倧ãããã®ãå°ãããã®ãšåèš <i>n</i> å確èªãããã
</p>
<p>
ãããã¹ããªãŒãã³ã¿ãŒã空äžãããã¹ããªãŒãµãŒã¯ã«ã®å
šäœåãæ®åœ±ããããšè©Šã¿ããšãããååã®èŒªéãã¯ã£ããããŠããªãã£ããããæ åã«ãã®çŸããæš¡æ§ãæ ãåºãããšãé£ããããšãåãã£ãã
</p>
<p>
ããã§ããã®ãã¹ããªãŒãã³ã¿ãŒã¯èŒªéã«æ²¿ã£ãŠç¹æ®çŽ æã®çŽãèšçœ®ãã茪éã匷調ããææ¡ãããã
</p>
<p>
çŽãèšçœ®ããéšåã¯ããããã¹ããªãŒãµãŒã¯ã«ã®ååšäžã§ãä»ã®ã©ã®ãã¹ããªãŒãµãŒã¯ã«ã«ãå«ãŸããªãéšåã§ããã
</p>
<p>
æ®åœ±éã¯å¿
èŠãªçŽã®é·ããèšæž¬ããããã«ãããã°ã©ã ã®äœæãããªãã«äŸé Œãããåãã¹ããªãŒãµãŒã¯ã«ã®äžå¿åº§æšãšååŸãå
¥åããèšçœ®ããçŽã®é·ããå ±åããããã°ã©ã ãäœæããã
</p>
<p>
åèãšããŠå
¥åºåäŸã®ïŒã€ç®ãšïŒã€ç®ã®ã±ãŒã¹ãããããå³ïŒãå³ïŒã«ç€ºããçŽã®éšåã倪ãç·ã§ç€ºãããŠããã
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cropCircle"><br>
<p>å³ïŒ</p>
</center>
<br>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cropCircle2"><br>
<p>å³ïŒ</p>
</center>
<br>
<H2>Input</H2>
<p>
å
¥åãšããŠè€æ°ã®ããŒã¿ã»ãããäžãããããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ<br>
<br>
<i>n</i>ãïŒãã¹ããªãŒãµãŒã¯ã«ã®æ°ïŒæŽæ°ïŒ<br>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>r</i><sub>1</sub> ãïŒ1 åç®ã®ãµãŒã¯ã«ã®äžå¿åº§æšãšååŸïŒç©ºçœåºåãã®å®æ°ïŒ<br>
<i>x</i><sub>2</sub> <i>y</i><sub>2</sub> <i>r</i><sub>2</sub> ãïŒ2 åç®ã®ãµãŒã¯ã«ã®äžå¿åº§æšãšååŸïŒç©ºçœåºåãã®å®æ°ïŒ<br>
.<br>
.<br>
<i>x</i><sub><i>n</i></sub> <i>y</i><sub><i>n</i></sub> <i>r</i><sub><i>n</i></sub> ãïŒ<i>n</i> åç®ã®ãµãŒã¯ã«ã®äžå¿åº§æšãšååŸïŒç©ºçœåºåãã®å®æ°ïŒ<br>
</p>
<!--
<p>
<i>n</i> 㯠100 以äžã<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> 㯠-1000 ä»¥äž 1000 以äžã§ããã
</p>
-->
<p>
<i>n</i> ã 0 ã®ãšããå
¥åã®çµããã瀺ãã
</p>
<H2>Output</H2>
<p>
åããŒã¿ã»ããã«å¯ŸããŠãçŽã®é·ããïŒè¡ã«åºåãããåºå㯠0.000001 以äžã®èª€å·®ãå«ãã§ãããã
</p>
<h2>Constraints</h2>
<ul>
<li><i>n</i> ≤ 100</li>
<li>-1000 ≤ <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> ≤ 1000</li>
<li>0 < <i>r<sub>i</sub></i> ≤ 100</li>
</ul>
<H2>Sample Input</H2>
<pre>
4
6 4 2
4 7 3
7 10 3
13 6 1
4
7 4 2
4 7 3
7 10 3
11 6 3
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
39.664699289572
45.627024663706
</pre>
|
p01921 |
<link rel="stylesheet" href="css/description.css" type="text/css" />
<script language="JavaScript" type="text/javascript" src="js/varmath2017.js" charset="UTF-8"></script>
<h2>F: æšãé ãã®ãªã森ã®äž</h2>
<h3>ç©èª</h3>
<p>
ãæšã¯ããã§ãã
å«è¶åºãã¿ãŒãã«ããŠã¹ããçµå¶ãããã³ã¡ããã¯ãæšã«äžŠã
ãªãã¬ææ
ãæã£ãŠããããªãã§ããæšã®äžåã®ããæ¹ã«å¿ãæŽããããããããããããªãã³ã¡ããã®æšãžã®ææ
ã確ããããããåãå«è¶åºã§ãã€ããããŠããã³ã³ãã¡ããã¯ãã³ã¡ããã«ããããã仿ããããšã«ããã
</p>
<p>ã³ã³ãã¡ããã¯ããã³ã¡ããã®ããã«æ£®ãçšæããŠãå«è¶åºè¿ãã«çããŠããæšãäœæ¬ã森ã®äžã«é ãããã³ã¡ããã®æšãžã®ææ
ã詊ãããšã«ãããå
·äœçã«ã¯ããã³ã¡ããã«ãé ããæšãæ£®ã®äžããèŠã€ããŠãããããšã«ãããæšããããªãæãããã³ã¡ãããªããäžåºŠèŠãããšãããæšã¯ãå¿ã®æŽããæ¹ã®éãã§ãããã®ã ããæšãç§»åããŠããŸã£ããããæšã®äžåã®ããæ¹ãå€ãã£ãŠããŸããã©ã®æšãå«è¶åºè¿ãã«ãã£ãæšãããããªããªã£ãŠããŸã£ããããããããžãªã³ã³ãã¡ãããçãã®æšãã©ããå¿ããŠããŸã£ãïŒãã®ãŸãŸã§ã¯çãã®æšãå
ã®å Žæã«æ»ããªãã®ã§ãã³ã³ãã¡ããããã³ã¡ããã«æãããŠããŸããããã§ãåªããããã°ã©ããŒã®çããã§ã³ã³ãã¡ããã«çãã®æšãäœæ¬ããã®ãæããŠãããããã°ã©ã ãæžããŠããããã</p>
<h3>åé¡</h3>
<p>å
¥åãšããŠã2ã€ã®ã°ã©ã<var>G_1</var>ãš<var>G_2</var>ãäžããããã<var>G_1</var>ã¯æ£®ãã€ãŸãéè·¯ã®ãªãã°ã©ãïŒé£çµãšã¯éããªãïŒã§ã<var>G_2</var>ã¯æšãã€ãŸãéè·¯ã®ãªãé£çµãªã°ã©ãã§ããããã®ãšãã<var>G_1</var>ã<var>G_2</var>ãšååãªé£çµæåãããã€æã€ã®ããæ±ãã</p>
<p>泚1ïŒã°ã©ã<var>G_1</var>ã®ããé£çµæå<var>H_1</var>ã«å«ãŸããä»»æã®2é ç¹<var>u, v</var>ã«å¯ŸããŠã<var>u, v</var>ã飿¥ããå Žåã«ã®ã¿ã<var>G_2</var>äžã®2é ç¹<var>f(u), f(v)</var>ã飿¥ãããããªå
šåå°<var>f</var>ãååšãããšãã<var>H_1</var>ã¯ã<var>G_2</var>ãšååãª<var>G_1</var>ã®é£çµæåã§ãããšããã</p>
<h3>å
¥å</h3>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
<var>N_1</var> <var>M_1</var>
<var>u_1</var> <var>v_1</var>
<var>...</var>
<var>u_{M_1}</var> <var>v_{M_1}</var>
<var>N_2</var>
<var>w_1</var> <var>x_1</var>
<var>...</var>
<var>w_{N_2 - 1}</var> <var>x_{N_2 - 1}</var>
</pre>
<p>1è¡ç®ã§ã¯ã森<var>G_1</var>ã®é ç¹æ°<var>N_1ïŒ1 \leq N_1 \leq 300,000ïŒ</var>ãšèŸºæ°<var>M_1ïŒ0 \leq M_1 \leq N_1 - 1ïŒ</var>ãäžãããããç¶ã<var>M_1</var>è¡ã§ã¯ã<var>i</var>è¡ç®ã§<var>G_1</var>ã®<var>i</var>çªç®ã®èŸº<var>e_i</var>ãäžãããã<var>(1 \leq i \leq M_1)</var>ã<var>e_i</var>ã¯2é ç¹<var>u_i</var>ãš<var>v_i</var>ãã€ãªã蟺ã§ããã<var>ïŒ1 \leq u_i, v_i \leq N_1, u_i \neq v_iïŒ</var>次ã®è¡ã«ã¯æš<var>G_2</var>ã®é ç¹æ°<var>N_2ïŒ1 \leq N_2 \leq 30,000ïŒ</var>ãäžãããããç¶ã<var>N_2 - 1</var>è¡ã§ã¯ã<var>j</var>è¡ç®ã§<var>G_2</var>ã®<var>j</var>çªç®ã®èŸº<var>e_j</var>ãäžãããã<var>(1 \leq j \leq N_2 - 1)</var>ã<var>e_j</var>ã¯2é ç¹<var>w_j</var>ãš<var>x_j</var>ãã€ãªã蟺ã§ããã<var>ïŒ1 \leq w_j, x_j \leq N_2, w_j \neq x_jïŒ</var></p>
<h3>åºå</h3>
<p><var>G_1</var>ã®æã€<var>G_2</var>ãšååãªé£çµæåã®æ°ãåºåããã</p>
<h3>å
¥åäŸ1</h3>
<pre>
6 4
1 2
2 3
2 4
5 6
4
2 3
3 1
3 4
</pre>
<h3>åºåäŸ1</h3>
<pre>1</pre>
<h3>å
¥åäŸ2</h3>
<pre>
14 9
5 8
5 11
10 14
6 4
13 9
3 14
1 2
6 12
7 9
3
3 1
2 1
</pre>
<h3>åºåäŸ2</h3>
<pre>4</pre> |
p00263 |
<H1>éåã®å</H1>
<p>
以äžã®ããã«ãå³ãã 7 ãããåãå°æ°éšãç¶ã24 ãããåãæŽæ°éšã§ãäžçªå·Šã® 1 ãããåã笊å·éšãšãã 32 ããã宿°åãèãã(b<sub>1</sub>, ... , b<sub>32</sub> 㯠0 ã1 ã衚ãïŒã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_kongoType1" width="780">
</center><br/>
<p>
ãã®åœ¢åŒãã人ãçè§£ãããã 10 鲿°è¡šçŸã«çŽããšãã¯ã以äžã®ããã«è§£éããã<br/>
(-1)<sup>笊å·éš</sup> × (æŽæ°éš + å°æ°éš)
</p>
<p>
äžã®è¡šçŸã§ãæŽæ°éšã®å€ã¯ b<sub>8</sub> ïŒ 2<sup>1</sup>×b<sub>9</sub> ïŒ 2<sup>2</sup>×b<sub>10</sub>ïŒ ... ïŒ 2<sup>23</sup>×b<sub>31</sub> ã«ãªããäŸãã°æŽæ°éšã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_kongoType2">
</center><br/>
<p>
ã®ããã«ãªã£ãŠããå ŽåãæŽæ°éšã®å€ã¯ä»¥äžã®ããã«èšç®ãããã<br/>
1 + 2<sup>1</sup> + 2<sup>3</sup> = 1 + 2 + 8 = 11
</p>
<p>
äžæ¹ãå°æ°éšã®å€ã¯(0.5)<sup>1</sup>×b<sub>7</sub>ïŒ(0.5)<sup>2</sup>×b<sub>6</sub> ïŒ ... ïŒ (0.5)<sup>7</sup> × b<sub>1</sub> ã«ãªããäŸãã°å°æ°éšã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_kongoType3">
</center><br/>
<p>
ã®ããã«ãªã£ãŠããå Žåãå°æ°éšã¯ä»¥äžã®ããã«èšç®ãããã<br/>
0.5<sup>1</sup> + 0.5<sup>3</sup> = 0.5 + 0.125 = 0.625
</p>
<p>
ããã«ã笊å·éšãæŽæ°éšãå°æ°éšãåããã以äžã®ãããªãããåã®å Žåã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_kongoType4" width="780">
</center><br/>
<p>
ãããåå
šäœã衚ã10 鲿°ã¯ã以äžã®ããã«ãªã(ãã ãã-1 ã®0 ä¹ã¯1)ã<br/>
(-1)<sup>0</sup> × (1 + 2 + 8 + 0.5 + 0.125) = 1 × (11.625) = 11.625<br/>
</p>
<p>
32 ãããã®ãããåã Q åå
¥åãããšããããã®ãããåã衚ã宿°ã®10 é²è¡šèšãäžåã®èª€å·®ç¡ãåº
åããããã°ã©ã ãäœæããŠãã ããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ïŒã€ã®ããŒã¿ã»ãããããªããå
¥åããŒã¿ã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
Q
s<sub>1</sub>
s<sub>2</sub>
.
.
.
s<sub>Q</sub>
</pre>
<p>
1 è¡ç®ã«ãããåã®æ° Q (1 ≤ Q ≤ 10000)ãäžãããããç¶ãQ è¡ã«å
¥åãããå s<sub>i</sub> ãäžããããã å
¥åãããå㯠16 鲿°è¡šèšã§äžãããããšãã (äŸ: 0111 1111 1000 1000 0000 0000 0000 0000 㯠7f880000 ãšäžãããã) ãã€ãŸããQ è¡ã®ããããã«ã¯ã2 鲿°ã 4 ãããåãã€ãŸãšãã 16 鲿°ã 8 åã空çœãã¯ããŸãã«äžŠãã§ããã10 鲿°ã2 鲿°ã16 鲿°ã®å¯Ÿå¿ã¯ä»¥äžã®è¡šã®ãšããã§ããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_kongoType5" width="780">
</center><br/>
<p>
16 鲿°ã®è±å a ãã f ãŸã§ã¯å°æåã§äžããããã
</p>
<h2>åºå</h2>
<p>
åãããåã衚ã宿°ã® 10 é²è¡šèšã 1 è¡ãã€åºåããããã ããå°æ°éšã«ãããŠãããæ¡ä»¥äžããã¹ãŠ 0 ã®å Žåããã®æ¡ä»¥äžã¯çç¥ãããã®ãšããããäŸå€ãšããŠå°æ°éšã 0 ã®å Žåã¯å°æ°éšã«ã¯ 0 ã²ãšã€ãåºåããã
</p>
<h2>å
¥åäŸ</h2>
<pre>
8
00000000
80000000
00000080
00000040
000000c0
00000100
80000780
80000f70
</pre>
<h2>åºåäŸ</h2>
<pre>
0.0
-0.0
1.0
0.5
1.5
2.0
-15.0
-30.875
</pre> |
p00799 |
<H1><font color="#000">Problem D:</font> Pump up Batteries</H1>
<p>
Bill is a boss of security guards. He has pride in that his men put on wearable computers on their
duty. At the same time, it is his headache that capacities of commercially available batteries are
far too small to support those computers all day long. His men come back to the office to charge
up their batteries and spend idle time until its completion. Bill has only one battery charger in
the office because it is very expensive.
</p>
<p>
Bill suspects that his men spend much idle time waiting in a queue for the charger. If it is the
case, Bill had better introduce another charger. Bill knows that his men are honest in some
sense and blindly follow any given instructions or rules. Such a simple-minded way of life may
lead to longer waiting time, but they cannot change their behavioral pattern.
</p>
<p>
Each battery has a data sheet attached on it that indicates the best pattern of charging and
consuming cycle. The pattern is given as a sequence of pairs of consuming time and charging
time. The data sheet says the pattern should be followed cyclically to keep the battery in quality.
A guard, trying to follow the suggested cycle strictly, will come back to the office exactly when
the consuming time passes out, stay there until the battery has been charged for the exact time
period indicated, and then go back to his beat.
</p>
<p>
The guards are quite punctual. They spend not a second more in the office than the time
necessary for charging up their batteries. They will wait in a queue, however, if the charger is
occupied by another guard, exactly on first-come-first-served basis. When two or more guards
come back to the office at the same instance of time, they line up in the order of their identifi-
cation numbers, and, each of them, one by one in the order of that line, judges if he can use the
charger and, if not, goes into the queue. They do these actions in an instant.
</p>
<p>
Your mission is to write a program that simulates those situations like Billâs and reports how
much time is wasted in waiting for the charger.
</p>
<H2>Input</H2>
<p>
The input consists of one or more data sets for simulation.
</p>
<p>
The first line of a data set consists of two positive integers separated by a space character: the
number of guards and the simulation duration. The number of guards does not exceed one
hundred. The guards have their identification numbers starting from one up to the number of
guards. The simulation duration is measured in minutes, and is at most one week, i.e., 10080
(min.).
</p>
<p>
Patterns for batteries possessed by the guards follow the first line. For each guard, in the order
of identification number, appears the pattern indicated on the data sheet attached to his battery.
A pattern is a sequence of positive integers, whose length is a multiple of two and does not exceed
fifty. The numbers in the sequence show consuming time and charging time alternately. Those
times are also given in minutes and are at most one day, i.e., 1440 (min.). A space character or
a newline follows each number. A pattern is terminated with an additional zero followed by a
newline.
</p>
<p>
Each data set is terminated with an additional empty line. The input is terminated with an
additional line that contains two zeros separated by a space character.
</p>
<H2>Output</H2>
<p>
For each data set your program should simulate up to the given duration. Each guard should
repeat consuming of his battery (i.e., being on his beat) and charging of his battery according
to the given pattern cyclically. At the beginning, all the guards start their cycle simultaneously,
that is, they start their beats and, thus, start their first consuming period.
</p>
<p>
For each data set, your program should produce one line containing the total wait time of the
guards in the queue up to the time when the simulation duration runs out. The output should
not contain any other characters.
</p>
<p>
For example, consider a data set:
</p>
<pre>
3 25
3 1 2 1 4 1 0
1 1 0
2 1 3 2 0
</pre>
<p>
The guard 1 tries to repeat 3 min. consuming, 1 min. charging, 2 min. consuming, 1 min.
charging, 4 min. consuming, and 1 min. charging, cyclically. Yet he has to wait sometimes to
use the charger, when he is on his duty together with the other guards 2 and 3. Thus, the actual
behavior of the guards looks like:
</p>
<pre>
0 10 20
| | | | | |
guard 1: ***.**.****.***.**-.****.
guard 2: *.*-.*-.*-.*.*.*.*--.*.*-
guard 3: **.***--..**-.***..**.***
</pre>
<p>
where â*â represents a minute spent for consuming, â.â for charging, and â-â for waiting in the
queue. At time 3, the guards 1 and 2 came back to the office and the guard 1 started charging
while the guard 2 went into the queue. At time 6, all the guards came back to the office and the
guard 1 started charging while the others went to the queue. When the charger got available
at time 7, the guard 2 started charging, leaving the guard 3 in the queue. All those happened are consequences of rules stated above. And the total time wasted in waiting for the charger
becomes 10 minutes.
</p>
<H2>Sample Input</H2>
<pre>
3 25
3 1 2 1 4 1 0
1 1 0
2 1 3 2 0
4 1000
80 20 80 20 80 20 80 20 0
80
20
0
80 20 90
10 80
20
0
90 10
0
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
10
110
</pre>
|
p01022 | <h1>Problem G: Yu-kun Likes Building Block</h1>
<h2>Background</h2>
<p>
äŒæŽ¥å€§åŠä»å±å¹Œçšåã¯ããã°ã©ãã³ã°ã倧奜ããªåäŸãéãŸã幌çšåã§ãããåå
ã®äžäººã§ããããåã¯ããã°ã©ãã³ã°ãšåããããé·æ¹åœ¢ã®ç©ã¿æšã倧奜ãã ã
ãããªããåã¯ãæè¿ç©ã¿æšã§å±±ãäœãéã³ã«ç±äžããŠããã
</p>
<p>
仿¥ãããåã¯å±±ãäœã£ãŠéãã§ããã®ã ããæã£ãŠããç©ã¿æšã§æ²¢å±±ã®å±±ãäœãäºã¯ç°¡åãªã®ã§ã仿¥ã¯å
šãŠã®ç©ã¿æšã䜿ã£ãŠåºæ¥ãå±±ã®æ°ãæå°åããããšèããã
ããã§ããåã¯ãå®éã«å
šãŠã®ç©ã¿æšã䜿ã£ãŠå±±ãäœã£ãåŸãæ¬åœã«ãã®å±±ã®æ°ãæå°ã«ãªã£ãŠããã®ãã©ããã確ãããããã«ãããã°ã©ã ãæžãäºã«ããã
</p>
<h2>Problem</h2>
<p>
ããåãæã£ãŠããç©ã¿æšã®æ°ãšç©ã¿æšã®æ
å ±ãäžããããã®ã§ãããããäœãäºã®ã§ããå±±ã®æ°ã®æå°å€ãæ±ããã
</p>
<p>
ç©ã¿æšã¯å¹³é¢äžã®é·æ¹åœ¢ãšããŠè¡šããããã®é·æ¹åœ¢ã®çžŠãšæšªã®é·ããç©ã¿æšã®æ
å ±ãšããŠäžãããã ( ç©ã¿æšã®é«ãã¯èæ
®ããªã )ã
</p>
<p>
å±±ã¯ç©ã¿æšã®äžã«ïŒå以äžã®ç©ã¿æšãç©ã¿éãªã£ããã®ã§ããã
ãã ããç©ã¿æšã®äžã«å¥ã®ç©ã¿æšãéããããã«ã¯ãäžã«ãªãç©ã¿æšã®çžŠã暪ã®é·ãã¯ããããäžãšãªãç©ã¿æšã®çžŠã暪ã®é·ãæªæºã§ãªããã°ãªããªãã
ïŒã€ã®ç©ã¿æšã®äžã«çŽæ¥çœ®ãããšãã§ããç©ã¿æšã¯1ã€ãŸã§ã§ããã
</p>
<p>
ç©ã¿æšã眮ãéã«ã2ã€ã®ç©ã¿æšã®çžŠã暪ã¯ããããå¹³è¡ã§ãªããã°ãªããªãïŒæãã®ç¶æ
ã§éããããšã¯èš±ãããªãïŒã
ç©ã¿æšãå転ããçžŠãšæšªã亀æããŠãè¯ãã
</p>
<p>
äŸãã°ãå³1ã®ãããªç¶æ
ã«ã€ããŠèãããé·æ¹åœ¢ã¯ç©ã¿æšã衚ãããã®å·Šã«ããæ°åã¯ç©ã¿æšã®çžŠã®é·ãããäžã«ããæ°åã¯æšªã®é·ãããé·æ¹åœ¢ã®äžã®å·Šäžã®æ°åã¯ç©ã¿æšã®çªå·ã衚ããŠããã
æåã®ç¶æ
ã§ã¯ïŒã€ã®å±±ãããã
</p>
<p>
å³1ã®ããã«éããŠããäºã§ãæçµçã«å±±ã®æ°ãïŒã€ãŸã§æžããããšãã§ããã
</p>
<br>
<center>
<img width="680" src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RitsCamp14Day2_pileStone.png" alt="å³ïŒ"><br>
å³1
</center>
<br>
<h2>Input</h2>
<pre>
<var>N</var>
<var>w<sub>0</sub></var> <var>h<sub>0</sub></var>
<var>w<sub>1</sub></var> <var>h<sub>1</sub></var>
...
<var>w<sub>N-1</sub></var> <var>h<sub>N-1</sub></var>
</pre>
<p>å
¥åã¯å
šãп޿°ã§ããã</p>
<p><var>N</var>ã¯ç©ã¿æšã®æ°ã衚ãã ( 1 ≤ <var>N</var> ≤ 100 )</p>
<p><var>w<sub>i</sub></var>,<var>h<sub>i</sub></var>ã¯ããããç©ã¿æšã®æšªã瞊ã®é·ãã衚ãã( 1 ≤ <var>w<sub>i</sub></var>,<var>h<sub>i</sub></var> ≤ 10<sup>9</sup> )</p>
<h2>Output</h2>
<p>å
šãŠã®ç©ã¿æšã䜿ã£ãŠã§ããå±±ã®æ°ã®æå°å€ãïŒè¡ã«åºåããã</p>
<h2>Sample Input 1</h2>
<pre>
3
1 1
2 2
3 3
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<h2>Sample Input 2</h2>
<pre>
5
2 3
3 5
1 2
1 4
3 5
</pre>
<h2>Sample Output 2</h2>
<pre>
2
</pre>
<h2>Sample Input 3</h2>
<pre>
5
1 5
2 4
3 3
4 2
5 1
</pre>
<h2>Sample Output 3</h2>
<pre>
5
</pre>
<h2>Sample Input 4</h2>
<pre>
10
5 11
12 12
4 14
22 12
11 13
3 3
3 3
12 5
55 55
1 1
</pre>
<h2>Sample Output 4</h2>
<pre>
3
</pre>
|
p01472 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<h2>å顿</h2>
<p>ãµããã®ãã¬ã€ã€ãŒãã²ãŒã ãããŠããã以äžãã²ãŒã ã®ã«ãŒã«ã説æããã</p>
<p>$NÃN$ ãã¹ã®ããŒãããããåãã¹ã«ã¯æ°å $X_{i,j}$ ($1 \leq i,j \leq N$)ãæžãããŠãããå
æãšåŸæã¯äº€äºã«æãéžãã§ç¹ãç©ã¿éããŠãããæåã«å
æã¯ $F$ ç¹æã£ãŠãããåŸæã¯ $0$ ç¹æã£ãŠããã</p>
<p>$t$ ã¿ãŒã³ç®($1 \leq t \leq 2N$)ã®ãã¬ã€ã€ãŒã®è¡åã瀺ãã</p>
<ol><li>ãã以éèªåãšçžæãã©ã®ãããªæãéžãã ãšããŠãèªåãè² ããŠããŸãå Žåãå³åº§ã«è² ãã宣èšããŠã²ãŒã ãçµäºããã</li>
<li>ãããŸã§ã«èªåãäžåºŠãéžãã ããšã®ãªãæ°åã $1,2,...,N$ ããäžã€éžãã§ $Y_t$ ãšããã
<ol><li>å
æã®æçª(ã€ãŸã $t$ ã奿°)ã〠$t>1$ ã®ãšããå
æã¯ $X_{Y_{t}, Y_{t-1}}$ ç¹ãåŸãã $t=1$ ã®ãšããå
æã®åŸç¹ã«å€åã¯èµ·ããªãã</li>
<li>åŸæã®æçª(ã€ãŸã $t$ ãå¶æ°)ã®ãšããåŸæã¯ $X_{Y_{t-1}, Y_{t}}$ ç¹ãåŸãã</li></ol></li>
<li>$t=2N$ ã®ãšããåæå€å®ãè¡ãã²ãŒã ãçµäºãããç¹ãå€ãç²åŸããŠãããã¬ã€ã€ãŒã®åã¡ã§ãç¹ãåãå Žåã¯åŒãåããšããã</li>
<li>ã¿ãŒã³ãçµäºããŠçžæã«æçªãæž¡ãã</li></ol>
<p>å
æãšåŸæã¯ä»¥äžã®åºæºã§æãéžã¶ã</p>
<ol><li>èªåãåã¡ã«ãªãæãååšãããšãã¯ãã®æãéžã¶ãèªåãåã¡ã«ãªãæãè€æ°ååšãããšãã¯ãã®äžããã²ãŒã ãæçã§çµäºãããããªæãéžã¶ã</li>
<li>èªåãåã¡ã«ãªãæãååšããªããšããåŒãåãã«ãªãæãååšããã°ãã®æãéžã¶ã</li>
<li>èªåãè² ãã«ãªãæããååšããªããšããã²ãŒã ãæé·ã§çµäºãããããªæãéžã¶ã</li></ol>
<p>å
æãšåŸæããã®ãããªåºæºã§æãéžãã ãšããã²ãŒã ã®çµæãšã²ãŒã ãäœã¿ãŒã³ã§çµäºããããæ±ããã</p>
<h2>å
¥å</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã«åŸããäžããããæ°ã¯å
šãп޿°ã§ããã</p>
<pre>$N$ $F$
$X_{1,1}$ $X_{1,2}$ $...$ $X_{1,N}$
$X_{2,1}$ $X_{2,2}$ $...$ $X_{2,N}$
$...$
$X_{N,1}$ $X_{N,2}$ $...$ $X_{N,N}$</pre>
<h2>å¶çŽ</h2>
<ul><li>$1 \leq N \leq 8$</li>
<li>$-10^5 \leq F \leq 10^5$</li>
<li>$-10^5 \leq X_{i,j} \leq 10^5$</li></ul>
<h2>åºå</h2>
<p>å
æãåã€å Žåã¯"First"ãåŸæãåã€å Žåã¯"Second"ãåŒãåãã«ãªãå Žåã¯"Draw"ãš1è¡ç®ã«åºåããã
2è¡ç®ã«ã²ãŒã ãçµäºããã®ãäœã¿ãŒã³ç®ã«ãªãã®ããåºåããã</p>
<h2>Sample Input 1</h2>
<pre>2 0
1 3
1 1</pre>
<h2>Output for the Sample Input 1</h2>
<pre>Second
3</pre>
<h2>Sample Input 2</h2>
<pre>2 100
0 0
0 0</pre>
<h2>Output for the Sample Input 2</h2>
<pre>First
2</pre>
<h2>Sample Input 3</h2>
<pre>2 5
3 4
7 6</pre>
<h2>Output for the Sample Input 3</h2>
<pre>Draw
4</pre>
<p>äž¡è
ãæåãå°œãããå Žå $(Y_1,Y_2,Y_3,Y_4) = (1,2,2,1)$ ãšãªãããã®ãšãäž¡è
11ç¹ãç²åŸããŠåŒãåãã«ãªãã</p>
|
p01188 |
<H1><font color="#000">Problem H:</font> Slippy Floors</H1>
<p>
The princess of the Fancy Kingdom has been loved by many people for her lovely face. However the
witch of the Snow World has been jealous of the princess being loved. For her jealousy, the witch has
shut the princess into the Ice Tower built by the witchâs extreme magical power.
</p>
<p>
As the Ice Tower is made of cubic ice blocks that stick hardly, the tower can be regarded to be composed
of <i>levels</i> each of which is represented by a 2D grid map. The only way for the princess to escape from the
tower is to reach downward stairs on every level. However, many magical traps set by the witch obstruct
her moving ways. In addition, because of being made of ice, the floor is so slippy that movement of the
princess is very restricted. To be precise, the princess can only press on one adjacent wall to move against
the wall as the reaction. She is only allowed to move in the vertical or horizontal direction, not in the
diagonal direction. Moreover, she is forced to keep moving without changing the direction until she is
prevented from further moving by the wall, or she reaches a stairway or a magical trap. She must avoid
the traps by any means because her being caught by any of these traps implies her immediate death by
its magic. These restriction on her movement makes her escape from the tower impossible, so she would
be frozen to death without any help.
</p>
<p>
You are a servant of the witch of the Snow World, but unlike the witch you love the princess as many other
people do. So you decided to help her with her escape. However, if you would go help her directly in the
Ice Tower, the witch would notice your act to cause your immediate death along with her. Considering
this matter and your ability, all you can do for her is to generate <i>snowmans</i> at arbitrary places (grid
cells) neither occupied by the traps nor specified as the cell where the princess is initially placed. These
snowmans are equivalent to walls, thus the princess may utilize them for her escape. On the other hand,
your magical power is limited, so you should generate the least number of snowmans needed for her
escape.
</p>
<p>
You are required to write a program that solves placement of snowmans for given a map on each level,
such that the number of generated snowmans are minimized.
</p>
<H2>Input</H2>
<p>
The first line of the input contains a single integer that represents the number of levels in the Ice Tower.
Each level is given by a line containing two integers <i>NY</i> (3 ≤ <i>NY</i> ≤ 30) and <i>NX</i> (3 ≤ <i>NX</i> ≤ 30) that
indicate the vertical and horizontal sizes of the grid map respectively, and following <i>NY</i> lines that specify
the grid map. Each of the <i>NY</i> lines contain <i>NX</i> characters, where âAâ represents the initial place of the
princess, â>â the downward stairs, â.â a place outside the tower, â_â an ordinary floor, â#â a wall, and â^â a
magical trap. Every map has exactly one âAâ and one â>â.
</p>
<p>
You may assume that there is no way of the princess moving to places outside the tower or beyond the
maps, and every case can be solved with not more than ten snowmans. The judge also guarantees that
this problem can be solved without extraordinary optimizations.
</p>
<H2>Output</H2>
<p>
For each level, print on a line the least number of snowmans required to be generated for letting the
princess get to the downward stairs.
</p>
<H2>Sample Input</H2>
<pre>
3
10 30
......#############...........
....##_____________#..........
...#________________####......
..#________####_________#.....
.#________#....##________#....
#_________#......#________#...
#__________###...#_____^^_#...
.#__________A_#...#____^^_#...
..#___________#...#_>__###....
...###########.....####.......
7 17
......#..........
.....#_##........
.#...#_A_#.......
#^####___#.......
#_______#........
#>_____#.........
########.........
6 5
#####
#_A_#
#___#
#_>_#
#___#
#####
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
1
0
</pre>
|
p01167 |
<H1><font color="#000">Problem E:</font> Alice in Foxland</H1>
<p>
<i>
- The world is made of foxes; people with watchful eyes will find foxes in every
fragment of the world.
</i>
</p>
<p>
</i>Defoxyrenardnucleic Acids</i> (or DNAs for short) and <i>Renardnucleic Acids</i> (or RNAs) are similar
organic molecules contained in organisms. Each of those molecules consists of a sequence of 26
kinds of nucleobases. We can represent such sequences as strings by having each lowercase letter
from âaâ to âzâ denote one kind of nucleobase. The only difference between DNAs and RNAs is
the way of those nucleobases being bonded.
</p>
<p>
In the year of 2323, Prof. Fuchs discovered that DNAs including particular substrings act as
catalysts, that is, accelerate some chemical reactions. He further discovered that the reactions
are accelerated as the DNAs have longer sequences. For example, DNAs including the sequence
âfoxâ act as catalysts that accelerate dissolution of nitrogen oxides (NOx ). The DNAs âredfoxâ
and âcutefoxesâ are two of the instances, and the latter provides more acceleration than the
former. On the other hand, the DNA âfooooxâ will <i>not</i> be such a catalyst, since it does not
include âfoxâ as a <i>substring</i>.
</p>
<p>
DNAs can be easily obtained by extraction from some plants such as glory lilies. However,
almost all of extracted molecules have different sequences each other, and we can obtain very
few molecules that act as catalysts. From this background, many scientists have worked for
finding a way to obtain the demanded molecules.
</p>
<p>
In the year of 2369, Prof. Hu finally discovered the following process:
</p>
<ol>
<li> Prepare two DNAs <i>X</i> and <i>Y</i> .</li>
<li> Generate RNAs <i>X'</i> and <i>Y'</i> with their sequences copied from the DNAs <i>X</i> and <i>Y</i> respectively.</li>
<li> Delete zero or more bases from <i>X'</i> using some chemicals to obtain an RNA <i>X''</i>.</li>
<li> Also delete zero or more bases from <i>Y'</i> to obtain an RNA <i>Y''</i> , which has the same sequence
as <i>X''</i> .</li>
<li> Obtain a resulting DNA <i>Z</i> from the two RNAs <i>X''</i> and <i>Y''</i>
same sequence as <i>X''</i> and <i>Y''</i>.</li>
</ol>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_aliceInFoxland">
<p>Figure 1: New Method for Generation of DNAs</p>
</center>
<p>
The point is use of RNAs. It is difficult to delete specific bases on DNAs but relatively easy on
RNAs. On the other hand, since RNAs are less stable than DNAs, there is no known way to
obtain RNAs directly from some organisms. This is why we obtain RNAs from DNAs.
</p>
<p>
Alice is a researcher in Tail Environmental Natural Catalyst Organization. She is now requested
to generate DNAs with particular substrings, applying Huâs method to some pairs of DNAs.
Since longer DNAs are preferred, she wants a means of knowing the longest possible DNAs. So
she asked you for help.
</p>
<p>
Your task is to write a program that outputs the sequence of the longest possible DNA which
can be generated from the given pair of DNAs <i>X</i> and <i>Y</i> and contains the given substring <i>C</i>.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset consists of three lines. The first and
second lines contain the sequences <i>X</i> and <i>Y</i> respectively. The third line contains the substring
<i>C</i>. Each of the sequences and the substrings contains only lowercase letters (âaâââzâ) and has
the length between 1 and 1600 inclusive.
</p>
<p>
The input is terminated by a line with â*â.
</p>
<H2>Output</H2>
<p>
For each dataset, output the longest sequence in a line. If DNAs with the substring <i>C</i> cannot
be obtained in any way, output âImpossibleâ instead. Any of them is acceptable in case there
are two or more longest DNAs possible.
</p>
<H2>Sample Input</H2>
<pre>
czujthebdgfoliskax
bdgchuptzefliskaox
fox
fennec
oinarisama
xiaorong
customizedrevisedfoooox
accurateredundantfooooooooox
fox
*
</pre>
<H2>Output for the Sample Input</H2>
<pre>
cutefox
Impossible
cuteredfox
</pre>
|
p01537 |
<h1> Code Art Online</h1>
<h2> G: ã³ãŒãã¢ãŒããªã³ã©ã€ã³</h2>
<p>
ã³ãŒãã¢ãŒããªã³ã©ã€ã³ïŒCAOïŒã¯ïŒæ§ã
ãªåé¡ãããã°ã©ãã³ã°ã«ãã£ãŠè§£ãããšã«ããïŒåéºãé²ããŠè¡ããªã³ã©ã€ã³RPGã§ããïŒ
CAOã¯ïŒäžçåã®ããŒãã£ã«ãªã¢ãªãã£ç©ºéãå®çŸããã²ãŒã ã§ãã£ãããšãããïŒå€§äººæ°ã®å
ã«å®å£²ãïŒã²ãŒã ã賌å
¥ãããŠãŒã¶éã¯ãã®äžçãæ¥œããã¯ãã§ãã£ãïŒ
ãããïŒã²ãŒã ã«ãã€ããããã¬ã€ã€ãŒéã¯ïŒã²ãŒã ãã¹ã¿ãŒããæãã¹ãèšå®£ãèããããïŒ
</p>
<p>
ãåãã¡ãã¬ã€ã€ãŒã®å
ã®èª°ããïŒã©ã¹ããã³ãžã§ã³ã®ã©ã¹ããããã¬ã ãè§£ããªãéãïŒãã®ä»®æ³ç©ºéããæãåºãããšã¯ã§ããªãïŒãããŠïŒãã®äžçã§ã®ïŒWAãTLEã»REã¯ïŒçŸå®äžçã§ã®æ»ãæå³ããïŒå¿ããŠåé¡ã«ãšãããã£ãŠã»ããïŒã
</p>
<p>
ããªããïŒCAOã®ãã¬ã€ã€ãŒã®å
ã®1人ã§ïŒãã®ã²ãŒã ãã¯ãªã¢ããŠçŸå®äžçã«æ»ãããã«ïŒã²ãŒã æ»ç¥ã«å
šåãå°œãããŠããïŒ
ããæ¥ïŒããªãã¯æ¬¡ã®ãããªåé¡ã«çŽé¢ããããšãšãªã£ãïŒ
</p>
<p>
ä»åïŒæ°ããªãã³ãžã§ã³ãæ»ç¥ããããã«ïŒ<i>n</i>人ã®ã¡ã³ããŒã§ããŒãã£ãçµãŸããïŒ
ããªãããã®ããŒãã£ã®å
ã®1人ã§ããïŒ
ä»ããæ»ç¥ãããã³ãžã§ã³ã«çªå
¥ããããã«ã¯ïŒåŽããèŠãã穎ãééããªããŠã¯ãªããªãïŒ
ç¡äºã«ç©Žãééã§ããã°ïŒãã³ãžã§ã³ã«çªå
¥ã§ãããïŒç©Žã«çªå
¥ã§ããä»ã®éšåã«è§ŠããŠããŸããšïŒæ»ãåŸ
ã£ãŠããïŒ
ããã«ïŒ1ã€ã®ç©Žã«èª°ããéããšïŒãã®ç©Žã¯éããŠããŸãããïŒ1人1人å¥ã
ã®ç©Žã«å
¥ããªããã°ãªããªãïŒ
</p>
<p>
穎ã人ã¯ïŒäºæ¬¡å
å¹³é¢äžã§èããããšãšããïŒ
穎ã®åœ¢ã¯ïŒå³G-1ã®ãããªïŒå€§å°æ§ã
ãªåã§ããïŒå
¥åã§ã¯ïŒååŸã®é·ããäžããããïŒ
</p>
<p>
<center>
<table>
<tr>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2012Day1_G_1" width="300">
</td>
</tr>
<tr>
<td>
<center>
å³G-1: 穎ã®åœ¢
</center>
</td>
</tr>
</table>
</center>
</p>
<p>
人ã®åœ¢ã¯ïŒå³G-2ã®ããã«äººã®æé¢ãå€è§åœ¢ã§äžããããïŒåžãšã¯éããªãïŒïŒ
å
¥åã§ã¯ïŒå€è§åœ¢ã®åœ¢ã衚ãããã«ïŒé ç¹ãåæèšãŸããã§äžããããïŒ
å€è§åœ¢ã®ä»»æã®äžç¹ã¯ïŒ1çŽç·äžã«äžŠã°ãªããšä»®å®ããŠããïŒ
ããã«ïŒé ç¹ãæ§æããç®ç以å€ã§ïŒå€è§åœ¢ã®ç·åå士ã亀差ããããšã¯ãªããã®ãšããïŒ
穎ã«éãããã«ïŒèªç±ã«å転ããŠããïŒãã ãïŒz軞æ¹åãžã®å転ã¯çŠæ¢ããïŒïŒ
人ã衚ãå€è§åœ¢ã®é ç¹ãïŒç©Žã®ååšäžã«ããå Žåã§ãïŒç©Žãééã§ãããã®ãšããïŒ
</p>
<p>
<center>
<table>
<tr>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2012Day1_G_2" width="300">
</td>
</tr>
<tr>
<td>
<center>
å³G-2: 人ã®åœ¢
</center>
</td>
</tr>
</table>
</center>
</p>
<p>
ããŒãã£ã®äžã§æãã¢ã«ãŽãªãºã ã¹ãã«ãé«ãããªãã¯ïŒã¿ããªã§ç¡äºã«ç©Žãééã§ãããã©ããã®å€å®åé¡ãè§£ãããšã«ããïŒ
ããïŒç¡äºã«ééã§ãããªãïŒã©ã®äººãã©ã®ç©Žãééããã°ããã®ã衚瀺ããïŒ
</p>
<p>
â»ä»åã®ã³ã³ãã¹ãã§æ»ã¬ããšã¯ãããŸãããïŒééã£ããæ»ã¬ã€ããã§è§£ããŠãã ããïŒ
</p>
<h2> Input</h2>
<p>
1è¡ç®ã«ïŒç©Žã®æ°ãè¡šãæŽæ°<i>n</i> (1 <= <i>n</i> <= 100)ãšïŒããŒãã£ã®äººæ°ãè¡šãæŽæ°<i>m</i> (1 <= <i>m</i> <= <i>n</i>)ãã¹ããŒã¹åºåãã§å
¥åãããïŒ
</p>
<p>
次ã®è¡ã«ïŒç©Žã®ååŸãè¡šãæŽæ°<i>r<sub>i</sub></i> (1 <= <i>r<sub>i</sub></i> <= 1000)ãã¹ããŒã¹åºåãã§<i>n</i>åå
¥åãããïŒ
ãããã®ç©Žã¯ïŒå
¥åãããé çªã«ïŒ1çªã®ç©Ž, 2çªã®ç©Ž, ..., <i>n</i>çªã®ç©Žãšæ°ããããšãšããïŒ
</p>
<p>
ç¶ããŠïŒ<i>m</i>人ã®äººã®åœ¢ã®æ
å ±ãå
¥åãããïŒ
1äººã®æ
å ±ã¯ïŒãŸã1è¡ç®ã«å€è§åœ¢ã®é ç¹æ°<i>p</i> (3 <= <i>p</i> <= 100)ãå
¥åãããïŒ
ç¶ã<i>p</i>è¡ã«ã¯ïŒå€è§åœ¢ã®é ç¹ã®åº§æšãåæèšåšãã§äžããããïŒ
åè¡ã«ã¯ïŒ1ã€ã®é ç¹ãè¡šãæŽæ°<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> (-1000 <= <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> <= 1000)ãã¹ããŒã¹åºåãã§å
¥åãããïŒ
人ã¯ïŒå
¥åãããé çªã«ïŒ1çªã®äºº, 2çªã®äºº, ..., <i>m</i>çªã®äººãšæ°ããããšãšããïŒ
</p>
<h2> Output</h2>
<p>
<i>i</i>çª(1 <= <i>i</i> <= <i>m</i>)ã®äººãïŒäœçªã®ç©Žã«å
¥ãã°ããããåºåããïŒ
<i>i</i>è¡ç®ã«ã¯ïŒ<i>i</i>çªã®äººãéãã¹ã穎ã®çªå·ãåºåããããšïŒ
</p>
<p>
ããïŒè€æ°ã®éãæ¹ãããå ŽåïŒèŸæžé ã§äžçªå°ãããªãéãæ¹ãåºåããããšïŒ
2ã€ã®æ°å<i>A</i> = {<i>a<sub>1</sub></i>, <i>a<sub>2</sub></i>, ..., <i>a<sub>m</sub></i>}ãš<i>B</i> = {<i>b<sub>1</sub></i>, <i>b<sub>2</sub></i>, ..., <i>b<sub>m</sub></i>}ããã£ããšãïŒ<i>A</i>ã<i>B</i>ããèŸæžé ã§å°ãããšã¯ïŒ<i>a<sub>i</sub></i>ã<i>b<sub>i</sub></i>ãšç°ãªããããªæåã®<i>i</i>ã«ã€ããŠïŒ<i>a<sub>i</sub></i>ã<i>b<sub>i</sub></i>ããå°ãããšãã®ããšãèšãïŒ
</p>
<p>
éãæ¹ã1ã€ãèŠã€ãããªãå Žåã¯ïŒ"NG"ãš1è¡åºåããããšïŒ
æåŸã«æ¹è¡ãåºåããã®ãå¿ããªãããšïŒ
</p>
<h2> Sample Input 1</h2>
<pre>
3 3
25 100 10
8
-10 0
-2 2
0 10
2 2
10 0
2 -2
0 -10
-2 -2
4
30 0
50 0
50 40
30 40
3
30 -10
45 -70
60 -10
</pre>
<h2> Sample Output 1</h2>
<pre>
3
1
2
</pre>
<h2> Sample Input 2</h2>
<pre>
4 3
25 15 15 30
5
0 0
10 0
20 10
0 20
-20 10
3
20 0
40 0
30 10
3
-50 0
-30 0
-40 10
</pre>
<h2> Sample Output 2</h2>
<pre>
1
2
3
</pre>
<h2> Sample Input 3</h2>
<pre>
2 2
1 30
4
0 0
10 0
10 10
0 10
3
5 5
20 20
5 20
</pre>
<h2> Sample Output 3</h2>
<pre>
NG
</pre> |
p00776 |
<h3>Encryption System</h3>
<p>
A programmer developed a new encryption system.
However, his system has an issue that
two or more distinct strings are `encrypted' to the same string.
</p>
<p>
We have a string encrypted by his system.
To decode the original string, we want to enumerate all the candidates of the string before the encryption.
Your mission is to write a program for this task.
</p>
<p>
The encryption is performed taking the following steps. Given a string that consists only of lowercase letters ('a' to 'z').
</p>
<ol>
<li>Change the first 'b' to 'a'. If there is no 'b', do nothing.</li>
<li>Change the first 'c' to 'b'. If there is no 'c', do nothing.</li>
...
<li value="25">Change the first 'z' to 'y'. If there is no 'z', do nothing.</li>
</ol>
<h3>Input</h3>
<p>
The input consists of at most 100 datasets.
Each dataset is a line containing an encrypted string.
The encrypted string consists only of lowercase letters, and contains at least 1 and at most 20 characters.
</p>
<p>
The input ends with a line with a single '#' symbol.
</p>
<h3>Output</h3>
<p>
For each dataset,
the number of candidates <i>n</i> of the string before encryption should be printed in a line first,
followed by lines each containing a candidate of the string before encryption.
If <i>n</i> does not exceed 10, print all candidates in dictionary order;
otherwise, print the first five and the last five candidates in dictionary order.
</p>
<p>
Here, dictionary order is recursively defined as follows.
The empty string comes the first in dictionary order.
For two nonempty strings <i>x</i> = <i>x</i><sub>1</sub> ... <i>x</i><sub>k</sub> and <i>y</i> = <i>y</i><sub>1</sub> ... <i>y</i><sub>l</sub>,
the string <i>x</i> precedes the string <i>y</i> in dictionary order if
</p>
<ul>
<li><i>x</i><sub>1</sub> precedes <i>y</i><sub>1</sub> in alphabetical order ('a' to 'z'), or</li>
<li><i>x</i><sub>1</sub> and <i>y</i><sub>1</sub> are the same character and <i>x</i><sub>2</sub> ... <i>x</i><sub>k</sub> precedes <i>y</i><sub>2</sub> ... <i>y</i><sub>l</sub> in dictionary order.</li>
</ul>
<h3>Sample Input</h3>
<pre>enw
abc
abcdefghijklmnopqrst
z
#
</pre>
<h3>Output for the Sample Input</h3>
<pre>1
fox
5
acc
acd
bbd
bcc
bcd
17711
acceeggiikkmmooqqssu
acceeggiikkmmooqqstt
acceeggiikkmmooqqstu
acceeggiikkmmooqrrtt
acceeggiikkmmooqrrtu
bcdefghijklmnopqrrtt
bcdefghijklmnopqrrtu
bcdefghijklmnopqrssu
bcdefghijklmnopqrstt
bcdefghijklmnopqrstu
0
</pre> |
p01864 |
<!--<script language="JavaScript" type="text/javascript" src="js/varmath.js" charset="UTF-8"></script>-->
<h2>G: æ
è²»æ¯çµŠ - Travel Support -</h2>
<h3>ç©èª</h3>
<p>ç§ïŒéŠåç©ä¹æ16æ³ïŒåŠçã¢ã€ãã«ããã£ãŠããŸãïŒïŒ</p>
<p>åŠçã¢ã€ãã«ã®è¯ããã¿ããªã«äŒããããã®ã©ã€ããããããšïŒããããã®åŠçã¢ã€ãã«ã®äººãã¡ãåŒãã§ã¢ããã¹ã¿ãžã¢ã ã§ã©ã€ããããŸãïŒ</p>
<p>ã ãã©ïŒé ãããæ¥ãã©ã€ãåå è
ãããŠãšã£ãŠãé»è»è³ããããã®ïŒã ããuâsã®ã¡ã³ããŒã§ãã€ããããŠïŒã©ã€ãåå è
ãã¡ã«é»è»è³ãæž¡ãããšã«ãããã ïŒãã ïŒãã€ã代ãå
¥ãã®ãé
ãããé»è»è³ãæž¡ãã®ãã©ã€ãåå è
ã®åºçºã«éã«åããªãããšããã£ããïŒãã€ã代ãè¶³ããªããŠé»è»è³ã®å
šé¡ã¯æž¡ããªãããšããããã ïŒãããªæã¯ïŒã©ã€ãåå è
ã«è¶³ããªãåã®ãéãäºåã«çšæããŠãããã®ã ãã©ïŒã©ã®ãããçšæããŠè²°ãã°ãããã ããïŒ</p>
<p>ããã§ïŒããªãã«ã©ã€ãåå è
ãçšæããå¿
èŠã®ããæå°ã®éé¡ãæ±ããŠæ¬²ãããã ïŒ</p>
<p>ããããçè¡£ã¡ããïŒé»è»è³è²žããŠïŒ</p>
<h3>åé¡</h3>
<p><var>N</var>åã®éœåžãããïŒãããã<var>1</var>ã<var>N</var>ãŸã§ã®çªå·ãã€ããããŠããïŒ<var>i</var>ïŒ<var>1 ≤ i ≤ N</var>ïŒçªç®ã®éœåžã¯äººå£ã<var>t_i</var>ïŒ<var>i ≠ j</var>ãªãã°<var>t_i ≠ t_j</var>ïŒã§ããïŒ</p>
<p>çŸåšïŒéœåž1ã«<var>K</var>人ã®ã©ã€ãåå è
ãéãŸãããšããŠããïŒèš±ãããäº€éææ®µã<var>M</var>éãããïŒ<var>i</var>çªç®ã®äº€éææ®µã§ã¯éœåž<var>a_i</var>ãšéœåž<var>b_i</var>ïŒ<var>1 ≤ a_i, b_i ≤ N</var>ïŒã<var>c_i</var>åã®è²»çšã§åæ¹åã«ç§»åãã§ããïŒç§»åã«ã¯ã©ã®äº€éææ®µã§ã1æ¥ãå¿
èŠãšããïŒ</p>
<p><var>i</var>ïŒ<var>1 ≤ i ≤ K</var>ïŒçªç®ã®åå è
ã¯ïŒéœåž<var>x_i</var>ãåºçºãå¿
èŠãªè²»çšãæå°ã«ãªããããªçµè·¯ã§éœåž1ã«åããïŒè²»çšãæå°ãªçµè·¯ãè€æ°ããå Žåã¯ïŒç§»åæ¥æ°ãå°ãªãçµè·¯ãéžã¶ïŒããã§ãè€æ°ã®çµè·¯ãããå Žåã¯ïŒäººå£ãå°ãªãéœåžãžåªå
ããŠç§»åãããããªçµè·¯ãéžã¶ïŒããã«ããçµè·¯ãå®ãŸãå°çãããŸã§ã®æ¥æ°ããããã®ã§ïŒåå è
ã¯ããããã©ã€ããè¡ãããæ¥ã«ã¡ããã©éœåž1ã«å°çããããã«ç§»åãéå§ããïŒ</p>
<p>ãŸãïŒ<var>i</var>ïŒ<var>1 ≤ i ≤ K</var>ïŒçªç®ã®åå è
ã«ã¯ã©ã€ãã®<var>d_i</var>æ¥åã«<var>p_i</var>åã®æ¯çµŠãããäºãç¥ããããŠããïŒæ¯çµŠåŸã®ç§»åã«ã¯å¯èœãªãããæ¯çµŠãããè²»çšãçšãããïŒæ¯çµŠåã«ããã£ãŠããè²»çšãïŒè³ããããªãæ¯çµŠåŸã®è²»çšã¯ïŒååå è
ãäºåã«çšæããå¿
èŠãããïŒ</p>
<p>ããããã®åå è
ãäºåã«çšæããè²»çšã®æå°å€ãæ±ããïŒ</p>
<h3>å
¥å圢åŒ</h3>
<p>å
¥åã¯æ¬¡ã®åœ¢åŒã§äžããããïŒ</p>
<pre>
<var>N</var> <var>M</var>
<var>t_1</var> ... <var>t_N</var>
<var>a_1</var> <var>b_1</var> <var>c_1</var>
...
<var>a_M</var> <var>b_M</var> <var>c_M</var>
<var>K</var>
<var>x_1</var> <var>d_1</var> <var>p_1</var>
...
<var>x_K</var> <var>d_K</var> <var>p_K</var>
</pre>
<p>1è¡ç®ã«ã¯2ã€ã®æŽæ°<var>N</var>ïŒ<var>1 ≤ N ≤ 100,000</var>ïŒïŒ<var>M</var>ïŒ<var>0 ≤ M ≤ 500,000</var>ïŒã空çœåºåãã§äžãããïŒããããéœåžæ°ãšèš±ãããäº€éææ®µã®æ°ã衚ãïŒ2è¡ç®ã«ã¯<var>N</var>åã®æŽæ°<var>t_i</var>ïŒ<var>1 ≤ i ≤ N</var>ïŒ<var>1 ≤ t_i ≤ 500,000</var>ïŒã空çœåºåãã§äžããããïŒ<var>t_i</var>ã¯éœåž<var>i</var>ã®äººå£ã衚ãïŒ<var>i ≠ j</var>ãªãã°<var>t_i ≠ t_j</var>ãæºããïŒ</p>
<p>ç¶ã<var>M</var>è¡ã¯äº€éææ®µã«ã€ããŠã®å
¥åã§ããïŒ<var>i</var>çªç®ã®äº€éææ®µã«ã€ããŠ3ã€ã®æŽæ°<var>a_i</var>ïŒ<var>b_i</var>ïŒ<var>c_i</var>ã空çœåºåãã§äžããããïŒããã¯ïŒ<var>i</var>çªç®ã®äº€éææ®µã§éœåž<var>a_i</var>ãš<var>b_i</var>ïŒ<var>1 ≤ a_i, b_i ≤ N</var>, <var>a_i ≠ b_i</var>ïŒãè¡ãæ¥ã§ãïŒ<var>c_i</var>ïŒ<var>1 ≤ c_i ≤ 10,000</var>ïŒåã®è²»çšããããããšã衚ãïŒãŸãïŒä»»æã®2ã€ã®éœåžãçŽæ¥çµã¶2ã€ä»¥äžã®äº€éææ®µã¯ç¡ãïŒå
šãŠã®éœåžã¯ïŒããã€ãã®äº€éææ®µãçšããŠäºãã«è¡ãæ¥ã§ããïŒ</p>
<p>次ã®è¡ã«ã¯åå è
ã®äººæ°ãè¡šãæŽæ°<var>K</var>ïŒ<var>1 ≤ K ≤ 100,000</var>ïŒãäžããããïŒ</p>
<p>ç¶ã<var>K</var>è¡ã¯åå è
ãã¡ã«ã€ããŠã®å
¥åã§ããïŒ<var>i</var>çªç®ã®åå è
ã«ã€ããŠ3ã€ã®æŽæ°<var>x_i, d_i, p_i</var>ã空çœåºåãã§äžããããïŒããã¯ïŒ<var>i</var>çªç®ã®åå è
ãæåã¯éœåž<var>x_i</var>ïŒ<var>1 ≤ x_i ≤ N</var>ïŒã«ããïŒã©ã€ãã®<var>d_i</var>ïŒ<var>0 ≤ d_i ≤ 100,000</var>ïŒæ¥åã«<var>p_i</var>ïŒ<var>0 ≤ p_i ≤ 100,000</var>ïŒåã®æ¯çµŠãåããããšã衚ãïŒ</p>
<h3>åºå圢åŒ</h3>
<p>ããããã®åå è
ãäºåã«çšæããè²»çšã®æå°å€ãïŒ1çªç®ã®åå è
ããé ã«æ¹è¡åºåãã§åºåããïŒ</p>
<p>å
¥åºåãéåžžã«å€§ãããªãå¯èœæ§ãããã®ã§ïŒå
¥åºåã®é¢æ°ã«ã¯é«éãªãã®ãçšããããšãæšå¥šããïŒ</p>
<h3>å
¥åäŸ1</h3>
<pre>
5 6
100 80 70 60 50
1 2 500
2 5 100
1 3 400
1 4 200
3 5 700
4 5 800
1
5 3 600
</pre>
<h3>åºåäŸ1</h3>
<pre>0</pre>
<p>ç§»åå
šäœã«ãããè²»çšã®æå°å€ã¯600åã§ïŒ2æ¥éã§éœåž1ã«ã€ãããšãã§ããïŒ3æ¥åã«ååãªè²»çšãæ¯çµŠãããã®ã§ïŒäºåã«è²»çšãçšæããå¿
èŠã¯ãªãïŒ</p>
<h3>å
¥åäŸ2</h3>
<pre>
5 6
400 200 500 300 100
1 2 500
2 5 100
1 3 400
1 4 200
3 5 200
4 5 800
1
5 1 800
</pre>
<h3>åºåäŸ2</h3>
<pre>100</pre>
<p>è²»çšãæå°ã§ãããã€æ¥æ°ãæå°ãšãªãçµè·¯ã¯<var>5−2−1</var>ãš<var>5−3−1</var>ã®2ã€ã®çµè·¯ããããïŒéœåž5ããæ¬¡ã®éœåžãžç§»åããéã«ïŒéœåž3ããéœåž2ã®æ¹ã人å£ãå°ãªãã®ã§çµè·¯<var>5−2−1</var>ãéžã¶ïŒåèšã®è²»çšã¯600åãªã®æ¯çµŠé¡ã§å
šé¡æ¯æãå¯èœã§ãããïŒæ¯çµŠãããããåã®è²»çšã¯ç«ãŠæ¿ããªããã°ãªããªãã®ã§ïŒ<var>5−2</var>éã®è²»çšã§ãã100åã ãäºåã«çšæããå¿
èŠãããïŒ</p>
<h3>å
¥åäŸ3</h3>
<pre>
10 13
100 90 80 70 60 50 40 30 20 10
1 2 5
1 4 4
2 3 3
3 5 2
4 5 6
4 6 7
4 7 2
5 8 1
5 9 8
6 7 10
6 9 7
6 10 3
7 10 10
10
2 0 0
2 1 3
3 0 100000
3 1 3
3 1 100000
3 2 100000
3 100000 100000
8 1 5
9 2 11
10 0 0
</pre>
<h3>åºåäŸ3</h3>
<pre>
5
2
8
5
3
0
0
7
7
14
</pre> |
p03859 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a string <var>S</var> of length <var>N</var> consisting of characters <code>0</code> and <code>1</code>. You will perform the following operation for each <var>i = 1, 2, ..., m</var>:</p>
<ul>
<li>Arbitrarily permute the characters within the substring of <var>S</var> starting at the <var>l_i</var>-th character from the left and extending through the <var>r_i</var>-th character.</li>
</ul>
<p>Here, the sequence <var>l_i</var> is non-decreasing.</p>
<p>How many values are possible for <var>S</var> after the <var>M</var> operations, modulo <var>1000000007(= 10^9+7)</var>?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2âŠNâŠ3000</var></li>
<li><var>1âŠMâŠ3000</var></li>
<li><var>S</var> consists of characters <code>0</code> and <code>1</code>.</li>
<li>The length of <var>S</var> equals <var>N</var>.</li>
<li><var>1âŠl_i < r_iâŠN</var></li>
<li><var>l_i ⊠l_{i+1}</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>S</var>
<var>l_1</var> <var>r_1</var>
:
<var>l_M</var> <var>r_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the possible values for <var>S</var> after the <var>M</var> operations, modulo <var>1000000007</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
01001
2 4
3 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>After the first operation, <var>S</var> can be one of the following three: <code>01001</code>, <code>00101</code> and <code>00011</code>.</p>
<p>After the second operation, <var>S</var> can be one of the following six: <code>01100</code>, <code>01010</code>, <code>01001</code>, <code>00011</code>, <code>00101</code> and <code>00110</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9 3
110111110
1 4
4 6
6 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>26
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>11 6
00101000110
2 4
2 3
4 7
5 6
6 10
10 11
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>143
</pre></section>
</div>
</span> |
p00326 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>ã¹ã±ãžã¥ãŒã©</H1>
<p>
ããªãã¯ãŠããŒã¯ãªãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ããŠã³ãºã°ãïŒïŒãã®éçºã«åãçµãã§ãããæ§èœã決å®ä»ããã¹ã±ãžã¥ãŒã©ã®èšèšã«é ãæ©ãŸããŠãããã¹ã±ãžã¥ãŒã©ãšã¯ãå®è¡ãã¹ãåŠçãã¿ã¹ã¯ãšããåäœã§è¡šçŸããããããã©ã®é åºã§å®è¡ããããæ±ºå®ããããã°ã©ã ã§ãããã¹ã±ãžã¥ãŒã©ã¯ã¿ã¹ã¯ã«ïŒãã <var>N</var> ã®çªå·ãã€ããŠç®¡çãããå
šãŠã®ã¿ã¹ã¯ã¯ <var>K</var> åã®å±æ§ <var>f<sub>1</sub></var>, <var>f<sub>2</sub></var>,..., <var>f<sub>K</sub></var> ãæã¡ãå屿§ã«ã¯ããããåºæã®å€ãèšå®ãããŠããããã ããããïŒã€ã®ã¿ã¹ã¯ã«ã€ããŠã察å¿ãã屿§ã®å€ãã¹ãŠãåãã«ãªãããšã¯ãªãã
</p>
<p>
ããã¿ã¹ã¯ã«ã¯ããã®ã¿ã¹ã¯ã®å®è¡ãå§ããåãŸã§ã«å®è¡ãå®äºããŠããªããã°ãªããªãã¿ã¹ã¯ãäžããããããšããããã¿ã¹ã¯ïŒ¡ãã¿ã¹ã¯ïŒ¢ã®åã«å®äºããŠããªããã°ãªããªãããšããã¿ã¹ã¯ïŒ¡ → ã¿ã¹ã¯ïŒ¢ããšè¡šããäŸãã°ãã¿ã¹ã¯ïŒ → ã¿ã¹ã¯ïŒãã¿ã¹ã¯ïŒ → ã¿ã¹ã¯ïŒãšããé¢ä¿ãããã°ãã¿ã¹ã¯ïŒãåŠçããåã«ã¿ã¹ã¯ïŒãšã¿ã¹ã¯ïŒã®äž¡æ¹ã®åŠçãçµãã£ãŠããªããã°ãªããªãããã®ãããªé¢ä¿ãã¿ã¹ã¯éã®äŸåé¢ä¿ãšããããã ããããã¿ã¹ã¯ããäŸåé¢ä¿ããã©ã£ãŠãã£ãŠããã®ã¿ã¹ã¯ã«ãã©ãçãããšã¯ãªãã
</p>
<p>
ã¹ã±ãžã¥ãŒã©ã¯äŸåé¢ä¿ã«åŸã£ãŠãå®è¡é åºã決å®ãããããããäŸåé¢ä¿ã ãã§ã¯é åºãäžéãã«å®ãŸããªãå Žåãããããã®ãããªå Žåã¯ãåã¿ã¹ã¯ãæã€å±æ§ã®å€ã«ãã£ãŠã次ã«åŠçããã¿ã¹ã¯ãéžæããã
</p>
<p>
ãŠã³ãºã°ãïŒïŒã®ã¿ã¹ã¯ã¯å±æ§ãè€æ°ãã€ããããã¹ãŠã®å±æ§ã®å€ãèæ
®ããŠå®è¡é åºã決å®ããå¿
èŠãããããã®ããã«ã屿§ãæ¯èŒããé çªãå®ããè©äŸ¡é åºãçšãããè©äŸ¡é åºãæãå
ã®å±æ§ãæ¯èŒãããã®å±æ§ã®å€ãæã倧ããã¿ã¹ã¯ãéžæããããã®ãããªã¿ã¹ã¯ãè€æ°ããå Žåã¯ãè©äŸ¡é åºããã®æ¬¡ã®å±æ§ã§æ¯èŒãã以äžåæ§ãªæé ãç¹°ãè¿ããäŸãã°ã以äžã®3 ã€ã®å±æ§ãæã€3 ã€ã®ã¿ã¹ã¯ã«ã€ããŠèããã
</p>
<center>
<table width="500">
<tr>
<td width="200">ã¿ã¹ã¯ïŒŒå±æ§</td>
<td width="100"><var>f<sub>1</sub></var></td>
<td width="100"><var>f<sub>2</sub></var></td>
<td width="100"><var>f<sub>3</sub></var></td>
</tr>
<tr>
<td>X</td> <td>3</td> <td>3</td> <td>2</td>
</tr>
<tr>
<td>Y</td> <td>3</td> <td>2</td> <td>2</td>
</tr>
<tr>
<td>Z</td> <td>3</td> <td>1</td> <td>3</td>
</tr>
</table>
</center>
<br/>
<p>
è©äŸ¡é åºã<var>f<sub>1</sub></var> <var>f<sub>2</sub></var> <var>f<sub>3</sub></var>ã<var>f<sub>2</sub></var> <var>f<sub>1</sub></var> <var>f<sub>3</sub></var>ããŸã㯠<var>f<sub>2</sub></var> <var>f<sub>3</sub></var> <var>f<sub>1</sub></var> ã«èšå®ãããŠããå Žåã¯ãã¿ã¹ã¯X ãéžã°ããããŸããè©äŸ¡é åºã <var>f<sub>1</sub></var> <var>f<sub>3</sub></var> <var>f<sub>2</sub></var>ã<var>f<sub>3</sub></var> <var>f<sub>1</sub></var> <var>f<sub>2</sub></var>ããŸã㯠<var>f<sub>3</sub></var> <var>f<sub>2</sub></var> <var>f<sub>1</sub></var> ã«èšå®ãããŠããå Žåã¯ã¿ã¹ã¯Z ãéžã°ããã
</p>
<p>
ãŠã³ãºã°ãïŒïŒã®ã¹ã±ãžã¥ãŒã©ã®ç¹åŸŽã¯ã屿§ã®è©äŸ¡é åºãéäžã§äœåºŠã§ã倿Žã§ããããšã§ãããè©äŸ¡é åºã¯ãããåæ°ã®ã¿ã¹ã¯ã®å®è¡ãå®äºããæç¹ã§å€æŽã§ããããã ããã¹ã±ãžã¥ãŒã©ãæåã«äœ¿ãè©äŸ¡é åºã¯ãããããæ±ºãŸã£ãŠããã
</p>
<p>
åã¿ã¹ã¯ã®å±æ§ã®å€ãã¿ã¹ã¯ã®äŸåé¢ä¿ãè©äŸ¡é åºã®å€æŽæ
å ±ãäžãããããšããã¿ã¹ã¯ãå®è¡ããé åºãå ±åããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var> <var>K</var>
<var>f<sub>1,1</sub></var> <var>f<sub>1,2</sub></var> ... <var>f<sub>1,K</sub></var>
<var>f<sub>2,1</sub></var> <var>f<sub>2,2</sub></var> ... <var>f<sub>2,K</sub></var>
:
<var>f<sub>N,1</sub></var> <var>f<sub>N,2</sub></var> ... <var>f<sub>N,K</sub></var>
<var>D</var>
<var>a<sub>1</sub></var> <var>b<sub>1</sub></var>
<var>a<sub>2</sub></var> <var>b<sub>2</sub></var>
:
<var>a<sub>D</sub></var> <var>b<sub>D</sub></var>
<var>e<sub>0,1</sub></var> <var>e<sub>0,2</sub></var> ... <var>e<sub>0,K</sub></var>
<var>R</var>
<var>m<sub>1</sub></var> <var>e<sub>1,1</sub></var> <var>e<sub>1,2</sub></var> ...⊠<var>e<sub>1,K</sub></var>
<var>m<sub>2</sub></var> <var>e<sub>2,1</sub></var> <var>e<sub>2,2</sub></var> ...⊠<var>e<sub>2,K</sub></var>
:
<var>m<sub>R</sub></var> <var>e<sub>R,1</sub></var> <var>e<sub>R,2</sub></var> ...⊠<var>e<sub>R,K</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ãã¿ã¹ã¯ã®æ° <var>N</var> (2 ≤ <var>N</var> ≤ 50000) ãšãåã¿ã¹ã¯ãæã€å±æ§ã®æ° <var>K</var> (1 ≤ <var>K</var> ≤ 4) ãäžãããããç¶ã <var>N</var> è¡ã«ãã¿ã¹ã¯ <var>i</var> ãæã€å±æ§ã®å€ <var>f<sub>i,j</sub></var> (1 ≤ <var>f<sub>i,j</sub></var> ≤ 100000) ãäžãããããç¶ãïŒè¡ã«ãäŸåé¢ä¿ã®åæ° <var>D</var> (0 ≤ <var>D</var> ≤ 200000) ãäžãããããç¶ã <var>D</var> è¡ã«äŸåé¢ä¿ <var>a<sub>i</sub></var> → <var>b<sub>i</sub></var> (1 ≤ <var>a<sub>i</sub></var>, <var>b<sub>i</sub></var> ≤ <var>N</var>) ãäžããããã
</p>
<p>
ç¶ãïŒè¡ã«ãæåã®è©äŸ¡é åº <var>e<sub>0,j</sub></var> (1 ≤ <var>e<sub>0,j</sub></var> ≤ <var>K</var>) ãäžãããããç¶ãïŒè¡ã«ãè©äŸ¡é åºã®å€æŽåæ° <var>R</var> (0 ≤ <var>R</var> < <var>N</var>) ãäžãããããç¶ã <var>R</var> è¡ã«ãè©äŸ¡é åºã®å€æŽæ
å ±ãäžããããã<var>i</var> åç®ã®å€æŽæ
å ±ã¯ãå®è¡ãå®äºããã¿ã¹ã¯ã®åæ° <var>m<sub>i</sub></var> (1 ≤ <var>m<sub>i</sub></var> < <var>N</var>) ãšè©äŸ¡é åº <var>e<sub>i,j</sub></var> (1 ≤ <var>e<sub>i,j</sub></var> ≤ <var>K</var>) ãããªããå
šéšã§ <var>m<sub>i</sub></var> åã®ã¿ã¹ã¯ã®å®è¡ãå®äºããæç¹ã§ãè©äŸ¡é åºã <var>e<sub>i,1</sub></var>, <var>e<sub>i,2</sub></var>,... , <var>e<sub>i,K</sub></var> ã«å€æŽããããšã瀺ãã
</p>
<p>
è©äŸ¡é åºã®å€æŽæ
å ±ã¯ä»¥äžã®æ¡ä»¶ãæºããã
</p>
<ul>
<li> <var>e<sub>i,1</sub></var>, <var>e<sub>i,2</sub></var>,..., <var>e<sub>i,K</sub></var> äžã«åãå€ã¯ïŒã€ä»¥äžçŸããªãã</li>
<li> <var>i</var> < <var>j</var> ã®ãšãã <var>m<sub>i</sub></var> < <var>m<sub>j</sub></var> ã§ããã</li>
</ul>
<h2>Output</h2>
<p>
ã¹ã±ãžã¥ãŒã©ãåŠçããé çªã«ãã¿ã¹ã¯ã®çªå·ãåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
5 3
1 5 2
3 8 5
1 2 3
5 5 5
4 8 2
0
1 2 3
2
2 2 3 1
4 3 1 2
</pre>
<h2>Sample Output 1</h2>
<pre>
4
5
2
1
3
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
5 2
1 1
2 1
3 1
4 4
5 2
3
1 4
2 4
2 5
1 2
1
3 2 1
</pre>
<h2>Sample Output 2</h2>
<pre>
3
2
5
1
4
</pre> |
p02931 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> cards placed on a grid with <var>H</var> rows and <var>W</var> columns of squares.</p>
<p>The <var>i</var>-th card has an integer <var>A_i</var> written on it, and it is placed on the square at the <var>R_i</var>-th row from the top and the <var>C_i</var>-th column from the left.</p>
<p>Multiple cards may be placed on the same square.</p>
<p>You will first pick up at most one card from each row.</p>
<p>Then, you will pick up at most one card from each column.</p>
<p>Find the maximum possible sum of the integers written on the picked cards.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values are integers.</li>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq H, W \leq 10^5</var></li>
<li><var>1 \leq A_i \leq 10^5</var></li>
<li><var>1 \leq R_i \leq H</var></li>
<li><var>1 \leq C_i \leq W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>H</var> <var>W</var>
<var>R_1</var> <var>C_1</var> <var>A_1</var>
<var>R_2</var> <var>C_2</var> <var>A_2</var>
<var>\vdots</var>
<var>R_N</var> <var>C_N</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible sum of the integers written on the picked cards.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6 2 2
2 2 2
1 1 8
1 1 5
1 2 9
1 2 7
2 1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>28
</pre>
<p>The sum of the integers written on the picked cards will be <var>28</var>, the maximum value possible, if you pick up cards as follows:</p>
<ul>
<li>Pick up the fourth card from the first row.</li>
<li>Pick up the sixth card from the second row.</li>
<li>Pick up the second card from the first column.</li>
<li>Pick up the fifth card from the second column.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>13 5 6
1 3 35902
4 6 19698
4 6 73389
3 6 3031
3 1 4771
1 4 4784
2 1 36357
2 1 24830
5 6 50219
4 6 22645
1 2 30739
1 4 68417
1 5 78537
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>430590
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 100000 100000
1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre></section>
</div>
</span> |
p03623 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke lives at position <var>x</var> on a number line.
On this line, there are two stores <var>A</var> and <var>B</var>, respectively at position <var>a</var> and <var>b</var>, that offer food for delivery.</p>
<p>Snuke decided to get food delivery from the closer of stores <var>A</var> and <var>B</var>.
Find out which store is closer to Snuke's residence.</p>
<p>Here, the distance between two points <var>s</var> and <var>t</var> on a number line is represented by <var>|s-t|</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq x \leq 1000</var></li>
<li><var>1 \leq a \leq 1000</var></li>
<li><var>1 \leq b \leq 1000</var></li>
<li><var>x, a</var> and <var>b</var> are pairwise distinct.</li>
<li>The distances between Snuke's residence and stores <var>A</var> and <var>B</var> are different.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>x</var> <var>a</var> <var>b</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If store <var>A</var> is closer, print <code>A</code>; if store <var>B</var> is closer, print <code>B</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>B
</pre>
<p>The distances between Snuke's residence and stores <var>A</var> and <var>B</var> are <var>3</var> and <var>2</var>, respectively.
Since store <var>B</var> is closer, print <code>B</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 999 1000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>A
</pre></section>
</div>
</span> |
p03789 | <span class="lang-en">
<p>Score : <var>1300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We will call a non-negative integer <em>increasing</em> if, for any two adjacent digits in its decimal representation, the digit to the right is greater than or equal to the digit to the left.
For example, <var>1558</var>, <var>11</var>, <var>3</var> and <var>0</var> are all increasing; <var>10</var> and <var>20170312</var> are not.</p>
<p>Snuke has an integer <var>N</var>. Find the minimum number of increasing integers that can represent <var>N</var> as their sum.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^{500000}</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of increasing integers that can represent <var>N</var> as their sum.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>80
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>One possible representation is <var>80 = 77 + 3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>123456789
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p><var>123456789</var> in itself is increasing, and thus it can be represented as the sum of one increasing integer.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>20170312
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>7204647845201772120166980358816078279571541735614841625060678056933503
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>31
</pre></section>
</div>
</span> |
p03273 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a grid of squares with <var>H</var> horizontal rows and <var>W</var> vertical columns.
The square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left is represented as <var>(i, j)</var>.
Each square is black or white.
The color of the square is given as an <var>H</var>-by-<var>W</var> matrix <var>(a_{i, j})</var>.
If <var>a_{i, j}</var> is <code>.</code>, the square <var>(i, j)</var> is white; if <var>a_{i, j}</var> is <code>#</code>, the square <var>(i, j)</var> is black.</p>
<p>Snuke is compressing this grid.
He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:</p>
<ul>
<li>Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.</li>
</ul>
<p>It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation.
Find the final state of the grid.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq H, W \leq 100</var></li>
<li><var>a_{i, j}</var> is <code>.</code> or <code>#</code>.</li>
<li>There is at least one black square in the whole grid.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var>
<var>a_{1, 1}...a_{1, W}</var>
<var>:</var>
<var>a_{H, 1}...a_{H, W}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 4
##.#
....
##.#
.#.#
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>###
###
.##
</pre>
<p>The second row and the third column in the original grid will be removed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3
#..
.#.
..#
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>#..
.#.
..#
</pre>
<p>As there is no row or column that consists only of white squares, no operation will be performed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 5
.....
.....
..#..
.....
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>#
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>7 6
......
....#.
.#....
..#...
..#...
......
.#..#.
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>..#
#..
.#.
.#.
#.#
</pre></section>
</div>
</span> |
p02032 | <h2>C: çŽæ°ã²ãŒã / Divisor Game</h2>
<h3>åé¡</h3>
<p>tsutaj ããã¯çŽæ°ã²ãŒã ã§éãŒããšããŠããŸãã</p>
<p>çŽæ°ã²ãŒã ã§ã¯ããŸã <var>2</var> 以äžã®èªç¶æ° <var>N</var> ãäžãããããã®åŸã¯ä»¥äžã®æé ã§ã²ãŒã ãé²ãã§ãããŸãã</p>
<ul>
<li> <var>N</var> 以å€ã® <var>N</var> ã®çŽæ°ã®äžãããæŽæ°ã <var>1</var> ã€å®£èšããããã ããã®ãšããæ¢ã«å®£èšããããšãããæŽæ°ã®çŽæ°ã«ãªããã®ã¯å®£èšã§ããªãã</li>
<li> 宣èšã§ããæŽæ°ãããéããããç¹°ãè¿ãã宣èšã§ãããã®ããªããã°ã²ãŒã ã¯çµäºããã</li>
</ul>
<p>ã²ãŒã ãçµäºããããŸã§ã«è¡ããã宣èšã®åæ°ãšããŠããåŸãæ°ã®æå°å€ãšæå€§å€ãæ±ããŠãã ããã</p>
<h3>å
¥å圢åŒ</h3>
<p>å
¥å㯠<var>1</var> è¡ã§äžããããã</p>
<pre><var>N</var></pre>
<h3>å¶çŽ</h3>
<ul>
<li> <var>2 \leq N \leq 10^{12}</var></li>
</ul>
<h3>åºå圢åŒ</h3>
<p>宣èšåæ°ã®æå°å€ãšæå€§å€ããã¹ããŒã¹åºåãã§ <var>1</var> è¡ã«åºåããã</p>
<h3>å
¥åäŸ1</h3>
<pre>18</pre>
<h3>åºåäŸ1</h3>
<pre>2 5</pre>
<p>宣èšåæ°ã <var>2</var> åã«ããäžäŸã¯ä»¥äžã®éãã§ãã</p>
<ul>
<li> <var>9</var> ã宣èšããã</li>
<li> <var>6</var> ã宣èšããã (<var>6</var> 㯠<var>9</var> ã®çŽæ°ã§ã¯ãªããã宣èšãå¯èœã§ãã)</li>
</ul>
<p>ãããè¡ããšã<var>18</var> ã®çŽæ°ã§ <var>18</var> ã§ãªãä»»æã®æŽæ°ã¯ä»ãŸã§å®£èšããŠããæŽæ°ã®çŽæ°ã«ãªããããã²ãŒã ãçµäºããŸãã</p>
<p>æ¢ã«å®£èšããããšãããæŽæ°ã®çŽæ°ã«ãªããã®ã¯å®£èšã§ããªãããšã«æ³šæããŠãã ãããäŸãã°ã <var>9</var> ã宣èšããããšã« <var>3</var> ã宣èšããããšã¯ã§ããŸããããªããªãã<var>3</var> 㯠<var>9</var> ã®çŽæ°ã«ãªãããã§ãã</p>
<h3>å
¥åäŸ2</h3>
<pre>99</pre>
<h3>åºåäŸ2</h3>
<pre>2 5</pre>
<h3>å
¥åäŸ3</h3>
<pre>10000000019</pre>
<h3>åºåäŸ3</h3>
<pre>1 1</pre>
<p>å
¥å㯠<var>32</var> bit æŽæ°åã«åãŸããªãå ŽåããããŸãã</p>
|
p02198 | <h2>ã¢ã«ã猶ã®äžã«ãããã«ã³ (Oranges on Cans)</h2>
<p>square1001 åã¯ãããŒãã«ã«ã¢ã«ã猶ã $N$ 猶眮ããŸããã</p>
<p>E869120 åã¯ãããŒãã«äžã®ããããã®ã¢ã«ã猶ã®äžã« $M$ åãã€ãã«ã³ãä¹ããŸããã</p>
<p>ã¢ã«ã猶ã®äžã«ä¹ã£ãŠãããã«ã³ã¯å
šéšã§äœåãããŸããïŒ</p>
<h3>å
¥å</h3>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã</p>
<pre>
$N$ $M$
</pre>
<h3>åºå</h3>
<p>ã¢ã«ã猶ã®äžã«ä¹ã£ãŠãããã«ã³ã®æ°ã 1 è¡ã§åºåããŠãã ããã</p>
<p>ãã ããæåŸã«ã¯æ¹è¡ãå
¥ããããšã</p>
<h3>å¶çŽ</h3>
<ul>
<li>$1 \leq N \leq 9$</li>
<li>$1 \leq M \leq 9$</li>
<li>å
¥åã¯å
šãп޿°ã§ããã</li>
</ul>
<h3>å
¥åäŸ1</h3>
<pre>
3 4
</pre>
<h3>åºåäŸ1</h3>
<pre>
12
</pre>
<h3>å
¥åäŸ2</h3>
<pre>
7 7
</pre>
<h3>åºåäŸ2</h3>
<pre>
49
</pre> |
p02462 | <h1>Multi-Map</h1>
<p>
For a dictionary $M$ that stores elements formed by a pair of a string key and an integer value, perform a sequence of the following operations. Note that <u>multiple elements can have equivalent keys</u>.
</p>
<ul>
<li>insert($key$, $x$): Insert an element formed by a pair of $key$ and $x$ to $M$.</li>
<li>get($key$): Print all values with the specified $key$.</li>
<li>delete($key$): Delete all elements with the specified $key$.</li>
<li>dump($L$, $R$): Print all elements formed by a pair of the key and the value such that the key is greater than or equal to $L$ and less than or equal to $R$ in lexicographic order.</li>
</ul>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$q$
$query_1$
$query_2$
:
$query_q$
</pre>
<p>
Each query $query_i$ is given by
</p>
<pre>
0 $key$ $x$
</pre>
<p>or</p>
<pre>
1 $key$
</pre>
<p>or</p>
<pre>
2 $key$
</pre>
<p>or</p>
<pre>
3 $L$ $R$
</pre>
<p>
where the first digits <span>0</span>, <span>1</span>, <span>2</span> and <span>3</span> represent insert, get, delete and dump operations.
</p>
<h2>Output</h2>
<p>
For each get operation, print the corresponding values in the order of insertions.<br>
For each dump operation, print the corresponding elements formed by a pair of the key and the value. For the dump operation, print the elements in ascending order of the keys, in case of a tie, in the order of insertions.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq q \leq 200,000$</li>
<li>$1 \leq x \leq 1,000,000,000$</li>
<li>$1 \leq $ length of $key$ $ \leq 20$ </li>
<li>$key$ consists of lower-case letters</li>
<li>$L \leq R$ in lexicographic order</li>
<li>The total number of elements printed by get operations does not exceed $500,000$</li>
<li>The total number of elements printed by dump operations does not exceed $500,000$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
10
0 blue 6
0 red 1
0 blue 4
0 white 5
1 red
1 blue
2 red
1 black
1 red
3 w z
</pre>
<h2>Sample Output 1</h2>
<pre>
1
6
4
white 5
</pre>
|
p02177 | <h1>C: åå€åœé¡</h1>
<h2>åé¡</h2>
<p>
$N$ åã®åœé¡ããã, ãããã $1, 2, \cdots,N$ ãšããååãã€ããŠãã. </br>
ãŸã, åœé¡ã«é¢ããæ
å ±ã $M$ åäžãããã. $i$ çªç®ã®æ
å ±ã¯ã$a_i$ $b_i$ããšãã圢åŒã§äžããã, ãã㯠$a_i$ ãªãã° $b_i$ ã§ããããšã衚ã.ïŒããªãã°ãã¯è«çå
å«ã§ãããæšç§»åŸãæãç«ã€ïŒ</br>
ååœé¡ $i$ ã«å¯Ÿã㊠$i$ ãšåå€ãªåœé¡ãå
šãŠæé ã«åºåãã.</br>
ãã ãåœé¡ $i$ ãšåœé¡ $i$ ã¯åžžã«åå€ã§ãã.</br>
åœé¡ $X$ ãšåœé¡ $Y$ ãåå€ãšã¯,ã$X$ ãªãã° $Y$ããã€ã$Y$ ãªãã° $X$ãã®ããšã§ãã.
</p>
<h2>å¶çŽ</h2>
<ul>
<li>å
¥åå€ã¯å
šãп޿°ã§ãã.</li>
<li>$ 2 \leq N \leq 300$</li>
<li>$ 1 \leq M \leq N(N - 1)$</li>
<li>$ a_i \neq b_i $</li>
<li>$1 \leq a_i, b_i \leq N $</li>
</ul>
<h2>å
¥å圢åŒ</h2>
<p> å
¥åã¯ä»¥äžã®åœ¢åŒã§äžãããã. </p>
<p>
$N\ M$<br>
$a_1\ b_1$<br>
$a_2\ b_2$<br>
$\vdots$<br>
$a_M\ b_M$<br>
</p>
<h2>åºå</h2>
<p>
$i$ è¡ç®ã«ã¯åœé¡ $i$ ãšåå€ã§ããåœé¡ãæé ã«ç©ºçœåºåãã§ãã¹ãŠåºåãã. ãŸã, åè¡ã®æ«å°Ÿã«æ¹è¡ãåºåãã.
</p>
<h2>ãµã³ãã«</h2>
<h3>ãµã³ãã«å
¥å 1</h3>
<pre>
5 2
1 2
2 1
</pre>
<h3>ãµã³ãã«åºå 1</h3>
<pre>
1 2
1 2
3
4
5
</pre>
<h3>ãµã³ãã«å
¥å 2</h3>
<pre>
3 3
1 2
2 3
3 1
</pre>
<h3>ãµã³ãã«åºå 2</h3>
<pre>
1 2 3
1 2 3
1 2 3
</pre>
<h3>ãµã³ãã«å
¥å 3</h3>
<pre>
6 7
1 2
1 3
2 6
3 4
4 5
5 3
6 2
</pre>
<h3>ãµã³ãã«åºå 3</h3>
<pre>
1
2 6
3 4 5
3 4 5
3 4 5
2 6
</pre>
|
p00849 |
<H1><font color="#000">Problem E:</font> Manhattan Wiring</H1>
<p>
There is a rectangular area containing <i>n</i> × <i>m</i> cells. Two cells are marked with "2", and another two with "3". Some cells are occupied by obstacles. You should connect the two "2"s and also the two "3"s with non-intersecting lines. Lines can run only vertically or horizontally connecting
centers of cells without obstacles.
</p>
<p>
Lines cannot run on a cell with an obstacle. Only one line can run on a cell at most once. Hence,
a line cannot intersect with the other line, nor with itself. Under these constraints, the total
length of the two lines should be minimized. The length of a line is defined as the number of
cell borders it passes. In particular, a line connecting cells sharing their border has length 1.
</p>
<p>
Fig. 6(a) shows an example setting. Fig. 6(b) shows two lines satisfying the constraints above
with minimum total length 18.
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_manhattanWiring">
<p>
Figure 6: An example setting and its solution
</p>
</center>
<H2>Input</H2>
<p>
The input consists of multiple datasets, each in the following format.
</p>
<pre>
<i>n m</i>
row<sub>1</sub>
...
row<sub><i>n</i></sub>
</pre>
<p>
<i>n</i> is the number of rows which satisfies 2 ≤ <i>n</i> ≤ 9. <i>m</i> is the number of columns which satisfies
2 ≤ <i>m</i> ≤ 9. Each row<sub><i>i</i></sub> is a sequence of <i>m</i> digits separated by a space. The digits mean the
following.
</p>
<p><span>0</span>: Empty</p>
<p><span>1</span>: Occupied by an obstacle</p>
<p><span>2</span>: Marked with "2"</p>
<p><span>3</span>: Marked with "3"</p>
<p>
The end of the input is indicated with a line containing two zeros separated by a space.
</p>
<H2>Output</H2>
<p>
For each dataset, one line containing the minimum total length of the two lines should be output.
If there is no pair of lines satisfying the requirement, answer "0" instead. No other characters
should be contained in the output.
</p>
<H2>Sample Input</H2>
<pre>
5 5
0 0 0 0 0
0 0 0 3 0
2 0 2 0 0
1 0 1 1 1
0 0 0 0 3
2 3
2 2 0
0 3 3
6 5
2 0 0 0 0
0 3 0 0 0
0 0 0 0 0
1 1 1 0 0
0 0 0 0 0
0 0 2 3 0
5 9
0 0 0 0 0 0 0 0 0
0 0 0 0 3 0 0 0 0
0 2 0 0 0 0 0 2 0
0 0 0 0 3 0 0 0 0
0 0 0 0 0 0 0 0 0
9 9
3 0 0 0 0 0 0 0 2
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 3
9 9
0 0 0 1 0 0 0 0 0
0 2 0 1 0 0 0 0 3
0 0 0 1 0 0 0 0 2
0 0 0 1 0 0 0 0 3
0 0 0 1 1 1 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
9 9
0 0 0 0 0 0 0 0 0
0 3 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 2 3 2
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
18
2
17
12
0
52
43
</pre>
|
p02874 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><var>10^9</var> contestants, numbered <var>1</var> to <var>10^9</var>, will compete in a competition.
There will be two contests in this competition.</p>
<p>The organizer prepared <var>N</var> problems, numbered <var>1</var> to <var>N</var>, to use in these contests.
When Problem <var>i</var> is presented in a contest, it will be solved by all contestants from Contestant <var>L_i</var> to Contestant <var>R_i</var> (inclusive), and will not be solved by any other contestants.</p>
<p>The organizer will use these <var>N</var> problems in the two contests.
Each problem must be used in exactly one of the contests, and each contest must have at least one problem.</p>
<p>The <em>joyfulness</em> of each contest is the number of contestants who will solve all the problems in the contest.
Find the maximum possible total joyfulness of the two contests.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10^5</var></li>
<li><var>1 \leq L_i \leq R_i \leq 10^9</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>L_1</var> <var>R_1</var>
<var>L_2</var> <var>R_2</var>
<var>\vdots</var>
<var>L_N</var> <var>R_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible total joyfulness of the two contests.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
4 7
1 4
5 8
2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>The optimal choice is:</p>
<ul>
<li>Use Problem <var>1</var> and <var>3</var> in the first contest. Contestant <var>5</var>, <var>6</var>, and <var>7</var> will solve both of them, so the joyfulness of this contest is <var>3</var>.</li>
<li>Use Problem <var>2</var> and <var>4</var> in the second contest. Contestant <var>2</var>, <var>3</var>, and <var>4</var> will solve both of them, so the joyfulness of this contest is <var>3</var>.</li>
<li>The total joyfulness of these two contests is <var>6</var>. We cannot make the total joyfulness greater than <var>6</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 20
2 19
3 18
4 17
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>34
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
457835016 996058008
456475528 529149798
455108441 512701454
455817105 523506955
457368248 814532746
455073228 459494089
456651538 774276744
457667152 974637457
457293701 800549465
456580262 636471526
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>540049931
</pre></section>
</div>
</span> |
p03766 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>How many infinite sequences <var>a_1, a_2, ...</var> consisting of {<var>{1, ... ,n}</var>} satisfy the following conditions?</p>
<ul>
<li>The <var>n</var>-th and subsequent elements are all equal. That is, if <var>n \leq i,j</var>, <var>a_i = a_j</var>.</li>
<li>For every integer <var>i</var>, the <var>a_i</var> elements immediately following the <var>i</var>-th element are all equal. That is, if <var>i < j < k\leq i+a_i</var>, <var>a_j = a_k</var>.</li>
</ul>
<p>Find the count modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq n \leq 10^6</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>n</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print how many sequences satisfy the conditions, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>The four sequences that satisfy the conditions are:</p>
<ul>
<li><var>1, 1, 1, ...</var></li>
<li><var>1, 2, 2, ...</var></li>
<li><var>2, 1, 1, ...</var></li>
<li><var>2, 2, 2, ...</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>654321
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>968545283
</pre></section>
</div>
</span> |
p03336 | <span class="lang-en">
<p>Score : <var>2400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi and Aoki love calculating things, so they will play with numbers now.</p>
<p>First, they came up with one positive integer each. Takahashi came up with <var>X</var>, and Aoki came up with <var>Y</var>.
Then, they will enjoy themselves by repeating the following operation <var>K</var> times:</p>
<ul>
<li>Compute the bitwise AND of the number currently kept by Takahashi and the number currently kept by Aoki. Let <var>Z</var> be the result.</li>
<li>Then, add <var>Z</var> to both of the numbers kept by Takahashi and Aoki.</li>
</ul>
<p>However, it turns out that even for the two math maniacs this is just too much work.
Could you find the number that would be kept by Takahashi and the one that would be kept by Aoki eventually?</p>
<p>Note that input and output are done in binary.
Especially, <var>X</var> and <var>Y</var> are given as strings <var>S</var> and <var>T</var> of length <var>N</var> and <var>M</var> consisting of <code>0</code> and <code>1</code>, respectively, whose initial characters are guaranteed to be <code>1</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †K †10^6</var></li>
<li><var>1 †N,M †10^6</var></li>
<li>The initial characters of <var>S</var> and <var>T</var> are <code>1</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var> <var>K</var>
<var>S</var>
<var>T</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>In the first line, print the number that would be kept by Takahashi eventually; in the second line, print the number that would be kept by Aoki eventually.
Those numbers should be represented in binary and printed as strings consisting of <code>0</code> and <code>1</code> that begin with <code>1</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 3
11
101
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10000
10010
</pre>
<p>The values of <var>X</var> and <var>Y</var> after each operation are as follows:</p>
<ul>
<li>After the first operation: <var>(X,Y)=(4,6)</var>.</li>
<li>After the second operation: <var>(X,Y)=(8,10)</var>.</li>
<li>After the third operation: <var>(X,Y)=(16,18)</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 8 3
10101
10101001
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>100000
10110100
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 10 10
1100110011
1011001101
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>10000100000010001000
10000100000000100010
</pre></section>
</div>
</span> |
p01425 |
<H1>White Bird</H1>
<p>
Angry Birds is a mobile game of a big craze all over the world.
You were convinced that it was a waste of time to play the game, so you decided to create an automatic solver.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_2308-bird-3">
</center>
<p>
You are describing a routine that optimizes the white bird's strategy to defeat a pig (enemy) by hitting an egg bomb.
The white bird follows a parabolic trajectory from the initial position,
and it can vertically drop egg bombs on the way.
</p>
<p>
In order to make it easy to solve, the following conditions hold for the stages.
</p>
<ul>
<li><var>N</var> obstacles are put on the stage.</li>
<li>Each obstacle is a rectangle whose sides are parallel to the coordinate axes.</li>
<li>The pig is put on the point <var>(X, Y)</var>.</li>
<li>You can launch the white bird in any direction at an initial velocity <var>V</var> from the origin.</li>
<li>If the white bird collides with an obstacle, it becomes unable to drop egg bombs.</li>
<li>If the egg bomb collides with an obstacle, the egg bomb is vanished.</li>
</ul>
<p>
The acceleration of gravity is <var>9.8 {\rm m/s^2}</var>.
Gravity exerts a force on the objects in the decreasing direction of <var>y</var>-coordinate.
</p>
<H2>Input</H2>
<p>
A dataset follows the format shown below:
</p>
<p>
<var>N</var> <var>V</var> <var>X</var> <var>Y</var><br/>
<var>L_1</var> <var>B_1</var> <var>R_1</var> <var>T_1</var><br/>
<var>...</var><br/>
<var>L_N</var> <var>B_N</var> <var>R_N</var> <var>T_N</var><br/>
</p>
<p>
All inputs are integer.
</p>
<ul>
<li><var>N</var>: the number of obstacles</li>
<li><var>V</var>: the initial speed of the white bird</li>
<li><var>X</var>, <var>Y</var>: the position of the pig</li>
</ul>
<p>
(<var>0 \leq N \leq 50</var>, <var>0 \leq V \leq 50</var>, <var>0 \leq X, Y \leq 300</var>, <var>X \neq 0</var>)
</p>
<p>
for <var>1 \leq i \leq N,</var>
</p>
<ul>
<li><var>L_i</var>: the x-coordinate of the left side of the <var>i</var>-th obstacle</li>
<li><var>B_i</var>: the y-coordinate of the bottom side of the <var>i</var>-th obstacle</li>
<li><var>R_i</var>: the x-coordinate of the right side of the <var>i</var>-th obstacle</li>
<li><var>T_i</var>: the y-coordinate of the top side of the <var>i</var>-th obstacle</li>
</ul>
<p>
(<var>0 \leq L_i, B_i, R_i, T_i \leq 300</var>)
</p>
<p>
It is guaranteed that the answer remains unaffected by a change of <var>L_i</var>, <var>B_i</var>, <var>R_i</var> and <var>T_i</var> in <var>10^{-6}</var>.
</p>
<H2>Output</H2>
<p>
Yes/No<br/>
</p>
<p>
You should answer whether the white bird can drop an egg bomb toward the pig.
</p>
<H2>Sample Input 1</H2>
<pre>
0 7 3 1
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
Yes
</pre>
<H2>Sample Input 2</H2>
<pre>
1 7 3 1
1 1 2 2
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
No
</pre>
<H2>Sample Input 3</H2>
<pre>
1 7 2 2
0 1 1 2
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>
No
</pre>
|
p03418 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi had a pair of two positive integers not exceeding <var>N</var>, <var>(a,b)</var>, which he has forgotten.
He remembers that the remainder of <var>a</var> divided by <var>b</var> was greater than or equal to <var>K</var>.
Find the number of possible pairs that he may have had.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>0 \leq K \leq N-1</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of possible pairs that he may have had.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7
</pre>
<p>There are seven possible pairs: <var>(2,3),(5,3),(2,4),(3,4),(2,5),(3,5)</var> and <var>(4,5)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>100
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>31415 9265
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>287927211
</pre></section>
</div>
</span> |
p01075 |
<h1>Problem D: One-Time Path</h1>
<h2>Problem</h2>
<p>
<var>N</var>åã®å³¶ãš<var>M</var>æ¬ã®æ©ãããã
<var>N</var>åã®å³¶ã«ã¯ãããã1ãã<var>N</var>ãŸã§ã®çªå·ãå²ãæ¯ãããŠããã
<var>M</var>æ¬ã®æ©ã«ããããã1ãã<var>M</var>ãŸã§ã®çªå·ãå²ãæ¯ãããŠããã
</p>
<p>
ãã£ã¡ãåã¯çŸåš(æå»0ã®æç¹ã§)ã1çªç®ã®å³¶ã«ããã
ãã£ã¡ãåã¯<var>i</var>çªç®ã®æ©ãå©çšããããšã«ããã<var>a<sub>i</sub></var>çªç®ã®å³¶ãã<var>b<sub>i</sub></var>çªç®ã®å³¶ãžãšåæ¹åã«ç§»åããããšãã§ããã
</p>
<p>
ããããæå»0ã®æç¹ã§ã¯ããã¹ãŠã®æ©ã¯æœ®ãæºã¡ãŠããŠæµ·ã®äžã«æ²ãã§ããŸã£ãŠããã
<var>i</var>çªç®ã®æ©ã¯ãæå»<var>c<sub>i</sub></var>ã«ãªããšæœ®ãåŒããŠæž¡ããããã«ãªãã
ãããŠãæå»<var>c<sub>i</sub></var>ãéãããšãããã«ãŸãæœ®ãæºã¡ãŠ<var>i</var>çªç®ã®æ©ã¯åã³æ²ãã§ããŸãã
åã³æ²ãã§ããŸããšããŸããã€æœ®ãåŒããŠæž¡ããããã«ãªããã¯ããããªãã
ããã§ããã£ã¡ãåã¯ãããªã£ãæ©ã¯æ°žé ã«æž¡ããªããªããšèããããã«ããã
</p>
<p>
ãã£ã¡ãåã¯ãã§ããã ãé·ãéã1ãã<var>N</var>-1çªç®ã®å³¶ã®æ¯è²ãçºããŠãããã®ã ãã<var>N</var>çªç®ã®å³¶ã«è¹ãæ³ããŠããã®ã§ãæçµçã«ã¯<var>N</var>çªç®ã®å³¶ã«å°çããŠããªããã°ãªããªãããŸããè¹ã®äžã§äž¡èŠªãåŸ
ãããŠããããããã£ã¡ãåã¯<var>N</var>çªç®ã®å³¶ã«ã€ãããããã«è¹ã§åºçºããŠå®¶ãžãšåž°ããªããã°ãªããªãã
</p>
<p>
ãã£ã¡ãåãæ©ãæž¡ã£ããå³¶ã®äžãç§»åããæéã¯ãšãŠãçãã®ã§ã0ãšä»®å®ããŠããããã£ã¡ãåã1ãã<var>N</var>-1çªç®ã®ããããã®å³¶ã«ããããšã®ã§ããæéã®æå€§å€ãæ±ããããã ããã©ã®ããã«ç§»åããŠããã£ã¡ãåã<var>N</var>çªç®ã®å³¶ãžãšç§»åã§ããªãå Žåã¯ä»£ããã«-1ãåºåããã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
<var>N</var> <var>M</var>
<var>a<sub>1</sub></var> <var>b<sub>1</sub></var> <var>c<sub>1</sub></var>
<var>a<sub>2</sub></var> <var>b<sub>2</sub></var> <var>c<sub>2</sub></var>
âŠ
<var>a<sub>M</sub></var> <var>b<sub>M</sub></var> <var>c<sub>M</sub></var>
</pre>
<p>
1è¡ç®ã«ã¯ã2ã€ã®æŽæ°<var>N</var>, <var>M</var>ã空çœåºåãã§äžããããã<br>
2è¡ç®ãã<var>M</var>+1è¡ç®ã®ããããã®è¡<var>i</var>ã«ã¯ã3ã€ã®æŽæ°<var>a<sub>i</sub></var>, <var>b<sub>i</sub></var>, <var>c<sub>i</sub></var>ã空çœåºåãã§äžããããã
</p>
<h2>Constraints</h2>
<ul>
<li>2 ≤ <var>N</var> ≤ 10<sup>5</sup></li>
<li>1 ≤ <var>M</var> ≤ 2 × 10<sup>5</sup></li>
<li>1 ≤ <var>a<sub>i</sub></var> < <var>N</var></li>
<li>1 ≤ <var>b<sub>i</sub></var> ≤ <var>N</var></li>
<li>1 ≤ <var>c<sub>i</sub></var> ≤ 10<sup>9</sup></li>
<li><var>a<sub>i</sub></var> ≠ <var>b<sub>i</sub></var></li>
</ul>
<h2>Output</h2>
<p>
ãã£ã¡ãåã<var>N</var>çªç®ã®å³¶ãžãšç§»åã§ããå Žåã¯ããã£ã¡ãåã1ãã<var>N</var>-1çªç®ã®ããããã®å³¶ã«ããããšã®ã§ããæéã®æå€§å€ãåºåããã<var>N</var>çªç®ã®å³¶ãžãšç§»åã§ããªãå Žåã¯ã代ããã«-1ãåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
3 2
1 2 10
2 3 20
</pre>
<h2>Sample Output 1</h2>
<pre>
20
</pre>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2016Day2AIZU_D_sample1" alt="å³1" style="width: 70px"><br>
ãŸãã1çªç®ã®å³¶ã§æå»ã10ã«ãªããŸã§åŸ
ã£ãŠããã2çªç®ã®å³¶ãžãšç§»åããã<br>
次ã«ã2çªç®ã®å³¶ã§æå»ã20ã«ãªããŸã§åŸ
ã£ãŠããã3çªç®ã®å³¶ãžãšç§»åããã<br>
以äžããã1ãã2çªç®ã®ããããã®å³¶ã«ããæéã¯20ãšãªãã
</p>
<h2>Sample Input 2</h2>
<pre>
4 4
1 2 27
1 3 37
2 3 47
3 1 57
</pre>
<h2>Sample Output 2</h2>
<pre>
-1
</pre>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2016Day2AIZU_D_sample2" alt="å³2" style="width: 200px"><br>
4çªç®ã®å³¶ã«ç¹ããæ©ããªãããã4çªç®ã®å³¶ãžç§»åããããšãã§ããªãã
</p>
<h2>Sample Input 3</h2>
<pre>
3 3
1 2 13
2 3 17
2 3 15
</pre>
<h2>Sample Output 3</h2>
<pre>
17
</pre>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2016Day2AIZU_D_sample3" alt="å³3" style="width: 70px"><br>
</p>
<h2>Sample Input 4</h2>
<pre>
3 2
1 2 20
2 3 10
</pre>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2016Day2AIZU_D_sample4" alt="å³4" style="width: 70px">
</p>
<h2>Sample Output 4</h2>
<pre>
-1
</pre>
<h2>Sample Input 5</h2>
<pre>
3 2
1 2 10
2 3 10
</pre>
<h2>Sample Output 5</h2>
<pre>
10
</pre> |
p03048 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes:</p>
<ul>
<li>Red boxes, each containing <var>R</var> red balls</li>
<li>Green boxes, each containing <var>G</var> green balls</li>
<li>Blue boxes, each containing <var>B</var> blue balls</li>
</ul>
<p>Snuke wants to get a total of exactly <var>N</var> balls by buying <var>r</var> red boxes, <var>g</var> green boxes and <var>b</var> blue boxes.
How many triples of non-negative integers <var>(r,g,b)</var> achieve this?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq R,G,B,N \leq 3000</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>R</var> <var>G</var> <var>B</var> <var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 2 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>Four triples achieve the objective, as follows:</p>
<ul>
<li><var>(4,0,0)</var></li>
<li><var>(2,1,0)</var></li>
<li><var>(1,0,1)</var></li>
<li><var>(0,2,0)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>13 1 4 3000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>87058
</pre></section>
</div>
</span> |
p02209 | <h2>ã«ãŒãã¯ããã€ã«å
¥ããŸããïŒ(Are Cards Snacks?)</h2>
<p>square1001å㯠$N$ æã®ã«ãŒããæã£ãŠããŸãã</p>
<p>ãããã®ã«ãŒãã«ã¯ããããæŽæ°ãæžãããŠããã$i$ æç®ã®ã«ãŒãã«æžãããŠããæŽæ°ã¯ $A_i$ ã§ãã</p>
<p>square1001åã®ä»æ¥ã®ä¹±æ°ã¯ $K$ ã§ããsquare1001åã¯ãããã® $N$ æã®ã«ãŒãã®äžããäœæãã®ã«ãŒããéžã³ãåèšã $K$ ãšãªãããã«ãããã§ãã</p>
<p>ãã®æ§åãèŠãŠããE869120åã¯ãããã黿¢ããããšèããŸããã</p>
<p>å
·äœçã«ã¯ãäºåã«äœæãã®ã«ãŒããé£ã¹ãããšã§ãsquare1001 åãã©ã®ããã«æ®ãã®ã«ãŒããéžãã§ãåèšã $K$ ãšãªããªãããã«ãããã§ãã</p>
<p>ããããE869120 åã¯æºè
¹ã§ããããããªãã¹ãã«ãŒããé£ã¹ãããããŸããã</p>
<p>ããŠãE869120 åã¯æäœäœæã®ã«ãŒããé£ã¹ãããšã§ããã黿¢ã§ããŸããïŒ</p>
<h3>å
¥å</h3>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã</p>
<pre>
$N$ $K$
$A_1$ $A_2$ $A_3$ $\cdots$ $A_N$
</pre>
<h3>åºå</h3>
<p>E869120 åãç®çãéæããããã«é£ã¹ãã«ãŒãã®ææ°ã®æå°å€ãã1 è¡ã§åºåããªããã</p>
<p>ãã ããæåŸã«ã¯æ¹è¡ãå
¥ããããšã</p>
<h3>å¶çŽ</h3>
<ul>
<li>$1 \leq N \leq 20$</li>
<li>$1 \leq K \leq 1000000000 \ (= 10^9)$</li>
<li>$0 \leq A_i \leq 1000000 \ (= 10^6)$</li>
<li>å
¥åã¯å
šãп޿°ã§ããã</li>
</ul>
<h3>å
¥åäŸ1</h3>
<pre>
5 9
8 6 9 1 2
</pre>
<h3>åºåäŸ1</h3>
<pre>
2
</pre>
<p>äŸãã°ã3 çªç®ã®ã«ãŒã (9 ãæžãããŠãã) ãš 4 çªç®ã®ã«ãŒã (1 ãæžãããŠãã) ãé£ã¹ãããšã§ãsquare1001 åã®ç®çã黿¢ããããšãã§ããŸãã</p>
<h3>å
¥åäŸ2</h3>
<pre>
8 2
1 1 1 1 1 1 1 1
</pre>
<h3>åºåäŸ2</h3>
<pre>
7
</pre>
<h3>å
¥åäŸ3</h3>
<pre>
20 200
31 12 21 17 19 29 25 40 5 8 32 1 27 20 31 13 35 1 8 5
</pre>
<h3>åºåäŸ3</h3>
<pre>
6
</pre>
|
p00234 |
<H1>äŒæŽ¥ã®åèµé</H1>
<p>
äŒæŽ¥ã«ã¯å€ãããäŒããåèµéã®äŒèª¬ããããŸããããªãã¯ãéã«åèµéãåãŸã£ãŠããå Žæãçªãæ¢ããŸãããåèµéãåãŸã£ãŠããæ·±ããæãé²ããå°å±€ã®ç¶æ
ãåãã£ãŠããã®ã§ãç¶¿å¯ã«èšç»ãç«ãŠãã°æå°è²»çšã§åèµéãŸã§å°éããããšãã§ããŸããããã§ããªãã¯ãå°å±€ã®ç¶æ
ãèªã¿åã£ãŠåèµéã®åãŸã£ãŠããæ·±ããŸã§æå°è²»çšã§å°éããã«ãŒããç®åºããããã°ã©ã ãäœæããããšã«ããŸããã
</p>
<p>å°å±€ã®ç¶æ
㯠2 次å
æ Œåç¶ã«é
眮ãããã»ã«ã§è¡šããããåã»ã«ã®äœçœ®ã¯åº§æš (x,y) ã§è¡šãããŸããå·Šäžã (1,1) ãšããx 座æšã¯å³ã«è¡ãã«ã€ããŠå€§ãããªããy 座æšã¯äžã«æ·±ããªãã«ã€ããŠå€§ãããªããã®ãšããŸããããªã㯠y 座æšã®äžçªå°ããã»ã«ã®ãã¡äžã€ãéžãã§ããããæãå§ããy 座æšã®äžçªå€§ããã»ã«ã®äžã€ãŸã§æãé²ããŸããå°å±€ã«ã¯ä»¥äžã® 2 çš®é¡ã®ã»ã«ããããŸãïŒ
</p>
<ol>
<li>åã®è©°ãŸã£ãã»ã«ãæãã®ã«ãã»ã«ããšã«æ±ºããããè²»çšããããã</li>
<li>é
žçŽ ã®ããŸã£ãã»ã«ãæãå¿
èŠã¯ãªããã»ã«ããšã«æ±ºãŸã£ãéã®é
žçŽ ãè£çµŠã§ãããäžåºŠé
žçŽ ãè£çµŠããã»ã«ã®é
žçŽ ã¯ãªããªããå床ã®è£çµŠã¯ã§ããªãããŸãããã®ã»ã«ã«èŸ¿ãã€ãããå¿
ãé
žçŽ ã®è£çµŠãããªããã°ãªããªãã</li>
</ol>
<p>
ããã»ã«ããæãããšãã§ããã®ã¯å·Šå³ãšäžæ¹åã®ã»ã«ã®ã¿ã§ãã
äžåºŠæã£ãã»ã«ãå·Šå³ã«ç§»åããããšã¯ã§ããŸãããäžã«ç§»åããããšã¯ã§ããŸããã
</p>
<p>çºæã«ããã£ãŠã¯ãé
žçŽ ãã³ããæºåž¯ããªããã°ãªããŸãããé
žçŽ ãã³ãã®æ®éã 0 ã«ãªã£ãç¬éãç§»åãçºæãé
žçŽ ã®è£çµŠãã§ããªããªããŸããæ®éã¯ã»ã«ãç§»åãããã³ã« 1 æžããŸããé
žçŽ ãã³ãã®æ®éã 0 ã§åèµéã®åãŸã£ãŠããæ·±ããŸã§å°éããŠããå°éãããšã¿ãªãããŸããããŸããé
žçŽ ã®ããŸã£ãã»ã«ã§ã¯é
žçŽ ãè£çµŠããããšãã§ããŸããã容éãè¶
ããåã¯å»æ£ãããŸãã</p>
<p>
å°å±€ã®ãµã€ãº ãçºæè²»çšãé
žçŽ ãã³ãã®å®¹éãåæç¶æ
ã§æã£ãŠããé
žçŽ ã®éãå°å±€ã®æ
å ±ãå
¥åãšããäžçªæ·±ãã»ã«ãŸã§ãã©ãã€ãããã®æå°è²»çšãåºåããããã°ã©ã ãäœæããŠãã ããããã ããæå°è²»çšãçºæè²»çšãè¶
ããŠããŸãå Žåããã©ã®ããã«æãé²ããŠãåèµéã«ãã©ãã€ããªãå Žåã¯âNAâãšåºåããŠãã ããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_aizuTreasure">
</center>
<br>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžãããããå
¥åã®çµããã¯ãŒããµãã€ã®è¡ã§ç€ºãããã
åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>W</var> <var>H</var>
<var>f</var> <var>m</var> <var>o</var>
<var>c<sub>1,1</sub></var> <var>c<sub>2,1</sub></var> ... <var>c<sub>W,1</sub></var>
<var>c<sub>1,2</sub></var> <var>c<sub>2,2</sub></var> ... <var>c<sub>W,2</sub></var>
...
<var>c<sub>1,H</sub></var> <var>c<sub>2,H</sub></var> ... <var>c<sub>W,H</sub></var>
</pre>
<p>
ïŒè¡ç®ã«å°å±€ã®æšªæ¹åã®ãµã€ãº <var>W</var>, 瞊æ¹åã®ãµã€ãº <var>H</var> (3 ≤ <var>W</var>, <var>H</var> ≤ 10) ãäžããããã ïŒè¡ç®ã«ããªãã®çºæè²»çšãè¡šãæŽæ° <var>f</var> (1 ≤ <var>f</var> ≤ 10000)ãé
žçŽ ãã³ãã®å®¹éãè¡šãæŽæ° <var>m</var> (3 ≤ <var>m</var> ≤ 50)ãåæç¶æ
ã§æã£ãŠããé
žçŽ ã®éãè¡šãæŽæ° <var>o</var> (o ≤ <var>m</var>) ãäžããããã
</p>
<p>ç¶ã <var>H</var> è¡ã«å°å±€ã®æ
å ± <var>c<sub>i,j</sub></var> ãäžããããã<var>c<sub>i,j</sub></var> ã¯ãåº§æš (<var>i</var>, <var>j</var>) ã«å¯Ÿããã»ã«ã®æ
å ±ã衚ãã以äžã®åœ¢åŒã§äžããããïŒ<br>
è² ã®å€ã®å Žåãåã®è©°ãŸã£ãã»ã«ã§ãå€ã¯è²»çšã衚ã<br>
æ£ã®å€ã®å Žåãé
žçŽ ã®ããŸã£ãã»ã«ã§ãå€ã¯é
žçŽ ã®éã衚ã<br>
ãã ããé
žçŽ ã®ããŸã£ãã»ã«ã¯ 50 ç®æä»¥å
ã§ããã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯50 ãè¶
ããªãã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããããšã«ãæå°è²»çšãŸã㯠NA ã1è¡ã«åºåããã
</p>
<H2>Sample Input</H2>
<pre>
3 3
100 10 10
-100 -20 -100
-100 -20 -100
-100 -20 -100
3 3
100 10 10
-100 -20 -100
-100 -20 -20
-100 -60 -20
3 3
100 10 3
-100 -20 -100
-20 -20 -20
-20 -100 -20
3 3
100 3 3
-100 -20 -30
-100 -20 2
-100 -20 -20
4 5
1500 5 4
-10 -380 -250 -250
-90 2 -80 8
-250 -130 -330 -120
-120 -40 -50 -20
-250 -10 -20 -150
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
60
80
NA
50
390
</pre>
|
p02659 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Compute <var>A \times B</var>, truncate its fractional part, and print the result as an integer.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 \leq A \leq 10^{15}</var></li>
<li><var>0 \leq B < 10</var></li>
<li><var>A</var> is an integer.</li>
<li><var>B</var> is a number with two digits after the decimal point.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer as an integer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>198 1.10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>217
</pre>
<p>We have <var>198 \times 1.10 = 217.8</var>. After truncating the fractional part, we have the answer: <var>217</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 0.01
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1000000000000000 9.99
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>9990000000000000
</pre></section>
</div>
</span> |
p00664 |
<H1>Problem F: Cosmic Market</H1>
<p>
Cosmic market(ã³ãºããã¯ã»ããŒã±ãã)ãéç§°ã³ãºãã±ãã¯å
šå®å®æå€§èŠæš¡ã®å人å³å£²äŒã ã
ã³ãºãã±ã«ã¯ãããããžã£ã³ã«ã®å人æå¥œå®¶éãéãã
è¿å¹Žãã³ãºãã±ãžã®æ¥å Žè
ã¯å¢å åŸåã«ããã
æåããå
šãŠã®äººãå
¥å Žã§ãããšå€§å€æ··éããŠå±éºãªã®ã§ãéå ŽçŽåŸã¯å
¥å ŽèŠå¶ãè¡ã£ãŠããã
ããäžå®äººæ°ã®äººã ããéå Žãšåæã«å
¥å Žããããšãåºæ¥ãã®ã ã
ãã以å€ã®äººãã¡ã¯ãã°ããåŸ
ã£ãŠããã®å
¥å Žãšãªã£ãŠããã
</p>
<p>
ãããå
çé ã«äŒå Žã«å
¥ãããšã«ãããšã培å€ã§åæ¥ãã䞊ã¶äººãåºãŠããŸãã
ã³ãºãã±ã®åå è
ã«ã¯æªæå¹Žãå€ããæ²»å®äžã®åé¡ãããã®ã§å
çé ãšããæ±ºãæ¹ã¯ãšãŠãè¯ããªãã
ããããçç±ããã£ãŠãã³ãºãã±ã§ã¯åå è
ã®äžã§ããçš®ã®ã²ãŒã ãè¡ãããã®ã²ãŒã ã§åã¡æ®ã£ã人ãæåã«å
¥å Žããæš©å©ãæã«ã§ããã
å
¬å¹³ãæãããã«æ¯å¹Žã©ã³ãã æ§ã®é«ãã²ãŒã ãæ¡çšããŠããã
</p>
<p>
åã¯ä»åãã³ãºãã±ã«åå ããäºå®ã ã
åã¯ä»åã®ã³ãºãã±ã§ã©ãããŠãæã«å
¥ãããå人èªãããã
ãšãã人æ°ãµãŒã¯ã«ãé åžããå人èªã§ãä»å¹Žã®æ¥ã«è©±é¡ã«ãªã£ãéæ³å°å¥³ã®ã¢ãã¡ãåãæ±ã£ãŠããã
ãããããã®ãµãŒã¯ã«ã¯ãšãŠã人æ°ã§æ¯åããã«é åžãçµäºããŠããŸãã
éå Žãšåæã«å
¥å Žã§ããªãã£ãå Žåã«æã«å
¥ããããšã¯ã»ãŒäžå¯èœã ããã
ãã¡ããåŸæ¥å人ã·ã§ãããªã©ã§ãæã«å
¥ãããã«ãªãã®ã¯ééããªããããããããŸã§ææ
¢ããããšãªã©åã«ã¯åºæ¥ãªãã
åã¯ã©ããªæã䜿ã£ãŠã§ãã³ãºãã±åœæ¥ã«æã«å
¥ããªããŠã¯ãããªãã®ã ã
äžå¹žãªããšã«åã¯ä»ãŸã§ã®ã³ãºãã±ã§æåã«å
¥å Žã§ããããšã¯äžåºŠããªãã
</p>
<p>
ã³ãºãã±ã®ã«ã¿ãã°ã«ãããšãä»åã¯ä»¥äžã®ãããªã²ãŒã ã§æåã«å
¥å Žã§ãã人ãéžã¶ãããã
ãŸãåå è
ã®ãã¡å
ç <i>r</i>Ã<i>c</i> 人ã®äººãã<i>r</i>Ã<i>c</i>ãã®ã°ãªããã®ããã«é
眮ããã座åžã®å¥œããªå Žæã«åº§ãã
å
çé ã§å Žæãéžã¹ãã®ã§æ©ãè¡ã£ãæ¹ãéžæè¢ã沢山ããã
<i>r</i>Ã<i>c</i> 人ã®äººã座ã£ããã²ãŒã ãå§ãŸãã
ãã®ã²ãŒã ã¯ããäžå®ã®åæ°ããã1ã€ã®åïŒè¡ïŒã®åº§åžã«ããå
šãŠã®äººã«å¯ŸããŠãçåžããããã¯èµ·ç«ãæç€ºãããã
ãã§ã«çåžããŠãã人ã«çåžã®æç€ºãåºãããå Žåã¯ãã®ãŸãŸåŸ
æ©ããã°ãèµ·ç«ããŠãã人ãåæ§ã§ããã
ãã®æç€ºãåºããã察象ã®åïŒè¡ïŒãšæç€ºã®å
容ã¯ã©ã³ãã ã«ã«ãŒã¬ããã§æ±ºããããã
ããäžå®ã®åæ°ã®æç€ºãçµãã£ãæç¹ã§èµ·ç«ããŠãã人ã ããæåã«éå Žã«å
¥ããã®ã ã
æç€ºã®åæ°ã¯åå è
ã«ã¯ç¥ããããŠããªãã®ã§ããã€ã²ãŒã ãçµãããåãããªãã
ãªã®ã§ããæç¹ã§ç«ã£ãŠãã人ã座ã£ãŠãã人ãèªåãæåã«å
¥å Žã§ãããã¯åãããªãã
ã ããã¹ãªã«ãå³ããããšãåºæ¥ãããšã«ã¿ãã°ã§ã¯åŒ·èª¿ãããŠããã
</p>
<p>
ã³ãºãã±åæ¥ã®ååŸ1æãåã¯ä»å¹Žã®ã²ãŒã ã«é¢ããããŒã¿ããã¹ãŠæã«å
¥ããã
åãæã«å
¥ããæ
å ±ã«ãããšããã®æç€ºã®åæ°ã<i>q</i> ã¯ãã§ã«æ±ºãŸã£ãŠããã
ããã©ããã<i>q</i> åã®æç€ºå
容ãå
šãŠããã§ã«æ±ºãŸã£ãŠããã
ã©ã³ãã æ§ãé«ããªã©ãšããããŠãããããã¯åã ã£ãã®ã ã
ã©ãããçç±ããã£ãŠäºåã«æ±ºãŸã£ãŠããã®ãã¯åãããªãã
ããããã®æ
å ±ã¯åã«ãšã£ãŠã¯å€©ã®æµã¿ã®ããã ã
</p>
<p>
ãããã®ããŒã¿ã©ããã«ã²ãŒã ãè¡ããããã®ã§ããã°ãæåã«å
¥å Žããããšãåºæ¥ã座åžã®å Žæãå
šãŠåããã
ææªã®å Žåãå以å€ã®åå è
å
šå¡ããã®æ
å ±ãåŸãŠãããšããŠã¿ããã
ãããªå Žåã§ãé
ããšãäœçªç®ã«éå Žã«å°çããã°æåã«äŒå Žã«å
¥ãããšãåºæ¥ãããããã¯ãã ã
ããããã®æç€ºå
容ãä»ããæèšç®ã§è§£æããã®ã¯éãå€ãããã®ã§ç¡çããã ã
ã©ããªã«é 匵ã£ãŠãã³ãºãã±ã«ã¯éã«åããªãã
</p>
<p>
ããã§ãåã¯åã«ãã®èšç®ãä»»ããããšã«ããã
åã¯ããã°ã©ãã³ã°ã³ã³ãã¹ãã«ããåå ããŠããããã®ãããªã®èšç®ããã°ã©ã ãæžãã®ã¯åŸæãªã¯ãã ã
ãã¡ãããã ã§ãã£ãŠãããšã¯èšããªãã
ã«ã¿ãã°ã«ãããšãä»å¹Žã®ã³ãºãã±ã«ã¯ããã°ã©ãã³ã°ã³ã³ãã¹ãã«é¢ããå人èªãåºããŠãããµãŒã¯ã«ãåå ããäºå®ã®ã¯ãã ã
ããåãéå Žãšåæã«å
¥å Žã§ãããå ±é
¬ãšããŠãã®å人èªãæã«å
¥ããŠåã«ãã¬ãŒã³ããããã
ããŠãåã¯ãããã5æéãããä»®ç ããšãããšã«ãããããã®éã«åãªããã£ãšçããåºããŠããããšåã¯ä¿¡ããŠããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯è€æ°ã®ã±ãŒã¹ãããªãã
åã±ãŒã¹ã¯ä»¥äžã®ãã©ãŒãããã§äžããããã
</p>
<pre>
<i>r</i> <i>c</i> <i>q</i>
<i>A<sub>0</sub></i> <i>B<sub>0</sub></i> <i>order<sub>0</sub></i>
<i>A<sub>1</sub></i> <i>B<sub>1</sub></i> <i>order<sub>1</sub></i>
.
.
.
<i>A<sub>q-1</sub></i> <i>B<sub>q-1</sub></i> <i>order<sub>q-1</sub></i>
</pre>
<p>
<i>A<sub>i</sub></i> = 0 ã®æ,<i>B<sub>i</sub></i> è¡ç®ã«å¯ŸããŠ<i>order<sub>i</sub></i> ã®æç€ºãå®è¡ãããã<br>
<i>A<sub>i</sub></i> = 1 ã®æ,<i>B<sub>i</sub></i> åç®ã«å¯ŸããŠ<i>order<sub>i</sub></i> ã®æç€ºãå®è¡ãããã<br>
<i>order<sub>i</sub></i> = 0ã®æã¯æå®ãããè¡ãŸãã¯åã®äººå
šå¡ã座ãããã<br>
<i>order<sub>i</sub></i> = 1ã®æã¯æå®ãããè¡ãŸãã¯åã人å
šå¡ãç«ãããã<br>
</p>
<p>
å
¥åã®çµããã¯<i>r</i> =0 <i>c</i> =0 <i>q </i>=0 ã§äžããããã
</p>
<p>
å
¥åã®å€ã¯ä»¥äžã®æ¡ä»¶ãæºããã<br>
1 ≤ <i>r</i> ≤ 50,000<br>
1 ≤ <i>c</i> ≤ 50,000<br>
1 ≤ <i>q</i> ≤ 50,000<br>
<i>order<sub>i</sub></i> = 0 ãŸã㯠1<br>
<i>A<sub>i</sub></i> = 0 ã®æ<br>
0 ≤ <i>B<sub>i</sub></i> < <i>r</i><br>
<i>A<sub>i</sub></i> = 1 ã®æ<br>
0 ≤ <i>B<sub>i</sub></i> < <i>c</i><br>
</p>
<p>
ãã¹ãã±ãŒã¹ã®æ°ã¯100ãè¶
ããªã<br>
</p>
<h2>Output</h2>
<p>
ææªã®å Žåã«ãäœçªç®ãŸã§ã«å°çããã°æåã«äŒå Žã«å
¥ããæš©å©ãåŸãããšãåºæ¥ãããäžè¡ã§åºåããã
</p>
<h2>Sample input</h2>
<pre>
5 5 5
0 0 1
0 0 0
0 2 0
1 2 1
0 0 0
5 5 5
1 4 0
0 1 1
0 4 1
1 3 0
0 3 1
5 5 5
1 0 0
0 3 0
1 2 1
0 4 0
0 1 1
0 0 0
</pre>
<H2>Sample output</H2>
<pre>
4
13
8
</pre>
<hr>
<p>
The University of Aizu Programming Contest 2011 Summer<br>
åæ¡ãå顿: Tomoya Sakai<br>
</p> |
p01976 | <h1>C: äžèŽ</h1>
<h2>åé¡</h2>
<p>
é·ã $N$ ã®æ°å $a_i$ ãäžããããã
æ¬¡ã®æ¡ä»¶ãæºããæŽæ° $K (1 \le K \le N)$ ãå
šãŠåºåããã
</p>
<p>
æ¡ä»¶:
$a_1, \cdots, a_K$ ãããŸãäžŠã³æ¿ãããš $a_{N-K+1}, \cdots, a_N$ ãšäžèŽããã
</p>
<h2>å¶çŽ</h2>
<ul>
<li>$1 \le N \le 10^5$</li>
<li>$1 \le a_i \le 10^9$</li>
<li>å
¥åã¯å
šãп޿°</li>
</ul>
<h2>å
¥å:</h2>
<p>
$N$<br>
$a_1 \cdots a_N$<br>
</p>
<h2>åºå:</h2>
<p>
æ¡ä»¶ãæºãã $K$ ãæé ã«ç©ºçœåºåãã§åºåããããŸãæ«å°Ÿã«æ¹è¡ãåºåããã
</p>
<h2>ãµã³ãã«</h2>
<h3>ãµã³ãã«å
¥å 1</h3>
<pre>
8
5 2 4 9 4 9 2 5
</pre>
<h3>ãµã³ãã«åºå 1</h3>
<pre>
1 2 4 6 7 8
</pre>
<h3>ãµã³ãã«å
¥å 2</h3>
<pre>
3
5 7 5
</pre>
<h3>ãµã³ãã«åºå 2</h3>
<pre>
1 2 3
</pre>
<h3>ãµã³ãã«å
¥å 3</h3>
<pre>
9
118 118 97 116 97 97 114 110 101
</pre>
<h3>ãµã³ãã«åºå 3</h3>
<pre>
9
</pre>
<!-- - - - - - end nicebody - - - - - -->
|
p00371 | <H1>Lottery Box</H1>
<p>
A lottery is being held in a corner of the venue of the Aizu festival. Several types of balls are inside the lottery box and each type has its unique integer printed on the surfaces of the balls. An integer <var>T</var> is printed on the lottery box.
</p>
<p>
In the lottery, you first declare two integers <var>A</var> and <var>B</var>, and draw up to <var>M</var> balls from the box. Let the sum of the integers printed on the balls be <var>S</var>. You can get a wonderful gift if the following two criteria are met: <var>S</var> divided by <var>T</var> gives a remainder greater than or equal to <var>A</var>, and <var>S</var> divided by <var>T</var> gives a quotient (fractional portion dropped) greater than or equal to <var>B</var>.
</p>
<p>
Write a program to determine if you have any chance of getting the gift given the following information: the number of ball types, ball-type specific integers, the maximum number of balls to be drawn from the box, the integer printed on the lottery box, and two integers declared before drawing. Assume that each ball type has sufficient (≥M) population in the box. Note also that there may be a chance of getting the gift even without drawing any ball.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>N</var> <var>M</var> <var>T</var>
<var>a_1</var>
<var>a_2</var>
:
<var>a_N</var>
<var>Q</var>
<var>A_1</var> <var>B_1</var>
<var>A_2</var> <var>B_2</var>
:
<var>A_Q</var> <var>B_Q</var>
</pre>
<p>
The first line provides the number of ball types <var>N</var>(1≤<var>N</var>≤10<sup>5</sup>), the maximum number of balls you can draw from the box <var>M</var>(1≤<var>M</var>≤10<sup>5</sup>), and the integer printed on the box <var>T</var>(1≤<var>T</var>≤1000). Each of the subsequent <var>N</var> lines provides an integer <var>a_i</var> (1≤<var>a_i</var>≤10<sup>9</sup>) printed on the <var>i</var>-th ball type. The next line following these provides the number of declarations <var>Q</var> (1≤<var>Q</var>≤10<sup>5</sup>). Each of the <var>Q</var> lines following this provides a pair of integers <var>A_i</var> (0 ≤ <var>A_i</var> < <var>T</var>), <var>B_i</var> (0 ≤ <var>B_i</var> ≤ 10<sup>9</sup>) that constitute the <var>i</var>-th declaration.
</p>
<h2>Output</h2>
<p>
Output a line for each pair of declaration <var>A</var> and <var>B</var> that contains "<span>yes</span>" if there is a chance of getting the gift or "<span>no</span>" otherwise.
</p>
<h2>Sample Input 1</h2>
<pre>
3 2 7
8
3
6
5
2 2
3 2
4 1
6 1
6 0
</pre>
<h2>Sample Output 1</h2>
<pre>
yes
no
yes
no
yes
</pre>
|
p01999 | <h1>D: éé£</h1>
<h2>åé¡</h2>
<p>
$H * W$ ã®ã°ãªããã§è¡šãããå°å³ãäžããããã
åãã¹ã¯ '#' ã '.' ã§ãããåè
ã¯éžå°ã§ããããšããåŸè
ã¯æµ·ã§ããããšã瀺ããŠããã
</p>
<p>
以äžã®ããã«äžäžå·Šå³ã«é£æ¥ããŠããéžå°ã®éåãå³¶ãšåŒã¶ã
</p>
<pre>
.....
.###.
..##.
..#..
.....
</pre>
<p>éžå° $6$ ãã¹ã®å³¶ã</p>
<pre>
......
.##.#.
....#.
......
</pre>
<p>éžå° $2$ ãã¹ã®å³¶ã $2$ ã€ã</p>
<p>
äžããããå°å³ã¯ã以äžã®æ¡ä»¶ãæºããã
<ul>
<li>å°å³ã®ç«¯ $1$ ãã¹ã¯å¿
ã '.' ã§ããã</li>
<li>åã圢ã®å³¶ãäºã€ä»¥äžååšããããšã¯ãªãã<br>
ã€ãŸããå³¶ã«å«ãŸããéžå°ã®ãã¡ãæãäžã«ããããã®äžã§æãå·Šã«ããéžå°ãåºæºãšããéžå°ã®åº§æšéåãçããå³¶ã¯ååšããªãã</li>
<li>å
šãŠã® '.' ãã¹ã¯é£çµã§ãããã€ãŸãã以äžã®ãããªå³¶ã¯ååšããªãã</li>
<pre>
.....
.###.
.#.#.
.###.
.....
</pre>
</ul>
</p>
<p>
éžå°ã®ã©ããã«AORã€ã«ã¡ãããããã
ããªãã®ç®æšã¯ãAORã€ã«ã¡ãããæåã«ãããã¹ãåœãŠãããšã§ããã
ãã®ããã«ãããªãã¯æ¬¡ã®ã¯ãšãªãç¹°ãè¿ãéãããšãã§ããã
</p>
<p>
<ul>
<li>'U', 'D', 'L', 'R' ã®ãã¡ãã²ãšã€ãéžã¶ãAORã€ã«ã¡ããã®çŸåšäœçœ®ã $c_{y, x}$ ãšãããšããããã $c_{y - 1, x},\ c_{y + 1, x},\ c_{y, x - 1},\ c_{y, x + 1}$ ã«ç§»åããããã«æç€ºããããšãã§ããã<br>
ç§»åå
ã '.' ã§ããå ŽåãAORã€ã«ã¡ãã㯠"NO" ãè¿ããç§»åããªãã ããã§ãªãå ŽåãAORã€ã«ã¡ãã㯠"YES" ãè¿ããæå®ãããã¹ã«ç§»åããã
</li>
</ul>
</p>
<p>
ã¯ãšãªãé«ã
$800000$ å ãŸã§éãããšã§ãAORã€ã«ã¡ãããæåã«ãããã¹ãæ±ããã
</p>
<!--p>
ãªããã¯ãšãªã®åœ¢åŒã誀ã£ãŠããå Žåã¯ãå³åº§ã«WAãšãªãã
</p-->
<h2>å
¥åºå</h2>
<p>
ãŸããå°å³ã®å€§ããã衚ãéè² æŽæ° $H, W$ ãšãå°å³ã衚ã $H$ è¡ $W$ åã®æå $c_{i,j}$ ãäžããããã
</p>
<p>
$H\ W$<br>
$c_{0,0}, \dots , c_{0, W - 1}$<br>
$\vdots$<br>
$c_{H - 1, 0}, \dots , c_{H - 1, W - 1}$<br>
</p>
<p>ç¶ããŠãããªãã®ããã°ã©ã ã¯äœåãå¿çããã°ã©ã ã«è³ªåãããïŒè³ªåã®ãã©ãŒãããã¯ä»¥äžã®ãšããã§ããã</p>
<pre>
? com
</pre>
<p>
$com$ 㯠U, D, L, R ã®ãã¡ãããã $1$ æåã§ããã
ãã®è³ªåã§ãæå®ãããæ¹åãžç§»åå¯èœãã衚ãæååãæšæºå
¥åã« $1$ è¡ã§æž¡ãããã
</p>
<p>
äœåã質åãè¡ã£ãåŸãããªãã¯AORã€ã«ã¡ããã®åæäœçœ®ãåœãŠããAORã€ã«ã¡ãããæåã«ãããã¹ã $c_{y,x}$ ã ãšãããšã
</p>
<pre>
! y x
</pre>
<p>
ãšãããã©ãŒãããã§åºåãããåæäœçœ®ãåºåããåŸãããªãã®ããã°ã©ã ã¯çŽã¡ã«çµäºããªããã°ãªããªããçµäºããªãã£ãå Žåã®ãžã£ããžçµæã¯äžå®ã§ããã
ãŸããããã以å€ã®ãã©ãŒãããã§åºåããå Žåã®ãžã£ããžçµæãäžå®ã§ããã
</p>
<p>
ãªãã質åãåæäœçœ®ãå¿çããã°ã©ã ã«éã£ãããšãã©ãã·ã¥ããªããšTLEãšãªãããšãããã<br>
ãã©ãã·ã¥ã¯Cã§ã¯
</p>
<pre>
fflush(stdout);
</pre>
<p>
C++ã§ã¯
</p>
<pre>
std::cout << endl;
</pre>
<p>
ã§è¡ãããšãã§ããã
fflush() 㯠stdlib.h ãã€ã³ã¯ã«ãŒããããšäœ¿çšã§ããã
</p>
<h2>å¶çŽ</h2>
<ul>
<li>$3 \leq H, W \leq 500$</li>
<li>å°å³ã«å«ãŸããæå㯠'#' ã '.' ã®ã¿ã§ããã</li>
</ul>
<h2>å
¥åºåäŸ</h2>
<table border='1'>
<tr>
<th>ããã°ã©ã ãžã®å
¥å</th>
<th>ããã°ã©ã ã®åºå</th>
</tr>
<tr>
<td>
<pre>
4 8
........
.#.#.##.
...#.##.
........
</pre>
</td>
<td></td>
</tr>
<tr>
<td></td>
<td>? R</td>
</tr>
<tr>
<td>NO</td>
<td></td>
</tr>
<tr>
<td></td>
<td>? U</td>
</tr>
<tr>
<td>NO</td>
<td></td>
</tr>
<tr>
<td></td>
<td>? D</td>
</tr>
<tr>
<td>YES</td>
<td></td>
</tr>
<tr>
<td></td>
<td>? L</td>
</tr>
<tr>
<td>NO</td>
<td></td>
</tr>
<tr>
<td></td>
<td>! 1 3</td>
</tr>
</table>
|
p00721 |
<h1><font color="#000">Problem F:</font> Cleaning Robot</h1>
<p>
Here, we want to solve path planning for a mobile robot cleaning a
rectangular room floor with furniture.
</p>
<p>
Consider the room floor paved with square tiles whose size fits
the cleaning robot (1 × 1).
There are 'clean tiles' and 'dirty tiles', and the robot can change
a 'dirty tile' to a 'clean tile' by visiting the tile.
Also there may be some obstacles (furniture) whose size fits a
tile in the room. If there is an obstacle on a tile, the robot cannot visit
it.
The robot moves to an adjacent tile with one move.
The tile onto which the robot moves must be one of four tiles
(i.e., east, west, north or south) adjacent to the tile where the
robot is present. The robot may visit a tile twice or more.
</p>
<p>
Your task is to write a program which computes the minimum number of
moves for the robot to change all 'dirty tiles' to 'clean tiles',
if ever possible.
</p>
<h2>Input</h2>
<p>
The input consists of multiple maps, each representing the size
and arrangement of the room. A map is given in the following format.
</p>
<blockquote>
<i>
w h<br>
</i>
<i>c</i><sub>11</sub> <i>c</i><sub>12</sub> <i>c</i><sub>13</sub> ... <i>c</i><sub>1<i>w</i></sub><br>
<i>c</i><sub>21</sub> <i>c</i><sub>22</sub> <i>c</i><sub>23</sub> ... <i>c</i><sub>2<i>w</i></sub><br>
...<br>
<i>c</i><sub><i>h</i>1</sub> <i>c</i><sub><i>h</i>2</sub> <i>c</i><sub><i>h</i>3</sub> ... <i>c</i><sub><i>hw</i></sub><br>
</i>
</blockquote>
<p>
The integers <i>w</i> and <i>h</i> are the lengths of the two sides
of the floor of the room in terms of widths of floor tiles. <i>w</i> and <i>h</i>
are less than or equal to 20. The character <i>c<sub>yx</sub></i> represents
what is initially on the tile with coordinates (<i>x, y</i>) as follows.
</p>
<blockquote>
'<tt>.</tt>' : a clean tile<br>
'<tt>*</tt>' : a dirty tile <br>
'<tt>x</tt>' : a piece of furniture (obstacle) <br>
'<tt>o</tt>' : the robot (initial position)<br>
</blockquote>
<p>
In the map the number of 'dirty tiles' does not exceed 10.
There is only one 'robot'.
</p>
<p>
The end of the input is indicated by a line containing two zeros.
</p>
<h2>Output</h2>
<p>
For each map, your program should output a line containing the minimum
number of moves. If the map includes 'dirty tiles' which the robot cannot reach,
your program should output -1.
</p>
<h2>Sample Input</h2>
<pre>
7 5
.......
.o...*.
.......
.*...*.
.......
15 13
.......x.......
...o...x....*..
.......x.......
.......x.......
.......x.......
...............
xxxxx.....xxxxx
...............
.......x.......
.......x.......
.......x.......
..*....x....*..
.......x.......
10 10
..........
..o.......
..........
..........
..........
.....xxxxx
.....x....
.....x.*..
.....x....
.....x....
0 0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
8
49
-1
</pre>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.