question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p00084 |
<H1>æ€çŽ¢ãšã³ãžã³</H1>
<p>
ã€ã³ã¿ãŒãããã®æ€çŽ¢ãšã³ãžã³ãäŸãã°ãGoogle ãªã©ã§ã¯ãäžçäžã®ãŠã§ãããŒãžãèªåã§åæšããŠåé¡ãã巚倧ãªããŒã¿ããŒã¹ãäœæããŸãããŸãããŠãŒã¶ãå
¥åããæ€çŽ¢ããŒã¯ãŒããè§£æããŠãããŒã¿ããŒã¹æ€çŽ¢ã®ããã®åãåããæãäœæããŸãã
</p>
<p>
ãããã®å Žåããå¹ççãªæ€çŽ¢ãå®çŸããããã«è€éãªåŠçãè¡ã£ãŠããŸããããšããããã®åºæ¬ã¯å
šãŠæç« ããã®åèªã®åãåºãã§ãã
</p>
<p>
ãšããããšã§ãæç« ããã®åèªã®åãåºãã«ææŠããŠãã ãããä»åã¯ä»¥äžã®éããåèªåºåããæç¢ºãªè±èªã®æç« ã察象ãšããŸãã
</p>
<ul>
<li> 察象ãšãªãæç« ãïŒãæ¹è¡ãå«ãŸãªã 1024 æå以äžã®è±èªã®æç« </li>
<li> åºåãæå ïŒãããããåè§ã§ç©ºçœãããªãªããã«ã³ãã®ã¿</li>
<li> åãåºãåèªãïŒã3 ãã 6 æåã®åèªïŒ2æå以äžã7æå以äžã®åèªã¯ç¡èŠïŒã</li>
</ul>
<H2>å
¥å</H2>
<p>åºåãæååã³è±æ°åã§æ§æãããè±æãïŒè¡ïŒãã¹ãŠåè§ïŒã«äžããããŸãã
</p>
<H2>åºå</H2>
<p>ç©ºçœæåïŒæåïŒåè§ïŒã§åºåãããåèªãïŒè¡ã«åºåããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
Rain, rain, go to Spain.
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Rain rain Spain
</pre>
<H2>Sample Input 2</H2>
<pre>
Win today's preliminary contest and be qualified to visit University of Aizu.
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
Win and visit Aizu
</pre>
|
p02543 | <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> points on a number line, <var>i</var>-th of which is placed on coordinate <var>X_i</var>.
These points are numbered in the increasing order of coordinates.
In other words, for all <var>i</var> (<var>1 \leq i \leq N-1</var>), <var>X_i < X_{i+1}</var> holds.
In addition to that, an integer <var>K</var> is given.</p>
<p>Process <var>Q</var> queries.</p>
<p>In the <var>i</var>-th query, two integers <var>L_i</var> and <var>R_i</var> are given.
Here, a set <var>s</var> of points is said to be a <em>good</em> set if it satisfies all of the following conditions.
Note that the definition of good sets varies over queries.</p>
<ul>
<li>Each point in <var>s</var> is one of <var>X_{L_i},X_{L_i+1},\ldots,X_{R_i}</var>.</li>
<li>For any two distinct points in <var>s</var>, the distance between them is greater than or equal to <var>K</var>.</li>
<li>The size of <var>s</var> is maximum among all sets that satisfy the aforementioned conditions.</li>
</ul>
<p>For each query, find the size of the union of all good sets.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2 \times 10^5</var></li>
<li><var>1 \leq K \leq 10^9</var></li>
<li><var>0 \leq X_1 < X_2 < \cdots < X_N \leq 10^9</var></li>
<li><var>1 \leq Q \leq 2 \times 10^5</var></li>
<li><var>1 \leq L_i \leq R_i \leq N</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>K</var>
<var>X_1</var> <var>X_2</var> <var>\cdots</var> <var>X_N</var>
<var>Q</var>
<var>L_1</var> <var>R_1</var>
<var>L_2</var> <var>R_2</var>
<var>\vdots</var>
<var>L_Q</var> <var>R_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>For each query, print the size of the union of all good sets in a line.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 3
1 2 4 7 8
2
1 5
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
2
</pre>
<p>In the first query, you can have at most <var>3</var> points in a good set.
There exist two good sets: <var>\{1,4,7\}</var> and <var>\{1,4,8\}</var>.
Therefore, the size of the union of all good sets is <var>|\{1,4,7,8\}|=4</var>.</p>
<p>In the second query, you can have at most <var>1</var> point in a good set.
There exist two good sets: <var>\{1\}</var> and <var>\{2\}</var>.
Therefore, the size of the union of all good sets is <var>|\{1,2\}|=2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>15 220492538
4452279 12864090 23146757 31318558 133073771 141315707 263239555 350278176 401243954 418305779 450172439 560311491 625900495 626194585 891960194
5
6 14
1 8
1 13
7 12
4 12
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
6
11
2
3
</pre></section>
</div>
</span> |
p02810 | <span class="lang-en">
<p>Score : <var>1100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Niwango bought a piece of land that can be represented as a half-open interval <var>[0, X)</var>.</p>
<p>Niwango will lay out <var>N</var> vinyl sheets on this land. The sheets are numbered <var>1,2, \ldots, N</var>, and they are distinguishable.
For Sheet <var>i</var>, he can choose an integer <var>j</var> such that <var>0 \leq j \leq X - L_i</var> and cover <var>[j, j + L_i)</var> with this sheet.</p>
<p>Find the number of ways to cover the land with the sheets such that no point in <var>[0, X)</var> remains uncovered, modulo <var>(10^9+7)</var>.
We consider two ways to cover the land different if and only if there is an integer <var>i</var> <var>(1 \leq i \leq N)</var> such that the region covered by Sheet <var>i</var> is different.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq N \leq 100</var></li>
<li><var>1 \leq L_i \leq X \leq 500</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>X</var>
<var>L_1</var> <var>L_2</var> <var>\ldots</var> <var>L_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>3 3
1 1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
</pre>
<ul>
<li>If we ignore whether the whole interval is covered, there are <var>18</var> ways to lay out the sheets.</li>
<li>Among them, there are <var>4</var> ways that leave <var>[0, 1)</var> uncovered, and <var>4</var> ways that leave <var>[2, 3)</var> uncovered.</li>
<li>Each of the other ways covers the whole interval <var>[0,3)</var>, so the answer is <var>10</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>18 477
324 31 27 227 9 21 41 29 50 34 2 362 92 11 13 17 183 119
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>134796357
</pre>
<ul>
<li>Find the number of ways modulo <var>(10^9+7)</var>.</li>
</ul></section>
</div>
</span> |
p03702 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are going out for a walk, when you suddenly encounter <var>N</var> monsters. Each monster has a parameter called <em>health</em>, and the health of the <var>i</var>-th monster is <var>h_i</var> at the moment of encounter. A monster will vanish immediately when its health drops to <var>0</var> or below.</p>
<p>Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:</p>
<ul>
<li>Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by <var>A</var>, and the health of each of the other monsters will decrease by <var>B</var>. Here, <var>A</var> and <var>B</var> are predetermined parameters, and <var>A > B</var> holds.</li>
</ul>
<p>At least how many explosions do you need to cause in order to vanish all the monsters?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All input values are integers.</li>
<li><var>1 †N †10^5</var></li>
<li><var>1 †B < A †10^9</var></li>
<li><var>1 †h_i †10^9</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>A</var> <var>B</var>
<var>h_1</var>
<var>h_2</var>
<var>:</var>
<var>h_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 5 3
8
7
4
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>You can vanish all the monsters in two explosion, as follows:</p>
<ul>
<li>First, cause an explosion centered at the monster with <var>8</var> health. The healths of the four monsters become <var>3</var>, <var>4</var>, <var>1</var> and <var>-1</var>, respectively, and the last monster vanishes.</li>
<li>Second, cause an explosion centered at the monster with <var>4</var> health remaining. The healths of the three remaining monsters become <var>0</var>, <var>-1</var> and <var>-2</var>, respectively, and all the monsters are now vanished.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 10 4
20
20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre>
<p>You need to cause two explosions centered at each monster, for a total of four.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 2 1
900000000
900000000
1000000000
1000000000
1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>800000000
</pre></section>
</div>
</span> |
p00987 | <h2>One-Way Conveyors</h2>
<p>
You are working at a factory manufacturing many different products. Products have to be processed on a number of different machine tools. Machine shops with these machines are connected with conveyor lines to exchange unfinished products. Each unfinished product is transferred from a machine shop to another through one or more of these conveyors.
</p>
<p>
As the orders of the processes required are not the same for different types of products, the conveyor lines are currently operated in two-way. This may induce inefficiency as conveyors have to be completely emptied before switching their directions. <i>Kaizen</i> (efficiency improvements) may be found here!
</p>
<p>
Adding more conveyors is too costly. If all the required transfers are possible with currently installed conveyors operating in fixed directions, no additional costs are required. All the required transfers, from which machine shop to which, are listed at hand. You want to know whether all the required transfers can be enabled with all the conveyors operated in one-way, and if yes, directions of the conveyor lines enabling it.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case of the following format.
</p>
<pre>
$n$ $m$
$x_1$ $y_1$
.
.
.
$x_m$ $y_m$
$k$
$a_1$ $b_1$
.
.
.
$a_k$ $b_k$
</pre>
<p>
The first line contains two integers $n$ ($2 \leq n \leq 10 000$) and $m$ ($1 \leq m \leq 100 000$), the number of machine shops and the number of conveyors, respectively. Machine shops are numbered $1$ through $n$. Each of the following $m$ lines contains two integers $x_i$ and $y_i$ ($1 \leq x_i < y_i \leq n$), meaning that the $i$-th conveyor connects machine shops $x_i$ and $y_i$. At most one conveyor is installed between any two machine shops. It is guaranteed that any two machine shops are connected through one or more conveyors. The next line contains an integer $k$ ($1 \leq k \leq 100 000$), which indicates the number of required transfers from a machine shop to another. Each of the following $k$ lines contains two integers $a_i$ and $b_i$ ($1 \leq a_i \leq n$, $1 \leq b_i \leq n$, $a_i \ne b_i$), meaning that transfer from the machine shop $a_i$ to the machine shop $b_i$ is required. Either $a_i \ne a_j$ or $b_i \ne b_j$ holds for $i \ne j$.
</p>
<h3> Output
</h3>
<p>
Output â<pan>No</span>â if it is impossible to enable all the required transfers when all the conveyors are operated in one-way. Otherwise, output â<span>Yes</span>â in a line first, followed by $m$ lines each of which describes the directions of the conveyors. All the required transfers should be possible with the conveyor lines operated in these directions. Each direction should be described as a pair of the machine shop numbers separated by a space, with the start shop number on the left and the end shop number on the right. The order of these $m$ lines do not matter as far as all the conveyors are specified without duplicates or omissions. If there are multiple feasible direction assignments, whichever is fine.
</p>
<h3>Sample Input 1 </h3>
<pre>
3 2
1 2
2 3
3
1 2
1 3
2 3
</pre>
<h3>Sample Output 1</h3>
<pre>
Yes
1 2
2 3
</pre>
<h3>Sample Input 2 </h3>
<pre>
3 2
1 2
2 3
3
1 2
1 3
3 2
</pre>
<h3>Sample Output 2</h3>
<pre>
No
</pre>
<h3>Sample Input 3 </h3>
<pre>
4 4
1 2
1 3
1 4
2 3
7
1 2
1 3
1 4
2 1
2 3
3 1
3 2
</pre>
<h3>Sample Output 3</h3>
<pre>
Yes
1 2
2 3
3 1
1 4
</pre>
|
p01695 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<!-- begin en only -->
<h3><u>JAG-channel</u></h3>
<!-- end en only -->
<!-- begin ja only -->
<!--<h3><u>JAG-channel</u></h3>-->
<!-- end ja only -->
<!-- begin en only -->
<!-- end en only -->
<!-- begin ja only -->
<p>ãã€ãµã³ã»Oã»ãã€ãã¹ã¯JAG-channelãšããé»åæ²ç€ºæ¿ãéå¶ããŠããïŒ
圌ã¯çŸåšïŒã¹ã¬ãããã¥ãŒãšããæ°æ©èœã®è¿œå ã«åãçµãã§ããïŒ
</p>
<p>ä»ã®å€ãã®é»åæ²ç€ºæ¿ãšåãããã«ïŒJAG-channelã¯ã¹ã¬ããããŒã¹ã§ããïŒ
ããã§ïŒã¹ã¬ãããšã¯ïŒäžé£ã®æçš¿ãããªãäžã€ã®äŒè©±ã®ãŸãšãŸããæãïŒ
æçš¿ã«ã¯ïŒä»¥äžã®2çš®é¡ãååšããïŒ
</p><ul><li>æ°ããã¹ã¬ãããäœãæåã®æçš¿
</li><li>ãã§ã«ããã¹ã¬ããã®éå»ã®æçš¿ãžã®è¿ä¿¡
</li></ul>
<p>ã¹ã¬ãããã¥ãŒã¯ïŒæçš¿éã®è¿ä¿¡ã»è¢«è¿ä¿¡é¢ä¿ã«ããè«ççãªæ§é ã衚ãïŒããªãŒç¶ã®ãã¥ãŒã§ããïŒ
ããããã®æçš¿ã¯ããªãŒã®ããŒããšãªãïŒãã®æçš¿ã«å¯Ÿããè¿ä¿¡ãåããŒããšããŠæã€ïŒ
ããæçš¿ã«å¯ŸããçŽæ¥ã»éæ¥ã®è¿ä¿¡ãïŒå
šäœãšããŠéšåæšãšãªãããšã«æ³šæããŠã»ããïŒ
</p>
<p>äŸãèŠãŠã¿ããïŒäŸãã°ïŒ
"<samp>hoge</samp>"ãšããæåã®æçš¿ã«å¯ŸããŠ
"<samp>fuga</samp>"ãš"<samp>piyo</samp>"ãšãã2ã€ã®è¿ä¿¡ãä»ãïŒ
"<samp>fuga</samp>"ã«å¯ŸããŠããã«"<samp>foobar</samp>"ãš"<samp>jagjag</samp>"ãšããè¿ä¿¡ãä»ãïŒ
"<samp>jagjag</samp>"ã«å¯ŸããŠ"<samp>zigzag</samp>"ãšããè¿ä¿¡ãä»ãããšããïŒ
ãã®ã¹ã¬ããã®ããªãŒã¯æ¬¡ã®ããã«ãªãïŒ
</p>
<pre>hoge
ââfuga
âãââfoobar
âãââjagjag
âãããââzigzag
ââpiyo</pre>
<p>ãã€ãµã³ã»Oã»ãã€ãã¹ã¯ããã°ã©ããŒãéã£ãŠæ©èœãå®è£
ãããŠãããïŒãã®ããã°ã©ããŒãæåŸã®æ®µéã§å€±èžªããŠããŸã£ãïŒ
ãã®ããã°ã©ããŒã¯ïŒã¹ã¬ããã®ããªãŒãäœãïŒãããç°¡æãã©ãŒãããã§è¡šç€ºãããšãããŸã§å®æãããŠããïŒ
ãã®ç°¡æãã©ãŒãããã§ã¯ïŒè¿ä¿¡ã®æ·±ãã '<samp>.</samp>' (åè§ããã) ã§è¡šããïŒããæçš¿ã«å¯Ÿããè¿ä¿¡ã¯ïŒå
ã®æçš¿ãã1ã€å€ãã® '<samp>.</samp>' ãå·Šã«ã€ãïŒãŸãïŒããæçš¿ã«å¯Ÿããè¿ä¿¡ã¯å¿
ãå
ã®æçš¿ãããäžã«æ¥ãïŒè¿ä¿¡å
ã®æçš¿ãšè¿ä¿¡ã®éã«ã¯ïŒè¿ä¿¡å
ã®æçš¿ã«å¯Ÿããä»ã®è¿ä¿¡ (ããã³ïŒããã«å¯ŸããçŽæ¥ã»éæ¥ã®è¿ä¿¡) ãçŸããããšããããïŒãã以å€ã®æçš¿ãäž¡è
ã®éã«çŸããããšã¯ãªãïŒ
äžã®ããªãŒã®ç°¡æãã©ãŒãããè¡šç€ºã¯æ¬¡ã®ããã«ãªãïŒ
</p>
<pre>hoge
.fuga
..foobar
..jagjag
...zigzag
.piyo</pre>
<p>ããªãã®ä»äºã¯ïŒãã®ç°¡æãã©ãŒããã衚瀺ãåãåãïŒèŠãããæŽåœ¢ããããšã§ããïŒ
ããªãã¡ïŒ
</p>
<ul><li>åæçš¿ã®ããå·Šã® '<samp>.</samp>' (åæçš¿ã®å·Šã«ã€ãã '<samp>.</samp>' ã®ãã¡ïŒãã£ãšãå³ã®ãã®) ã '<samp>+</samp>' (åè§ãã©ã¹)ïŒ
</li><li>åãæçš¿ã«å¯ŸããçŽæ¥ã®è¿ä¿¡ã«ã€ããŠïŒããããã®ããå·Šã«ãã '<samp>+</samp>' ã®éã«äœçœ®ãã '<samp>.</samp>' ã '<samp>|</samp>' (åè§çžŠç·)ïŒ
</li><li>ãã以å€ã® '<samp>.</samp>' 㯠'<samp> </samp>' (åè§ã¹ããŒã¹)
</li></ul>
<p>ã«çœ®ãæããŠæ¬²ããïŒ
</p>
<p>äžã®ç°¡æãã©ãŒããã衚瀺ã«å¯ŸããæŽåœ¢æžã¿ã®è¡šç€ºã¯æ¬¡ã®ããã«ãªãïŒ
</p>
<pre>hoge
+fuga
|+foobar
|+jagjag
| +zigzag
+piyo</pre>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>å
¥åã¯è€æ°ã®ããŒã¿ã»ããããæ§æãããïŒåããŒã¿ã»ããã®åœ¢åŒã¯æ¬¡ã®éãã§ããïŒ
</p><blockquote>$n$<br>$s_1$<br>$s_2$<br>...<br>$s_n$</blockquote>
<p>$n$ ã¯ç°¡æãã©ãŒããã衚瀺ã®è¡æ°ãè¡šãæŽæ°ã§ããïŒ$1$ ä»¥äž $1{,}000$ 以äžãšä»®å®ããŠããïŒ
ç¶ã $n$ è¡ã«ã¯ã¹ã¬ããããªãŒã®ç°¡æãã©ãŒããã衚瀺ãèšèŒãããŠããïŒ
$s_i$ ã¯ç°¡æãã©ãŒããã衚瀺㮠$i$ è¡ç®ã衚ãïŒããã€ãã® '<samp>.</samp>' ãšïŒããã«ç¶ã $1$ æåä»¥äž $50$ æå以äžã®ã¢ã«ãã¡ãããå°æåã§æ§æãããæååãããªãïŒ
$s_1$ ã¯ã¹ã¬ããã®æåã®æçš¿ã§ããïŒ'<samp>.</samp>' ãå«ãŸãªãïŒ
$s_2$, ..., $s_n$ ã¯ãã®ã¹ã¬ããã§ã®è¿ä¿¡ã§ããïŒå¿
ã1ã€ä»¥äžã® '<samp>.</samp>' ãå«ãïŒ
</p>
<p>$n=0$ ã¯å
¥åã®çµããã瀺ãïŒããã¯ããŒã¿ã»ããã«ã¯å«ããªãïŒ
</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>åããŒã¿ã»ããã«å¯ŸããæŽåœ¢æžã¿ã®è¡šç€ºãå $n$ è¡ã§åºåããïŒ
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>6
hoge
.fuga
..foobar
..jagjag
...zigzag
.piyo
8
jagjag
.hogehoge
..fugafuga
...ponyoponyo
....evaeva
....pokemon
...nowawa
.buhihi
8
hello
.goodmorning
..howareyou
.goodafternoon
..letshavealunch
.goodevening
.goodnight
..gotobed
3
caution
.themessagelengthislessthanorequaltofifty
..sothelengthoftheentirelinecanexceedfiftycharacters
0</pre>
<h3>Output for Sample Input</h3>
<pre>hoge
+fuga
|+foobar
|+jagjag
| +zigzag
+piyo
jagjag
+hogehoge
|+fugafuga
| +ponyoponyo
| |+evaeva
| |+pokemon
| +nowawa
+buhihi
hello
+goodmorning
|+howareyou
+goodafternoon
|+letshavealunch
+goodevening
+goodnight
+gotobed
caution
+themessagelengthislessthanorequaltofifty
+sothelengthoftheentirelinecanexceedfiftycharacters</pre>
|
p03352 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a positive integer <var>X</var>.
Find the largest <em>perfect power</em> that is at most <var>X</var>.
Here, a perfect power is an integer that can be represented as <var>b^p</var>, where <var>b</var> is an integer not less than <var>1</var> and <var>p</var> is an integer not less than <var>2</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1</var> <var>â€</var> <var>X</var> <var>â€</var> <var>1000</var></li>
<li><var>X</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>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the largest perfect power that is at most <var>X</var>.</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>9
</pre>
<p>There are four perfect powers that are at most <var>10</var>: <var>1</var>, <var>4</var>, <var>8</var> and <var>9</var>.
We should print the largest among them, <var>9</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>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>999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>961
</pre></section>
</div>
</span> |
p02390 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<H1>Watch</H1>
<p>
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
</p>
<H2>Input</H2>
<p>
An integer $S$ is given in a line.
</p>
<H2>Output</H2>
<p>
Print $h$, $m$ and $s$ separated by ':'. You do not need to put '0' for a value, which consists of a digit.
</p>
<h2>Constraints</h2>
<ul>
<li>$0 \leq S \leq 86400$</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
46979
</pre>
<H2>Sample Output 1</H2>
<pre>
13:2:59
</pre> |
p00657 |
<H1>Problem K: Rearranging Seats</H1>
<p>
Haruna is a high school student.
She must remember the seating arrangements in her class because she is a class president.
It is too difficult task to remember if there are so many students.
</p>
<p>
That is the reason why seating rearrangement is depress task for her.
But students have a complaint if seating is fixed.
</p>
<p>
One day, she made a rule that all students must move but they don't move so far as the result of seating rearrangement.
</p>
<p>
The following is the rule.
The class room consists of <i>r*c</i> seats.
Each <i>r</i> row has <i>c</i> seats.
The coordinate of the front row and most left is (1,1). The last row and right most is (<i>r</i>,<i>c</i>).
After seating rearrangement, all students must move next to their seat.
If a student sit (<i>y</i>,<i>x</i>) before seating arrangement, his/her seat must be (<i>y</i>,<i>x</i>+1) , (<i>y</i>,<i>x</i>-1), (<i>y</i>+1,<i>x</i>) or (<i>y</i>-1,<i>x</i>).
The new seat must be inside of the class room. For example (0,1) or (<i>r</i>+1,<i>c</i>) is not allowed.
</p>
<p>
Your task is to check whether it is possible to rearrange seats based on the above rule.
</p>
<H2>Input</h2>
<p>
Input consists of multiple datasets.
Each dataset consists of 2 integers.
The last input contains two 0.
A dataset is given by the following format.
</p>
<pre>
<i>r</i> <i>c</i>
</pre>
<p>
Input satisfies the following constraint.<br>
1 ≤ <i>r</i> ≤ 19, 1 ≤ <i>c</i> ≤ 19
</p>
<h2>Output</h2>
<p>
Print "yes" without quates in one line if it is possible to rearrange the seats, otherwise print "no" without quates in one line.
</p>
<h2>Sample Input</h2>
<pre>
1 1
2 2
0 0
</pre>
<h2>Sample Output</h2>
<pre>
no
yes
</pre>
<h2>Hint</h2>
<p>
For the second case, before seat rearrangement, the state is shown as follows.
</p>
<pre>
1 2
3 4
</pre>
<p>
There are some possible arrangements.
For example
</p>
<pre>
2 4
1 3
</pre>
<p>
or
</p>
<pre>
2 1
4 3
</pre>
<p>
is valid arrangement.
</p> |
p03978 | <span class="lang-en">
<p>Score : <var>150</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>
There is a long blackboard with <var>2</var> rows and <var>N</var> columns in a classroom of Kyoto University.
This blackboard is so long that it is impossible to tell which cells are already used and which unused.
</p>
<p>
Recently, a blackboard retrieval device was installed at the classroom.
To use this device, you type a search query that forms a rectangle with 2 rows and any length of columns, where each cell is used or unused.
When you input a query, the decive answers whether the rectangle that corresponds to the query exists in the blackboard.
Here, for a rectangle that corresponds to a search query, if two integer <var>i, j</var> ( <var>i < j</var> ) exist
and the rectangle equals to the partial blackboard between column <var>i</var> and <var>j</var> ,
the rectangle is called a sub-blackboard of the blackboard.
</p>
<p>
You are currently preparing for a presentation at this classroom.
To make the presentation go well, you decided to write a program to detect the status of the whole blackboard using the retrieval device.
Since it takes time to use the device, you want to use it as few times as possible.
</p>
<p>
The status of the whole blackboard is already determined at the beginning and does not change while you are using the device.
</p>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>The first input is given in the following format:</p>
<pre>
<var>N</var>
</pre>
<p> <var>N</var> <var>(1 \leq N \leq 100)</var> is an integer that represents the length of the blackboard. </p>
<p>
After this input value, your program must print search queries.
A search query has the following format.
</p>
<pre>
<var>s_1</var>
<var>s_2</var>
</pre>
<p>
Here, <var>s_1</var> represents the upper part of the blackboard and <var>s_2</var> represents the lower.
<code>#</code> in <var>s_1</var> and <var>s_2</var> represents the cell is already used and <code>.</code> represents the cell is still unused.
The lengths of <var>s_1</var> and <var>s_2</var> are arbitrary, but they must be the same.
Make sure to insert a line break at the end of the lines.
</p>
<p>
Every time your program prints a search query, a string that represents the search result of the device is returned in the followin format.
</p>
<pre>
<var>r</var>
</pre>
<p>
<var>r</var> is either <code>T</code> or <code>F</code> .
The meaning of each character is as follows.
</p>
<ul>
<li> <code>T</code> represents that the sub-blackboard that corresponds to the search query exists in the blackboard. </li>
<li> <code>F</code> represents that the sub-blackboard that corresponds to the search query does not exist in the blackboard. </li>
</ul>
<p>
If the search query equals to the whole blackboard or the number of the search queries exceeds the limit, string <code>end</code> is given instead of <var>r</var> .
Once you receive this string, exit your program immediately.
If your program prints the whole blackboard as a search query before exceedin the limit, it is judged as <em>Accepted</em>. Note that the search query that represents the whole blackboard is also counted as the number of search queries.
</p>
</section>
</div>
</div>
<p>
Note that the output needs to be flushed every time the output is printed.
For example, In C/C++, search query <code>s1</code>, <code>s2</code> can be printed as follows.
</p>
<pre class="prettyprint">printf("%s\n%s\n", s1, s2); fflush(stdout);</pre>
<p>
Make sure your program receive all the input from the device. Otherwise, the result may be <em>Time Limit Exceeded</em> .
</p>
<hr/>
<div class="part">
<section>
<h3>Query Limit</h3>
<p>
The maximun number of search queries is <var>420</var>.
If the number of queries exceeds the limit, the result will be <em>Query Limit Exceeded</em> .
</p>
<hr/>
</section>
</div>
<div class="part">
<section>
<h3>Sample Input and Output</h3>
<p>The following is an example where <var>N=3</var> and the blackboard is as follows. </p>
<pre>
.#.
...
</pre>
<p>Note that your program does not know the state of the blackboard. </p>
<pre>
<table class="table table-striped table-bordered table-condensed">
<tr>
<th>Output of your program</th>
<th>Input to your program</th>
<th>Explanation</th>
</tr>
<tr>
<td></td>
<td>3</td>
<td>The length of the blackboard is given</td>
</tr>
<tr>
<td>..<br/>##</td>
<td></td>
<td>Output a search query</td>
</tr>
<tr>
<td></td>
<td>F</td>
<td>The sub-blackboard does not exist</td>
</tr>
<tr>
<td>.<br/>.</td>
<td></td>
<td>Output a search query</td>
</tr>
<tr>
<td></td>
<td>T</td>
<td>The sub-blackboard exists</td>
</tr>
<tr>
<td>..<br/>..</td>
<td></td>
<td>Output a search query</td>
</tr>
<tr>
<td></td>
<td>F</td>
<td>The sub-blackboard does not exist</td>
</tr>
<tr>
<td>.#<br/>..</td>
<td></td>
<td>Output a search query</td>
</tr>
<tr>
<td></td>
<td>T</td>
<td>The sub-blackboard exists</td>
</tr>
<tr>
<td>.#.<br/>...</td>
<td></td>
<td>Output a search query</td>
</tr>
<tr>
<td></td>
<td>end</td>
<td>Exit your program because the above sub-blackboard equals to the whole blackboard. </td>
</tr>
</table>
</pre>
</section>
</div>
</span> |
p01945 |
<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>
Star in Parentheses
</H1>
<p>
You are given a string $S$, which is balanced parentheses with a star symbol '<span>*</span>' inserted.
</p>
<p>
Any balanced parentheses can be constructed using the following rules:
</p>
<ul>
<li>An empty string is balanced.</li>
<li>Concatenation of two balanced parentheses is balanced.</li>
<li>If $T$ is balanced parentheses, concatenation of '<span>(</span>', $T$, and '<span>)</span>' in this order is balanced.</li>
</ul>
<p>
For example, '<span>()()</span>' and '<span>(()())</span>' are balanced parentheses. '<span>)(</span>' and '<span>)()(()</span>' are not balanced parentheses.
</p>
<p>
Your task is to count how many matching pairs of parentheses surround the star.
</p>
<p>
Let $S_i$be the $i$-th character of a string $S$. The pair of $S_l$ and $S_r$ ($l < r$) is called a matching pair of parentheses if $S_l$ is '<span>(</span>', $S_r$ is '<span>)</span>' and the surrounded string by them is balanced when ignoring a star symbol.
</p>
<H2>Input</H2>
<p>
The input consists of a single test case formatted as follows.
</p>
<pre>
$S$
</pre>
<p>
$S$ is balanced parentheses with exactly one '<span>*</span>' inserted somewhere. The length of $S$ is between 1 and 100, inclusive.
</p>
<H2>Output</H2>
<p>
Print the answer in one line.
</p>
<H2>Sample Input 1</H2>
<pre>
((*)())
</pre>
<H2>Output for Sample Input 1</H2>
<pre>
2
</pre>
<H2>Sample Input 2</H2>
<pre>
(*)
</pre>
<H2>Output for Sample Input 2</H2>
<pre>
1
</pre>
<H2>Sample Input 3</H2>
<pre>
(()())*
</pre>
<H2>Output for Sample Input 3</H2>
<pre>
0
</pre>
<H2>Sample Input 4</H2>
<pre>
()*()
</pre>
<H2>Output for Sample Input 4</H2>
<pre>
0
</pre>
<H2>Sample Input 5</H2>
<pre>
((((((((((*))))))))))
</pre>
<H2>Output for Sample Input 5</H2>
<pre>
10
</pre>
<H2>Sample Input 6</H2>
<pre>
*
</pre>
<H2>Output for Sample Input 6</H2>
<pre>
0
</pre>
|
p00207 |
<H1>ãããã¯</H1>
<p>
A ããã®å®¶ã«èŠªæã® B åããã£ãŠããŸããã圌㯠3 æ³ã§ãããã¯ã倧奜ãã§ãã圌ãæã£ãŠãããããã¯ã¯å³ 1 ã®ãããªåœ¢ãããŠããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_blockMaze1">
<p>
å³1
</p>
</center>
<p>
B åã¯ããŒãã®äžã«ãããã¯ãæ·ãè©°ããŠããŸãã圌ã«ãäœãäœã£ãŠããã®?ããšèããšã圌ã¯ãè¿·è·¯!!ããšå
æ°ããçããŸããã圌ã®èšãè¿·è·¯ãšã¯ãã¹ã¿ãŒããããŽãŒã«ãŸã§åŽé¢ãæ¥ããŠãããåãè²ã®ãããã¯ã ãã§ãã©ãããšãã§ãããããã¯ã®é
眮ã®ããšã ããã§ããå³ 2 ã¯é»è²ã®ãããã¯ã«ãããå·Šäž(ã¹ã¿ãŒã)ããå³äž(ãŽãŒã«)ãžè¿·è·¯ãã§ããŠããããšã衚ããŠããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_blockMaze2">
<p>
å³2
</p>
</center>
<p>
ç¡éªæ°ã«éãã§ãã B åãæšªç®ã«ãããã°ã©ããŒã§ããããªãã¯ããããã¯ã®äžŠã³ãè¿·è·¯ãšãªã£ãŠãããã確ãããŠã¿ãããšã«ããŸããã
</p>
<p>
ãããã¯ã®æ
å ±ãšã¹ã¿ãŒãããŽãŒã«ã®åº§æšãå
¥åãšãããããã¯ãè¿·è·¯ãšãªã£ãŠããã° OK ããªã£ãŠããªããã° NG ãåºåããããã°ã©ã ãäœæããŠãã ããã ããŒãã¯æšªæ¹åã« <var>w</var> ã瞊æ¹åã« <var>h</var> ã®å€§ããããã¡ã å·Šäžã®åº§æšã¯(1 , 1)ãå³äžã®åº§æšã¯(<var>w, h</var>)ãšããŸãããããã¯ã¯ <var>2 × 4</var> ã®é·æ¹åœ¢ã§ãã¹ãŠåã倧ããã§ãããããã¯ã®è² <var>c</var> 㯠1 (çœ)ã2 (é»)ã3 (ç·)ã4 (é)ã5 (èµ€) ã®ããããã§ãããããã¯ã®ããŒãäžã§ã®åã <var>d</var> 㯠暪æ¹åã«é·ãå Žå 0 ã 瞊æ¹åã«é·ãå Žå 1 ãšããŸãã ãããã¯ã®äœçœ®ã¯ãããã¯ã®å·Šäžã®åº§æš (<var>x, y</var>) ã«ãã£ãŠè¡šãããŸãããªãããããã¯ã®äœçœ®ã¯ä»ã®ãããã¯ãšéãªãããšã¯ç¡ããããŒãããã¯ã¿åºãããšããããŸããã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸãã å
¥åã®çµããã¯ãŒããµãã€ã®è¡ã§ç€ºãããŸãã
åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>w</var> <var>h</var>
<var>xs</var> <var>ys</var>
<var>xg</var> <var>yg</var>
<var>n</var>
<var>c<sub>1</sub></var> <var>d<sub>1</sub></var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var>
<var>c<sub>2</sub></var> <var>d<sub>2</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var>
:
<var>c<sub>n</sub></var> <var>d<sub>n</sub></var> <var>x<sub>n</sub></var> <var>y<sub>n</sub></var>
</pre>
<p>
1 è¡ç®ã«ããŒãã®å€§ãã<var>w, h</var> (4 ≤ <var>w, h</var> ≤ 100) ãäžããããŸãã2 è¡ç®ã«ã¹ã¿ãŒãã®åº§æš <var>xs, ys</var>ã3 è¡ç®ã«ãŽãŒã«ã®åº§æš <var>xg, yg</var> ãäžããããŸãã
</p>
<p>
4 è¡ç®ã«ãããã¯ã®åæ° <var>n</var> ãäžããããŸããç¶ã <var>n</var> è¡ã« <var>i</var> çªç®ã®ãããã¯ã®è² <var>c<sub>i</sub></var>ãåã <var>d<sub>i</sub></var>ãäœçœ® <var>x<sub>i</sub>, y<sub>i</sub></var> ãäžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 30 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
å
¥åããŒã¿ã»ããããšã«ãå€å¥çµæãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
20 20
1 1
9 9
7
2 0 1 1
5 1 1 3
2 1 3 3
1 1 5 2
5 1 7 3
2 0 2 7
2 0 6 8
20 20
9 9
1 1
6
2 0 1 1
1 0 5 1
2 1 1 3
5 0 1 7
3 1 5 5
4 1 8 5
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
OK
NG
</pre>
|
p03581 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><var>A + B</var> balls are arranged in a row.
The leftmost <var>A</var> balls are colored red, and the rightmost <var>B</var> balls are colored blue.</p>
<p>You perform the following operation:</p>
<ul>
<li>First, you choose two integers <var>s, t</var> such that <var>1 \leq s, t \leq A + B</var>.</li>
<li>Then, you repeat the following step <var>A + B</var> times:
In each step, you remove the first ball or the <var>s</var>-th ball (if it exists) or the <var>t</var>-th ball (if it exists, all indices are 1-based) from left in the row, and give it to Snuke.</li>
</ul>
<p>In how many ways can you give the balls to Snuke?
Compute the answer modulo <var>10^9 + 7</var>.</p>
<p>Here, we consider two ways to be different if for some <var>k</var>, the <var>k</var>-th ball given to Snuke has different colors.
In particular, the choice of <var>s, t</var> doesn't matter.
Also, we don't distinguish two balls of the same color.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq A, B \leq 2000</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>A</var> <var>B</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>3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>20
</pre>
<p>There are <var>20</var> ways to give <var>3</var> red balls and <var>3</var> blue balls.
It turns out that all of them are possible.</p>
<p>Here is an example of the operation (<code>r</code> stands for red, <code>b</code> stands for blue):</p>
<ul>
<li>You choose <var>s = 3, t = 4</var>.</li>
<li>Initially, the row looks like <code>rrrbbb</code>.</li>
<li>You remove <var>3</var>rd ball (<code>r</code>) and give it to Snuke. Now the row looks like <code>rrbbb</code>.</li>
<li>You remove <var>4</var>th ball (<code>b</code>) and give it to Snuke. Now the row looks like <code>rrbb</code>.</li>
<li>You remove <var>1</var>st ball (<code>r</code>) and give it to Snuke. Now the row looks like <code>rbb</code>.</li>
<li>You remove <var>3</var>rd ball (<code>b</code>) and give it to Snuke. Now the row looks like <code>rb</code>.</li>
<li>You remove <var>1</var>st ball (<code>r</code>) and give it to Snuke. Now the row looks like <code>b</code>.</li>
<li>You remove <var>1</var>st ball (<code>b</code>) and give it to Snuke. Now the row is empty.</li>
</ul>
<p>This way, Snuke receives balls in the order <code>rbrbrb</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>67
</pre>
<p>There are <var>70</var> ways to give <var>4</var> red balls and <var>4</var> blue balls.
Among them, only <code>bbrrbrbr</code>, <code>brbrbrbr</code>, and <code>brrbbrbr</code> are impossible.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>7772
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1987 1789
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>456315553
</pre></section>
</div>
</span> |
p01046 |
<h1>Problem J: Yu-kun Likes a lot of Money</h1>
<h2>Background</h2>
<p>
äŒæŽ¥å€§åŠä»å±å¹Œçšåã¯ããã°ã©ãã³ã°ã倧奜ããªåäŸãéãŸã幌çšåã§ãããåå
ã®äžäººã§ããããåã¯ãããã°ã©ãã³ã°ãšåãããããéã倧奜ãã ãããåã¯ã仿¥ããéã皌ãããã«è²¡å®ã®ç ãå³¶ã蚪ãããããåã¯äºåã«è²¡å®ã®ãããã®æãããå°å³ãæã«å
¥ããŠããããã®å°å³ãããšã«åºæ¥ãã ãå€ãã®ãéã皌ããããããåã¯æå€§ã§ã©ã®ããããéãæã«å
¥ããããšãã§ããã ãããïŒ
</p>
<h2>Problem</h2>
<p>
å°å³ãããåã®åæäœçœ®ã財å®ã®çš®é¡ãšãããããåŸããããéããããŠå°ãã岩ãç Žå£ããããã«å¿
èŠãªè²»çšã®æ
å ±ãäžãããããå°å³ã®æ
å ±ã¯ <var>h</var>ãã¹ × <var>w</var>ãã¹ã®ãã£ãŒã«ããšããŠäžãããããå°å³ã®åãã¹ã«æžãããŠããæåãšãã®æå³ã¯æ¬¡ã®éãã§ããã
</p>
<ul>
<li>'@' : ããåãæåã«ããäœçœ®ã衚ããããåãç§»åããåŸã¯éãšåãããã«æ±ãã</li>
<li>'.' : éã衚ãããã®ãã¹ã¯èªç±ã«éãããšãã§ãè²»çšãããããªãã</li>
<li>'#' : 倧ããªå²©ã衚ãããã®ãã¹ã¯éãããšãã§ããªãã</li>
<li>'*' : å°ããªå²©ã衚ããäžå®ã®éé¡ãæ¯æãããšã§å£ãããšãã§ãããå£ããåŸã¯éã«ãªãã</li>
<li>'0','1',...,'9','a','b',...,'z','A','B',...,'Z' : 財å®ããããã¹ã衚ãããã®ãã¹ã蚪ããããšã§ããã«æžãããŠããæåã«å¯Ÿå¿ãã財å®ã®éé¡åã®ãéãåŸãããã ããéãåŸãããšãåºæ¥ãã®ã¯æåã«èšªããæã®ã¿ã§ããã</li>
</ul>
<p>
ããåã¯ïŒåã®ç§»åã§é£æ¥ããäžäžå·Šå³ã®ããããã®ãã¹ã«ç§»åããããšãã§ããã
ãã ããå°å³ã®å€ãžåºããããªç§»åã¯ã§ããªãã
</p>
<p>
åŸæããããããšãã§ãããããå°ããªå²©ãå£ãéã«ããã«å¿
èŠãªéé¡ããã®æã«ææããŠããå¿
èŠã¯ãªãããã®ãããããåã¯æçµçã«å°ããªå²©ãå£ãéã«ããã£ãéé¡ã®ç·å以äžã®ãéãåŸãŠããå¿
èŠãããã
</p>
<p>
ããåãåŸãããæå€§ã®éé¡ãåºåããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>h</var> <var>w</var> <var>n</var> <var>r</var>
<var>c<sub>1,1</sub></var> <var>c<sub>1,2</sub></var> ⊠<var>c<sub>1,w</sub></var>
<var>c<sub>2,1</sub></var> <var>c<sub>2,2</sub></var> ⊠<var>c<sub>2,w</sub></var>
âŠ
<var>c<sub>h,1</sub></var> <var>c<sub>h,2</sub></var> ⊠<var>c<sub>h,w</sub></var>
<var>m<sub>1</sub></var> <var>v<sub>1</sub></var>
<var>m<sub>2</sub></var> <var>v<sub>2</sub></var>
âŠ
<var>m<sub>n</sub></var> <var>v<sub>n</sub></var>
</pre>
<p>
ïŒè¡ç®ã«å°å³ã®çžŠã®é·ã<var>h</var>,暪ã®é·ã<var>w</var>,å°å³ã«å«ãŸãã財å®ã®æ°<var>n</var>,å°ããªå²©ãç Žå£ããããã«ãããè²»çš<var>r</var>ã空çœåºåãã§äžããããã
</p>
<p>
ç¶ã<var>h</var>è¡ã«å°å³ã衚ãåãã¹ã®æ
å ±<var>c<sub>i,j</sub></var>ã<var>w</var>åäžããããã ( 1 ≤ <var>i</var> ≤ <var>h</var>, 1 ≤ <var>j</var> ≤ <var>w</var> )
</p>
<p>
ç¶ã<var>n</var>è¡ã«è²¡å®ã®çš®é¡<var>m<sub>k</sub></var> ãšãã®è²¡å®ã®éé¡<var>v<sub>k</sub></var>ã空çœåºåãã§äžããããã ( 1 ≤ <var>k</var> ≤ <var>n</var> )
</p>
<h2>Constraints</h2>
<p>
å
¥åã¯ä»¥äžã®å¶çŽãæºããã
</p>
<ul>
<li>1 ≤ <var>h</var>,<var>w</var> ≤ 8</li>
<li>0 ≤ <var>n</var> ≤ min(<var>h</var>×<var>w</var> -1,62) ãã ããmin(<var>a</var>,<var>b</var>)ã¯<var>a</var>,<var>b</var>ã®æå°å€ã衚ã</li>
<li> 1 ≤ <var>v<sub>i</sub></var> ≤ 10<sup>5</sup> ( 1 ≤ <var>i</var> ≤ <var>n</var> )</li>
<li>1 ≤ <var>r</var> ≤ 10<sup>5</sup></li>
<li><var>c<sub>j,k</sub></var>, <var>m<sub>l</sub></var> ãé€ãå
šãŠã®å
¥åã¯æŽæ°ãšããŠäžãããã ( 1 ≤ <var>j</var> ≤ <var>h</var>, 1 ≤ <var>k</var> ≤ <var>w</var>, 1 ≤ <var>l</var> ≤ <var>n</var> )</li>
<li>å°å³ã«ã¯ã¡ããã©ã²ãšã€'@'ãæžãããŠãã</li>
<li>å°å³ã«ã¯ã¡ããã©<var>n</var>åã®è²¡å®ãæžãããŠãã</li>
<li>å°å³ã«æžãããŠãã財å®ã®çš®é¡ã¯å
¥åã§äžãããã<var>m<sub>l</sub></var>ã®ããããã§ãã</li>
<li>å°å³ã«åãçš®é¡ã®è²¡å®ãïŒã€ä»¥äžçŸããããšã¯ãªã</li>
</ul>
<h2>Output</h2>
<p>
ããåãåŸãããæå€§ã®ãéã®éé¡ã1è¡ã«åºåããã
</p>
<h2>Sample Input1</h2>
<pre>
3 3 1 10
@0.
...
...
0 100
</pre>
<h2>Sample Output1</h2>
<pre>
100
</pre>
<h2>Sample Input2</h2>
<pre>
3 3 1 10
@#b
.#.
.#.
b 100
</pre>
<h2>Sample Output2</h2>
<pre>
0
</pre>
<h2>Sample Input3</h2>
<pre>
3 3 1 20
@*C
..*
...
C 10
</pre>
<h2>Sample Output3</h2>
<pre>
0
</pre>
|
p01416 |
<H1>J: Tiles are Colorful</H1>
<p>
ICPC ã§è¯ãæçžŸãåããã«ã¯ä¿®è¡ãæ¬ ãããªãïŒããã㯠ICPC ã§åã¡ããã®ã§ïŒä»æ¥ãä¿®è¡ãããããšã«ããïŒ
</p>
<p>
仿¥ã®ä¿®è¡ã¯ïŒæµè¡ãã®ããºã«ããã°ããè§£ããŠïŒç¬çºåãéããããšãããã®ã§ããïŒä»æ¥ææŠããã®ã¯ïŒè²ãšãã©ãã®ã¿ã€ã«ã䞊ãã§ããŠããããäžæãæ¶ããŠããããºã«ã
</p>
<p>
åæç¶æ
ã§ã¯ïŒã°ãªããäžã®ããã€ãã®ãã¹ã«ã¿ã€ã«ã眮ãããŠããïŒåã¿ã€ã«ã«ã¯è²ãã€ããŠããïŒãã¬ã€ã€ãŒã¯ã²ãŒã éå§åŸïŒä»¥äžã®æé ã§ç€ºãããæäœãäœåãè¡ãããšãã§ããïŒ
</p>
<ol>
<li>ã¿ã€ã«ã眮ãããŠããªããã¹ã 1 ã€éžæãïŒãã®ãã¹ãå©ãïŒ</li>
<li>å©ãããã¹ããäžã«é ã«èŸ¿ã£ãŠããïŒã¿ã€ã«ã眮ãããŠãããã¹ã«è³ã£ããšããã§ãã®ã¿ã€ã«ã«çç®ããïŒã¿ã€ã«ã眮ãããŠãããã¹ããªããŸãŸç€é¢ã®ç«¯ã«èŸ¿ãçãããäœã«ãçç®ããªãïŒ</li>
<li>åæ§ã®æäœãå©ãããã¹ããäžã»å·Šã»å³æ¹åã«å¯ŸããŠè¡ãïŒæå€§ 4 æã®ã¿ã€ã«ãçç®ãããããšã«ãªãïŒ</li>
<li>çç®ããã¿ã€ã«ã®äžã§åãè²ã®ãã®ãããã°ïŒãããã®ã¿ã€ã«ãç€é¢ããåãé€ãïŒåãè²ã®ã¿ã€ã«ã®çµã 2 çµããã°ïŒãããäž¡æ¹ãåãé€ãïŒ</li>
<li>ã¿ã€ã«ãåãé€ããææ°ãšåãå€ã®åŸç¹ãå
¥ãïŒ</li>
<li>çç®ããããïŒ</li>
</ol>
<p>
ããšãã°ïŒä»¥äžã®ãããªç¶æ³ãèãããïŒã¿ã€ã«ã眮ãããŠããªããã¹ã¯ããªãªãã§ïŒã¿ã€ã«ã®è²ã¯ã¢ã«ãã¡ããã倧æåã§è¡šãããŠããïŒ
</p>
<center><pre>
..A.......
.......B..
..........
..B.......
..A.CC....
</pre></center>
<p>
ããã§äžãã 2 è¡ç®ïŒå·Šãã 3 åç®ã®ãã¹ãå©ãæäœãèããïŒçç®ããããšã«ãªãã¿ã€ã«ã¯ <tt>A</tt> , <tt>B</tt> , <tt>B</tt> ã® 3 æã§ããããïŒ<tt>B</tt> ã® 2 æãæ¶ããŠç€é¢ã¯ä»¥äžã®ããã«ãªãïŒ2 ç¹ãåŸãïŒ
</p>
<center><pre>
..A.......
..........
..........
..........
..A.CC....
</pre></center>
<p>
ãã®ããºã«ã¯ãã£ããããŠãããšæéåãã«ãªã£ãŠããŸãïŒç€é¢ã®äžéšãèŠããªããªãã©ã®ãããä¿®è¡ãè¶³ããªãã£ãã®ããããããªããªã£ãŠããŸãïŒ
åè²ã®ã¿ã€ã«ã¯ 2 æãã€çœ®ãããŠãããïŒãããããã¹ãŠæ¶ãããšã¯éããªãã®ã§ïŒäºãããã°ã©ã ã«åŸç¹ã®æå€§å€ãèšç®ãããŠããããïŒ
</p>
<H2>Input</H2>
<pre>
<i>M</i> <i>N</i>
<i>C</i><sub>1,1</sub><i>C</i><sub>1,2</sub>...<i>C</i><sub>1,<i>N</i></sub>
<i>C</i><sub>2,1</sub><i>C</i><sub>2,2</sub>...<i>C</i><sub>2,<i>N</i></sub>
...
<i>C</i><sub><i>M</i>,1</sub><i>C</i><sub><i>M</i>,2</sub>...<i>C</i><sub><i>M</i>,<i>N</i></sub>
</pre>
<p>
æŽæ° <i>M</i>, <i>N</i> ã¯ç€ã 瞊 <i>M</i> × æšª <i>N</i> ã®ãã¹ç®ã§ããããšã衚ãïŒ<i>C</i><sub><i>i</i>, <i>j</i></sub> ã¯ã¢ã«ãã¡ããã倧æåãŸãã¯ããªãªã ( <tt>.</tt> ) ã§ããïŒäžãã <i>i</i> è¡ç®ïŒå·Šãã <i>j</i> åç®ã®ãã¹ã«ã€ããŠïŒã¢ã«ãã¡ããã倧æåã®å Žåã¯çœ®ãããŠããã¿ã€ã«ã®è²ã衚ãïŒããªãªãã®å Žåã¯ãã®ãã¹ã«ã¿ã€ã«ã眮ãããŠããªãããšã衚ãïŒ
</p>
<p>
1 ≤ <i>M</i> ≤ 500ïŒ1 ≤ <i>N</i> ≤ 500 ãæºããïŒåã¢ã«ãã¡ããã倧æåã¯å
¥åäžã« 0 åãŸã㯠2 åçŸããïŒ
</p>
<H2>Output</H2>
<p>
åŸç¹ã®æå€§å€ã 1 è¡ã«åºåããïŒ
</p>
<H2>Sample Input 1</H2>
<pre>
5 10
..A.......
.......B..
..........
..B.......
..A.CC....
</pre>
<H2>Sample Output 1</H2>
<pre>
4
</pre>
<H2>Sample Input 2</H2>
<pre>
3 3
ABC
D.D
CBA
</pre>
<H2>Sample Output 2</H2>
<pre>
4
</pre>
<H2>Sample Input 3</H2>
<pre>
5 7
NUTUBOR
QT.SZRQ
SANAGIP
LMDGZBM
KLKIODP
</pre>
<H2>Sample Output 3</H2>
<pre>
34
</pre> |
p01103 |
<h3><u>A Garden with Ponds</u></h3>
<p>
Mr. Gardiner is a modern garden designer who is excellent at utilizing the terrain features.
His design method is unique: he first decides the location of ponds and design them with the terrain features intact.
</p>
<p>
According to his unique design procedure, all of his ponds are rectangular with simple aspect ratios.
First, Mr. Gardiner draws a regular grid on the map of the garden site so that the land is divided into cells of unit square, and annotates every cell with its elevation.
In his design method, a pond occupies a rectangular area consisting of a number of cells.
Each of its outermost cells has to be higher than all of its inner cells.
For instance, in the following grid map, in which numbers are elevations of cells, a pond can occupy the shaded area, where the outermost cells are shaded darker and the inner cells are shaded lighter.
You can easily see that the elevations of the outermost cells are at least three and those of the inner ones are at most two.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2017_C1" width="300pt">
</center>
<p>
A rectangular area on which a pond is built must have at least one inner cell.
Therefore, both its width and depth are at least three.
</p>
<p>
When you pour water at an inner cell of a pond, the water can be kept in the pond until its level reaches that of the lowest outermost cells.
If you continue pouring, the water inevitably spills over.
Mr. Gardiner considers the larger <i>capacity</i> the pond has, the better it is.
Here, the capacity of a pond is the maximum amount of water it can keep.
For instance, when a pond is built on the shaded area in the above map, its capacity is (3 − 1) + (3 − 0) + (3 − 2) = 6, where 3 is the lowest elevation of the outermost cells and 1, 0, 2 are the elevations of the inner cells.
Your mission is to write a computer program that, given a grid map describing the elevation of each unit square cell, calculates the largest possible capacity of a pond built in the site.
</p>
<p>
Note that neither of the following rectangular areas can be a pond.
In the left one, the cell at the bottom right corner is not higher than the inner cell.
In the right one, the central cell is as high as the outermost cells.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2017_C2" width="500pt">
</center>
<h3>Input</h3>
<p>
The input consists of at most 100 datasets, each in the following format.
</p>
<pre>
<i>d w</i>
<i>e</i><sub>1, 1</sub> ... <i>e</i><sub>1, <i>w</i></sub>
...
<i>e</i><sub><i>d</i>, 1</sub> ... <i>e<sub>d, w</sub></i>
</pre>
<p>
The first line contains <i>d</i> and <i>w</i>, representing the depth and the width, respectively, of the garden site described in the map.
They are positive integers between 3 and 10, inclusive.
Each of the following <i>d</i> lines contains <i>w</i> integers between 0 and 9, inclusive, separated by a space.
The <i>x</i>-th integer in the <i>y</i>-th line of the <i>d</i> lines is the elevation of the unit square cell with coordinates (<i>x, y</i>).
</p>
<p>
The end of the input is indicated by a line containing two zeros separated by a space.
</p>
<h3>Output</h3>
<p>
For each dataset, output a single line containing the largest possible capacity of a pond that can be built in the garden site described in the dataset.
If no ponds can be built, output a single line containing a zero.
</p>
<h3>Sample Input</h3>
<pre>3 3
2 3 2
2 1 2
2 3 1
3 5
3 3 4 3 3
3 1 0 2 3
3 3 4 3 2
7 7
1 1 1 1 1 0 0
1 0 0 0 1 0 0
1 0 1 1 1 1 1
1 0 1 0 1 0 1
1 1 1 1 1 0 1
0 0 1 0 0 0 1
0 0 1 1 1 1 1
6 6
1 1 1 1 2 2
1 0 0 2 0 2
1 0 0 2 0 2
3 3 3 9 9 9
3 0 0 9 0 9
3 3 3 9 9 9
0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>0
3
1
9
</pre> |
p01553 |
<h1>åé¡å ç®±æ ¹é§
äŒ</h1>
<p>æ¥æ¬ã®ãæ£æã®é¢šç©è©©ã«ç®±æ ¹é§
äŒããããŸããç®±æ ¹é§
äŒã¯ãåããŒã 10 人ã®èµ°è
ãäžç¶æããšã«è¥·ãã€ãªããªãããŽãŒã«ãç®æããšãããã®ã§ãããã¬ãã®æŸéã§ã¯äžç¶æã§åããŒã ã®ééé äœãšå
±ã«åã®äžç¶æããã®é äœå€åã衚瀺ãããŸããããã§ããããèŠãŠåã®äžç¶æã®åããŒã ã®ééé ãšããŠèãããããã®ãäœéããããçããŠãã ãããããããééé ã®æ°ã¯éåžžã«å€§ãããªãããã®ã§ã1,000,000,007 ã§å²ã£ãäœãã§çããŠäžããã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢ã§äžããããŸã
</p><blockquote>
<var>n</var><br><var>c<sub>1</sub></var><br><var>c<sub>2</sub></var><br>...<br><var>c<sub>n</sub></var><br></blockquote>
<p>1è¡ç®ã«ã¯ããŒã æ°ãè¡šãæ°å <var>n</var> (<var>1 ≤ n ≤ 200</var>) ããç¶ã <var>n</var> è¡ã«ã¯ 1 äœããé ã«åã®äžç¶æããã®é äœå€å <var>c<sub>i</sub></var> ('<code>D</code>' ãªãé äœãèœã¡ãŠãã'<code>U</code>' ãªãé äœãäžãã£ãŠãã'<code>-</code>' ãªãé äœãå€ãã£ãŠãªã) ãæžããŠãããŸãã
</p>
<h2>Output</h2>
<p>åã®äžç¶æã§ããããééé ãäœéãããã 1,000,000,007 ã§å²ã£ãããŸãã§ 1 è¡ã§åºåããŠäžããã
</p>
<h2>Sample Input 1</h2>
<pre>3
-
U
D
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>1
</pre>
<p>ãã®äžç¶æã 1 äœã 2 äœã 3 äœã§ééããããŒã ã®ããŒã åããããã A, B, C ãšãããšãåã®äžç¶æã®ééé ãšããŠèããããã®ã¯ 1 äœïŒããŒã A, 2 äœïŒããŒã C, 3 äœïŒããŒã B ã® 1 éãã®ã¿ã§ãã
</p>
<h2>Sample Input 2</h2>
<pre>5
U
U
-
D
D
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>5
</pre>
<p>ãã®äžç¶æã®ééé ã«ããŒã åã A, B, C, D, E ãšãããšãåã®äžç¶æã®ééé ãšããŠèããããã®ã¯ {D, E, C, A, B}, {D, E, C, B, A}, {E, D, C, A, B}, {E, D, C, B, A}, {D, A, C, E, B} ã®5éãã§ãã
</p>
<h2>Sample Input 3</h2>
<pre>8
U
D
D
D
D
D
D
D
</pre>
<h2>Output for the Sample Input 3</h2>
<pre>1
</pre>
<h2>Sample Input 4</h2>
<pre>10
U
D
U
D
U
D
U
D
U
D
</pre>
<h2>Output for the Sample Input 4</h2>
<pre>608
</pre>
<h2>Sample Input 5</h2>
<pre>2
D
U
</pre>
<h2>Output for the Sample Input 5</h2>
<pre>0
</pre>
|
p03094 | <span class="lang-en">
<p>Score : <var>1800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a round pizza. Snuke wants to eat one third of it, or something as close as possible to that.</p>
<p>He decides to cut this pizza as follows.</p>
<p>First, he divides the pizza into <var>N</var> pieces by making <var>N</var> cuts with a knife. The knife can make a cut along the segment connecting the center of the pizza and some point on the circumference of the pizza. However, he is very poor at handling knives, so the cuts are made at uniformly random angles, independent from each other.</p>
<p>Then, he chooses one or more <strong>consecutive</strong> pieces so that the total is as close as possible to one third of the pizza, and eat them. (Let the total be x of the pizza. He chooses consecutive pieces so that <var>|x - 1/3|</var> is minimized.)</p>
<p>Find the expected value of <var>|x - 1/3|</var>. It can be shown that this value is rational, and we ask you to print it modulo <var>10^9 + 7</var>, as described in Notes.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><p>When you print a rational number, first write it as a fraction <var>\frac{y}{x}</var>, where <var>x, y</var> are integers and <var>x</var> is not divisible by <var>10^9 + 7</var>
(under the constraints of the problem, such representation is always possible).
Then, you need to print the only integer <var>z</var> between <var>0</var> and <var>10^9 + 6</var>, inclusive, that satisfies <var>xz \equiv y \pmod{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>
</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 expected value of <var>|x - 1/3|</var> modulo <var>10^9 + 7</var>, as described in Notes.</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>138888890
</pre>
<p>The expected value is <var>\frac{5}{36}</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>179012347
</pre>
<p>The expected value is <var>\frac{11}{162}</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>954859137
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>44679646
</pre></section>
</div>
</span> |
p00712 |
<h1>
<font color="#000">Problem C:</font> Unit Fraction Partition
</h1>
<p>
A fraction whose numerator is 1
and whose denominator is a positive integer
is called a unit fraction.
A representation of a positive rational number
<I>p</I>/<I>q</I>
as the sum of finitely many unit fractions is called a <I>partition</I> of
<I>p</I>/<I>q</I>
into unit fractions.
For example,
1/2 + 1/6
is a partition of
2/3
into unit fractions.
The difference in the order of addition is disregarded.
For example, we do not distinguish
1/6 + 1/2
from
1/2 + 1/6.
</p>
<p>
For given four positive integers
<I>p</I>,
<I>q</I>,
<I>a</I>, and
<I>n</I>,
count the number
of partitions of
<I>p</I>/<I>q</I>
into unit fractions satisfying the following two conditions.
</p>
<UL>
<LI>
The partition is the sum of at most
<I>n</I>
many unit fractions.
</LI>
<LI>
The product of the denominators of the unit fractions in the
partition is less than or equal to
<I>a</I>.
</LI>
</UL>
<p>
For example, if
(<I>p</I>,<I>q</I>,<I>a</I>,<I>n</I>) = (2,3,120,3),
you should report 4 since
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_c009" WIDTH="104" HEIGHT="156" ALIGN="MIDDLE" BORDER="0" ALT="2/3 = 1/3 + 1/3 = 1/2 + 1/6 = 1/4 + 1/4 + 1/6 = 1/3 + 1/6 + 1/6">
</center>
<p>
enumerates all of the valid partitions.
</p>
<h2>Input</h2>
<p>
The input is a sequence of at most 1000 data sets followed by a terminator.
</p>
<p>
A data set is a line containing four positive integers
<I>p</I>,
<I>q</I>,
<I>a</I>, and
<I>n</I>
satisfying
<I>p</I>,<I>q</I> <= 800,
<I>a</I> <= 12000
and
<I>n</I> <= 7.
The integers are separated by a space.
</p>
<p>
The terminator is composed of just one line
which contains four zeros separated by a space.
It is not a part of the input data but a mark for the end of the input.
</p>
<h2>Output</h2>
<p>
The output should be composed of lines
each of which contains a single integer.
No other characters should appear in the output.
</p>
<p>
The output integer corresponding to a data set
<I>p</I>,
<I>q</I>,
<I>a</I>,
<I>n</I>
should be the number of all partitions of
<I>p</I>/<I>q</I>
into at most
<I>n</I>
many unit fractions such that the product of the denominators of the
unit fractions is less than or equal to
<I>a</I>.
</p>
<h2>Sample Input</h2>
<pre>
2 3 120 3
2 3 300 3
2 3 299 3
2 3 12 3
2 3 12000 7
54 795 12000 7
2 3 300 1
2 1 200 5
2 4 54 2
0 0 0 0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
4
7
6
2
42
1
0
9
3
</pre>
|
p01800 |
<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 K
Runner and Sniper</h2>
<p>
You are escaping from an enemy for some reason. The enemy is a sniper equipped with a high-tech laser gun, and you will be immediately defeated if you get shot. You are a very good runner, but just wondering how fast you have to run in order not to be shot by the sniper. The situation is as follows:
</p>
<p>
You and the sniper are on the $xy$-plane whose $x$-axis and $y$-axis are directed to the right and the top, respectively. You can assume that the plane is infinitely large, and that there is no obstacle that blocks the laser or your movement.
</p>
<p>
The sniper and the laser gun are at $(0, 0)$ and cannot move from the initial location. The sniper can continuously rotate the laser gun by at most $\omega$ degrees per unit time, either clockwise or counterclockwise, and can change the direction of rotation at any time. The laser gun is initially directed $\theta$ degrees counterclockwise from the positive direction of the $x$-axis.
</p>
<p>
You are initially at ($x$, $y$) on the plane and can move in any direction at speed not more than $v$ (you can arbitrarily determine the value of $v$ since you are a very good runner). You will be shot by the sniper exactly when the laser gun is directed toward your position, that is, you can ignore the time that the laser reaches you from the laser gun. Assume that your body is a point and the laser is a half-line whose end point is (0, 0).
</p>
<p>
Find the maximum speed $v$ at which you are shot by the sniper in finite time when you and the sniper behave optimally.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case. The input contains four integers in a line, $x$, $y$, $\theta$ and $\omega$. The two integers $x$ and $y$ $(0 \leq |x|, |y| \leq 1,000$, ($x$, $y$) $\ne$ (0, 0)) represent your initial position on the $xy$-plane. The integer $\theta$ $(0 \leq \theta < 360)$ represents the initial direction of the laser gun: it is the counterclockwise angle in degrees from the positive direction of the $x$-axis. The integer $\omega$ $(1 \leq \omega \leq 100)$ is the angle which the laser gun can rotate in unit time. You can assume that you are not shot by the sniper at the initial position.
</p>
<h3>Output</h3>
<p>
Display a line containing the maximum speed $v$ at which you are shot by the sniper in finite time. The
absolute error or the relative error should be less than $10^{-6}$.
</p>
<h3>Sample Input 1</h3>
<pre>100 100 0 1</pre>
<h3>Output for the Sample Input 1</h3>
<pre>1.16699564</pre> |
p00342 |
<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> åã®ç°ãªãèªç¶æ°ãäžããããããã®äžããç°ãªãïŒã€ãéžãã§ããããã $A$, $B$, $C$, $D$ ãšãããšããæ¬¡ã®æ°åŒ </p>
<center>
$\frac{A + B}{C - D}$ <br/>
</center>
<br/>
<p>
ã®æå€§å€ãæ±ãããã
</p>
<br/>
<p>
<var>N</var> åã®ç°ãªãèªç¶æ°ãäžãããããšãããã®äžããç°ãªãïŒã€ãéžãã§ãäžã®æ°åŒã®æå€§å€ãæ±ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>a<sub>1</sub></var> <var>a<sub>2</sub></var> ... <var>a<sub>N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«èªç¶æ°ã®åæ° <var>N</var> (4 ≤ <var>N</var> ≤ 1000) ãäžãããããïŒè¡ç®ã«åèªç¶æ°ã®å€ <var>a<sub>i</sub></var> (1 ≤ <var>a<sub>i</sub></var> ≤ 10<sup>8</sup>) ãäžããããããã ããåãèªç¶æ°ãéè€ããŠçŸããããšã¯ãªãïŒ<var>i</var> ≠ <var>j</var> ã«ã€ã㊠<var>a<sub>i</sub></var> ≠ <var>a<sub>j</sub></var>)ã
</p>
<h2>Output</h2>
<p>
äžãããã <var>N</var> åã®èªç¶æ°ã«å¯ŸããŠãäžã®æ°åŒã®æå€§å€ã宿°ã§åºåããããã ãã誀差ããã©ã¹ãã€ãã¹ 10<sup>-5</sup> ãè¶
ããŠã¯ãªããªãã
</p>
<h2>Sample Input 1</h2>
<pre>
10
1 2 3 4 5 6 7 8 9 10
</pre>
<h2>Sample Output 1</h2>
<pre>
19.00000
</pre>
<p>
å
¥åäŸïŒã§ã¯ã$A=9$, $B=10$, $C=2$, $D=1$ ãªã©ã®çµã¿åããã§æå€§ã«ãªãã
</p>
<br/>
<h2>Sample Input 2</h2>
<pre>
5
22 100 42 3 86
</pre>
<h2>Sample Output 2</h2>
<pre>
9.78947
</pre>
<p>
å
¥åäŸïŒã§ã¯ã$A=100$, $B=86$, $C=22$, $D=3$ ãªã©ã®çµã¿åããã§æå€§ã«ãªãã
</p>
<br/>
<h2>Sample Input 3</h2>
<pre>
6
15 21 36 10 34 5
</pre>
<h2>Sample Output 3</h2>
<pre>
18.00000
</pre>
<p>
å
¥åäŸïŒã§ã¯ã$A=21$, $B=15$, $C=36$, $D=34$ ãªã©ã®çµã¿åããã§æå€§ã«ãªãã
</p>
<br/>
<h2>Sample Input 4</h2>
<pre>
4
100000 99999 8 1
</pre>
<h2>Sample Output 4</h2>
<pre>
28571.285714
</pre>
<br/> |
p02685 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> blocks arranged in a row. Let us paint these blocks.</p>
<p>We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.</p>
<p>Find the number of ways to paint the blocks under the following conditions:</p>
<ul>
<li>For each block, use one of the <var>M</var> colors, Color <var>1</var> through Color <var>M</var>, to paint it. It is not mandatory to use all the colors.</li>
<li>There may be at most <var>K</var> pairs of adjacent blocks that are painted in the same color.</li>
</ul>
<p>Since the count may be enormous, print it modulo <var>998244353</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N, M \leq 2 \times 10^5</var></li>
<li><var>0 \leq K \leq N - 1</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> <var>K</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>3 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>The following ways to paint the blocks satisfy the conditions: <code>112</code>, <code>121</code>, <code>122</code>, <code>211</code>, <code>212</code>, and <code>221</code>. Here, digits represent the colors of the blocks.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>100 100 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>73074801
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>60522 114575 7559
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>479519525
</pre></section>
</div>
</span> |
p03997 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a trapezoid. The lengths of its upper base, lower base, and height are <var>a</var>, <var>b</var>, and <var>h</var>, respectively.</p>
<div style="text-align: center;">
<img src="https://atcoder.jp/img/arc061/1158e37155d46a42e90f31566478e6da.png">
<p>An example of a trapezoid</p>
</img></div>
<p>Find the area of this trapezoid.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1âŠaâŠ100</var></li>
<li><var>1âŠbâŠ100</var></li>
<li><var>1âŠhâŠ100</var></li>
<li>All input values are integers.</li>
<li><var>h</var> is even.</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>a</var>
<var>b</var>
<var>h</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the area of the given trapezoid. It is guaranteed that the area is an integer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
4
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7
</pre>
<p>When the lengths of the upper base, lower base, and height are <var>3</var>, <var>4</var>, and <var>2</var>, respectively, the area of the trapezoid is <var>(3+4)Ã2/2 = 7</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
4
4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>16
</pre>
<p>In this case, a parallelogram is given, which is also a trapezoid.</p></section>
</div>
</span> |
p00196 |
<H1>éç倧äŒ</H1>
<p>
éçã®åœå¥å¯ŸææŠ WBC ã§ãæ¥æ¬ã2é£èŠéæ!! éç人æ°ãé«ãŸãäžãäŒæŽ¥åŠå髿 ¡ãäŒå Žã«éç倧äŒãè¡ãããŸããããã®å€§äŒã§ã¯ãç·åœãã®ãªãŒã°æŠãè¡ãã以äžã®ãããªæ¹æ³ã§é äœã決ããããšã«ãªããŸããã
</p>
<ol>
<li> åã¡æ°ã®å€ãããŒã ãäžäœãšãã</li>
<li> åã¡æ°ãåæ°ã®å Žåã¯è² ãæ°ã®å°ãªãããŒã ãäžäœãšãã</li>
</ol>
<p>
åããŒã ã®æçžŸãå
¥åãšããããŒã åãäžäœã®ããŒã ããé ã«åºåããããã°ã©ã ãäœæããŠãã ãããåé äœã®ããŒã ãååšããå Žåã¯ãå
¥åé ã«åºåããŠãã ããããã ããããŒã æ° <var>n</var> 㯠2 ä»¥äž 10 以äžã®æŽæ°ãããŒã å <var>t</var> 㯠1 æåã®åè§è±åãè©Šåæ¯ã®æçžŸ <var>r</var> 㯠<var>n</var> - 1 åã®æ°åã§è¡šãããåã¡ã®å Žå㯠0 ãè² ãã®å Žå㯠1 ãåŒãåãã®å Žå㯠2 ãšããŸãããŸããããŒã åã«éè€ã¯ãªããã®ãšããŸãã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã
åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var>
<var>score<sub>1</sub></var>
<var>score<sub>2</sub></var>
:
<var>score<sub>n</sub></var>
</pre>
<p>
1 è¡ç®ã«ããŒã ã®æ° <var>n</var> (2 ≤ <var>n</var> ≤ 10) ãç¶ã <var>n</var> è¡ã«ç¬¬ <var>i</var> ã®ããŒã ã®æçžŸ <var>score<sub>i</sub></var> ãäžããããŸããåæçžŸã¯æ¬¡ã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>t</var> <var>r<sub>1</sub></var> <var>r<sub>2</sub></var> ... <var>r<sub>n−1</sub></var>
</pre>
<p>
ããŒã å <var>t</var> (ïŒæåã®åè§è±å)ã<var>t</var> ã®è©Šåæ¯ã®æçžŸ <var>r<sub>i</sub></var> (0, 1, ãŸã㯠2) ã空çœåºåãã§äžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããããšã«ãããŒã åãäžäœã®ããŒã ããé ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
6
A 1 0 0 2 0
B 0 0 1 1 0
C 1 1 1 1 1
D 1 0 0 1 2
E 2 0 0 0 0
F 1 1 0 2 1
4
g 1 1 1
h 0 1 2
w 0 0 0
b 0 2 1
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
E
A
B
D
F
C
w
h
b
g
</pre>
|
p02451 | <h1>Binary Search</h1>
<p>
For a given sequence $A = \{a_0, a_1, ..., a_{n-1}\}$ which is sorted by ascending order, find a specific value $k$ given as a query.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$n$
$a_0 \; a_1 \; ,..., \; a_{n-1}$
$q$
$k_1$
$k_2$
:
$k_q$
</pre>
<p>
The number of elements $n$ and each element $a_i$ are given in the first line and the second line respectively. In the third line, the number of queries $q$ is given and the following $q$ lines, $q$ integers $k_i$ are given as queries.
<h2>Output</h2>
<p>
For each query, print <span>1</span> if any element in $A$ is equivalent to $k$, and <span>0</span> otherwise.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq n \leq 100,000$</li>
<li>$1 \leq q \leq 200,000$</li>
<li>$0 \leq a_0 \leq a_1 \leq ... \leq a_{n-1} \leq 1,000,000,000$
<li>$0 \leq k_i \leq 1,000,000,000$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
4
1 2 2 4
3
2
3
5
</pre>
<h2>Sample Output 1</h2>
<pre>
1
0
0
</pre>
|
p02001 | <h1>F: Swap</h1>
<h2>åé¡</h2>
<p>
é·ã $N$ ã®æåå $S,\ T$ ãäžããããŸãïŒ$S,\ T$ ã¯ãããã 'o' , '.' ã®äºçš®é¡ã®æåã ãã§æ§æãããŠããŸãïŒ
ããªã㯠$S$ ã«å¯ŸããŠïŒä»¥äžã®æäœãè¡ãããšãã§ããŸãïŒ
</p>
<p>
<ul>
<li> 以äžã®æ¡ä»¶ãå
šãŠæºããæŽæ°å¯Ÿ $(l, r)$ ãéžæããïŒãã®åŸïŒ$S[l]$ ãš $S[l + 1]ïŒS[r - 1]$ ãš $S[r]$ ãããããã¹ã¯ããããïŒ</li>
<ul>
<li>$1 \leq l, r \leq N$</li>
<li>$r - l \geq 3$</li>
<li>$S[l] = S[r] =$ '.'</li>
<li>$S[l + 1] = S[l + 2] = \dots = S[r - 1] =$ 'o'</li>
</ul>
</ul>
</p>
<p>
äœåãæäœãç¹°ãè¿ããããš(0åã§ãå¯)ïŒæåå S ã T ã«å€åœ¢ããããšãå¯èœãå€å®ããŠãã ããïŒ
</p>
<h2>å¶çŽ</h2>
<ul>
<li>$1 \leq N \leq 100000$</li>
<li>$|S| = |T| = N \ \ \ \ \ \ \ |S|$ , $|T|$ ã¯æååã®é·ã</li>
<li>$S$ , $T$ 㯠'o', '.' ã®äºçš®é¡ã®æåããã®ã¿æ§æãããã
</ul>
<h2>å
¥å圢åŒ</h2>
<p> å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã </p>
<p>
$N$<br>
$S$<br>
$T$<br>
</p>
<h2>åºå</h2>
<p>æäœãäœåãé©çšåŸ( $0$ åã§ãå¯)ïŒ $S$ ã $T$ ã«å€åœ¢ããããšãå¯èœãªãã° YesïŒã©ã®ããã«æäœããŠãäžå¯èœãªãã° No ãåºåããŠãã ããïŒãŸããæ«å°Ÿã«æ¹è¡ãåºåããŠãã ããïŒ
</p>
<h2>ãµã³ãã«</h2>
<h3>ãµã³ãã«å
¥å 1</h3>
<pre>
8
.oo.ooo.
o.o.oo.o
</pre>
<h3>ãµã³ãã«åºå 1</h3>
<pre>
Yes
</pre>
<p>
以äžã®æé ã§æäœãè¡ãããšã§éæã§ããŸãïŒ
<ol>
<li>$S$ = ".oo.ooo." : $(l, r) = (1, 4)$ ãéžæããïŒ</li>
<li>$S$ = "o..oooo." : $(l, r) = (4, 9)$ ãéžæããïŒ</li>
<li>$S$ = "o.o.oo.o" : $T$ ãšäžèŽãïŒç®çãéæïŒ</li>
</ol>
</p>
<h3>ãµã³ãã«å
¥å 2</h3>
<pre>
7
.ooooo.
oo.o.oo
</pre>
<h3>ãµã³ãã«åºå 2</h3>
<pre>
Yes
</pre>
<p>
以äžã®æé ã§æäœãè¡ãããšã§éæã§ããŸãïŒ
<ol>
<li>$S$ = ".ooooo." : $(l, r) = (1, 7)$ ãéžæããïŒ</li>
<li>$S$ = "o.ooo.o" : $(l, r) = (2, 6)$ ãéžæããïŒ</li>
<li>$S$ = "oo.o.oo" : $T$ ãšäžèŽãïŒç®çãéæïŒ</li>
</ol>
</p>
<h3>ãµã³ãã«å
¥å 3</h3>
<pre>
6
o.o.o.
ooo...
</pre>
<h3>ãµã³ãã«åºå 3</h3>
<pre>
No
</pre>
<p>
æäœãé©çšã§ãã $(l, r)$ ãååšããªãããïŒ$S$ ãå€åœ¢ã㊠$T$ ã«ããããšãã§ããŸããïŒ
</p>
<h3>ãµã³ãã«å
¥å 4</h3>
<pre>
9
.oo.oooo.
.oo.oooo.
</pre>
<h3>ãµã³ãã«åºå 4</h3>
<pre>
Yes
</pre>
<p>
$1$ åãå€åœ¢ãããã«ç®çãéæã§ããŸã
</p>
<h3>ãµã³ãã«å
¥å 5</h3>
<pre>
11
.oooo.oooo.
oo.oo.oo.oo
</pre>
<h3>ãµã³ãã«åºå 5</h3>
<pre>
Yes
</pre>
|
p00895 |
<H1><font color="#000">Problem B: </font>The Sorcerer's Donut </H1>
<p>
Your master went to the town for a day. You could have a relaxed day without hearing his
scolding. But he ordered you to make donuts dough by the evening. Loving donuts so much, he
can't live without eating tens of donuts everyday. What a chore for such a beautiful day.
</p>
<p>
But last week, you overheard a magic spell that your master was using. It was the time to
try. You casted the spell on a broomstick sitting on a corner of the kitchen. With a flash of
lights, the broom sprouted two arms and two legs, and became alive. You ordered him, then he
brought flour from the storage, and started kneading dough. The spell worked, and how fast he
kneaded it!
</p>
<p>
A few minutes later, there was a tall pile of dough on the kitchen table. That was enough for
the next week. \OK, stop now." You ordered. But he didn't stop. Help! You didn't know the
spell to stop him! Soon the kitchen table was filled with hundreds of pieces of dough, and he
still worked as fast as he could. If you could not stop him now, you would be choked in the
kitchen filled with pieces of dough.
</p>
<p>
Wait, didn't your master write his spells on his notebooks? You went to his den, and found the
notebook that recorded the spell of cessation.
</p>
<p>
But it was not the end of the story. The spell written in the notebook is not easily read by
others. He used a plastic model of a donut as a notebook for recording the spell. He split the
surface of the donut-shaped model into square mesh (Figure B.1), and filled with the letters
(Figure B.2). He hid the spell so carefully that the pattern on the surface looked meaningless.
But you knew that he wrote the pattern so that the spell "appears" more than once (see the next
paragraph for the precise conditions). The spell was not necessarily written in the left-to-right
direction, but any of the 8 directions, namely left-to-right, right-to-left, top-down, bottom-up,
and the 4 diagonal directions.
</p>
<p>
You should be able to find the spell as the longest string that appears more than once. Here,
a string is considered to appear more than once if there are square sequences having the string
on the donut that satisfy the following conditions.<br><br>
<li>Each square sequence does not overlap itself. (Two square sequences can share some squares.)</li>
<li>The square sequences start from different squares, and/or go to different directions.</li>
</p>
<center>
<table width="480">
<tr>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1316_1">
</td>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1316_2">
</td>
<tr>
<td>
<b>Figure B.1: The Sorcerer's Donut Before
Filled with Letters, Showing the Mesh and 8
Possible Spell Directions </b>
</td>
<td valign="top">
<b>
Figure B.2: The Sorcerer's Donut After Filled
with Letters
</b>
</td>
</tr>
</table>
</center>
<p>
Note that a palindrome (i.e., a string that is the same whether you read it backwards or forwards)
that satisfies the first condition "appears" twice.
</p>
<p>
The pattern on the donut is given as a matrix of letters as follows.
</p>
<pre>
ABCD
EFGH
IJKL
</pre>
<p>
Note that the surface of the donut has no ends; the top and bottom sides, and the left and right
sides of the pattern are respectively connected. There can be square sequences longer than both
the vertical and horizontal lengths of the pattern. For example, from the letter F in the above
pattern, the strings in the longest non-self-overlapping sequences towards the 8 directions are
as follows.
</p>
<pre>
FGHE
FKDEJCHIBGLA
FJB
FIDGJAHKBELC
FEHG
FALGBIHCJEDK
FBJ
FCLEBKHAJGDI
</pre>
<p>
Please write a program that finds the magic spell before you will be choked with pieces of donuts
dough.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets. Each dataset begins with a line of two integers <i>h</i> and <i>w</i>,
which denote the size of the pattern, followed by <i>h</i> lines of <i>w</i> uppercase letters from A to Z,
inclusive, which denote the pattern on the donut. You may assume 3 ≤ <i>h</i> ≤ 10 and 3 ≤ <i>w</i> ≤ 20.
</p>
<p>
The end of the input is indicated by a line containing two zeros.
</p>
<H2>Output</H2>
<p>
For each dataset, output the magic spell. If there is more than one longest string of the same
length, the first one in the dictionary order must be the spell. The spell is known to be at least
two letters long. When no spell is found, output 0 (zero).
</p>
<H2>Sample Input</H2>
<pre>
5 7
RRCABXT
AABMFAB
RROMJAC
APTADAB
YABADAO
3 13
ABCDEFGHIJKLM
XMADAMIMADAMY
ACEGIKMOQSUWY
3 4
DEFG
ACAB
HIJK
3 6
ABCDEF
GHIAKL
MNOPQR
10 19
JFZODYDXMZZPEYTRNCW
XVGHPOKEYNZTQFZJKOD
EYEHHQKHFZOVNRGOOLP
QFZOIHRQMGHPNISHXOC
DRGILJHSQEHHQLYTILL
NCSHQMKHTZZIHRPAUJA
NCCTINCLAUTFJHSZBVK
LPBAUJIUMBVQYKHTZCW
XMYHBVKUGNCWTLLAUID
EYNDCCWLEOODXYUMBVN
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
ABRACADABRA
MADAMIMADAM
ABAC
0
ABCDEFGHIJKLMNOPQRSTUVWXYZHHHHHABCDEFGHIJKLMNOPQRSTUVWXYZ
</pre> |
p01787 | <h2>H - RLE Replacement</h2>
<h3>Problem Statement</h3>
<p>
In JAG Kingdom, ICPC (Intentionally Compressible Programming Code) is one of the common programming languages. Programs in this language only contain uppercase English letters and the same letters often appear repeatedly in ICPC programs. Thus, programmers in JAG Kingdom prefer to compress ICPC programs by <i>Run Length Encoding</i> in order to manage very large-scale ICPC programs.
</p>
<p>
Run Length Encoding (RLE) is a string compression method such that each maximal sequence of the same letters is encoded by a pair of the letter and the length. For example, the string "RRRRLEEE" is represented as "R4L1E3" in RLE.
</p>
<p>
Now, you manage many ICPC programs encoded by RLE. You are developing an editor for ICPC programs encoded by RLE, and now you would like to implement a replacement function. Given three strings $A$, $B$, and $C$ that are encoded by RLE, your task is to implement a function replacing the first occurrence of the substring $B$ in $A$ with $C$, and outputting the edited string encoded by RLE. If $B$ does not occur in $A$, you must output $A$ encoded by RLE without changes.
</p>
<h3>Input</h3>
<p>
The input consists of three lines.
</p>
<blockquote> $A$<br> $B$<br> $C$</blockquote>
<p>
The lines represent strings $A$, $B$, and $C$ that are encoded by RLE, respectively. Each of the lines has the following format:
</p>
<blockquote> $c_1$ $l_1$ $c_2$ $l_2$ $\ldots$ $c_n$ $l_n$ \$</blockquote>
<p>
Each $c_i$ ($1 \leq i \leq n$) is an uppercase English letter (<code>A</code>-<code>Z</code>) and $l_i$ ($1 \leq i \leq n$, $1 \leq l_i \leq 10^8$) is an integer which represents the length of the repetition of $c_i$. The number $n$ of the pairs of a letter and an integer satisfies $1 \leq n \leq 10^3$. A terminal symbol <code>$</code> indicates the end of a string encoded by RLE. The letters and the integers are separated by a single space. It is guaranteed that $c_i \neq c_{i+1}$ holds for any $1 \leq i \leq n-1$.
</p>
<h3>Output</h3>
<p>
Replace the first occurrence of the substring $B$ in $A$ with $C$ if $B$ occurs in $A$, and output the string encoded by RLE. The output must have the following format:
</p>
<blockquote> $c_1$ $l_1$ $c_2$ $l_2$ $\ldots$ $c_m$ $l_m$ \$</blockquote>
<p>
Here, $c_i \neq c_{i+1}$ for $1 \leq i \leq m-1$ and $l_i \gt 0$ for $1 \leq i \leq m$ must hold.
</p>
<h3>Sample Input 1</h3>
<pre>R 100 L 20 E 10 \$
R 5 L 10 \$
X 20 \$</pre>
<h3>Output for the Sample Input 1</h3>
<pre>R 95 X 20 L 10 E 10 \$</pre>
<h3>Sample Input 2</h3>
<pre>A 3 B 3 A 3 \$
A 1 B 3 A 1 \$
A 2 \$</pre>
<h3>Output for the Sample Input 2</h3>
<pre>A 6 \$</pre>
|
p03240 | <span class="lang-en">
<p>Score: <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc.<br/>
The pyramid had <em>center coordinates</em> <var>(C_X, C_Y)</var> and <em>height</em> <var>H</var>. The altitude of coordinates <var>(X, Y)</var> is <var>max(H - |X - C_X| - |Y - C_Y|, 0)</var>. </p>
<p>Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information: </p>
<ul>
<li><var>C_X, C_Y</var> was integers between <var>0</var> and <var>100</var> (inclusive), and <var>H</var> was an integer not less than <var>1</var>. </li>
<li>Additionally, he obtained <var>N</var> pieces of information. The <var>i</var>-th of them is: "the altitude of point <var>(x_i, y_i)</var> is <var>h_i</var>." </li>
</ul>
<p>This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above. </p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>N</var> is an integer between <var>1</var> and <var>100</var> (inclusive).</li>
<li><var>x_i</var> and <var>y_i</var> are integers between <var>0</var> and <var>100</var> (inclusive).</li>
<li><var>h_i</var> is an integer between <var>0</var> and <var>10^9</var> (inclusive).</li>
<li>The <var>N</var> coordinates <var>(x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_N, y_N)</var> are all different.</li>
<li>The center coordinates and the height of the pyramid can be uniquely identified.</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_1</var> <var>y_1</var> <var>h_1</var>
<var>x_2</var> <var>y_2</var> <var>h_2</var>
<var>x_3</var> <var>y_3</var> <var>h_3</var>
<var>:</var>
<var>x_N</var> <var>y_N</var> <var>h_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print values <var>C_X, C_Y</var> and <var>H</var> representing the center coordinates and the height of the pyramid in one line, with spaces in between. </p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
2 3 5
2 1 5
1 2 5
3 2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2 2 6
</pre>
<p>In this case, the center coordinates and the height can be identified as <var>(2, 2)</var> and <var>6</var>. </p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
0 0 100
1 1 98
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0 0 100
</pre>
<p>In this case, the center coordinates and the height can be identified as <var>(0, 0)</var> and <var>100</var>.<br/>
Note that <var>C_X</var> and <var>C_Y</var> are known to be integers between <var>0</var> and <var>100</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3
99 1 191
100 1 192
99 0 192
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>100 0 193
</pre>
<p>In this case, the center coordinates and the height can be identified as <var>(100, 0)</var> and <var>193</var>. </p></section>
</div>
</span> |
p02902 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is a directed graph <var>G</var> with <var>N</var> vertices and <var>M</var> edges.<br/>
The vertices are numbered <var>1</var> to <var>N</var>, and the <var>i</var>-th edge is directed from Vertex <var>A_i</var> to Vertex <var>B_i</var>.<br/>
It is guaranteed that the graph contains no self-loops or multiple edges.</p>
<p>Determine whether there exists an induced subgraph (see Notes) of <var>G</var> such that the in-degree and out-degree of every vertex are both <var>1</var>. If the answer is yes, show one such subgraph.<br/>
Here the null graph is not considered as a subgraph.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><p>For a directed graph <var>G = (V, E)</var>, we call a directed graph <var>G' = (V', E')</var> satisfying the following conditions an induced subgraph of <var>G</var>:</p>
<ul>
<li><var>V'</var> is a (non-empty) subset of <var>V</var>.</li>
<li><var>E'</var> is the set of all the edges in <var>E</var> that have both endpoints in <var>V'</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 1000</var></li>
<li><var>0 \leq M \leq 2000</var></li>
<li><var>1 \leq A_i,B_i \leq N</var></li>
<li><var>A_i \neq B_i</var></li>
<li>All pairs <var>(A_i, B_i)</var> are distinct.</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>M</var>
<var>A_1</var> <var>B_1</var>
<var>A_2</var> <var>B_2</var>
<var>:</var>
<var>A_M</var> <var>B_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there is no induced subgraph of <var>G</var> that satisfies the condition, print <code>-1</code>.
Otherwise, print an induced subgraph of <var>G</var> that satisfies the condition, in the following format:</p>
<pre><var>K</var>
<var>v_1</var>
<var>v_2</var>
:
<var>v_K</var>
</pre>
<p>This represents the induced subgraph of <var>G</var> with <var>K</var> vertices whose vertex set is <var>\{v_1, v_2, \ldots, v_K\}</var>. (The order of <var>v_1, v_2, \ldots, v_K</var> does not matter.)
If there are multiple subgraphs of <var>G</var> that satisfy the condition, printing any of them is accepted.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 5
1 2
2 3
2 4
4 1
4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
1
2
4
</pre>
<p>The induced subgraph of <var>G</var> whose vertex set is <var>\{1, 2, 4\}</var> has the edge set <var>\{(1, 2), (2, 4), (4, 1)\}</var>. The in-degree and out-degree of every vertex in this graph are both <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 5
1 2
2 3
2 4
1 4
4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>There is no induced subgraph of <var>G</var> that satisfies the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 9
1 2
2 3
3 4
4 5
5 6
5 1
5 2
6 1
6 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
2
3
4
5
</pre></section>
</div>
</span> |
p03610 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>s</var> consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index <var>1</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>Each character in <var>s</var> is a lowercase English letter.</li>
<li><var>1â€|s|â€10^5</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>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the string obtained by concatenating all the characters in the odd-numbered positions.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>atcoder
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>acdr
</pre>
<p>Extract the first character <code>a</code>, the third character <code>c</code>, the fifth character <code>d</code> and the seventh character <code>r</code> to obtain <code>acdr</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>aaaa
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>aa
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>z
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>z
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>fukuokayamaguchi
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>fkoaaauh
</pre></section>
</div>
</span> |
p01338 |
<h1><font color="#000">Problem F:</font> KULASIS</h1>
<h2>Description</h2>
<p>
<i>
ãKULASISãšã¯ïŒå
šåŠå
±éç§ç®ã«é¢ããæ
å ±ãWebåãïŒåŠçã»æå¡ãžã®æ¯æŽããµãŒãã¹ã®åäžãç®çã«ïŒé«çæè²ç ç©¶éçºæšé²æ©æ§ã§éçºã»éçšããŠããã·ã¹ãã ã®åç§°ã§ãããKULASISã¯2003幎床ã®ãªã³ã©ã€ã³ã·ã©ãã¹éçºããå§ãŸãïŒWebæ²ç€ºæ¿ã»å±¥ä¿®ç»é²ã»æçžŸé¢ä¿ïŒæ¡ç¹ç»é²ã»åŠçããã®æ¡ç¹ç¢ºèªïŒãšé 次ã·ã¹ãã ãæ¡å
ããŠããŸããã<br>
ãåŠçã¯ããœã³ã³ã»æºåž¯é»è©±ããåŠå
å€ãåããïŒæåæ
å ±ïŒäŒè¬ã»ææ¥å€æŽã»ã¬ããŒãïŒã®ç¢ºèªã»å±¥ä¿®ç»é²ã»æ¡ç¹ç¢ºèªçã®æ©èœãå©çšããããšãã§ããŸãããã°ã€ã³ä»¶æ°ã¯å€ãæ¥ã«ã¯10,000ä»¶ãè¶
ãïŒäº¬éœå€§åŠã®æåæ
å ±ã·ã¹ãã ãšããŠæµžéãïŒå
šåŠå
±éç§ç®ã履修ããããã«ã¯æ¬ ãããªããã®ãšãªã£ãŠããŸãããã®KULASISãå
šåŠå
±éç§ç®ã®ã¿ã«ãšã©ãŸããïŒåŠéšå°é課çšã倧åŠé¢ã«ãé©çšã§ãããã éçºãé²ããŠããŸãã<br>
http://www.z.k.kyoto-u.ac.jp/introduction_kulasis.html
</i>
</p>
<p>
京倧çã®Qã¯åŸæã®ã·ã©ãã¹ãçµãããã«KULASISã«ãã°ã€ã³ããŠããïŒ
ã©ã®ç§ç®ãå
¥ããããšããŠãããæ©ãã§ãããšïŒçªç¶KULASISãç©ãå
ãæŸã¡ïŒå¥ã®ããŒãžãžãšé·ç§»ããïŒ<br>
é·ç§»ããå
ã®ããŒãžã¯äžå³ã®ãããªãã®ã§ãã£ãïŒ5x5ã®ãã¹ã«ã¯ç§ç®åãšè©äŸ¡(äžå¯ïŒå¯ïŒè¯ïŒåª)ãæžãããŠããïŒæ Œåäžã«ã¯<font color=orange>â</font>ã®ãã¿ã³ã16åé
眮ãããŠããïŒ<br>
ãã£ãããªã«ãèµ·ããã®ãåãããªãã£ãQã ã£ããïŒã©ãããæ Œåäžã«ãã<font color=orange>â</font>ã®ãã¿ã³ãæŒããšïŒãã®å³äžïŒå³äžïŒå·ŠäžïŒå·Šäžã«ãããã¹ã®ç§ç®ã®è©äŸ¡ããããã äžå¯âå¯ïŒå¯âè¯ïŒè¯âåªïŒåªâäžå¯ ãšå
¥ãæ¿ããããã§ãã£ãïŒ<br>
<br><br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_03Ffig" height=263 width=646><br>
<br><br>
<font color=orange>â</font>ã®ãã¿ã³ã¯äœåºŠã§ãæŒãããšãã§ããïŒ<br>
KULASISãäœè
ãã«ãã£ãŠæžãæããããŠããŸã£ãã®ãèªåã倢ãèŠãŠããã®ãããåãããªããïŒããã§æçžŸã確å®ã§ãããªãã°ïŒåºæ¥ãã ãè¯ãæçžŸãåŸãããšQã¯èããïŒ<br>
åäœãå€ãéããŠããããšã«èªä¿¡ããã£ãQã¯ïŒåäœã®æ°ãã®ãã®ãããå幎åŸã®ç 究宀é
å±ã«åããŠ<b>æŠéå</b>ãæå€§ã«ãããããšã«ããïŒ<br>
<b>æŠéå</b>ãšã¯åç§ç®ã®è©äŸ¡ãïŒäžå¯â0ç¹ïŒå¯â60ç¹ïŒè¯â70ç¹ïŒåªâ80ç¹ãšæç®ããŠåèšããå€ã®ããšã§ïŒããã¯ç 究宀é
å±ã®éã«èªåãã©ã®çšåºŠåªäœãªã®ãã衚ããš(Qã®åŠç§ã§ã¯)æãããŠããïŒ<br>
<br>
ããŸïŒKULASISã®ç»é¢ã®è¡šç€ºãããŠããç§ç®ãšãã®è©äŸ¡ãäžããããã®ã§ïŒåŸãããšãåºæ¥ã<b>æŠéå</b>ã®æå€§å€ãåºåããããã°ã©ã ãèšããŠã»ããïŒ
</p>
<h2>Input</h2>
<p>
å
¥åã®1è¡ç®ã«ã¯ãã¹ãã±ãŒã¹ã®åæ°ãäžããããïŒãã¹ãã±ãŒã¹ã®æ°ã¯100å以äžã§ããããšãä¿éãããŠããïŒ<br>
2è¡ç®ä»¥éã¯5x5ã®æ°åã䞊ã³ïŒKULASISã®ç»é¢ã«è¡šç€ºãããŠããç§ç®ã®è©äŸ¡ãäžãããïŒ1,2,3,4ãããããäžå¯ïŒå¯ïŒè¯ïŒåªã«å¯Ÿå¿ããïŒ<br>
0ãªãã°ãã®ã³ãã«ã¯ç§ç®ã¯ç»é²ãããŠããªãïŒ<br>
ãã¹ãã±ãŒã¹å士ã®éã¯ç©ºè¡ã§åºåãããŠããïŒ
</p>
<h2>Output</h2>
<p>
åãã¹ãã±ãŒã¹ã«å¯ŸãïŒåŸãããšã®åºæ¥ã<b>æŠéå</b>ã®æå€§å€ãåºåããïŒ
</p>
<h2>Sample Input</h2>
<pre>
5
1 1 0 3 3
1 1 0 3 3
0 0 0 0 0
2 2 0 4 4
2 2 0 4 4
1 1 1 0 0
1 1 1 1 0
1 0 1 1 0
0 0 1 1 1
1 1 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
4 3 4 3 4
3 4 3 4 3
4 3 4 3 4
3 4 3 4 3
4 3 4 3 4
2 2 2 2 2
0 0 0 2 0
2 2 0 2 0
2 2 0 2 0
0 0 0 2 0
</pre>
<h2>Output for Sample Input</h2>
<pre>
1280
1420
0
1920
1020
</pre>
|
p03305 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Kenkoooo is planning a trip in Republic of Snuke.
In this country, there are <var>n</var> cities and <var>m</var> trains running.
The cities are numbered <var>1</var> through <var>n</var>, and the <var>i</var>-th train connects City <var>u_i</var> and <var>v_i</var> bidirectionally.
Any city can be reached from any city by changing trains.</p>
<p>Two currencies are used in the country: yen and snuuk.
Any train fare can be paid by both yen and snuuk.
The fare of the <var>i</var>-th train is <var>a_i</var> yen if paid in yen, and <var>b_i</var> snuuk if paid in snuuk.</p>
<p>In a city with a money exchange office, you can change <var>1</var> yen into <var>1</var> snuuk.
However, when you do a money exchange, you have to change all your yen into snuuk.
That is, if Kenkoooo does a money exchange when he has <var>X</var> yen, he will then have <var>X</var> snuuk.
Currently, there is a money exchange office in every city, but the office in City <var>i</var> will shut down in <var>i</var> years and can never be used in and after that year.</p>
<p>Kenkoooo is planning to depart City <var>s</var> with <var>10^{15}</var> yen in his pocket and head for City <var>t</var>, and change his yen into snuuk in some city while traveling.
It is acceptable to do the exchange in City <var>s</var> or City <var>t</var>.</p>
<p>Kenkoooo would like to have as much snuuk as possible when he reaches City <var>t</var> by making the optimal choices for the route to travel and the city to do the exchange.
For each <var>i=0,...,n-1</var>, find the maximum amount of snuuk that Kenkoooo has when he reaches City <var>t</var> if he goes on a trip from City <var>s</var> to City <var>t</var> after <var>i</var> years.
You can assume that the trip finishes within the year.</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 m \leq 10^5</var></li>
<li><var>1 \leq s,t \leq n</var></li>
<li><var>s \neq t</var></li>
<li><var>1 \leq u_i < v_i \leq n</var></li>
<li><var>1 \leq a_i,b_i \leq 10^9</var></li>
<li>If <var>i\neq j</var>, then <var>u_i \neq u_j </var> or <var>v_i \neq v_j</var>.</li>
<li>Any city can be reached from any city by changing trains.</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>m</var> <var>s</var> <var>t</var>
<var>u_1</var> <var>v_1</var> <var>a_1</var> <var>b_1</var>
<var>:</var>
<var>u_m</var> <var>v_m</var> <var>a_m</var> <var>b_m</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>n</var> lines.
In the <var>i</var>-th line, print the maximum amount of snuuk that Kenkoooo has when he reaches City <var>t</var> if he goes on a trip from City <var>s</var> to City <var>t</var> after <var>i-1</var> years.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 3 2 3
1 4 1 100
1 2 1 10
1 3 20 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>999999999999998
999999999999989
999999999999979
999999999999897
</pre>
<p>After <var>0</var> years, it is optimal to do the exchange in City <var>1</var>.<br/>
After <var>1</var> years, it is optimal to do the exchange in City <var>2</var>.<br/>
Note that City <var>1</var> can still be visited even after the exchange office is closed.
Also note that, if it was allowed to keep <var>1</var> yen when do the exchange in City <var>2</var> and change the remaining yen into snuuk, we could reach City <var>3</var> with <var>999999999999998</var> snuuk, but this is NOT allowed.<br/>
After <var>2</var> years, it is optimal to do the exchange in City <var>3</var>.<br/>
After <var>3</var> years, it is optimal to do the exchange in City <var>4</var>.
Note that the same train can be used multiple times.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>8 12 3 8
2 8 685087149 857180777
6 7 298270585 209942236
2 4 346080035 234079976
2 5 131857300 22507157
4 8 30723332 173476334
2 6 480845267 448565596
1 4 181424400 548830121
4 5 57429995 195056405
7 8 160277628 479932440
1 6 475692952 203530153
3 5 336869679 160714712
2 7 389775999 199123879
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>999999574976994
999999574976994
999999574976994
999999574976994
999999574976994
999999574976994
999999574976994
999999574976994
</pre></section>
</div>
</span> |
p02847 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is a string <var>S</var> representing the day of the week today.</p>
<p><var>S</var> is <code>SUN</code>, <code>MON</code>, <code>TUE</code>, <code>WED</code>, <code>THU</code>, <code>FRI</code>, or <code>SAT</code>, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.</p>
<p>After how many days is the next Sunday (tomorrow or later)?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>S</var> is <code>SUN</code>, <code>MON</code>, <code>TUE</code>, <code>WED</code>, <code>THU</code>, <code>FRI</code>, or <code>SAT</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>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of days before the next Sunday.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>SAT
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>It is Saturday today, and tomorrow will be Sunday.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>SUN
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>7
</pre>
<p>It is Sunday today, and seven days later, it will be Sunday again.</p></section>
</div>
</span> |
p01768 |
<h1 id="c-shopping-è²·ãç©">C : Shopping / è²·ãç©</h1>
<h2 id="å顿">å顿</h2>
<p>æçãåŸæãª2Dåã¯æŒãã¯ããäœãããšããŠãããæçã«ã¯ <var>N</var> åã®ææ <var>a_{0}, a_{1}, ⊠, a_{N−1}</var> ãå
šãŠãå¿
èŠã§ããã</p>
<p>ããŠãä»2Dåã®å®¶ã®å·èµåº«ã«ã¯äžã€ãææãå
¥ã£ãŠããªãã®ã§ãã¹ãŒããŒã«è²·ãã«è¡ããªããã°ãªããªããã¹ãŒããŒã§ã¯ææ <var>a_{i}</var> ã倿®µ <var>x_{i}</var> åã§è²·ãããšãã§ããã</p>
<p>2Dåã¯éæ³äœ¿ãã§ãããã <var>M</var> çš®é¡ã®éæ³ã䜿ããã <var>i</var> çªç®ã®éæ³ãææ <var>s_{i}</var> ã«ãããã°ææ <var>t_{i}</var> ã«ããŸãéã« <var>t_{i}</var> ã«ãããã° <var>s_{i}</var> ã«å€ããããšãã§ãããããã«ãäžã€ã®ææã«å¯ŸããŠè€æ°ã®éæ³ãç¹°ãè¿ããŠäœ¿ãããšãã§ãããäŸãã°ã <var>p</var> ãã <var>q</var> ã«å€ããéæ³ãšã <var>q</var> ãã <var>r</var> ã«å€ããéæ³ã®2ã€ã䜿ã£ãŠã <var>p</var> ãã <var>r</var> ãåŸãããšãã§ããã</p>
<p>2Dåã¯éæ³ã®åãåããŠãªãã¹ãå®ãææãæããããšã«ãããæçã宿ãããããã«2Dåãè²·ãå¿
èŠã®ããææã®ã倿®µã®ç·åã®æå°å€ãæ±ããã</p>
<h2 id="å
¥å">å
¥å</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre><var>N</var>
<var>a_{0}</var> <var>x_{0}</var>
<var>âŠ</var>
<var>a_{N−1}</var> <var>x_{N−1}</var>
<var>M</var>
<var>s_{0}</var> <var>t_{0}</var>
<var>âŠ</var>
<var>s_{M−1}</var> <var>t_{M−1}</var>
</pre>
<h2 id="å¶çŽ">å¶çŽ</h2>
<ul>
<li>æ°å€ã¯ãã¹ãп޿°ã§ãã</li>
<li>ææã®ååã¯ãã¹ãŠ <var>1</var> æåä»¥äž <var>10</var> æå以äžã®ã¢ã«ãã¡ãããå°æåãããªã</li>
<li><var>i â j</var> ãªã <var>a_{i} â a_{j}</var></li>
<li><var>1 \≤ x_{i} \≤ 1,000</var></li>
<li><var>1 \≤ N \≤ 5,000</var></li>
<li><var>0 \≤ M \≤ {\rm min}(N(N−1)</var>/<var>2, 1000)</var></li>
<li><var>s_{i} â t_{i}</var></li>
<li><var>s_{i},t_{i}</var> ã®çµã«éè€ã¯ãªã</li>
<li><var>s_{i},t_{i}</var> 㯠<var>a_{0},âŠ,a_{N−1}</var> ã«å«ãŸãã</li>
</ul>
<h2 id="åºå">åºå</h2>
<p>çãã1è¡ã§åºåããã</p>
<h2 id="ãµã³ãã«">ãµã³ãã«</h2>
<h3 id="ãµã³ãã«å
¥å1">ãµã³ãã«å
¥å1</h3>
<pre>2
tako 2
yaki 1
1
tako yaki
</pre>
<p>éæ³ã«ãã£ãŠå®ã yaki ã tako ã«å€ããããšãã§ããã®ã§ã yaki ã <var>2</var> åè²·ãã°ããã</p>
<h3 id="ãµã³ãã«åºå1">ãµã³ãã«åºå1</h3>
<pre>2
</pre>
<h3 id="ãµã³ãã«å
¥å2">ãµã³ãã«å
¥å2</h3>
<pre>5
a 1
b 2
c 2
d 4
e 3
5
b a
a c
c d
e b
c b
</pre>
<h3 id="ãµã³ãã«åºå2">ãµã³ãã«åºå2</h3>
<pre>5
</pre>
<p>äžã«ç€ºãããã«ãå
šãŠã®ææã a ããå€ããŠããããããšãã§ããã</p>
<ul>
<li>a : a ãã®ãŸãŸ</li>
<li>b : a -> c -> b</li>
<li>c : a -> c</li>
<li>d : a -> c -> d</li>
<li>e : a -> b -> e</li>
</ul>
<div class="figure">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RUPC2015_C1" />
</div> |
p03755 | <span class="lang-en lang-child hidden-lang">
<div id="task-statement">
Max Score: <var>1000</var> Points <br/>
<section>
<h3>Problem Statement</h3>
There is a railroad company in Atcoder Kingdom, "Atcoder Railroad". <br/>
There are <var>N + 1</var> stations numbered <var>0, 1, 2, ..., N</var> along a railway. <br/>
Currently, two kinds of train are operated, local and express. <br/>
A local train stops at every station, and it takes one minute from station <var>i</var> to <var>i + 1</var>, and vice versa. <br/>
An express train only stops at station <var>S_0, S_1, S_2, ..., S_{K-1} (0 = S_0 < S_1 < S_2 < ... < S_{K-1} = N)</var>. It takes one minute from station <var>S_i</var> to <var>S_{i + 1}</var>, and vice versa. <br/>
But the president of Atcoder Railroad, Semiexp said it is not very convenient so he planned to operate one more kind of train, "semi-express". <br/>
The stations where the semi-express stops (This is <var>T_0, T_1, T_2, ..., T_{L-1}</var>, <var>0 = T_0 < T_1 < T_2 < ... < T_{L-1} = N</var>) have to follow following conditions: <br/>
From station <var>T_i</var> to <var>T_{i+1}</var> takes 1 minutes, and vice versa. <br/>
<ul>
<li>The center of Atcoder Kingdom is station <var>0</var>, and you have to be able to go to station <var>i</var> atmost <var>X</var> minutes.</li>
<li>If the express stops at the station, semi-express should stops at the station.</li>
</ul>
Print the number of ways of the set of the station where semi-express stops (sequence <var>T</var>). <br/>
Since the answer can be large, print the number modulo <var>10^9 + 7</var>. <br/>
</section>
</div>
<div class="io-style">
<div class="part">
<section>
<h3>Input Format</h3>
<pre>
<var>N</var> <var>K</var> <var>X</var>
<var>S_0</var> <var>S_1</var> <var>S_2</var> ... <var>S_{K-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output Format</h3>
Print the number of ways of the set of the station where semi-express stops, mod <var>10^9 + 7</var> in one line. <br/>
Print <code>\n</code> (line break) in the end. <br/>
</section>
<section>
<h3>Constraints</h3>
<ul>
<li><var>2 †K †2500</var>.</li>
<li><var>1 †X †2500</var>.</li>
<li><var>S_0 = 0, S_{K-1} = N</var>.</li>
<li><var>1 †S_{i + 1} - S_i †10000</var>.</li>
</ul>
</section>
<section>
<h3>Scoring</h3>
Subtask 1 [<var>120</var> points] <br/>
<ul>
<li><var>N, K, X †15</var>.</li>
</ul>
Subtask 2 [<var>90</var> points] <br/>
<ul>
<li><var>K, X †15</var>.</li>
<li><var>S_{i + 1} - S_i †15</var>.</li>
</ul>
Subtask 3 [<var>260</var> points] <br/>
<ul>
<li><var>K, X †40</var>.</li>
<li><var>S_{i + 1} - S_i †40</var>.</li>
</ul>
Subtask 4 [<var>160</var> points] <br/>
<ul>
<li><var>K, X †300</var>.</li>
<li><var>S_{i + 1} - S_i †300</var>.</li>
</ul>
Subtask 5 [<var>370</var> points] <br/>
<ul>
<li>There are no additional constraints.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Sample Input 1</h3>
<pre>
7 2 3
0 7
</pre>
</section>
<section>
<h3>Sample Output 1</h3>
<pre>
55
</pre>
The set of trains that stops station <var>0</var> and <var>7</var>, and can't satisfy the condition is: <br/>
<var>[0, 7], [0, 1, 7], [0, 1, 2, 7], [0, 1, 6, 7], [0, 1, 2, 6, 7], [0, 1, 2, 3, 6, 7], [0, 1, 2, 5, 6, 7], [0, 1, 2, 3, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]</var>, <var>9</var> ways.<br/>
Therefore, the number of ways is <var>2^6 - 9 = 55</var>. <br/>
</section>
</div>
</div>
</span> |
p01292 |
<H1><font color="#000">Problem J:</font> Secret Operation</H1>
<p>
Mary Ice is a member of a spy group. She is about to carry out a secret operation with her colleague.
</p>
<p>
She has got into a target place just now, but unfortunately the colleague has not reached there yet. She
needs to hide from her enemy George Water until the colleague comes. Mary may want to make herself
appear in Georgeâs sight as short as possible, so she will give less chance for George to find her.
</p>
<p>
You are requested to write a program that calculates the time Mary is in Georgeâs sight before her colleague arrives, given the information about moves of Mary and George as well as obstacles blocking their
sight.
</p>
<p>
Read the Input section for the details of the situation.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset has the following format:
</p>
<p>
<i>Time R</i><br>
<i>L</i><br>
<i>MaryX</i><sub>1</sub> <i>MaryY</i><sub>1</sub> <i>MaryT</i><sub>1</sub><br>
<i>MaryX</i><sub>2</sub> <i>MaryY</i><sub>2</sub> <i>MaryT</i><sub>2</sub><br>
...<br>
<i>MaryX</i><sub><i>L</i></sub> <i>MaryY</i><sub><i>L</i></sub> <i>MaryT</i><sub><i>L</i></sub><br>
<i>M</i><br>
<i>GeorgeX</i><sub>1</sub> <i>GeorgeY</i><sub>1</sub> <i>GeorgeT</i><sub>1</sub><br>
<i>GeorgeX</i><sub>2</sub> <i>GeorgeY</i><sub>2</sub> <i>GeorgeT</i><sub>2</sub><br>
...<br>
<i>GeorgeX</i><sub><i>M</i></sub> <i>GeorgeY</i><sub><i>M</i></sub> <i>GeorgeT</i><sub><i>M</i></sub><br>
<i>N</i>
<i>BlockSX</i><sub>1</sub> <i>BlockSY</i><sub>1</sub> <i>BlockTX</i><sub>1</sub> <i>BlockTY</i><sub>1</sub><br>
<i>BlockSX</i><sub>2</sub> <i>BlockSY</i><sub>2</sub> <i>BlockTX</i><sub>2</sub> <i>BlockTY</i><sub>2</sub><br>
...<br>
<i>BlockSX</i><sub><i>N</i></sub> <i>BlockSY</i><sub><i>N</i></sub> <i>BlockTX</i><sub><i>N</i></sub> <i>BlockTY</i><sub><i>N</i></sub><br>
</p>
<p>
The first line contains two integers. Time (0 ≤ <i>Time</i> ≤ 100) is the time Mary's colleague reaches the
place. <i>R</i> (0 < <i>R</i> < 30000) is the distance George can see - he has a sight of this distance and of 45
degrees left and right from the direction he is moving. In other words, Mary is found by him if and only
if she is within this distance from him and in the direction different by not greater than 45 degrees from
his moving direction and there is no obstacles between them.
</p>
<p>
The description of Mary's move follows. Mary moves from (<i>MaryX<sub>i</sub></i>, <i>MaryY<sub>i</sub></i>) to (<i>MaryX</i><sub><i>i</i>+1</sub>, <i>MaryY</i><sub><i>i</i>+1</sub>)
straight and at a constant speed during the time between <i>MaryT<sub>i</sub></i> and <i>MaryT</i><sub><i>i</i>+1</sub>, for each 1 ≤ <i>i</i> ≤ <i>L</i> - 1.
The following constraints apply: 2 ≤ <i>L</i> ≤ 20, <i>MaryT</i><sub>1</sub> = 0 and <i>MaryT<sub>L</sub></i> = <i>Time</i>, and <i>MaryT<sub>i</sub></i> < <i>MaryT</i><sub><i>i</i>+1</sub>
for any 1 ≤ <i>i</i> ≤ <i>L</i> - 1.
</p>
<p>
The description of George's move is given in the same way with the same constraints, following Mary's.
In addition, (<i>GeorgeX<sub>j</sub></i>, <i>GeorgeY<sub>j</sub></i> ) and (<i>GeorgeX</i><sub><i>j</i>+1</sub>, <i>GeorgeY</i><sub><i>j</i>+1</sub>) do not coincide for any 1 ≤ <i>j</i> ≤ <i>M</i> - 1. In other words, George is always moving in some direction.
</p>
<p>
Finally, there comes the information of the obstacles. Each obstacle has a rectangular shape occupying
(<i>BlockSX<sub>k</sub></i>, <i>BlockSY<sub>k</sub></i>) to (<i>BlockTX<sub>k</sub></i>, <i>BlockTY<sub>k</sub></i>). No obstacle touches or crosses with another. The number of obstacles ranges from 0 to 20 inclusive.
</p>
<p>
All the coordinates are integers not greater than 10000 in their absolute values. You may assume that, if
the coordinates of Mary's and George's moves would be changed within the distance of 10<sup>-6</sup>, the solution would be changed by not greater than 10<sup>-6</sup>.
</p>
<p>
The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and should not be processed.
</p>
<H2>Output</H2>
<p>
For each dataset, print the calculated time in a line. The time may be printed with any number of digits after the decimal
point, but should be accurate to 10<sup>-4</sup> .
</p>
<H2>Sample Input</H2>
<pre>
50 100
2
50 50 0
51 51 50
2
0 0 0
1 1 50
0
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
50
</pre>
|
p00529 |
<h2>JOIOI ã®å¡(Tower of JOIOI)</h2>
<p>
JOIOI ã®å¡ãšã¯ïŒ1 人ã§éã¶åç€ã䜿ã£ãã²ãŒã ã§ããïŒ
</p>
<p>
ãã®ã²ãŒã ã¯ïŒ<span>J</span>ïŒ<span>O</span>ïŒ<span>I</span> ã®ããããã®æåãæžãããããã€ãã®åç€ãçšããŠè¡ãïŒåç€ã¯çŽåŸãäºãã«ç°ãªãïŒã²ãŒã éå§æã«ã¯ãããã®åç€ã¯çŽåŸã®å€§ãããã®ããé ã«äžããäžã«åãã£ãŠç©ãŸããŠããïŒããªãã¯ïŒãããã®åç€ãçšããŠïŒåºæ¥ãã ãå€ãã®ãã JOIOI ã®å¡ãäœãããïŒãã JOIOI ã®å¡ãšã¯ 3 æã®åç€ãããªãïŒåç€ã®çŽåŸãå°ãããã®ããé ã«èªãã§ <span>JOI</span> ããã㯠<span>IOI</span> ãšèªãããã®ã§ããïŒãã ãïŒåãåç€ã2 床以äžäœ¿ãããšã¯ã§ããªãïŒ
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2012_2012_ho_4"><br>
<p>
å³: <span>JOIOII</span> ããã¯ãã JOIOI ã®å¡ã 2 ã€äœãã
</p>
</center>
<h3>課é¡</h3>
<p>
çšæãããåç€ã«æžãããæåãããããåç€ã®çŽåŸãå°ãããã®ããé ã«é·ã <var>N</var> ã®æåå <var>S</var> ãšããŠäžããããïŒãããã®åç€ã䜿ã£ãŠäœãããšã®ã§ãããã JOIOI ã®å¡ã®åæ°ã®æå€§å€ãæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h3>å¶é</h3>
<ul>
<li>1 ≤ <var>N</var> ≤ 1 000 000 æåå <var>S</var> ã®é·ã</li>
</ul>
<h3>å
¥å</h3>
<p>
æšæºå
¥åãã以äžã®ããŒã¿ãèªã¿èŸŒãïŒ
</p>
<ul>
<li> 1 è¡ç®ã«ã¯æŽæ° <var>N</var> ãæžãããŠããïŒ<var>N</var> ã¯æåå <var>S</var> ã®é·ãã衚ãïŒ </li>
<li> 2 è¡ç®ã«ã¯æåå <var>S</var> ãæžãããŠããïŒ</li>
</ul>
<h3>åºå</h3>
<p>
æšæºåºåã«ïŒäœãããšã®ã§ãããã JOIOI ã®å¡ã®æ°ã®æå€§å€ãè¡šãæŽæ°ã 1 è¡ã§åºåããïŒ
</p>
<h3>å
¥åºåäŸ</h3>
<h3>å
¥åäŸ 1</h3>
<pre>
6
JOIIOI
</pre>
<h3> åºåäŸ 1</h3>
<pre>
2
</pre>
<p>
<span>JOIIOI</span> 㯠<span>JOI</span> ããã³ <span>IOI</span> ããããã 1 ã€ãã€éšååãšããŠå«ãã§ããïŒäœãããšã®ã§ãããã JOIOI ã®å¡ã¯ 2 ã€ã§ããïŒ
</p>
<br>
<h3>å
¥åäŸ 2</h3>
<pre>
5
JOIOI
</pre>
<h3>åºåäŸ 2</h3>
<pre>
1
</pre>
<p>
éšååãšã㊠<span>JOI</span> ããã³ <span>IOI</span> ãå«ãã§ãããïŒæåã 2 床以äžäœ¿ãããšã¯ã§ããªãããåæã«åãåºãããšã¯ã§ããªãïŒ
</p>
<br>
<h3>å
¥åäŸ 3</h3>
<pre>
6
JOIOII
</pre>
<h3> åºåäŸ 3</h3>
<pre>
2
</pre>
<p>
ãã®å
¥åºåäŸã¯å顿äžã®äŸã«å¯Ÿå¿ããŠããïŒ
</p>
<br>
<h3>å
¥åäŸ 4</h3>
<pre>
15
JJOIIOOJOJIOIIO
</pre>
<h3>åºåäŸ 4</h3>
<pre>
4
</pre>
<br>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p02144 | <h1>Problem H: Loss</h1>
<h2>Problem</h2>
<p>
ããªãã¯ããšããäŒç€Ÿããããã°ã©ã ã®äœæãäŸé Œãããã
ãã®äŒç€Ÿã«ã¯$N$åã®ä»äºããããããããã®ä»äºã«ã¯$1$ãã$N$ãŸã§ã®çªå·ãæ¯ãããŠããã
ä»äº$i$ã«ã¯ã$M_i$åã®åæãšãªãä»äº$X_{i,j}$ãååšããä»äº$i$ãåæãšãªãä»äº$X_{i,j}$ãããå
ã«è¡ããšãä»äº$i$ã¯å€å€§ãªæå€±ã被ãã
</p>
<p>ããã§ããªãã«ã¯ãæå€±ã被ãä»äºã®æ°ãæå°ãšãªããããªé çªã§ãã¹ãŠã®ä»äºãè¡ã£ããšãã®æå€±ã被ã£ãä»äºã®æ°ãæ±ããŠãããããã</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§ãã¹ãп޿°ã§äžããããã</p>
<pre>
$N$
$M_1$ $X_{1,1}$ $X_{1,2}$ ... $X_{1,M_1}$
$M_2$ $X_{2,1}$ $X_{2,2}$ ... $X_{2,M_2}$
:
$M_N$ $X_{N,1}$ $X_{N,2}$ ...$X_{N,M_N}$
</pre>
<p>
ä»äºã®æ°$N$ã$1$è¡ã«äžããããã<br>
ç¶ã$N$è¡ã«åæãšãªãä»äºã®æ
å ±ãäžããããã$i+1$è¡ç®ã«ã¯ä»äº$i$ã®æ
å ±ã空çœåºåãã§äžããããã$M_i$ã¯ãä»äº$i$ã®åæãšãªãä»äºã®æ°ã$X_{i,j}$ã¯ä»äº$i$ã®åæãšãªãä»äºã®çªå·ã衚ããŠããã<br>
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>$1 \le N \le 10^5$</li>
<li>$0 \le M_i \le N$</li>
<li>$M_i$ã®ç·åã¯$10^5$ãè¶
ããªã</li>
<li>$1 \le X_{i,j} \le min(i+1,N)$</li>
</ul>
<h2>Output</h2>
<p>æå€±ã被ãä»äºã®æ°ãæå°ã«ãªããããªé çªã§ãã¹ãŠã®ä»äºãè¡ã£ããšãããã®ãšãã®æå€±ã被ã£ãä»äºã®æ°ãäžè¡ã«åºåããã</p>
<h2>Sample Input 1</h2>
<pre>
2
1 1
0
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<p>
ä»äº$1$ã®ããã«åæãšãªãä»äºããã®ä»äºèªèº«ãšãªããããªå
¥åãååšããã
</p>
<h2>Sample Input 2</h2>
<pre>
3
3 2 1 2
0
1 2
</pre>
<h2>Sample Output 2</h2>
<pre>
1
</pre>
<h2>Sample Input 3</h2>
<pre>
5
1 2
1 3
2 1 2
3 1 3 5
0
</pre>
<h2>Sample Output 3</h2>
<pre>
1
</pre>
<p>äŸãã°ã$3,2,1,5,4$ã®é ã«ä»äºãè¡ããšæå€±ãæå°åã§ããã</p>
|
p00179 |
<H1>ãµãããªè«</H1>
<p>
äŒæŽ¥çç©åŠç ç©¶æã®Aå士ã¯ããšããåã®å³¶ã§ãµãããªè«ãçºèŠããŸããã圢ã¯èè«ã®ããã«çްé·ãã®ã§ãããã²ãšã€ã®äœç¯ãçã®ãããªåœ¢ãããŠããã®ã§ã糞ã§ã€ãªãã ããŒãºçã®ããã«èŠããŸãããµãããªã®ã¯äœã®è²ã«æ§ã
ãªããªãšãŒã·ã§ã³ãããããšãšããªãã«ã¯æéããã€ã«ã€ããŠäœã®è²ãå€ã£ãŠããè«ãããããšã§ãããã©ã®è«ã®äœç¯ã®è²ãèµ€ãç·ãéã®ã©ããã«éãããããã§ããã1 ç§ããšã«äœç¯ã®è²ãå€ãã£ãŠãããæåŸã«ã¯ãã¹ãŠã®äœç¯ãåãè²ã«ãªã£ãŠèœã¡çãå Žåãããã°ããã€ãŸã§åŸ
ã£ãŠããã£ãšè²ãå€ããã€ã¥ããå Žåãããããã§ããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_pck200807_1">
<br/><br/>
</center>
<p>
調ã¹ãŠãããã¡ã«ããµã ãã¯ãã¹ãŠã®äœç¯ãåãè²ãããŠããã®ã§ãããäœãã«é©ãããããŠè奮ããåŸã¯äœç¯ã®è²ãåæã«å€ãã£ãŠããŸãããšãããããŸãããäžåºŠäœç¯ã®è²ãå€ãã£ãŠããŸããšããµããã³ãã¹ãŠã®äœç¯ãåãè²ã«ãªããŸã§ã¯ãã£ãšè²ãå€ããç¶ããããšãããããŸããã
</p>
<p>
Aå士ã¯ãã®è«ãäœå¹ãæãŸããŠè奮ãããŠã¿ãŠã¯ãè²ãå€ããæ§åãè峿·±ã芳å¯ããŠããŸãããããããŠè²ãå€åããŠããæäžã®è²ã®å€ããæ¹ã«ã¯æ¬¡ã®ãããªèŠåæ§ãããããšã«æ°ãã€ããŸããã
</p>
<ul>
<li>è²ãå€ããã®ã¯ãé£ãåã£ãŠããè²éãã® 2ã€ã®äœç¯ã®ã㢠1çµã ããå€ãããä»ã®äœç¯ã®è²ã¯å€ãããªãããã ãããã®ãããªãã¢ãè€æ°ãããšãã«ãã©ã®ãã¢ã®è²ãå€ãããã¯ãããããäºæž¬ã§ããªãã</li>
<li>ãã®ãããªãã¢ã¯ã2ã€ã®äœç¯ã®è²ã®ã©ã¡ãã§ããªãè²ã«åæã«å€ãã(ããšãã°ãç·ãšèµ€ã®äœç¯ãé£ãåã£ãŠãããšãã¯ãããããåæã«éã«å€ãã)ã</li>
</ul>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_pck200807_2">
<br/><br/>
</center>
<p>
è«ã®è²ã®å€åãã2ç§åŸãŸã§ãã¹ãŠæžãããã®ãäžã®å³ã§ããå³ã®äžæ®µã®ãããªè²ãããè«ããããšããŸãããã®ãšããé£ãåã£ãè²éãã®äœç¯ã®ãã¢ã¯ 3çµããã®ã§ã1ç§åŸã«ã¯äžæ®µã«äžŠã¹ãŠæãã 3éãã®è²ã®ã©ããã«å€ãããŸãã1ç§åŸã«äžæ®µå·ŠåŽã® 2ã€ã®ããã«å€ãã£ããšãã«ã¯ã2ç§åŸã«ãã¹ãŠã®äœç¯ãç·è²ã«ãªãããšãã§ããŸã(å³ã®äžæ®µã®å·ŠåŽãã 2çªç®)ã ããã«å¯ŸããŠã1ç§åŸã«äžæ®µã®1çªå³ã®ããã«å€ãã£ããšãã«ã¯ã2ç§åŸã«ãã¹ãŠã®äœç¯ãåãè²ã«å€ããããšã¯ãããŸããã
</p>
<p>
å士ã¯ãç®ã®åã«ããè«ã®äœç¯ããã¹ãŠåãè²ã«ãªãå¯èœæ§ãããã®ãããããšããããããªãã®ã¯æçã§äœç§åŸãªã®ããäºæž¬ããããšã«ããŸããã
</p>
<p>
ç®ã®åã«ããè«ã®äœç¯ã®è²ã®äžŠã³ãå
¥åãšãããã®è«ã®äœç¯ããã¹ãŠåãè²ã«ãªãã®ã«èŠããæçã®æéãç§åäœã§åºåããããã°ã©ã ãäœæããŠãã ããããã ããåãè²ã«ãªãå¯èœæ§ããªããšãã¯ãNA(åè§è±å€§æå)ããšåºåããŠãã ããããŸããè«ã®äœç¯ã®è²ã®äžŠã³ã¯2 ä»¥äž 10 以äžã®r(èµ€)ãg(ç·)ãb(é)ãããªãæååã§è¡šãããŸãã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸ
ããåããŒã¿ã»ãããšããŠã è«ã®äœç¯ã®æ
å ±ã衚ãïŒã€ã®æååãïŒè¡ã«äžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããæ¯ã«ããã¹ãŠã®äœç¯ã®è²ãåãã«ãªããŸã§ã«èŠããæå°æé (ç§åäœã®æŽæ°) ãŸã㯠NA ãïŒè¡ã«åºåããŸãã
</pre>
<H2>Sample Input</H2>
<pre>
rbgrg
rbbgbbr
bgr
bgrbrgbr
bggrgbgrr
gbrggrbggr
rrrrr
bgbr
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
5
7
1
6
NA
8
0
4
</pre>
|
p00483 |
<H1> æææ¢æ»(Planetary Exploration) </H1>
<p>
ããªããä¹ããè¶
æç©ºç§»æ°è¹ã¯é·æ
ã®æ«ïŒã€ãã«å±
äœå¯èœãšæãããææãçºèŠããïŒJOI æãšåä»ãããããã®ææã¯ïŒãã®åã®éãããžã£ã³ã°ã«(Jungle)ãïŒãæµ·(Ocean)ãïŒãæ°·(Ice)ãã®3 çš®é¡ã®å°åœ¢ãå
¥ãçµãã éé
·ãªææã§ããïŒç°¡åãªèª¿æ»ã«ããïŒå±
äœäºå®å°è¿èŸºã®å°å³ãäœæãããïŒå±
äœäºå®å°ã¯åå<i>M</i> km, æ±è¥¿<i>N</i> km ã®é·æ¹åœ¢ã®åœ¢ãããŠããïŒ 1 km åæ¹ã®æ£æ¹åœ¢ã®åºç»ã«åããããŠããïŒåºç»ã¯å
šéšã§<i>MN</i> åããïŒåãã<i>p</i> è¡ç®ïŒè¥¿ãã<i>q</i> åç®ã®åºç»ã(<i>p</i>, <i>q</i>) ã§è¡šãïŒå西ã®è§ã®åºç»ã(1, 1) ã§ããïŒåæ±ã®è§ã®åºç»ã(<i>M</i>, <i>N</i>) ã§ããïŒååºç»ã®å°åœ¢ã¯ïŒããžã£ã³ã°ã«ãïŒãæµ·ãïŒãæ°·ãã®ããããã§ããïŒããžã£ã³ã°ã«ãã¯J, ãæµ·ãã¯O, ãæ°·ãã¯I ã®è±å1 æåã§è¡šããã.
</p>
<p>
ããŠïŒè©³çްãªç§»äœèšç»ãç«ãŠãã«ãããïŒ K ç®æã®é·æ¹åœ¢é åå
ã«ããžã£ã³ã°ã«ãïŒãæµ·ãïŒãæ°·ããããããäœåºç»å«ãŸãããã調ã¹ãããšã«ããïŒ
</p>
<h2>課é¡</h2>
<p>
å±
äœäºå®å°ã®æ
å ±ãšïŒèª¿æ»å¯Ÿè±¡ãšãªãé åã®æ
å ±ãäžãããããšãïŒããããã®é åã«ã€ããŠïŒ ããžã£ã³ã°ã«ãïŒãæµ·ãïŒãæ°·ããäœåºç»å«ãŸããŠããããæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h2>å¶é</h2>
<p>
1 ≤ <i>M</i> ≤ 1000 å±
äœäºå®å°ã®ååã®é·ã(km)<br>
1 ≤ <i>N</i> ≤ 1000 å±
äœäºå®å°ã®æ±è¥¿ã®é·ã(km)<br>
1 ≤ <i>K</i> ≤ 100000 調æ»å¯Ÿè±¡ãšãªãé åã®åæ°
</p>
<h2>å
¥å</h2>
<p>
æšæºå
¥åãã以äžã®å
¥åãèªã¿èŸŒãïŒ
</p>
<ul>
<li> 1 è¡ç®ã«ã¯æŽæ°<i>M</i>, <i>N</i> ã空çœãåºåããšããŠæžãããŠããïŒå±
äœäºå®å°ãååã«<i>M</i> km ïŒæ±è¥¿ã«<i>N</i> km ã®åºãã§ããããšã衚ãïŒ</li>
<li> 2 è¡ç®ã«ã¯æŽæ°<i>K</i> ãæžãããŠããïŒèª¿æ»å¯Ÿè±¡ãšãªãé åã®åæ°ã衚ãïŒ</li>
<li> ç¶ã<i>M</i> è¡ã«ã¯å±
äœäºå®å°ã®æ
å ±ãæžãããŠããïŒ<i>i</i> + 2 è¡ç®(1 ≤ <i>i</I> ≤ <i>M</i>) ã«ã¯ïŒå±
äœäºå®å°ã®åãã<i>i</i>è¡ç®ã«äœçœ®ãã<i>N</i> åºç»ã®æ
å ±ã衚ãJïŒOïŒI ãããªã<i>N</i> æåã®æååãæžãããŠããïŒ</li>
<li> ç¶ã<i>K</i> è¡ã«ã¯èª¿æ»å¯Ÿè±¡ãšãªãé åãæžãããŠããïŒ<i>j</i> + <i>M</i> + 2 è¡ç®(1 ≤ <i>j</i> ≤ <i>K</i>) ã«ã¯ïŒ <i>j</i> çªç®ã®é åãè¡šãæ£æŽæ°<i>a<sub>j</sub></i>, <i>b<sub>j</sub></i>, <i>c<sub>j</sub></i>, <i>d<sub>j</sub></i> ã空çœãåºåããšããŠæžãããŠããïŒ(<i>a<sub>j</sub></i>, <i>b<sub>j</sub></i>) ã¯èª¿æ»é åã®å西ã®è§ã®åºç»ãïŒ(<i>c<sub>j</sub></i>, <i>d<sub>j</sub></i>) ã¯èª¿æ»é åã®åæ±ã®è§ã®åºç»ã衚ãïŒãã ãïŒ<i>a<sub>j</sub></i>, <i>b<sub>j</sub></i>, <i>c<sub>j</sub></i>, <i>d<sub>j</sub></i> ã¯ïŒ1 ≤ <i>a<sub>j</sub></i> ≤ <i>c<sub>j</sub></i> ≤ <i>M</i>, 1 ≤ <i>b<sub>j</sub></i> ≤ <i>d<sub>j</sub></i> ≤ <i>N</i>ãæºããïŒ
</ul>
<h2>åºå</h2>
<p>
æšæºåºåã«èª¿æ»ã®çµæã衚ã<i>K</i> è¡ãåºåããïŒåºåã®<i>j</i> è¡ç®ã«ã¯ïŒ j çªç®ã®èª¿æ»é åã«å«ãŸããããžã£ã³ã°ã«ã(J) ã®åºç»æ°ïŒãæµ·ã(O) ã®åºç»æ°ïŒãæ°·ã(I) ã®åºç»æ°ã衚ã3 ã€ã®æŽæ°ãïŒãã®é ã«ç©ºçœãåºåããšããŠæžãïŒ
</p>
<h2>æ¡ç¹åºæº</h2>
<p>
æ¡ç¹çšããŒã¿ã®ãã¡ïŒé
ç¹ã®30%åã«ã€ããŠã¯ïŒ<i>M</i> ≤ 50 ãã€<i>K</i> ≤ 100 ãæºããïŒé
ç¹ã®50%åã«ã€ããŠã¯ïŒ<i>M</i> ≤ 50 ãæºããïŒ
</p>
<h2>å
¥åºåã®äŸ</h2>
<h3>å
¥åäŸ</h3>
<pre>
4 7
4
JIOJOIJ
IOJOIJO
JOIJOOI
OOJJIJO
3 5 4 7
2 2 3 6
2 2 2 2
1 1 4 7
</pre>
<h3>åºåäŸ</h3>
<pre>
1 3 2
3 5 2
0 1 0
10 11 7
</pre>
<br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_planetaryExploration">
<br>
<p>
ãã®å
¥åäŸã§ã¯ïŒ 2 çªç®ã®é åã¯äžå³ã®ããã«ããžã£ã³ã°ã«ãã3 åºç»ïŒãæµ·ãã5 åºç»ïŒãæ°·ãã2 åºç»å«ãïŒ
</p>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p01441 |
<H1><font color="#000">Problem E:</font> Full Text Search</H1>
<p>
Mr. Don is an administrator of a famous quiz website named QMACloneClone. The users there can submit their own questions to the system as well as search for question texts with arbitrary queries. This search system employs bi-gram search method.
</p>
<p>
The bi-gram search method introduces two phases, namely preprocessing and search:
</p>
<p>
<b>Preprocessing</b> Precompute the set of all the substrings of one or two characters long for each question text.
</p>
<p>
<b>Search</b> Compute the set for the query string in the same way. Then nd the question texts whose precomputed sets completely contain the set constructed from the query.
</p>
<p>
Everything looked fine for a while after the feature was released. However, one of the users found an issue: the search results occasionally contained questions that did not include the query string as-is. Those questions are not likely what the users want. So Mr. Don has started to dig into the issue and asked you for help. For each given search query, your task is to find the length of the shortest question text picked up by the bi-gram method but not containing the query text as its substring.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. A dataset is given as a search query on each line. The input ends with a line containing only a hash sign ("<span>#</span>"), which should not be processed.
</p>
<p>
A search query consists of no more than 1,000 and non-empty lowercase and/or uppercase letters. The question texts and queries are case-sensitive.
</p>
<H2>Output</H2>
<p>
For each search query, print the minimum possible length of a question text causing the issue. If there is no such question text, print "<span>No Results</span>" in one line (quotes only to clarify).
</p>
<H2>Sample Input</H2>
<pre>
a
QMAClone
acmicpc
abcdefgha
abcdefgdhbi
abcbcd
#
</pre>
<H2>Output for the Sample Input</H2>
<pre>
No Results
9
7
9
12
6
</pre>
<H2>Note</H2>
<p>
Let's consider the situation that one question text is "CloneQMAC". In this situation, the set computed in the preprocessing phase is {"C", "Cl", "l", "lo", "o", "on", "n", "ne", "e", "eQ", "Q", "QM", "M", "MA", "A", "AC"}.
</p>
<p>
In the testcase 2, our input text (search query) is "QMAClone". Thus the set computed by the program in the search phase is {"Q", "QM", "M", "MA", "A", "AC", "C", "Cl", "l", "lo", "o", "on", "n", "ne", "e"}.
</p>
<p>
Since the first set contains all the elements in the second set, the question text "CloneQMAC" is picked up by the program when the search query is "QMAClone" although the text "CloneQ-MAC" itself does not contain the question text "QMAClone". In addition, we can prove that there's no such text of the length less than 9, thus, the expected output for this search query is 9.
</p>
|
p03186 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi has <var>A</var> untasty cookies containing antidotes, <var>B</var> tasty cookies containing antidotes and <var>C</var> tasty cookies containing poison.</p>
<p>Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death.
As he wants to live, he cannot eat one in such a situation.
Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches.</p>
<p>Find the maximum number of tasty cookies that Takahashi can eat.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 \leq A,B,C \leq 10^9</var></li>
<li><var>A,B</var> and <var>C</var> 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>C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum number of tasty cookies that Takahashi can eat.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>We can eat all tasty cookies, in the following order:</p>
<ul>
<li>A tasty cookie containing poison</li>
<li>An untasty cookie containing antidotes</li>
<li>A tasty cookie containing poison</li>
<li>A tasty cookie containing antidotes</li>
<li>A tasty cookie containing poison</li>
<li>An untasty cookie containing antidotes</li>
<li>A tasty cookie containing poison</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 2 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>10
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8 8 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>9
</pre></section>
</div>
</span> |
p01011 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<h1>Problem F: Prize Game</h1>
<h2>Problem</h2>
<p>
æ°ããã²ãŒã ã»ã³ã¿ãŒãéåºããããšã«ãªã£ããããããã®ã客ãããåãå
¥ããããã«ãå
šãæ°ãããã©ã€ãºã²ãŒã ãèšçœ®ããããšã«ãªã£ãã
</p>
<p>
ãã®ãã©ã€ãºã²ãŒã ã¯<var>R</var>×<var>C</var>ã®ã°ãªããããæ§æããããåãã¹ã¯ç©ºçœãã1ã18ã®ããããã®æ°åãæžãããŠããããã¬ã€ã€ãŒã¯ã²ãšã€ã®ç©ºçœã®ãã¹ãéžæãããã®ãã¹ã®æ¯åãç²åŸã§ããããã ãããã¹ã«ããæ¯åã¯ãã¬ã€ã€ãŒããèŠãããšãã§ããªãã
</p>
<p>
ã¹ã¿ããã¯ãã®ãã©ã€ãºã²ãŒã ã«æ¯åãèšçœ®ããªããã°ãªããªããã¹ã¿ããã¯ä»¥äžã®ã«ãŒã«ãå®ãããŠããã°ãã©ã®ããã«æ¯åãé
眮ããŠããããæ°åãæžãããŠãããã¹ã«ã€ããŠããã®æ°åã<var>x</var>ãšãããšããã®æ°åãäžå¿ãšããåžåã®ç¯å²ã®äžã«æ¯åãã¡ããã©<var>x</var>å眮ãããŠããå¿
èŠãããïŒäžã®å³ãåç
§ïŒããã®åžåã®åºã£åŒµã£ãŠããéšåã¯äžãåããŠããããŸããæ¯åã¯ç©ºçœã®ãã¹ã®ã¿ã«çœ®ãããšãã§ãã1ã€ã®ãã¹ã«3åãŸã§çœ®ãããšãåºæ¥ãã1åã眮ããªãããšãå¯èœã§ããã
</p>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2013Aizu_aizuicpc_grid" alt="åžåã®ç¯å²ã®å³"><br>
äžå€®ã®æ°åã5ã ã£ãå Žåã®æ¯åã®çœ®ãæ¹ã®äŸããªã¬ã³ãžè²ã®éšåã«ã¡ããã©èš5åã®æ¯åã眮ãããŠããå¿
èŠãããã
</p>
<p>
ã客ããã«æ¯åã®å Žæãç°¡åã«æšæž¬ãããŠã¯å€§æã§ãããããã§ããªãŒããã³ã°ã¹ã¿ããã§ããããªãã«ãäžèšã«ãŒã«ã«åã£ãæ¯åã®çœ®ãæ¹ã®å Žåã®æ°ãæ°ããŠãããããããã ããæ¯åã¯äºãã«åºå¥ã§ããªããã®ãšãããçãã¯å€§ãããªãå Žåãããã®ã§çãã®å Žåã®æ°ã1000000007ã§å²ã£ãäœããçããªããã
</p>
<h2>Input</h2>
<pre>
<var>R</var> <var>C</var>
<var>a<sub>1,1</sub></var> <var>a<sub>1,2</sub></var> ... <var>a<sub>1,C</sub></var>
<var>a<sub>2,1</sub></var> <var>a<sub>2,2</sub></var> ... <var>a<sub>2,C</sub></var>
:
<var>a<sub>R,1</sub></var> <var>a<sub>R,2</sub></var> ... <var>a<sub>R,C</sub></var>
</pre>
<p>
1è¡ç®ã«2ã€ã®æŽæ°<var>R</var>,<var>C</var>ã空çœåºåãã§äžãããããããããã°ãªããã®è¡æ°ãšåæ°ã衚ããæ¬¡ã«ãã©ã€ãºã²ãŒã ã衚ãã°ãªããã®æ
å ±ã<var>R</var>è¡ã§äžãããããã°ãªããã®æ
å ±ã®<var>i</var>è¡ç®ã«ã¯<var>C</var>åã®æŽæ° <var>a<sub>i,j</sub></var>ã空çœåºåãã§äžããããã<var>a<sub>i,j</sub></var>ã¯ã°ãªããã®<var>i</var>è¡<var>j</var>åã®ãã¹æ
å ±ã衚ãã0ã®å Žåã¯ç©ºçœã®ãã¹ããã以å€ã®å Žåã¯æ°å<var>a<sub>i,j</var></sub></var>ãæžããããã¹ã衚ãããŸããäžããããã°ãªããã¯1è¡ç®ããã©ã€ãºã²ãŒã ã®äžçªäžã衚ãã<var>R</var>è¡ç®ãäžçªäžã衚ãã
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>1 ≤ <var>R</var>,<var>C</var> ≤ 6</li>
<li>0 ≤ <var>a<sub>i,j</sub></var> ≤ 18 (1 ≤ <var>i</var> ≤ <var>R</var> , 1 ≤ <var>j</var> ≤ <var>C</var>)</li>
</ul>
<h2>Output</h2>
<p>ã«ãŒã«ã«åã£ãæ¯åã®çœ®ãæ¹ã®å Žåã®æ°ã1000000007ã§å²ã£ãäœãã1è¡ã«åºåããã</p>
<h2>Sample Input 1</h2>
<pre>
3 3
0 0 0
0 18 0
0 0 0
</pre>
<h2>Sample Output 1</h2>
<pre>
16
</pre>
<h2>Sample Input 2</h2>
<pre>
3 3
0 0 0
0 2 0
0 0 0
</pre>
<h2>Sample Output 2</h2>
<pre>
336
</pre>
<h2>Sample Input 3</h2>
<pre>
3 3
0 1 0
1 0 0
0 1 1
</pre>
<h2>Sample Output 3</h2>
<pre>
1
</pre>
<h2>Sample Input 4</h2>
<pre>
1 1
1
</pre>
<h2>Sample Output 4</h2>
<pre>
0
</pre>
<h2>Sample Input 5</h2>
<pre>
6 6
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
</pre>
<h2>Sample Output 5</h2>
<pre>
80065005
</pre> |
p00250 |
<H1>ã¹ã³ãŒã³é
éèšç»</H1>
<p>
ææããã®å®¶ã¯ãå°ããªå«è¶åºãçµå¶ããŠããŸããææããã®ãæ¯ãããçŒãã¹ã³ãŒã³ã¯ãšãŠãçŸå³ãããŠãåºã¯ãšãŠãç¹çããŠããŸããã
</p>
<p>
ãŠã§ã€ãã¬ã¹ã§ããææããã®ä»äºã®äžã€ã¯ã次ã
ãšçŒãäžããã¹ã³ãŒã³ããã客æ§ã®åžãŸã§å±ããããšã§ããçŒãããã£ãã¹ã³ãŒã³ã¯ãçã®äžã«ä¹ããããã«ãŠã³ã¿ãŒã®äžã«äžåã«äžŠã¹ãããŸãã<var>i</var> çªç®ã®ãçã®äžã«ä¹ã£ãŠããã¹ã³ãŒã³ã®æ°ã <var>K<sub>i</sub></var> ãšããŸããããææããã¯ãããããã®ã客æ§ã«ã¡ããã© <var>m</var> åã®ã¹ã³ãŒã³ãéã°ãªããã°ãªããŸãããææããã¯äžåºŠã«ããã€ã§ããçãæã€ããšãã§ãããŸãè€æ°ã®ãçãã 1 人ã®ã客æ§ã«ã¹ã³ãŒã³ãé
ã£ãããïŒã€ã®ãçããè€æ°ã®ã客æ§ã«é
ã£ãŠãæ§ããŸããã
</p>
<p>
å«è¶åºã«ã¯ãšãŠãããããã®ã客æ§ããã£ãŠããã®ã§ãã«ãŠã³ã¿ãŒã«çœ®ããŠããå
šãŠã®ã¹ã³ãŒã³ãéãã§ããå
šãŠã®ã客æ§ã«å±ããããšã¯ã§ããŸãããããããã§ããã ãå€ãã®ã客æ§ã«å±ããåŸã§ã<var>m</var> åã«æºããªãæ°ã®ã¹ã³ãŒã³ãäœãããšããããããããŸããããã®ãããªã¹ã³ãŒã³ã¯ããæäŒãã®ãè€çŸãšããŠãææãããè²°ããããšã«ãªããŸããã
<!--ã¹ã³ãŒã³ã¯ãšãŠãçŸå³ããã®ã§ãææããã倧奜ããªã®ã§ãã-->
</p>
<p>
ããã§ãµãšãææããã¯èããŸãããäžåºŠã«å
šãŠã®ãçãæã€ã®ã§ã¯ãªããäžéšã®ãçã ããæã£ãŠã客æ§ã«ã¹ã³ãŒã³ãå±ãããšãäœãã¹ã³ãŒã³ã®æ°ãéã£ãŠããã¯ãã§ããé©åã«ãçãéžã¶ããšã§ãããå€ãã®ã¹ã³ãŒã³ãäœãããã«ã§ãããããããŸãããææããã¯ãäœçºçã«ãçãéžãã§ããããšããæ¯ããã«èŠæãããªãããã«ãã«ãŠã³ã¿ãŒã®äžã®1ã€ã®é£ç¶ããç¯å²ã®ãçãéžã¶ããšã«ããŸããããŸããæ®ã£ããçã¯ãç¶ããããæ¯ãããéãã§ããŸãã®ã§ãææãããã¹ã³ãŒã³ãããããã£ã³ã¹ã¯äžåºŠãããããŸããã
</p>
<p>
ããŠãææããã¯æå€§ããã€ã®ã¹ã³ãŒã³ãè²°ããã§ããããïŒèšç®ããããã°ã©ã ãæžããŠãã ããããçã®æ° <var>n</var> 㯠1 ä»¥äž 30,000以äžã <var>m</var> 㯠1 ä»¥äž 100,000 以äžã§ãããŸãæ°åã®åèŠçŽ <var>K<sub>i</sub></var> 㯠0 ä»¥äž 2<sup>32</sup>-1 ã§ãã
</p>
<h2>å
¥å</h2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒããµãã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®ãšããã§ãã
</p>
<p>
1è¡ç® <var>n</var> <var>m</var>ïŒæŽæ° æŽæ°ïŒåè§ç©ºçœåºåãïŒ<br>
2è¡ç® ãçäžã®ã¹ã³ãŒã³ã®æ
å ± <var>K<sub>1</sub></var> <var>K<sub>2</sub></var> ... <var>K<sub>n</sub></var>ïŒãã¹ãп޿° ; åè§ç©ºçœåºåãïŒ<br>
<var>K<sub>i</sub></var>: <var>i</var>çªç®ã®ãçäžã®ã¹ã³ãŒã³ã®æ°<br>
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<h2>åºå</h2>
<p>
ããŒã¿ã»ããããšã«ãããããã¹ã³ãŒã³ã®æå€§æ°ãïŒè¡ã«åºåããŸãã
</p>
<h2>å
¥åäŸ</h2>
<pre>
5 11
11 27 34 45 56
8 5
0 2 1 5 4 6 8 3
5 2
2 4 2 4 6
10 18
10 15 12 31 12 50 11 23 43 181
1 100
5
0 0
</pre>
<h2>åºåäŸ</h2>
<pre>
8
4
0
17
5
</pre> |
p02797 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are three integers <var>N</var>, <var>K</var>, and <var>S</var>.</p>
<p>Find a sequence <var>A_1, A_2, ..., A_N</var> of <var>N</var> integers between <var>1</var> and <var>10^9</var> (inclusive) that satisfies the condition below.
We can prove that, under the conditions in Constraints, such a sequence always exists.</p>
<ul>
<li>There are exactly <var>K</var> pairs <var>(l, r)</var> of integers such that <var>1 \leq l \leq r \leq N</var> and <var>A_l + A_{l + 1} + \cdots + A_r = S</var>.</li>
</ul>
</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</var></li>
<li><var>1 \leq S \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>K</var> <var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print a sequence satisfying the condition, in the following format:</p>
<pre><var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
</pre>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1 2 3 4
</pre>
<p>Two pairs <var>(l, r) = (1, 2)</var> and <var>(3, 3)</var> satisfy the condition in the statement.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 3 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>50 50 50 30 70
</pre></section>
</div>
</span> |
p03885 | <span class="lang-en">
<p>Score : <var>1500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><style>
#nck {
width: 30px;
height: auto;
}
</style>
<p>Snuke received two matrices <var>A</var> and <var>B</var> as birthday presents.
Each of the matrices is an <var>N</var> by <var>N</var> matrix that consists of only <var>0</var> and <var>1</var>.</p>
<p>Then he computed the product of the two matrices, <var>C = AB</var>.
Since he performed all computations in modulo two, <var>C</var> was also an <var>N</var> by <var>N</var> matrix that consists of only <var>0</var> and <var>1</var>.
For each <var>1 †i, j †N</var>, you are given <var>c_{i, j}</var>, the <var>(i, j)</var>-element of the matrix <var>C</var>.</p>
<p>However, Snuke accidentally ate the two matrices <var>A</var> and <var>B</var>, and now he only knows <var>C</var>.
Compute the number of possible (ordered) pairs of the two matrices <var>A</var> and <var>B</var>, modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N †300</var></li>
<li><var>c_{i, j}</var> is either <var>0</var> or <var>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>c_{1, 1}</var> <var>...</var> <var>c_{1, N}</var>
:
<var>c_{N, 1}</var> <var>...</var> <var>c_{N, N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of possible (ordered) pairs of two matrices <var>A</var> and <var>B</var> (modulo <var>10^9+7</var>).</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
0 1
1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10
1 0 0 1 1 1 0 0 1 0
0 0 0 1 1 0 0 0 1 0
0 0 1 1 1 1 1 1 1 1
0 1 0 1 0 0 0 1 1 0
0 0 1 0 1 1 1 1 1 1
1 0 0 0 0 1 0 0 0 0
1 1 1 0 1 0 0 0 0 1
0 0 0 1 0 0 1 0 1 0
0 0 0 1 1 1 0 0 0 0
1 0 1 0 0 1 1 1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>741992411
</pre></section>
</div>
</span> |
p00600 |
<H1><font color="#000000">Problem F:</font> Computation of Minimum Length of Pipeline</H1>
<p>
The Aizu Wakamatsu city office decided to lay a hot water pipeline covering the whole area of the city to heat houses. The pipeline starts from some hot springs and connects every district in the city. The pipeline can fork at a hot spring or a district, but no cycle is allowed. The city office wants to minimize the length of pipeline in order to build it at the least possible expense.
</p>
<p>
Write a program to compute the minimal length of the pipeline. The program reads an input that consists of the following three parts:
</p>
<H2>Input</H2>
<ul>
<li>The first part consists of two positive integers in one line, which represent the number <i>s</i> of hot springs and the number <i>d</i> of districts in the city, respectively.</li>
<li>The second part consists of <i>s</i> lines: each line contains <i>d</i> non-negative integers. The <i>i</i>-th integer in the <i>j</i>-th line represents the distance between the <i>j</i>-th hot spring and the <i>i</i>-th district if it is non-zero. If zero it means they are not connectable due to an obstacle between them.</li>
<li>The third part consists of <i>d</i>-1 lines. The <i>i</i>-th line has <i>d - i</i> non-negative integers. The <i>i</i>-th integer in the <i>j</i>-th line represents the distance between the <i>j</i>-th and the (<i>i</i> + <i>j</i>)-th districts if it is non-zero. The meaning of zero is the same as mentioned above.</li>
</ul>
<p>
For the sake of simplicity, you can assume the following:
</p>
<ul>
<li>The number of hot springs and that of districts do not exceed 50.</li>
<li>Each distance is no more than 100.</li>
<li>Each line in the input file contains at most 256 characters.</li>
<li>Each number is delimited by either whitespace or tab.</li>
</ul>
<p>
The input has several test cases. The input terminate with a line which has two 0. The number of test cases is less than 20.
</p>
<H2>Output</H2>
<p>
Output the minimum length of pipeline for each test case.
</p>
<H2>Sample Input</H2>
<pre>
3 5
12 8 25 19 23
9 13 16 0 17
20 14 16 10 22
17 27 18 16
9 7 0
19 5
21
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
38
</pre>
<H2>Hint</H2>
<p>
The first line correspondings to the first part: there are three hot springs and five districts. The following three lines are the second part: the distances between a hot spring and a district. For instance, the distance between the first hot spring and the third district is 25. The last four lines are the third part: the distances between two districts. For instance, the distance between the second and the third districts is 9. The second hot spring and the fourth district are not connectable The second and the fifth districts are not connectable, either.
</p> |
p01912 |
<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>H: ãžã£ã³ãããŒãã£</h1>
<h2>åé¡</h2>
<p>
ãšãããã³ã¹ããŒã«ã§ $N$ 人ã®åå ãããã³ã¹ããŒãã£ãŒãè¡ãããã
ãã®ãã³ã¹ããŒã«ã¯çžŠæ¹åã« $H$ åãæšªæ¹åã« $W$ åã®ã°ãªããã«åããããŠããã
å·Šäžã $(0,0)$ãäžãã $r$ ãã¹ãå·Šãã $c$ ãã¹ç®ã®ã°ãªããã®åº§æšã $(r,c)$ ãšè¡šãã
$i$ çªç®ã®åå è
ã®åæäœçœ®ã¯ $(R_i, C_i)$ ã§ããã$(i,j)$ ã®ã°ãªããã«ã¯ $(r_{ij}, c_{ij})$ ãæžãããŠããã
</p>
<p>
ååå è
ã¯ãç¡éã«ç¶ã鳿¥œã«åãããŠæ¬¡ã®ããã«åæã«ç§»åãè¡ãã
</p>
<ul>
<li>ãã®æã«ãã座æšã $(i,j)$ ã®ãšãã$(r_{ij}, c_{ij})$ ãžãžã£ã³ãã§ç§»åããã</li>
</ul>
<p>
ããããã®ã°ãªããã¯çãã2 人以äžã®åå è
ãåæã«åãã°ãªããã«ç§»åãããšè¡çªããŠããŸãããã ãã空äžã§è¡çªããããšã¯ç¡ããšããã
ãããèããããªãã¯ããžã£ã³ãåŸã« 2 人以äžã®åå è
ãè¡çªããŠããŸããªãããšå¿é
ã«ãªã£ãã
ããã§ãè¡çªãèµ·ããå¯èœæ§ããããããããªãã°äœåç®ã®ãžã£ã³ãã®åŸã«è¡çªãèµ·ããããæ±ããããšã«ããã
</p>
<h2>å¶çŽ</h2>
<ul>
<li>$1 \le H,W \le 500$</li>
<li>$0 \le N \le H \times W$</li>
<li>$0 \le r_{ij} < H \ (0 \le i < H, 0 \le j < W)$</li>
<li>$0 \le c_{ij} < W \ (0 \le i < H, 0 \le j < W)$</li>
<li>$0 \le R_i < H \ (0 \le i < N)$</li>
<li>$0 \le C_i < W \ (0 \le i < N)$</li>
<li>åå è
ã®åæäœçœ®ã¯çžç°ãªã</li>
</ul>
<h2>å
¥å圢åŒ</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<p>
$H \ W \ N$<br>
$r_{00} \ c_{00} \ \cdots \ r_{0 \ W-1} \ c_{0 \ W-1}$<br>
$\vdots$<br>
$r_{H-1 \ 0} \ c_{H-1 \ 0} \ \cdots \ r_{H-1 \ W-1} \ c_{H-1 \ W-1}$<br>
$R_0 \ C_0$<br>
$\vdots$<br>
$R_{N-1} \ C_{N-1}$<br>
</p>
<p>
ãã®åé¡ã§ã¯å
¥åãã¡ã€ã«ãéåžžã«å€§ãããªãããšãããããšã«æ³šæããã
C++ ãªã<a href="http://qnighy.hatenablog.com/entry/20110115/1295054750">ãã®ããŒãž</a>ãåèã«ãããšè¯ããããããªãã
</p>
<h2>åºå</h2>
<p>
è¡çªãèµ·ããå Žåã¯äœåç®ã®ãžã£ã³ãã®åŸã«èµ·ãããã 1 è¡ã§åºåããã
ããã§ãªãå Žå㯠-1 ãåºåããã
ãŸããæ«å°Ÿã«æ¹è¡ãåºåããã
</p>
<h2>ãµã³ãã«</h2>
<h3>ãµã³ãã«å
¥å 1</h3>
<pre>
2 2 2
1 0 0 1
0 0 1 0
0 0
0 1
</pre>
<h3>ãµã³ãã«åºå 1</h3>
<pre>
-1
</pre>
<h3>ãµã³ãã«å
¥å 2</h3>
<pre>
2 2 2
1 0 0 1
0 0 1 0
0 0
1 1
</pre>
<h3>ãµã³ãã«åºå 2</h3>
<pre>
1
</pre>
|
p00315 |
<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>N</var> ãã¯ã»ã«ã®æ£æ¹åœ¢ã®çœé»ç»åãšããŠè¡šããããåãã¯ã»ã«ã¯çœãŸãã¯é»ã®ç»åã«å¯Ÿå¿ããŠã0 ãŸã㯠1 ã®å€ããšãã
</p>
<p>
ãã®åºŠãçç£ã©ã€ã³ã®æ©åšæŽæ°ã«ãšããªã£ãŠãç»åè§£æã·ã¹ãã ã®ãœãããŠã§ã¢ãæŽæ°ããããšã«ãªã£ããæ°ã·ã¹ãã ã§ã¯ãéä¿¡ããŒã¿éãåæžãã工倫ããªããã以äžã®æ¹æ³ã§ã«ã¡ã©ããè§£æã·ã¹ãã ã«ããŒã¿ãéãããŠããã
</p>
<ul>
<li> ã©ã€ã³ã«æµããŠããæåã®ã³ãŒã¹ã¿ãŒã®æ
å ±ã¯ã<var>N</var> × <var>N</var> ãã¯ã»ã«ã®ç»åãšããŠã·ã¹ãã ã«éãããŠããã</li>
<li> ïŒæç®ä»¥éã®ã³ãŒã¹ã¿ãŒã®æ
å ±ã¯ãïŒã€åã«éãããç»åãšã®å·®åã ããéãããŠãããå·®åã¯ãã0 ãã 1 ããŸãã¯ã1 ãã 0 ããžãšå€åãããã¯ã»ã«ã®äœçœ®ã®éåãšããŠäžããããã</li>
</ul>
<p>
<var>C</var> æã®ã³ãŒã¹ã¿ãŒã«ã€ããŠãïŒæç®ã®ç»åã®ãã¯ã»ã«æ
å ±ãšç¶ã <var>C</var> - 1 æåã®å·®åæ
å ±ãå
¥åããäžäžå¯Ÿç§°ãã€å·Šå³å¯Ÿç§°ãšãªã£ãŠããã³ãŒã¹ã¿ãŒã®ææ°ãå ±åããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>C</var> <var>N</var>
<var>p<sub>11</sub>p<sub>12</sub></var>...<var>p<sub>1N</sub></var>
<var>p<sub>21</sub>p<sub>22</sub></var>...<var>p<sub>2N</sub></var>
:
<var>p<sub>N1</sub>p<sub>N2</sub></var>...<var>p<sub>NN</sub></var>
<var>diff<sub>1</sub></var>
<var>diff<sub>2</sub></var>
:
<var>diff<sub>C−1</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ã³ãŒã¹ã¿ãŒã®ææ° <var>C</var> (1 ≤ <var>C</var> ≤ 10000) ãšç»åã®çžŠãšæšªã®ãã¯ã»ã«æ° <var>N</var> (2 ≤ <var>N</var> ≤ 1000 ã〠<var>N</var> ã¯å¶æ°) ãäžãããããïŒè¡ç®ãã <var>N</var> + 1 è¡ç®ã«æåã®ã³ãŒã¹ã¿ãŒã®ç»åã®ãã¯ã»ã«ã衚ã <var>N</var>è¡ × <var>N</var> åã®æ°å <var>p<sub>ij</sub></var> (<var>p<sub>ij</sub></var> 㯠0 ãŸã㯠1)ãäžããããã
</p>
<p>
<var>N</var> + 2 è¡ç®ä»¥éã«ãïŒæç®ä»¥éã®ã³ãŒã¹ã¿ãŒã®æ
å ±ã衚ãå·®å <var>diff<sub>i</sub></var> ãæ¬¡ã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>D</var>
<var>r<sub>1</sub></var> <var>c<sub>1</sub></var>
<var>r<sub>2</sub></var> <var>c<sub>2</sub></var>
:
<var>r<sub>D</sub></var> <var>c<sub>D</sub></var>
</pre>
<p>
ïŒè¡ç®ã«å€åãããã¯ã»ã«ã®æ° <var>D</var> (0 ≤ <var>D</var> ≤ 100) ãäžãããããç¶ã<var>D</var> è¡ã«å€åãããã¯ã»ã«ã®è¡ãšåã®çªå·ããããã衚ã <var>r<sub>i</sub></var> ãš<var>c<sub>i</sub></var> (1 ≤ <var>r<sub>i</sub></var>, <var>c<sub>i</sub></var> ≤ <var>N</var>) ãäžããããã<var>diff<sub>i</sub></var> ã®äžã«ãåãäœçœ®ã¯ïŒå以äžäžããããªãã
</p>
<h2>Output</h2>
<p>
äžäžå¯Ÿç§°ãã€å·Šå³å¯Ÿç§°ãšãªã£ãŠããã³ãŒã¹ã¿ãŒã®ææ°ãïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
7 8
00100000
00011000
10111101
01100110
01000110
10111101
00011000
00100100
2
5 3
1 6
1
6 8
3
6 8
3 3
3 6
2
6 3
6 6
0
2
3 8
6 8
</pre>
<h2>Sample Output 1</h2>
<pre>
3
</pre>
<p>
å
¥åäŸïŒã®ã³ãŒã¹ã¿ãŒã®ç»åã以äžã«ç€ºãããã®å ŽåãïŒæç®ãïŒæç®ãïŒæç®ã®ã³ãŒã¹ã¿ãŒãäžäžå¯Ÿç§°ãã€å·Šå³å¯Ÿç§°ãšãªãããã3ãšå ±åããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2015_checking" width="680">
</center>
<br/>
<h2>Sample Input 2</h2>
<pre>
1 6
000000
000000
010010
010010
000000
000000
</pre>
<h2>Sample Output 2</h2>
<pre>
1
</pre>
<br/>
<h2>Sample Input 3</h2>
<pre>
2 2
00
00
4
1 1
1 2
2 1
2 2
</pre>
<h2>Sample Output 3</h2>
<pre>
2
</pre> |
p02328 |
<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>Largest Rectangle in a Histogram</H1>
<p>
A histogram is made of a number of contiguous bars, which have same width.
</p>
<p>
For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area.
</p>
<h2>Constraints</h2>
<ul>
<li> $1 \leq N \leq 10^5$ </li>
<li> $0 \leq h_i \leq 10^9$</li>
</ul>
<h2>Input</h2>
<p>The input is given in the following format.</p>
<p>
$N$<br>
$h_1$ $h_2$ ... $h_N$<br>
</p>
<h2>Output</h2>
<p>
Print the area of the largest rectangle.
</p>
<h2>Sample Input 1</h2>
<pre>
8
2 1 3 5 3 4 2 1
</pre>
<h2>Sample Output 1</h2>
<pre>
12
</pre>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_DPL_3_histogram">
</center>
<br/>
<h2>Sample Input 2</h2>
<pre>
3
2 0 1
</pre>
<h2>Sample Output 2</h2>
<pre>
2
</pre>
|
p02282 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Reconstruction of a Tree</H1>
<p>
Write a program which reads two sequences of nodes obtained by the preorder tree walk and the inorder tree walk on a binary tree respectively, and prints a sequence of the nodes obtained by the postorder tree walk on the binary tree.
</p>
<H2>Input</H2>
<p>
In the first line, an integer $n$, which is the number of nodes in the binary tree, is given.<br>
In the second line, the sequence of node IDs obtained by the preorder tree walk is given separated by space characters.<br>
In the second line, the sequence of node IDs obtained by the inorder tree walk is given separated by space characters.
</p>
<p>
Every node has a unique ID from $1$ to $n$. Note that the root does not always correspond to $1$.
</p>
<H2>Output</H2>
<p>
Print the sequence of node IDs obtained by the postorder tree walk in a line. Put a single space character between adjacent IDs.
</p>
<H2>Constraints</H2>
<ul>
<li>$1 \leq n \leq 40$</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
5
1 2 3 4 5
3 2 4 1 5
</pre>
<H2>Sample Output 1</H2>
<pre>
3 4 2 5 1
</pre>
<H2>Sample Input 2</H2>
<pre>
4
1 2 3 4
1 2 3 4
</pre>
<H2>Sample Output 2</H2>
<pre>
4 3 2 1
</pre> |
p00745 |
<h1><font color="#000000">Problem F:</font> Tighten Up!</h1>
<p>
We have a flat panel with two holes. Pins are nailed on its
surface. From the back of the panel, a string comes out through one
of the holes to the surface. The string is then laid on the surface
in a form of a polygonal chain, and goes out to the panel's back through
the other hole. Initially, the string does not touch any pins.
</p>
<p>
Figures F-1, F-2, and F-3 show three example layouts of holes, pins and
strings. In each layout, white squares and circles denote holes and
pins, respectively. A polygonal chain of solid segments denotes the
string.
</p>
<p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009F7" width="400"><br/>
Figure F-1: An example layout of holes, pins and a string
</center>
</p>
<p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009F0" width="400"><br/>
Figure F-2: An example layout of holes, pins and a string
</center>
</p>
<p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009F3" width="400"><br/>
Figure F-3: An example layout of holes, pins and a string
</center>
</p>
<p>
When we tie a pair of equal weight stones to the both ends of the
string, the stones slowly straighten the string until there is no
loose part. The string eventually forms a different polygonal chain as it is
obstructed by some of the pins. (There are also cases when the
string is obstructed by no pins, though.)
</p>
<p>
The string does not hook itself while being straightened. A fully
tightened string thus draws a polygonal chain on the surface of the
panel, whose vertices are the positions of some pins with the end
vertices at the two holes. The layouts in Figures F-1, F-2, and F-3 result in the
respective polygonal chains in Figures F-4, F-5, and F-6. Write a program that
calculates the length of the tightened polygonal chain.
</p>
<p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009F8" width="400"><br/>
Figure F-4: Tightened polygonal chains from the example in Figure F-1.
</center>
</p>
<p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009F1" width="400"><br/>
Figure F-5: Tightened polygonal chains from the example in Figure F-2.
</center>
</p>
<p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009F6" width="400"><br/>
Figure F-6: Tightened polygonal chains from the example in Figure F-3.
</center>
</p>
<p>
Note that the strings, pins and holes are thin enough so that you
can ignore their diameters.
</p>
<!-- end en only -->
<h3>Input</h3>
<p>
The input consists of multiple datasets, followed by a line containing
two zeros separated by a space. Each dataset gives the initial shape of the string (i.e., the positions of holes and vertices) and the positions of
pins in the
following format.
</p>
<blockquote>
<i>m n</i> <br>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <br>
... <br>
<i>x<sub>l</sub> y<sub>l</sub></i> <br>
</blockquote>
<!-- begin en only -->
<p>
The first line has two integers <i>m</i> and <i>n</i> (2 ≤ <i>m</i>
≤ 100, 0 ≤ <i>n</i> ≤ 100), representing the number of
vertices including two holes that give the initial string shape (<i>m</i>) and the number
of pins (<i>n</i>). Each of the following <i>l</i> = <i>m</i>
+ <i>n</i> lines has two integers <i>x<sub>i</sub></i>
and <i>y<sub>i</sub></i> (0 ≤ <i>x<sub>i</sub></i> ≤ 1000, 0 ≤ <i>y<sub>i</sub></i> ≤ 1000), representing a position <i>P<sub>i</sub></i> =
(<i>x<sub>i</sub></i> ,<i>y<sub>i</sub></i> ) on the surface of the
panel.
<ul>
<li>Positions <i>P</i><sub>1</sub>, ..., <i>P<sub>m</sub></i> give the initial shape of
the string; i.e., the two holes are at <i>P</i><sub>1</sub>
and <i>P<sub>m</sub></i> , and the string's shape is a polygonal
chain whose vertices are <i>P<sub>i</sub></i> (<i>i</i> =
1, ..., <i>m</i>), in this order.
<li>Positions <i>P</i><sub><i>m</i>+1</sub>, ..., <i>P</i><sub><i>m</i>+<i>n</i></sub> are the positions of
the pins.
</ul>
</p>
<!-- end en only -->
</p>
<!-- begin en only -->
<p>
Note that no two points are at the same position. No three points are
exactly on
a straight line.
</p>
<!-- end en only -->
<h3>Output</h3>
<!-- begin en only -->
<p>
For each dataset, the length of the part of the tightened string that
remains on the surface of the panel should be output in a line.
No extra characters
should appear in the output.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
No lengths in the output should have an error greater than 0.001.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>
6 16
5 4
11 988
474 975
459 16
985 12
984 982
242 227
140 266
45 410
92 570
237 644
370 567
406 424
336 290
756 220
634 251
511 404
575 554
726 643
868 571
907 403
845 283
10 4
261 196
943 289
859 925
56 822
112 383
514 0
1000 457
514 1000
0 485
233 224
710 242
850 654
485 915
140 663
26 5
0 953
180 0
299 501
37 301
325 124
162 507
84 140
913 409
635 157
645 555
894 229
598 223
783 514
765 137
599 445
695 126
859 462
599 312
838 167
708 563
565 258
945 283
251 454
125 111
28 469
1000 1000
185 319
717 296
9 315
372 249
203 528
15 15
200 247
859 597
340 134
967 247
421 623
1000 427
751 1000
102 737
448 0
978 510
556 907
0 582
627 201
697 963
616 608
345 819
810 809
437 706
702 695
448 474
605 474
329 355
691 350
816 231
313 216
864 360
772 278
756 747
529 639
513 525
0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
2257.0518296609
3609.92159564177
2195.83727086364
3619.77160684813
</pre>
|
p02778 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Given is a string <var>S</var>. Replace every character in <var>S</var> with <code>x</code> and print the result.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>S</var> is a string consisting of lowercase English letters.</li>
<li>The length of <var>S</var> is between <var>1</var> and <var>100</var> (inclusive).</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>Replace every character in <var>S</var> with <code>x</code> and print the result.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>sardine
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>xxxxxxx
</pre>
<p>Replacing every character in <var>S</var> with <code>x</code> results in <code>xxxxxxx</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>xxxx
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>xxxx
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>gone
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>xxxx
</pre></section>
</div>
</span> |
p01857 |
<h1 id="f-åµ-eggs">F : åµ / Eggs</h1>
<h2 id="å顿">å顿</h2>
<p><var>1</var> ãæåã®ããšã§ããïŒ å°åŠçã®è西åã¯å€äŒã¿ã®å®¿é¡ããã£ãŠããªãã£ãïŒ ããã§èªç±ç ç©¶ã¯å®¶ã«ãã£ãåµã®åŒ·åºŠã調ã¹ãããšã«ããïŒ</p>
<p>ãã®ç ç©¶ã«ãããŠïŒåµãé«ã <var>H</var> ããèœãšããŠãå²ããïŒ é«ã <var>H+1</var> ããèœãšããšå²ãããšãïŒ ãã®åµã®åŒ·åºŠã¯ <var>H</var> ã§ãããšå®çŸ©ããïŒ ããã§ <var>H</var> ã¯éè² æŽæ°ã§ããïŒéè² æŽæ°ä»¥å€ã®é«ãããèœãšãããšã¯ç¡ããšããïŒ è西ããã¯åµã <var>1</var> ã€èœäžãããå®éšãè¡ãïŒ å®éšã®çµæã¯å²ãããå²ããªããã®ããããã§ããïŒ ãŸãïŒåµã®åŒ·åºŠã¯å
šãŠåãã§ããïŒã€ãŸãïŒã©ã®åµãçšããŠãå®éšã®çµæã¯åãã§ããïŒ</p>
<p>è西ããã¯é«ã <var>1</var> ãã <var>N</var> ãŸã§ã®æŽæ°ã®é«ãã®æ®µãããªãéæ®µãšïŒ 匷床ãäžæãª <var>E</var> åã®åµãçšæããïŒ é«ã <var>0</var> ã§ã¯å²ããïŒé«ã <var>N+1</var> ã§ã¯å²ãããšããããšã¯æ¢ã«ããã£ãŠããïŒ è西ããã¯å段ãšåãé«ãããå°é¢ã«åãã£ãŠèœãšãïŒãã®åºŠã«åµãå²ãããå²ããªãã£ããã調ã¹ãïŒ ãã®ãšãå²ããåµã¯äºåºŠãšäœ¿ããªããïŒå²ããªãã£ãå Žåã¯åå©çšã§ããïŒ ãã®å®éšãåµãæ®ã£ãŠããéãç¶ããããšãã§ããïŒ äœåºŠãå®éšãç¹°ãè¿ãïŒäžã«å®ãã <var>H</var> ãæ±ãŸã£ããšãïŒåµã®åŒ·åºŠãæ±ãŸã£ããšããïŒ</p>
<p>å€äŒã¿çµäºãŸã§åŸæ°æ¥ããç¡ãïŒ æå°ã®åæ°ã§å®éšãçµããããªããšéã«åããªãïŒ ããã§ïŒè西ããã®å
ã§ããããªãã¯ïŒåµã®åŒ·åºŠãç¥ãããã« èœãšãåæ°ãå°ãªããªãããã«æé©ãªæ¹æ³ããšã£ãå Žåã« å¿
èŠãªå®éšåæ°ã®æå€§å€ãæ±ããããã°ã©ã ãæžãããšã«ããïŒ</p>
<h2 id="å
¥å">å
¥å</h2>
<pre>
<var>T</var>
<var>N_1 E_1</var>
âŠ
<var>N_T</var> <var>E_T</var>
</pre>
<p>1 ã€ã®ãã¡ã€ã«ã«è€æ°ã®ãã¹ãã±ãŒã¹ãå«ãŸããïŒ <var>1</var> è¡ç®ã«æŽæ° <var>T</var> ãäžããããïŒ <var>1+i</var> è¡ç®ã« <var>i</var> çªç®ã®ãã¹ãã±ãŒã¹ <var>E_i, N_i</var> ãäžãããã</p>
<h2 id="å¶çŽ">å¶çŽ</h2>
<ul>
<li>æŽæ°ã§ãã</li>
<li><var>1 ≤ T ≤ 1000</var></li>
<li><var>1 ≤ N_i ≤ 10^{18}</var></li>
<li><var>1 ≤ E_i ≤ 50</var></li>
<li>åºåã <var>50</var> ãè¶
ãããããªå
¥åã¯å«ãŸããªã</li>
</ul>
<h2 id="åºå">åºå</h2>
<p><var>i</var> çªç®ã®ãã¹ãã±ãŒã¹ã«å¯Ÿããçãã <var>i</var> è¡ç®ã«åºåããïŒ å
šäœã§ <var>T</var> è¡ã«ãããïŒ</p>
<h2 id="ãµã³ãã«">ãµã³ãã«</h2>
<h3 id="ãµã³ãã«å
¥å1">ãµã³ãã«å
¥å1</h3>
<pre>
3
5 1
5 2
1 2
</pre>
<h3 id="ãµã³ãã«åºå1">ãµã³ãã«åºå1</h3>
<pre>
5
3
1
</pre>
<ul>
<li><var>1</var> ã€ç®ã®å Žå
<ul>
<li>åµã <var>1</var> ã€ãããªããã <var>1</var> 段ç®ããé ã«èœãšããŠãããããªã</li>
</ul></li>
<li><var>2</var> ã€ç®ã®å Žå
<ul>
<li>ãŸã <var>2</var> 段ç®ããèœãšã</li>
<li><var>2</var> 段ç®ããèœãšããŠå²ããå Žå <var>1</var> 段ç®ããèœãšã</li>
<li><var>2</var> 段ç®ããèœãšããŠå²ããªãã£ãå Žå <var>4</var> 段ç®ããèœãšã</li>
<li><var>1</var> 段ç®ããèœãšããŠå²ããå Žåå®éšçµäº</li>
<li><var>1</var> 段ç®ããèœãšããŠå²ããªãã£ãå Žåå®éšçµäº</li>
<li><var>4</var> 段ç®ããèœãšããŠå²ããå Žå <var>3</var> 段ç®ããèœãšã</li>
<li><var>4</var> 段ç®ããèœãšããŠå²ããªãã£ãå Žå <var>5</var> 段ç®ããèœãšã</li>
<li><var>3</var> 段ç®ããèœãšããŠå²ããå Žåå®éšçµäº</li>
<li><var>3</var> 段ç®ããèœãšããŠå²ããªãã£ãå Žåå®éšçµäº</li>
<li><var>5</var> 段ç®ããèœãšããŠå²ããå Žåå®éšçµäº</li>
<li><var>5</var> 段ç®ããèœãšããŠå²ããªãã£ãå Žåå®éšçµäº</li>
</ul></li>
<li><var>3</var> ã€ç®ã®å Žå
<ul>
<li><var>1</var> 段ç®ããèœãšããŠå®éšçµäº</li>
</ul></li>
</ul>
<!-- - - - end nicebady - - - -->
|
p03539 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Consider the following game:</p>
<ul>
<li>The game is played using a row of <var>N</var> squares and many stones.</li>
<li>First, <var>a_i</var> stones are put in Square <var>i\ (1 \leq i \leq N)</var>.</li>
<li>A player can perform the following operation as many time as desired: "Select an integer <var>i</var> such that Square <var>i</var> contains exactly <var>i</var> stones. Remove all the stones from Square <var>i</var>, and add one stone to each of the <var>i-1</var> squares from Square <var>1</var> to Square <var>i-1</var>."</li>
<li>The final score of the player is the total number of the stones remaining in the squares.</li>
</ul>
<p>For a sequence <var>a</var> of length <var>N</var>, let <var>f(a)</var> be the minimum score that can be obtained when the game is played on <var>a</var>.</p>
<p>Find the sum of <var>f(a)</var> over all sequences <var>a</var> of length <var>N</var> where each element is between <var>0</var> and <var>K</var> (inclusive).
Since it can be extremely large, find the answer modulo <var>1000000007 (= 10^9+7)</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 100</var></li>
<li><var>1 \leq K \leq N</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>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the sum of <var>f(a)</var> modulo <var>1000000007 (= 10^9+7)</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
</pre>
<p>There are nine sequences of length <var>2</var> where each element is between <var>0</var> and <var>2</var>. For each of them, the value of <var>f(a)</var> and how to achieve it is as follows:</p>
<ul>
<li><var>f(\{0,0\})</var>: <var>0</var> (Nothing can be done)</li>
<li><var>f(\{0,1\})</var>: <var>1</var> (Nothing can be done)</li>
<li><var>f(\{0,2\})</var>: <var>0</var> (Select Square <var>2</var>, then Square <var>1</var>)</li>
<li><var>f(\{1,0\})</var>: <var>0</var> (Select Square <var>1</var>)</li>
<li><var>f(\{1,1\})</var>: <var>1</var> (Select Square <var>1</var>)</li>
<li><var>f(\{1,2\})</var>: <var>0</var> (Select Square <var>1</var>, Square <var>2</var>, then Square <var>1</var>)</li>
<li><var>f(\{2,0\})</var>: <var>2</var> (Nothing can be done)</li>
<li><var>f(\{2,1\})</var>: <var>3</var> (Nothing can be done)</li>
<li><var>f(\{2,2\})</var>: <var>3</var> (Select Square <var>2</var>)</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>20 17
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>983853488
</pre></section>
</div>
</span> |
p01504 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<H1>AYBABTU</H1>
<p>
There is a tree that has <var>n</var> nodes and <var>n-1</var> edges.
There are military bases on <var>t</var> out of the <var>n</var> nodes.
We want to disconnect the bases as much as possible by destroying <var>k</var> edges.
The tree will be split into <var>k+1</var> regions when we destroy <var>k</var> edges.
Given the purpose to disconnect the bases, we only consider to split in a way that each of these <var>k+1</var> regions has at least one base.
When we destroy an edge, we must pay destroying cost.
Find the minimum destroying cost to split the tree.
</p>
<H2>Input</H2>
<p>
The input consists of multiple data sets.
Each data set has the following format.
The first line consists of three integers <var>n</var>, <var>t</var>, and <var>k</var> (<var>1 \leq n \leq 10,000</var>, <var>1 \leq t \leq n</var>, <var>0 \leq k \leq t-1</var>).
Each of the next <var>n-1</var> lines consists of three integers representing an edge.
The first two integers represent node numbers connected by the edge.
A node number is a positive integer less than or equal to <var>n</var>.
The last one integer represents destroying cost.
Destroying cost is a non-negative integer less than or equal to 10,000.
The next <var>t</var> lines contain a distinct list of integers one in each line, and represent the list of nodes with bases.
The input ends with a line containing three zeros, which should not be processed.
</p>
<H2>Output</H2>
<p>
For each test case, print its case number and the minimum destroying cost to split the tree with the case number.
</p>
<H2>Sample Input</H2>
<pre>
2 2 1
1 2 1
1
2
4 3 2
1 2 1
1 3 2
1 4 3
2
3
4
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Case 1: 1
Case 2: 3
</pre>
|
p03493 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has a grid consisting of three squares numbered <var>1</var>, <var>2</var> and <var>3</var>.
In each square, either <code>0</code> or <code>1</code> is written. The number written in Square <var>i</var> is <var>s_i</var>.</p>
<p>Snuke will place a marble on each square that says <code>1</code>.
Find the number of squares on which Snuke will place a marble.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>Each of <var>s_1</var>, <var>s_2</var> and <var>s_3</var> is either <code>1</code> or <code>0</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>s_{1}s_{2}s_{3}</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>101
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<ul>
<li>A marble will be placed on Square <var>1</var> and <var>3</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<ul>
<li>No marble will be placed on any square.</li>
</ul></section>
</div>
</span> |
p03169 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> dishes, numbered <var>1, 2, \ldots, N</var>.
Initially, for each <var>i</var> (<var>1 \leq i \leq N</var>), Dish <var>i</var> has <var>a_i</var> (<var>1 \leq a_i \leq 3</var>) pieces of sushi on it.</p>
<p>Taro will perform the following operation repeatedly until all the pieces of sushi are eaten:</p>
<ul>
<li>Roll a die that shows the numbers <var>1, 2, \ldots, N</var> with equal probabilities, and let <var>i</var> be the outcome. If there are some pieces of sushi on Dish <var>i</var>, eat one of them; if there is none, do nothing.</li>
</ul>
<p>Find the expected number of times the operation is performed before all the pieces of sushi are eaten.</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 300</var></li>
<li><var>1 \leq a_i \leq 3</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>a_1</var> <var>a_2</var> <var>\ldots</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the expected number of times the operation is performed before all the pieces of sushi are eaten.
The output is considered correct when the relative difference is not greater than <var>10^{-9}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5.5
</pre>
<p>The expected number of operations before the first piece of sushi is eaten, is <var>1</var>.
After that, the expected number of operations before the second sushi is eaten, is <var>1.5</var>.
After that, the expected number of operations before the third sushi is eaten, is <var>3</var>.
Thus, the expected total number of operations is <var>1 + 1.5 + 3 = 5.5</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
<p>Outputs such as <code>3.00</code>, <code>3.000000003</code> and <code>2.999999997</code> will also be accepted.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4.5
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>10
1 3 2 3 3 2 3 2 1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>54.48064457488221
</pre></section>
</div>
</span> |
p01154 |
<H1><font color="#000">Problem I:</font> Light The Room</H1>
<p>
You are given plans of rooms of polygonal shapes. The walls of the rooms on the plans are
placed parallel to either <i>x</i>-axis or <i>y</i>-axis. In addition, the walls are made of special materials so
they reflect light from sources as mirrors do, but only once. In other words, the walls do not
reflect light already reflected at another point of the walls.
</p>
<p>
Now we have each room furnished with one lamp. Walls will be illuminated by the lamp directly
or indirectly. However, since the walls reflect the light only once, some part of the walls may
not be illuminated.
</p>
<p>
You are requested to write a program that calculates the total length of <i>unilluminated</i> part of
the walls.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_lightTheRoom">
<p>Figure 10: The room given as the second case in Sample Input</p>
</center>
<H2>Input</H2>
<p>
The input consists of multiple test cases.
</p>
<p>
The first line of each case contains a single positive even integer <i>N</i> (4 ≤ <i>N</i> ≤ 20), which indicates
the number of the corners. The following <i>N</i> lines describe the corners counterclockwise. The
i-th line contains two integers <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i> , where (<i>x<sub>i</sub></i> , <i>y<sub>i</sub></i> ) indicates the coordinates of the <i>i</i>-th
corner. The last line of the case contains <i>x'</i> and <i>y'</i> , where (<i>x'</i> , <i>y'</i> ) indicates the coordinates of
the lamp.
</p>
<p>
To make the problem simple, you may assume that the input meets the following conditions:
</p>
<ul>
<li>All coordinate values are integers not greater than 100 in their absolute values.</li>
<li>No two walls intersect or touch except for their ends.</li>
<li>The walls do not intersect nor touch each other.</li>
<li>The walls turn each corner by a right angle.</li>
<li>The lamp exists strictly inside the room off the wall.</li>
<li>The x-coordinate of the lamp does not coincide with that of any wall; neither does the
y-coordinate.</li>
</ul>
<p>
The input is terminated by a line containing a single zero.
</p>
<H2>Output</H2>
<p>
For each case, output the length of the unilluminated part in one line. The output value may
have an arbitrary number of decimal digits, but may not contain an error greater than 10<sup>-3</sup> .
</p>
<H2>Sample Input</H2>
<pre>
4
0 0
2 0
2 2
0 2
1 1
6
2 2
2 5
0 5
0 0
5 0
5 2
1 4
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0.000
3.000
</pre>
|
p01343 |
<H1><font color="#000">Problem E: </font>Psychic Accelerator</H1>
<p>
In the west of Tokyo, there is a city named âAcademy City.â There are many schools and laboratories to develop psychics in Academy City.
</p>
<p>
You are a psychic student of a school in Academy City. Your psychic ability is to give acceleration to a certain object.
</p>
<p>
You can use your psychic ability anytime and anywhere, but there are constraints. If the object remains stationary, you can give acceleration to the object in any direction. If the object is moving, you can give acceleration to the object only in 1) the direction the object is moving to, 2) the direction opposite to it, or 3) the direction perpendicular to it.
</p>
<p>
Todayâs training menu is to move the object along a given course. For simplicity you can regard the course as consisting of line segments and circular arcs in a 2-dimensional space. The course has no branching. All segments and arcs are connected smoothly, i.e. there are no sharp corners.
</p>
<p>
In the beginning, the object is placed at the starting point of the first line segment. You have to move the object to the ending point of the last line segment along the course and stop the object at that point by controlling its acceleration properly. Before the training, a coach ordered you to simulate the minimum time to move the object from the starting point to the ending point.
</p>
<p>
Your task is to write a program which reads the shape of the course and the maximum acceleration <i>a<sub>max</sub></i> you can give to the object and calculates the minimum time to move the object from the starting point to the ending point.
</p>
<p>
The object follows basic physical laws. When the object is moving straight in some direction, with acceleration either forward or backward, the following equations hold:
</p>
<center>
<p>
<i>v</i> = <i>v</i><sub>0</sub> + <i>at</i>
</p>
</center>
<p>
and
</p>
<center>
<p>
<i>s</i> = <i>v</i><sub>0</sub><i>t</i> + (1/2)<i>at</i><sup>2</sup>
</p>
</center>
<p>
where <i>v</i>, <i>s</i>, <i>v</i><sub>0</sub>, <i>a</i>, and <i>t</i> are the velocity, the distance from the starting point, the initial velocity (i.e. the velocity at the starting point), the acceleration, and the time the object has been moving in that direction, respectively. Note that they can be simplified as follows:
</p>
<center>
<p>
<i>v</i><sup>2</sup> − <i>v</i><sub>0</sub><sup>2</sup> = 2<i>as</i>
</p>
</center>
<p>
When the object is moving along an arc, with acceleration to the centroid, the following equations hold:
</p>
<center>
<p>
<i>a</i> = <i>v</i><sup>2</sup>/<i>r</i>
</p>
</center>
<p>
wher <i>v</i>, <i>a</i>, and <i>r</i> are the velocity, the acceleration, and the radius of the arc, respectively. Note that the object cannot change the velocity due to the criteria on your psychic ability.
</p>
<H2>Input</H2>
<p>
The input has the following format:
</p>
<p>
<i>N a<sub>max</sub></i><br>
<i>x</i><sub><i>a</i>,1</sub> <i>y</i><sub><i>a</i>,1</sub> <i>x</i><sub><i>b</i>,1</sub> <i>y</i><sub><i>b</i></sub>,1</sub><br>
<i>x</i><sub><i>a</i>,2</sub> <i>y</i><sub><i>a</i>,2</sub> <i>x</i><sub><i>b</i>,2</sub> <i>y</i><sub><i>b</i></sub>,2</sub><br>
.<br>
.<br>
.<br>
</p>
<p>
<i>N</i> is the number of line segments; <i>a<sub>max</sub></i> is the maximum acceleration you can give to the object; (<i>x<sub>a,i</sub></i>, <i>y<sub>a,i</sub></i>) and (<i>x<sub>b,i</sub></i>, <i>y<sub>b,i</sub></i>) are the starting point and the ending point of the <i>i</i>-th line segment, respectively. The given course may have crosses but you cannot change the direction there.
</p>
<p>
The input meets the following constraints: 0 < <i>N</I> ≤ 40000, 1 ≤ <i>a<sub>max</sub></i> ≤ 100, and -100 ≤ <i>x<sub>a</sub>i</i>, <i>y<sub>a</sub>i</i>, <i>x<sub>b</sub>i</i>, <i>y<sub>b</sub>i</i> ≤ 100.
</p>
<H2>Output</H2>
<p>
Print the minimum time to move the object from the starting point to the ending point with an relative or absolute error of at most 10<sup>-6</sup>. You may output any number of digits after the decimal point.
</p>
<H2>Sample Input 1</H2>
<pre>
2 1
0 0 1 0
1 1 0 1
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
5.2793638507
</pre>
<H2>Sample Input 2</H2>
<pre>
1 1
0 0 2 0
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
2.8284271082
</pre>
<H2>Sample Input 3</H2>
<pre>
3 2
0 0 2 0
1 -1 1 2
0 1 2 1
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>
11.1364603512
</pre>
|
p02996 | <span class="lang-en">
<p>Score: <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Kizahashi, who was appointed as the administrator of ABC at National Problem Workshop in the Kingdom of AtCoder, got too excited and took on too many jobs.</p>
<p>Let the current time be time <var>0</var>. Kizahashi has <var>N</var> jobs numbered <var>1</var> to <var>N</var>.</p>
<p>It takes <var>A_i</var> units of time for Kizahashi to complete Job <var>i</var>. The deadline for Job <var>i</var> is time <var>B_i</var>, and he must complete the job before or at this time.</p>
<p>Kizahashi cannot work on two or more jobs simultaneously, but when he completes a job, he can start working on another immediately.</p>
<p>Can Kizahashi complete all the jobs in time? If he can, print <code>Yes</code>; if he cannot, print <code>No</code>.</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 2 \times 10^5</var></li>
<li><var>1 \leq A_i, B_i \leq 10^9 (1 \leq i \leq N)</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>A_1</var> <var>B_1</var>
<var>.</var>
<var>.</var>
<var>.</var>
<var>A_N</var> <var>B_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>If Kizahashi can complete all the jobs in time, 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>5
2 4
1 9
1 8
4 9
3 12
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>He can complete all the jobs in time by, for example, doing them in the following order:</p>
<ul>
<li>Do Job <var>2</var> from time <var>0</var> to <var>1</var>.</li>
<li>Do Job <var>1</var> from time <var>1</var> to <var>3</var>.</li>
<li>Do Job <var>4</var> from time <var>3</var> to <var>7</var>.</li>
<li>Do Job <var>3</var> from time <var>7</var> to <var>8</var>.</li>
<li>Do Job <var>5</var> from time <var>8</var> to <var>11</var>.</li>
</ul>
<p>Note that it is fine to complete Job <var>3</var> exactly at the deadline, time <var>8</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
334 1000
334 1000
334 1000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>He cannot complete all the jobs in time, no matter what order he does them in.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>30
384 8895
1725 9791
170 1024
4 11105
2 6
578 1815
702 3352
143 5141
1420 6980
24 1602
849 999
76 7586
85 5570
444 4991
719 11090
470 10708
1137 4547
455 9003
110 9901
15 8578
368 3692
104 1286
3 4
366 12143
7 6649
610 2374
152 7324
4 7042
292 11386
334 5720
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre></section>
</div>
</span> |
p03684 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> towns on a plane. The <var>i</var>-th town is located at the coordinates <var>(x_i,y_i)</var>. There may be more than one town at the same coordinates.</p>
<p>You can build a road between two towns at coordinates <var>(a,b)</var> and <var>(c,d)</var> for a cost of <var>min(|a-c|,|b-d|)</var> yen (the currency of Japan). It is not possible to build other types of roads.</p>
<p>Your objective is to build roads so that it will be possible to travel between every pair of towns by traversing roads. At least how much money is necessary to achieve this?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 †N †10^5</var></li>
<li><var>0 †x_i,y_i †10^9</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>x_1</var> <var>y_1</var>
<var>x_2</var> <var>y_2</var>
:
<var>x_N</var> <var>y_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum necessary amount of money in order to build roads so that it will be possible to travel between every pair of towns by traversing roads.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 5
3 9
7 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>Build a road between Towns <var>1</var> and <var>2</var>, and another between Towns <var>2</var> and <var>3</var>. The total cost is <var>2+1=3</var> yen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6
8 3
4 9
12 19
18 1
13 5
7 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>8
</pre></section>
</div>
</span> |
p00801 |
<H1><font color="#000">Problem F:</font> Numoeba</H1>
<p>
A scientist discovered a strange variation of amoeba. The scientist named it <i>numoeba</i>. A numoeba, though it looks like an amoeba, is actually a community of cells, which always forms a tree.
</p>
<p>
The scientist called the cell <i>leader</i> that is at the root position of the tree. For example, in Fig. 1, the leader is <i>A</i>. In a numoeba, its leader may change time to time. For example, if <i>E</i> gets new leadership, the tree in Fig. 1 becomes one in Fig. 2. We will use the terms root, leaf, parent, child and subtree for a numoeba as defined in the graph theory.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_numoeba1">
</center>
<p>
Numoeba changes its physical structure at every biological clock by cell division and cell death. The leader may change depending on this physical change.
</p>
<p>
The most astonishing fact about the numoeba cell is that it contains an organic unit called <i>numbosome</i>, which represents an odd integer within the range from 1 to 12,345,677. At every biological clock, the value of a numbosome changes from n to a new value as follows:
</p>
<ol>
<li> The maximum odd factor of 3<i>n</i> + 1 is calculated. This value can be obtained from 3<i>n</i> + 1 by repeating division by 2 while even.</li>
<li> If the resulting integer is greater than 12,345,678, then it is subtracted by 12,345,678.</li>
</ol>
<p>
For example, if the numbosome value of a cell is 13, 13 × 3 + 1 = 40 is divided by 2<sup>3</sup> = 8 and a new numbosome value 5 is obtained. If the numbosome value of a cell is 11,111,111, it changes to 4,320,989, instead of 16,666,667. If 3<i>n</i> + 1 is a power of 2, yielding 1 as the result, it signifies the death of the cell as will be described below.
</p>
<p>
At every biological clock, the next numbosome value of every cell is calculated and the fate of the cell and thereby the fate of numoeba is determined according to the following steps.
</p>
<ol>
<li> A cell that is a leaf and increases its numbosome value is designated as a <i>candidate</i> leaf.<br>
A cell dies if its numbosome value becomes 1. If the dying cell is the leader of the numoeba, the numoeba dies as a whole. Otherwise, all the cells in the subtree from the dying cell (including itself) die. However, there is an exceptional case where the cells in the subtree do not necessarily die; if there is only one child cell of the dying non-leader cell, the child cell will replace the dying cell. Thus, a straight chain simply shrinks if its non-leader constituent dies.
<br>
For example, consider a numoeba with the leader A below. <br>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_numoeba2">
</center>
<br>
If the leader A dies in (1), the numoeba dies.<br>
If the cell D dies in (1), (1) will be as follows. <br>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_numoeba3">
</center>
<br>
And, if the cell E dies in (1), (1) will be as follows.<br>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_numoeba4">
</center>
<br>
Note that this procedure is executed sequentially, top-down from the root of the numoeba to leaves. If the cells <i>E</i> and <i>F</i> will die in (1), the death of <i>F</i> is not detected at the time the procedure examines the cell <i>E</i>. The numoeba, therefore, becomes (3). One should not consider in such a way that the death of <i>F</i> makes <i>G</i> the only child of <i>E</i>, and, therefore, <i>G</i> will replace the dying <i>E</i>.</li>
<li> If a <i>candidate</i> leaf survives with the numbosome value of <i>n</i>, it spawns a cell as its child, thereby a new leaf, whose numbosome value is the least odd integer greater than or equal to (<i>n</i> + 1)/2. We call the child leaf bonus.</li>
<li> Finally, a new leader of the numoeba is selected, who has a unique maximum numbosome value among all the constituent cells. The tree structure of the numoeba is changed so that the new leader is its root, like what is shown in Fig. 1 and Fig. 2. Note that the parent-child relationship of some cells may be reversed by this leader change. When a new leader of a unique maximum numbosome value, say <i>m</i>, is selected (it may be the same cell as the previous leader), it spawns a cell as its child with the numbosome whose value is the greatest odd integer less than or equal to (<i>m</i> + 1)/2. We call the child <i>leader bonus</i>. If there is more than one cell of the same maximum numbosome value, however, the leader does not change for the next period, and there is no leader bonus.
</li>
</ol>
<p>
The following illustrates the growth and death of a numoeba starting from a single cell seed with the numbosome value 15, which plays both roles of the leader and a leaf at the start. In the figure, a cell is nicknamed with its numbosome value. Note that the order of the children of a parent is irrelevant.
</p>
<br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_numoeba5"><br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_numoeba6">
<br>
<p>
The numoeba continues changing its structure, and at clock 104, it looks as follows.
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_numoeba7"><br>
</center>
<br>
<p>
Here, two ambitious 2429's could not become the leader. The leader 5 will die without promoting these talented cells at the next clock. This alludes the fragility of a big organization.
</p>
<p>
And, the numoeba dies at clock 105.
</p>
<p>
Your job is to write a program that outputs statistics about the life of numoebae that start from a single cell seed at clock zero.
</p>
<H2>Input</H2>
<p>
A sequence of odd integers, each in a line. Each odd integer <i>k<sub>i</sub></i> (3 ≤ <i>k<sub>i</sub></i> ≤ 9,999) indicates the initial numbosome value of the starting cell. This sequence is terminated by a zero.
</p>
<H2>Output</H2>
<p>
A sequence of pairs of integers:an integer that represents the numoeba's life time and an integer that represents the maximum number of constituent cells in its life. These two integers should be separated by a space character, and each pair should be followed immediately by a newline. Here, the lifetime means the clock when the numoeba dies.
</p>
<p>
You can use the fact that the life time is less than 500, and that the number of cells does not exceed 500 in any time, for any seed value given in the input. You might guess that the program would consume a lot of memory. It is true in general. But, don't mind. Referees will use a test data set consisting of no more than 10 starting values, and, starting from any of the those values, the total numbers of cells spawned during the lifetime will not exceed 5000.
</p>
<H2>Sample Input</H2>
<pre>
3
5
7
15
655
2711
6395
7195
8465
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2 3
1 1
9 11
105 65
398 332
415 332
430 332
428 332
190 421
</pre>
|
p01713 |
<h1>åé¡ B : Evacuation Route</h1>
<h2>å顿</h2>
<p>
æ¥æ¬ã§ã¯é²çœç ç©¶ãçãã«è¡ãããŠããïŒè¿å¹Žãã®éèŠæ§ããŸããŸãå¢ããŠããïŒ
é¿é£çµè·¯ã®è©äŸ¡ãéèŠãªç ç©¶ã®ã²ãšã€ã§ããïŒ
ä»åã¯çŽç·ç¶ã®éè·¯ã®å®å
šè©äŸ¡ãè¡ãïŒ
</p>
<p>
é路㯠<var>W</var> åã®ãŠãããã«åããããŠããïŒäžæ¹ã®ç«¯ã®ãŠãããããããäžæ¹ã®ç«¯ã®ãŠããããŸã§ <var>0,  1,  2,  âŠ ,  W-1</var> ã®çªå·ãã€ããããŠããïŒ
éè·¯å
ã®åãŠãããã«ã¯ïŒå
¥å£ã®æïŒåºå£ã®æïŒé²ç«æã®ãããã1ã€ãååšããïŒ
å
¥ãå£ã®æïŒåºå£ã®æïŒé²ç«æã¯ããããéè·¯å
ã«è€æ°åååšãããïŒ
</p>
<p>
ãã®åé¡ã§ã¯æå» <var>t=0</var> ã§ç«çœãçºçãããšæ³å®ããïŒ
ããã«ããïŒéè·¯ã®å€éšã«ããŠé¿é£ããããšããŠãã人ã
ãå
¥å£ã®æãéããŠéè·¯ãžå
¥ãïŒããå®å
šãªå Žæãžåºãããã«åºå£ã®æãžè±åºããããšãããã®ãšããïŒ
é¿é£äžã®ããããã®äººã¯åäœæå»ããšã« 1 ã€ã®ãŠããããç§»åãããïŒä»ã®ãŠãããã«çãŸãããšãã§ããïŒ
ããªãã¡ïŒæå» <var>t</var> ã«ãã人ããŠããã <var>i</var> ã«ãããšãããšãïŒãã®äººã¯æå» <var>t+1</var> ã§ã¯ãŠããã <var>i-1,  i,   i+1</var> ã®3ã€ã®æ°åã®ãã¡ <var>0</var> ä»¥äž <var>W-1</var> 以äžã§ãããã®ãéžæãïŒãã®çªå·ã®ãŠããããžç§»åããããšãã§ããïŒ
é²ç«æããããŠãããã¯ïŒããäžå®æå»ä»¥éã«ãªããšå®å
šã«é®æãããŠããŸãïŒé¿é£äžã®äººã
ã¯ãã®ãŠãããã«ç«ã¡å
¥ãã§ããªããªãïŒãŸãïŒãã®ãŠãããå
ã«å±
ã人ã
ãããããä»ã®ãŠãããã«ç§»åã§ããªããªã£ãŠããŸãïŒ
</p>
<p>
ãã®åé¡ã«ãããç®çã¯ïŒããããã®æã®æ
å ±ãäžããããã®ã§ïŒé¿é£äžã®äººã
ãæé©ã«è¡åããæã«æå€§ã§äœäººãåºå£ã®æãžãã©ãçãããèšç®ããããšã§ããïŒ
</p>
<p>
éè·¯ã®æ
å ±ã<var>W</var>åã®æŽæ°<var>a_i</var>ã§äžããããïŒ
</p>
<ul>
<li><var>a_i = 0</var>ã®ãšãïŒ<var>i</var> çªç®ã®ãŠããããåºå£ã®æã§ããããšãããããïŒ</li>
<li><var>a_i < 0</var>ã®ãšãïŒ<var>i</var> çªç®ã®ãŠããããé²ç«æã«ããæé <var>|a_i|</var> 以éåºå
¥ãã§ããªããªãããšã衚ãïŒ</li>
<li><var>a_i > 0</var>ã®ãšãïŒæå» <var>t=0, 1, 2, âŠ , a_{i}-1</var> ã®ããããã«ãããŠïŒã¡ããã©äžäººã®äººã <var>i</var> çªç®ã®ãŠãããã«çŸããïŒæå» <var>t</var> ã«çŸãã人ã¯ïŒæå» <var>t+1</var> 以éããç§»åãéå§ããïŒ</li>
</ul>
<p>
ãªãïŒ1ã€ã®ãŠãããã«è€æ°ã®äººã
ãååšããŠãããŸããªãïŒ
</p>
<p>
åºå£ã®æãžãã©ãçããæå€§ã®äººæ°ãæ±ããïŒ
</p>
<h2>å
¥å圢åŒ</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžãããã
<pre>
<var>W</var>
<var>a_0</var> <var>a_1</var> <var>...</var> <var>a_{W-1}</var>
</pre>
<h2>åºå圢åŒ</h2>
<p>
æå€§äººæ°ã1è¡ã§åºåããïŒ
</p>
<h2>å¶çŽ</h2>
<ul>
<li><var>1 ≤ W ≤ 10^5</var></li>
<li><var>|a_i|   ≤ 10^4</var></li>
<li>å
¥åå€ã¯ãã¹ãп޿°ã§ããïŒ</li>
</ul>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
7
2 0 -2 3 2 -2 0
</pre>
<h3>åºåäŸ 1</h3>
<pre>
4
</pre>
<p>
<var>0,   3,   5</var>çªç®ã®ãŠãããã«å
¥ãå£ã®æãããïŒ
<var>1,   6</var>çªç®ã®ãŠãããã«åºå£ã®æãããïŒ<br>
<var>0</var>çªç®ã®ãŠãããããã¯ïŒ<var>1</var>çªç®ã®ãŠããããžïŒäººåºãããšãã§ããïŒ<br>
<var>3</var>çªç®ã®ãŠãããããã¯ïŒ<var>1</var>çªç®ã®ãŠããããžïŒäººåºãããšãã§ããïŒ<br>
<var>5</var>çªç®ã®ãŠãããããã¯ïŒ<var>6</var>çªç®ã®ãŠããããžïŒäººåºãããšãã§ããïŒ<br>
ãã£ãŠåãããŠïŒäººãåºå£ãžãšãã©ãçããïŒ
</p>
<h3>å
¥åäŸ 2</h3>
<pre>
4
1 1 1 1
</pre>
<h3>åºåäŸ 2</h3>
<pre>
0
</pre>
<p>
åºå£ããªãã®ã§èª°ãè±åºã§ããªãïŒ
</p>
<h3>å
¥åäŸ 3</h3>
<pre>
9
10 -10 10 -10 10 -10 10 -10 0
</pre>
<h3>åºåäŸ 3</h3>
<pre>
24
</pre> |
p00552 |
<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>
<h2>æå±€(Geologic Fault)</h2>
<p>
é ãæïŒIOI ææãšããé«åºŠãªææãæ ããŠããïŒãããïŒç«å±±ã®åŽç«ã«ããïŒãã®é«åºŠãªææã¯ã€ãã«æ»
ãã§ããŸã£ãïŒIOI ææã¯çŽç·ç¶ã®æ²³å·ã«æ²¿ã£ãŠç¹æ ããŠããïŒIOI ææãæ»
ãã ãšãïŒãã®å°è¡šé¢ã¯å¹³ãã§ãã£ãïŒIOI ææã®è·¡å°ã¯åº§æšå¹³é¢ã®x 軞ãšèŠãªãããšãã§ããïŒy 軞ã¯é«ãæ¹åã衚ãïŒããªãã¡ïŒåº§æšå¹³é¢ã«ãããŠïŒçŽç· $y = 0$ ã¯å°è¡šãïŒé å $y > 0$ ã¯å°äžãïŒé å $y < 0$ ã¯å°äžã衚ãïŒãŸãïŒIOI ææãæ»
ãã ãšãïŒ$a$ 幎å$(a \geq 0)$ ã®å°å±€ã¯ïŒçŽç· $y = -a$ ã®äœçœ®ã«ãã£ãïŒ
</p>
<p>
IOI ææãæ»
ãã åŸïŒIOI ææã®è·¡å°ã§ã¯ $Q$ åã®å°æ®»å€åãèµ·ããïŒ$i$ åç®$(1 \leq i \leq Q)$ ã®å°æ®»å€åã¯ïŒäœçœ® $X_i$ïŒæ¹å $D_i$ïŒå€åã®é $L_i$ ã§è¡šãããïŒ$D_i$ 㯠1 ãŸã㯠2 ã§ããïŒ$i$ åç®ã®å°æ®»å€åã¯ä»¥äžã®ããã«èµ·ããïŒ
</p>
<ul>
<li> å°å±€ã®ç§»åãæ¬¡ã®ããã«èµ·ããïŒ
<ul>
<li> $D_i = 1$ ã®ãšãïŒæå±€ãç¹$(X_i, 0)$ ãéãåŸã $1$ ã®çŽç·ã«æ²¿ã£ãŠé ããïŒãã®çŽç·ããäžã®é åã«ããå°å±€ãïŒçŽç·ã«æ²¿ã£ãŠé«ã $L_i$ ã ãç§»åããïŒããªãã¡ïŒãã®çŽç·ããäžã®ç¹ $(x, y)$ ã¯ïŒç¹$(x + L_i, y + L_i)$ ã«ç§»åããïŒ</li>
<li> $D_i = 2$ ã®ãšãïŒæå±€ãç¹$(X_i, 0)$ ãéãåŸã $-1$ ã®çŽç·ã«æ²¿ã£ãŠé ããïŒãã®çŽç·ããäžã®é åã«ããå°å±€ãïŒçŽç·ã«æ²¿ã£ãŠé«ã $L_i$ ã ãç§»åããïŒããªãã¡ïŒãã®çŽç·ããäžã®ç¹$(x, y)$ ã¯ïŒç¹$(x - L_i, y + L_i)$ ã«ç§»åããïŒ</li>
</ul>
</li>
<li> ãã®ããåŸã«ïŒé å $y > 0$ ã®å°å±€ã颚åã«ãã£ãŠãã¹ãŠæ¶ããïŒ</li>
</ul>
<p>
æã¯å€ããçŸä»£ïŒèå€åŠè
ã®JOI å士ã¯IOI ææã®éºè·¡ãçºæããããšã«ããïŒJOI å士ã¯ã©ã®äœçœ®ã®å°è¡šã®å°å±€ãïŒIOI ææãæ»
ã¶äœå¹Žåã®å°å±€ã§ããããç¥ãããïŒã©ã®ãããªå°æ®»å€åãèµ·ãããã¯åãã£ãŠããïŒããªãã®ä»äºã¯ïŒJOI å士ã«ããã£ãŠïŒ$1 \leq i \leq N$ ãæºããåæŽæ° $i$ ã«ã€ããŠïŒç¹$(i-1, 0)$ ãšç¹$(i, 0)$ã®éã®å°è¡šã®å°å±€ãIOI ææãæ»
ã¶äœå¹Žåã®å°å±€ã§ããããæ±ããããšã§ããïŒ
</p>
<h2>課é¡</h2>
<p>
IOI ææã®è·¡å°ã«èµ·ããã®æ
å ±ãäžãããããšãïŒãã¹ãŠã®æŽæ° $i$ $(1 \leq i \leq N)$ ã«å¯ŸãïŒç¹$(i - 1, 0)$ ãšç¹$(i, 0)$ ã®éã®å°è¡šã®å°å±€ãIOI ææãæ»
ã¶äœå¹Žåã®å°å±€ã§ããããåºåããïŒ
</p>
<h2>å
¥å</h2>
<p>
æšæºå
¥åãã以äžã®å
¥åãèªã¿èŸŒãïŒ
</p>
<ul>
<li> 1 è¡ç®ã«ã¯ïŒ 2 åã®æŽæ° $N, Q$ ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒçããæ±ããå°ç¹ã®æ°ã $N$ïŒå°æ®»å€åã®åæ°ã $Q$ ã§ããããšã衚ãïŒ</li>
<li> ç¶ã $Q$ è¡ã®ãã¡ã® $i$ è¡ç®$(1 \leq i \leq Q)$ ã«ã¯ïŒ3 åã®æŽæ° $X_i, D_i, L_i$ ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒ$i$ åç®ã®å°æ®»å€åã®äœçœ®ã $X_i$ïŒæ¹åã $D_i$ïŒå€åã®éã $L_i$ ã§ããããšã衚ãïŒ</li>
</ul>
<h2>åºå</h2>
<p>
åºå㯠$N$ è¡ãããªãïŒæšæºåºåã® $i$ è¡ç®$(1 \leq i \leq N)$ ã«ã¯ïŒç¹$(i - 1, 0)$ ãšç¹$(i, 0)$ ã®éã®å°è¡šã®å°å±€ãIOIææãæ»
ã¶äœå¹Žåã®å°å±€ã§ããããè¡šãæŽæ°ãåºåããïŒ
</p>
<h2>å¶é</h2>
<p>
ãã¹ãŠã®å
¥åããŒã¿ã¯ä»¥äžã®æ¡ä»¶ãæºããïŒ
</p>
<ul>
<li> $1 \leq N \leq 200 000$ </li>
<li> $1 \leq Q \leq 200 000$ </li>
<li> $ -1 000 000 000 \leq X_i \leq 1 000 000 000$ $(1 \leq i \leq Q)$ </li>
<li> $1 \leq D_i \leq 2$ $(1 \leq i \leq Q)$ </li>
<li> $1 \leq L_i \leq 1 000 000 000$ $(1 \leq i \leq Q)$ </li>
</ul>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ1</h3>
<pre>
10 2
12 1 3
2 2 2
</pre>
<h3>åºåäŸ1</h3>
<pre>
3
3
5
5
5
5
5
5
2
2
</pre>
<p>
ãã®å
¥åäŸã¯ïŒä»¥äžã®å³ã«å¯Ÿå¿ããïŒ
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2015_geologicFault1">
</center>
<h3>å
¥åäŸ2</h3>
<pre>
10 6
14 1 1
17 1 1
-6 2 1
3 2 1
4 1 1
0 2 1
</pre>
<h3>åºåäŸ2</h3>
<pre>
5
5
4
5
5
5
5
5
4
4
</pre>
<h3>å
¥åäŸ3</h3>
<pre>
15 10
28 1 7
-24 2 1
1 1 1
8 1 1
6 2 1
20 1 3
12 2 2
-10 1 3
7 2 1
5 1 2
</pre>
<h3>åºåäŸ3</h3>
<pre>
15
14
14
14
14
12
12
12
12
12
12
12
15
15
12
</pre>
<div class="source">
<p class="source">
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="ã¯ãªãšã€ãã£ãã»ã³ã¢ã³ãºã»ã©ã€ã»ã³ã¹" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a>
</p>
<p class="source">
<a href="https://www.ioi-jp.org/joi/2015/2016-ho/2016-ho.pdf">第15å æ¥æ¬æ
å ±ãªãªã³ããã¯æ¬éž èª²é¡ 2016 幎 2 æ 14 æ¥</a>
</p>
</div>
|
p02095 |
<h2>H: Colorful Tree</h2>
<h3>Story</h3>
<p>
<i>Yamiuchi</i> (assassination) is a traditional event that is held annually in JAG summer camp. Every team displays a decorated tree in the dark and all teams' trees are compared from the point of view of their colorfulness. In this competition, it is allowed to cut the other teamsâ tree to reduce its colorfulness. Despite a team would get a penalty if it were discovered that the team cuts the tree of another team, many teams do this obstruction.
</p>
<p>You decided to compete in <i>Yamiuchi</i> and write a program that maximizes the colorfulness of your teamâs tree. The program has to calculate maximum scores for all subtrees in case the other teams cut your tree.</p>
<h3>Problem Statement</h3>
<p>You are given a rooted tree <var>G</var> with <var>N</var> vertices indexed with <var>1</var> through <var>N</var>. The root is vertex <var>1</var>. There are <var>K</var> kinds of colors indexed with <var>1</var> through <var>K</var>. You can paint vertex <var>i</var> with either color <var>c_i</var> or <var>d_i</var>. Note that <var>c_i = d_i</var> may hold, and if so you have to paint vertex <var>i</var> with <var>c_i</var> (<var>=d_i</var>).</p>
<p>Let the colorfulness of tree <var>T</var> be the number of different colors in <var>T</var>. Your task is to write a program that calculates maximum colorfulness for all rooted subtrees. Note that coloring for each rooted subtree is done independently, so previous coloring does not affect to other coloring.</p>
<h3>Input</h3>
<pre>
<var>N</var> <var>K</var>
<var>u_1</var> <var>v_1</var>
<var>:</var>
<var>u_{N-1}</var> <var>v_{N-1}</var>
<var>c_1</var> <var>d_1</var>
<var>:</var>
<var>c_N</var> <var>d_N</var>
</pre>
<p>The first line contains two integers <var>N</var> and <var>K</var> in this order.</p>
<p>The following <var>N-1</var> lines provide information about the edges of <var>G</var>. The <var>i</var>-th line of them contains two integers <var>u_i</var> and <var>v_i</var>, meaning these two vertices are connected with an edge.</p>
<p>The following <var>N</var> lines provide information about color constraints. The <var>i</var>-th line of them contains two integers <var>c_i</var> and <var>d_i</var> explained above.</p>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq K \leq 2\times 10^5</var></li>
<li><var>1 \leq u_i , v_i \leq N</var></li>
<li><var>1 \leq c_i , d_i \leq K</var></li>
<li>The input graph is a tree.</li>
<li> All inputs are integers.</li>
</ul>
<h3>Output</h3>
<p>Output <var>N</var> lines.</p>
<p>The <var>i</var>-th line of them contains the maximum colorfulness of the rooted subtree of <var>G</var> whose root is <var>i</var>.</p>
<h3>Sample Input 1</h3>
<pre>
2 10
1 2
1 9
8 7
</pre>
<h3>Output for Sample Input 1</h3>
<pre>
2
1
</pre>
<h3>Sample Input 2</h3>
<pre>
3 2
1 2
1 3
1 2
1 1
1 2
</pre>
<h3>Output for Sample Input 2</h3>
<pre>
2
1
1
</pre>
<p>Note that two color options of a vertex can be the same.</p>
<h3>Sample Input 3</h3>
<pre>
5 100000
4 3
3 5
1 3
2 1
3 2
1 3
2 1
4 2
1 4
</pre>
<h3>Output for Sample Input 3</h3>
<pre>
4
1
3
1
1
</pre>
|
p00102 |
<H1>Matrix-like Computation</H1>
<p>
Your task is to develop a tiny little part of spreadsheet software.
</p>
<p>
Write a program which adds up columns and rows of given table as shown in the following figure:
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_matrixLike" width="640">
</center>
<H2>Input</H2>
<p>
The input consists of several datasets. Each dataset consists of:
</p>
<pre>
<i>n</i> (the size of row and column of the given table)
1st row of the table
2nd row of the table
:
:
<i>n</i>th row of the table
</pre>
<p>
The input ends with a line consisting of a single 0.
</p>
<H2>Output</H2>
<p>
For each dataset, print the table with sums of rows and columns. Each item of the table should be aligned to the right with a margin for five digits. Please see the sample output for details.
</p>
<H2>Sample Input</H2>
<pre>
4
52 96 15 20
86 22 35 45
45 78 54 36
16 86 74 55
4
52 96 15 20
86 22 35 45
45 78 54 36
16 86 74 55
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
52 96 15 20 183
86 22 35 45 188
45 78 54 36 213
16 86 74 55 231
199 282 178 156 815
52 96 15 20 183
86 22 35 45 188
45 78 54 36 213
16 86 74 55 231
199 282 178 156 815
</pre>
|
p00417 | <h1>ã³ã³ãã¥ãŒã¿ã·ã¹ãã ã®äžå
·å</h1>
ã
<p>
ããªãã¯äžçæé«æ§èœã®ã³ã³ãã¥ãŒã¿ã·ã¹ãã ãé£ç±å€ïŒãªããïŒããèšèšããŠããããããããã®ã·ã¹ãã ã®ãããã¿ã€ãã®å®è£
äžã«ãåœä»€åãããæ¡ä»¶ãæºãããšã·ã¹ãã ã忢ãããšããäžå
·åãèŠã€ãã£ãã
</p>
<p>
ãã®ã·ã¹ãã ã¯ãé·ã$N$ã®åœä»€åãããã°ã©ã ãšããŠäžããããšã§åäœãããåœä»€åã®äžã®$m$çªç®ã®åœä»€ãæ°$X_m$ã§è¡šãããšããäžå
·åãèµ·ããæ¡ä»¶ã¯ãããæŽæ°$i,j$ ($2 \leq iïŒj \leq N$)ã«å¯ŸããŠ$X_i + X_{j-1} = X_j + X_{i-1}$ãšãªãåœä»€ã®ãã¿ãŒã³ãåœä»€åã«ååšããããšã§ãããšå€æããã
</p>
<p>
ããªãã¯ãã®äžå
·åãã©ã®çšåºŠã®åœ±é¿ã«ãªãã®ãã調ã¹ããããããé·ãã§äœãããšãã§ããåœä»€åã®ãã¡ãäœçš®é¡ã®åœä»€åãäžå
·åãèµ·ãããã調ã¹ãããšã«ããã
</p>
<p>
é·ã$N$ã®åœä»€åã®ãã¡ãäžå
·åãèµ·ããåœä»€åãäœéãããããæ±ããããã°ã©ã ãäœæããããã ããåœä»€ã¯$1$以äž$K$以äžã®æŽæ°ã§è¡šããããšãšãããçãã¯äžããããçŽ æ°$M$ã§å²ã£ãäœããšããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
$N$ $K$ $M$
</pre>
<p>
ïŒè¡ã«ãåœä»€åã®é·ã$N$ ($3 \leq N \leq 100,000$)ãåœä»€ã®çš®é¡ã®æ°$K$ ($1 \leq K \leq 10$)ãçŽ æ°$M$ ($100,000,007 \leq M \leq 1,000,000,007$)ãäžããããã
</p>
<h2>åºå</h2>
<p>
äžå
·åãèµ·ããåœä»€åã®æ°ãMã§å²ã£ãäœããåºåããã
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸïŒ</h3>
<pre>
3 2 100000007
</pre>
<h3>åºåäŸïŒ</h3>
<pre>
2
</pre>
<p>
åœä»€åã$(X_1,X_2,X_3)$ã®ããã«è¡šããšãèããããåœä»€åã¯$(1,1,1)$ã$(1,1,2)$ã$(1,2,1)$ã$(1,2,2)$ã$(2,1,1)$ã$(2,1,2)$ã$(2,2,1)$ã$(2,2,2)$ã®ïŒéãããã®ãã¡ãäžå
·åãèµ·ããåœä»€åã¯$(1,1,1)$ã$(2,2,2)$ã®ïŒéãã
</p>
<h3>å
¥åäŸïŒ</h3>
<pre>
9 10 100000037
</pre>
<h3>åºåäŸïŒ</h3>
<pre>
66631256
</pre>
<p>
äžå
·åãèµ·ããåœä»€åã¯866631552éããããããã®æ°ãçŽ æ°100000037ã§å²ã£ãäœããåºåãšãªãã
</p>
|
p02580 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a two-dimensional grid with <var>H \times W</var> squares. There are <var>M</var> targets to destroy in this grid - the position of the <var>i</var>-th target is <var>\left(h_i, w_i \right)</var>.</p>
<p>Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.</p>
<p>Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq H, W \leq 3 \times 10^5</var></li>
<li><var>1 \leq M \leq \min\left(H\times W, 3 \times 10^5\right)</var></li>
<li><var>1 \leq h_i \leq H</var></li>
<li><var>1 \leq w_i \leq W</var></li>
<li><var>\left(h_i, w_i\right) \neq \left(h_j, w_j\right) \left(i \neq j\right)</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>H</var> <var>W</var> <var>M</var>
<var>h_1</var> <var>w_1</var>
<var>\vdots</var>
<var>h_M</var> <var>w_M</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>2 3 3
2 2
1 1
1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>We can destroy all the targets by placing the bomb at <var>\left(1, 2\right)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3 4
3 3
3 1
1 1
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 5 10
2 5
4 3
2 3
5 5
2 2
5 4
5 3
5 1
3 5
1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>6
</pre></section>
</div>
</span> |
p00047 |
<H1>ã«ããã²ãŒã </H1>
<center>
<table>
<tr>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cupGame"></td>
</tr>
</table>
</center>
<br/>
<p>
3 ã€ã®ã«ããããµããŠçœ®ãããŠããŸããã«ããã®çœ®ãããŠããå Žæããé ã« A,B,C ãšåŒã¶ããšã«ããŸããæå㯠A ã«çœ®ãããŠããã«ããã®äžã«ããŒã«ãé ãããŠãããšããŸããã«ããã®äœçœ®ãå
¥ãæ¿ãããšãäžã«å
¥ã£ãŠããããŒã«ãäžç·ã«ç§»åããŸãã
</p>
<p>
å
¥ãæ¿ããïŒã€ã®ã«ããã®äœçœ®ãèªã¿èŸŒãã§ãæçµçã«ã©ã®å Žæã®ã«ããã«ããŒã«ãé ãããŠããããåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<H2>Input</H2>
<p>
å
¥ãæ¿ããïŒã€ã®ã«ããã®äœçœ®ãé çªã«è€æ°è¡ã«ãããäžããããŸããåè¡ã«ãå
¥ãæ¿ããïŒã€ã®ã«ããã®äœçœ®ã衚ãæåïŒA, B, ãŸã㯠CïŒãã«ã³ãåºåãã§äžããããŸãã
</p>
<p>
å
¥ãæ¿ããæäœã¯ 50 åãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ããŒã«ãå
¥ã£ãŠããã«ããã®å ŽæïŒA, B, ãŸã㯠CïŒãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
B,C
A,C
C,B
A,B
C,B
</pre>
<H2>Output for the Sample Input</H2>
<pre>
A
</pre>
|
p04004 | <span class="lang-en">
<p>Score : <var>1100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Alice, Bob and Charlie are playing <em>Card Game for Three</em>, as below:</p>
<ul>
<li>At first, each of the three players has a deck consisting of some number of cards. Alice's deck has <var>N</var> cards, Bob's deck has <var>M</var> cards, and Charlie's deck has <var>K</var> cards. Each card has a letter <code>a</code>, <code>b</code> or <code>c</code> written on it. The orders of the cards in the decks cannot be rearranged.</li>
<li>The players take turns. Alice goes first.</li>
<li>If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says <code>a</code>, Alice takes the next turn.)</li>
<li>If the current player's deck is empty, the game ends and the current player wins the game.</li>
</ul>
<p>There are <var>3^{N+M+K}</var> possible patters of the three player's initial decks. Among these patterns, how many will lead to Alice's victory?</p>
<p>Since the answer can be large, print the count modulo <var>1\,000\,000\,007 (=10^9+7)</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 3Ã10^5</var></li>
<li><var>1 \leq M \leq 3Ã10^5</var></li>
<li><var>1 \leq K \leq 3Ã10^5</var></li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Scores</h3><ul>
<li><var>500</var> points will be awarded for passing the test set satisfying the following: <var>1 \leq N \leq 1000</var>, <var>1 \leq M \leq 1000</var>, <var>1 \leq K \leq 1000</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>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer modulo <var>1\,000\,000\,007 (=10^9+7)</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>17
</pre>
<ul>
<li>If Alice's card is <code>a</code>, then Alice will win regardless of Bob's and Charlie's card. There are <var>3Ã3=9</var> such patterns.</li>
<li>If Alice's card is <code>b</code>, Alice will only win when Bob's card is <code>a</code>, or when Bob's card is <code>c</code> and Charlie's card is <code>a</code>. There are <var>3+1=4</var> such patterns.</li>
<li>If Alice's card is <code>c</code>, Alice will only win when Charlie's card is <code>a</code>, or when Charlie's card is <code>b</code> and Bob's card is <code>a</code>. There are <var>3+1=4</var> such patterns.</li>
</ul>
<p>Thus, there are total of <var>9+4+4=17</var> patterns that will lead to Alice's victory.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1227
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1000 1000 1000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>261790852
</pre></section>
</div>
</span> |
p01206 |
<H1><font color="#000">Problem E:</font> Black Force</H1>
<p>
A dam construction project was designed around an area called Black Force. The area is surrounded by
mountains and its rugged terrain is said to be very suitable for constructing a dam.
</p>
<p>
However, the project is now almost pushed into cancellation by a strong protest campaign started by the
local residents. Your task is to plan out a compromise proposal. In other words, you must find a way to
build a dam with sufficient capacity, without destroying the inhabited area of the residents.
</p>
<p>
The map of Black Force is given as <i>H</i> × <i>W</i> cells (0 < <i>H</i>, <i>W</i> ≤ 20). Each cell <i>h<sub>i, j</sub></i> is a positive integer
representing the height of the place. The dam can be constructed at a connected region surrounded
by higher cells, as long as the region contains neither the outermost cells nor the inhabited area of the
residents. Here, a region is said to be connected if one can go between any pair of cells in the region
by following a sequence of left-, right-, top-, or bottom-adjacent cells without leaving the region. The
constructed dam can store water up to the height of the lowest surrounding cell. The capacity of the dam
is the maximum volume of water it can store. Water of the depth of 1 poured to a single cell has the
volume of 1.
</p>
<p>
The important thing is that, in the case it is difficult to build a sufficient large dam, it is allowed to
choose (at most) one cell and do groundwork to increase the height of the cell by 1 unit. Unfortunately,
considering the protest campaign, groundwork of larger scale is impossible. Needless to say, you cannot
do the groundwork at the inhabited cell.
</p>
<p>
Given the map, the required capacity, and the list of cells inhabited, please determine whether it is possible
to construct a dam.
</p>
<H2>Input</H2>
<p>
The input consists of multiple data sets. Each data set is given in the following format:
</p>
<pre>
<i>H W C R</i>
<i>h</i><sub>1,1</sub> <i>h</i><sub>1,2</sub> . . . <i>h</i><sub>1,<i>W</i></sub>
...
<i>h</i><sub><i>H</i>,1</sub> <i>h</i><sub><i>H</i>,2</sub> . . . <i>h</i><sub><i>H</i>,<i>W</i></sub>
<i>y</i><sub>1</sub> <i>x</i><sub>1</sub>
...
<i>y<sub>R</sub> x<sub>R</sub></i>
</pre>
<p>
<i>H</i> and <i>W</i> is the size of the map. <i.C</i> is the required capacity. <i>R</i> (0 < <i>R</i> < <i>H</i> × <i>W</i>) is the number of cells
inhabited. The following <i>H</i> lines represent the map, where each line contains <i>W</i> numbers separated by
space. Then, the <i>R</i> lines containing the coordinates of inhabited cells follow. The line â<i>y x</i>â means that
the cell <i>h<sub>y,x</sub></i> is inhabited.
</p>
<p>
The end of input is indicated by a line â0 0 0 0â. This line should not be processed.
</p>
<H2>Output</H2>
<p>
For each data set, print âYesâ if it is possible to construct a dam with capacity equal to or more than <i>C</i>.
Otherwise, print âNoâ.
</p>
<H2>Sample Input</H2>
<pre>
4 4 1 1
2 2 2 2
2 1 1 2
2 1 1 2
2 1 2 2
1 1
4 4 1 1
2 2 2 2
2 1 1 2
2 1 1 2
2 1 2 2
2 2
4 4 1 1
2 2 2 2
2 1 1 2
2 1 1 2
2 1 1 2
1 1
3 6 6 1
1 6 7 1 7 1
5 1 2 8 1 6
1 4 3 1 5 1
1 4
5 6 21 1
1 3 3 3 3 1
3 1 1 1 1 3
3 1 1 3 2 2
3 1 1 1 1 3
1 3 3 3 3 1
3 4
0 0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Yes
No
No
No
Yes
</pre>
|
p03391 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given sequences <var>A</var> and <var>B</var> consisting of non-negative integers.
The lengths of both <var>A</var> and <var>B</var> are <var>N</var>, and the sums of the elements in <var>A</var> and <var>B</var> are equal.
The <var>i</var>-th element in <var>A</var> is <var>A_i</var>, and the <var>i</var>-th element in <var>B</var> is <var>B_i</var>.</p>
<p>Tozan and Gezan repeats the following sequence of operations:</p>
<ul>
<li>If <var>A</var> and <var>B</var> are equal sequences, terminate the process.</li>
<li>Otherwise, first Tozan chooses a positive element in <var>A</var> and decrease it by <var>1</var>.</li>
<li>Then, Gezan chooses a positive element in <var>B</var> and decrease it by <var>1</var>.</li>
<li>Then, give one candy to Takahashi, their pet.</li>
</ul>
<p>Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible.
Find the number of candies given to Takahashi when both of them perform the operations optimally.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2 Ã 10^5</var></li>
<li><var>0 \leq A_i,B_i \leq 10^9(1\leq i\leq N)</var></li>
<li>The sums of the elements in <var>A</var> and <var>B</var> are equal.</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>B_1</var>
<var>:</var>
<var>A_N</var> <var>B_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of candies given to Takahashi when both Tozan and Gezan perform the operations optimally.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
1 2
3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>When both Tozan and Gezan perform the operations optimally, the process will proceed as follows:</p>
<ul>
<li>Tozan decreases <var>A_1</var> by <var>1</var>.</li>
<li>Gezan decreases <var>B_1</var> by <var>1</var>.</li>
<li>One candy is given to Takahashi.</li>
<li>Tozan decreases <var>A_2</var> by <var>1</var>.</li>
<li>Gezan decreases <var>B_1</var> by <var>1</var>.</li>
<li>One candy is given to Takahashi.</li>
<li>As <var>A</var> and <var>B</var> are equal, the process is terminated.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
8 3
0 1
4 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1
1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p02979 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a blackboard on which all integers from <var>-10^{18}</var> through <var>10^{18}</var> are written, each of them appearing once. Takahashi will repeat the following sequence of operations any number of times he likes, possibly zero:</p>
<ul>
<li>Choose an integer between <var>1</var> and <var>N</var> (inclusive) that is written on the blackboard. Let <var>x</var> be the chosen integer, and erase <var>x</var>.</li>
<li>If <var>x-2</var> is not written on the blackboard, write <var>x-2</var> on the blackboard.</li>
<li>If <var>x+K</var> is not written on the blackboard, write <var>x+K</var> on the blackboard.</li>
</ul>
<p>Find the number of possible sets of integers written on the blackboard after some number of operations, modulo <var>M</var>.
We consider two sets different when there exists an integer contained in only one of the sets.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq K\leq N \leq 150</var></li>
<li><var>10^8\leq M\leq 10^9</var></li>
<li><var>N</var>, <var>K</var>, and <var>M</var> 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> <var>M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of possible sets of integers written on the blackboard after some number of operations, modulo <var>M</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 1 998244353
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7
</pre>
<p>Every set containing all integers less than <var>1</var>, all integers greater than <var>3</var>, and at least one of the three integers <var>1</var>, <var>2</var>, and <var>3</var> satisfies the condition. There are seven such sets.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6 3 998244353
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>61
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>9 4 702443618
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>312
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>17 7 208992811
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>128832
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>123 45 678901234
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>256109226
</pre></section>
</div>
</span> |
p00944 |
<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 J
Post Office Investigation</h2>
<p>
In this country, all international mails from abroad are first gathered to the central post office, and then delivered to each destination post office relaying some post offices on the way. The delivery routes between post offices are described by a directed graph $G = (V,E)$, where $V$ is the set of post offices and $E$ is the set of possible mail forwarding steps. Due to the inefficient operations, you cannot expect that the mails are delivered along the shortest route.
</p>
<p>
The set of post offices can be divided into a certain number of groups. Here, a group is defined as a set of post offices where mails can be forwarded from any member of the group to any other member, directly or indirectly. The number of post offices in such a group does not exceed 10.
</p>
<p>
The post offices frequently receive complaints from customers that some mails are not delivered yet. Such a problem is usually due to system trouble in a single post office, but identifying which is not easy. Thus, when such complaints are received, the customer support sends staff to check the system of each candidate post office. Here, the investigation cost to check the system of the post office $u$ is given by $c_u$, which depends on the scale of the post office.
</p>
<p>
Since there are many post offices in the country, and such complaints are frequently received, reducing the investigation cost is an important issue. To reduce the cost, the post service administration determined to use the following scheduling rule: When complaints on undelivered mails are received by the post offices $w_1, ..., w_k$ one day, staff is sent on the next day to investigate a single post office $v$ with the lowest investigation cost among candidates. Here, the post office $v$ is a candidate if all mails from the central post office to the post offices $w_1, ... , w_k$ must go through $v$. If no problem is found in the post office $v$, we have to decide the order of investigating other post offices, but the problem is left to some future days.
</p>
<p>
Your job is to write a program that finds the cost of the lowest-cost candidate when the list of complained post offices in a day, described by $w_1, ... , w_k$, is given as a query.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case, formatted as follows.<br>
<br>
$n$ $m$<br>
$u_1$ $v_1$<br>
...<br>
$u_m$ $v_m$<br>
$c_1$<br>
...<br>
$c_n$<br>
$q$<br>
$k_1$ $w_{11}$ ... $w_{1k_1}$<br>
...<br>
$k_q$ $w_{q1}$ ... $w_{qk_q}$<br>
<br>
$n$ is the number of post offices $(2 \leq n \leq 50,000)$, which are numbered from 1 to $n$. Here, post office 1 corresponds to the central post office. $m$ is the number of forwarding pairs of post offices $(1 \leq m \leq 100,000)$. The pair, $u_i$ and $v_i$, means that some of the mails received at post office $u_i$ are forwarded to post office $v_i$ $(i = 1, ..., m)$. $c_j$ is the investigation cost for the post office $j$ $(j = 1, ..., n, 1 \leq c_j \leq 10^9)$. $q$ $(q \geq 1)$ is the number of queries, and each query is specified by a list of post offices which received undelivered mail complaints. $k_i$ $(k_i \geq 1)$ is the length of the list and $w_{i1}, ..., w_{ik_i}$ are the distinct post offices in the list. $\sum_{i=1}^{q} k_i \leq 50,000$.
</p>
<p>
You can assume that there is at least one delivery route from the central post office to all the post offices.
</p>
<h3>Output</h3>
<p>
For each query, you should output a single integer that is the lowest cost of the candidate of troubled post office.
</p>
<h3>Sample Input 1</h3>
<pre>8 8
1 2
1 3
2 4
2 5
2 8
3 5
3 6
4 7
1000
100
100
10
10
10
1
1
3
2 8 6
2 4 7
2 7 8</pre>
<h3>Sample Output 1</h3>
<pre>1000
10
100</pre>
<h3>Sample Input 2</h3>
<pre>10 12
1 2
2 3
3 4
4 2
4 5
5 6
6 7
7 5
7 8
8 9
9 10
10 8
10
9
8
7
6
5
4
3
2
1
3
2 3 4
3 6 7 8
3 9 6 3</pre>
<h3>Sample Output 2</h3>
<pre>8
5
8</pre>
|
p01656 |
<h2>A - æ§ç·åç ç©¶ïŒå·é€š</h2>
<p>
æã¯å¹³æ50幎æ¥äŒã¿ïŒæ
å ±åŠç ç©¶ç§ã«æå±ãã京åããã¯ïŒäº¬éœã«ããæç ç©¶ããŒã¯ããã®ç 究宀ã®åŒè¶ãããã£ãšçµããïŒãããšäžæ¯ã€ããŠããïŒ
ä»åã®åŒè¶ãã¯ïŒå€ããªã£ãæ ¡èã®æ¹ä¿®å·¥äºã«ãããã®ã§ïŒæ°å¹ŽåºŠããå·¥äºã«äŒŽãæ ¡èã®ååã倿Žãããããšã«ãªã£ãŠããïŒ
</p>
<p>
ãããšããŠããã®ãã€ãã®éïŒäº¬åããã¯å
çãã倧åŠã®è³æã«èŒã£ãŠããæ ¡èåãæ°ããååã«å€æŽãããä»äºãé ŒãŸããŠããŸã£ãïŒ
ãããç·šéããªããã°ãªããªãè³æã«ã¯ïŒä»ãŸã§ã®æ
åœè
ãä»äºãæ ã£ãŠãããããïŒã²ãšã€å€ãååãããã£ãšå€ãååã䜿ãããŠãããã®ããã£ãïŒ
</p>
<p>
ãªããšã京åããã¯ïŒå¹³æã®éã«æ ¡èãæ¹åãè¡ããã幎床ãšãã®ååã®ãªã¹ããèŠã€ããããšãã§ããïŒå¹³æå
å¹ŽåºŠã®æ ¡èå㯠"kogakubu10gokan" ã§ãã£ãïŒ<br>
ã ãåŒè¶ãäœæ¥ã«ãšãŠãç²ããã®ã§ïŒãã®è³æãäœããã幎床ã«ãã®æ ¡èãã©ããªååã ã£ãã®ããèªåã®æã§èª¿ã¹ãã®ã«ã¯ææ
¢ãªããªãã£ãïŒ
</p>
<p>
ããã§äº¬åããã¯ïŒããã°ã©ãã³ã°ãåŸæãªããªãã«æäŒã£ãŠãšãé¡ãããããšã«ããïŒ<br>
æ¹åã®æŽå²ãšè³æãäœããã幎床ãäžããããã®ã§ãã®å¹ŽåºŠã®æ ¡èã®ååãåºåããããã°ã©ãã³ã°ãæžããŠããããïŒ
</p>
<h2>å
¥å圢åŒ</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ
</p><pre><var>N</var> <var>Q</var>
<var>year<sub>1</sub></var> <var>name<sub>1</sub></var>
<var>year<sub>2</sub></var> <var>name<sub>2</sub></var>
<var>âŠ</var>
<var>year<sub>N</sub></var> <var>name<sub>N</sub></var>
</pre>
<p>
<var>N</var> ã¯å¹³æ2幎床ããå¹³æ50幎床ãŸã§ã«è¡ãããæ¹åãšæ¹åããã幎床ã®çµã®åæ°ã§ããïŒ<var>Q</var> ã¯è³æãäœããã幎床ã衚ãïŒ<br>
<var>year<sub>i</sub></var> ã¯æ¹åãè¡ããã幎床ã§ããïŒ<var>name<sub>i</sub></var> ã¯æ¹åãããååãããããïŒ
</p>
<h2>åºå圢åŒ</h2>
<p>å¹³æ<var>Q</var>å¹ŽåºŠã®æ ¡èã®ååãåºåããïŒ
</p>
<h2>å¶çŽ</h2>
<ul>
<li><var>1 ≤ N < 50</var></li>
<li><var>1 ≤ Q < 50</var></li>
<li><var>2 ≤ year<sub>1</sub> < year<sub>2</sub> < ⊠< year<sub>n</sub> ≤ 50 </var></li>
<li>ãã¹ãŠã® <var>i</var> ã«å¯ŸããŠïŒ<var>name<sub>i</sub></var> ã¯é·ã1以äž30以äžã§å«ãŸããæåã¯è±æ°å('a'-'z', 'A'-'Z', '0'-'9') ã§ããïŒ</li>
<!-- <li><var>âi </var>ïŒ <var>Q</var> â <var>year_i</var> </li> -->
<li>å¹³æå
å¹ŽåºŠã®æ ¡èã®ååã¯ïŒ"kogakubu10gokan" ã§ããïŒ
</li></ul>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>3 12
5 sogo5gokan
10 sogo10gokan
15 sogo15gokan
</pre>
<h3>åºåäŸ 1</h3>
<pre>sogo10gokan
</pre>
<p>
å¹³æ12å¹ŽåºŠã®æ ¡èåãåºåããã°ããïŒ<br>
æ ¡èã¯ïŒå¹³æå
幎床㮠kogakubu10gokan ããå§ãŸãïŒå¹³æ5幎床㫠sogo5gokanïŒ å¹³æ10幎床㫠sogo10gokan ããã³å¹³æ15幎床㫠sogo15gokan ã«æ¹åãããŠããïŒ
</p>
<h3>å
¥åäŸ 2</h3>
<pre>3 10
5 kogakubu11gokan
10 sogo10gokan
15 KyotoUniversityResearchPark
</pre>
<h3>åºåäŸ 2</h3>
<pre>sogo10gokan
</pre>
<p>
å¹³æ10å¹ŽåºŠã®æ ¡èåãåºåããã°ããïŒ<br>
æ ¡èã¯ïŒå¹³æ10幎床㫠sogo10gokan ã«æ¹åãããŠããïŒ
</p>
<h3>å
¥åäŸ 3</h3>
<pre>3 3
5 kogakubu11gokan
10 sogo10gokan
15 KyotoUniversityResearchPark
</pre>
<h3>åºåäŸ 3</h3>
<pre>kogakubu10gokan
</pre>
<p>
å¹³æ3å¹ŽåºŠã®æ ¡èåãåºåããã°ããïŒ<br>
å¹³æå
幎床ããå¹³æ4幎床ãŸã§ã®æ ¡èã®åå㯠"kogakubu10gokan" ã§ããïŒ
</p> |
p00694 |
<h1>
Strange Key
</h1>
<p>
Professor Tsukuba invented a mysterious jewelry box that can be opened
with a special gold key whose shape is very strange. It is composed
of gold bars joined at their ends. Each gold bar
has the same length and is placed parallel to one of the three
orthogonal axes in a three dimensional space,
i.e., x-axis, y-axis and z-axis.</p>
<p>
The locking mechanism of the jewelry box
is truly mysterious, but the shape of the key is known.
To identify the key of the jewelry box, he gave a way to describe
its shape.</p>
<p>
The description
indicates a list of connected paths that completely defines the shape
of the key: the gold bars of the key are arranged along the paths and
joined at their ends.
Except for the first path,
each path must start from an end point of a gold bar on a previously
defined path.
Each path is represented by a sequence of elements, each of which is one
of six symbols (+x, -x, +y, -y, +z and -z) or a positive integer.
Each symbol indicates the direction from an end point to the other end
point of a gold bar along the path. Since each gold bar is
parallel to one of the three orthogonal axes, the 6 symbols are enough to
indicate the direction. Note that a description of a path has
direction but the gold bars themselves have no direction.
</p>
<p>
An end point of a gold bar can have a label, which is a positive integer.
The labeled point may be referred to as the beginnings of other paths.
In a key description, the first occurrence of a positive integer
defines a label of a point and each subsequent occurrence of the same
positive integer indicates the beginning of a new path at the point.
</p>
<p>
An example of a key composed of 13 gold bars is depicted
in Figure 1. </p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_fig1">
<br>
<p>The following sequence of lines</p>
<pre>
19
1 +x 1 +y +z 3 +z
3 +y -z +x +y -z -x +z 2 +z
2 +y
</pre>
<p>
is a description of the key in Figure 1.
Note that newlines have the same role as space characters in the
description, so that <tt>"19 1 +x 1 +y +z 3 +z 3 +y -z +x +y -z -x +z
2 +z 2 +y"</tt> has the same meaning.
</p>
<p>
The meaning of this description is quite simple.
The first integer "19" means the number of
the following elements in this description.
Each element is one of the 6 symbols or a positive integer.
</p>
<p>
The integer "1" at the head of the second line
is a label attached to the starting point of the first path.
Without loss of generality,
it can be assumed that the starting point of the first path is the
origin, i.e., (0,0,0), and that the length of each gold bar is 1.
The next element "+x" indicates that the first gold bar
is parallel to the x-axis,
so that the other end point of the gold bar is at (1,0,0).
These two elements "1" and "+x" indicates
the first path consisting of only one gold bar.
The third element of the second line in the description is the positive
integer "1", meaning that the point with the label "1", i.e., the
origin (0,0,0) is the beginning of a new path.
The following elements "+y", "+z", "3", and "+z" indicate the second
path consisting of three gold bars. Note that this "3" is its first
occurrence so that the point with coordinates (0,1,1) is labeled "3".
The head of the third line "3" indicates
the beginning of the third path and so on.
Consequently, there are four paths by which the shape of the key in
Figure 1 is completely defined.
</p>
<p>
Note that there are various descriptions of the same key since there
are various sets of paths that cover the shape of the key.
For example,
the following sequence of lines</p>
<pre>
19
1 +x 1 +y +z 3 +y -z +x +y -z -x +z 2 +y
3 +z
2 +z
</pre>
<p>
is another description of the key in Figure 1, since
the gold bars are placed in the same way.
</p>
<p>
Furthermore, the key may be turned 90-degrees around
x-axis, y-axis or z-axis several times and may be moved parallelly.
Since any combinations of rotations and parallel moves don't change
the shape of the key, a description of a rotated and moved key also
represent the same shape of the original key. For example, a
sequence</p>
<pre>
17
+y 1 +y -z +x
1 +z +y +x +z +y -x -y 2 -y
2 +z
</pre>
<p>
is a description of a key in Figure 2 that represents the same key
as in Figure 1.
Indeed, they are congruent under a rotation around x-axis and
a parallel move.
</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_fig2">
<p>
Your job is to write a program to
judge whether or not the given two descriptions define the same key.
</p>
<p>
Note that paths may make a cycle.
For example, <tt>"4 +x +y -x -y"</tt> and <tt>"6 1 +x 1 +y +x -y"</tt>
are valid descriptions. However, two or more gold bars must not be placed at the same position.
For example, key descriptions
<tt>"2 +x -x"</tt>
and
<tt>"7 1 +x 1 +y +x -y -x"</tt> are invalid.
</p>
<h2>Input</h2>
<p>
An input data is a list of pairs of key descriptions followed by
a zero that indicates the end of the input.
For <i>p</i> pairs of key descriptions, the input is given in the
following format.
</p>
<ul>
<i>key-description</i><sub>1-a</sub><br>
<i>key-description</i><sub>1-b</sub><br>
<i>key-description</i><sub>2-a</sub><br>
<i>key-description</i><sub>2-b</sub><br>
...<br>
<i>key-description</i><sub><i>p</i>-a</sub><br>
<i>key-description</i><sub><i>p</i>-b</sub><br>
0
</ul>
<p>
Each key description (<i>key-description</i>) has the following format.</p>
<ul>
<I>n</I><tt> </tt>
<I>e</I><sub>1</sub> <tt> </tt> <I>e</I><sub>2</sub> <tt> </tt>
... <tt> </tt>
<I>e</I><sub><I>k</I></sub> <tt> </tt>
... <tt> </tt>
<I>e</I><sub><I>n</I></sub>
</ul>
<p>
The positive integer <I>n</I> indicates the number of the following elements
<I>e</I><sub>1</sub>, ...,
<I>e<sub>n</sub></I> .
They are separated by one or more space characters and/or newlines.
Each element <I>e<sub>k</sub></I> is
one of the six symbols
(<tt>+x</tt>, <tt>-x</tt>, <tt>+y</tt>, <tt>-y</tt>, <tt>+z</tt> and <tt>-z</tt>)
or a positive integer.
</p>
<p>
You can assume that each label is a positive integer that is less than 51,
the number of elements in a single key description is less than 301,
and the number of characters in a line is less than 80.
You can also assume that the given key descriptions are valid and
contain at least one gold bar.
</p>
<h2>Output</h2>
<p>
The number of output lines should be equal to that of
pairs of key descriptions given in the input.
In each line, you should output one of two words "SAME",
when the two key descriptions represent the same key, and
"DIFFERENT", when they are different.
Note that the letters should be in upper case.
</p>
<H2>Sample Input</H2>
<pre>
19
1 +x 1 +y +z 3 +z
3 +y -z +x +y -z -x +z 2 +z
2 +y
19
1 +x 1 +y +z 3 +y -z +x +y -z -x +z 2 +y
3 +z
2 +z
19
1 +x 1 +y +z 3 +z
3 +y -z +x +y -z -x +z 2 +y
2 +z
18
1 -y
1 +y -z +x
1 +z +y +x +z +y -x -y 2 -y
2 +z
3 +x +y +z
3 +y +z -x
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
SAME
SAME
DIFFERENT
</pre>
|
p01986 | <h3>察空ã·ãŒã«ã</h3>
<!-- begin ja only -->
<p>æã¯3xxx幎ïŒå€ªéœç³»å€ã®ææã«é²åºãã人é¡ã¯ïŒå€§éã®éç³ã®é£æ¥ã«ããåºå°ã®è¢«å®³ã§é ãæ©ãŸããŠããïŒåœéå®å®é²è·äŒç€ŸïŒInternational Cosmic Protection CompanyïŒã¯ïŒãã®åé¡ã解決ããããã«æ°ããªå¯Ÿç©ºã·ãŒã«ããéçºããïŒ</p>
<p>é²è·å¯Ÿè±¡ã®åºå°ã¯åããµã€ãºã® <i>N</i> åã®ãŠããããäžçŽç·äžã«çééã§äžŠãã 圢ãããŠããïŒ 1 ãã <i>N</i> ãŸã§ã®çªå·ãé ã«ä»ããããŠããïŒICPCã¯ïŒãããã®ãŠãããã«ïŒåèšã§ <i>M</i> åã®ã·ãŒã«ããèšçœ®ããããšã«ããïŒ<i>i</i> çªç®ã®ã·ãŒã«ããèœå <i>a<sub>i</sub></i> ãæã¡ïŒãŠããã <i>x<sub>i</sub></i> ã«èšçœ®ãããŠãããšããïŒãã®ãšãïŒãããŠããã <i>u</i> ã«ããã匷床ã¯ïŒä»¥äžã®åŒã§è¡šãããïŒ</p>
<blockquote><i>Σ<sub>i=1</sub><sup>M</sup> max(a<sub>i</sub>-(u-x<sub>i</sub>)<sup>2</sup>,0)</i></blockquote>
<p>ã·ãŒã«ãã¯ãŠãããã«ã®ã¿èšçœ®ããããšãã§ãïŒè€æ°ã®ã·ãŒã«ããåããŠãããã«èšçœ®ããããšãã§ããïŒãããŠïŒICPCã«æ¯æãããå ±é
¬ã¯ <i>N</i> åã®ãŠãããã®åŒ·åºŠã®æå°å€ã«æ¯äŸããé¡ãšãªãïŒ</p>
<p>ã·ãŒã«ãã®èœåã¯å
šãŠæ¢ã«æ±ºãŸã£ãŠããïŒäœçœ®ãæåŸã® 1 ã€ä»¥å€ã¯æ±ºå®ããŠããïŒæåŸã® 1 ã€ã®ã·ãŒã«ãã®äœçœ®ã決ããã«ããã£ãŠïŒå ±é
¬ããªãã¹ã倧ãããªãããã«ãããïŒãã®ããã«æåŸã®ã·ãŒã«ãã®äœçœ®ã決ãããšãã®åŒ·åºŠã®æå°å€ãæ±ããïŒ</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>å
¥åã¯æå€§ã§ 30 åã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§è¡šãããïŒ</p>
<blockquote><i>N</i> <i>M</i>
<i>a<sub>1</sub></i> <i>x<sub>1</sub></i>
âŠ
<i>a<sub>M-1</sub></i> <i>x<sub>M-1</sub></i>
<i>a<sub>M</sub></i></blockquote>
<p><i>N</i> ã¯ãŠãããã®åæ°ïŒ<i>M</i> ã¯ã·ãŒã«ãã®åæ°ã衚ãïŒ<i>N</i> ãš <i>M</i> ã¯æŽæ°ã§ããïŒ<i>1 ≤ N ≤ 10<sup>6</sup></i>ïŒ<i>1 ≤ M ≤ 10<sup>5</sup></i>ãæºããïŒç¶ã <i>M</i> è¡ã«ã¯åã·ãŒã«ãã®æ
å ±ãäžããããïŒ<i>a<sub>i</sub></i> ãš <i>x<sub>i</sub></i> ã¯ããããã·ãŒã«ãã®èœåãšäœçœ®ãè¡šãæŽæ°ã§ããïŒ<i>1 ≤ a<sub>i</sub> ≤ 10<sup>9</sup></i>ïŒ<i>1 ≤ x<sub>i</sub> ≤ N</i> ãæºããïŒ<i>M</i> çªç®ã®ã·ãŒã«ãã®äœçœ®ã¯ãŸã 決å®ããŠããªãããïŒå
¥åã§äžããããªãããšã«æ³šæããïŒ</p>
<p>å
¥åã®çµãã㯠2 ã€ã®ãŒããããªãè¡ã§è¡šãããïŒ</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>åããŒã¿ã»ããã«ã€ããŠïŒ<i>M</i> çªç®ã®ã·ãŒã«ãã®èšçœ®äœçœ®ãé©åã«æ±ºãããšãã®ïŒåŒ·åºŠã®æå°å€ã 1 è¡ã«åºåããïŒ</p>
<!-- end ja only -->
<h3>Sample Input</h3><pre>3 3
2 1
2 2
10
10 4
1 1
1 5
1 9
1
5 7
1000000000 1
1000000000 1
1000000000 3
1000000000 3
1000000000 5
1000000000 5
1
10000 11
10934235 560
3155907 1508
10901182 2457
3471816 3590
10087848 4417
16876957 5583
23145027 6540
15162205 7454
1749653 8481
6216466 9554
7198514
701 14
8181 636
4942 273
1706 282
6758 20
7139 148
6055 629
8765 369
5487 95
6111 77
2302 419
9974 699
108 444
1136 495
2443
0 0
</pre><h3>Output for the Sample Input</h3><pre>10
0
5999999960
23574372
985
</pre>
|
p02353 | <H1>RSQ and RUQ</H1>
<p>
Write a program which manipulates a sequence $A$ = {$a_0, a_1, ..., a_{n-1}$} with the following operations:
</p>
<p>
<ul>
<li> $update(s, t, x)$: change $a_s, a_{s+1}, ..., a_t$ to $x$.</li>
<li> $getSum(s, t)$: print the sum of $a_s, a_{s+1}, ..., a_t$.</li>
</ul>
</p>
<p>
Note that the initial values of $a_i ( i = 0, 1, ..., n-1 )$ are 0.
</p>
<h2>Input</h2>
<pre>
$n$ $q$
$query_1$
$query_2$
:
$query_q$
</pre>
<p>
In the first line, $n$ (the number of elements in $A$) and $q$ (the number of queries) are given. Then, $i$-th query $query_i$ is given in the following format:
</p>
</p>
<pre>
0 $s$ $t$ $x$
</pre>
<p>or</p>
<pre>
1 $s$ $t$
</pre>
<p>
The first digit represents the type of the query. '<span>0</span>' denotes $update(s, t, x)$
and '<span>1</span>' denotes $find(s, t)$.
</p>
<h2>Output</h2>
<p>
For each $getSum$ query, print the sum in a line.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 ≤ n ≤ 100000$</li>
<li>$1 ≤ q ≤ 100000$</li>
<li>$0 ≤ s ≤ t < n$</li>
<li>$-1000 ≤ x ≤ 1000$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
6 7
0 1 3 1
0 2 4 -2
1 0 5
1 0 1
0 3 5 3
1 3 4
1 0 5
</pre>
<h2>Sample Output 1</h2>
<pre>
-5
1
6
8
</pre>
|
p02703 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>There are <var>N</var> cities numbered <var>1</var> to <var>N</var>, connected by <var>M</var> railroads.</p>
<p>You are now at City <var>1</var>, with <var>10^{100}</var> gold coins and <var>S</var> silver coins in your pocket.</p>
<p>The <var>i</var>-th railroad connects City <var>U_i</var> and City <var>V_i</var> bidirectionally, and a one-way trip costs <var>A_i</var> silver coins and takes <var>B_i</var> minutes.
You cannot use gold coins to pay the fare.</p>
<p>There is an exchange counter in each city. At the exchange counter in City <var>i</var>, you can get <var>C_i</var> silver coins for <var>1</var> gold coin.
The transaction takes <var>D_i</var> minutes for each gold coin you give.
You can exchange any number of gold coins at each exchange counter.</p>
<p>For each <var>t=2, ..., N</var>, find the minimum time needed to travel from City <var>1</var> to City <var>t</var>. You can ignore the time spent waiting for trains.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>2 \leq N \leq 50</var></li>
<li><var>N-1 \leq M \leq 100</var></li>
<li><var>0 \leq S \leq 10^9</var></li>
<li><var>1 \leq A_i \leq 50</var></li>
<li><var>1 \leq B_i,C_i,D_i \leq 10^9</var></li>
<li><var>1 \leq U_i < V_i \leq N</var></li>
<li>There is no pair <var>i, j(i \neq j)</var> such that <var>(U_i,V_i)=(U_j,V_j)</var>.</li>
<li>Each city <var>t=2,...,N</var> can be reached from City <var>1</var> with some number of railroads.</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>M</var> <var>S</var>
<var>U_1</var> <var>V_1</var> <var>A_1</var> <var>B_1</var>
<var>:</var>
<var>U_M</var> <var>V_M</var> <var>A_M</var> <var>B_M</var>
<var>C_1</var> <var>D_1</var>
<var>:</var>
<var>C_N</var> <var>D_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>For each <var>t=2, ..., N</var> in this order, print a line containing the minimum time needed to travel from City <var>1</var> to City <var>t</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2 1
1 2 1 2
1 3 2 4
1 11
1 2
2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
14
</pre>
<p>The railway network in this input is shown in the figure below.</p>
<p>In this figure, each city is labeled as follows:</p>
<ul>
<li>The first line: the ID number <var>i</var> of the city (<var>i</var> for City <var>i</var>)</li>
<li>The second line: <var>C_i</var> / <var>D_i</var></li>
</ul>
<p>Similarly, each railroad is labeled as follows:</p>
<ul>
<li>The first line: the ID number <var>i</var> of the railroad (<var>i</var> for the <var>i</var>-th railroad in input)</li>
<li>The second line: <var>A_i</var> / <var>B_i</var></li>
</ul>
<p><img alt="Figure" src="https://img.atcoder.jp/ghi/83f6a1d296d017f40372ea1e1d3b26e5.png"/></p>
<p>You can travel from City <var>1</var> to City <var>2</var> in <var>2</var> minutes, as follows:</p>
<ul>
<li>Use the <var>1</var>-st railroad to move from City <var>1</var> to City <var>2</var> in <var>2</var> minutes.</li>
</ul>
<p><br/></p>
<p>You can travel from City <var>1</var> to City <var>3</var> in <var>14</var> minutes, as follows:</p>
<ul>
<li>Use the <var>1</var>-st railroad to move from City <var>1</var> to City <var>2</var> in <var>2</var> minutes.</li>
<li>At the exchange counter in City <var>2</var>, exchange <var>3</var> gold coins for <var>3</var> silver coins in <var>6</var> minutes.</li>
<li>Use the <var>1</var>-st railroad to move from City <var>2</var> to City <var>1</var> in <var>2</var> minutes.</li>
<li>Use the <var>2</var>-nd railroad to move from City <var>1</var> to City <var>3</var> in <var>4</var> minutes.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 4 1
1 2 1 5
1 3 4 4
2 4 2 2
3 4 1 1
3 1
3 1
5 2
6 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
5
7
</pre>
<p>The railway network in this input is shown in the figure below:</p>
<p><img alt="Figure" src="https://img.atcoder.jp/ghi/a081a72c42da7902a30f29f981c368d0.png"/></p>
<p>You can travel from City <var>1</var> to City <var>4</var> in <var>7</var> minutes, as follows:</p>
<ul>
<li>At the exchange counter in City <var>1</var>, exchange <var>2</var> gold coins for <var>6</var> silver coins in <var>2</var> minutes.</li>
<li>Use the <var>2</var>-nd railroad to move from City <var>1</var> to City <var>3</var> in <var>4</var> minutes.</li>
<li>Use the <var>4</var>-th railroad to move from City <var>3</var> to City <var>4</var> in <var>1</var> minutes.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 5 1
1 2 1 1
1 3 2 1
2 4 5 1
3 5 11 1
1 6 50 1
1 10000
1 3000
1 700
1 100
1 1
100 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
9003
14606
16510
16576
</pre>
<p>The railway network in this input is shown in the figure below:</p>
<p><img alt="Figure" src="https://img.atcoder.jp/ghi/c61c66a7977129c9ef86c6770b37acba.png"/></p>
<p>You can travel from City <var>1</var> to City <var>6</var> in <var>16576</var> minutes, as follows:</p>
<ul>
<li>Use the <var>1</var>-st railroad to move from City <var>1</var> to City <var>2</var> in <var>1</var> minute.</li>
<li>At the exchange counter in City <var>2</var>, exchange <var>3</var> gold coins for <var>3</var> silver coins in <var>9000</var> minutes.</li>
<li>Use the <var>1</var>-st railroad to move from City <var>2</var> to City <var>1</var> in <var>1</var> minute.</li>
<li>Use the <var>2</var>-nd railroad to move from City <var>1</var> to City <var>3</var> in <var>1</var> minute.</li>
<li>At the exchange counter in City <var>3</var>, exchange <var>8</var> gold coins for <var>8</var> silver coins in <var>5600</var> minutes.</li>
<li>Use the <var>2</var>-nd railroad to move from City <var>3</var> to City <var>1</var> in <var>1</var> minute.</li>
<li>Use the <var>1</var>-st railroad to move from City <var>1</var> to City <var>2</var> in <var>1</var> minute.</li>
<li>Use the <var>3</var>-rd railroad to move from City <var>2</var> to City <var>4</var> in <var>1</var> minute.</li>
<li>At the exchange counter in City <var>4</var>, exchange <var>19</var> gold coins for <var>19</var> silver coins in <var>1900</var> minutes.</li>
<li>Use the <var>3</var>-rd railroad to move from City <var>4</var> to City <var>2</var> in <var>1</var> minute.</li>
<li>Use the <var>1</var>-st railroad to move from City <var>2</var> to City <var>1</var> in <var>1</var> minute.</li>
<li>Use the <var>2</var>-nd railroad to move from City <var>1</var> to City <var>3</var> in <var>1</var> minute.</li>
<li>Use the <var>4</var>-th railroad to move from City <var>3</var> to City <var>5</var> in <var>1</var> minute.</li>
<li>At the exchange counter in City <var>5</var>, exchange <var>63</var> gold coins for <var>63</var> silver coins in <var>63</var> minutes.</li>
<li>Use the <var>4</var>-th railroad to move from City <var>5</var> to City <var>3</var> in <var>1</var> minute.</li>
<li>Use the <var>2</var>-nd railroad to move from City <var>3</var> to City <var>1</var> in <var>1</var> minute.</li>
<li>Use the <var>5</var>-th railroad to move from City <var>1</var> to City <var>6</var> in <var>1</var> minute.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>4 6 1000000000
1 2 50 1
1 3 50 5
1 4 50 7
2 3 50 2
2 4 50 4
3 4 50 3
10 2
4 4
5 5
7 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>1
3
5
</pre>
<p>The railway network in this input is shown in the figure below:</p>
<p><img alt="Figure" src="https://img.atcoder.jp/ghi/bfbde2d55baea1e0487f80a62ef9b4ab.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>2 1 0
1 2 1 1
1 1000000000
1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>1000000001
</pre>
<p>The railway network in this input is shown in the figure below:</p>
<p><img alt="Figure" src="https://img.atcoder.jp/ghi/16b8d5c94640ed5b38c0863716196890.png"/></p>
<p>You can travel from City <var>1</var> to City <var>2</var> in <var>1000000001</var> minutes, as follows:</p>
<ul>
<li>At the exchange counter in City <var>1</var>, exchange <var>1</var> gold coin for <var>1</var> silver coin in <var>1000000000</var> minutes.</li>
<li>Use the <var>1</var>-st railroad to move from City <var>1</var> to City <var>2</var> in <var>1</var> minute.</li>
</ul></section>
</div>
</span> |
p03811 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> integers written on a blackboard. The <var>i</var>-th integer is <var>A_i</var>.</p>
<p>Takahashi and Aoki will arrange these integers in a row, as follows:</p>
<ul>
<li>First, Takahashi will arrange the integers as he wishes.</li>
<li>Then, Aoki will repeatedly swap two adjacent integers that are coprime, as many times as he wishes.</li>
</ul>
<p>We will assume that Takahashi acts optimally so that the eventual sequence will be lexicographically as small as possible, and we will also assume that Aoki acts optimally so that the eventual sequence will be lexicographically as large as possible.
Find the eventual sequence that will be produced.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ⊠N ⊠2000</var></li>
<li><var>1 ⊠A_i ⊠10^8</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>A_1</var> <var>A_2</var> ⊠<var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the eventual sequence that will be produced, in a line.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
1 2 3 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5 3 2 4 1
</pre>
<p>If Takahashi arranges the given integers in the order <var>(1,2,3,4,5)</var>, they will become <var>(5,3,2,4,1)</var> after Aoki optimally manipulates them.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
2 3 4 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2 4 6 3
</pre></section>
</div>
</span> |
p01085 |
<h2>Entrance Examination</h2>
<p>
The International Competitive Programming College (ICPC) is famous
for its research on competitive programming.
Applicants to the college are required to take its entrance examination.
</p>
<p>
The successful applicants of the examination are chosen as follows.
</p>
<ul>
<li>The score of any successful applicant is higher than that of any unsuccessful applicant.</li>
<li>The number of successful applicants <i>n</i> must be between <i>n</i><sub>min</sub> and <i>n</i><sub>max</sub>, inclusive.
We choose <i>n</i> within the specified range that maximizes the <i>gap.</i>
Here, the <i>gap</i> means the difference between the lowest score of
successful applicants and the highest score of unsuccessful applicants.
</li>
<li> When two or more candidates for <i>n</i> make exactly the same <i>gap,</i>
use the greatest <i>n</i> among them.</li>
</ul>
<p>
Let's see the first couple of examples given in Sample Input below.
In the first example, <i>n</i><sub>min</sub> and <i>n</i><sub>max</sub> are two and four, respectively, and there are five applicants whose scores are 100, 90, 82, 70, and 65.
For <i>n</i> of two, three and four, the gaps will be 8, 12, and 5, respectively.
We must choose three as <i>n</i>, because it maximizes the gap.
</p>
<p>
In the second example, <i>n</i><sub>min</sub> and <i>n</i><sub>max</sub> are two and four, respectively, and there are five applicants whose scores are 100, 90, 80, 75, and 65.
For <i>n</i> of two, three and four, the gap will be 10, 5, and 10,
respectively. Both two and four maximize the gap, and we must choose the
greatest number, four.
</p>
<p>
You are requested to write a program that computes the number of successful applicants that satisfies the conditions.
</p>
<h3>Input</h3>
<p>
The input consists of multiple datasets. Each dataset is formatted as follows.
</p>
<blockquote>
<i>m</i> <i>n</i><sub>min</sub> <i>n</i><sub>max</sub><br>
<i>P</i><sub>1</sub><br>
<i>P</i><sub>2</sub><br>
...<br>
<i>P<sub>m</sub></i><br>
</blockquote>
<p>
The first line of a dataset contains three integers separated by single spaces.
<i>m</i> represents the number of applicants, <i>n</i><sub>min</sub> represents the minimum number of successful applicants, and <i>n</i><sub>max</sub> represents the maximum number of successful applicants.
Each of the following <i>m</i> lines contains an integer
<i>P<sub>i</sub></i>, which represents the score of each applicant.
The scores are listed in descending order.
These numbers satisfy 0 < <i>n</i><sub>min</sub> < <i>n</i><sub>max</sub> < <i>m</i> ≤ 200, 0 ≤ <i>P<sub>i</sub></i> ≤ 10000 (1 ≤ <i>i</i> ≤ <i>m</i>) and <i>P</i><sub><i>n</i><sub>min</sub></sub> > <i>P</i><sub><i>n</i><sub>max</sub>+1</sub>. These ensure that there always exists an <i>n</i> satisfying the conditions.
</p>
<p>
The end of the input is represented by a line containing three zeros separated by single spaces.
</p>
<h3>Output</h3>
<p>
For each dataset, output the number of successful applicants in a line.
</p>
<h3>Sample Input</h3>
<pre>5 2 4
100
90
82
70
65
5 2 4
100
90
80
75
65
3 1 2
5000
4000
3000
4 2 3
10000
10000
8000
8000
4 2 3
10000
10000
10000
8000
5 2 3
100
80
68
60
45
0 0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>3
4
2
2
3
2
</pre> |
p03542 | <span class="lang-en">
<p>Score : <var>1900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Ringo has a tree with <var>N</var> vertices.
The <var>i</var>-th of the <var>N-1</var> edges in this tree connects Vertex <var>A_i</var> and Vertex <var>B_i</var> and has a weight of <var>C_i</var>.
Additionally, Vertex <var>i</var> has a weight of <var>X_i</var>.</p>
<p>Here, we define <var>f(u,v)</var> as the distance between Vertex <var>u</var> and Vertex <var>v</var>, plus <var>X_u + X_v</var>.</p>
<p>We will consider a complete graph <var>G</var> with <var>N</var> vertices.
The cost of its edge that connects Vertex <var>u</var> and Vertex <var>v</var> is <var>f(u,v)</var>.
Find the minimum spanning tree of <var>G</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 200,000</var></li>
<li><var>1 \leq X_i \leq 10^9</var></li>
<li><var>1 \leq A_i,B_i \leq N</var></li>
<li><var>1 \leq C_i \leq 10^9</var></li>
<li>The given graph is a tree.</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>X_1</var> <var>X_2</var> <var>...</var> <var>X_N</var>
<var>A_1</var> <var>B_1</var> <var>C_1</var>
<var>A_2</var> <var>B_2</var> <var>C_2</var>
<var>:</var>
<var>A_{N-1}</var> <var>B_{N-1}</var> <var>C_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the cost of the minimum spanning tree of <var>G</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
1 3 5 1
1 2 1
2 3 2
3 4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>22
</pre>
<p>We connect the following pairs: Vertex <var>1</var> and <var>2</var>, Vertex <var>1</var> and <var>4</var>, Vertex <var>3</var> and <var>4</var>. The costs are <var>5</var>, <var>8</var> and <var>9</var>, respectively, for a total of <var>22</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6
44 23 31 29 32 15
1 2 10
1 3 12
1 4 16
4 5 8
4 6 15
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>359
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
1000000000 1000000000
2 1 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3000000000
</pre></section>
</div>
</span> |
p03112 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Along a road running in an east-west direction, there are <var>A</var> shrines and <var>B</var> temples.
The <var>i</var>-th shrine from the west is located at a distance of <var>s_i</var> meters from the west end of the road, and the <var>i</var>-th temple from the west is located at a distance of <var>t_i</var> meters from the west end of the road.</p>
<p>Answer the following <var>Q</var> queries:</p>
<ul>
<li>Query <var>i</var> (<var>1 \leq i \leq Q</var>): If we start from a point at a distance of <var>x_i</var> meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq A, B \leq 10^5</var></li>
<li><var>1 \leq Q \leq 10^5</var></li>
<li><var>1 \leq s_1 < s_2 < ... < s_A \leq 10^{10}</var></li>
<li><var>1 \leq t_1 < t_2 < ... < t_B \leq 10^{10}</var></li>
<li><var>1 \leq x_i \leq 10^{10}</var></li>
<li><var>s_1, ..., s_A, t_1, ..., t_B, x_1, ..., x_Q</var> are all different.</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>Q</var>
<var>s_1</var>
<var>:</var>
<var>s_A</var>
<var>t_1</var>
<var>:</var>
<var>t_B</var>
<var>x_1</var>
<var>:</var>
<var>x_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>Q</var> lines. The <var>i</var>-th line should contain the answer to the <var>i</var>-th query.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 4
100
600
400
900
1000
150
2000
899
799
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>350
1400
301
399
</pre>
<p>There are two shrines and three temples. The shrines are located at distances of <var>100, 600</var> meters from the west end of the road, and the temples are located at distances of <var>400, 900, 1000</var> meters from the west end of the road.</p>
<ul>
<li>Query <var>1</var>: If we start from a point at a distance of <var>150</var> meters from the west end of the road, the optimal move is first to walk <var>50</var> meters west to visit a shrine, then to walk <var>300</var> meters east to visit a temple.</li>
<li>Query <var>2</var>: If we start from a point at a distance of <var>2000</var> meters from the west end of the road, the optimal move is first to walk <var>1000</var> meters west to visit a temple, then to walk <var>400</var> meters west to visit a shrine. We will pass by another temple on the way, but it is fine.</li>
<li>Query <var>3</var>: If we start from a point at a distance of <var>899</var> meters from the west end of the road, the optimal move is first to walk <var>1</var> meter east to visit a temple, then to walk <var>300</var> meters west to visit a shrine.</li>
<li>Query <var>4</var>: If we start from a point at a distance of <var>799</var> meters from the west end of the road, the optimal move is first to walk <var>199</var> meters west to visit a shrine, then to walk <var>200</var> meters west to visit a temple.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 1 3
1
10000000000
2
9999999999
5000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>10000000000
10000000000
14999999998
</pre>
<p>The road is quite long, and we may need to travel a distance that does not fit into a <var>32</var>-bit integer.</p></section>
</div>
</span> |
p03407 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>An elementary school student Takahashi has come to a variety store.</p>
<p>He has two coins, <var>A</var>-yen and <var>B</var>-yen coins (yen is the currency of Japan), and wants to buy a toy that costs <var>C</var> yen. Can he buy it?</p>
<p>Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All input values are integers.</li>
<li><var>1 \leq A, B \leq 500</var></li>
<li><var>1 \leq C \leq 1000</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>A</var> <var>B</var> <var>C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If Takahashi can buy the toy, 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>50 100 120
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>He has <var>50 + 100 = 150</var> yen, so he can buy the <var>120</var>-yen toy.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>500 100 1000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>He has <var>500 + 100 = 600</var> yen, but he cannot buy the <var>1000</var>-yen toy.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>19 123 143
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre>
<p>There are <var>19</var>-yen and <var>123</var>-yen coins in Takahashi Kingdom, which are rather hard to use.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>19 123 142
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>Yes
</pre></section>
</div>
</span> |
p03057 | <span class="lang-en">
<p>Score : <var>1500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Consider a circle whose perimeter is divided by <var>N</var> points into <var>N</var> arcs of equal length, and each of the arcs is painted red or blue. Such a circle is said to <em>generate a string <var>S</var> from every point</em> when the following condition is satisfied:</p>
<ul>
<li>We will arbitrarily choose one of the <var>N</var> points on the perimeter and place a piece on it.</li>
<li>Then, we will perform the following move <var>M</var> times: move the piece clockwise or counter-clockwise to an adjacent point.</li>
<li>Here, whatever point we choose initially, it is always possible to move the piece so that the color of the <var>i</var>-th arc the piece goes along is <var>S_i</var>, by properly deciding the directions of the moves.</li>
</ul>
<p>Assume that, if <var>S_i</var> is <code>R</code>, it represents red; if <var>S_i</var> is <code>B</code>, it represents blue.
Note that the directions of the moves can be decided separately for each choice of the initial point.</p>
<p>You are given a string <var>S</var> of length <var>M</var> consisting of <code>R</code> and <code>B</code>.
Out of the <var>2^N</var> ways to paint each of the arcs red or blue in a circle whose perimeter is divided into <var>N</var> arcs of equal length, find the number of ways resulting in a circle that generates <var>S</var> from every point, modulo <var>10^9+7</var>.</p>
<p>Note that the rotations of the same coloring are also distinguished.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 2 \times 10^5</var></li>
<li><var>1 \leq M \leq 2 \times 10^5</var></li>
<li><var>|S|=M</var></li>
<li><var>S_i</var> is <code>R</code> or <code>B</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>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways to paint each of the arcs that satisfy the condition, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 7
RBRRBRR
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>The condition is satisfied only if the arcs are alternately painted red and blue, so the answer here is <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3
BBB
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>12 10
RRRRBRRRRB
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>78
</pre></section>
</div>
</span> |
p01590 |
<H1><font color="#000">Problem K:</font> Trading Ship</H1>
<p>
You are on board a trading ship as a crew.
</p>
<p>
The ship is now going to pass through a strait notorious for many pirates often robbing ships. The Maritime Police has attempted to expel those pirates many times, but failed their attempts as the pirates are fairly strong. For this reason, every ship passing through the strait needs to defend themselves from the pirates.
</p>
<p>
The navigator has obtained a sea map on which the location of every hideout of pirates is shown. The strait is considered to be a rectangle of W × H on an xy-plane, where the two opposite corners have the coordinates of (0, 0) and (<i>W</i>, <i>H</i>). The ship is going to enter and exit the strait at arbitrary points on <i>y</i> = 0 and <i>y</i> = <i>H</i> respectively.
</p>
<p>
To minimize the risk of attack, the navigator has decided to take a route as distant from the hideouts as possible. As a talented programmer, you are asked by the navigator to write a program that finds the best route, that is, the route with the maximum possible distance to the closest hideouts. For simplicity, your program just needs to report the distance in this problem.
</p>
<H2>Input</H2>
<p>
The input begins with a line containing three integers <i>W</i>, <i>H</i>, and <i>N</i>. Here, <i>N</i> indicates the number of hideouts on the strait. Then <i>N</i> lines follow, each of which contains two integers <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i>, which denote the coordinates the <i>i</i>-th hideout is located on.
</p>
<p>
The input satisfies the following conditions: 1 ≤ <i>W</i>, <i>H</i> ≤ 10<sup>9</sup>, 1 ≤ <i>N</i> ≤ 500, 0 ≤ <i>x<sub>i</sub></i> ≤ <i>W</i>, 0 ≤ <i>y<sub>i</sub></i> ≤ <i>H</i>.
</p>
<H2>Output</H2>
<!--
<p>
There should be a line containing the distance from the best route to the closest hideout(s). The distance should be printed with three fractional digits and should not contain an absolute error greater than 10<sup>-3</sup>.
</p>
-->
<p>
There should be a line containing the distance from the best route to the closest hideout(s). The distance should be in a decimal fraction and should not contain an absolute error greater than 10<sup>-3</sup>.
</p>
<H2>Sample Input and Output</H2>
<H2>Input #1</H2>
<pre>
10 10 1
3 5
</pre>
<H2>Output #1</H2>
<pre>
7.000
</pre>
<br/>
<H2>Input #2</H2>
<pre>
10 10 2
2 2
8 8
</pre>
<H2>Output #2</H2>
<pre>
4.243
</pre>
<br/>
<H2>Input #3</H2>
<pre>
10 10 3
0 1
4 4
8 1
</pre>
<H2>Output #3</H2>
<pre>
2.500
</pre> |
p02216 | <span class="lang">
<span class="lang-ja">
<h1>E: æ°åã²ãŒã </h1>
<div class="part">
<section>
<h3>å顿</h3><p>é·ã $N$ ã®æ£æŽæ°å $a_1, a_2, \ldots, a_N$ ããããŸãã</p>
<p>ãã®æ°åãçšããã$2$ 人ã®ãã¬ã€ã€ãŒãå
æãšåŸæã«åãããŠè¡ã以äžã®ã²ãŒã ãèããŸãã</p>
<ul>
<li>å
æãšåŸæã¯äº€äºã«ã以äžã®æäœã®ã©ã¡ãããéžãã§è¡ãã<ul>
<li>æ°åã®æ£ã®é
ã $1$ ã€éžã³ããã®å€ã $1$ æžããã</li>
<li>æ°åã®å
šãŠã®é
ãæ£ã®ãšããå
šãŠã®é
ã®å€ã $1$ ãã€æžããã</li>
</ul>
</li>
</ul>
<p>å
ã«æäœãè¡ããªããªã£ãã»ããè² ãã§ãã</p>
<p>$2$ 人ã®ãã¬ã€ã€ãŒãæé©ã«è¡åãããšããå
æãšåŸæã©ã¡ããåã€ããæ±ããŠãã ããã</p>
</section>
</div>
<div class="part">
<section>
<h3>å¶çŽ</h3><ul>
<li>$1 \leq N \leq 2 \times 10^5$</li>
<li>$1 \leq a_i \leq 10^9$</li>
<li>å
¥åã¯å
šãп޿°ã§ãã</li>
</ul>
</section>
</div>
<hr />
<div class="io-style">
<div class="part">
<section>
<h3>å
¥å</h3><p>å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã</p>
<pre>$N$
$a_1$ $a_2$ $...$ $a_N$
</pre>
</section>
</div>
<div class="part">
<section>
<h3>åºå</h3><p>å
æãåã€ãšã㯠<code>First</code> ããåŸæãåã€ãšã㯠<code>Second</code> ãåºåããã</p>
</section>
</div>
</div>
<hr />
<div class="part">
<section>
<h3>å
¥åäŸ 1</h3><pre>2
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>åºåäŸ 1</h3><pre>First
</pre>
<p>å
æãæåã«ç¬¬ $1$ é
ã®å€ã $1$ æžãããšã次ã«åŸæã¯ç¬¬ $2$ é
ã®å€ã $1$ æžãããããããŸããã</p>
<p>ãã®ããšã§å
æã第 $2$ é
ã®å€ã $1$ æžãããšãæ°åã®å
šãŠã®é
ã®å€ã¯ $0$ ã«ãªãã
åŸæã¯æäœãè¡ãããšãã§ããªããªããŸãã</p>
</section>
</div>
<hr />
<div class="part">
<section>
<h3>å
¥åäŸ 2</h3><pre>5
3 1 4 1 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>åºåäŸ 2</h3><pre>Second
</pre>
</section>
</div>
<hr />
<div class="part">
<section>
<h3>å
¥åäŸ 3</h3><pre>8
2 4 8 16 32 64 128 256
</pre>
</section>
</div>
<div class="part">
<section>
<h3>åºåäŸ 3</h3><pre>Second
</pre>
</section>
</div>
<hr />
<div class="part">
<section>
<h3>å
¥åäŸ 4</h3><pre>3
999999999 1000000000 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>åºåäŸ 4</h3><pre>First
</pre></section>
</div>
</span>
</span>
|
p02646 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate <var>A</var>, and he can travel the distance of <var>V</var> per second.
The other child is now at coordinate <var>B</var>, and she can travel the distance of <var>W</var> per second.</p>
<p>He can catch her when his coordinate is the same as hers.
Determine whether he can catch her within <var>T</var> seconds (including exactly <var>T</var> seconds later).
We assume that both children move optimally.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>-10^9 \leq A,B \leq 10^9</var></li>
<li><var>1 \leq V,W \leq 10^9</var></li>
<li><var>1 \leq T \leq 10^9</var></li>
<li><var>A \neq B</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>V</var>
<var>B</var> <var>W</var>
<var>T</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If "it" can catch the other child, print <code>YES</code>; otherwise, print <code>NO</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 2
3 1
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 2
3 2
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 2
3 3
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>NO
</pre></section>
</div>
</span> |
p03954 | <span class="lang-en">
<p>Score : <var>1300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a pyramid with <var>N</var> steps, built with blocks.
The steps are numbered <var>1</var> through <var>N</var> from top to bottom.
For each <var>1â€iâ€N</var>, step <var>i</var> consists of <var>2i-1</var> blocks aligned horizontally.
The pyramid is built so that the blocks at the centers of the steps are aligned vertically.</p>
<div style="text-align: center;">
<img src="https://atcoder.jp/img/agc006/a2bde72df5ad036d1699f4a74d74a370.png">
<p>A pyramid with <var>N=4</var> steps</p>
</img></div>
<p>Snuke wrote a permutation of (<var>1</var>, <var>2</var>, <var>...</var>, <var>2N-1</var>) into the blocks of step <var>N</var>.
Then, he wrote integers into all remaining blocks, under the following rule:</p>
<ul>
<li>The integer written into a block <var>b</var> must be equal to the median of the three integers written into the three blocks directly under <var>b</var>, or to the lower left or lower right of <var>b</var>.</li>
</ul>
<div style="text-align: center;">
<img src="https://atcoder.jp/img/agc006/a940f1d8303f255e1f91d17a5696633f.png">
<p>Writing integers into the blocks</p>
</img></div>
<p>Afterwards, he erased all integers written into the blocks.
Now, he only remembers that the permutation written into the blocks of step <var>N</var> was (<var>a_1</var>, <var>a_2</var>, <var>...</var>, <var>a_{2N-1}</var>).</p>
<p>Find the integer written into the block of step <var>1</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2â€Nâ€10^5</var></li>
<li>(<var>a_1</var>, <var>a_2</var>, <var>...</var>, <var>a_{2N-1}</var>) is a permutation of (<var>1</var>, <var>2</var>, <var>...</var>, <var>2N-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>a_1</var> <var>a_2</var> <var>...</var> <var>a_{2N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the integer written into the block of step <var>1</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
1 6 3 7 4 5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>This case corresponds to the figure in the problem statement.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre></section>
</div>
</span> |
p01969 | <h2>CïŒ AA ã°ã©ã (AA Graph)</h2>
<h3>Problem</h3>
<p>Given a graph as an ASCII Art (AA), please print the length of shortest paths from the vertex <var>s</var> to the vertex <var>t</var>. The AA of the graph satisfies the following constraints.</p>
<p>A vertex is represented by an uppercase alphabet and symbols <code>o</code> in 8 neighbors as follows.</p>
<pre>
ooo
oAo
ooo
</pre>
<p>
Horizontal edges and vertical edges are represented by symbols <code>-</code> and <code>|</code>, respectively.
Lengths of all edges are 1, that is, it do not depends on the number of continuous symbols <code>-</code> or <code>|</code>.
All edges do not cross each other, and all vertices do not overlap and touch each other.
</p>
<p>
For each vertex, outgoing edges are at most 1 for each directions top, bottom, left, and right.
Each edge is connected to a symbol <code>o</code> that is adjacent to an uppercase alphabet in 4 neighbors as follows.
</p>
<pre>
..|..
.ooo.
-oAo-
.ooo.
..|..
</pre>
<p>Therefore, for example, following inputs are not given.</p>
<pre>
..........
.ooo..ooo.
.oAo..oBo.
.ooo--ooo.
..........
</pre>
<p>(Edges do not satisfies the constraint about their position.)</p>
<pre>
oooooo
oAooBo
oooooo
</pre>
<p>(Two vertices are adjacent each other.)</p>
<h3>Input Format</h3>
<pre>
<var>H</var> <var>W</var> <var>s</var> <var>t</var>
<var>a_1</var>
$\vdots$
<var>a_H</var>
</pre>
<ul>
<li> In line 1, two integers <var>H</var> and <var>W</var>, and two characters <var>s</var> and <var>t</var> are given. <var>H</var> and <var>W</var> is the width and height of the AA, respectively. <var>s</var> and <var>t</var> is the start and end vertices, respectively. They are given in separating by en spaces.</li>
<li> In line <var>1 + i</var> where <var>1 \leq i \leq H</var>, the string representing line <var>i</var> of the AA is given.</li>
</ul>
<h3>Constraints</h3>
<ul>
<li> <var>3 \leq H, W \leq 50</var></li>
<li> <var>s</var> and <var>t</var> are selected by uppercase alphabets from <code>A</code> to <code>Z</code>, and <var>s \neq t</var>.</li>
<li> <var>a_i</var> (<var>1 \leq i \leq H</var>) consists of uppercase alphabets and symbols <code>o</code>, <code>-</code>, <code>|</code>, and <code>.</code>.</li>
<li> Each uppercase alphabet occurs at most once in the AA.</li>
<li> It is guaranteed that there are two vertices representing <var>s</var> and <var>t</var>.</li>
<li> The AA represents a connected graph.</li>
</ul>
<h3>Output Format</h3>
<p>Print the length of the shortest paths from <var>s</var> to <var>t</var> in one line.</p>
<h3>Example 1</h3>
<pre>
14 16 A L
ooo.....ooo.....
oAo-----oHo.....
ooo.....ooo..ooo
.|.......|...oLo
ooo..ooo.|...ooo
oKo--oYo.|....|.
ooo..ooo.|....|.
.|....|.ooo...|.
.|....|.oGo...|.
.|....|.ooo...|.
.|....|.......|.
ooo..ooo.....ooo
oFo--oXo-----oEo
ooo..ooo.....ooo
</pre>
<h3>Output 1</h3>
<pre>5</pre>
<h3>Exapmple 2</h3>
<pre>
21 17 F L
.................
.....ooo.....ooo.
.....oAo-----oBo.
.....ooo.....ooo.
......|.......|..
.ooo..|..ooo..|..
.oCo..|..oDo.ooo.
.ooo.ooo.ooo.oEo.
..|..oFo..|..ooo.
..|..ooo..|...|..
..|...|...|...|..
..|...|...|...|..
..|...|...|...|..
.ooo.ooo.ooo..|..
.oGo-oHo-oIo..|..
.ooo.ooo.ooo..|..
..|...........|..
.ooo...ooo...ooo.
.oJo---oKo---oLo.
.ooo...ooo...ooo.
.................
</pre>
<h3>Output 2</h3>
<pre>4</pre>
|
p00381 | <h1>Transporter</h1>
<p>
In the year 30XX, an expedition team reached a planet and found a warp machine suggesting the existence of a mysterious supercivilization. When you go through one of its entrance gates, you can instantaneously move to the exit irrespective of how far away it is. You can move even to the end of the universe at will with this technology!
</p>
<p>
The scientist team started examining the machine and successfully identified all the planets on which the entrances to the machine were located. Each of these N planets (identified by an index from $1$ to $N$) has an entrance to, and an exit from the warp machine. Each of the entrances and exits has a letter inscribed on it.
</p>
<p>
The mechanism of spatial mobility through the warp machine is as follows:
</p>
<ul>
<li>If you go into an entrance gate labeled with c, then you can exit from any gate with label c.</li>
<li>If you go into an entrance located on the $i$-th planet, then you can exit from any gate located on the $j$-th planet where $i < j$.</li>
</ul>
<p>
Once you have reached an exit of the warp machine on a planet, you can continue your journey by entering into the warp machine on the same planet. In this way, you can reach a faraway planet. Our human race has decided to dispatch an expedition to the star $N$, starting from Star $1$ and using the warp machine until it reaches Star $N$. To evaluate the possibility of successfully reaching the destination. it is highly desirable for us to know how many different routes are available for the expedition team to track.
</p>
<p>
Given information regarding the stars, make a program to enumerate the passages from Star $1$ to Star $N$.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$N$
$s$
$t$
</pre>
<p>
The first line provides the number of the stars on which the warp machine is located $N$ ($2 \leq N \leq 100,000$). The second line provides a string $s$ of length $N$, each component of which represents the letter inscribed on the entrance of the machine on the star. By the same token, the third line provides a string $t$ of length $N$ consisting of the letters inscribed on the exit of the machine. Two strings $s$ and $t$ consist all of lower-case alphabetical letters, and the $i$-th letter of these strings corresponds respectively to the entrance and exit of Star $i$ machine.
</p>
<h2>Output</h2>
<p>
Divide the number of possible routes from Star $1$ to Star $N$ obtained above by 1,000,000,007, and output the remainder.
</p>
<h2>Sample Input 1</h2>
<pre>
6
abbaba
baabab
</pre>
<h2>Sample Output 1</h2>
<pre>
5
</pre>
<h2>Sample Input 2</h2>
<pre>
25
neihsokcpuziafoytisrevinu
universityofaizupckoshien
</pre>
<h2>Sample Output 2</h2>
<pre>
4
</pre>
|
p02168 | <h1>Problem G: Double or Increment</h1>
<h2>Problem</h2>
<p>
ããæ¥ãmo3tthiåãštubuannåã¯ãéæ³ã®ãã±ãããšãã¹ã±ããã䜿ã£ãŠã²ãŒã ãããããšã«ããŸããã<br>
ä»ããã« $K$ åã®ãã±ãããããã$1,2, \ldots ,K$ ã®çªå·ãã€ããŠããŸãã<br>
$i$ çªç®ã®ãã±ããã®å®¹é㯠$M_i$ ã§ãæå $N_i$ æã®ãã¹ã±ãããå
¥ã£ãŠããŸãã<br>
mo3tthiåãštubuannåã¯ãmo3tthiåããå§ããŠã以äžã®äžé£ã®æäœã亀äºã«è¡ããŸãã<br>
</p>
<ul>
<li>ãã±ãããäžã€éžã¶ã</li>
<li>以äžã®ããããäžæ¹ã®æäœãäžåºŠã ãè¡ãããã ããæäœã®çµæéžãã ãã±ããã«å
¥ã£ãŠãããã¹ã±ããã®ææ°ããã±ããã®å®¹éãè¶
ããå Žåãæäœãè¡ãããšã¯ã§ããªãã</li>
<ul>
<li>éžãã ãã±ãããæ«ã§ããéæ³ã®åã«ãã£ãŠéžãã ãã±ããã«å
¥ã£ãŠãããã¹ã±ããã®ææ°ã $1$ å¢ããã</li>
<li>éžãã ãã±ãããå©ããéæ³ã®åã«ãã£ãŠéžãã ãã±ããã«å
¥ã£ãŠãããã¹ã±ããã®ææ°ã $2$ åã«ãªãã</li>
</ul>
</ul>
<p>
æäœãè¡ããªããªã£ãæç¹ã§ã²ãŒã ã¯çµäºããæäœãè¡ããªããªã£ã人ãè² ããããã§ãªã人ãåã¡ã«ãªããŸãã<br>
mo3tthiåã®å人ã§ããããªãã¯ãmo3tthiåããäºåã«ãã®ã²ãŒã ã«åãŠããã©ãããå€å®ã§ããªããçžè«ãããŸããã<br>
mo3tthiåã®ããã«ãmo3tthiåããã®ã²ãŒã ã«å¿
ãåã€ããšãã§ãããã©ãããå€å®ããããã°ã©ã ãäœã£ãŠãã ããã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
$K$
$N_1$ $M_1$
$\vdots$
$N_K$ $M_K$
</pre>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>$1 \leq K \leq 10^5$</li>
<li>$1 \leq N_i \leq M_i \leq 10^{18}$</li>
<li>å
¥åã¯å
šãп޿°ã§ãã</li>
</ul>
<h2>Output</h2>
<p>
mo3tthiåãæé©ã«è¡åãããšããå¿
ãåã€ããšãã§ãããªã"mo3tthi"ããããã§ãªããªã"tubuann"ãäžè¡ã«åºåããã<br>
</p>
<h2>Sample Input 1</h2>
<pre>
1
2 4
</pre>
<h2>Sample Output 1</h2>
<pre>
mo3tthi
</pre>
<p>
mo3tthiåãäžçªç®ã®ãã±ãããå©ããšãäžçªç®ã®ãã±ããã«å
¥ã£ãŠãããã¹ã±ããã®ææ°ã $4$ ã«ãªããtubuannåã¯æäœãè¡ãããšãã§ããªãã
</p>
<h2>Sample Input 2</h2>
<pre>
2
2 3
3 8
</pre>
<h2>Sample Output 2</h2>
<pre>
tubuann
</pre>
<h2>Sample Input 3</h2>
<pre>
10
2 8
5 9
7 20
8 41
23 48
90 112
4 5
7 7
2344 8923
1 29
</pre>
<h2>Sample Output 3</h2>
<pre>
mo3tthi
</pre>
|
p00155 |
<H1>ã¹ãã€ããŒäºº</H1>
<p>
æ£çŸ©ã®ããŒããŒãã¹ãã€ããŒäººãã¯ãè
ããããŒããåºããŠãã«ãããã«ãžé£ã³ç§»ãããšãã§ããŸããããããããŒããçãã®ã§èªåããã®è·é¢ã 50 以äžã®ãã«ã«ããç§»åã§ããŸãããããããé ãã®ãã«ã«ç§»åããã«ã¯ãäžæŠå¥ã®ãã«ã«é£ã³ç§»ããªããŠã¯ãªããŸããã
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_spider">
</center>
<br><br>
<p>
ãã«ã®æ° <var>n</var>ã<var>n</var> åã®ãã«ã®æ
å ±ãã¹ãã€ããŒäººã®ç§»åéå§äœçœ®åã³ç®çå°ãå
¥åãšãããã®ç§»åã®æççµè·¯ãåºåããããã°ã©ã ãäœæããŠãã ãããã©ã®ããã«ãã«ãçµç±ããŠãç®æšã®ãã«ã«ç§»åã§ããªãå Žå㯠NA ãšåºåããŠãã ãããåãã«ã¯ç¹ãšããŠæ±ããæçè·é¢ã§ç§»åãããã«ã®çµç±æ¹æ³ãïŒã€ä»¥äžååšããããšã¯ãªããã®ãšããŸãã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã
åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var>
<var>b<sub>1</sub></var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var>
<var>b<sub>2</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var>
:
<var>b<sub>n</sub></var> <var>x<sub>n</sub></var> <var>y<sub>n</sub></var>
<var>m</var>
<var>s<sub>1</sub></var> <var>g<sub>1</sub></var>
<var>s<sub>2</sub></var> <var>g<sub>2</sub></var>
:
<var>s<sub>m</sub></var> <var>g<sub>m</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ãã«ã®æ° <var>n</var> (1 ≤ <var>n</var> ≤ 100)ãç¶ã <var>n</var> è¡ã« <var>i</var> çªç®ã®ãã«ã®ãã«çªå· <var>b<sub>i</sub></var> (1 ≤ <var>b<sub>i</sub></var> ≤ <var>n</var>)ããã®ãã«ã®x座æšãšy座æšãè¡šãæŽæ° <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> (-1000 ≤ <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> ≤ 1000) ã空çœåºåãã§äžããããŸãã
</p>
<p>
ç¶ãè¡ã«ç§»åæ
å ±ã®åæ° <var>m</var> (1 ≤ <var>m</var> ≤ 100)ãç¶ã <var>m</var> è¡ã«<var>i</var> çªç®ã®ç§»åæ
å ±ãäžããããŸããåç§»åæ
å ±ãšããŠãç§»åãéå§ãããã«ã®çªå· <var>s<sub>i</sub></var> ãšç®çå°ãã«ã®çªå· <var>g<sub>i</sub></var> ã空çœåºåãã§äžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 10 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
å
¥åããŒã¿ã»ããããšã«æ¬¡ã®åœ¢åŒã§åºåããŸãã
</p>
<p>
<var>i</var> è¡ç®ã« <var>i</var> çªç®ã®ç§»åæ
å ±ã«å¯Ÿããçµè·¯ãŸã㯠NA ãïŒè¡ã«åºåããŸããåçµè·¯ã¯ä»¥äžã®åœ¢åŒã§åºåããŸãã
</p>
<pre>
<var>s<sub>i</sub></var> <var>br<sub>i1</sub></var> <var>br<sub>i2</sub></var> ... <var>g<sub>i</sub></var>
</pre>
<p>
<var>br<sub>ij</sub></var> 㯠<var>i</var> çªç®ã®ç§»åæ
å ±ã«ãããã<var>j</var> çªç®ã«çµç±ãããã«ã®çªå·ã衚ããŸãã
</p>
<H2>Sample Input</H2>
<pre>
4
1 0 0
2 30 0
3 60 40
4 0 60
2
1 3
1 4
22
1 0 0
2 150 40
3 30 20
4 180 150
5 40 80
6 130 130
7 72 28
8 172 118
9 50 50
10 160 82
11 90 105
12 144 131
13 130 64
14 80 140
15 38 117
16 190 90
17 60 100
18 100 70
19 130 100
20 71 69
21 200 110
22 120 150
1
1 22
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1 2 3
NA
1 3 9 20 11 6 22
</pre>
|
p02538 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have a string <var>S</var> of length <var>N</var>.
Initially, all characters in <var>S</var> are <code>1</code>s.</p>
<p>You will perform queries <var>Q</var> times.
In the <var>i</var>-th query, you are given two integers <var>L_i, R_i</var> and a character <var>D_i</var> (which is a digit).
Then, you must replace all characters from the <var>L_i</var>-th to the <var>R_i</var>-th (inclusive) with <var>D_i</var>.</p>
<p>After each query, read the string <var>S</var> as a decimal integer, and print its value modulo <var>998,244,353</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N, Q \leq 200,000</var></li>
<li><var>1 \leq L_i \leq R_i \leq N</var></li>
<li><var>1 \leq D_i \leq 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>Q</var>
<var>L_1</var> <var>R_1</var> <var>D_1</var>
<var>:</var>
<var>L_Q</var> <var>R_Q</var> <var>D_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>Q</var> lines.
In the <var>i</var>-th line print the value of <var>S</var> after the <var>i</var>-th query, modulo <var>998,244,353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>8 5
3 6 2
1 4 7
3 8 3
2 2 2
4 5 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>11222211
77772211
77333333
72333333
72311333
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>200000 1
123 456 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>641437905
</pre>
<p>Don't forget to take the modulo.</p></section>
</div>
</span> |
p00505 |
<H1>åé¡1</h2>
<br/>
<p style="line-height: 200%;">
ãäžè§åœ¢ã®åœ¢ã¯èŸºã®é·ãã§æ±ºãŸãïŒ
é çªã«ïŒã€ã®æ£æŽæ°ãäžãããããšãïŒ
蟺ã®é·ãããããã®å€ãšäžèŽããäžè§åœ¢ãååšãããã©ããã調ã¹ïŒ
ååšãããªãéè§äžè§åœ¢ïŒçŽè§äžè§åœ¢ïŒéè§äžè§åœ¢ã®ãããããå€å®ãïŒ
次ã®å
¥åãžé²ãïŒ
äžè§åœ¢ãååšããªããšãïŒ
ãããŸã§ã«å
¥åãããïŒäžè§åœ¢ïŒçŽè§äžè§åœ¢ïŒéè§äžè§åœ¢ïŒéè§äžè§åœ¢ã®
åæ°ã空çœã§åºåã£ãŠåºåãïŒ
ãã以éã®å
¥åã¯ç¡èŠããŠçµäºããïŒ
å
¥åã®äžã«ã¯å¿
ãäžè§åœ¢ãååšããªããããªãã®ããã
ãšä»®å®ããŠãã.
å
¥åã®è¡æ°ã¯å€ããªããåè¡ã«ã¯ïŒã€ã®æ£æŽæ°ã空çœã§åºåã£ãŠæžãããŠããïŒ
ãã ãïŒåæŽæ°ã¯100 以äžãšãã.
</p>
<p style="line-height: 200%;">
<!--ãå
¥åãã¡ã€ã«ã®æ¹è¡ã³ãŒã㯠CR+LF ã§ããïŒ
ãŸãïŒ-->
åºåãã¡ã€ã«ã«ãããŠã¯ïŒ
åºåã®æåŸã®è¡ã«ãæ¹è¡ã³ãŒããå
¥ããããšïŒ
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸïŒ</h3>
<pre>
3 4 5
2 1 2
6 3 4
1 1 1
1 2 3
</pre>
<h3åºåäŸïŒ</h3>
<pre>
4 1 2 1
</pre>
<br>
<h3>å
¥åäŸïŒ</h3>
<pre>
3 4 5
2 1 2
6 3 4
1 2 3
1 1 1
</pre>
<h3>åºåäŸïŒ</h3>
<pre>
3 1 1 1
</pre>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p03283 | <span class="lang-en">
<p>Score: <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>In Takahashi Kingdom, there is a east-west railroad and <var>N</var> cities along it, numbered <var>1</var>, <var>2</var>, <var>3</var>, ..., <var>N</var> from west to east.
A company called <em>AtCoder Express</em> possesses <var>M</var> trains, and the train <var>i</var> runs from City <var>L_i</var> to City <var>R_i</var> (it is possible that <var>L_i = R_i</var>).
Takahashi the king is interested in the following <var>Q</var> matters:</p>
<ul>
<li>The number of the trains that runs <strong>strictly within</strong> the section from City <var>p_i</var> to City <var>q_i</var>, that is, the number of trains <var>j</var> such that <var>p_i \leq L_j</var> and <var>R_j \leq q_i</var>.</li>
</ul>
<p>Although he is genius, this is too much data to process by himself. Find the answer for each of these <var>Q</var> queries to help him.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>N</var> is an integer between <var>1</var> and <var>500</var> (inclusive).</li>
<li><var>M</var> is an integer between <var>1</var> and <var>200 \ 000</var> (inclusive).</li>
<li><var>Q</var> is an integer between <var>1</var> and <var>100 \ 000</var> (inclusive).</li>
<li><var>1 \leq L_i \leq R_i \leq N</var> <var>(1 \leq i \leq M)</var></li>
<li><var>1 \leq p_i \leq q_i \leq N</var> <var>(1 \leq i \leq Q)</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> <var>Q</var>
<var>L_1</var> <var>R_1</var>
<var>L_2</var> <var>R_2</var>
<var>:</var>
<var>L_M</var> <var>R_M</var>
<var>p_1</var> <var>q_1</var>
<var>p_2</var> <var>q_2</var>
<var>:</var>
<var>p_Q</var> <var>q_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print <var>Q</var> lines. The <var>i</var>-th line should contain the number of the trains that runs <strong>strictly within</strong> the section from City <var>p_i</var> to City <var>q_i</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1
1 1
1 2
2 2
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>As all the trains runs within the section from City <var>1</var> to City <var>2</var>, the answer to the only query is <var>3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 3 2
1 5
2 8
7 10
1 7
3 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
1
</pre>
<p>The first query is on the section from City <var>1</var> to <var>7</var>. There is only one train that runs strictly within that section: Train <var>1</var>.
The second query is on the section from City <var>3</var> to <var>10</var>. There is only one train that runs strictly within that section: Train <var>3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 10 10
1 6
2 9
4 5
4 7
4 7
5 8
6 6
6 7
7 9
10 10
1 8
1 9
1 10
2 8
2 9
2 10
3 8
3 9
3 10
1 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>7
9
10
6
8
9
6
7
8
10
</pre></section>
</div>
</span> |
p00856 |
<H1><font color="#000">Problem C:</font> Minimal Backgammon</H1>
<p>
Here is a very simple variation of the game backgammon, named âMinimal Backgammonâ. The game is played by only one player, using only one of the dice and only one checker (the token used by the player).
</p>
<p>
The game board is a line of (<i>N</i> + 1) squares labeled as 0 (the start) to <i>N</i> (the goal). At the beginning, the checker is placed on the start (square 0). The aim of the game is to bring the checker to the goal (square <i>N</i>). The checker proceeds as many squares as the roll of the dice. The dice generates six integers from 1 to 6 with equal probability.
</p>
<p>
The checker should not go beyond the goal. If the roll of the dice would bring the checker beyond the goal, the checker retreats from the goal as many squares as the excess. For example, if the checker is placed at the square (<i>N</i> - 3), the roll "5" brings the checker to the square (<i>N</i> - 2), because the excess beyond the goal is 2. At the next turn, the checker proceeds toward the goal
as usual.
</p>
<p>
Each square, except the start and the goal, may be given one of the following two special instructions.
</p>
<ul>
<li>Lose one turn (labeled "<span>L</span>" in Figure 2) If the checker stops here, you cannot move the checker in the next turn.</li>
<li>
Go back to the start (labeled "<span>B</span>" in Figure 2)<br> If the checker stops here, the checker is brought back to the start.</li>
</ul>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_minimalBackgammon">
<br>
Figure 2: An example game
<br>
</center>
<br>
<p>
Given a game board configuration (the size <i>N</i>, and the placement of the special instructions), you are requested to compute the probability with which the game succeeds within a given number of turns.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets, each containing integers in the following format.
</p>
<pre>
<i>N T L B</i>
<i>Lose</i><sub>1</sub>
...
<i>Lose<sub>L</sub></i>
<i>Back</i><sub>1</sub>
...
<i>Back<sub>B</sub></i>
</pre>
<p>
<i>N</i> is the index of the goal, which satisfies 5 ≤ <i>N</i> ≤ 100. <i>T</i> is the number of turns. You are requested to compute the probability of success within <i>T</i> turns. <i>T</i> satisfies 1 ≤ <i>T</i> ≤ 100. <i>L</i> is the number of squares marked âLose one turnâ, which satisfies 0 ≤ <i>L</i> ≤ <i>N</i> - 1. <i>B</i> is the number of squares marked âGo back to the startâ, which satisfies 0 ≤ <i>B</i> ≤ <i>N</i> - 1. They are separated by a space.
</p>
<p>
<i>Lose<sub>i</sub></i>'s are the indexes of the squares marked âLose one turnâ, which satisfy 1 ≤ <i>Lose<sub>i</sub></i> ≤ <i>N</i> - 1. All <i>Lose<sub>i</sub></i>'s are distinct, and sorted in ascending order. <i>Back<sub>i</sub></i>'s are the indexes of the squares marked âGo back to the startâ, which satisfy 1 ≤ <i>Back<sub>i</sub></i> ≤ <i>N</i> - 1. All <i>Back<sub>i</sub></i>'s are distinct, and sorted in ascending order. No numbers occur both in <i>Lose<sub>i</sub></i>'s and <i>Back<sub>i</sub></i>'s.
</p>
<p>
The end of the input is indicated by a line containing four zeros separated by a space.
</p>
<H2>Output</H2>
<p>
For each dataset, you should answer the probability with which the game succeeds within the
given number of turns. The output should not contain an error greater than 0.00001.
</p>
<H2>Sample Input</H2>
<pre>
6 1 0 0
7 1 0 0
7 2 0 0
6 6 1 1
2
5
7 10 0 6
1
2
3
4
5
6
0 0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0.166667
0.000000
0.166667
0.619642
0.000000
</pre>
|
p01744 |
<p>
<var>w</var> æ¬ã®çžŠæ£ãããªãïŒé«ã(暪æ£ã远å ããããšã®ã§ããæ®µæ°) ã <var>h</var> ã®ãã¿ã ãããããïŒ<var>w</var> ã¯å¶æ°ã§ããïŒãã®ãã¿ã ããã®æšªæ£ã远å ããå Žæã®åè£ã®ãã¡äžãã <var>a</var> çªç®ïŒå·Šãã <var>b</var> çªç®ã <var>(a, b)</var> ãšããïŒ(<var>(a, b)</var> ã«æšªæ£ã远å ããå ŽåïŒäžãã <var>a</var> 段ç®ã§å·Šãã <var>b</var> çªç®ãš <var>b+1</var> çªç®ã®çžŠæ£ãçµã°ããïŒ) ãã®ãããªå Žæã¯åèš <var>h(w −1)</var> ç®æ(1 ≤ <var>a</var> ≤ <var>h</var>, 1 ≤ <var>b</var> ≤ <var>w</var> â 1) ååšããïŒ
</p>
<p>
ãã¬ãåã¯ïŒ<var>a</var> ≡ <var>b</var> (mod 2) ãã¿ããå Žæ <var>(a, b)</var> ã«å
šãŠæšªæ£ã远å ããïŒæ¬¡ã«ïŒãã¬ãåã¯ïŒ<var>(a<sub>1</sub>, b<sub>1</sub>), . . . , (a<sub>n</sub>, b<sub>n</sub>)</var> ã®å Žæã®æšªæ£ãæ¶ããïŒäžç«¯ã§å·Šãã <var>i</var> çªç®ãéžãã ãšãäžç«¯ã§å·Šããäœçªç®ã«ãªããïŒãšããã®ãå
šãŠæ±ããïŒ
</p>
<h2>Constraints</h2>
<ul>
<li> 1 ≤ <var>h, w, n</var> ≤ 200000 </li>
<li> <var>w</var> ã¯å¶æ°</li>
<li> 1 ≤ <var>a<sub>i</sub></var> ≤ <var>h</var></li>
<li> 1 ≤ <var>b<sub>i</sub></var> ≤ <var>w</var> â 1</li>
<li> <var>a<sub>i</sub></var> ≡ <var>b<sub>i</sub></var> (mod 2)</li>
<li> <var>(a<sub>i</sub>, b<sub>i</sub>)</var> = <var>(a<sub>j</sub>, b<sub>j</sub>)</var> ãšãªããããªçžç°ãªã <var>i, j</var> ã¯ååšããªã</li>
</ul>
<h2>Input</h2>
<pre>
<var>h</var> <var>w</var> <var>n</var>
<var>a<sub>1</sub></var> <var>b<sub>1</sub></var>
. . .
<var>a<sub>n</sub></var> <var>b<sub>n</sub></var>
</pre>
<h2>Output</h2>
<p>
<var>w</var> è¡åºåããïŒ<var>i</var> è¡ç®ã«ã¯ïŒäžç«¯ã§å·Šãã <var>i</var> çªç®ãéžãã ãšãäžç«¯ã§å·Šããäœçªç®ã«ãªãããåºåããïŒ
</p>
<h2>Sample Input 1</h2>
<pre>
4 4 1
3 3
</pre>
<h2>Sample Output 1</h2>
<pre>
2
3
4
1
</pre>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummer2014_denseAmidakuji" title="Dense Amidakuji" alt="Dense Amidakuji" width="200">
<p>
å³1: ããšãã°ïŒäžç«¯ã§å·Šç«¯ã®çžŠæ£ãéžã¶ãšïŒ(1, 1), (2, 2), (4, 2) ãéã£ãŠäžç«¯ã§å·Šããäºçªç®ã®çžŠæ£ã«ãã©ãçãïŒ
</p>
<h2>Sample Input 2</h2>
<pre>
10 6 10
10 4
4 4
5 1
4 2
7 3
1 3
2 4
8 2
7 5
7 1
</pre>
<h2>Sample Output 2</h2>
<pre>
1
4
3
2
5
6
</pre> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.