question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p01484 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<h1> Icy Composer</h1>
<p>
Time Limit: 8 sec / Memory Limit: 64 MB
</p>
<h2> F: æ°·ã®äœæ²å®¶</h2>
<p>
岡éšé¬å€ªé(æç§°ãªã«ã¬ã³)ã¯ïŒè¥¿æŽé³æ¥œã®ç¬¬äžäººè
ã§ããïŒ
圌ã¯ïŒ5æ³ããäœæ²ãè¡ãããšãã§ãã倩æã§ããïŒåœŒãäœè©ã»äœæ²ãããæ»åã®æ§ãã¯ãšãŠãæåã§ããïŒ
æèœããµãããªã«ã¬ã³ã ãïŒæ®å¿µãªããšã«ïŒåœŒã¯ïŒã¬ã¹ãã©ã³ã§é£ã¹ãéã«ããã£ãŠäº¡ããªã£ãŠããïŒ
</p>
<p>
ã»ã»ã»å°ãªããšãïŒãã®äžçç·ã§ã¯ïŒããããããšã«ãªã£ãŠããïŒ
äžçç·ãšã¯äœãïŒ
äžã€ã®æŽå²ã¯ïŒäžã€ã®äžçç·ã«å¯Ÿå¿ããïŒ
æã
ãæ©ãã§ããæŽå²ãšã¯ïŒç¡éã«ååšããäžçç·ã®ãã¡ã®äžã€ã«éããïŒ
å¥ã®äžçç·ã§ã¯ïŒãŸãéã£ãæŽå²ãå»ãŸããŠããïŒ
</p>
<p>
ãªã«ã¬ã³ã¯ïŒèªããåŸ
ã¡ãããéé
·ãªæªæ¥ã«ç«ã¡åããããã«ïŒå¥ã®äžçç·ãžãšæ
ç«ã€ããšã決æããã®ã ã£ãïŒ
ãªã«ã¬ã³ãç®æãäžçç·ã¯ïŒãã®æåãªäžçç·ããã£ãã€ã³ãºã²ãŒããã§ããïŒ
ããã£ãã€ã³ãºã²ãŒããã§ã¯ïŒå
šãŠã®éã¯æ°·ã®éæ³ãçšããŠæ°é®®ãªãŸãŸå·åä¿åãããããïŒéã«ããã人ã¯ããªãïŒ
</p>
<p>
äžçç·ã¯ïŒã¢ã«ãã¡ãããã®å°æåãããªãæååã§è¡šãããïŒ
ããã£ãã€ã³ãºã²ãŒããã衚ãæååã¯æ¢ã«è§£æãããŠãããïŒéåžžã«é·ãæååã§è¡šãããïŒ
ãããç°¡æœã«è¡šèšããããïŒæåå <i>seq</i> ã® <i>N</i> åã®ç¹°ãè¿ãã <i>N</i>(<i>seq</i>) ãšå§çž®ããŠè¡šãïŒ
ããã§ïŒ <i>N</i> ã¯ïŒ1以äžã®èªç¶æ°ã§ããïŒ <i>seq</i> ã¯å°æåãããªãæååãïŒå§çž®ããŠè¡šãããæååïŒãŸãã¯ïŒããããããã€ãé£çµããæååã§ããïŒ
</p>
<p>
äŸãã°ïŒä»¥äžã®è¡šèšã¯ïŒæåå bbbababababxbbbababababx ã衚ãïŒ
</p>
<pre>
2(3(b)4(ab)x)
</pre>
<p>
ãªã«ã¬ã³ã¯ïŒåœŒã®ãã€ãéçŒãªãŒãã£ã³ã°ãã£ãã€ããŒãã«ãã£ãŠïŒåœŒãããäžçç·ããæ¬¡ã«ç§»åã§ããäžçç·ãèªã¿ãšãããšãã§ããïŒ
圌ãããäžçç·ã¯ïŒããã£ãã€ã³ãºã²ãŒããããé ãé¢ããŠããããïŒçŽæ¥ããã£ãã€ã³ãºã²ãŒãããžç§»åããããšã¯ã§ããªãïŒ
ãªã«ã¬ã³ã¯ïŒããã£ãã€ã³ãºã²ãŒããã«ã§ããã ãè¿ã¥ãããã«ïŒããã£ãã€ã³ãºã²ãŒããã«å¯Ÿããé¡äŒŒåºŠãé«ãäžçç·ãžãšç§»åããããšã«ããïŒ
</p>
<p>
ããã£ãã€ã³ãºã²ãŒããã衚ãæååã <i>x</i> ïŒããäžçç·ã衚ãæååã<i>y</i>ãšããå ŽåïŒ
<i>x</i>ã«å¯Ÿãã<i>y</i>ã®é¡äŒŒåºŠã¯ïŒ <i>y</i> ã®éšåæååã®ãã¡ïŒ <i>x</i> ã«ãéšåæååãšããŠçŸãããã®ã®æ°ã§ããïŒ
ãã ãïŒ <i>y</i> ã®éšåæååãšããŠåãæååãè€æ°åçŸãããšããŠãïŒãããã¯ïŒå¥ã
ã«æ°ãããã®ãšããïŒ
é¡äŒŒåºŠãåãäžçç·ãè€æ°ããå Žåã¯ïŒå
ã«å
¥åãšããŠäžããããäžçç·ã®æ¹ãé¡äŒŒåºŠãé«ããšã¿ãªããã®ãšããïŒ
</p>
<p>
諞åã«ã¯ïŒäžçç·ããã£ãã€ã³ãºã²ãŒããã衚ãæååãšãªã«ã¬ã³ã次ã«ç§»åã§ããäžçç·ã«å¯Ÿå¿ããæååãè€æ°äžãããããšãã«ïŒããã£ãã€ã³ãºã²ãŒããã«å¯Ÿããé¡äŒŒåºŠãæãé«ãäžçç·ãæ±ããŠãããããïŒ
</p>
<p>
å¥éãç¥ãïŒ<br/>
ãšã«ã»ããµã€ã»ã³ã³ã¬ãªã£ïŒ
</p>
<h2> Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ
</p>
<pre>
<i>n</i> <i>m</i> <i>k</i>
<i>s</i>
<i>t<sub>1</sub></i>
<i>t<sub>2</sub></i>
...
<i>t<sub>k</sub></i>
</pre>
<p>
å
¥å圢åŒã®å倿°ã®æå³ã¯ä»¥äžã®éãã§ããïŒ
</p>
<ul>
<li> <i>n</i> ã¯ãã£ãã€ã³ãºã²ãŒãã衚ãæåå <i>s</i> ã®é·ã (1 <= <i>n</i> <= 250)</li>
<li> <i>m</i> ã¯ãªã«ã¬ã³ãç§»åã§ããäžçç·ã衚ãæååã®é·ã (1 <= <i>m</i> <= 400)</li>
<li> <i>k</i> ã¯ãªã«ã¬ã³ãç§»åã§ããäžçç·ã衚ãæååã®æ° (1 <= <i>k</i> <= 5)</li>
<li> <i>s</i> ã¯ãã£ãã€ã³ãºã²ãŒãã衚ãæåå</li>
<li> <i>t<sub>i</sub></i> ã¯ãªã«ã¬ã³ãç§»åã§ããäžçç·ã衚ãæåå (1 <= <i>i</i> <= <i>k</i>)</li>
</ul>
<h2> Output</h2>
<p>
æåå <i>s</i> ã«æãé¡äŒŒããæåå <i>t<sub>i</sub></i> ã®çªå· <i>i</i> ãšé¡äŒŒåºŠã空çœåºåãã§äžè¡ã§åºåããïŒ
</p>
<h2> Sample Input 1</h2>
<pre>
5 3 2
aaaaa
aaa
aab
</pre>
<h2> Sample Output 1</h2>
<pre>
1 6
</pre>
<h2> Sample Input 2</h2>
<pre>
10 3 3
2(ab)3(bc)
abc
bcb
cbc
</pre>
<h2> Sample Output 2</h2>
<pre>
2 6
</pre>
<h2> Sample Input 3</h2>
<pre>
13 24 1
2(3(b)4(ab)x)
bbbababababxbbbababababx
</pre>
<h2> Sample Output 3</h2>
<pre>
1 300
</pre>
<h2> Sample Input 4</h2>
<pre>
12 7 5
hyadainsgate
hyadain
mahyado
behoimi
megante
moshyas
</pre>
<h2> Sample Output 4</h2>
<pre>
1 28
</pre>
<h2> Sample Input 5</h2>
<pre>
44 6 5
sh1000(1000(1000(1000(ee))))t100(a)paz100(u)
sheeta
pazuuu
romusk
apalou
rlaput
</pre>
<h2> Sample Output 5</h2>
<pre>
2 21
</pre>
</body>
</html> |
p03143 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a connected undirected graph with <var>N</var> vertices and <var>M</var> edges.
The vertices are numbered <var>1</var> to <var>N</var>, and the edges are numbered <var>1</var> to <var>M</var>.
Also, each of these vertices and edges has a specified weight.
Vertex <var>i</var> has a weight of <var>X_i</var>; Edge <var>i</var> has a weight of <var>Y_i</var> and connects Vertex <var>A_i</var> and <var>B_i</var>.</p>
<p>We would like to remove zero or more edges so that the following condition is satisfied:</p>
<ul>
<li>For each edge that is not removed, the sum of the weights of the vertices in the connected component containing that edge, is greater than or equal to the weight of that edge.</li>
</ul>
<p>Find the minimum number of edges that need to be removed.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>N-1 \leq M \leq 10^5</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 Y_i \leq 10^9</var></li>
<li><var>(A_i,B_i) \neq (A_j,B_j)</var> (<var>i \neq j</var>)</li>
<li>The given graph is connected.</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>X_1</var> <var>X_2</var> <var>...</var> <var>X_N</var>
<var>A_1</var> <var>B_1</var> <var>Y_1</var>
<var>A_2</var> <var>B_2</var> <var>Y_2</var>
<var>:</var>
<var>A_M</var> <var>B_M</var> <var>Y_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Find the minimum number of edges that need to be removed.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 4
2 3 5 7
1 2 7
1 3 9
2 3 12
3 4 18
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>Assume that we removed Edge <var>3</var> and <var>4</var>.
In this case, the connected component containing Edge <var>1</var> contains Vertex <var>1, 2</var> and <var>3</var>, and the sum of the weights of these vertices is <var>2+3+5=10</var>.
The weight of Edge <var>1</var> is <var>7</var>, so the condition is satisfied for Edge <var>1</var>.
Similarly, it can be seen that the condition is also satisfied for Edge <var>2</var>.
Thus, a graph satisfying the condition can be obtained by removing two edges.</p>
<p>The condition cannot be satisfied by removing one or less edges, so the answer is <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6 10
4 4 1 1 1 7
3 5 19
2 5 20
4 5 8
1 6 16
2 3 9
3 6 16
3 4 1
2 6 20
2 4 19
1 2 9
</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>10 9
81 16 73 7 2 61 86 38 90 28
6 8 725
3 10 12
1 4 558
4 9 615
5 6 942
8 9 918
2 7 720
4 7 292
7 10 414
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>8
</pre></section>
</div>
</span> |
p03513 | <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> islands floating in Ringo Sea, and <var>M</var> travel agents operate ships between these islands. For convenience, we will call these islands Island <var>1,</var> <var>2,</var> <var>âŠ,</var> <var>N,</var> and call these agents Agent <var>1,</var> <var>2,</var> <var>âŠ,</var> <var>M</var>.</p>
<p>The sea currents in Ringo Sea change significantly each day. Depending on the state of the sea on the day, Agent <var>i</var> <var>(1 †i †M)</var> operates ships from Island <var>a_i</var> to <var>b_i</var>, or Island <var>b_i</var> to <var>a_i</var>, but not both at the same time. Assume that the direction of the ships of each agent is independently selected with equal probability.</p>
<p>Now, Takahashi is on Island <var>1</var>, and Hikuhashi is on Island <var>2</var>. Let <var>P</var> be the probability that Takahashi and Hikuhashi can travel to the same island in the day by ships operated by the <var>M</var> agents, ignoring the factors such as the travel time for ships. Then, <var>P Ã 2^M</var> is an integer. Find <var>P Ã 2^M</var> modulo <var>10^9 + 7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 †N †15</var></li>
<li><var>1 †M †N(N-1)/2</var></li>
<li><var>1 †a_i < b_i †N</var></li>
<li>All pairs <var>(a_i, b_i)</var> are distinct.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>a_1</var> <var>b_1</var>
<var>:</var>
<var>a_M</var> <var>b_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the value <var>P Ã 2^M</var> modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 3
1 3
2 3
3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<div style="text-align: center;">
<img alt="36cba65088d9b1224a6ce9665aa44048.png" src="https://img.atcoder.jp/relay2/36cba65088d9b1224a6ce9665aa44048.png">
</img></div>
<p>The <var>2^M = 8</var> scenarios shown above occur with equal probability, and Takahashi and Hikuhashi can meet on the same island in <var>6</var> of them. Thus, <var>P = 6/2^M</var> and <var>P Ã 2^M = 6</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 5
1 3
2 4
3 4
3 5
4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>18
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 6
1 2
2 3
3 4
4 5
5 6
1 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>64
</pre></section>
</div>
</span> |
p03006 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> balls in a two-dimensional plane. The <var>i</var>-th ball is at coordinates <var>(x_i, y_i)</var>.</p>
<p>We will collect all of these balls, by choosing two integers <var>p</var> and <var>q</var> such that <var>p \neq 0</var> or <var>q \neq 0</var> and then repeating the following operation:</p>
<ul>
<li>Choose a ball remaining in the plane and collect it. Let <var>(a, b)</var> be the coordinates of this ball. If we collected a ball at coordinates <var>(a - p, b - q)</var> in the previous operation, the cost of this operation is <var>0</var>. Otherwise, including when this is the first time to do this operation, the cost of this operation is <var>1</var>.</li>
</ul>
<p>Find the minimum total cost required to collect all the balls when we optimally choose <var>p</var> and <var>q</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 50</var></li>
<li><var>|x_i|, |y_i| \leq 10^9</var></li>
<li>If <var>i \neq j</var>, <var>x_i \neq x_j</var> or <var>y_i \neq y_j</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_1</var> <var>y_1</var>
<var>:</var>
<var>x_N</var> <var>y_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum total cost required to collect all the balls.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
1 1
2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>If we choose <var>p = 1, q = 1</var>, we can collect all the balls at a cost of <var>1</var> by collecting them in the order <var>(1, 1)</var>, <var>(2, 2)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 4
4 6
7 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>If we choose <var>p = -3, q = -2</var>, we can collect all the balls at a cost of <var>1</var> by collecting them in the order <var>(7, 8)</var>, <var>(4, 6)</var>, <var>(1, 4)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4
1 1
1 2
2 1
2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
</pre></section>
</div>
</span> |
p03456 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>AtCoDeer the deer has found two positive integers, <var>a</var> and <var>b</var>.
Determine whether the concatenation of <var>a</var> and <var>b</var> in this order is a square number.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1</var> <var>â€</var> <var>a,b</var> <var>â€</var> <var>100</var></li>
<li><var>a</var> and <var>b</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>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the concatenation of <var>a</var> and <var>b</var> in this order is a square number, 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 21
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>As <var>121</var> <var>=</var> <var>11</var> Ã <var>11</var>, it is a square number.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>100 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p><var>100100</var> is not a square number.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>12 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre></section>
</div>
</span> |
p01191 |
<H1><font color="#000"></font>Grated Radish</H1>
<!-- Problem B-->
<p>
Grated radish (daikon-oroshi) is one of the essential spices in Japanese cuisine. As the name shows, itâs
made by grating white radish.
</p>
<p>
You are developing an automated robot for grating radish. You have finally finished developing mechan-
ical modules that grates radish according to given instructions from the microcomputer. So you need to
develop the software in the microcomputer that controls the mechanical modules. As the first step, you
have decided to write a program that simulates the given instructions and predicts the resulting shape of
the radish.
</p>
<H2>Input</H2>
<p>
The input consists of a number of test cases. The first line on each case contains two floating numbers <i>R</i>
and <i>L</i> (in centimeters), representing the radius and the length of the cylinder-shaped radish, respectively.
The white radish is placed in the <i>xyz</i>-coordinate system in such a way that cylinderâs axis of rotational
symmetry lies on the <i>z</i> axis.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_gratedRadish">
<p>Figure 1: The placement of the white radish</p>
</center>
<p>
The next line contains a single integer <i>N</i>, the number of instructions. The following <i>N</i> lines specify
instructions given to the grating robot. Each instruction consists of two floating numbers <i>θ</i> and <i>V</i>, where
<i>θ</i> is the angle of grating plane in degrees, and <i>V</i> (in cubic centimeters) is the volume of the grated part of
the radish.
</p>
<p>
You may assume the following conditions:
</p>
<ul>
<li> the direction is measured from positive <i>x</i> axis (0 degree) to positive <i>y</i> axis (90 degrees),</li>
<li> 1 ≤ <i>R</i> ≤ 5 (in centimeters),</li>
<li> 1 ≤ <i>L</i> ≤ 40 (in centimeters),</li>
<li> 0 ≤ <i>θ</i> < 360, and</li>
<li> the sum of <i>V</i>âs is the smaller than the volume of the given white radish.</li>
</ul>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_gratedRadish2">
<p>Figure 2: An example of grating</p>
</center>
<H2>Output</H2>
<p>
For each test case, print out in one line two numbers that indicate the shape of the base side (the side
parallel to <i>xy</i>-plane) of the remaining radish after the entire grating procedure is finished, where the first
number of the total length is the linear (straight) part and the second is the total length of the curved part.
</p>
<p>
You may output an arbitrary number of digits after the decimal points, provided that difference from the
true answer is smaller than 10<sup>-6</sup> centimeters.
</p>
<H2>Sample Input</H2>
<pre>
2
1 2
1
42 3.141592653589793
5 20
3
0 307.09242465218927
180 307.09242465218927
90 728.30573874452591
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2.0 3.141592653589793
8.660254038 5.235987756
</pre>
|
p02617 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a tree with <var>N</var> vertices and <var>N-1</var> edges, respectively numbered <var>1, 2,\cdots, N</var> and <var>1, 2, \cdots, N-1</var>. Edge <var>i</var> connects Vertex <var>u_i</var> and <var>v_i</var>.</p>
<p>For integers <var>L, R</var> (<var>1 \leq L \leq R \leq N</var>), let us define a function <var>f(L, R)</var> as follows:</p>
<ul>
<li>Let <var>S</var> be the set of the vertices numbered <var>L</var> through <var>R</var>. <var>f(L, R)</var> represents the number of connected components in the subgraph formed only from the vertex set <var>S</var> and the edges whose endpoints both belong to <var>S</var>.</li>
</ul>
<p>Compute <var>\sum_{L=1}^{N} \sum_{R=L}^{N} f(L, R)</var>.</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 u_i, v_i \leq N</var></li>
<li>The given graph is a tree.</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>u_1</var> <var>v_1</var>
<var>u_2</var> <var>v_2</var>
<var>:</var>
<var>u_{N-1}</var> <var>v_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>\sum_{L=1}^{N} \sum_{R=L}^{N} f(L, R)</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 3
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7
</pre>
<p>We have six possible pairs <var>(L, R)</var> as follows:</p>
<ul>
<li>For <var>L = 1, R = 1</var>, <var>S = \{1\}</var> and we have <var>1</var> connected component.</li>
<li>For <var>L = 1, R = 2</var>, <var>S = \{1, 2\}</var> and we have <var>2</var> connected components.</li>
<li>For <var>L = 1, R = 3</var>, <var>S = \{1, 2, 3\}</var> and we have <var>1</var> connected component, since <var>S</var> contains both endpoints of each of the edges <var>1, 2</var>.</li>
<li>For <var>L = 2, R = 2</var>, <var>S = \{2\}</var> and we have <var>1</var> connected component.</li>
<li>For <var>L = 2, R = 3</var>, <var>S = \{2, 3\}</var> and we have <var>1</var> connected component, since <var>S</var> contains both endpoints of Edge <var>2</var>.</li>
<li>For <var>L = 3, R = 3</var>, <var>S = \{3\}</var> and we have <var>1</var> connected component.</li>
</ul>
<p>The sum of these is <var>7</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
5 3
5 7
8 9
1 9
9 10
8 4
7 4
6 10
7 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>113
</pre></section>
</div>
</span> |
p01938 |
<h2>AïŒ A-Z-</h2>
<h3>åé¡</h3>
<p><var>26</var> ãã¹ã®åç°ç¶ã®ããŒãããããåãã¹ã«ã¯å€§æåã®ã¢ã«ãã¡ããã <var>1</var> æåããã¢ã«ãã¡ãããé ã«æèšåãã«æžãããŠããŸããããªãã¡ã 'A' ã®ãã¹ã®æèšåãé£ã¯ 'B' ã®ãã¹ã§ã 'B' ã®ãã¹ã®é£ã¯ 'C' ã®ãã¹ã§ãã»ã»ã»ã 'Z' ã®ãã¹ã®æèšåãé£ã¯ 'A' ã®ãã¹ã§ãã</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2017Day3_HUPC2017_aizu17-a-01" type="image/png" width="300"></img>
<p>ãŸããããŒãã«ã¯ 'A' ã®ãã¹ã«é§ã <var>1</var> ã€çœ®ãããŠããŸãã</p>
<p>
ããªãã¯ãæåå <var>S</var> ãåãåãã <var>S</var> ã®å
é ãã <var>1</var> æåãã€èŠãŠé§ãæäœããŸãã <var>i</var> åç®ã®æäœã¯ä»¥äžã®ããã«ãªããŸãã
</p>
<ul>
<li>ãã®æç¹ã§é§ã®ãããã¹ãã <var>S</var> ã® <var>i</var> æåç®ã®ã¢ã«ãã¡ãããã®ãã¹ãç®æããŠãé§ãæèšåãã« <var>1</var> ãã¹ãã€ç§»åãããããã®ãšãå°ãªããšã <var>1</var> ãã¹ã¯ç§»åãããšããããããã£ãŠãäŸãã° 'A' ã®ãã¹ãã 'A' ã®ãã¹ã«ç§»åããéã¯ãããŒãã <var>1</var> åšããªããŠã¯ãªããªãã</li>
</ul>
<p>äžèšã®æäœã®çµæãé§ã 'A' ã®ãã¹ãäœåèžãã ããçããŠãã ããããªãã 'A' ã®ãã¹ãèžãããšã¯ã 'Z' ã®ãã¹ãã 'A' ã®ãã¹ã«é§ãé²ããããšãèšããŸãã</p>
<h3>å
¥å圢åŒ</h3>
<p>å
¥å㯠<var>1</var> è¡ã§äžããããã</p>
<pre><var>S</var></pre>
<p><var>S</var> ã¯ããªããåãåãæååã衚ãã</p>
<h3>å¶çŽ</h3>
<ul>
<li> <var>1 \leq |S| \leq 100</var></li>
<li> <var>S</var> ã¯è±å€§æåã®ã¿ã§æ§æãããã</li>
</ul>
<h3>åºå圢åŒ</h3>
<p>'A' ã®ãã¹ãäœåèžãã ãã <var>1</var> è¡ã§åºåããã</p>
<h3>å
¥åäŸ1</h3>
<pre>AIZU</pre>
<h3>åºåäŸ1</h3>
<pre>2</pre>
<ul>
<li>A -> A (ããã§ 1 å)</li>
<li>A -> I (ãããŸã§ 1 å)</li>
<li>I -> Z (ãããŸã§ 1 å)</li>
<li>Z -> U (ãããŸã§ 2 å)</li>
</ul>
<h3>å
¥åäŸ2</h3>
<pre>HOKKAIDO</pre>
<h3>åºåäŸ2</h3>
<pre>4</pre> |
p03905 | <span class="lang-en">
<p>Score : <var>1500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is an undirected connected graph with <var>N</var> vertices numbered <var>1</var> through <var>N</var>.
The lengths of all edges in this graph are <var>1</var>.
It is known that for each <var>i (1âŠiâŠN)</var>, the distance between vertex <var>1</var> and vertex <var>i</var> is <var>A_i</var>, and the distance between vertex <var>2</var> and vertex <var>i</var> is <var>B_i</var>.
Determine whether there exists such a graph.
If it exists, find the minimum possible number of edges in it.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2âŠNâŠ10^5</var></li>
<li><var>0âŠA_i,B_iâŠN-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>B_1</var>
<var>A_2</var> <var>B_2</var>
:
<var>A_N</var> <var>B_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there exists a graph satisfying the conditions, print the minimum possible number of edges in such a graph. Otherwise, print <code>-1</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
0 1
1 0
1 1
2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>The figure below shows two possible graphs. The graph on the right has fewer edges.</p>
<p><img alt="" src="https://atcoder.jp/img/code-festival-2016-final/dd1e04d837fd7fc1be56b231cd8c2a17.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
0 1
1 0
2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>Such a graph does not exist.</p></section>
</div>
</span> |
p02247 |
<H1>Naive String Search</H1>
<p>
Find places where a string <var>P</var> is found within a text <var>T</var>.
Print all indices of <var>T</var> where <var>P</var> found. The indices of <var>T</var> start with 0.
</p>
<H2>Input</H2>
<p>
In the first line, a text <var>T</var> is given. In the second line, a string <var>P</var> is given.
</p>
<H2>output</H2>
<p>
Print an index of <var>T</var> where <var>P</var> found in a line. Print the indices in ascending order.
</p>
<H2>Constraints</H2>
<ul>
<li> 1 ≤ length of <var>T</var> ≤ 1000 </li>
<li> 1 ≤ length of <var>P</var> ≤ 1000 </li>
<li>The input consists of alphabetical characters and digits</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
aabaaa
aa
</pre>
<H2>Sample Output 1</H2>
<pre>
0
3
4
</pre>
<H2>Sample Input 2</H2>
<pre>
xyzz
yz
</pre>
<H2>Sample Output 2</H2>
<pre>
1
</pre>
<H2>Sample Input 3</H2>
<pre>
abc
xyz
</pre>
<H2>Sample Output3</H2>
<pre>
</pre>
<p>
The ouput should be empty.
</p>
|
p00780 |
<H1><font color="#000">Problem A:</font>Goldbach's Conjecture</H1>
<p>
<b>Goldbach's Conjecture:</b> For any even number <i>n</i> greater than or equal to 4, there exists at least one pair of prime numbers <i>p</i><sub>1</sub> and <i>p</i><sub>2</sub> such that <i>n</i> = <i>p</i><sub>1</sub> + <i>p</i><sub>2</sub>.
</p>
<p>
This conjecture has not been proved nor refused yet. No one is sure whether this conjecture actually holds. However, one can find such a pair of prime numbers, if any, for a given even number. The problem here is to write a program that reports the number of all the pairs of prime numbers satisfying the condition in the conjecture for a given even number.
</p>
<p>
A sequence of even numbers is given as input. Corresponding to each number, the program should output the number of pairs mentioned above. Notice that we are intereseted in the number of essentially different pairs and therefore you should not count (<i>p</i><sub>1</sub>, <i>p</i><sub>2</sub>) and (<i>p</i><sub>2</sub>, <i>p</i><sub>1</sub>) separately as two different pairs.
</p>
<H2>Input</H2>
<p>
An integer is given in each input line. You may assume that each integer is even, and is greater than or equal to 4 and less than 2<sup>15</sup>. The end of the input is indicated by a number 0.
</p>
<H2>Output</H2>
<p>
Each output line should contain an integer number. No other characters should appear in the output.
</p>
<H2>Sample Input</H2>
<pre>
6
10
12
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1
2
1
</pre>
|
p01892 |
<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>B: ã€ã«ã£ã㌠/ SNS</h1>
<h2>å顿</h2>
<p>
AOR ã€ã«ã¡ããã¯æè¿å°ãæ©å«ãæªãã
ã©ããããâã€ã«ã£ããŒâã®ãã©ããŒæ°ãšãã©ãã¯ãŒæ°ã®æ¯ãæ°ã«å
¥ããªãããã
ãçŸåšãAOR ã€ã«ã¡ããã®ãã©ããŒæ°ã¯ $A$ 人ããã©ãã¯ãŒæ°ã¯ $B$ 人ã§ãããæ¯ã¯ $A:B$ ã§ããã
</p>
<p>
ããã§ãAOR ã€ã«ã¡ããã¯ãã©ããŒæ°ãšãã©ãã¯ãŒæ°ã®æ¯ãæ°ã«å
¥ã£ãæŽæ°æ¯ã«ãªãããã«ã<b><u>ãã©ããŒæ°</u></b>ã墿žãããããšã«ããã
ãªãæ°ã«å
¥ã£ãæŽæ°æ¯ãšã¯ãæ¯ã«å«ãŸããã©ã¡ãã®å€ã $1$ ä»¥äž $N$ 以äžã®æŽæ°ãšãªãããã«è¡šããæ¯ã§ããã
</p>
<p>
ããããAOR ã€ã«ã¡ããã¯ã§ããã ããã©ããŒæ°ã倿Žããããªãã®ã§ã倿Žåãšã®å·®ã®çµ¶å¯Ÿå€ãã§ããã ãå°ãããããã
AOR ã€ã«ã¡ããã®æ©å«ãè¯ãããããã«ãå°ãªããšããã©ããŒæ°ãããã€å€æŽããå¿
èŠãããããæ±ããããã°ã©ã ãäœæããã
</p>
<h2>å
¥å</h2>
<p>
$A \ B \ N$<br>
</p>
<h2>å
¥åã®å¶çŽ</h2>
<p>
$1 \le A, \ B \le 10^{12}$<br>
$1 \leq N \leq 100 $<br>
</p>
<h2>åºå</h2>
<p>
æ°ã«å
¥ã£ãæŽæ°æ¯ã«ã§ããã$A$ ã®å€åéã®çµ¶å¯Ÿå€ã®æå°å€ãåºåããã
</p>
<h2>ãµã³ãã«</h2>
<h3>ãµã³ãã«å
¥å1</h3>
<pre>
19 30 3
</pre>
<h3>ãµã³ãã«åºå1</h3>
<pre>
1
</pre>
<h3>ãµã³ãã«å
¥å2</h3>
<pre>
3 7 7
</pre>
<h3>ãµã³ãã«åºå2</h3>
<pre>
0
</pre>
<h3>ãµã³ãã«å
¥å3</h3>
<pre>
3 7 1
</pre>
<h3>ãµã³ãã«åºå3</h3>
<pre>
4
</pre>
<h3>ãµã³ãã«å
¥å4</h3>
<pre>
102 30 3
</pre>
<h3>ãµã³ãã«åºå4</h3>
<pre>
12
</pre>
<p>
ãã©ããŒã $12$ 人æžããããšã§ $90:30 \ (=3:1)$ ã«ãªããæ¯ã®å€§ããæ¹ã®æ°åã $3$ 以äžãšãªããŸãã<br>
ãã®ãšããå€åé㯠$12$ ã§ãã
</p>
<h3>ãµã³ãã«å
¥å5</h3>
<pre>
3 4 2
</pre>
<h3>ãµã³ãã«åºå5</h3>
<pre>
1
</pre>
<p>
äžäººãã©ããŒãå€ããš $2:4 \ (=1:2)$ ã«ããã©ããŒãããš $4:4 \ (=1:1)$ ã«ãªããã©ã¡ãã墿žã®çµ¶å¯Ÿå€ã¯ $1$ ã§ãããçãã§ãã
</p>
<h3>ãµã³ãã«å
¥å6</h3>
<pre>
1 100 2
</pre>
<h3>ãµã³ãã«åºå6</h3>
<pre>
49
</pre>
<p>
æäœã§ã $1$ 人ã¯ãã©ããŒããŠããªããã°ãããªãäºã«æ³šæããŠãã ããã
</p> |
p00515 |
<H1>åé¡ 1: å¹³åç¹ (Average Score)
</H1>
<br/>
<h2>åé¡</h2>
<p>
JOI 髿 ¡ã®ææ¥ã«ã¯ïŒå€ªéåïŒæ¬¡éåïŒäžéåïŒåéåïŒè±åããã® 5 人ã®çåŸãåå ããïŒ
</p>
<p>
ãã®ææ¥ã§ã¯ïŒææ«è©Šéšã宿œããïŒææ«è©Šéšã¯ïŒ5 人å
šå¡ãåéšããïŒææ«è©Šéšã®ç¹æ°ã 40 ç¹ä»¥äžã®çåŸã¯ïŒææ«è©Šéšã®ç¹æ°ããã®ãŸãŸæçžŸã«ãªã£ãïŒææ«è©Šéšã®ç¹æ°ã 40 ç¹æªæºã®çåŸã¯å
šå¡ïŒè£ç¿ãåãïŒæçžŸã 40 ç¹ã«ãªã£ãïŒ
</p>
<p>
5 人ã®çåŸã®ææ«è©Šéšã®ç¹æ°ãäžãããããšãïŒ5 äººã®æçžŸã®å¹³åç¹ãèšç®ããããã°ã©ã ãäœæããïŒ
</p>
<h2> å
¥å</h2>
<p>
å
¥å㯠5 è¡ãããªãïŒ1 è¡ã« 1 ã€ãã€æŽæ°ãæžãããŠããïŒ <br>
1 è¡ç®ã«ã¯ 倪éåã®ææ«è©Šéšã®ç¹æ°ãæžãããŠããïŒ <br>
2 è¡ç®ã«ã¯ 次éåã®ææ«è©Šéšã®ç¹æ°ãæžãããŠããïŒ <br>
3 è¡ç®ã«ã¯ äžéåã®ææ«è©Šéšã®ç¹æ°ãæžãããŠããïŒ <br>
4 è¡ç®ã«ã¯ åéåã®ææ«è©Šéšã®ç¹æ°ãæžãããŠããïŒ <br>
5 è¡ç®ã«ã¯ è±åããã®ææ«è©Šéšã®ç¹æ°ãæžãããŠããïŒ <br>
</p>
<p>
çåŸã®ææ«è©Šéšã®ç¹æ°ã¯ãã¹ãŠ 0 ç¹ä»¥äž 100 ç¹ä»¥äžã®æŽæ°ã§ããïŒ <br>
çåŸã®ææ«è©Šéšã®ç¹æ°ã¯ãã¹ãŠ 5 ã®åæ°ã§ããïŒ <br>
5 人ã®çåŸã®æçžŸã®å¹³åç¹ã¯å¿
ãæŽæ°ã«ãªãïŒ
</p>
<h2> åºå</h2>
<p>
5 人ã®çåŸã®æçžŸã®å¹³åç¹ãããããæŽæ°ã 1 è¡ã§åºåããïŒ
</p>
<h2> å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
10
65
100
30
95
</pre>
<h3>åºåäŸ 1</h3>
<pre>
68
</pre>
<p>
å
¥åºåäŸ 1 ã§ã¯ïŒå€ªéåãšåéåã®ææ«è©Šéšã®ç¹æ°ã¯ 40 ç¹æªæºãªã®ã§ïŒå€ªéåãšåéåã®æçžŸã¯ 40 ç¹ã«ãªãïŒæ¬¡éåãšäžéåãšè±åããã®ææ«è©Šéšã®ç¹æ°ã¯ 40 ç¹ä»¥äžãªã®ã§ïŒæ¬¡éåã®æçžŸã¯ 65 ç¹ïŒäžéåã®æçžŸã¯ 100 ç¹ïŒè±åããã®æçžŸã¯ 95 ç¹ãšãªãïŒ5 äººã®æçžŸã®åèšã¯ 340 ãªã®ã§ïŒå¹³åç¹ã¯ 68 ç¹ãšãªãïŒ
</p>
<h3>å
¥åäŸ 2</h3>
<pre>
40
95
0
95
50
</pre>
<h3>åºåäŸ 2</h3>
<pre>
64
</pre>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p02178 | <h1>D: Walking</h1>
<h2>åé¡</h2>
<p>
$1$ ãã $N$ ã®çªå·ãã€ããããŠãã $N$ åã®å³¶ããã.<br>
ããããã®å³¶ã¯ $N-1$ åã®æ©ã«ãã£ãŠãã©ã® $2$ ã€ã®å³¶ãäœæ¬ãã®æ©ãæž¡ã£ãŠäºãã«ç§»åããããšãã§ãã.<br>
ããããã®æ©ã«ã¯èä¹
床ããããå
¥åãäžããããæç¹ã§ã® $i$ çªç®ã®æ©ã®èä¹
床㯠$w_i$ ã§ãã.<br>
ããããã®å³¶ã«ã¯ãå®ã $1$ ã€ãã€çœ®ããŠãããå³¶ã«æ»åšããŠãããšãã«ãå®ãæŸãããšãã§ãã.
</p>
<p>
çŸåšå³¶ $S$ ã«ããyebiããã¯ãå³¶ $E$ ã«ããåç©é€šã«å
šãŠã®ãå®ãéã³ãã.<br>
yebiããã¯âéåâãæã£ãŠããã®ã§ãå³¶ $v$ ã«èšªåãããã³ã«ã $v$ ããåºãå
šãŠã®æ©ã®èä¹
床ã $T$ æžå°ãã.<br>
æ©ã®èä¹
床ã $0$ 以äžã«ãªã£ããšããæ©ã¯åŽ©å£ãããã以éã«ã¯æž¡ãããšãã§ããªããªã.<br>
yebiããã¯åç©é€šã«å
šãŠã®ãå®ãå±ããããšãã§ãããïŒ<br>
ãã ããyebiããã¯åæã¡ãªã®ã§åæã«ããã€ã§ããå®ãæã¡éã¶ããšãã§ãã.<br>
</p>
<h2>å¶çŽ</h2>
<ul>
<li>å
¥åå€ã¯å
šãп޿°ã§ãã</li>
<li>$2 \leq N \leq 10^5$</li>
<li>$1 \leq S, E \leq N$</li>
<li>$0 \leq T \leq 10^9$</li>
<li>$1 \leq w_i \leq 10^9$</li>
<li>$1 \leq a_i, b_i \leq N$</li>
</ul>
<h2>å
¥å圢åŒ</h2>
<p> å
¥åã¯ä»¥äžã®åœ¢åŒã§äžãããã </p>
<p>
$N\ T\ S\ E$<br>
$a_1\ b_1\ w_1$<br>
:<br>
:<br>
$a_{N-1}\ b_{N-1}\ w_{N-1}$
</p>
<h2>åºå</h2>
<p>
åç©é€šã«å
šãŠã®ãå®ãå±ããããšãã§ãããªã "Yes"ãããã§ãªããã° "No" ãåºåãã.<br>
ãŸããæ«å°Ÿã«æ¹è¡ãåºåãã.<br>
</p>
<h2>ãµã³ãã«</h2>
<h3>ãµã³ãã«å
¥å 1</h3>
<pre>
4 10 1 4
1 2 52
1 3 68
3 4 45
</pre>
<h3>ãµã³ãã«åºå 1</h3>
<pre>
Yes
</pre>
<h3>ãµã³ãã«å
¥å 2</h3>
<pre>
4 10 1 4
1 2 15
1 3 60
3 4 10
</pre>
<h3>ãµã³ãã«åºå 2</h3>
<pre>
No
</pre>
<h3>ãµã³ãã«å
¥å 3</h3>
<pre>
3 0 1 3
1 2 5
2 3 5
</pre>
<h3>ãµã³ãã«åºå 3</h3>
<pre>
Yes
</pre>
<P>
yebiããã®éåã¯è²§åŒ±ãããŠãæ©ã®èä¹
åºŠãæžããããšã¯ã§ããªã.
</P>
|
p00145 |
<H1>ã«ãŒã</H1>
<p>
æ£ã®æŽæ°ãæžãããäžçµã®ã«ãŒãããããŸããã«ãŒããç©ãã§å±±ãããã€ãäœããããããæšªäžåã«äžŠã¹ãŸãããã®äžããé£ãåã£ã 2 ã€ã®ã«ãŒãã®å±±ãéžã³ãå³åŽã®å±±ã®äžã«å·ŠåŽã®å±±ããã®ãŸãŸéããŸãããã®æäœãã«ãŒãã®å±±ãäžã€ã«ãªããŸã§ç¹°ãè¿ããŠãããŸãã
</p>
<p>
2 ã€ã®ã«ãŒãã®å±±ãéããæã«ãããã®äžçªäžãšäžã®ã«ãŒãã«æžãããæ°ããã¹ãŠæãåãããŸããããããŠåŸãããæ°ãã«ãŒãã®éãåããã®ã³ã¹ããšåŒã¶ããšã«ããŸããã«ãŒãã®å±±ãäžã€ã«ããããã®ã³ã¹ãã¯ãã¹ãŠã®éãåããã®ã³ã¹ããè¶³ãåããããã®ãšããŸãã
</p>
<p>
ã©ã®ãããªé çªã§ã«ãŒãã®å±±ãéãããã§ã³ã¹ãã¯å€ãããŸããããšãã°ã3 ã€ã®ã«ãŒãã®å±±ãããå ŽåãèããŸãããããã®äžçªäžãšäžã®ã«ãŒãã«æžãããæ°ãïŒå·ŠåŽã®å±±ããé ã«ãããã 3 ãš 5, 2 ãš 8, 5 ãš4 ã ã£ããšããŸãããã®ãšãïŒã¯ããã«å·Šãšçãäžã®å±±ãéãããšãã®ã³ã¹ãã¯ã3 à 5 à 2 à 8 = 240 ã§ãããã®éãåããã«ãã£ãŠãäžçªäžã®ã«ãŒãã 3 ã§äžçªäžã®ã«ãŒãã 8 ã§ããå±±ãã§ããŸãã
</p>
<p>
ãã®å±±ãå³ã®å±±ã®äžã«éãããšããã®ã³ã¹ã㯠3 à 8 à 5 à 4 = 480 ã«ãªããŸãããããã£ãŠããã®é çªã§ã«ãŒãã®å±±ãäžã€ã«ãŸãšãããšãã®ã³ã¹ã㯠240 + 480 = 720 ã§ããïŒå³1ïŒ
</p>
<p>
äžæ¹ãã¯ããã«çãäžãšå³ã®å±±ãéããŠããæåŸã«å·Šã®å±±ãéããããšã«ãããšããã®ãšãã®ã³ã¹ã㯠2 à 8 à 5 à 4 + 3 à 5 à 2 à 4 = 440 ã«ãªããŸãããããã£ãŠïŒåŸã®å Žåã®ããã«éããæ¹ãã³ã¹ããå°ãããªããŸããïŒå³2ïŒ
</p>
<center>
<table border=0>
<tr>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cards1"></td>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cards2"></td>
</tr>
</table>
</center>
<br/>
<p>
ã«ãŒãã®å±±ã®åæ°ãšããããã®å±±ã®äžçªäžãšäžã®ã«ãŒãã«æžãããæ°ãå
¥åãšããã«ãŒãã®å±±ãäžã€ã«ãŸãšããã®ã«å¿
èŠãªæå°ã®ã³ã¹ããåºåããããã°ã©ã ãäœæããŠãã ããããã ããå±±ã®åæ°ã¯ 100 å以äžãšããå
¥åãããããŒã¿ã¯ã©ã®ãããªé çªã§ã³ã¹ããèšç®ããŠã 2<sup>31</sup>-1 ãè¶
ããããšã¯ãããŸããã
</p>
<H2>Input</H2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var>
<var>a<sub>1</sub></var> <var>b<sub>1</sub></var>
<var>a<sub>2</sub></var> <var>b<sub>2</sub></var>
:
<var>a<sub>n</sub></var> <var>b<sub>n</sub></var>
</pre>
<p>
1 è¡ç®ã«ã«ãŒãã®å±±ã®åæ° <var>n</var>(<var>n</var> ≤ 100)ãç¶ã <var>n</var> è¡ã«å·Šãã <var>i</var> çªç®ã®å±±ã® 1 çªäžã®ã«ãŒãã«æžãããæ° <var>a<sub>i</sub></var> (1 ≤ <var>a<sub>i</sub></var> ≤ 200) ãš 1 çªäžã®ã«ãŒãã«æžãããæ° <var>b<sub>i</sub></var> (1 ≤ <var>b<sub>i</sub></var> ≤ 200) ãäžããããŸãã
</p>
<H2>Output</H2>
<p>
ã«ãŒãã®å±±ãäžã€ã«ãŸãšããã®ã«å¿
èŠãªæå°ã®ã³ã¹ããïŒè¡ã«åºåããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
3
3 5
2 8
5 4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
440
</pre>
|
p01304 |
<h1><font color="#000">Problem B:</font> å¹³å®äº¬ãŠã©ãŒãã³ã°</h1>
<p>
å¹³å®äº¬ã¯ãéãæ Œåç¶ã«ãªã£ãŠããçºãšããŠç¥ãããŠããã
</p>
<p>
å¹³å®äº¬ã«äœãã§ããããã®ãã¯ãµã€ã¯ãããããŒã«ã®ããã«æ¯æ¥èªå®
ããçºã¯ããã®ç§å¯ã®å ŽæãŸã§è¡ããªããã°ãªããªããããããæ¯æ¥åãéãéãã®ã¯é£œããããåŸãä»ããããå±éºãããã®ã§ããã¯ãµã€ã¯ã§ããã ãæ¯æ¥ç°ãªãçµè·¯ã䜿ãããããã®äžæ¹ã§ããã¯ãµã€ã¯é¢åèãããªã®ã§ãç®çå°ããé ããããããªéã¯éããããªãã
</p>
<p>
å¹³å®äº¬ã®ãã¡ãã¡ã®éã«ã¯ãã¿ã¿ããèœã¡ãŠããŠããã¯ãµã€ã¯ãã¿ã¿ããèœã¡ãŠããéãéãããšãã§ããªãããã®ãããªéãéããšããããã«ãªã£ãŠããŸãããã§ããã幞ããªããšã«ã亀差ç¹ã«ã¯ãã¿ã¿ãã¯èœã¡ãŠããªãã
</p>
<p>
ãã¯ãµã€ã¯ãèªå®
ããç§å¯ã®å ŽæãŸã§ã®å¯èœãªçµè·¯ã®æ°ãç¥ããããããã§ããã¯ãµã€ã®èªå®
㯠(0, 0) ã«ãããç§å¯ã®å Žæã¯(<var>g</var><sub><var>x</var></sub>, <var>g</var><sub><var>y</var></sub>)ã«ãããé㯠<var>x</var> = <var>i</var> (<var>i</var> ã¯æŽæ°), <var>y</var> = <var>j</var> (<var>j</var> ã¯æŽæ°) ã«æ Œåç¶ã«æ·ãããŠããã
</p>
<h2>Input</h2>
<p>
å
¥åã®1è¡ç®ã«ã¯ãç§å¯ã®å Žæã®åº§æš (<var>g</var><sub><var>x</var></sub>, <var>g</var><sub><var>y</var></sub>) ãäžããããããããã¯ãããã1以äž15以äžã®æŽæ°ã§ã空çœ1åã§åºåãããŠäžããããã 2è¡ç®ã«ã¯ãã¿ã¿ããèœã¡ãŠããåºéã®æ° <var>p</var> (0 ≤ <var>p</var> ≤ 100) ãäžããããç¶ã<var>p</var>è¡ã«ã¯ãã¿ã¿ããèœã¡ãŠããåºéã1è¡ã«1åºéãã€äžããããã <var>p</var>åã®åºéã¯äºãã«ç°ãªãã 1åºé㯠<var>x</var><sub>1</sub> <var>y</var><sub>1</sub> <var>x</var><sub>2</sub> <var>y</var><sub>2</sub> ã®åœ¢ã§è¡šããã(<var>x</var><sub>1</sub>, <var>y</var><sub>1</sub>) ãš (<var>x</var><sub>2</sub>, <var>y</var><sub>2</sub>) ã端ç¹ãšããã<var>x</var>軞ãŸãã¯<var>y</var>軞ã«å¹³è¡ãªé·ã1ã®ç·åã§ããã <var>x</var><sub>1</sub>, <var>x</var><sub>2</sub> 㯠[0, <var>g</var><sub><var>x</var></sub>] ã®ç¯å²ã«ããã<var>y</var><sub>1</sub>, <var>y</var><sub>2</sub> 㯠[0, <var>g</var><sub><var>y</var></sub>] ã®ç¯å²ã«ããã
</p>
<h2>Output</h2>
<p>
å¯èœãªçµè·¯ã®æ°ãåºåãããå¯èœãªçµè·¯ã1ã€ããªãå Žå㯠"Miserable Hokusai!" ãš1è¡ã«åºåããã
</p>
<h2>Notes on Submission</h2>
<p>
äžèšåœ¢åŒã§è€æ°ã®ããŒã¿ã»ãããäžããããŸããå
¥åããŒã¿ã® 1 è¡ç®ã«ããŒã¿ã»ããã®æ°ãäžããããŸããåããŒã¿ã»ããã«å¯Ÿããåºåãäžèšåœ¢åŒã§é çªã«åºåããããã°ã©ã ãäœæããŠäžããã
</p>
<h2>Sample Input</h2>
<pre>
4
2 2
0
1 1
2
0 0 0 1
0 0 1 0
4 3
4
1 0 0 0
3 3 4 3
4 1 4 0
0 2 0 3
15 15
0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
6
Miserable Hokusai!
5
155117520
</pre>
<hr>
|
p03339 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> people standing in a row from west to east.
Each person is facing east or west.
The directions of the people is given as a string <var>S</var> of length <var>N</var>.
The <var>i</var>-th person from the west is facing east if <var>S_i =</var> <code>E</code>, and west if <var>S_i =</var> <code>W</code>.</p>
<p>You will appoint one of the <var>N</var> people as the leader, then command the rest of them to face in the direction of the leader.
Here, we do not care which direction the leader is facing.</p>
<p>The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized.
Find the minimum number of people who have to change their directions.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 3 \times 10^5</var></li>
<li><var>|S| = N</var></li>
<li><var>S_i</var> is <code>E</code> or <code>W</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>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of people who have to change their directions.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
WEEWW
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>Assume that we appoint the third person from the west as the leader.
Then, the first person from the west needs to face east and has to turn around.
The other people do not need to change their directions, so the number of people who have to change their directions is <var>1</var> in this case.
It is not possible to have <var>0</var> people who have to change their directions, so the answer is <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>12
WEWEWEEEWWWE
</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>8
WWWWWEEE
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3
</pre></section>
</div>
</span> |
p03293 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given string <var>S</var> and <var>T</var> consisting of lowercase English letters.</p>
<p>Determine if <var>S</var> equals <var>T</var> after <em>rotation</em>.</p>
<p>That is, determine if <var>S</var> equals <var>T</var> after the following operation is performed some number of times:</p>
<p>Operation: Let <var>S = S_1 S_2 ... S_{|S|}</var>. Change <var>S</var> to <var>S_{|S|} S_1 S_2 ... S_{|S|-1}</var>.</p>
<p>Here, <var>|X|</var> denotes the length of the string <var>X</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq |S| \leq 100</var></li>
<li><var>|S| = |T|</var></li>
<li><var>S</var> and <var>T</var> consist of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
<var>T</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If <var>S</var> equals <var>T</var> after <em>rotation</em>, print <code>Yes</code>; if it does not, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>kyoto
tokyo
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<ul>
<li>In the first operation, <code>kyoto</code> becomes <code>okyot</code>.</li>
<li>In the second operation, <code>okyot</code> becomes <code>tokyo</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>abc
arc
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p><code>abc</code> does not equal <code>arc</code> after any number of operations.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>aaaaaaaaaaaaaaab
aaaaaaaaaaaaaaab
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre></section>
</div>
</span> |
p01754 |
<p>
2014 幎æ¥ïŒããåŠçã¯ç¡äºå€§åŠã«åæ ŒãïŒäžäººæ®ãããå§ããäºãšãªã£ãïŒããã§åé¡ãšãªãã®ãå€é£ãã©ããããã§ããïŒåœŒã¯ãããã <var>N</var> æ¥éã®å€é£ã®èšç»ãç«ãŠãäºã«ããïŒ
</p>
<p>
圌㯠<var>N</var> æ¥éã§åŸããã幞çŠåºŠã®åèšãåºæ¥ãéã倧ãããããïŒãã¡ããïŒçŸå³ãããã®ã奜ããªãã®ãé£ã¹ãã»ã©å¹žçŠåºŠã¯é«ãïŒ
</p>
<p>
圌ã®å€é£ã®éžæè¢ã¯2 ã€ïŒè¿ãã®é£å ã«åãããïŒèªçããããã®ã©ã¡ããã§ããïŒ
</p>
<p>
é£å ã§åŸããã幞çŠåºŠã¯ïŒãã®æ¥ã®ã¡ãã¥ãŒã«ãã£ãŠå€ããïŒã¡ãã¥ãŒã¯æ¥æ¿ããã ãæ¯æ¥äžçš®é¡ã®ã¿ã§ïŒ<var>N</var> æ¥éã®ã¡ãã¥ãŒã¯å
šãŠæ¢ã«å
¬éãããŠããïŒãªã®ã§ïŒåœŒã¯ <var>i</var> æ¥ç® (1 ≤ <var>i</var> ≤ <var>N</var>) ã«é£å ã«è¡ãã° <var>C<sub>i</sub></var> ã®å¹žçŠåºŠãåŸããããšããæ
å ±ãå
šãŠç¥ã£ãŠããïŒ
</p>
<p>
èªçã§åŸããã幞çŠåºŠã¯ïŒãã®èªçã®éå§æç¹ã§ã®<b>èªçãã¯ãŒ</b>ã«å®æ° <var>P</var> ãæãããã®ã§ããïŒ<b>èªçãã¯ãŒ</b>ã¯åæå€ã <var>Q</var> ã§ããïŒæ¯æ¥ïŒé£å ã«è¡ãã°-1ïŒèªçãããã°+1ïŒãã®æ¥ã®é£äºã®çµäºæã«å€åããïŒ
</p>
<p>
圌ã®ããã«å¹žçŠåºŠã®ç·åã®æå€§å€ãæ±ãããïŒ
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§ <var>N + 1</var> è¡ã§äžããããïŒ
</p>
<pre>
<var>N</var> <var>P</var> <var>Q</var>
<var>C<sub>1</sub></var>
<var>C<sub>2</sub></var>
:
<var>C<sub>N</sub></var>
</pre>
<ul>
<li> 1 è¡ç®ã¯ 3 ã€ã®æŽæ° <var>N, P, Q</var> ãäžãããïŒããããæ¥æ°ïŒèªçã®å¹žçŠåºŠãç®åºããããã®å®æ°ïŒèªçãã¯ãŒã®åæå€ã§ããïŒ</li>
<li> 2 è¡ç®ãã <var>N + 1</var> è¡ç®ã«ã¯ããããæŽæ°ã 1 ã€ãã€äžãããïŒ<var>i + 1</var> è¡ç®ã§ã¯ <var>i</var> æ¥ç®ã«é£å ã«è¡ã£ãæã«åŸããã幞çŠåºŠãäžããããïŒ
</li>
</ul>
<h2>Constraints</h2>
<ul>
<li> 1 ≤ <var>N</var> ≤ 500,000 </li>
<li> 0 ≤ <var>P</var> ≤ 500,000</li>
<li> <var>|Q|</var> ≤ 500,000</li>
<li> <var>|C<sub>i</sub>|</var> ≤ 500,000</li>
</ul>
<h2>Output</h2>
<p>
幞çŠåºŠã®åãããæå€§å€ãäžè¡ã«åºåããïŒ
</p>
<h2>Sample Input 1</h2>
<pre>
1 1 1
2
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>
2
</pre>
<ul>
<li> èããã¹ãäºå®ã¯1 æ¥ã ãã§ããïŒé£å ã«è¡ãã°2ïŒèªçãããš1 ã®å¹žçŠåºŠãªã®ã§ïŒçãã¯2 ãšãªãïŒ</li>
</ul>
<h2>Sample Input 2</h2>
<pre>
3 2 1
3
3
3
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>
12
</pre>
<ul>
<li>ãã®ã±ãŒã¹ã§ã¯æ¯æ¥èªçãããã®ãæé©ã§ïŒå¹žçŠåºŠã¯ <var>2 × 1 + 2 × 2 + 2 × 3 = 12</var> ãšãªãïŒ
</li>
</ul>
<h2>Sample Input 3</h2>
<pre>
3 1 -1
2
-3
2
</pre>
<h2>Output for the Sample Input 3</h2>
<pre>
2
</pre>
<ul>
<li> 2 æ¥ç®ã®ã¿ã§èªçãããããšãæåãšãªãïŒ</li>
</ul>
<h2>Sample Input 4</h2>
<pre>
3 1 -10
-10
-10
-10
</pre>
<h2>Output for the Sample Input 4</h2>
<pre>
-27
</pre>
<ul>
<li> çããè² ã«ãªãããšãããïŒããããŸãããŠãå€é£ã¯é£ã¹ãªããã°ãªããªãïŒ</li>
</ul>
|
p03769 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We will call a string <var>x</var> <em>good</em> if it satisfies the following condition:</p>
<ul>
<li>Condition: <var>x</var> can be represented as a concatenation of two copies of another string <var>y</var> of length at least <var>1</var>.</li>
</ul>
<p>For example, <code>aa</code> and <code>bubobubo</code> are good; an empty string, <code>a</code>, <code>abcabcabc</code> and <code>abba</code> are not good.</p>
<p>Eagle and Owl created a puzzle on good strings.
Find one string <var>s</var> that satisfies the following conditions. It can be proved that such a string always exists under the constraints in this problem.</p>
<ul>
<li><var>1 †|s| †200</var></li>
<li>Each character of <var>s</var> is one of the <var>100</var> characters represented by the integers <var>1</var> through <var>100</var>.</li>
<li>Among the <var>2^{|s|}</var> subsequences of <var>s</var>, exactly <var>N</var> are good strings.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N †10^{12}</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>In the first line, print <var>|s|</var>, the length of <var>s</var>.
In the second line, print the elements in <var>s</var> in order, with spaces in between. Any string that satisfies the above conditions will be accepted.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
1 1 1 1
</pre>
<p>There are two good strings that appear as subsequences of <var>s</var>: <var>(1,1)</var> and <var>(1,1,1,1)</var>. There are six occurrences of <var>(1,1)</var> and one occurrence of <var>(1,1,1,1)</var>, for a total of seven.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>299
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>23
32 11 11 73 45 8 11 83 83 8 45 32 32 10 100 73 32 83 45 73 32 11 10
</pre></section>
</div>
</span> |
p00846 |
<H1><font color="#000">Problem B:</font> How I Mathematician Wonder What You Are!</H1>
<p>
After counting so many stars in the sky in his childhood, Isaac, now an astronomer and a
mathematician, uses a big astronomical telescope and lets his image processing program count
stars. The hardest part of the program is to judge if a shining object in the sky is really a star.
As a mathematician, the only way he knows is to apply a mathematical definition of <i>stars</i>.
</p>
<p>
The mathematical defiition of a star shape is as follows: A planar shape <i>F</i> is <i>star-shaped</i> if and
only if there is a point C ∈ <i>F</i> such that, for any point P ∈ <i>F</i>, the line segment CP is contained
in <i>F</i>. Such a point C is called a center of <i>F</i>. To get accustomed to the definition, let's see some
examples below.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_howIMath">
<p>
Figure 2: Star shapes (the first row) and non-star shapes (the second row)
</p>
</center>
<p>
The firrst two are what you would normally call stars. According to the above definition, however,
all shapes in the first row are star-shaped. The two in the second row are not. For each star
shape, a center is indicated with a dot. Note that a star shape in general has infinitely many
centers. For example, for the third quadrangular shape, all points in it are centers.
</p>
<p>
Your job is to write a program that tells whether a given polygonal shape is star-shaped or not.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets followed by a line containing a single zero. Each dataset
specifies a polygon, and is formatted as follows.
</p>
<pre>
<i>n</i>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub>
<i>x</i><sub>2</sub> <i>y</i><sub>2</sub>
...
<i>x</i><sub><i>n</i></sub> <i>y</i><sub><i>n</i></sub>
</pre>
<p>
The first line is the number of vertices, <i>n</i>, which satisfies 4 ≤ <i>n</i> ≤ 50. Subsequent <i>n</i> lines are the <i>x</i>- and <i>y</i>-coordinates of the <i>n</i> vertices. They are integers and satisfy 0 ≤ <i>x<sub>i</sub></i> ≤ 10000 and 0 ≤ <i>y<sub>i</sub></i> ≤ 10000 (<i>i</i> = 1, ..., <i>n</i>). Line segments (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>)-(<i>x</i><sub><i>i</i>+1</sub>, <i>y</i><sub><i>i</i>+1</sub>) (<i>i</i> = 1, ..., <i>n</i> - 1) and the line segment (<i>x<sub>n</sub></i>, <i>y<sub>n</sub></i>)-(<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>) form the border of the polygon in the counterclockwise order. That is, these line segments see the inside of the polygon in the left of their directions.
</p>
<p>
You may assume that the polygon is <i>simple</i>, that is, its border never crosses or touches itself.
You may also assume that no three edges of the polygon meet at a single point even when they
are infinitely extended.
</p>
<H2>Output</H2>
<p>
For each dataset, output "1" if the polygon is star-shaped and "0" otherwise. Each number must be in a separate line and the line should not contain any other characters.
</p>
<H2>Sample Input</H2>
<pre>
6
66 13
96 61
76 98
13 94
4 0
45 68
8
27 21
55 14
93 12
56 95
15 48
38 46
51 65
64 31
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1
0
</pre>
|
p01241 |
<H1><font color="#000">Problem H:</font> Finding the Top RPS Player</H1>
<p>
A company âACM Foodsâ is preparing for opening its chain shop in a certain area, but another company âICPC
Pizzaâ is also planning to set up its branch shop in the same area. In general, two competitive shops gain less
incomes if they are located so close to each other. Thus, if both âACM Foodsâ and âICPC Pizzaâ went on
opening, they would be damaged financially. So, they had a discussion on this matter and made the following
agreement: only one of them can branch its shop in the area. It is determined by Rock-Paper-Scissors (RPS)
which to branch the shop.
</p>
<p>
ACM Foods is facing financial difficulties and strongly desires to open their new shop in that area. The executives
have decided to make every effort for finding out a very strong RPS player. They believes that players who win
consecutive victories must be strong players. In order to find such a player for sure, they have decided their
simple strategy.
</p>
<p>
In this strategy, many players play games of RPS repeatedly, but the games are only played between players with
the same number of consecutive wins. At the beginning, all the players have no wins, so any pair of players
can play a game. The games can be played by an arbitrary number of pairs simultaneously. Let us call a set of
simultaneous games as a <i>turn</i>. After the first turn, some players will have one win, and the other players will
remain with no wins. In the second turn, some games will be played among players with one win, and some
other games among players with no wins. For the former games, the winners will have two <i>consecutive</i> wins,
and the losers will lose their first wins and have no consecutive wins. For the latter games, the winners will have
one win, and the losers will remain with no wins. Therefore, after the second turn, the players will be divided
into three groups: players with two consecutive wins, players with one win, and players with no wins. Again,
in the third turn, games will be played among players with two wins, among with one win, and among with no
wins. The following turns will be conducted so forth. After a sufficient number of turns, there should be a player
with the desired number of consecutive wins.
</p>
<p>
The strategy looks crazy? Oh well, maybe they are confused because of their financial difficulties.
</p>
<p>
Of course, this strategy requires an enormous amount of plays. The executives asked you, as an employee of
ACM Foods, to estimate how long the strategy takes. Your task is to write a program to count the minimum
number of turns required to find a player with <i>M</i> consecutive wins among <i>N</i> players.
</p>
<H2>Input</H2>
<p>
The input consists of multiple test cases. Each test case consists of two integers <i>N</i> (2 ≤ <i>N</i> ≤ 20) and <i>M</i>
(1 ≤ <i>M</i> < <i>N</i>) in one line.
</p>
<p>
The input is terminated by the line containing two zeroes.
</p>
<H2>Output</H2>
<p>
For each test case, your program must output the case number followed by one integer which indicates the
minimum number of turns required to find a person with <i>M</i> consecutive wins.
</p>
<H2>Sample Input</H2>
<pre>
2 1
10 5
15 10
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Case 1: 1
Case 2: 11
Case 3: 210
</pre>
|
p03786 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke found <var>N</var> strange creatures.
Each creature has a fixed color and size. The color and size of the <var>i</var>-th creature are represented by <var>i</var> and <var>A_i</var>, respectively.</p>
<p>Every creature can absorb another creature whose size is at most twice the size of itself.
When a creature of size <var>A</var> and color <var>B</var> absorbs another creature of size <var>C</var> and color <var>D</var> (<var>C \leq 2 \times A</var>), they will merge into one creature of size <var>A+C</var> and color <var>B</var>.
Here, depending on the sizes of two creatures, it is possible that both of them can absorb the other.</p>
<p>Snuke has been watching these creatures merge over and over and ultimately become one creature.
Find the number of the possible colors of this creature.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 100000</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
<li><var>A_i</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> ⊠<var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the possible colors of the last remaining creature after the <var>N</var> creatures repeatedly merge and ultimately become one creature.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
3 1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>The possible colors of the last remaining creature are colors <var>1</var> and <var>3</var>.
For example, when the creature of color <var>3</var> absorbs the creature of color <var>2</var>, then the creature of color <var>1</var> absorbs the creature of color <var>3</var>, the color of the last remaining creature will be color <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
1 1 1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
<p>There may be multiple creatures of the same size.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
40 1 30 2 7 20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
</pre></section>
</div>
</span> |
p04043 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha loves <em>Haiku</em>. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with <var>5</var>, <var>7</var> and <var>5</var> syllables, in this order.</p>
<p>To create a Haiku, Iroha has come up with three different phrases. These phrases have <var>A</var>, <var>B</var> and <var>C</var> syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1âŠA,B,CâŠ10</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>A</var> <var>B</var> <var>C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is possible to construct a Haiku by using each of the phrases once, print <code>YES</code> (case-sensitive). Otherwise, print <code>NO</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 5 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p>Using three phrases of length <var>5</var>, <var>5</var> and <var>7</var>, it is possible to construct a Haiku.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7 7 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre></section>
</div>
</span> |
p02894 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are <var>N</var> points on the circumference of a circle centered at <var>(0,0)</var> in an <var>xy</var>-plane.
The coordinates of the <var>i</var>-th point are <var>(\cos(\frac{2\pi T_i}{L}),\sin(\frac{2\pi T_i}{L}))</var>.</p>
<p>Three distinct points will be chosen uniformly at random from these <var>N</var> points.
Find the expected <var>x</var>- and <var>y</var>-coordinates of the center of the circle inscribed in the triangle formed by the chosen points.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 \leq N \leq 3000</var></li>
<li><var>N \leq L \leq 10^9</var></li>
<li><var>0 \leq T_i \leq L-1</var></li>
<li><var>T_i<T_{i+1}</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>L</var>
<var>T_1</var>
<var>:</var>
<var>T_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the expected <var>x</var>- and <var>y</var>-coordinates of the center of the circle inscribed in the triangle formed by the chosen points.
Your output will be considered correct when the absolute or relative error is at most <var>10^{-9}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4
0
1
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0.414213562373095 -0.000000000000000
</pre>
<p>The three points have the coordinates <var>(1,0)</var>, <var>(0,1)</var>, and <var>(0,-1)</var>. The center of the circle inscribed in the triangle formed by these points is <var>(\sqrt{2}-1,0)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 8
1
3
5
6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-0.229401949926902 -0.153281482438188
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 100
2
11
35
42
54
69
89
91
93
99
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0.352886583546338 -0.109065017701873
</pre></section>
</div>
</span> |
p01611 |
<h2>K-th String</h2>
<h2>Problem Statement</h2>
<p>é·ã<var>N</var>ã®æåå<var>S</var>ã«å¯Ÿããæ¥å°ŸèŸé
å<var>SA</var>ãïŒä»¥äžã®æé ã§åŸããã<var>N</var>以äžã®æ£æŽæ°ã®é åãšããŠå®çŸ©ããïŒ<br />
<var>S</var>ã®<var>i</var>æåç®ãã<var>j</var>æåç®ãŸã§ã®éšåæååã<var>S[i..j]</var>ãšè¡šãïŒãã ãæ·»åã¯1-indexedã§ããïŒ</p>
<ol class="list1" style="padding-left:16px;margin-left:16px"><li>åæ¥å°ŸèŸ<var>S[i..N] (i=1,2,...,N)</var>ãèŸæžåŒé åºïŒæé ïŒã§æŽåããïŒ</li>
<li>æŽåããåæ¥å°ŸèŸã®éå§äœçœ®<var>i</var>ãé ã«äžŠã¹ãïŒ</li></ol>
<p>ããšãã°ïŒ<var>S</var>="mississippi"ã®æ¥å°ŸèŸé
å<var>SA</var>ã¯ïŒä»¥äžã®ããã«ãªãïŒ</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_Rits_Camp13_Day2_K_mississippi">
<br/>
<br/>
<!--
<pre> i | S[i] | SA[i] | S[SA[i]..N-1]
----+------+-------+-----------------
1 | m | 11 | i
2 | i | 8 | ippi
3 | s | 5 | issippi
4 | s | 2 | ississippi
5 | i | 1 | mississippi
6 | s | 10 | pi
7 | s | 9 | ppi
8 | i | 7 | sippi
9 | p | 4 | sissippi
10 | p | 6 | ssippi
11 | i | 3 | ssissippi</pre>
-->
<p>å
¥åãšããŠïŒé·ã<var>N</var>ã®æååã«å¯Ÿããæ¥å°ŸèŸé
å<var>SA</var>ãäžããããïŒ<br />
<var>SA</var>ãåŸããããããªæååã®ãã¡ïŒèŸæžåŒé åºã§<var>K</var>çªç®(1-indexed)ã®ãã®ãæ±ããïŒ<br />
ãã ãïŒå
ã®æååã¯ïŒã¢ã«ãã¡ãããé ã«'a'ããæ°ããŠé«ã
<var>A</var>åã®æåã®ã¿ãããªãïŒ</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã«åŸãïŒäžããããæ°ã¯å
šãп޿°ã§ããïŒ</p>
<pre><var>N</var> <var>A</var> <var>K</var>
<var>SA_1</var>
<var>SA_2</var>
...
<var>SA_N</var></pre>
<h2>Constraints</h2>
<ul class="list1" style="padding-left:16px;margin-left:16px"><li><var>1âŠNâŠ10^5</var></li>
<li><var>1âŠAâŠ26</var></li>
<li><var>1âŠKâŠ10^{18}</var></li>
<li><var>1âŠSA_iâŠN</var></li>
<li><var>i \neq j</var> ãªãã° <var>SA_i \neq SA_j</var></li></ul>
<h2>Output</h2>
<p><var>SA</var>ãåŸããããããªèŸæžåŒé åºã§<var>K</var>çªç®ã®æååã1è¡ã«åºåããïŒ<br />
<var>K</var>çªç®ã®æååãååšããªãå ŽåïŒ"Impossible"ãšåºåããïŒ</p>
<h2>Sample Input 1</h2>
<pre>3 4 2
2
1
3</pre>
<h2>Output for the Sample Input 1</h2>
<pre>bad</pre>
<p><var>A</var>=4ã®å ŽåïŒ<var>SA</var>={2,1,3}ãšãªãæååã¯"bac","bad","cad","cbd"ã®4éãïŒ<br />
ãããã£ãŠïŒèŸæžåŒé åºã§2çªç®ã®"bad"ãçããšãªãïŒ</p>
<h2>Sample Input 2</h2>
<pre>18 26 10275802967
10
14
9
13
7
8
2
6
11
18
12
1
4
3
16
5
17
15</pre>
<h2>Output for the Sample Input 2</h2>
<pre>ritsumeicampdaytwo</pre>
|
p00903 |
<H1><font color="#000">Problem J:</font>Round Trip</H1>
<p>
Jim is planning to visit one of his best friends in a town in the mountain area. First, he leaves his hometown and goes to the destination town. This is called the go phase. Then, he comes back to his hometown. This is called the return phase. You are expected to write a program to find the minimum total cost of this trip, which is the sum of the costs of the go phase and the return phase.
</p>
<p>
There is a network of towns including these two towns. Every road in this network is one-way, i.e., can only be used towards the specified direction. Each road requires a certain cost to travel.
</p>
<p>
In addition to the cost of roads, it is necessary to pay a specified fee to go through each town on the way. However, since this is the visa fee for the town, it is not necessary to pay the fee on the second or later visit to the same town.
</p>
<p>
The altitude (height) of each town is given. On the go phase, the use of descending roads is inhibited. That is, when going from town <i>a</i> to <i>b</i>, the altitude of <i>a</i> should not be greater than that of <i>b</i>. On the return phase, the use of ascending roads is inhibited in a similar manner. If the altitudes of <i>a</i> and <i>b</i> are equal, the road from <i>a</i> to <i>b</i> can be used on both phases.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets, each in the following format.
</p>
<p>
<i>n m<br>
d<sub>2</sub> e<sub>2</sub><br>
d<sub>3</sub> e<sub>3</sub><br>
.<br>
.<br>
.<br>
d<sub>n-1</sub> e<sub>n-1</sub><br>
a<sub>1</sub> b<sub>1</sub> c<sub>1</sub><br>
a<sub>2</sub> b<sub>2</sub> c<sub>2</sub><br>
.<br>
.<br>
.<br>
a<sub>m</sub> b<sub>m</sub> c<sub>m</sub>
</i>
</p>
<p>
Every input item in a dataset is a non-negative integer. Input items in a line are separated by a space.
</p>
<p>
<i>n</i> is the number of towns in the network. <i>m</i> is the number of (one-way) roads. You can assume the inequalities 2 ≤ <i>n</i> ≤ 50 and 0 ≤ <i>m</i> ≤ <i>n</i>(<i>n</i>−1) hold. Towns are numbered from 1 to <i>n</i>, inclusive. The town 1 is Jim's hometown, and the town <i>n</i> is the destination town.
</p>
<p>
<i>d<sub>i</sub></i> is the visa fee of the town <i>i</i>, and <i>e<sub>i</sub></i> is its altitude. You can assume 1 ≤ <i>d<sub>i</sub></i> ≤ 1000 and 1≤<i>e<sub>i</sub></i> ≤ 999 for 2≤<i>i</i>≤<i>n</i>−1. The towns 1 and <i>n</i> do not impose visa fee. The altitude of the town 1 is 0, and that of the town n is 1000. Multiple towns may have the same altitude, but you can assume that there are no more than 10 towns with the same altitude.
</p>
<p>
The <i>j</i>-th road is from the town <i>a<sub>j</sub></i> to <i>b<sub>j</sub></i> with the cost <i>c<sub>j</sub></i> (1 ≤ <i>j</i> ≤ <i>m</i>). You can assume 1 ≤ <i>a<sub>j</sub></i> ≤ <i>n</i>, 1 ≤ <i>b<sub>j</sub></i> ≤ <i>n</i>, and 1 ≤ <i>c<sub>j</sub></i> ≤ 1000. You can directly go from <i>a<sub>j</sub></i> to <i>b<sub>j</sub></i>, but not from <i>b<sub>j</sub></i> to <i>a<sub>j</sub></i> unless a road from <i>b<sub>j</sub></i> to <i>a<sub>j</sub></i> is separately given. There are no two roads connecting the same pair of towns towards the same direction, that is, for any <i>i</i> and <i>j</i> such that <i>i</i> ≠ <i>j</i>, <i>a<sub>i</sub></i> ≠ <i>a<sub>j</sub></i> or <i>b<sub>i</sub></i> ≠ <i>b<sub>j</sub></i>. There are no roads connecting a town to itself, that is, for any <i>j</i>, <i>a<sub>j</sub></i> ≠ <i>b<sub>j</sub></i>.
</p>
<p>
The last dataset is followed by a line containing two zeros (separated by a space).
</p>
<H2>Output</H2>
<p>
For each dataset in the input, a line containing the minimum total cost, including the visa fees, of the trip should be output. If such a trip is not possible, output “-1”.
</p>
<H2>Sample Input</H2>
<pre>
3 6
3 1
1 2 1
2 3 1
3 2 1
2 1 1
1 3 4
3 1 4
3 6
5 1
1 2 1
2 3 1
3 2 1
2 1 1
1 3 4
3 1 4
4 5
3 1
3 1
1 2 5
2 3 5
3 4 5
4 2 5
3 1 5
2 1
2 1 1
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
7
8
36
-1
</pre> |
p00450 |
<H1> ç¢ç³ãªãã¹ </H1>
<h2>åé¡</h2>
<p>
çœãšé»ã®ç¢ç³ãããŒãã«ã®äžã«ãªãã¹ãŠéã¶.ãŸãããŒãã«ã®å·Šç«¯ã«ç¢ç³ã眮ã.次ã«å·Šãã 2 çªç®ã®å Žæã«ç¢ç³ã眮ã.ããã n åç¹°ãè¿ã㊠n åã®ç¢ç³ã暪äžåã«ãªãã¹ã.ãã ã,æ°ãã i çªç®ã®ç¢ç³ã眮ãéã«ã¯,次ã®ã«ãŒã«ã«åŸã£ãŠããŒãã«äžã®ç¢ç³ã眮ãæãã.
</p>
<ul>
<li> i ã奿°ã®å Žå: ããŒãã«ã«çœ®ããŠãã£ãç¢ç³ã¯çœ®ãæãã,æ°ããç¢ç³ãå·Š
ãã i çªç®ã«çœ®ã.</li>
<li> i ãå¶æ°ã®å Žå: æ°ããå·Šãã i çªç®ã«çœ®ãç¢ç³ã®è²ãšããŒãã«äžã®å³ç«¯ã®ç¢
ç³ã®è²ãåãå Žåã¯,ããŒãã«äžã®ç¢ç³ã¯çœ®ãæãã,æ°ããç¢ç³ãå·Šãã i
çªç®ã«çœ®ã.ããã§ãªãå Žå,ããªãã¡,æ°ããå·Šãã i çªç®ã«çœ®ãç¢ç³ã®è²
ãšããŒãã«äžã®å³ç«¯ã®ç¢ç³ã®è²ãç°ãªãå Žåã¯,ãŸãããŒãã«äžã®å³ç«¯ã®é£ç¶
ããåè²ã®ç¢ç³ãå
šãŠåãé€ã,i çªç®ã®ç¢ç³ãšåè²ã®ç¢ç³ã«çœ®ãæãã.ã
ããŠããŒãã«ã®å³ç«¯ã« i çªç®ã®ç¢ç³ã眮ã.</li>
</ul>
<p>
äŸãã°,æåã® 7 åã®ç¢ç³ã眮ããæç¹ã§,
</p>
<p>
âââââââ
</p>
<p>
ãšãªã£ãŠãããšãã. (âã¯çœã®ç¢ç³ã,âã¯é»ã®ç¢ç³ã衚ã. )
</p>
<ul>
<li> 8 çªç®ã®ç¢ç³ãçœ(â)ã®å Žåã¯,å³ç«¯ã®ç¢ç³ãšåè²ãªã®ã§,ãã®ãŸãŸçœ®ã.ã
ããã£ãŠ,ããŒãã«äžã®ç¢ç³ã¯<br>
<p>ââââââââ</p>
ãšãªã.
</li>
<li> 8 çªç®ã®ç¢ç³ãé»(â)ã®å Žåã¯,å³ç«¯ã®ç¢ç³(â)ãšè²ãç°ãªãã®ã§,ãŸã
ããŒãã«ã®å³ç«¯ã«ãã 3 åã®é£ç¶ããçœãç¢ç³(â)ãåãé€ã,é»ãç¢ç³
(â)ã«çœ®ãæãã.ãããŠå³ç«¯ã« 8 çªç®ã®ç¢ç³ã眮ã.ãããã£ãŠ,ããŒã
ã«äžã®ç¢ç³ã¯<br>
<p>
ââââââââ
</p>
ãšãªã.
</li>
</ul>
<p>
å
¥åãšããŠçœ®ãç¢ç³ã®é çªãäžãããããšã,n åã®ç¢ç³ããªãã¹çµãã£ãåŸ,ããŒ
ãã«äžã«çœ®ããŠããçœãç¢ç³ã®åæ°ãæ±ããããã°ã©ã ãäœæãã.
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ
</p>
<p>
<!-- å
¥åãã¡ã€ã«ã®ãã¡ã€ã«å㯠input.txt ã§ãã.-->
1 è¡ç®ã«ã¯æ£æŽæ° n (1 ≤ n ≤ 100000) ãæžãããŠãã.2 è¡ç®ä»¥éã®ç¬¬ i + 1 è¡ç® (1 ≤ i ≤ n) ã«ã¯,i çªç®ã«çœ®ãç¢ç³ã®è²ãè¡šãæŽæ° c<sub>i</sub> ãæžãããŠãã,c<sub>i</sub> ã 0 ãªã i çªç®ã«çœ®ãç¢ç³ã®è²ãçœã§ããããšã,1 ãªã i çªç®ã«çœ®ãç¢ç³ã®è²ãé»ã§ããããšã衚ã.
</p>
<p>
æ¡ç¹çšããŒã¿ã®ãã¡, é
ç¹ã® 50% åã«ã€ããŠã¯, n ≤ 10000 ãæºãã.
</p>
<p>
n ã 0 ã®ãšãå
¥åã®çµäºã瀺ã. ããŒã¿ã»ããã®æ°ã¯ 10 ãè¶
ããªãïŒ
</p>
<h2>åºå</h2>
<p>
<!-- åºåãã¡ã€ã«ã®ãã¡ã€ã«å㯠output.txt ã§ãã.
output.txt ã¯,n åã®ç¢ç³ããªãã¹çµãã£ãåŸã«ããŒãã«äžã«çœ®ããŠããçœãç¢ç³ã®åæ°ã ããå«ã 1 è¡ãããªã.
-->
ããŒã¿ã»ããããšã«, n åã®ç¢ç³ããªãã¹çµãã£ãåŸã«ããŒãã«äžã«çœ®ããŠããçœãç¢ç³ã®åæ°ã 1 è¡ã«åºåãã.
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ</h3>
<pre>
8
1
0
1
1
0
0
0
0
8
1
0
1
1
0
0
0
1
0
</pre>
<h3>åºåäŸ</h3>
<pre>
6
2
</pre>
<div class="source">
<p class="source">
äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p02197 | <h2>åå (Twins)</h2>
<p>square1001åãšE869120åã¯ååã§ãã</p>
<p>ãã®ãã¡å
ã«çãŸããæ¹ãåºåããŠäžããã</p>
<h3>å
¥å</h3>
<p>å
¥åã¯äžããããªãã</p>
<h3>åºå</h3>
<p>æ£è§£ã®æååãäžè¡ã«åºåããã</p>
<p>ãã ããæåŸã«ã¯æ¹è¡ãå
¥ããããšã</p>
<h3>åºåäŸ1</h3>
<pre>
square1001
</pre> |
p00000 |
<H1>QQ</H1>
<p>
Write a program which prints multiplication tables in the following format:
</p>
<pre>
1x1=1
1x2=2
.
.
9x8=72
9x9=81
</pre>
<H2>Input</H2>
<p>
No input.
</p>
<H2>Output</H2>
<pre>
1x1=1
1x2=2
.
.
9x8=72
9x9=81
</pre>
<H2>Template for C</H2>
<pre>
#include<stdio.h>
int main(){
return 0;
}
</pre>
<H2>Template for C++</H2>
<pre>
#include<iostream>
using namespace std;
int main(){
return 0;
}
</pre>
<H2>Template for Java</H2>
<pre>
class Main{
public static void main(String[] a){
}
}
</pre> |
p03505 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><em>ButCoder Inc.</em> runs a programming competition site called <em>ButCoder</em>. In this site, a user is given an integer value called rating that represents his/her skill, which changes each time he/she participates in a contest. The initial value of a new user's rating is <var>0</var>, and a user whose rating reaches <var>K</var> or higher is called <em>Kaiden</em> ("total transmission"). Note that a user's rating may become negative.</p>
<p>Hikuhashi is a new user in ButCoder. It is estimated that, his rating increases by <var>A</var> in each of his odd-numbered contests (first, third, fifth, ...), and decreases by <var>B</var> in each of his even-numbered contests (second, fourth, sixth, ...).</p>
<p>According to this estimate, after how many contests will he become Kaiden for the first time, or will he never become Kaiden?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †K, A, B †10^{18}</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>K</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is estimated that Hikuhashi will never become Kaiden, print <code>-1</code>. Otherwise, print the estimated number of contests before he become Kaiden for the first time.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4000 2000 500
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>Each time Hikuhashi participates in a contest, his rating is estimated to change as <var>0</var> â <var>2000</var> â <var>1500</var> â <var>3500</var> â <var>3000</var> â <var>5000</var> â <var>âŠ</var> After his fifth contest, his rating will reach <var>4000</var> or higher for the first time.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4000 500 2000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>Each time Hikuhashi participates in a contest, his rating is estimated to change as <var>0</var> â <var>500</var> â <var>-1500</var> â <var>-1000</var> â <var>-3000</var> â <var>-2500</var> â <var>âŠ</var> He will never become Kaiden.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1000000000000000000 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1999999999999999997
</pre>
<p>The input and output values may not fit into <var>32</var>-bit integers.</p></section>
</div>
</span> |
p01538 |
<h1>ãããã</h1>
<p>
倪éåã¯ãããããç¿ãããŠã®å°åŠçã§ãããªããšãªãã圌ã¯ãããããæ°ã«å
¥ã£ãŠããã®ã§ãæ°åãèŠããããšãããããããããªããŸãããããªåœŒã¯ããã®ãšãããæ¬¡ã®ãããªåŠçã0以äžã®æŽæ°ã«æœãããšã奜ããªããã§ãã
(åŠçã®æµã)
</p>
<ul>
<li>æé 1. ãã0以äžã®æŽæ°nã10鲿°è¡šç€ºã§äžãããªãã°ããã§åŠçãçµäºãããããã§ãªããã°æé 2ã«é²ã
</li><li>æé 2. 10以äžã®æŽæ°nã10鲿°è¡šç€ºããããšã©ããã®æ¡ã®éã«åãç®ãå
¥ããŠäºã€ã®æ°åã«åè§£ããããšãå¯èœã§ãã(äŸãã°2012-> 20,12)ããã®ãããªåãæ¹ãšããŠãããããã®ã«å¯ŸããŠ,åŸãããäºã€ã®æ°åãæãåãããŠæã倧ãããã®ã次ã®nãšããŠæé 1ã«æ»ãã(詳ããã¯äžèšã®"æé 2ã«é¢ããè£è¶³ãåç
§")
</li></ul>
<p>
倪éåã¯ãã®åŠçãæ°ã«å
¥ã£ãŠããããã§ãããäœåæé 2ã®æäœãç¹°ãè¿ãã°ããã®ã倧ããæ°åã ãšäºæ³ãã§ãããããããããç¡éåè¡ãããªããã°ãªããªããããããªããšæã£ãŠããŸããããã§ã倪éåã®å
ã§ãã倧åŠçã§ããããªãã«0以äžã®æŽæ°nã«å¯ŸããŠãã®æé 2ãäœåããªããã°ãªããªãããèããŠããŸããã
</p>
<p>
ããªãã®ä»äºã¯ãQåã®0以äžã®æŽæ°<var>N<sub>1</sub></var>..<var>N<sub>Q</sub></var>ãäžããããã®ã§ãããããã®æŽæ°ã§åŠçã®çµäºãŸã§ã«äœåã®æé 2ãæœãããããæ±ããããšã§ãããã®éã«ããç¡éåã®æé ãå¿
èŠãªãã°ã-1ãåºåããŠãã ããã
</p>
<h3>æé 2ã«é¢ããè£è¶³</h3>
<p>
åãåããçµæãæ¡ã®åãã«0ãã€ããã®ãèæ
®ã«å
¥ããå¿
èŠããããŸãã<br>
äŸãã°n=1024ã®ãšãã1*024 , 10*24 , 102*4ãããããèšç®ãããšãããã24,240,408ãšãªãããã408ãéžã°ãããããæ¬¡ã®nãšãªããŸãã
</p>
<h2>Input</h2>
<blockquote>
<var>Q</var><br><var>N<sub>1</sub></var><br><var>N<sub>2</sub></var><br>...<br><var>N<sub>Q</sub></var><br></blockquote>
<ul>
<li><var>Q</var>ã¯äžãããã0以äžã®æŽæ°ã®åæ°ã衚ã
</li><li><var>N<sub>i</sub></var>ã¯å€ªéåãæ°ã«ãªã£ãŠãã0以äžã®æŽæ°ã§,içªç®ã®ãã®ã衚ã
</li></ul>
<h2>Constraints</h2>
<blockquote>
<var>1≤Q≤100</var><br><var>0≤N<sub>i</sub>≤10<sup>6</sup></var><br></blockquote>
<h2>Output</h2>
<p>
<var>Q</var>åã®æŽæ°ãæ¹è¡åºåãã§åºåãã
</p>
<blockquote>
<var>R<sub>1</sub></var><br><var>R<sub>2</sub></var><br>..<br><var>R<sub>Q</sub></var><br></blockquote>
<ul>
<li><var>R<sub>i</sub></var>ã¯ã<var>N<sub>i</sub></var>ã«å¯ŸããŠåŠçãçµäºãããŸã§ã«æé 2ãå®è¡ããåæ°ã衚ã
</li><li><var>N<sub>i</sub></var>ã«å¯ŸããŠæé 2ãç¡éåã ãå®è¡ããå¿
èŠãããå Žåã¯<var>R<sub>i</sub></var> 㯠-1ãšãªã
</li></ul>
<H2>Sample Input 1</H2>
<pre>3
9
99
123
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>0
2
3
</pre>
<p>
9ã¯1æ¡ã®æ°ãªã®ã§ãæé 2ãå®è¡ãããããšã¯ãããŸããã
99ã¯2æ¡ã§ãããæé 2ãæœãã°9,9ãšããåå²ã§ãããã®æ¬¡ã®æ°ã¯81ãšãªãã
81ã2æ¡ã®æ°ã§ãããæé 2ãæœãã°8,1ãšããåå²ã§ãããã®æ¬¡ã®æ°ã¯8ãšãªãã
1æ¡ã®æ°ã«ãªã£ãã®ã§åŠçãçµäºããçãã¯2ã
123ã¯3æ¡ã®æ°ãªã®ã§ãæé 2ãæœããŸãã
ãã®å Žåã¯12,3ãš1,23ã®äºã€ã®åãæ¹ããããããããã§ããããããããš36,23ãšãªãã®ã§ã
36ãæ¬¡ã®æ°ãšããŠéžã°ããŸãã
</p>
<H2>Sample Input 2</H2>
<pre>2
999999
1000000
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>12
1
</pre>
|
p03155 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>It has been decided that a programming contest sponsored by company A will be held, so we will post the notice on a bulletin board.</p>
<p>The bulletin board is in the form of a grid with <var>N</var> rows and <var>N</var> columns, and the notice will occupy a rectangular region with <var>H</var> rows and <var>W</var> columns.</p>
<p>How many ways are there to choose where to put the notice so that it completely covers exactly <var>HW</var> squares?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq H, W \leq N \leq 100</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>H</var>
<var>W</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
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>There are two ways to put the notice, as follows:</p>
<pre>### ...
### ###
... ###
</pre>
<p>Here, <code>#</code> represents a square covered by the notice, and <code>.</code> represents a square not covered.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>100
1
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>10000
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
4
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>8
</pre></section>
</div>
</span> |
p01168 |
<H1><font color="#000">Problem F:</font> Lying about Your Age</H1>
<p>
You have moved to a new town. As starting a new life, you have made up your mind to do
one thing: lying about your age. Since no person in this town knows your history, you donât
have to worry about immediate exposure. Also, in order to ease your conscience somewhat,
you have decided to claim ages that represent your real ages when interpreted as the base-<i>M</i>
numbers (2 ≤ <i>M</i> ≤ 16). People will misunderstand your age as they interpret the claimed age
as a decimal number (i.e. of the base 10).
</p>
<p>
Needless to say, you donât want to have your real age revealed to the people in the future. So
you should claim only one age each year, it should contain digits of decimal numbers (i.e. â0â
through â9â), and it should always be equal to or greater than that of the previous year (when
interpreted as decimal).
</p>
<p>
How old can you claim you are, after some years?
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset is a single line that contains three integers
<i>A</i>, <i>B</i>, and <i>C</i>, where <i>A</i> is the present real age (in decimal), <i>B</i> is the age you presently claim
(which can be a non-decimal number), and <i>C</i> is the real age at which you are to find the age
you will claim (in decimal). It is guaranteed that 0 ≤ <i>A</i> < <i>C</i> ≤ 200, while <i>B</i> may contain up to
eight digits. No digits other than â0â through â9â appear in those numbers.
</p>
<p>
The end of input is indicated by <i>A</i> = <i>B</i> = <i>C</i> = -1, which should not be processed.
</p>
<H2>Output</H2>
<p>
For each dataset, print in a line the minimum age you can claim when you become <i>C</i> years old.
In case the age you presently claim cannot be interpreted as your real age with the base from 2
through 16, print -1 instead.
</p>
<H2>Sample Input</H2>
<pre>
23 18 53
46 30 47
-1 -1 -1
</pre>
<H2>Output for the Sample Input</H2>
<pre>
49
-1
</pre>
|
p01492 |
<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 G:
CarrotBreeding
</h2>
<p>
ã«ãããã¯ç¹æ®ã®å¥œããªæ€ç©ã§ãã.
</p>
<p>
ããããçã§ã«ãããã飌ãããšã«ãã. ç㯠(0, 0) ãš (1000000000, 1000000000) ã察è§ç·ãšããæ£æ¹åœ¢ (boundary ãå«ã) ã§ãã. ãããã¯, 2 å以äžã®ã«ããããéããã¹ãŠã®çŽç·ã«æ²¿ã£ãŠæ¯æ¥1 åãã€æ°ŽããŸãããšã«ãã.
</p>
<p>
ãã®ã«ããããã¡ã¯, æ¯æ¥ $N$ åãã€æ°ŽããŸãããã®ãç¹æ®ã«æé©ã ãšèããŠããã®ã§, ãã®ãããªæ¡ä»¶ãæºããããã«ãããã®çã«äžŠã¶ããšã«ãã. ã«ãããã¯çå
éšã®æ Œåç¹ã«ãã䞊ã¶ããšãã§ããªã. ãŸã, ãã®ãããªæ¡ä»¶ãæºããäžŠã³æ¹ãè€æ°ããå Žåã¯, æãã«ãããã®åæ°ãå°ãªããã®ãéžã¶ããšã«ãã.
</p>
<p>
æ¡ä»¶ãæºããã«ãããã®é
眮ã1 ã€åºåãã. ãã®ãããªé
眮ãååšããªãå Žåã«ã¯ -1 ãšåºåãã.
</p>
<h3>Constraints</h3>
<ul>
<li>$N$ will be between 1 and 1,000,000, inclusive.</li>
</ul>
<h3>Input</h3>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžãããã:<br>
<br>
$N$
<br>
</p>
<h3>Output</h3>
<p>
æ¡ä»¶ãæºããé
眮ãååšããªãå Žå, -1 ãšäžè¡ã«åºåãã.<br>
ååšããå Žå, ã«ãããã®æ¬æ°ã $K$ ãšãããš, 以äžã®åœ¢åŒã§åºåãã:<br>
<br>
$K$<br>
$x_1$ $y_1$<br>
...<br>
$x_K$ $y_K$<br>
</p>
<h3>Sample Input 1</h3>
<pre>4</pre>
<h3>Sample Output 1</h3>
<pre>4
0 0
1 0
2 0
1 1</pre>
<h3>Sample Input 2</h3>
<pre>6</pre>
<h3>Sample Output 2</h3>
<pre>4
0 0
0 1
1 0
1 1</pre> |
p00329 |
<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>
PCK åã¯ã¿ããªã§ã²ãŒã 倧äŒãããŠããŸãããã®ã²ãŒã 倧äŒã§ã¯ã倧äŒã®æåŸã«ãã¿ã ããã§é äœãå
¥ãæ¿ããŸãã倧äŒã«ã¯ <var>N</var> 人ã®ãã¬ã€ã€ãŒãåå ããŠããããã¿ã ããã«ã¯ <var>N</var> æ¬ã®çžŠæ£ããããŸãã
</p>
<p>
ãã¿ã ããã¯ãå³ã®ããã« <var>N</var> - 1 段ã®éšåããã§ããŠããããããã 1 ãã <var>N</var>-1 ã®çªå·ãå²ãåœãŠãããŠããŸããåéšåã¯ããã¿ã ããã®äžéšã暪æ¹åã«åãåã£ãéšåã§ããåéšåã«ã¯ããã€ãã®æšªæ£ãåŒãããŠããŸãããéšåã®äžã®æšªæ£ã¯ãã¹ãŠåãé«ãã«ãããŸããæšªæ£å士ãã€ãªããããšã¯ãããŸããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2015_amida"><br/>
</center>
<br/>
<p>
倧äŒã®æåŸã«ãé äœã®é«ã人ããå³ããå·Šã®é ã«çžŠæ£ãå²ãåœãŠãããŸããPCK åã¯çŸæç¹ã§æäžäœãªã®ã§ã巊端ããã¹ã¿ãŒãã§ããäŸãã°ãäžå³ã®çµã¿ç«ãŠæ¹ã§ã¯ãïŒäœã ã£ãPCK åã¯ããã®ãã¿ã ããã«ãã£ãŠïŒäœïŒå³ããïŒçªç®ã®æ£ïŒã«æµ®äžããããšãã§ããŸãã
</p>
<p>
ãã®ã²ãŒã ã§ã¯ãæäžäœã®äººã«ãã¿ã ãããçµã¿ç«ãŠãæš©å©ãäžããããŸããPCK åã¯ããŸããã¿ã ããã®éšåã®é çªã決ããŠãé転åªåãçã£ãŠããŸãããã ããéšåãå転ããããšã¯ã§ããŸããã
</p>
<p>
ïŒâ»è£è¶³ïŒãã¿ã ããã®ãã©ãæ¹ã«ã€ããŠïŒ<br/>
ãã¿ã ããã®ãã瞊æ£ã®äžç«¯ããåºçºããŠäžããäžãžé²ãããã ããæšªæ£ãããå°ç¹ã§ã¯ãã®æšªæ£ã§ã€ãªãã£ãå¥ã®çžŠæ£ã«ç§»åããããããã瞊æ£ã®äžç«¯ã«ãã©ãçããŸã§ç¹°ãè¿ãã
</p>
<p>
ã²ãŒã ã®åå 人æ°ãšãã¿ã ããã®éšåã®æ
å ±ãå
¥åããPCK åãåªåã§ãããã©ããå€å®ããããã°ã©ã ãäœæãããåªåã§ããå Žåããã®ãã¿ã ããã®éšåã®äžŠã³ãïŒã€åºåããããã ãããã®ãããªäžŠã¹æ¹ãè€æ°ããå Žåã¯ãäžããããéšåã®çªå·ã§èŸæžé æå°ã®ãã®ãåºåããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>b<sub>1,1</sub></var> <var>b<sub>1,2</sub></var> ... <var>b<sub>1,N−1</sub></var>
<var>b<sub>2,1</sub></var> <var>b<sub>2,2</sub></var> ... <var>b<sub>2,N−1</sub></var>
:
<var>b<sub>N−1,1</sub></var> <var>b<sub>N−1,2</sub></var> ... <var>b<sub>N−1,N−1</sub></var>
</pre>
<p>
ïŒè¡ç®ã«å€§äŒã®åå è
æ° <var>N</var> (2 ≤ <var>N</var> ≤ 500) ãäžãããããç¶ã <var>N</var>-1 è¡ã« <var>i</var> çªç®ã®éšåã®æšªæ£ã®æ
å ±ãäžããããã<var>b<sub>i,j</sub></var> ã 1 ã§ãããšãã<var>i</var> çªç®ã®éšåã®ãå·Šãã <var>j</var> æ¬ç®ã®çžŠæ£ãã <var>j</var>+1 çªç®ã®çžŠæ£ãžæšªæ£ãåŒãããŠããããšã衚ãã<var>b<sub>i,j</sub></var> ã 0 ã§ãããšãã<var>i</var> çªç®ã®éšåã®ãå·Šãã <var>j</var> æ¬ç®ã®çžŠæ£ãã <var>j</var>+1 çªç®ã®çžŠæ£ãžæšªæ£ã¯åŒãããŠããªãããšã衚ãã<var>b<sub>i,j</sub></var> ã 1 ã§ãããšãã<var>b<sub>i,j+1</sub></var> ã 1 ãšãªããããªéšåã¯äžããããªãããŸããæšªæ£ã®ç·æ°ã¯ 10000 ãè¶ããªãã
</p>
<h2>Output</h2>
<p>
PCK åãåªåã§ããå ŽåïŒïŒè¡ç®ã«ãyesããšåºåãããç¶ã <var>N</var>-1 è¡ã«ããã¿ã ããã®äžããé ã«ãéšåã®çªå·ã®äžŠã³ãåºåããããã®ãããªäžŠã³ãè€æ°ããå ŽåãèŸæžé æå°ã§ãã䞊ã³ãåºåãããPCK åãåªåã§ããªãå ŽåãïŒè¡ã«ãnoããšåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
6
1 0 0 0 1
1 0 1 0 1
0 1 0 1 0
0 0 0 1 0
0 1 0 0 1
</pre>
<h2>Sample Output 1</h2>
<pre>
yes
1
3
2
4
5
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
5
0 1 0 1
0 1 0 1
1 0 1 0
1 0 0 1
</pre>
<h2>Sample Output 2</h2>
<pre>
yes
4
1
3
2
</pre>
<p>
4 1 3 2 ãš 4 2 3 1 ã®ïŒéãã®çµã¿ç«ãŠæ¹ãå¯èœã ããèŸæžé ã§å°ããæ¹ã® 4 1 3 2 ãåºåããã
</p>
<br/>
<h2>Sample Input 3</h2>
<pre>
5
1 0 0 1
0 1 0 1
1 0 0 0
0 1 0 1
</pre>
<h2>Sample Output 3</h2>
<pre>
no
</pre> |
p02314 |
<H1>Coin Changing Problem</H1>
<br/>
<p>
Find the minimum number of coins to make change for <var>n</var> cents using coins of denominations <var>d<sub>1</sub></var>, <var>d<sub>2</sub></var>,.., <var>d</var><sub><var>m</var></sub>. The coins can be used any number of times.
</p>
<H2>Input</H2>
<pre>
<var>n</var> <var>m</var>
<var>d<sub>1</sub></var> <var>d<sub>2</sub></var> ... <var>d</var><sub><var>m</var></sub>
</pre>
<p>
Two integers <var>n</var> and <var>m</var> are given in the first line. The available denominations are given in the second line.
</p>
<H2>Output</H2>
<p>
Print the minimum number of coins in a line.
</p>
<H2>Constraints</H2>
<ul>
<li>
1 ≤ <var>n</var> ≤ 50000
</li>
<li>
1 ≤ <var>m</var> ≤ 20
</li>
<li>
1 ≤ denomination ≤ 10000
</li>
<li>
The denominations are all different and contain 1.
</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
55 4
1 5 10 50
</pre>
<H2>Sample Output 1</H2>
<pre>
2
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
15 6
1 2 7 8 12 50
</pre>
<H2>Sample Output 2</H2>
<pre>
2
</pre>
<br/>
<H2>Sample Input 3</H2>
<pre>
65 6
1 2 7 8 12 50
</pre>
<H2>Sample Output 3</H2>
<pre>
3
</pre>
|
p03856 | <span class="lang-en">
<p>Score : <var>300</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.
Another string <var>T</var> is initially empty.
Determine whether it is possible to obtain <var>S = T</var> by performing the following operation an arbitrary number of times:</p>
<ul>
<li>Append one of the following at the end of <var>T</var>: <code>dream</code>, <code>dreamer</code>, <code>erase</code> and <code>eraser</code>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1âŠ|S|âŠ10^5</var></li>
<li><var>S</var> consists of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>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>If it is possible to obtain <var>S = T</var>, print <code>YES</code>. Otherwise, print <code>NO</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>erasedream
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p>Append <code>erase</code> and <code>dream</code> at the end of <var>T</var> in this order, to obtain <var>S = T</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>dreameraser
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>YES
</pre>
<p>Append <code>dream</code> and <code>eraser</code> at the end of <var>T</var> in this order, to obtain <var>S = T</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>dreamerer
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>NO
</pre></section>
</div>
</span> |
p00779 |
<h3>Don't Cross the Circles!</h3>
<p>
There are one or more circles on a plane.
Any two circles have different center positions and/or different radiuses.
A circle may intersect with another circle,
but no three or more circles have areas nor points shared by all of them.
A circle may completely contain another circle or two circles may intersect at two separate points,
but you can assume that the circumferences of two circles never
touch at a single point.
</p>
<p>
Your task is to judge
whether there exists a path that connects the given two points, <i>P</i> and <i>Q</i>,
without crossing the circumferences of the circles.
You are given one or more point pairs for each layout of circles.
</p>
<p>
In the case of Figure G-1,
we can connect <i>P</i> and <i>Q</i><sub>1</sub> without crossing the circumferences of the circles, but we cannot connect <i>P</i> with <i>Q</i><sub>2</sub>, <i>Q</i><sub>3</sub>, or <i>Q</i><sub>4</sub> without crossing the circumferences of the circles.
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_domestic2014_G0"><br>
<p>Figure G-1: Sample layout of circles and points</p>
</center>
<br>
<h3>Input</h3>
<p>
The input consists of multiple datasets, each in the following format.
</p>
<blockquote>
<i>n</i> <i>m</i><br>
<i>Cx</i><sub>1</sub> <i>Cy</i><sub>1</sub> <i>r</i><sub>1</sub> <br>
...<br>
<i>Cx</i><sub><i>n</i></sub> <i>Cy</i><sub><i>n</i></sub> <i>r</i><sub><i>n</i></sub> <br>
<i>Px</i><sub>1</sub> <i>Py</i><sub>1</sub> <i>Qx</i><sub>1</sub> <i>Qy</i><sub>1</sub> <br>
...<br>
<i>Px</i><sub><i>m</i></sub> <i>Py</i><sub><i>m</i></sub> <i>Qx</i><sub><i>m</i></sub> <i>Qy</i><sub><i>m</i></sub> <br>
</blockquote>
<p>
The first line of a dataset contains two integers <i>n</i> and <i>m</i>
separated by a space.
<i>n</i> represents the number of circles, and
you can assume 1 ≤ <i>n</i> ≤ 100.
<i>m</i> represents the number of point pairs, and
you can assume 1 ≤ <i>m</i> ≤ 10.
Each of the following <i>n</i> lines contains three integers separated by a single space.
(<i>Cx</i><sub><i>i</i></sub>, <i>Cy</i><sub><i>i</i></sub>) and <i>r</i><sub><i>i</i></sub> represent the center position and the radius of the <i>i</i>-th circle, respectively.
Each of the following <i>m</i> lines contains four integers separated by a single space.
These four integers represent coordinates of two separate points
<i>P</i><sub><i>j</i></sub> = (<i>Px</i><sub><i>j</i></sub>, <i>Py</i><sub><i>j</i></sub>) and
<i>Q</i><sub><i>j</i></sub> =(<i>Qx</i><sub><i>j</i></sub>, <i>Qy</i><sub><i>j</i></sub>).
These two points <i>P</i><sub><i>j</i></sub> and <i>Q</i><sub><i>j</i></sub>
form the <i>j</i>-th point pair.
You can assume
0 ≤ <i>Cx</i><sub><i>i</i></sub> ≤ 10000,
0 ≤ <i>Cy</i><sub><i>i</i></sub> ≤ 10000,
1 ≤ <i>r</i><sub><i>i</i></sub> ≤ 1000,
0 ≤ <i>Px</i><sub><i>j</i></sub> ≤ 10000,
0 ≤ <i>Py</i><sub><i>j</i></sub> ≤ 10000,
0 ≤ <i>Qx</i><sub><i>j</i></sub> ≤ 10000,
0 ≤ <i>Qy</i><sub><i>j</i></sub> ≤ 10000.
In addition,
you can assume
<i>P</i><sub><i>j</i></sub> or <i>Q</i><sub><i>j</i></sub>
are not located on the circumference of any circle.
</p>
<p>
The end of the input is indicated by a line containing two zeros separated by a space.
</p>
<p>
Figure G-1 shows the layout of the circles and the points in the first dataset of the sample input below.
Figure G-2 shows the layouts of the subsequent datasets in the sample input.
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_domestic2014_G1"><br>
<p>Figure G-2: Sample layout of circles and points</p>
</center>
<br>
<h3>Output</h3>
<p>
For each dataset,
output a single line containing the <i>m</i> results separated by a space.
The <i>j</i>-th result should be "YES" if there exists a path connecting <i>P</i><sub><i>j</i></sub> and <i>Q</i><sub><i>j</i></sub>, and "NO" otherwise.
</p>
<h3>Sample Input</h3>
<pre>5 3
0 0 1000
1399 1331 931
0 1331 500
1398 0 400
2000 360 340
450 950 1600 380
450 950 1399 1331
450 950 450 2000
1 2
50 50 50
0 10 100 90
0 10 50 50
2 2
50 50 50
100 50 50
40 50 110 50
40 50 0 0
4 1
25 100 26
75 100 26
50 40 40
50 160 40
50 81 50 119
6 1
100 50 40
0 50 40
50 0 48
50 50 3
55 55 4
55 105 48
50 55 55 50
20 6
270 180 50
360 170 50
0 0 50
10 0 10
0 90 50
0 180 50
90 180 50
180 180 50
205 90 50
180 0 50
65 0 20
75 30 16
90 78 36
105 30 16
115 0 20
128 48 15
128 100 15
280 0 30
330 0 30
305 65 42
0 20 10 20
0 20 10 0
50 30 133 0
50 30 133 30
90 40 305 20
90 40 240 30
16 2
0 0 50
0 90 50
0 180 50
90 180 50
180 180 50
205 90 50
180 0 50
65 0 20
115 0 20
90 0 15
280 0 30
330 0 30
305 65 42
75 40 16
90 88 36
105 40 16
128 35 250 30
90 50 305 20
0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>YES NO NO
YES NO
NO NO
NO
YES
YES NO NO YES NO NO
NO NO
</pre> |
p02744 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In this problem, we only consider strings consisting of lowercase English letters.</p>
<p>Strings <var>s</var> and <var>t</var> are said to be <strong>isomorphic</strong> when the following conditions are satisfied:</p>
<ul>
<li><var>|s| = |t|</var> holds.</li>
<li>For every pair <var>i, j</var>, one of the following holds:<ul>
<li><var>s_i = s_j</var> and <var>t_i = t_j</var>.</li>
<li><var>s_i \neq s_j</var> and <var>t_i \neq t_j</var>.</li>
</ul>
</li>
</ul>
<p>For example, <code>abcac</code> and <code>zyxzx</code> are isomorphic, while <code>abcac</code> and <code>ppppp</code> are not.</p>
<p>A string <var>s</var> is said to be in <strong>normal form</strong> when the following condition is satisfied:</p>
<ul>
<li>For every string <var>t</var> that is isomorphic to <var>s</var>, <var>s \leq t</var> holds. Here <var>\leq</var> denotes lexicographic comparison.</li>
</ul>
<p>For example, <code>abcac</code> is in normal form, but <code>zyxzx</code> is not since it is isomorphic to <code>abcac</code>, which is lexicographically smaller than <code>zyxzx</code>.</p>
<p>You are given an integer <var>N</var>.
Print all strings of length <var>N</var> that are in normal form, in lexicographically ascending order.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10</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>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Assume that there are <var>K</var> strings of length <var>N</var> that are in normal form: <var>w_1, \ldots, w_K</var> in lexicographical order.
Output should be in the following format:</p>
<pre><var>w_1</var>
<var>:</var>
<var>w_K</var>
</pre>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>a
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>aa
ab
</pre></section>
</div>
</span> |
p00283 |
<h1>å·šæš¹ã®å»ã¿æ</h1>
<p>
ããªã㯠<var>N</var> çš®é¡ã®éå
·ã䜿ã£ãŠãç®ã®åã®å·šæš¹ãåãåãããšããŠããŸããã¯ããã¯ãæš¹ã®èä¹
å㯠<var>D</var>ãããªãã®çµéšå€ã¯ 0 ã§ãããéå
· <var>i</var> ã§ïŒåæš¹ãå©ããšæš¹ã®èä¹
å㯠<var>a<sub>i</sub></var> æžããããªã㯠<var>e<sub>i</sub></var> ã®çµéšå€ãåŸãŸãããã ããéå
· <var>i</var> ã䜿ãããã«ã¯ãããªã㯠<var>r<sub>i</sub></var> 以äžã®çµéšå€ãæã£ãŠããªããã°ãªããŸãããæš¹ã®èä¹
åã 0 以äžã«ãªããšæš¹ã¯åããŸãã
</p>
<p>
æš¹ã®èä¹
åãšéå
·ã«ã€ããŠã®æ
å ±ãäžãããããšããæš¹ãåãåãã«ã¯æäœäœåæš¹ãå©ããªããã°ãããªãããæ±ããããã°ã©ã ãäœæããŠãã ããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããå
¥åã®çµããã¯ãŒãïŒã€ã®è¡ã§ç€ºããããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>D</var> <var>N</var>
<var>a<sub>1</sub></var> <var>e<sub>1</sub></var> <var>r<sub>1</sub></var>
<var>a<sub>2</sub></var> <var>e<sub>2</sub></var> <var>r<sub>2</sub></var>
:
<var>a<sub>N</sub></var> <var>e<sub>N</sub></var> <var>r<sub>N</sub></var>
</pre>
<p>
1 è¡ç®ã«æš¹ã®èä¹
åãè¡šãæŽæ° <var>D</var> (1 ≤ <var>D</var> ≤ 100) ãšéå
·ã®çš®é¡ã®æ° <var>N</var>(1 ≤ <var>N</var> ≤ 100) ãäžãããããç¶ã <var>N</var> è¡ã«éå
· 1 ãã <var>N</var> ãŸã§ã®æ
å ±ãäžããããã<var>a<sub>i</sub></var> (0 ≤ <var>a<sub>i</sub></var> ≤ 100) ãš <var>e<sub>i</sub></var> (0 ≤ <var>e<sub>i</sub></var> ≤ 100) ã¯ãéå
·iãïŒå䜿ãããšã§æžãæš¹ã®èä¹
åãšããªããåŸãããšã®ã§ããçµéšå€ããããã衚ãã<var>r<sub>i</sub></var> (0 ≤ <var>r<sub>i</sub></var> ≤ 100) ã¯éå
·ã䜿ãããã«å¿
èŠãªçµéšå€ã衚ãã<var>a<sub>i</sub></var>, <var>e<sub>i</sub></var>, <var>r<sub>i</sub></var> ã¯ãã¹ãп޿°ã§ããã<br>
<br>
ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããªãã
</p>
<h2>åºå</h2>
<p>
æš¹ãåãåãã®ã«å¿
èŠãªãæš¹ãå©ãæå°ã®åæ°ãïŒè¡ã«åºåããããã ããæš¹ãåãåãããšãäžå¯èœãªå Žå㯠<span>NA</span> ãšåºåããã
</p>
<h2>å
¥åºåäŸ</h2>
<br>
<h2>å
¥åäŸ</h2>
<pre>
15 4
1 1 0
1 2 2
5 10 5
8 1 15
60 4
5 2 0
8 8 2
3 5 0
49 0 18
100 1
1 1 1
0 0
</pre>
<h2>åºåäŸ</h2>
<pre>
6
4
NA
</pre>
|
p01884 |
<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>Similarity of Subtrees</h2>
<p>
Define the depth of a node in a rooted tree by applying the following rules recursively:
</p>
<ul>
<li> The depth of a root node is 0.</li>
<li> The depths of child nodes whose parents are with depth $d$ are $d + 1$.</li>
</ul>
<p>
Let $S(T, d)$ be the number of nodes of $T$ with depth $d$. Two rooted trees $T$ and $T'$ are similar if and only if $S(T, d)$ equals $S(T', d)$ for all non-negative integer $d$.
</p>
<p>
You are given a rooted tree $T$ with $N$ nodes. The nodes of $T$ are numbered from 1 to $N$. Node 1 is the root node of $T$. Let $T_i$ be the rooted subtree of $T$ whose root is node $i$. Your task is to write a program which calculates the number of pairs $(i, j)$ such that $T_i$ and $T_j$ are similar and $i < j$.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case.<br/>
<br/>
$N$<br/>
$a_1$ $b_1$<br/>
$a_2$ $b_2$<br/>
...<br/>
$a_{N-1}$ $b_{N-1}$
</p>
<p>
The first line contains an integer $N$ ($1 \leq N \leq 100,000$), which is the number of nodes in a tree. The following $N -1$ lines give information of branches: the $i$-th line of them contains $a_i$ and $b_i$, which indicates that a node $a_i$ is a parent of a node $b_i$. ($1 \leq a_i, b_i \leq N, a_i \ne b_i$) The root node is numbered by 1. It is guaranteed that a given graph is a rooted tree, i.e. there is exactly one parent for each node except the node 1, and the graph is connected.
</p>
<h3>Output</h3>
<p>
Print the number of the pairs $(x, y)$ of the nodes such that the subtree with the root $x$ and the subtree with the root $y$ are similar and $x < y$.
</p>
<h3>Sample Input 1</h3>
<pre>
5
1 2
1 3
1 4
1 5
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>
6
</pre>
<h3>Sample Input 2</h3>
<pre>
6
1 2
2 3
3 4
1 5
5 6
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>
2
</pre>
<h3>Sample Input 3</h3>
<Pre>
13
1 2
1 3
2 4
2 5
3 6
3 7
4 8
4 9
6 10
7 11
8 12
11 13
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>
14
</pre> |
p00796 |
<H1><font color="#000">Problem A:</font> Lost in Space</H1>
<p>
William Robinson was completely puzzled in the music room; he could not find his triangle in
his bag. He was sure that he had prepared it the night before. He remembered its clank when
he had stepped on the school bus early that morning. No, not in his dream. His triangle was
quite unique: no two sides had the same length, which made his favorite peculiar jingle. He
insisted to the music teacher, Mr. Smith, that his triangle had probably been stolen by those
aliens and thrown away into deep space.
</p>
<p>
Your mission is to help Will find his triangle in space. His triangle has been made invisible by the
aliens, but candidate positions of its vertices are somehow known. You have to tell which three
of them make his triangle. Having gone through worm-holes, the triangle may have changed its
size. However, even in that case, all the sides are known to be enlarged or shrunk equally, that
is, the transformed triangle is <i>similar</i> to the original.
</p>
<H2>Input</H2>
<p>
The very first line of the input has an integer which is the number of data sets. Each data set
gives data for one incident such as that of Willâs. At least one and at most ten data sets are
given.
</p>
<p>
The first line of each data set contains three decimals that give lengths of the sides of the original
triangle, measured in centimeters. Three vertices of the original triangle are named P, Q, and
R. Three decimals given in the first line correspond to the lengths of sides QR, RP, and PQ, in
this order. They are separated by one or more space characters.
</p>
<p>
The second line of a data set has an integer which is the number of points in space to be
considered as candidates for vertices. At least three and at most thirty points are considered.
</p>
<p>
The rest of the data set are lines containing coordinates of candidate points, in light years. Each
line has three decimals, corresponding to x, y, and z coordinates, separated by one or more space
characters. Points are numbered in the order of their appearances, starting from one.
</p>
<p>
Among all the triangles formed by three of the given points, only one of them is <i>similar</i> to the
original, that is, ratios of the lengths of any two sides are equal to the corresponding ratios of
the original allowing an error of less than 0.01 percent. Other triangles have some of the ratios
different from the original by at least 0.1 percent.
</p>
<p>
The origin of the coordinate system is not the center of the earth but the center of our galaxy.
Note that negative coordinate values may appear here. As they are all within or close to our galaxy, coordinate values are less than one hundred thousand light years. You donât have to
take relativistic effects into account, i.e., you may assume that we are in a Euclidean space. You
may also assume in your calculation that one light year is equal to 9.461 × 10<sup>12</sup> kilometers.
</p>
<p>
A succeeding data set, if any, starts from the line immediately following the last line of the
preceding data set.
</p>
<H2>Output</H2>
<p>
For each data set, one line should be output. That line should contain the point numbers of the
three vertices of the similar triangle, separated by a space character. They should be reported
in the order P, Q, and then R.
</p>
<H2>Sample Input</H2>
<pre>
2
50.36493 81.61338 79.96592
5
-10293.83 -4800.033 -5296.238
14936.30 6964.826 7684.818
-4516.069 25748.41 -27016.06
18301.59 -11946.25 5380.309
27115.20 43415.93 -71607.81
11.51547 13.35555 14.57307
5
-56292.27 2583.892 67754.62
-567.5082 -756.2763 -118.7268
-1235.987 -213.3318 -216.4862
-317.6108 -54.81976 -55.63033
22505.44 -40752.88 27482.94
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1 2 4
3 4 2
</pre>
|
p02251 | <h1>Change-Making Problem</h1>
<p>You want to make change for $n$ cents. Assuming that you have infinite supply of coins of 1, 5, 10 and/or 25 cents coins respectively, find the minimum number of coins you need.</p>
<h2>Input</h2>
<pre>
$n$
</pre>
<p>The integer $n$ is given in a line.</p>
<h2>åºå</h2>
<p>Print the minimum number of coins you need in a line.</p>
<h2>Constraints</h2>
<ul>
<li>$1 \le n \le 10^9$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
100
</pre>
<h2>Sample Output 1</h2>
<pre>
4
</pre>
<h2>Sample Input 2</h2>
<pre>
54321
</pre>
<h2>Sample Output 2</h2>
<pre>
2175
</pre>
|
p03913 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Rng is baking cookies.</p>
<p>Initially, he can bake one cookie per second.</p>
<p>He can also eat the cookies baked by himself.
When there are <var>x</var> cookies not yet eaten, he can choose to eat all those cookies. After he finishes eating those cookies, the number of cookies he can bake per second becomes <var>x</var>. Note that a cookie always needs to be baked for <var>1</var> second, that is, he cannot bake a cookie in <var>1/x</var> seconds when <var>x > 1</var>.
When he choose to eat the cookies, he must eat all of them; he cannot choose to eat only part of them.
It takes him <var>A</var> seconds to eat the cookies regardless of how many, during which no cookies can be baked.</p>
<p>He wants to give <var>N</var> cookies to Grandma.
Find the shortest time needed to produce at least <var>N</var> cookies not yet eaten.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1âŠNâŠ10^{12}</var></li>
<li><var>0âŠAâŠ10^{12}</var></li>
<li><var>A</var> is an integer.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li><var>500</var> points will be awarded for passing the test set satisfying <var>NâŠ10^6</var> and <var>AâŠ10^6</var>.</li>
<li>Additional <var>500</var> points will be awarded for passing the test set without additional constraints.</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</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the shortest time needed to produce at least <var>N</var> cookies not yet eaten.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>8 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7
</pre>
<p>It is possible to produce <var>8</var> cookies in <var>7</var> seconds, as follows:</p>
<ul>
<li>After <var>1</var> second: <var>1</var> cookie is done.</li>
<li>After <var>2</var> seconds: <var>1</var> more cookie is done, totaling <var>2</var>. Now, Rng starts eating those <var>2</var> cookies.</li>
<li>After <var>3</var> seconds: He finishes eating the cookies, and he can now bake <var>2</var> cookies per second.</li>
<li>After <var>4</var> seconds: <var>2</var> cookies are done.</li>
<li>After <var>5</var> seconds: <var>2</var> more cookies are done, totaling <var>4</var>.</li>
<li>After <var>6</var> seconds: <var>2</var> more cookies are done, totaling <var>6</var>.</li>
<li>After <var>7</var> seconds: <var>2</var> more cookies are done, totaling <var>8</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1000000000000 1000000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1000000000000
</pre></section>
</div>
</span> |
p02601 | <span class="lang-en">
<p>Score: <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>M-kun has the following three cards:</p>
<ul>
<li>A red card with the integer <var>A</var>.</li>
<li>A green card with the integer <var>B</var>.</li>
<li>A blue card with the integer <var>C</var>.</li>
</ul>
<p>He is a genius magician who can do the following operation at most <var>K</var> times:</p>
<ul>
<li>Choose one of the three cards and multiply the written integer by <var>2</var>.</li>
</ul>
<p>His magic is successful if both of the following conditions are satisfied after the operations:</p>
<ul>
<li>The integer on the green card is <strong>strictly</strong> greater than the integer on the red card.</li>
<li>The integer on the blue card is <strong>strictly</strong> greater than the integer on the green card.</li>
</ul>
<p>Determine whether the magic can be successful.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq A, B, C \leq 7</var></li>
<li><var>1 \leq K \leq 7</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>C</var>
<var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>If the magic can be successful, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7 2 5
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>The magic will be successful if, for example, he does the following operations:</p>
<ul>
<li>First, choose the blue card. The integers on the red, green, and blue cards are now <var>7</var>, <var>2</var>, and <var>10</var>, respectively.</li>
<li>Second, choose the green card. The integers on the red, green, and blue cards are now <var>7</var>, <var>4</var>, and <var>10</var>, respectively.</li>
<li>Third, choose the green card. The integers on the red, green, and blue cards are now <var>7</var>, <var>8</var>, and <var>10</var>, respectively.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7 4 2
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>He has no way to succeed in the magic with at most three operations.</p></section>
</div>
</span> |
p01187 |
<H1><font color="#000">Problem G:</font> Make Friendships</H1>
<p>
Isaac H. Ives attended an international student party and made a lot of girl friends (as many other persons
expected). To strike up a good friendship with them, he decided to have dates with them. However, it
is hard for him to schedule dates because he made so many friends. Thus he decided to find the best
schedule using a computer program. The most important criterion in scheduling is how many different
girl friends he will date. Of course, the more friends he will date, the better the schedule is. However,
though he has the ability to write a program finding the best schedule, he doesnât have enough time to
write it.
</p>
<p>
Your task is to write a program to find the best schedule instead of him.
</p>
<H2>Input</H2>
<p>
The input consists of a series of data sets. The first line of each data set contains a single positive integer
<i>N</i> (<i>N</i> ≤ 1,000) that represents the number of persons Isaac made friends with in the party. The next line
gives Isaacâs schedule, followed by <i>N</i> lines that give his new friendsâ schedules. Each schedule consists of
a positive integer <i>M</i> that represents the number of available days followed by <i>M</i> positive integers each
of which represents an available day.
</p>
<p>
The input is terminated by a line that contains a single zero. This is not part of data sets and should
not be processed.
</p>
<H2>Output</H2>
<p>
For each data set, print a line that contains the maximum number of girl friends Isaac can have dates
with.
</p>
<H2>Sample Input</H2>
<pre>
3
3 1 3 5
2 1 4
4 1 2 3 6
1 3
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
</pre>
|
p03440 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a forest with <var>N</var> vertices and <var>M</var> edges. The vertices are numbered <var>0</var> through <var>N-1</var>.
The edges are given in the format <var>(x_i,y_i)</var>, which means that Vertex <var>x_i</var> and <var>y_i</var> are connected by an edge.</p>
<p>Each vertex <var>i</var> has a value <var>a_i</var>.
You want to add edges in the given forest so that the forest becomes connected.
To add an edge, you choose two different vertices <var>i</var> and <var>j</var>, then span an edge between <var>i</var> and <var>j</var>.
This operation costs <var>a_i + a_j</var> dollars, and afterward neither Vertex <var>i</var> nor <var>j</var> can be selected again.</p>
<p>Find the minimum total cost required to make the forest connected, or print <code>Impossible</code> if it is impossible.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N †100,000</var></li>
<li><var>0 †M †N-1</var></li>
<li><var>1 †a_i †10^9</var></li>
<li><var>0 †x_i,y_i †N-1</var></li>
<li>The given graph is a forest.</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>M</var>
<var>a_0</var> <var>a_1</var> <var>..</var> <var>a_{N-1}</var>
<var>x_1</var> <var>y_1</var>
<var>x_2</var> <var>y_2</var>
<var>:</var>
<var>x_M</var> <var>y_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum total cost required to make the forest connected, or print <code>Impossible</code> if it is impossible.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7 5
1 2 3 4 5 6 7
3 0
4 0
1 2
1 3
5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7
</pre>
<p>If we connect vertices <var>0</var> and <var>5</var>, the graph becomes connected, for the cost of <var>1 + 6 = 7</var> dollars.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 0
3 1 4 1 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Impossible
</pre>
<p>We can't make the graph connected.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 0
5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>The graph is already connected, so we do not need to add any edges.</p></section>
</div>
</span> |
p03010 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Diverta City is a new city consisting of <var>N</var> towns numbered <var>1, 2, ..., N</var>.</p>
<p>The mayor Ringo is planning to connect every pair of two different towns with a bidirectional road. The length of each road is undecided.</p>
<p>A <em>Hamiltonian path</em> is a path that starts at one of the towns and visits each of the other towns exactly once.
The reversal of a Hamiltonian path is considered the same as the original Hamiltonian path.</p>
<p>There are <var>N! / 2</var> Hamiltonian paths. Ringo wants all these paths to have distinct total lengths (the sum of the lengths of the roads on a path), to make the city diverse.</p>
<p>Find one such set of the lengths of the roads, under the following conditions:</p>
<ul>
<li>The length of each road must be a positive integer.</li>
<li>The maximum total length of a Hamiltonian path must be at most <var>10^{11}</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>N</var> is a integer between <var>2</var> and <var>10</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>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print a set of the lengths of the roads that meets the objective, in the following format:</p>
<pre><var>w_{1, 1} \ w_{1, 2} \ w_{1, 3} \ ... \ w_{1, N}</var>
<var>w_{2, 1} \ w_{2, 2} \ w_{2, 3} \ ... \ w_{2, N}</var>
<var>:</var> <var>:</var> <var>:</var>
<var>w_{N, 1} \ w_{N, 2} \ w_{N, 3} \ ... \ w_{N, N}</var>
</pre>
<p>where <var>w_{i, j}</var> is the length of the road connecting Town <var>i</var> and Town <var>j</var>, which must satisfy the following conditions:</p>
<ul>
<li><var>w_{i, i} = 0</var></li>
<li><var>w_{i, j} = w_{j, i} \ (i \neq j)</var></li>
<li><var>1 \leq w_{i, j} \leq 10^{11} \ (i \neq j)</var></li>
</ul>
<p>If there are multiple sets of lengths of the roads that meet the objective, any of them will be accepted.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0 6 15
6 0 21
15 21 0
</pre>
<p>There are three Hamiltonian paths. The total lengths of these paths are as follows: </p>
<ul>
<li><var>1 â 2 â 3</var>: The total length is <var>6 + 21 = 27</var>.</li>
<li><var>1 â 3 â 2</var>: The total length is <var>15 + 21 = 36</var>.</li>
<li><var>2 â 1 â 3</var>: The total length is <var>6 + 15 = 21</var>.</li>
</ul>
<p>They are distinct, so the objective is met.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0 111 157 193
111 0 224 239
157 224 0 258
193 239 258 0
</pre>
<p>There are <var>12</var> Hamiltonian paths, with distinct total lengths.</p></section>
</div>
</span> |
p01703 |
<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>
<meta http-equiv="X-UA-Compatible" CONTENT="IE=EmulateIE7" /><style type="text/css">blockquote {
font-family: Menlo, Monaco, "Courier New", monospace;
color: #333333;
display: block;
padding: 8.5px;
margin: 0 0 9px;
font-size: 12px;
line-height: 18px;
background-color: #f5f5f5;
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, 0.15);
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
white-space: pre;
white-space: pre-wrap;
word-break: break-all;
word-wrap: break-word;
}</style><div class="part"><h3>Problem Statement</h3><p><i>Infinite Chronicle -Princess Castle-</i> is a simple role-playing game.
There are $n + 1$ checkpoints, numbered $0$ through $n$,
and for each $i = 1, 2, \ldots, n$, there is a unique one-way road running from checkpoint $i - 1$ to $i$.
The game starts at checkpoint $0$ and ends at checkpoint $n$.
Evil monsters will appear on the roads and the hero will have battles against them.
You can save your game progress at any checkpoint; if you lose a battle, you can restart the game from the checkpoint where you have saved for the last time.
At the beginning of the game, the progress is automatically saved at checkpoint $0$ with no time.
</p>
<p>Rabbit Hanako is fond of this game and now interested in speedrunning.
Although Hanako is an expert of the game, she cannot always win the battles because of random factors.
For each $i$, she estimated the probability $p_i$ to win all the battles along the road from checkpoint $i - 1$ to $i$.
Everytime she starts at checkpoint $i - 1$, after exactly one miniutes,
she will be at checkpoint $i$ with probability $p_i$ and where she saved for the last time with probability $1 - p_i$.
</p>
<p>What puzzles Hanako is that it also takes one minute (!) to save your progress at a checkpoint,
so it might be a good idea to pass some checkpoints without saving in order to proceed quickly.
The task is to compute the minimum possible expected time needed to complete the game.
</p>
</div><div class="part"><h3>Input</h3>
<p>The input consists of multiple datasets. The number of datasets is no more than $50$.
Each dataset has two lines: the first line contains an integer $n$ ($1 \le n \le 10^5$), representing the number of roads,
and the second line contains $n$ numbers $p_1, p_2, \ldots, p_n$ ($0 \lt p_i \le 1$), representing the winning probabilities.
Each $p_i$ has exactly two digits after the decimal point.
The end of input is denoted as a line containing only a single zero.
</p>
</div><div class="part"><h3>Output</h3>
<p>For each dataset, display the minimum expected time in minutes with a relative error of at most $10^{-8}$ in a line.
</p>
</div><div class="part"><h3>Sample Input</h3>
<pre>2
0.50 0.40
2
0.70 0.60
4
0.99 1.00 1.00 0.01
0</pre>
</div><div class="part"><h3>Output for the Sample Input</h3>
<pre>5.5000000000
4.0476190476
104.0101010101</pre>
</div> |
p00811 | <H1><font color="#000">Problem A:</font> Calling Extraterrestrial Intelligence Again</H1>
<p>
A message from humans to extraterrestrial intelligence was sent through the Arecibo radio telescope in Puerto Rico on the afternoon of Saturday November l6, l974. The message consisted of l679 bits and was meant to be translated to a rectangular picture with 23 × 73 pixels. Since both 23 and 73 are prime numbers, 23 × 73 is the unique possible size of the translated rectangular picture each edge of which is longer than l pixel. Of course, there was no guarantee that the receivers would try to translate the message to a rectangular picture. Even if they would, they might put the pixels into the rectangle incorrectly. The senders of the Arecibo message were optimistic.
</p>
<p>
We are planning a similar project. Your task in the project is to find the most suitable width and height of the translated rectangular picture. The term ``most suitable'' is defined as follows. An integer m greater than 4 is given. A positive fraction <i>a</i>/<i>b</i> less than or equal to 1 is also given. The area of the picture should not be greater than <i>m</i>. Both of the width and the height of the translated picture should be prime numbers. The ratio of the width to the height should not be less than <i>a</i>/<i>b</i> nor greater than 1. You should maximize the area of the picture under these constraints.
</p>
<p>
In other words, you will receive an integer <i>m</i> and a fraction <i>a</i>/<i>b</i> . It holds that <i>m</i> > 4 and 0 < <i>a</i>/<i>b</i> ≤ 1 . You should find the pair of prime numbers <i>p</i>, <i>q</i> such that <i>pq</i> ≤ <i>m</i> and <i>a</i>/<i>b</i> ≤ <i>p</i>/<i>q</i> ≤ 1 , and furthermore, the product <i>pq</i> takes the maximum value among such pairs of two prime numbers. You should report <i>p</i> and <i>q</i> as the "most suitable" width and height of the translated picture.
</p>
<H2>Input</H2>
<p>
The input is a sequence of at most 2000 triplets of positive integers, delimited by a space character in between. Each line contains a single triplet. The sequence is followed by a triplet of zeros, 0 0 0, which indicates the end of the input and should not be treated as data to be processed.
</p>
<p>
The integers of each input triplet are the integer <i>m</i>, the numerator <i>a</i>, and the denominator <i>b</i> described above, in this order. You may assume 4 < <i>m</i> < 100000 and 1 ≤ <i>a</i> ≤ <i>b</i> ≤ 1000.
</p>
<H2>Output</H2>
<p>
The output is a sequence of pairs of positive integers. The <i>i</i>-th output pair corresponds to the <i>i</i>-th input triplet. The integers of each output pair are the width <i>p</i> and the height <i>q</i> described above, in this order.
</p>
<p>
Each output line contains a single pair. A space character is put between the integers as a delimiter. No other characters should appear in the output.
</p>
<H2>Sample Input</H2>
<pre>
5 1 2
99999 999 999
1680 5 16
1970 1 1
2002 4 11
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2 2
313 313
23 73
43 43
37 53
</pre>
|
p01353 |
<H1>Problem E: Rabbit Plays Games!</H1>
<p>
ãããããšããããŒã«ãã¬ã€ã³ã°ã²ãŒã ã§éãã§ãã. åã«å
¥ãçŽåã§, æµã«åŸ
ã¡äŒããããŠããïŒ
</p>
<p>
ããããæäœãã䞻人å
¬1 人ãš, <i>n</i> äœã®æµãšã®æŠéãšãªã£ã. åãã£ã©ã¯ã¿ãŒã«ã¯4 ã€ã®èœåå€, äœå<i>h<sub>i</sub></i>, æ»æå<i>a<sub>i</sub></i>, é²åŸ¡å<i>d<sub>i</sub></i>, ææ·<i>s<sub>i</sub></i> ãå®ããããŠãã. <i>i</i> = 0 ã¯äž»äººå
¬ã®æ
å ±, 1 ≤ <i>i</i> ≤ <i>n</i> ã¯åæµã®æ
å ±ã衚ã.
</p>
<p>
æŠéã¯ã¿ãŒã³å¶ã§ãã. åã¿ãŒã³, çãæ®ã£ãŠãããã£ã©ã¯ã¿ãŒã, ææ·ã®å€ãé«ãé ã«æ»æãè¡ã. æµã¯å¿
ã䞻人å
¬ãæ»æãã. 䞻人å
¬ã¯æµ1 äœãæ»æããã, ã©ã®æµãæ»æãããã¯æ¯ã¿ãŒã³ããšã«äž»äººå
¬ãéžã¹ã.æ»æå<i>a</i> ã®ãã£ã©ã¯ã¿ãŒãé²åŸ¡å<i>d</i> ã®ãã£ã©ã¯ã¿ãŒã«æ»æãããšã, max{<i>a</i> â <i>d</i>, 0} ã®ãã¡ãŒãžãäžãããã. åãããã¡ãŒãžã®åèšãäœåã®å€ä»¥äžã«ãªã£ããã£ã©ã¯ã¿ãŒã¯çŽã¡ã«æŠéäžèœã«ãªã£ãŠããŸã. 䞻人å
¬ãæŠéäžèœã«ãªã£ããšã, ãããã¯æµããã¹ãŠæŠéäžèœã«ãªã£ããšã, æŠéã¯çµäºãã.
</p>
<H2>Input</H2>
<p>
1 ≤ <i>n</i> ≤ 40 000<br>
1 ≤ <i>h<sub>i</sub></i>, <i>a<sub>i</sub></i>, <i>d<sub>i</sub></i>, <i>s<sub>i</sub></i> ≤ 1 000 000 000 (æŽæ°)<br>
<i>s<sub>i</sub></i> ã¯ãã¹ãŠç°ãªã.<br>
</p>
<H2>Output</H2>
<p>
䞻人å
¬ãå¿
ãæŠéäžèœã«ãªã£ãŠããŸããšã, â1 ãåºåãã. ããã§ãªããšã, 䞻人å
¬ãåãããã¡ãŒãžã®åèšã®æå°å€ãäžè¡ã«åºåãã.
</p>
<H2>Sample Input 1</H2>
<pre>
2
10 3 1 2
2 4 1 3
2 2 1 1
</pre>
<H2>Sample Output 1</H2>
<pre>
4
</pre>
<H2>Sample Input 2</H2>
<pre>
1
1 1 1 1
10000 10000 10000 10000
</pre>
<H2>Sample Output 2</H2>
<pre>
-1
</pre>
|
p03694 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>It is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts.<br/>
There are <var>N</var> houses along <em>TopCoDeer street</em>. The <var>i</var>-th house is located at coordinate <var>a_i</var>. He has decided to deliver gifts to all these houses.<br/>
Find the minimum distance to be traveled when AtCoDeer can start and end his travel at any positions. </p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N †100</var></li>
<li><var>0 †a_i †1000</var></li>
<li><var>a_i</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum distance to be traveled. </p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
2 3 7 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7
</pre>
<p>The travel distance of <var>7</var> can be achieved by starting at coordinate <var>9</var> and traveling straight to coordinate <var>2</var>.<br/>
It is not possible to do with a travel distance of less than <var>7</var>, and thus <var>7</var> is the minimum distance to be traveled. </p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>8
3 1 4 1 5 9 2 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>8
</pre>
<p>There may be more than one house at a position. </p></section>
</div>
</span> |
p02986 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a tree with <var>N</var> vertices numbered <var>1</var> to <var>N</var>.
The <var>i</var>-th edge in this tree connects Vertex <var>a_i</var> and Vertex <var>b_i</var>, and the color and length of that edge are <var>c_i</var> and <var>d_i</var>, respectively.
Here the color of each edge is represented by an integer between <var>1</var> and <var>N-1</var> (inclusive). The same integer corresponds to the same color, and different integers correspond to different colors.</p>
<p>Answer the following <var>Q</var> queries:</p>
<ul>
<li>Query <var>j</var> (<var>1 \leq j \leq Q</var>): assuming that the length of every edge whose color is <var>x_j</var> is changed to <var>y_j</var>, find the distance between Vertex <var>u_j</var> and Vertex <var>v_j</var>. (The changes of the lengths of edges do not affect the subsequent queries.)</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10^5</var></li>
<li><var>1 \leq Q \leq 10^5</var></li>
<li><var>1 \leq a_i, b_i \leq N</var></li>
<li><var>1 \leq c_i \leq N-1</var></li>
<li><var>1 \leq d_i \leq 10^4</var></li>
<li><var>1 \leq x_j \leq N-1</var></li>
<li><var>1 \leq y_j \leq 10^4</var></li>
<li><var>1 \leq u_j < v_j \leq N</var></li>
<li>The given graph is a tree.</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>a_1</var> <var>b_1</var> <var>c_1</var> <var>d_1</var>
<var>:</var>
<var>a_{N-1}</var> <var>b_{N-1}</var> <var>c_{N-1}</var> <var>d_{N-1}</var>
<var>x_1</var> <var>y_1</var> <var>u_1</var> <var>v_1</var>
<var>:</var>
<var>x_Q</var> <var>y_Q</var> <var>u_Q</var> <var>v_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>Q</var> lines. The <var>j</var>-th line (<var>1 \leq j \leq Q</var>) should contain the answer to Query <var>j</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 3
1 2 1 10
1 3 2 20
2 4 4 30
5 2 1 40
1 100 1 4
1 100 1 5
3 1000 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>130
200
60
</pre>
<p>The graph in this input is as follows:</p>
<p><img alt="Figure" src="https://img.atcoder.jp/ghi/ca75688b08f73eb63a30ce6daa54a781.png"/></p>
<p>Here the edges of Color <var>1</var> are shown as solid red lines, the edge of Color <var>2</var> is shown as a bold green line, and the edge of Color <var>4</var> is shown as a blue dashed line.</p>
<ul>
<li>Query <var>1</var>: Assuming that the length of every edge whose color is <var>1</var> is changed to <var>100</var>, the distance between Vertex <var>1</var> and Vertex <var>4</var> is <var>100 + 30 = 130</var>.</li>
<li>Query <var>2</var>: Assuming that the length of every edge whose color is <var>1</var> is changed to <var>100</var>, the distance between Vertex <var>1</var> and Vertex <var>5</var> is <var>100 + 100 = 200</var>.</li>
<li>Query <var>3</var>: Assuming that the length of every edge whose color is <var>3</var> is changed to <var>1000</var> (there is no such edge), the distance between Vertex <var>3</var> and Vertex <var>4</var> is <var>20 + 10 + 30 = 60</var>. Note that the edges of Color <var>1</var> now have their original lengths.</li>
</ul></section>
</div>
</span> |
p00112 |
<h1>ãã«ã¯ã·ã§ãã</h1>
<p>
éŽæšããã¯äŒæŽ¥å°åã«æ°ããæŸãããŠãã«ã¯ã®ç§»å販売ã®ãåºãéããŸããããã®æ¥è²·ãæ±ãã«æ¥ãã客ããã¯å
šå¡æã¡åž°ãããã®ããã«ãæã£ãŠæ¢ã«ãåºã«äžŠãã§ããŠããã以äžå¢ããªããã®ãšããŸããã客ããã¯ãããã1åã ãããæ³šæããŸãããã¿ã³ã¯ã®èå£ãäžã€ãããªãã®ã§ãäžäººãã€é çªã«è²©å£²ããªããã°ãªããŸãããããã§ãéŽæšããã¯ãªãã¹ã䞊ãã§ããã客ããã®åŸ
ã¡æéãå°ãªãããããšèããŠããŸãã
</p>
<p>
ã客ããã®äººæ°ãšã客ãããçä¹³ãæ³šãããã®ã«èŠããæéãå
¥åãšããŠäžããããŸããããªãã¯ã客ããã®ãäžäººäžäººã®åŸ
ã¡æéã®åèšã(以äžãåŸ
ã¡æéã®åèšããšãã)ãæå°ã«ããããã®æ³šæã®é åºãéŽæšããã«ä»£ãã£ãŠèª¿ã¹ããã®ãšãã®ãåŸ
ã¡æéã®åèšããåºåããŠçµäºããããã°ã©ã ãäœæããŠãã ããããã ããã客ãã㯠10,000 人以äžã§ 1 人ãããã«èŠããæé㯠60 å以äžãšããŸãã
</p>
<p>
äŸãã°ãã客ããã®äººæ°ã 5 人ã§ãåã客ãããèŠããæéãé ã« 2,6,4,3,9 åã®å Žåããã®ãŸãŸã®é åºã ãšãåŸ
ã¡æéã®åèšã㯠37 åã«ãªããŸããæ¬¡ã®äŸã§ã¯ãæåã®åã®é ã® 2 人ç®ãš 3 人ç®ãå
¥ãæ¿ããŠããŸãããã®å ŽåããåŸ
ã¡æéã®åèšã㯠35 åã«ãªããŸããæé©ãªé åºã ãš 31 åã§æžã¿ãŸãã
</p>
<table>
<tr><td width="110"></td><td>åŸ
ã¡æé</td><td></td></tr>
<tr><td>1 äººç® 2 å</td><td> 0 å</td><td></td></tr>
<tr><td>2 äººç® 6 å</td><td> 2 å</td><td></td></tr>
<tr><td>3 äººç® 4 å</td><td> 8 å</td><td></td></tr>
<tr><td>4 äººç® 3 å</td><td> 12 å</td><td></td></tr>
<tr><td>5 äººç® 9 å</td><td> 15 å</td><td></td></tr>
<tr><td></td><td> 37 å</td><td> â ãåŸ
ã¡æéã®åèšã</td></tr>
</table>
<br/>
<p>
2 人ç®ãš 3 人ç®ãå
¥ãæ¿ããäŸ
</p>
<table>
<tr><td width="110"></td><td>åŸ
ã¡æé</td><td></td></tr>
<tr><td>1 äººç® 2 å</td><td align="right"> 0 å</td><td></td></tr>
<tr><td>2 äººç® 4 å</td><td> 2 å</td><td></td></tr>
<tr><td>3 äººç® 6 å</td><td> 6 å</td><td></td></tr>
<tr><td>4 äººç® 3 å</td><td> 12 å</td><td></td></tr>
<tr><td>5 äººç® 9 å</td><td> 15 å</td><td></td></tr>
<tr><td> </td><td> 35 å</td><td> â ãåŸ
ã¡æéã®åèšã</td></tr>
</table>
<br/>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var>
<var>t<sub>1</sub></var>
<var>t<sub>2</sub></var>
:
<var>t<sub>n</sub></var>
</pre>
<p>
1 è¡ç®ã«ã客ããã®äººæ° <var>n</var> (<var>n</var> ≤ 10,000) ãäžããããŸããç¶ã <var>n</var> è¡ã« <var>i</var> 人ç®ã®ã客ãããèŠããæéãè¡šãæŽæ° <var>t<sub>i</sub></var> (0 ≤ <var>t<sub>i</sub></var> ≤ 60) ãããããïŒè¡ã«äžããããŸãã
</p>
<p>
å
¥åã¯ïŒã€ã® 0 ãå«ãè¡ã§çµãããŸããããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
åããŒã¿ã»ããããšã«ãåŸ
ã¡æéã®åèš(æŽæ°)ãïŒè¡ã«åºåããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
5
2
6
4
3
9
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
31
</pre>
|
p00542 |
<h1>ç§ç®éžæ (Selecting Subjects)</h1>
<h2> åé¡</h2>
<p>
JOI åã¯ç©çïŒååŠïŒçç©ïŒå°åŠïŒæŽå²ïŒå°çã® 6 ç§ç®ã®ãã¹ããåããïŒ
ããããã®ãã¹ã㯠100 ç¹æºç¹ã§æ¡ç¹ãããïŒ
</p>
<p>
JOI åã¯ç©çïŒååŠïŒçç©ïŒå°åŠã® 4 ç§ç®ãã 3 ç§ç®ãéžæãïŒæŽå²ïŒå°çã® 2 ç§ç®ãã 1 ç§ç®ãéžæããïŒ
</p>
<p>
ãã¹ãã®åèšç¹ãæãé«ããªãããã«ç§ç®ãéžã¶ãšãïŒ
JOI åã®éžãã ç§ç®ã®ãã¹ãã®åèšç¹ãæ±ããïŒ
</p>
<h2> å
¥å</h2>
<p>
å
¥å㯠6 è¡ãããªãïŒ1 è¡ã« 1 ã€ãã€æŽæ°ãæžãããŠããïŒ
</p>
<p>
1 è¡ç®ã«ã¯ JOI åã®ç©çã®ãã¹ãã®ç¹æ° A ãæžãããŠããïŒ<br>
2 è¡ç®ã«ã¯ JOI åã®ååŠã®ãã¹ãã®ç¹æ° B ãæžãããŠããïŒ<br>
3 è¡ç®ã«ã¯ JOI åã®çç©ã®ãã¹ãã®ç¹æ° C ãæžãããŠããïŒ<br>
4 è¡ç®ã«ã¯ JOI åã®å°åŠã®ãã¹ãã®ç¹æ° D ãæžãããŠããïŒ<br>
5 è¡ç®ã«ã¯ JOI åã®æŽå²ã®ãã¹ãã®ç¹æ° E ãæžãããŠããïŒ<br>
6 è¡ç®ã«ã¯ JOI åã®å°çã®ãã¹ãã®ç¹æ° F ãæžãããŠããïŒ
</p>
<p>
æžãããŠããæŽæ° A, B, C, D, E, F ã¯ãã¹ãŠ 0 ä»¥äž 100 以äžã§ããïŒ
</p>
<h2> åºå</h2>
<p>
JOI åãéžãã ç§ç®ã®ãã¹ãã®åèšç¹ã 1 è¡ã§åºåããïŒ
</p>
<h2> å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
100
34
76
42
10
0
</pre>
<h3>åºåäŸ 1</h3>
<pre>
228</pre>
<h3>å
¥åäŸ 2</h3>
<pre>
15
21
15
42
15
62
</pre>
<h3>åºåäŸ 2</h3>
<pre>
140</pre>
<p>
å
¥åºåäŸ 1 ã§ã¯ïŒJOI åãç©çïŒçç©ïŒå°åŠïŒæŽå²ã® 4 ç§ç®ãéžã¶ãšãïŒãã¹ãã®åèšç¹ãæé«ã«ãªãïŒ
</p>
<p>
ç©çïŒçç©ïŒå°åŠïŒæŽå²ã®ç¹æ°ã¯ãããã 100, 76, 42, 10 ãªã®ã§ïŒéžãã ç§ç®ã®ãã¹ãã®åèšç¹ã¯ 228 ã§ããïŒ
</p>
<p>
å
¥åºåäŸ 2 ã§ã¯ïŒJOI åãååŠïŒçç©ïŒå°åŠïŒå°çã® 4 ç§ç®ãéžã¶ãšãïŒãã¹ãã®åèšç¹ãæé«ã«ãªãïŒ
</p>
<p>
ååŠïŒçç©ïŒå°åŠïŒå°çã®ç¹æ°ã¯ãããã 21, 15, 42, 62 ãªã®ã§ïŒéžãã ç§ç®ã®ãã¹ãã®åèšç¹ã¯ 140 ã§ããïŒ
</p>
<p>
å
¥åºåäŸ 2 ã§ã¯ïŒJOI åãç©çïŒååŠïŒå°åŠïŒå°çã® 4 ç§ç®ãéžã¶å Žåã§ãïŒéžãã ãã¹ãã®åèšç¹ã¯ 140 ã§ããïŒ
</p>
<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-yo/index.html">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第 15 åæ¥æ¬æ
å ±ãªãªã³ãã㯠JOI 2015/2016 äºéžç«¶æèª²é¡ã</a>
</p>
</div>
|
p02085 |
<h1>H: Permutation Score</h1>
<h2>å顿</h2>
<p>æŸåŽããã¯é åã倧奜ãã§ãã仿¥ã¯é åã«ãã£ãŠå®ãŸãããµã€ã¯ã«æ£®ãã«ã€ããŠèããããšã«ããŸããã</p>
<p>$1$ ãã $k$ ãŸã§ã®é å $p = (p_1, \ldots, p_k)$ ã«å¯Ÿãã$p$ ã«ãã£ãŠå®ãŸããµã€ã¯ã«æ£®ããšã¯ã以äžã®2æ¡ä»¶ãæºããã°ã©ã $G(p)$ ãæããŸã:</p>
<ul>
<li>$G(p)$ 㯠$k$ é ç¹ãããªããããããã®é ç¹ã«ã¯ $1$ ãã $k$ ã®çªå·ãä»ããããŠããã</li>
<li>$i=1, \ldots, k$ ã«ã€ããŠãé ç¹ $i$ ãšé ç¹ $p_i$ ã®éã«èŸºã匵ãããŠããïŒèªå·±ã«ãŒãããã³å€é蟺ãèš±ããå¿
ã $k$ æ¬ã®èŸºã匵ãïŒãéã«ã$G(p)$ã«ã¯ããã $k$ æ¬ä»¥å€ã®èŸºã¯ååšããªãã</li>
</ul>
<p>é å $p$ ã®ã¹ã³ã¢ $f(p)$ ããã$G(p)$ ã®é£çµæåã®å€§ããã®ç·ç©ããšããŠå®çŸ©ããŸããäŸãã° $p = (2, 1, 4, 3)$ ãªãã° $f(p) = 4$ã$p = (2, 3, 1, 4)$ ãªãã° $f(p) = 3$ã§ãã</p>
<p>æ£æŽæ° $N$ ãäžããããŸããé·ã $N$ ã®é å㯠$N!$ éãèããããŸããããããå
šãŠã®é åã®ã¹ã³ã¢ã®åæ£ã¯ããã€ã«ãªããæ±ããŠãã ããã</p>
<p>å
šãŠã®é åã®ã¹ã³ã¢ã®åæ£ãšã¯ä»¥äžã®ããã«å®çŸ©ãããŸã:</p>
<ol>
<li>ãŸãã$P$ ã $N!$ åã®é åå
šãŠãããªãéåãšããŸãã</li>
<li>ã¹ã³ã¢ã®å¹³åã$a = \frac{1}{N!} \sum_{p \in P} f(p)$ ãšãããŸãã</li>
<li>ãã®æãå
šãŠã®é åã®ã¹ã³ã¢ã®åæ£ã¯ $\frac{1}{N!} \sum_{p \in P} (f(p) - a)^2$ ãšããŠå®çŸ©ãããŸãã</li>
</ol>
<p>å
¥åã®å¶çŽäžã«ãããŠãæ±ããå€ã¯ä»¥äžã®æ¡ä»¶ãæºããæçæ° $\frac{q}{p}$ ãšããŠè¡šããããšã蚌æã§ããŸã:</p>
<ul>
<li>$p$ ãš $q$ ã¯äºãã«çŽ ãªéè² æŽæ°ã§ããã</li>
<li>$p$ 㯠$10^9+7$ ã®åæ°ã«ãªããã$p \cdot r \equiv q (\bmod 10^9+7)$ ãªãæŽæ° $r$ãååšããã</li>
</ul>
<p>忣ã®å€ã®ä»£ããã« $r \bmod 10^9+7$ãåºåããŠãã ããã</p>
<h2>å¶çŽ</h2>
<ul>
<li>å
¥åã¯å
šãп޿°</li>
<li>$1 \leq N \leq 10^5$</li>
</ul>
<h2>å
¥å</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããŸãã</p>
<pre>$N$</pre>
<h2>åºå</h2>
<p>å顿äžã§æå®ãããå€ $r \bmod 10^9+7$ ã1è¡ã«åºåããŠãã ããã</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ1</h3>
<pre>1
</pre>
<h3>åºåäŸ1</h3>
<pre>0
</pre>
<p>é·ã1ã®é åã¯1ã€ã®ã¿ã§ããã忣ã¯0ã«ãªããŸãã</p>
<h3>å
¥åäŸ2</h3>
<pre>3
</pre>
<h3>åºåäŸ2</h3>
<pre>472222226
</pre>
<p>忣ã®å€ã¯ $\frac{17}{36}$ã§ãããå顿äžã®æç€ºã«åŸã£ãŠ $17 \times 27777778 \bmod 10^9+7 = 472222226$ ãåºåããŠãã ããã</p>
<h3>å
¥åäŸ3</h3>
<pre>10
</pre>
<h3>åºåäŸ3</h3>
<pre>309669455
</pre>
|
p02590 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Letâs take a prime <var>P = 200\,003</var>.
You are given <var>N</var> integers <var>A_1, A_2, \ldots, A_N</var>.
Find the sum of <var>((A_i \cdot A_j) \bmod P)</var> over all <var>N \cdot (N-1) / 2</var> unordered pairs of elements (<var>i < j</var>).</p>
<p>Please note that the sum isn't computed modulo <var>P</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 200\,000</var></li>
<li><var>0 \leq A_i < P = 200\,003</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format.</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> <var>\cdots</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print one integer â the sum over <var>((A_i \cdot A_j) \bmod P)</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
2019 0 2020 200002
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>474287
</pre>
<p>The non-zero products are:</p>
<ul>
<li><var>2019 \cdot 2020 \bmod P = 78320</var></li>
<li><var>2019 \cdot 200002 \bmod P = 197984</var></li>
<li><var>2020 \cdot 200002 \bmod P = 197983</var></li>
</ul>
<p>So the answer is <var>0 + 78320 + 197984 + 0 + 0 + 197983 = 474287</var>. </p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
1 1 2 2 100000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>600013
</pre></section>
</div>
</span> |
p00057 |
<H1>é åã®æ°</H1>
<p>
ç¡éã«åºãå¹³é¢ã®äžã«ãç¡éã«é·ãçŽç·ãæ°æ¬åŒããšããã®å¹³é¢ã¯ããã€ãã®é åã«åå²ãããŸããããšãã°ãçŽç·ãïŒæ¬åŒããšãå¹³é¢ã¯ïŒã€ã®é åã«åå²ãããŸããåãæ°ã®çŽç·ãåŒããŠããåŒãæ¹ã«ãã£ãŠåŸãããé åã®æ°ã¯ç°ãªããŸããããšãã°ã2 æ¬ã®çŽç·ãå¹³è¡ã«åŒãã°åŸãããé å㯠3 ã€ã«ãªããäºãã«åçŽã«åŒãã°åŸãããé å㯠4 ã€ã«ãªããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_area">
</center>
<br/>
<p>
<var>n</var> æ¬ã®çŽç·ãåŒãããšã§åŸãããæå€§ã®é åã®æ°ãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã« <var>n</var> (1 ≤ <var>n</var> ≤ 10,000) ãïŒè¡ã«äžããããŸããå
¥åã®æåŸãŸã§åŠçããŠäžããã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
åããŒã¿ã»ããã«å¯ŸããŠãæå€§ã®å岿°ãïŒè¡ã«åºåããŠäžããã
</p>
<H2>Sample Input</H2>
<pre>
1
3
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
7
</pre>
|
p00407 | <h1>倩空ã®åãã«ã¬</h1>
ã<p>
倩空ã®åãã«ã¬ã¯ã¢ã€ã
åœã®äžç©ºã«æµ®ããã§ãããã¢ã€ã
åœã§ã¯ã倩空ã®åãã«ã¬ã«ãã£ãŠæ¥å
ãããããããæ¥ããããæ¥å
ãåœãããªãæ¥ããã£ãå Žæã®äœäººã«ã¯ããã®æ¥æ°ã«å¿ããŠè£åéãæ¯æã£ãŠãããã¢ã€ã
åœã®è£å鿝æãæ
åœè
ã§ããããªãã¯ã倩空ã®åãã«ã¬ã®æ¥ããšã®äœçœ®ãšè£åéã®ç³è«ããã£ãå Žæã®ãªã¹ãããããã®æ¥ã«ãã®å Žæã§æ¥å
ãåœãããªãã£ãããšã確ãããå¿
èŠãããã
</p>
<p>
倩空ã®åãã«ã¬ã®å Žæãšã¢ã€ã
åœã®å°äžã®ããå Žæãäžãããããšãããã®æ¥ã«ãã®å Žæã圱ã«å
¥ã£ãŠãããã©ãããå€å®ããããã°ã©ã ãäœæããã圱ã®äžã«å
¥ã£ãŠãããã©ããã¯ãããç¹å®ã®æå»ã§å€å®ããã®ã§ã倩空ã®åãã«ã¬ã倪éœã®ç§»åã«ã€ããŠã¯èããªããŠè¯ãã倪éœã®äœçœ®ã¯$x=y=0,z=10^6$ã«ãã倧ããã®ãªãç¹ã§ããã倩空ã®åãã«ã¬ã¯$z=100$ã®å¹³é¢ã«ããåžå€è§åœ¢ãå°äžã®å Žæã¯$z=0$ã«ãã倧ããã®ãªãç¹ãšããããŸããããå°ç¹ãšå€ªéœãçµã¶çŽç·ã倩空ã®åãã«ã¬ããããããšãããã®å°ç¹ã¯åœ±ã«å
¥ããã®ãšããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
$N$
$xt_1$ $yt_1$
$xt_2$ $yt_2$
:
$xt_N$ $yt_N$
$Q$
$xa_1$ $ya_1$
$xa_2$ $ya_2$
:
$xa_Q$ $ya_Q$
</pre>
<p>
ïŒè¡ç®ã«å€©ç©ºã®åãã«ã¬ã®é åã衚ãç¹ã®æ°$N$ ($3 \leq N \leq 3 \times 10^4$)ãäžãããããç¶ã$N$è¡ã«ãé åãæ§æããé ç¹ã®åº§æš$xt_i$,$yt_i$ ($-10^8 \leq xt_i,yt_i \leq 10^8$)ãé åã®éå¿ã®åšãã«åæèšåãã«æŽæ°ã§äžããããããã ããåã座æšããã€é ç¹ã¯äžããããªãïŒ$i \ne j$ã«ã€ããŠã$xt_i \ne xt_j$ ãŸã㯠$yt_i \ne yt_j$ïŒããŸããé åã®é¢ç©ã¯0ãã倧ãããšèããŠè¯ããç¶ãïŒè¡ã«ãè£åéã®ç³è«ããã£ãå Žæã®æ°$Q$ ($1 \leq Q \leq 6 \times 10^4$)ãäžãããããç¶ã$Q$è¡ã«ãè£åéã®ç³è«ããã£ãå Žæã®åº§æš$xa_i$,$ya_i$ ($-10^8 \leq xa_i,ya_i \leq 10^8$)ãæŽæ°ã§äžããããããã ããè£åéã®ç³è«ããã£ãå Žæã®åº§æšã¯ã倩空ã®åãã«ã¬ã®åœ±ã®èŒªéç·ããè·é¢$10^{-3}$以äžé¢ããŠãããšèããŠè¯ãã
</p>
<h2>åºå</h2>
<p>
è£åéã®ç³è«ããã£ãåå Žæã«ã€ããŠã圱ã«å
¥ã£ãŠãããã1ããå
¥ã£ãŠããªãã£ããã0ããïŒè¡ã«åºåããã
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸïŒ</h3>
<pre>
6
0 0
4 0
6 3
5 5
1 5
0 3
5
2 2
6 6
3 1
5 1
-1 -1
</pre>
<h3>åºåäŸïŒ</h3>
<pre>
1
0
1
0
0
</pre>
<h3>å
¥åäŸïŒ</h3>
<pre>
4
100000 100000
101000 100000
101000 101000
100000 101000
2
100005 100005
101005 101005
</pre>
<h3>åºåäŸïŒ</h3>
<pre>
0
1
</pre>
|
p03381 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>When <var>l</var> is an odd number, the median of <var>l</var> numbers <var>a_1, a_2, ..., a_l</var> is the <var>(\frac{l+1}{2})</var>-th largest value among <var>a_1, a_2, ..., a_l</var>.</p>
<p>You are given <var>N</var> numbers <var>X_1, X_2, ..., X_N</var>, where <var>N</var> is an even number.
For each <var>i = 1, 2, ..., N</var>, let the median of <var>X_1, X_2, ..., X_N</var> excluding <var>X_i</var>, that is, the median of <var>X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N</var> be <var>B_i</var>.</p>
<p>Find <var>B_i</var> for each <var>i = 1, 2, ..., N</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 200000</var></li>
<li><var>N</var> is even.</li>
<li><var>1 \leq X_i \leq 10^9</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>X_1</var> <var>X_2</var> ... <var>X_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>N</var> lines.
The <var>i</var>-th line should contain <var>B_i</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
2 4 4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
3
3
4
</pre>
<ul>
<li>Since the median of <var>X_2, X_3, X_4</var> is <var>4</var>, <var>B_1 = 4</var>.</li>
<li>Since the median of <var>X_1, X_3, X_4</var> is <var>3</var>, <var>B_2 = 3</var>.</li>
<li>Since the median of <var>X_1, X_2, X_4</var> is <var>3</var>, <var>B_3 = 3</var>.</li>
<li>Since the median of <var>X_1, X_2, X_3</var> is <var>4</var>, <var>B_4 = 4</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
5 5 4 4 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
4
4
4
4
4
</pre></section>
</div>
</span> |
p01646 |
<h2>Problem Statement</h2>
<p>
We found a dictionary of the Ancient Civilization Mayo (ACM) during excavation of the ruins.
After analysis of the dictionary, we revealed they used a language that had not more than 26 letters.
So one of us mapped each letter to a different English alphabet and typed all the words in the dictionary into a computer.
</p>
<p>
How the words are ordered in the dictionary, especially whether they are ordered lexicographically, is an interesting topic to many people.
As a good programmer, you are requested to write a program to judge whether we can consider the words to be sorted in a lexicographical order.
</p>
<p>
Note:
In a lexicographical order, a word always precedes other words it is a prefix of.
For example, <code>ab</code>
precedes <code>abc</code>,
<code>abde</code>, and so on.
</p>
<h2>Input</h2>
<p>
The input consists of multiple datasets. Each dataset is formatted as follows:
</p>
<pre>
<var>n</var>
<var>string_1</var>
...
<var>string_n</var>
</pre>
<p>
Each dataset consists of <var>n+1</var> lines.
The first line of each dataset contains an integer that indicates <var>n</var> (<var>1 \leq n \leq 500</var>).
The <var>i</var>-th line of the following <var>n</var> lines contains <var>string_i</var>, which consists of up to 10 English lowercase letters.
</p>
<p>
The end of the input is <code>0</code>, and this should not be processed.
</p>
<h2>Output</h2>
<p>
Print either <code>yes</code> or
<code>no</code> in a line for each dataset, in the order of the input.
If all words in the dataset can be considered to be ordered lexicographically, print <code>yes</code>.
Otherwise, print <code>no</code>.
</p>
<h2>Sample Input</h2>
<pre>
4
cba
cab
b
a
3
bca
ab
a
5
abc
acb
b
c
c
5
abc
acb
c
b
b
0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
yes
no
yes
no
</pre>
|
p02969 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>It is known that the area of a regular dodecagon inscribed in a circle of radius <var>a</var> is <var>3a^2</var>.</p>
<p>Given an integer <var>r</var>, find the area of a regular dodecagon inscribed in a circle of radius <var>r</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq r \leq 100</var></li>
<li><var>r</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>r</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print an integer representing the area of the regular dodecagon.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>48
</pre>
<p>The area of the regular dodecagon is <var>3 \times 4^2 = 48</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>15
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>675
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>80
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>19200
</pre></section>
</div>
</span> |
p00954 |
<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 I
Skinny Polygon
</h2>
<p>
You are asked to find a polygon that satisfies all the following conditions, given two integers, $x_{bb}$ and $y_{bb}$.
</p>
<ul>
<li> The number of vertices is either 3 or 4.</li>
<li> Edges of the polygon do not intersect nor overlap with other edges, i.e., they do not share any points with other edges except for their endpoints.</li>
<li> The $x$- and $y$-coordinates of each vertex are integers. </li>
<li> The $x$-coordinate of each vertex is between 0 and $x_{bb}$, inclusive. Similarly, the $y$-coordinate is between 0 and $y_{bb}$, inclusive.</li>
<li> At least one vertex has its $x$-coordinate 0.</li>
<li> At least one vertex has its $x$-coordinate $x_{bb}$.</li>
<li> At least one vertex has its $y$-coordinate 0.</li>
<li> At least one vertex has its $y$-coordinate $y_{bb}$.</li>
<li> <b>The area of the polygon does not exceed 25000.</b></li>
</ul>
<p>
The polygon may be non-convex.
</p>
<h3>Input</h3>
<p>
The input consists of multiple test cases. The first line of the input contains an integer $n$, which is the number of the test cases ($1 \leq n \leq 10^5$). Each of the following $n$ lines contains a test case formatted as follows.<br/>
<br/>
$x_{bb}$ $y_{bb}$<br/>
<br/>
$x_{bb}$ and $y_{bb}$ ($2 \leq x_{bb} \leq 10^9, 2 \leq y_{bb} \leq 10^9$) are integers stated above.
</p>
<h3>Output</h3>
<p>
For each test case, output description of one polygon satisfying the conditions stated above, in the following format.<br/>
<br/>
$v$<br/>
$x_1$ $y_1$<br/>
. <br/>
. <br/>
. <br/>
$x_v$ $y_v$<br/>
</p>
<p>
Here, $v$ is the number of vertices, and each pair of $x_i$ and $y_i$ gives the coordinates of the $i$-th vertex, $(x_i, y_i)$. The first vertex $(x_1, y_1)$ can be chosen arbitrarily, and the rest should be listed either in clockwise or in counterclockwise order.
</p>
<p>
When more than one polygon satisfies the conditions, any one of them is acceptable. You can prove that, with the input values ranging as stated above, there is at least one polygon satisfying the conditions.
</p>
<h3>Sample Input 1</h3>
<pre>2
5 6
1000000000 2</pre>
<h3>Sample Output 1</h3>
<pre>4
5 6
0 6
0 0
5 0
3
1000000000 0
0 2
999999999 0</pre>
|
p04014 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>For integers <var>b (b \geq 2)</var> and <var>n (n \geq 1)</var>, let the function <var>f(b,n)</var> be defined as follows:</p>
<ul>
<li><var>f(b,n) = n</var>, when <var>n < b</var></li>
<li><var>f(b,n) = f(b,\,{\rm floor}(n / b)) + (n \ {\rm mod} \ b)</var>, when <var>n \geq b</var></li>
</ul>
<p>Here, <var>{\rm floor}(n / b)</var> denotes the largest integer not exceeding <var>n / b</var>,
and <var>n \ {\rm mod} \ b</var> denotes the remainder of <var>n</var> divided by <var>b</var>.</p>
<p>Less formally, <var>f(b,n)</var> is equal to the sum of the digits of <var>n</var> written in base <var>b</var>.
For example, the following hold:</p>
<ul>
<li><var>f(10,\,87654)=8+7+6+5+4=30</var></li>
<li><var>f(100,\,87654)=8+76+54=138</var></li>
</ul>
<p>You are given integers <var>n</var> and <var>s</var>.
Determine if there exists an integer <var>b (b \geq 2)</var> such that <var>f(b,n)=s</var>.
If the answer is positive, also find the smallest such <var>b</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq n \leq 10^{11}</var></li>
<li><var>1 \leq s \leq 10^{11}</var></li>
<li><var>n,\,s</var> are integers.</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>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there exists an integer <var>b (b \geq 2)</var> such that <var>f(b,n)=s</var>, print the smallest such <var>b</var>.
If such <var>b</var> does not exist, print <code>-1</code> instead.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>87654
30
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>87654
138
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>100
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>87654
45678
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>-1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>31415926535
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>31415926535
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>1
31415926535
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>-1
</pre></section>
</div>
</span> |
p01216 |
<H1><font color="#000">Problem A:</font> Election</H1>
<p>
Giselle has just made a vote for a national election. In her country, members of the legislature are elected
by a system called mixed member proportional representation (MMP). Basically, half the members are
elected from constituencies, and the other half are elected from party lists by proportional representation.
Each voter has two votes, one for a constituency representative and one for a party.
</p>
<p>
In each constituency, the representative is chosen by a single-winner voting system called the first-past-
the-post. This system is very simple: the candidate who earns the highest number of votes wins the seat.
There are constituencies equal to half the number of seats, and they are determined in accordance with
geographical areas.
</p>
<p>
Each party is allocated the seats according to the percentage of votes cast for that party. Only parties that
have either at least five percent of the total party votes or at least three constituency seats are eligible for
the seats; the parties that satisfy neither of these prerequisites are excluded on the following procedure.
The number of seats for each eligible party is determined based on the value given by:
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_election">
</center>
<p>
Note that the multiplier in the above formula is the number of <i>overall</i> seats, not party-list seats (i.e. not
half the members). Each party receives the seats equal to the integer part of this value. There usually
remain some seats, and they are allocated to the parties in decreasing order of the fraction parts, where
each party receive at most one extra seat. If two or more parties have the same fraction parts, the party
that gained a greater number of votes gets higher preference.
</p>
<p>
The number of seats allocated by the above procedure counts both the constituency seats and the party-
list seats. Each party is therefore entitled to add members from the list just as many as the number of
its allocated seats minus the number of its constituency seats. Those members are chosen in the order
predetermined by the party. If some candidates in the party list already have the seats for constituency
representatives (this happens because each constituency candidate is allowed to also be included in the
list), they are not counted and the next candidates down are added instead.
</p>
<p>
The candidates who won in constituencies never forfeit their seats. It sometimes happens that the number
of constituencies where a party won exceeds the number of seats allocated for the party vote. In this
case, <i>all</i> winners in constituencies receive the seats in the legislature, although no more members will
be elected from the party list. The same still applies to the candidates in the parties ineligible to be
allocated the seats. Note that this raises the total number of seats. The seats added for this reason are
called <i>overhang seats</i>.
<p>
<p>
Now, let us take an example. Suppose three parties A, B, and C are competing for eight seats, where the
party A has earned one constituency seat and 9,000 party votes, the party B one and 8,000, and the party
C two and 3,000. The total number of party votes is 9000 + 8000 + 3000 = 20000, thus the five-percent
threshold is 20000 Ã (5/100) = 1000. From this threshold, all parties are eligible to be allocated the seats.
The formula gives (8 × 9000)/20000 = 3.6, (8 × 8000)/20000 = 3.2, and (8 × 3000)/20000 = 1.2, so
the parties A, B, and C receive three seats, three, and one respectively. There is one remaining seat, and
it goes to the party A for the largest fraction part 0.6 ( = 3.6 â 3). In conclusion, the party A gains four
seats in total, and since this party won one constituency seat, there are three more members to be chosen
from the party Aâs list. Similarly, there are two more members from the party Bâs list. On the other hand,
the party C receives only one seat despite winning in two constituencies. So no members will be chosen
from the party Câs list and one overhang seat occurs. The total number of elected members therefore will
be nine. This example corresponds to the first case of the sample input and output.
</p>
<p>
You are required to write a program that determines which candidates win the seats.
</P>
<H2>Input</H2>
<p>
The input consists of multiple data sets. Each data set has the following format:
</p>
<pre>
<i>N M</i>
<i>Party</i><sub>1</sub>
<i>Party</i><sub>2</sub>
...
<i>Party</i><sub><i>M</i></sub>
<i>Constituency</i><sub>1</sub>
<i>Constituency</i><sub>2</sub>
...
<i>Constituency</i><sub><i>N</i>/2</sub>
</pre>
<p>
<i>N</i> is a positive even integer that represents the number of seats. <i>M</i> is a positive integer that represents the
number of parties. <i>Party<sub>i</sub></i> is the description of the <i>i</i>-th party. <i>Constituency<sub>i</sub></i> is the description of the <i>i</i>-th
constituency.
</p>
<p>
Each party description is given in the following format:
</p>
<pre>
<i>PartyName C V</i>
<i>Name</i><sub>1</sub>
<i>Name</i><sub>2</sub>
...
<i>Name</i><sub><i>C</i></sub>
</pre>
<p>
<i>PartyName</i> is the name of the party. <i>C</i> is a positive integer that represents the number of candidates in
the party list. <i>V</i> is a non-negative integer that represents the number of votes cast for that party. <i>Name<sub>i</sub></i> is
the name of the candidate with the <i>i</i>-th highest priority in the party list.
</p>
<p>
Each constituency description is given in the following format:
</p>
<pre>
<i>C</i>
<i>Name</i><sub>1</sub> <i>Party</i><sub>1</sub> <i>V</i><sub>1</sub>
<i>Name</i><sub>2</sub> <i>Party</i><sub>2</sub> <i>V</i><sub>2</sub>
...
<i>Name</i><sub><i>C</i></sub> <i>Party</i><sub><i>C</i></sub> <i>V</i><sub><i>C</i></sub>
</pre>
<p>
<i>C</i> is a positive integer, equal to or greater than two, that represents the number of candidates in the
constituency. <i>Name<sub>i</sub></i> is the name of the <i>i</i>-th candidate in the constituency. <i>Party<sub>i</sub></i> is the name of the party
that the <i>i</i>-th candidate belongs. <i>V<sub>i</sub></i> is a non-negative integer that represents the number of votes cast for
the <i>i</i>-th candidate.
</p>
<p>
The input is terminated with a line that contains two zeros. This line should not be processed.
</p>
<p>
You may assume all the followings:
</p>
<ul>
<li> The name of each party is a string up to ten characters that begins with an uppercase character
and consists of only uppercase and numeric characters. The name of each candidate is a string
up to twenty characters that begins with a lowercase character and consists of only lowercase and
numeric characters. No multiple parties or candidates have the same name.</li>
<li> The number of parties, the number of seats, and the total number of different candidates do not
exceed 20, 200, and 1,000 respectively. Neither the total number of party votes nor the total
number of votes in each constituency exceeds 10,000,000.</li>
<li> No two or more parties receive the same number of party votes. Also, in each constituency, no two
or more candidates receive the same number of constituency votes.</li>
<li> Each party list contains enough candidates, that is, the party can always choose the required number
of candidates from the list.</li>
<li> Every candidate belongs to just one of the parties. No candidate is allowed to compete in more
than one constituency. Note that, however, each candidate may appear up to twice in a data set,
one in a party list and one in a constituency description.</li>
<li> The number of data sets in the input does not exceed fifty.</li>
</ul>
<H2>Output</H2>
<p>
For each data set, print names of all elected persons, one name per line, in lexicographical order according
to the ASCII code. Print an empty line between two consecutive data sets.
</p>
<H2>Sample Input</H2>
<pre>
8 3
A 6 9000
a1
a2
a3
a4
a5
a6
B 6 8000
b1
b2
b3
b4
b5
b6
C 4 3000
c1
c2
c3
c4
2
a7 A 2000
b2 B 4000
3
a8 A 1500
c3 C 500
b1 B 1000
2
c2 C 2328
a3 A 2327
2
b5 B 2345
c5 C 4000
43
A 3 2500
a1
a2
a3
B 3 1500
b1
b2
b3
C 1 150
c1
2
a4 A 1500
b4 B 1000
2
a5 A 700
b5 B 800
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
a1
a2
a3
a8
b1
b2
b3
c2
c5
a1
a2
a4
b5
</pre>
|
p03801 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke loves constructing integer sequences.</p>
<p>There are <var>N</var> piles of stones, numbered <var>1</var> through <var>N</var>.
The pile numbered <var>i</var> consists of <var>a_i</var> stones.</p>
<p>Snuke will construct an integer sequence <var>s</var> of length <var>Σa_i</var>, as follows:</p>
<ol>
<li>Among the piles with the largest number of stones remaining, let <var>x</var> be the index of the pile with the smallest index. Append <var>x</var> to the end of <var>s</var>.</li>
<li>Select a pile with one or more stones remaining, and remove a stone from that pile.</li>
<li>If there is a pile with one or more stones remaining, go back to step 1. Otherwise, terminate the process.</li>
</ol>
<p>We are interested in the lexicographically smallest sequence that can be constructed. For each of the integers <var>1,2,3,...,N</var>, how many times does it occur in the lexicographically smallest sequence?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N †10^{5}</var></li>
<li><var>1 †a_i †10^{9}</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_{N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>N</var> lines. The <var>i</var>-th line should contain the number of the occurrences of the integer <var>i</var> in the lexicographically smallest sequence that can be constructed.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
1
</pre>
<p>The lexicographically smallest sequence is constructed as follows:</p>
<ul>
<li>Since the pile with the largest number of stones remaining is pile <var>2</var>, append <var>2</var> to the end of <var>s</var>. Then, remove a stone from pile <var>2</var>.</li>
<li>Since the piles with the largest number of stones remaining are pile <var>1</var> and <var>2</var>, append <var>1</var> to the end of <var>s</var> (we take the smallest index). Then, remove a stone from pile <var>2</var>.</li>
<li>Since the pile with the largest number of stones remaining is pile <var>1</var>, append <var>1</var> to the end of <var>s</var>. Then, remove a stone from pile <var>1</var>.</li>
</ul>
<p>The resulting sequence is <var>(2,1,1)</var>. In this sequence, <var>1</var> occurs twice, and <var>2</var> occurs once.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10
1 2 1 3 2 4 2 5 8 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>10
7
0
4
0
3
0
2
3
0
</pre></section>
</div>
</span> |
p02713 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Find <var>\displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}</var>.</p>
<p>Here <var>\gcd(a,b,c)</var> denotes the greatest common divisor of <var>a</var>, <var>b</var>, and <var>c</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq K \leq 200</var></li>
<li><var>K</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>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the value of <var>\displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>9
</pre>
<p><var>\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)</var>
<var>+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)</var>
<var>=1+1+1+1+1+1+1+2=9</var></p>
<p>Thus, the answer is <var>9</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>200
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>10813692
</pre></section>
</div>
</span> |
p01996 | <h1>A: ãã¹ã</h1>
<h2>åé¡</h2>
<p>
$N$ åã®åžãäžçŽç·äžã«äžŠãã§ããæå®€ã§ $M$ 人ã®çåŸããã¹ããåããããšã«ãªã£ãã
åžã«ã¯ãåãã $1 \dots N$ ã®çªå·ãæ¯ãããŠãããåž $1$ ã€ã«ã€ãçåŸ $1$ 人ã座ããã
</p>
<p>
ããŸã åçåŸã¯ã $A_1, \dots, A_M$ çªã®åžã«åº§ã£ãŠããã
</p>
<p>
ãã¹ããå§ããããã«ã¯ã以äžã®æ¡ä»¶ãæºãããªããã°ãªããªãã
<ul>
<li> $1 \dots M$ çªã®ã©ã®åžã«ãçåŸã座ã£ãŠããã</li>
</ul>
</p>
<p>
ããã§ãæ¡ä»¶ãæºãããŸã§æ¬¡ã®æäœãç¹°ãè¿ãããšã«ããã
<ul>
<li>æãåŸãã«åº§ã£ãŠããçåŸãç§»åããã空ããŠããåžã®ãã¡æãåã«åº§ãããã</li>
</ul>
</p>
<p>
æ¡ä»¶ãæºããããã«å¿
èŠãªæäœåæ°ãæ±ããã
</p>
<h2>å¶çŽ</h2>
<ul>
<li>å
¥åå€ã¯å
šãп޿°ã§ããã</li>
<li>$1 \leq N \leq 1000$</li>
<li>$1 \leq M \leq N$</li>
<li>$1 \leq A_i \leq N$</li>
<li>$1 \leq i < j \leq M$ ãªãã° $A_i < A_j$</li>
</ul>
<h2>å
¥å圢åŒ</h2>
<p> å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã </p>
<p>
$N\ M$<br>
$A_1 \dots A_M$<br>
</p>
<h2>åºå</h2>
<p>æ¡ä»¶ãæºããããã«å¿
èŠãªæäœåæ°ãåºåããããŸããæ«å°Ÿã«æ¹è¡ãåºåããã </p>
<h2>ãµã³ãã«</h2>
<h3>ãµã³ãã«å
¥å 1</h3>
<pre>
6 4
1 4 5 6
</pre>
<h3>ãµã³ãã«åºå 1</h3>
<pre>
2
</pre>
<h3>ãµã³ãã«å
¥å 2</h3>
<pre>
10 3
1 2 3
</pre>
<h3>ãµã³ãã«åºå 2</h3>
<pre>
0
</pre>
|
p00684 |
<H1>Calculation of Expressions</H1>
<P>Write a program to calculate values of arithmetic expressions which may
involve complex numbers. Details of the expressions are described below.</P>
<P>In this problem, basic elements of expressions are
non-negative integer numbers and
the special symbol "<TT>i</TT>". Integer numbers are sequences
of digits of arbitrary length and are in decimal notation. "<TT>i</TT>" denotes the
unit imaginary number <I>i</I>, i.e. <I>i</I><SUP> 2</SUP> = -1.</P>
<P>Operators appearing in expressions are <TT>+</TT> (addition), <TT>-</TT>
(subtraction), and <TT>*</TT> (multiplication). Division is excluded from
the repertoire of the operators. All three operators are only used as binary
operators. Unary plus and minus operators (e.g., <TT>-100</TT>) are also
excluded from the repertoire. Note that the multiplication symbol <TT>*</TT>
may not be omitted in any case. For example, the expression 1+3<I>i</I>
in mathematics should be written as <TT>1+3*i</TT>.</P>
<P>Usual formation rules of arithmetic expressions apply. Namely, (1) The
operator <TT>*</TT> binds its operands stronger than the operators <TT>+</TT>
and <TT>-</TT>. (2) The operators <TT>+</TT> and <TT>-</TT> have the same
strength in operand binding. (3) Two operators of the same strength bind
from left to right. (4) Parentheses are used to designate specific order
of binding.</P>
<P>The consequence of these rules can easily be understood from the following
examples.</P>
<BLOCKQUOTE>
<BLOCKQUOTE>
<P>(1) <TT>3+4*5</TT> is <TT>3+(4*5)</TT>, not <TT>(3+4)*5</TT><BR>
(2) <TT>5-6+7</TT> is <TT>(5-6)+7</TT>, not <TT>5-(6+7)</TT><BR>
(3) <TT>1+2+3</TT> is <TT>(1+2)+3</TT>, not <TT>1+(2+3)<BR>
</TT></P>
</BLOCKQUOTE>
</BLOCKQUOTE>
<P>Your program should successively read expressions, calculate them and
print their results. Overflow should be detected.</P>
<P>Whenever an abnormal value is yielded as a result of applying an operator
appearing in the given expression,
your program should report that the calculation failed due to overflow.
By "an abnormal value", we mean a value
whose real part or imaginary part is
greater than 10000 or less than -10000. Here are examples:</P>
<P ALIGN=CENTER><TABLE BORDER="1" CELLSPACING="2" CELLPADDING="0">
<TR>
<TD WIDTH="50%"><TT>10000+1+(0-10)</TT></TD>
<TD WIDTH="50%">overflow, not 9991</TD></TR>
<TR>
<TD WIDTH="50%"><TT>(10*i+100)*(101+20*i)</TT></TD>
<TD WIDTH="50%">9900+3010<I>i </I>, not overflow</TD></TR>
<TR>
<TD WIDTH="50%"><TT>4000000-4000000</TT></TD>
<TD WIDTH="50%">overflow, not 0</TD></TR>
</TABLE>
</P>
<P>Note that the law of associativity does not necessarily hold in this
problem. For example, in the first example,
overflow is detected by interpreting
the expression as <TT>(10000+1)+(0-10)</TT> following the binding rules,
whereas overflow could not be detected
if you interpreted it as <TT>10000+(1+(0-10))</TT>.
Moreover, overflow detection should take place for resulting value of each
operation.</P>
<P>In the second example, a value which exceeds 10000 appears
in the calculation process of one multiplication
if you use the mathematical rule</P>
<BLOCKQUOTE>
<P>(<I>a</I>+<I>b i</I>)(<I>c</I>+<I>d</I> <I>i</I>)=(<I>ac</I>-<I>bd</I>)+(<I>ad</I>+<I>bc</I>)<I>i
</I>.</P>
</BLOCKQUOTE>
<P>But the yielded result 9900+3010<I>i </I>does not contain any number
which exceeds 10000 and, therefore, overflow should not be reported.</P>
<P></P>
<H2>Input</H2>
<P>A sequence of lines each of which contains an expression is given as
input. Each line consists of less than 100 characters and does not contain
any blank spaces. You may assume that all expressions given in the sequence
are syntactically correct.</P>
<H2>Output</H2>
<P>Your program should produce output for each expression line by line.
If overflow is detected, output should be
a character string "<TT>overflow</TT>".
Otherwise, output should be the resulting value of calculation
in the following fashion.</P>
<UL>
<LI><TT>0</TT> , if the result is 0+0<I>i</I>.
<LI><TT>-123</TT> , if the result is -123+0<I>i</I>.
<LI><TT>45i</TT> , if the result is 0+45<I>i</I>.
<LI><TT>3+1i</TT> , if the result is 3+<I>i</I>.
<LI><TT>123-45i</TT> , if the result is 123-45<I>i</I>.
</UL>
<P>Output should not contain any blanks, surplus <TT>0</TT>,
<TT>+</TT>, or <TT>-</TT>.</P>
<H2>Sample Input</H2>
<pre>
(1-10*i)+00007+(3+10*i)
3+4*i*(4+10*i)
(102+10*i)*(99+10*i)
2*i+3+9999*i+4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
11
-37+16i
9998+2010i
overflow
</pre>
|
p02343 |
<H1>Disjoint Set</H1>
<p>
Write a program which manipulates a disjoint set <var>S = {S<sub>1</sub>, S<sub>2</sub>, . . . , S<sub>k</sub>}</var>.
</p>
<p>
First of all, the program should read an integer <var>n</var>, then make a disjoint set where each element consists of 0, 1, ... <var>n−1</var> respectively.
</p>
<p>
Next, the program should read an integer <var>q</var> and manipulate the set for <var>q</var> queries. There are two kinds of queries for different operations:
</p>
<ul>
<li><var>unite(x, y)</var>: unites sets that contain <var>x</var> and <var>y</var>, say <var>S<sub>x</sub></var> and <var>S<sub>y</sub></var>, into a new set.
<li><var>same(x, y)</var>: determine whether <var>x</var> and <var>y</var> are in the same set.</li>
</ul>
<H2>Input</H2>
<pre>
<var>n</var> <var>q</var>
<var>com<sub>1</sub></var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var>
<var>com<sub>2</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var>
...
<var>com<sub>q</sub></var> <var>x<sub>q</sub></var> <var>y<sub>q</sub></var>
</pre>
<p>
In the first line, <var>n</var> and <var>q</var> are given. Then, <var>q</var> queries are given where <var>com</var> represents the type of queries. '0' denotes <var>unite</var> and '1' denotes <var>same</var> operation.
</p>
<H2>Output</H2>
<p>
For each <var>same</var> operation, print <span>1</span> if <var>x</var> and <var>y</var> are in the same set, otherwise <span>0<span>, in a line.
</p>
<H2>Constraints</H2>
<ul>
<li>
<var>1 ≤ n ≤ 10000
</li>
<li>
<var>1 ≤ q ≤ 100000
</li>
<li>
<var>x ≠ y</var>
</li>
</ul>
<H2>Sample Input</H2>
<pre>
5 12
0 1 4
0 2 3
1 1 2
1 3 4
1 1 4
1 3 2
0 1 3
1 2 4
1 3 0
0 0 4
1 0 2
1 3 0
</pre>
<H2>Sample Output</H2>
<pre>
0
0
1
1
1
0
1
1
</pre> |
p03102 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> pieces of source code. The characteristics of the <var>i</var>-th code is represented by <var>M</var> integers <var>A_{i1}, A_{i2}, ..., A_{iM}</var>.</p>
<p>Additionally, you are given integers <var>B_1, B_2, ..., B_M</var> and <var>C</var>.</p>
<p>The <var>i</var>-th code correctly solves this problem if and only if <var>A_{i1} B_1 + A_{i2} B_2 + ... + A_{iM} B_M + C > 0</var>.</p>
<p>Among the <var>N</var> codes, find the number of codes that correctly solve this problem.</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 20</var></li>
<li><var>-100 \leq A_{ij} \leq 100</var></li>
<li><var>-100 \leq B_i \leq 100</var></li>
<li><var>-100 \leq C \leq 100</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var> <var>C</var>
<var>B_1</var> <var>B_2</var> <var>...</var> <var>B_M</var>
<var>A_{11}</var> <var>A_{12}</var> <var>...</var> <var>A_{1M}</var>
<var>A_{21}</var> <var>A_{22}</var> <var>...</var> <var>A_{2M}</var>
<var>\vdots</var>
<var>A_{N1}</var> <var>A_{N2}</var> <var>...</var> <var>A_{NM}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of codes among the given <var>N</var> codes that correctly solve this problem.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 -10
1 2 3
3 2 1
1 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>Only the second code correctly solves this problem, as follows:</p>
<ul>
<li>Since <var>3 \times 1 + 2 \times 2 + 1 \times 3 + (-10) = 0 \leq 0</var>, the first code does not solve this problem.</li>
<li><var>1 \times 1 + 2 \times 2 + 2 \times 3 + (-10) = 1 > 0</var>, the second code solves this problem.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 2 -4
-2 5
100 41
100 40
-3 0
-6 -2
18 -13
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3 3 0
100 -100 0
0 100 100
100 100 100
-100 100 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>All of them are <em>Wrong Answer</em>. Except yours.</p></section>
</div>
</span> |
p01095 |
<h3>Bamboo Blossoms</h3>
<p>
The bamboos live for decades, and at the end of their lives,
they flower to make their seeds. Dr. ACM, a biologist, was fascinated
by the bamboos in blossom in his travel to Tsukuba. He liked
the flower so much that he was tempted to make a garden where
the bamboos bloom annually. Dr. ACM started research of
improving breed of the bamboos, and finally, he established
a method to develop bamboo breeds with controlled lifetimes.
With this method, he can develop bamboo breeds that flower
after arbitrarily specified years.
</p>
<p>
Let us call bamboos that flower <i>k</i> years after sowing
"<i>k</i>-year-bamboos."
<i>k</i> years after being sowed, <i>k</i>-year-bamboos make
their seeds and then die,
hence their next generation flowers after another <i>k</i> years.
In this way, if he sows seeds of <i>k</i>-year-bamboos, he can
see bamboo blossoms every <i>k</i> years. For example,
assuming that he sows seeds of 15-year-bamboos,
he can see bamboo blossoms every 15 years;
15 years, 30 years, 45 years, and so on, after sowing.
</p>
<p>
Dr. ACM asked you for designing his garden. His garden is partitioned
into blocks, in each of which only a single breed of bamboo can grow.
Dr. ACM requested you to decide which breeds of bamboos
should he sow in the blocks in order to see bamboo blossoms
in at least one block for as many years as possible.
</p>
<p>
You immediately suggested to sow seeds of one-year-bamboos in all blocks.
Dr. ACM, however, said that it was difficult to develop a bamboo breed
with short lifetime, and would like a plan using only those breeds with
long lifetimes. He also said that, although he could wait for some years
until he would see the first bloom, he would like to see it in
every following year.
Then, you suggested a plan
to sow seeds of 10-year-bamboos, for example, in different blocks each year,
that is, to sow in a block this year and in another block next year, and so on,
for 10 years. Following this plan, he could see
bamboo blossoms in one block every year except for the first 10 years.
Dr. ACM objected again saying he had determined to sow in all
blocks this year.
</p>
<p>
After all, you made up your mind to make a sowing plan where the bamboos
bloom in at least one block for as many consecutive years as possible
after the first <i>m</i> years (including this year)
under the following conditions:
<ul>
<li>the plan should use only those bamboo breeds whose
lifetimes are <i>m</i> years or longer, and
<li>Dr. ACM should sow the seeds in all the blocks only this year.
</ul>
</p>
<h3>Input</h3>
<p>
The input consists of at most 50 datasets, each in the following format.
</p>
<p>
<i>m</i> <i>n</i><br>
</p>
<p>
An integer <i>m</i> (2 ≤ <i>m</i> ≤ 100) represents the lifetime
(in years)
of the bamboos with the shortest lifetime that Dr. ACM can use for
gardening.
An integer <i>n</i> (1 ≤ <i>n</i> ≤ 500,000) represents the number of blocks.
</p>
<p>
The end of the input is indicated by a line containing two zeros.
</p>
<h3>Output</h3>
<p>
No matter how good your plan is, a "dull-year" would
eventually come, in which the bamboos do not flower in any block.
For each dataset, output in a line an integer meaning how many
years from now the first dull-year comes after the first <i>m</i> years.
</p>
<p>
Note that the input of <i>m</i> = 2 and <i>n</i> = 500,000
(the last dataset of the Sample Input) gives the largest answer.
</p>
<h3>Sample Input</h3>
<pre>
3 1
3 4
10 20
100 50
2 500000
0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
4
11
47
150
7368791
</pre> |
p03552 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a deck consisting of <var>N</var> cards. Each card has an integer written on it. The integer on the <var>i</var>-th card from the top is <var>a_i</var>.</p>
<p>Two people X and Y will play a game using this deck. Initially, X has a card with <var>Z</var> written on it in his hand, and Y has a card with <var>W</var> written on it in his hand. Then, starting from X, they will alternately perform the following action:</p>
<ul>
<li>Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn.</li>
</ul>
<p>The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand.</p>
<p>X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All input values are integers.</li>
<li><var>1 \leq N \leq 2000</var></li>
<li><var>1 \leq Z, W, a_i \leq 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>Z</var> <var>W</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the score.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 100 100
10 1000 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>900
</pre>
<p>If X draws two cards first, Y will draw the last card, and the score will be <var>|1000 - 100| = 900</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 100 1000
10 100 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>900
</pre>
<p>If X draws all the cards first, the score will be <var>|1000 - 100| = 900</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 1 1
1 1 1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1 1 1
1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>999999999
</pre></section>
</div>
</span> |
p03047 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has <var>N</var> integers: <var>1,2,\ldots,N</var>.
He will choose <var>K</var> of them and give those to Takahashi.</p>
<p>How many ways are there to choose <var>K</var> consecutive integers?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq K \leq N \leq 50</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 answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>There are two ways to choose two consecutive integers: <var>(1,2)</var> and <var>(2,3)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>13 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>11
</pre></section>
</div>
</span> |
p01580 |
<H1><font color="#000">Problem K:</font> Up Above the World So High</H1>
<p>
One of the questions children often ask is "How many stars are there in the sky?" Under ideal conditions, even with the naked eye, nearly eight thousands are observable in the northern hemisphere. With a decent telescope, you may find many more, but, as the sight field will be limited, you may find much less at a time.
</p>
<p>
Children may ask the same questions to their parents in a spaceship billions of light-years away from the Earth. Their telescopes are similar to ours with circular sight field. It can be rotated freely, that is, the sight vector can take an arbitrary value.
</p>
<p>
Given a set of positions of stars and the spec of a telescope, your task is to determine the maximum
number of stars that can be seen through the telescope at a time.
</p>
<H2>Input</H2>
<p>
The first line of a test case contains a positive integer <i>N</i> not exceeding 100, meaning the number of stars. Each of the <i>N</i> lines following it contains three integers, <i>s<sub>x</sub></i>, <i>s<sub>y</sub></i> and <i>s<sub>z</sub></i>. They give the position (<i>s<sub>x</sub></i>, <i>s<sub>y</sub></i>, <i>s<sub>z</sub></i>) of the star described in Euclidean coordinates. You may assume that -1000 ≤ <i>s<sub>x</sub></i> ≤ 1000, -1000 ≤ <i>s<sub>y</sub></i> ≤ 1000, -1000 ≤ <i>s<sub>z</sub></i> ≤ 1000 and (<i>s<sub>x</sub></i>, <i>s<sub>y</sub></i>, <i>s<sub>z</sub></i>) ≠ (0, 0, 0).
</p>
<p>
Then comes a line containing a positive integer <i>ψ</i> (0 < <i>ψ</i> < 90), which represents the angular radius, in degrees, of the sight field of the telescope. The telescope is at the origin of the coordinate system (0, 0, 0).
</p>
<p>
You may assume that change of the angular radius <i>ψ</i> by less than 0.01 degrees does not affect the answer, and that ∠POQ is greater than 0.01 degrees for any pair of distinct stars P and Q and the origin O.
</p>
<H2>Output</H2>
<p>
One line containing an integer meaning the maximum number of stars observable through the telescope should be output. No other characters should be contained in the output.
</p>
<H2>Sample Input 1</H2>
<pre>
2
1 0 0
0 1 0
40
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
1
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
2
1 0 0
0 1 0
50
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
2
</pre>
<h2>Note</h2>
<p>
This problem statement is taken from "How I Wonder What You Are!" in ACM-ICPC Asia Regional Contest 2006, Yokohoma, with small but substantial changes.
</p> |
p03417 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive <var>N</var> rows and <var>M</var> columns, and a card is placed in each square in this region.
The front and back sides of these cards can be distinguished, and initially every card faces up.</p>
<p>We will perform the following operation once for each square contains a card:</p>
<ul>
<li>For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square.</li>
</ul>
<p>It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed.
Find the number of cards that face down after all the operations.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N,M \leq 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>M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of cards that face down after all the operations.</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>0
</pre>
<p>We will flip every card in any of the four operations. Thus, after all the operations, all cards face up.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
<p>After all the operations, all cards except at both ends face down.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>314 1592
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>496080
</pre></section>
</div>
</span> |
p03944 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a rectangle in the <var>xy</var>-plane, with its lower left corner at <var>(0, 0)</var> and its upper right corner at <var>(W, H)</var>. Each of its sides is parallel to the <var>x</var>-axis or <var>y</var>-axis. Initially, the whole region within the rectangle is painted white.</p>
<p>Snuke plotted <var>N</var> points into the rectangle. The coordinate of the <var>i</var>-th (<var>1 ⊠i ⊠N</var>) point was <var>(x_i, y_i)</var>.</p>
<p>Then, he created an integer sequence <var>a</var> of length <var>N</var>, and for each <var>1 ⊠i ⊠N</var>, he painted some region within the rectangle black, as follows:</p>
<ul>
<li>If <var>a_i = 1</var>, he painted the region satisfying <var>x < x_i</var> within the rectangle.</li>
<li>If <var>a_i = 2</var>, he painted the region satisfying <var>x > x_i</var> within the rectangle.</li>
<li>If <var>a_i = 3</var>, he painted the region satisfying <var>y < y_i</var> within the rectangle.</li>
<li>If <var>a_i = 4</var>, he painted the region satisfying <var>y > y_i</var> within the rectangle.</li>
</ul>
<p>Find the area of the white region within the rectangle after he finished painting.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ⊠W, H ⊠100</var></li>
<li><var>1 ⊠N ⊠100</var></li>
<li><var>0 ⊠x_i ⊠W</var> (<var>1 ⊠i ⊠N</var>)</li>
<li><var>0 ⊠y_i ⊠H</var> (<var>1 ⊠i ⊠N</var>)</li>
<li><var>W</var>, <var>H</var> (21:32, added), <var>x_i</var> and <var>y_i</var> are integers.</li>
<li><var>a_i</var> (<var>1 ⊠i ⊠N</var>) is <var>1, 2, 3</var> or <var>4</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>W</var> <var>H</var> <var>N</var>
<var>x_1</var> <var>y_1</var> <var>a_1</var>
<var>x_2</var> <var>y_2</var> <var>a_2</var>
<var>:</var>
<var>x_N</var> <var>y_N</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the area of the white region within the rectangle after Snuke finished painting.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 4 2
2 1 1
3 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>9
</pre>
<p>The figure below shows the rectangle before Snuke starts painting.</p>
<div style="text-align: center;">
<img alt="e19e673abcd0882783f635cce9d2f94d.png" src="https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png">
</img></div>
<p>First, as <var>(x_1, y_1) = (2, 1)</var> and <var>a_1 = 1</var>, he paints the region satisfying <var>x < 2</var> within the rectangle:</p>
<div style="text-align: center;">
<img alt="f25cd04bbac23c4e5426d70511a9762f.png" src="https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png">
</img></div>
<p>Then, as <var>(x_2, y_2) = (3, 3)</var> and <var>a_2 = 4</var>, he paints the region satisfying <var>y > 3</var> within the rectangle:</p>
<div style="text-align: center;">
<img alt="46b0c06fd9eee4f148e1f441f7abca53.png" src="https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png"/>
</div>
<p>Now, the area of the white region within the rectangle is <var>9</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 4 3
2 1 1
3 3 4
1 4 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>It is possible that the whole region within the rectangle is painted black.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 10 5
1 6 1
4 1 3
6 9 4
9 4 2
3 1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>64
</pre></section>
</div>
</span> |
p01979 | <h1>F: ãã¡ããæ°</h1>
<h2>åé¡</h2>
<p>
ãã¡ããã倧奜ããªAORã€ã«ã¡ããã¯ããã¡ããæ°ããå®çŸ©ããã
ãã¡ããæ°ãšã¯ã $10$ é²è¡šèšã«ãããŠã $51?3$ ããå«ãèªç¶æ°ã®ããšã§ããã<br>
$?$ 㯠$0$ ã $9$ ã®ã©ã®æ°åã§ãã£ãŠãããã
</p>
<p>
$N$ 以äžã®èªç¶æ°ã®ãã¡ããã¡ããæ°ã®åæ°ãæ±ããã
</p>
<h2>å¶çŽ</h2>
<ul>
<li>$1 \le N < 10^{18}$</li>
</ul>
<h2>å
¥å</h2>
<p>
$N$<br>
</p>
<h2>åºå</h2>
<p>
ãã¡ããæ°ã®åæ°ãäžè¡ã§åºåããããŸãæ«å°Ÿã«æ¹è¡ãåºåããã
</p>
<h2>ãµã³ãã«</h2>
<h3>ãµã³ãã«å
¥å 1</h3>
<pre>
5124
</pre>
<h3>ãµã³ãã«åºå 1</h3>
<pre>
3
</pre>
<p>
$5124$ 以äžã®ãã¡ããæ°ã¯ã$5103$ , $5113$ , $5123$ ã® äžã€ã§ããã
</p>
<h3>ãµã³ãã«å
¥å 2</h3>
<pre>
60000
</pre>
<h3>ãµã³ãã«åºå 2</h3>
<pre>
160
</pre>
<h3>ãµã³ãã«å
¥å 3</h3>
<pre>
100000
</pre>
<h3>ãµã³ãã«åºå 3</h3>
<pre>
200
</pre>
<!-- - - - - - end nicebody - - - - - -->
|
p02656 | <span class="lang-en">
<p>Score : <var>1800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has <var>X+Y</var> balls.
<var>X</var> of them have an integer <var>A</var> written on them, and the other <var>Y</var> of them have an integer <var>B</var> written on them.</p>
<p>Snuke will divide these balls into some number of groups.
Here, every ball should be contained in exactly one group, and every group should contain one or more balls.</p>
<p>A group is said to be <strong>good</strong> when the sum of the integers written on the balls in that group is a multiple of an integer <var>C</var>.
Find the maximum possible number of good groups.</p>
<p>Solve <var>T</var> test cases for each input file.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq T \leq 2 \times 10^4</var></li>
<li><var>1 \leq A,X,B,Y,C \leq 10^9</var></li>
<li><var>A \neq B</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.
The first line is as follows:</p>
<pre><var>T</var>
</pre>
<p>Then, <var>T</var> test cases follow.
Each test case is given in the following format:</p>
<pre><var>A</var> <var>X</var> <var>B</var> <var>Y</var> <var>C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>For each test case, print a line containing the maximum possible number of good groups.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
3 3 4 4 5
2 1 1 5 3
3 1 4 2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
2
0
</pre>
<p>In the first test case, we can have two good groups by making the following groups: <var>\{3,3,4\}</var> and <var>\{3,4,4,4\}</var>.</p>
<p>In the second test case, we can have two good groups by making the following groups: <var>\{2,1\}, \{1,1,1\},</var> and <var>\{1\}</var>.</p></section>
</div>
</span> |
p00391 | <h1>Treasure Map</h1>
<p>
Mr. Kobou found a bundle of old paper when he was cleaning his family home. On each paper, two series of numbers are written. Strange as it appeared to him, Mr. Kobou further went through the storehouse and found out a note his ancestor left. According to it, the bundle of paper is a treasure map, in which the two sequences of numbers seem to give a clue to the whereabouts of the treasure the ancestor buried.
</p>
<p>
Mr. Kobouâs ancestor divided the area where he buried his treasure in a reticular pattern and used only some of the grid sections. The two series of numbers indicate the locations: the $i$-th member of the first series indicates the number of locations in the $i$-th column (form left) of the grid sections where a part of the treasure is buried, and the $j$-th member of the second indicates the same information regarding the $j$-th row from the top. No more than one piece of treasure is buried in one grid section. An example of a 5 × 4 case is shown below. If the pieces of treasure are buried in the grid sections noted as "<span>#</span>" the two series of numbers become "0,2,2,1,1" and "1,1,1,3".
</p>
<center>
<table border="1" style="border-collapse: collapse" cellpadding="8">
<tr>
<td> </td><td>0</td><td>2</td><td>2</td><td>1</td><td>1</td>
</tr>
<tr>
<td>1</td><td> </td><td> </td><td>#</td><td> </td><td> </td>
</tr>
<tr>
<td>1</td><td> </td><td>#</td><td> </td><td> </td><td> </td>
</tr>
<tr>
<td>1</td><td> </td><td> </td><td> </td><td> </td><td>#</td>
</tr>
<tr>
<td>3</td><td> </td><td>#</td><td>#</td><td>#</td><td> </td>
</tr>
</table>
</center>
<br/>
<p>
Mr. Kobouâs ancestor seems to be a very careful person. He slipped some pieces of paper with completely irrelevant information into the bundle. For example, a set of number series "3,2,3,0,0" and "4,2,0,0,2" does not match any combination of 5 × 5 matrixes. So, Mr. Kobou has first to exclude these pieces of garbage information.
</p>
<p>
Given the set of information written on the pieces of paper, make a program to judge if the information is relevant.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$W$ $H$
$a_1$ $a_2$ $...$ $a_W$
$b_1$ $b_2$ $...$ $b_H$
</pre>
<p>
The first line provides the number of horizontal partitions $W$ ($1 \leq W \leq 1000$) and vertical partitions $H$ ($1 \leq H \leq 1000$). The second line provides the $i$-th member of the first number series $a_i$ ($0 \leq a_i \leq H$) written on the paper, and the third line the $j$-th member of the second series $b_j$ ($0 \leq b_j \leq W$).
</p>
<h2>Output</h2>
<p>
Output "<span>1</span>" if the information written on the paper is relevant, or "<span>0</span>" otherwise.
</p>
<h2>Sample Input 1 </h2>
<pre>
5 4
0 2 2 1 1
1 1 1 3
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<h2>Sample Input 2</h2>
<pre>
5 5
3 2 3 0 0
4 2 0 0 2
</pre>
<h2>Sample Output 2</h2>
<pre>
0
</pre>
|
p02206 | <h2>è³é (Prize)</h2>
<p>Segtree ããã¯ã $N$ 人ã®ããŒã ã§ããã°ã©ãã³ã°ã³ã³ãã¹ãã«åºå Žãã $K$ åã®è³éãåŸãŸããïŒä»ããã®è³éãåé
ããããšããŠããŸãã</p>
<p>Segtree ãããå«ã $N$ 人ã®ããŒã ã¡ã³ããŒããããã«ã¯ãå®åé ã« $1$ ãã $N$ ãŸã§ã®çªå·ãã€ããããŠããŸããSegtree ãã㯠$1$ çªã§ãã</p>
<p>$i$ çªã®ããŒã ã¡ã€ã $(i \geq 2)$ ã®åŸãè³éé¡ãã$i - 1$ çªã®ããŒã ã¡ã€ãã®åŸãè³éé¡ã®ååãæŽæ°ã«åãæšãŠãå€ãããå°ãªããšããã®äººã¯æã£ãŠããŸããŸãã</p>
<p>æã人ãäžäººãããªãããã« $K$ åã®è³éãåé
ãããšããSegtree ãããããããè³éã®æå€§å€ãæ±ããŠãã ããã</p>
<h3>å
¥å</h3>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã</p>
<pre>
N K
</pre>
<h3>åºå</h3>
<p>Segtree ãããããããè³éã®æå€§å€ãåºåããŠãã ããã</p>
<p>ãã ããæåŸã«ã¯æ¹è¡ãå
¥ããããšã</p>
<h3>å¶çŽ</h3>
<ul>
<li>$1 \leq N,K \leq 10^{18}$</li>
<li>å
¥åã¯å
šãп޿°ã§ããã</li>
</ul>
<h3>å
¥åäŸ1</h3>
<pre>
1 1
</pre>
<h3>åºåäŸ1</h3>
<pre>
1
</pre>
<h3>å
¥åäŸ2</h3>
<pre>
819875141880895728 349993004923078537
</pre>
<h3>åºåäŸ2</h3>
<pre>
174996502461539284
</pre>
|
p03899 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> panels arranged in a row in Takahashi's house, numbered <var>1</var> through <var>N</var>. The <var>i</var>-th panel has a number <var>A_i</var> written on it. Takahashi is playing by throwing balls at these panels.</p>
<p>Takahashi threw a ball <var>K</var> times. Let the panel hit by a boll in the <var>i</var>-th throw be panel <var>p_i</var>. He set the score for the <var>i</var>-th throw as <var>i \times A_{p_i}</var>.</p>
<p>He was about to calculate the total score for his throws, when he realized that he forgot the panels hit by balls, <var>p_1,p_2,...,p_K</var>. The only fact he remembers is that for every <var>i</var> <var>(1 ⊠i ⊠K-1)</var>, <var>1 ⊠p_{i+1}-p_i ⊠M</var> holds. Based on this fact, find the maximum possible total score for his throws.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ⊠M ⊠N ⊠100,000</var></li>
<li><var>1 ⊠K ⊠min(300,N)</var></li>
<li><var>1 ⊠A_i ⊠10^{9}</var></li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Scores</h3><ul>
<li>In the test set worth <var>100</var> points, <var>M = N</var>.</li>
<li>In the test set worth another <var>200</var> points, <var>N ⊠300</var> and <var>K ⊠30</var>.</li>
<li>In the test set worth another <var>300</var> points, <var>K ⊠30</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>
<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 maximum possible total score for Takahashi's throws.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2 3
10 2 8 10 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>56
</pre>
<p>The total score is maximized when panels <var>1,3</var> and <var>4</var> are hit, in this order.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 5 2
5 2 10 5 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>28
</pre>
<p>This case satisfies the additional constraint <var>M = N</var> for a partial score.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 3 5
3 7 2 6 9 4 8 5 1 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>5000000078
</pre></section>
</div>
</span> |
p02271 |
<H1>Exhaustive Search</H1>
<p>
Write a program which reads a sequence <i>A</i> of <i>n</i> elements and an integer <i>M</i>, and outputs "<span>yes</span>" if you can make <i>M</i> by adding elements in <i>A</i>, otherwise "<span>no</span>". You can use an element only once.
</p>
<p>
You are given the sequence <i>A</i> and <i>q</i> questions where each question contains <i>M<sub>i</sub></i>.
</p>
<H2>Input</H2>
<p>
In the first line <i>n</i> is given. In the second line, <i>n</i> integers are given. In the third line <i>q</i> is given. Then, in the fourth line, <i>q</i> integers (<i>M<sub>i</sub></i>) are given.
</p>
<H2>Output</H2>
<p>
For each question <i>M<sub>i</sub></i>, print <span>yes</span> or <span>no</span>.
</p>
<H2>Constraints</H2>
<ul>
<li>n ≤ 20</li>
<li> q ≤ 200 </li>
<li>1 ≤ elements in A ≤ 2000</li>
<li>1 ≤ M<sub>i</sub> ≤ 2000</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
5
1 5 7 10 21
8
2 4 17 8 22 21 100 35
</pre>
<H2>Sample Output 1</H2>
<pre>
no
no
yes
yes
yes
yes
no
no
</pre>
<H2>Notes</H2>
<p>
You can solve this problem by a Burte Force approach. Suppose solve(p, t) is a function which checkes whether you can make t by selecting elements after p-th element (inclusive). Then you can recursively call the following functions:
</p>
<p>
solve(0, M) <br>
solve(1, M-{sum created from elements before 1st element}) <br>
solve(2, M-{sum created from elements before 2nd element}) <br>
...
</p>
<p>
The recursive function has two choices: you selected p-th element and not. So, you can check solve(p+1, t-A[p]) and solve(p+1, t) in solve(p, t) to check the all combinations.
</p>
<p>
For example, the following figure shows that 8 can be made by A[0] + A[2].
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ALDS1_5_A">
</center>
<!--
<a href="template/ALDS1_3_A_template.c" target="_blank">Template in C</a>
-->
|
p03933 | <span class="lang-en lang-child hidden-lang">
<div id="task-statement">
<div class="part">
Max Score: $850$ Points <br/>
<section>
<h3>Problem statement</h3>
There is a circle which radius is 1. <br/>
There are $N$ vertices on the circle's circumference. <br/>
The vertices divides into $N$ equal parts over the circumference. <br/>
<div align="left" class="img-nocaption">
<img src="https://atcoder.jp/img/s8pc-3/4ed4ec92efd07ab59a34520d6e7f1c02.png" width="300"/>
</div>
<br/>
You can choose $3$ distinct vertices, and you can make a triangle. <br/>
There are $\frac{N(N - 1)(N - 2)}{6}$ ways choosing vertices.
The question is: Calculate the area of $K$-th smallest triangle in $\frac{N(N-1)(N-2)}{6}$ triangles. <br/>
If the area is same, you can order in any order. <br/>
<br/>
If $N = 4, K = 3$, the result is following:<br/>
<ul class="simple">
<li>If you select vertices $1$, $2$, and $3$, the area of triangle $= 1$.</li>
<li>If you select vertices $1$, $2$, and $4$, the area of triangle $= 1$.</li>
<li>If you select vertices $1$, $3$, and $4$, the area of triangle $= 1$.</li>
<li>If you select vertices $2$, $3$, and $4$, the area of triangle $= 1$.</li>
</ul>
As a result, the 3rd smallest triangle's area $= 1$.<br/>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
The input is given from Standard Input in the following format: <br/>
<blockquote>$N \ K$
</blockquote>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<ul>
<li>Please output the $K$-th triangle area.</li>
<li>Print a floating number denoting the answer. The relative or absolute error of your answer should not be higher than $10^{â9}$.</li>
</ul>
</section>
<section>
<h3>Constraints</h3>
<ul>
<li>$3 \le N \le 200,000$</li>
<li>$1 \le K \le \frac{N(N-1)(N-2)}{6}$</li>
</ul>
</section>
<section>
<h3>Subtasks</h3>
Subtask 1 [ $160$ points ] <br/>
<ul>
<li>$N \le 100$</li>
</ul>
Subtask 2 [ $240$ points ] <br/>
<ul>
<li>$N \le 1000$</li>
</ul>
Subtask 3 [ $450$ points ] <br/>
<ul>
<li>$N \le 200,000$</li>
</ul>
</section>
</div>
</div>
<div class="part">
<section>
<h3>Sample Input 1</h3>
<pre>
4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3>
<pre>
1.0000000000000
</pre>
This example is already explained in the problem statement. <br/>
</section>
</div>
<div class="part">
<section>
<h3>Sample Input 2</h3>
<pre>
6 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3>
<pre>
0.86602540378
</pre>
There are $6$ ways to choose a triangle which area is $\frac{\sqrt{3}}{4}$. <br/>
There are $10$ ways to choose a triangle which area is $\frac{\sqrt{3}}{2}$. <br/>
There are $2$ ways to choose a triangle which area is $\frac{3 \sqrt{3}}{4}$. <br/>
Therefore, the 9th smallest triangle's area is $\frac{\sqrt{3}}{2}$. <br/>
</section>
</div>
<div class="part">
<section>
<h3>Sample Input 3</h3>
<pre>
12 220
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3>
<pre>
1.29903810568
</pre>
</section>
</div>
Writer: E869120<br/>
</div>
</span> |
p02621 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an integer <var>a</var> as input, print the value <var>a + a^2 + a^3</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq a \leq 10</var></li>
<li><var>a</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>a</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the value <var>a + a^2 + a^3</var> as an integer.</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>14
</pre>
<p>When <var>a = 2</var>, we have <var>a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14</var>.</p>
<p>Print the answer as an input. Outputs such as <code>14.0</code> will be judged as incorrect.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1110
</pre></section>
</div>
</span> |
p03460 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>AtCoDeer is thinking of painting an infinite two-dimensional grid in a <em>checked pattern of side <var>K</var></em>.
Here, a checked pattern of side <var>K</var> is a pattern where each square is painted black or white so that each connected component of each color is a <var>K</var> <var>Ã</var> <var>K</var> square.
Below is an example of a checked pattern of side <var>3</var>:</p>
<div style="text-align: center;">
<img alt="cba927b2484fad94fb5ff7473e9aadef.png" src="https://img.atcoder.jp/arc089/cba927b2484fad94fb5ff7473e9aadef.png">
</img></div>
<p>AtCoDeer has <var>N</var> desires.
The <var>i</var>-th desire is represented by <var>x_i</var>, <var>y_i</var> and <var>c_i</var>.
If <var>c_i</var> is <code>B</code>, it means that he wants to paint the square <var>(x_i,y_i)</var> black; if <var>c_i</var> is <code>W</code>, he wants to paint the square <var>(x_i,y_i)</var> white.
At most how many desires can he satisfy at the same time?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1</var> <var>â€</var> <var>N</var> <var>â€</var> <var>10^5</var></li>
<li><var>1</var> <var>â€</var> <var>K</var> <var>â€</var> <var>1000</var></li>
<li><var>0</var> <var>â€</var> <var>x_i</var> <var>â€</var> <var>10^9</var></li>
<li><var>0</var> <var>â€</var> <var>y_i</var> <var>â€</var> <var>10^9</var></li>
<li>If <var>i</var> <var>â </var> <var>j</var>, then <var>(x_i,y_i)</var> <var>â </var> <var>(x_j,y_j)</var>.</li>
<li><var>c_i</var> is <code>B</code> or <code>W</code>.</li>
<li><var>N</var>, <var>K</var>, <var>x_i</var> and <var>y_i</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>x_1</var> <var>y_1</var> <var>c_1</var>
<var>x_2</var> <var>y_2</var> <var>c_2</var>
<var>:</var>
<var>x_N</var> <var>y_N</var> <var>c_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum number of desires that can be satisfied at the same time.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 3
0 1 W
1 2 W
5 3 B
5 4 B
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>He can satisfy all his desires by painting as shown in the example above.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 1000
0 0 B
0 1 W
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 2
1 2 B
2 1 W
2 2 B
1 0 B
0 6 W
4 5 W
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
</pre></section>
</div>
</span> |
p03030 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have decided to write a book introducing good restaurants.
There are <var>N</var> restaurants that you want to introduce: Restaurant <var>1</var>, Restaurant <var>2</var>, <var>...</var>, Restaurant <var>N</var>. Restaurant <var>i</var> is in city <var>S_i</var>, and your assessment score of that restaurant on a <var>100</var>-point scale is <var>P_i</var>.
No two restaurants have the same score.</p>
<p>You want to introduce the restaurants in the following order:</p>
<ul>
<li>The restaurants are arranged in lexicographical order of the names of their cities.</li>
<li>If there are multiple restaurants in the same city, they are arranged in descending order of score.</li>
</ul>
<p>Print the identification numbers of the restaurants in the order they are introduced in the book.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N †100</var></li>
<li><var>S</var> is a string of length between <var>1</var> and <var>10</var> (inclusive) consisting of lowercase English letters.</li>
<li><var>0 †P_i †100</var></li>
<li><var>P_i</var> is an integer.</li>
<li><var>P_i â P_j</var> <var>(1 †i < j †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>S_1</var> <var>P_1</var>
<var>:</var>
<var>S_N</var> <var>P_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>N</var> lines. The <var>i</var>-th line (<var>1 †i †N</var>) should contain the identification number of the restaurant that is introduced <var>i</var>-th in the book.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
4
6
1
5
2
</pre>
<p>The lexicographical order of the names of the three cities is <code>kazan</code> <var><</var> <code>khabarovsk</code> <var><</var> <code>moscow</code>. For each of these cities, the restaurants in it are introduced in descending order of score. Thus, the restaurants are introduced in the order <var>3,4,6,1,5,2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10
yakutsk 10
yakutsk 20
yakutsk 30
yakutsk 40
yakutsk 50
yakutsk 60
yakutsk 70
yakutsk 80
yakutsk 90
yakutsk 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>10
9
8
7
6
5
4
3
2
1
</pre></section>
</div>
</span> |
p01518 |
<!-- begin en only -->
<h3><u>Dog Food
</u></h3>
<!-- end en only -->
<!-- begin ja only -->
<h3><u>ããã°ããŒã
</u></h3>
<!-- end ja only -->
<div>
<!-- begin en only -->
<p>
English text is not available in this practice contest.
</p>
<!-- end en only -->
<!-- begin ja only -->
<p>
ããªãã¯, è³¢ãç¬ãéžã¶ã³ã³ãã¹ãã®äž»å¬è
ã§ããïŒ
çš®ç®ã®1ã€ã«ïŒä»¥äžã®ãããªãã®ãããïŒ
</p>
<p>
ãã®çš®ç®ã¯ïŒå¹³é¢çãªåºå Žã®äžã§è¡ãããïŒ
åºå Žã«ã¯æãããã€ãç«ã£ãŠããïŒãã®ãã¡ã®1ã€ãšïŒç¬ã¯ããŒãã§çµã°ããŠããïŒæãããŒãã®å€ªãã¯ç¡èŠã§ãããã®ãšããïŒããŒããçµã°ããŠããæã®åº§æšã(0ïŒ0)ïŒç¬ã®äœçœ®ã(DxïŒDy)ãšããïŒ
ãŸãïŒããŒããçµã°ããŠããæä»¥å€ã®æã®æ¬æ°ãïœæ¬ãšãïŒãããã®åº§æšã(x<sub>1</sub>ïŒy<sub>1</sub>)... (x<sub>n</sub>ïŒy<sub>n</sub>)ãšããïŒ
åæç¶æ
ã§ïŒããŒãã¯ãã³ãšåŒµãããç¶æ
ã§ããïŒããªãã¡ïŒããŒãã®é·ãã¯ã¡ããã©(DxïŒDy)ãš(0ïŒ0)ã®è·é¢ã«çããïŒãã®2ã€ã®ç«¯ã¯åç¹ã®æãšç¬ã«ããããçµã³ä»ããããŠããïŒ
(FxïŒFy)ã«ã¯ïŒããã°ããŒããããããŠããïŒãã®å°ç¹ããŽãŒã«ã§ããïŒãã®æ¡ä»¶äžã§ïŒçãèµ°è¡è·é¢ã§ãŽãŒã«ã«èŸ¿ãã€ããç¬ã»ã©è³¢ããšèããããïŒ
å Žåã«ãã£ãŠã¯ïŒå³F-1ã®ããã«ïŒçŽæ¥ãŽãŒã«ã«åãããšïŒå¥ã®æã«ããŒããåŒã£ãããïŒããŒãã®é·ããè¶³ããªããªã£ãŠïŒãŽãŒã«ã«ãã©ãã€ããªãããïŒæãè¿åããå¿
èŠãããããšã«æ³šæããïŒ
ãã®äŸã¯ïŒãµã³ãã«ã®1çªç®ã®å
¥åã衚ããŠããïŒ
</p>
<center>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_ukai">
</center>
</center>
<center>
<p>
<i>å³ F-1: æãè¿åããå¿
èŠãããäŸ</i>
</p>
</center>
<p>
åªç§ãªããã°ã©ããŒã§ãããããªãã¯ïŒç¬ããŽãŒã«ã«ãã©ãçãããã©ããïŒãŸããã©ãçãããšãããæçè·é¢ã¯ã©ããªãã®ããïŒãããããèšç®ããŠããããšã«ããïŒ
</p>
<!-- end ja only -->
</div>
<h3>Input</h3>
<div>
<!-- begin ja only -->
<p>
å
¥åã¯1ã€ä»¥äžã®ããŒã¿ã»ãããããªãïŒ1ã€ã®ããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒãããŠããïŒããŒã¿ã»ããäžã®å€ã¯ïŒå
šãп޿°ã§ããïŒ
</p>
<blockquote>
<var>n</var><br/>
<var>Dx</var> <var>Dy</var><br/>
<var>Fx</var> <var>Fx</var><br/>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var><br/>
<var>...</var><br/>
<var>x<sub>n</sub></var> <var>y<sub>n</sub></var><br/>
</blockquote>
<p>
n ã¯ããŒããç¹ãã£ãŠããªãæã®æ¬æ°ã衚ãïŒ
Dx, Dy ã¯ïŒç¬ã®åæäœçœ®ã®åº§æšã衚ãïŒ
Fx, Fy ã¯ïŒãŽãŒã«ã®äœçœ®ã衚ãïŒ
x<sub>i</sub>, y<sub>i</sub> ã¯ïŒããŒããç¹ãã£ãŠããªãæã®åº§æšã衚ãïŒ
</p>
<p>
ããŒã¿ã»ããã«ã€ããŠïŒã€ãã®å¶çŽãæç«ããŠããïŒ
</p>
<ul>
<li>1 ≤ n ≤ 8</li>
<li>-100 ≤ Dx, Dy, Fx, Fy, x<sub>i</sub>, y<sub>i</sub> ≤ 100</li>
<li>ç·å(0,0), (Dx,Dy)äžã«æã¯ååšããªã.</li>
<li>(0,0), (Dx, Dy), (Fx, Fy), (x<sub>1</sub>, y<sub>1</sub>), (x<sub>2</sub>, y<sub>2</sub>)... (x<sub>n</sub>, y<sub>n</sub>) ã¯ãã¹ãŠç°ãªã座æšã§ãã.</li>
</ul>
<p>
ãŸãïŒä»¥äžã®ããšãä»®å®ããŠãã.
</p>
<ul>
<li>(Dx,Dy) ãåç¹æ¹åã«å¯ŸããŠ, ε(|ε| < 0.00001)ã ãå€åãããšã, çµæã 0.0005 ãã倧ããå€åããããšã¯ãªãïŒ</li>
</ul>
<p>
å
¥åã®çµããã¯ïŒ0ã1ã€ã ãå«ãè¡ã§è¡šãããïŒ
</p>
<!-- end ja only -->
</div>
<h3>Output</h3>
<div>
<!-- begin ja only -->
<p>
åããŒã¿ã»ããã«ã€ããŠïŒãŽãŒã«ã«ãã©ãçããå Žåã¯æçè·é¢ãïŒãã©ãçããªãå Žåã¯-1ã 1 è¡ã«åºåããïŒ
åºåã«ã¯, 0.001ãè¶
ãã誀差ããã£ãŠã¯ãªããªã.
</p>
<!-- end ja only -->
</div>
<h3>Sample Input</h3>
<div>
<pre>
1
-4 -8
3 -8
0 -6
1
0 6
4 0
1 4
1
4 0
0 6
1 4
4
95 0
0 90
55 64
33 31
5 4
15 43
8
100 100
99 -100
60 50
6 5
12 10
24 20
30 0
70 0
-30 -10
-90 -30
0
</pre>
<!-- begin ja only -->
<p>
å³F-2, F-3, F-4 ã¯ïŒãããããµã³ãã«ã®2çªç®ãã4çªç®ã®é
眮ã瀺ããŠããïŒ
</p>
<center>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_sample0">
</center>
</center>
<center>
<p>
<i>å³ F-2: 2çªç®ã®ãµã³ãã«</i>
</p>
</center>
<center>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_sample1">
</center>
</center>
<center>
<p>
<i>å³ F-3: 3çªç®ã®ãµã³ãã«</i>
</p>
</center>
<center>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_sample2">
</center>
</center>
<center>
<p>
<i>å³ F-4: 4çªç®ã®ãµã³ãã«</i>
</p>
</center>
<!-- end ja only -->
</div>
<h3>Output for Sample Input</h3>
<div>
<pre>
8.0776872
7.2360679
-1
140.2870005
273.9090890
</pre>
<!-- begin ja only -->
<!-- end ja only -->
</div> |
p03525 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In CODE FESTIVAL XXXX, there are <var>N+1</var> participants from all over the world, including Takahashi.</p>
<p>Takahashi checked and found that the <em>time gap</em> (defined below) between the local times in his city and the <var>i</var>-th person's city was <var>D_i</var> hours.
The time gap between two cities is defined as follows. For two cities A and B, if the local time in city B is <var>d</var> o'clock at the moment when the local time in city A is <var>0</var> o'clock, then the time gap between these two cities is defined to be <var>min(d,24-d)</var> hours.
Here, we are using <var>24</var>-hour notation.
That is, the local time in the <var>i</var>-th person's city is either <var>d</var> o'clock or <var>24-d</var> o'clock at the moment when the local time in Takahashi's city is <var>0</var> o'clock, for example.</p>
<p>Then, for each pair of two people chosen from the <var>N+1</var> people, he wrote out the time gap between their cities. Let the smallest time gap among them be <var>s</var> hours.</p>
<p>Find the maximum possible value of <var>s</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 50</var></li>
<li><var>0 \leq D_i \leq 12</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>D_1</var> <var>D_2</var> <var>...</var> <var>D_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible value of <var>s</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
7 12 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>For example, consider the situation where it is <var>7</var>, <var>12</var> and <var>16</var> o'clock in each person's city at the moment when it is <var>0</var> o'clock in Takahashi's city. In this case, the time gap between the second and third persons' cities is <var>4</var> hours.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
11 11
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>Note that Takahashi himself is also a participant.</p></section>
</div>
</span> |
p01148 |
<!-- begin en only -->
<h3><U> Princess, a Strategist </U></h3>
<!-- end en only -->
<!-- begin ja only -->
<h3><U> ãå§«æ§ã¯æŠç¥å®¶ </U></h3>
<!-- end ja only -->
<!-- begin en only -->
<p>
English text is not available in this practice contest.
</p>
<!-- end en only -->
<!-- begin ja only -->
<p>
ããè²§ä¹ãªåœã®åæ¢ãªãå§«æ§ã¯ïŒãåãæãåºããŠå€ã®ç§å®ãæã«å
¥ããåéºã«åºãããç®æ®µãããŠããïŒãšãããïŒå€ã®ç§å®ã®åšå²ã¯è€æ°ã®ã¬ãŒãã£ã¢ã³ã«ãã£ãŠå®ãããŠããïŒæ®éã®æ¹æ³ã§ã¯èŸ¿ãçãããšãã§ããªãïŒããã§ïŒãå§«æ§ã¯åŸè
ã§ããããªããå®ã«ãïŒã¬ãŒãã£ã¢ã³éã®æ³šæãæ¹ãã€ããŠããéã«ç§å®ãåã£ãŠæ¥ããšããäœæŠãèããïŒãã®ãããªäºããããŠã¯åœãããã€ãã£ãŠãè¶³ããªãïŒããããå§«æ§ã®åœä»€ã«åŸããªãããã«ããããªãïŒããã§ïŒãŸãããªãã¯ãããããåµå¯ããïŒã©ã®ããã«åãã°ã¬ãŒãã£ã¢ã³ã®æ»æããããã€ã€ïŒæ³šæãåŒãã€ããããã®ãã念å
¥ãã«èª¿æ»ããïŒããªãã®ä»äºã¯ïŒãããã®èª¿æ»çµæãããšã«å®ã§ããããªããšã¬ãŒãã£ã¢ã³ã®çºå°ãã匟䞞ã®è¡çªããã€ïŒãããŠäœåèµ·ãã£ãã®ãèšç®ããããã°ã©ã ãæžãããšã§ããïŒ
</p>
<p>
ãŸãïŒç°¡åã®ããïŒãã£ãŒã«ããšããŠååã«é«ãå ŽæããèŠäžãããäºæ¬¡å
å¹³é¢ãèããïŒãããŠïŒããªãã¯ã¬ãŒãã£ã¢ã³ã®æ»æãã身ãå®ãããã«é§ãè£
åããŠããïŒãã®ããïŒããªãã®åœ¢ã¯å€è§åœ¢ã§ã§ãããã®ãšèããŠè¯ãïŒãªãïŒãã®å€è§åœ¢ã®åç·åã¯äžå亀差ãããéãªã£ããããªãïŒãŸãïŒããªãã®ç§»åã«ã€ããŠã¯ä»¥äžã®ããšãä»®å®ããŠè¯ãïŒ
</p>
<ul>
<li>çéçŽç·éåããããªãïŒ
<ul>
<li>å éïŒæžéïŒæ¹å転æã¯å
šãŠäžç¬ã§è¡ãããïŒ </li>
<li>å転ããªãããåãã¯åæç¶æ
ããäžåå€ãããªãïŒ</li>
</ul>
</li>
<li>å€è§åœ¢ã®å
šãŠã®éšåã¯åžžã« <i>y</i> 座æšãæ£ã®äœçœ®ã«ããïŒ</li>
</ul>
<p>
ãŸãïŒã¬ãŒãã£ã¢ã³ã®çºå°ãã匟䞞ã«ã€ããŠã¯ïŒä»¥äžã®ããšãä»®å®ããŠè¯ãïŒ
</p>
<ul>
<li>ã¬ãŒãã£ã¢ã³ãçºå°ãã匟䞞ã®å€ªãã¯ç¡èŠã§ãã </li>
<li>ã¬ãŒãã£ã¢ã³ãçºå°ããåŒŸäžžã¯æéã®é·ããã〠</li>
<li>é·ã <i>l</i> ã®åŒŸäžžãå
é åº§æš (<i>x</i>, 0) ããé床ãã¯ãã« (<i>v</i><sub><i>x</i></sub>, <i>v</i><sub><i>y</i></sub>) ããã£ãŠçºå°ããããšãããšïŒåŒŸäžžã®æ«å°Ÿåº§æšã¯ä»¥äžã®å°ç¹ã«ããïŒæ³šïŒåŒŸäžžãçºå°ãããç¬éã®åŒŸäžžã®å
é ã® <i>y</i> 座æšã¯ãã¹ãŠ0ã§ããïŒïŒ<br>
<center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_formula" alt="(x - (l * vx / sqrt(vx^2 + vy^2)), 0 - (l * vy / sqrt(vx^2 + vy^2))"></center>
<ul>
<li> ããšãã°ïŒ(4, 0) ã®å°ç¹ããé床ãã¯ãã« (3, 4) ã®é·ã 10 ã®åŒŸäžžãçºå°ãããã±ãŒã¹ã§ã¯åŒŸäžžã®æ«å°Ÿã¯(-2, -8) ã«ãã</li>
</ul>
</li>
<li> æµãã£ã©ã¯ã¿ãŒãçºå°ãã匟䞞å士ã®è¡çªã¯å
šãŠç¡èŠããã </li>
</ul>
<p>
ããªããšã¬ãŒãã£ã¢ã³ã®çºå°ãã匟䞞ã®è¡çªã®å®çŸ©ã以äžã«è¿°ã¹ãïŒããªããæ§æããå€è§åœ¢ãšã¬ãŒãã£ã¢ã³ã®çºå°ããç·åã®å
±æç¹ãåããŠçºçããæå»ã匟䞞ã®è¡çªæå»ãšããïŒã¬ãŒãã£ã¢ã³ã®çºå°ãã匟䞞ã«ããªããè¡çªãããšããŠãïŒããªãã¯ãã¡ãŒãžãåããã ãã§ç§»åã«ã¯äœã®æ¯éãããããªããã®ãšãïŒããªãã«è¡çªãã匟䞞ã¯è¡çªããç¬éã«æ¶æ»
ãããã®ãšããïŒãªãïŒããªããåæäœçœ®ããä»»æã®æ¹åã« 10<sup>-6</sup> ã®ç¯å²ã§å¹³è¡ç§»åãããšããŠãïŒè¡çªæéã¯é«ã
10<sup>-5</sup> ããå€åããªãããšãä¿èšŒãããŠããïŒ
</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>
å
¥åã¯ïŒè€æ°ã®ããŒã¿ã»ãããããªãïŒ
</p>
<p>
ããããã®ããŒã¿ã»ããã¯ïŒæ¬¡ã®ãããªåœ¢åŒã§äžããããïŒ
</p>
<blockquote>
<i>N</i> <i>M</i> <i>B</i><br>
<i>X</i><sub>1</sub> <i>Y</i><sub>1</sub><br>
...<br>
<i>X</i><sub><i>N</i></sub> <i>Y</i><sub><i>N</i></sub><br>
<i>T</i><sub>1</sub> <i>VX</i><sub>1</sub> <i>VY</i><sub>1</sub><br>
...<br>
<i>T</i><sub><i>M</i></sub> <i>VX</i><sub><i>M</i></sub> <i>VY</i><sub><i>M</i></sub><br>
<i>T'</i><sub>1</sub> <i>X'</i><sub>1</sub> <i>VX'</i><sub>1</sub> <i>VY'</i><sub>1</sub> <i>L</i><sub>1</sub><br>
...<br>
<i>T'</i><sub><i>B</i></sub> <i>X'</i><sub><i>B</i></sub> <i>VX'</i><sub><i>B</i></sub> <i>VY'</i><sub><i>B</i></sub> <i>L</i><sub><i>B</i></sub>
</blockquote>
<p>
åããŒã¿ã»ããã®å
é ã«ã¯3ã€ã®éè² æŽæ°
<i>N</i> (3 ⊠<i>N</i> ⊠20)ïŒ
<i>M</i> (0 ⊠<i>M</i> ⊠100)ïŒ
<i>B</i> (0 ⊠<i>B</i> ⊠100)
ãäžããããïŒ
ãããã¯ããããïŒããªãã§ããå€è§åœ¢ã®é ç¹ã®æ°ïŒããªãã®ç§»åã«é¢ããæ
å ±ã®æ°ïŒããã³ã¬ãŒãã£ã¢ã³ã®çºå°ããåŒŸäžžã®æ°ã衚ãïŒ
</p>
<p>
ç¶ã <i>N</i> è¡ã§ã¯ïŒããªãã衚ãå€è§åœ¢ã®é ç¹ã®æå»0ã§ã®åº§æšãé ã«åæãããïŒ
(<i>X</i><sub><i>i</i></sub>, <i>Y</i><sub><i>i</i></sub>)
(1 ⊠<i>i</i> ⊠<i>N</i>)
ã¯ããããïŒå€è§åœ¢ã® <i>i</i> çªç®ã®é ç¹ã®åº§æšã衚ãïŒ
ãããã®å€ã¯ãã¹ãп޿°ã§ããïŒ
-10,000 ⊠<i>X</i><sub><i>i</i></sub> ⊠10,000ïŒ
0 ïŒ <i>Y</i><sub><i>i</i></sub> ⊠10,000
ãæºããïŒ
</p>
<p>
ç¶ã <i>M</i> è¡ã§ã¯ïŒ
ããªãã®ç§»åã衚ãæç€ºã <i>M</i> åäžããããïŒ
<i>i</i>çªç® (1 ⊠<i>i</i> ⊠<i>M</i>) ã®ç§»åæç€ºã¯
3ã€ã®æŽæ° <i>T</i><sub><i>i</i></sub>, <i>VX</i><sub><i>i</i></sub>,
<i>VY</i><sub><i>i</i></sub> ããæãç«ã£ãŠããïŒ
ãã㯠æå» <i>T</i><sub><i>i</i>-1</sub> ãã <i>T</i><sub><i>i</i></sub>
ãŸã§ã®éïŒããªãã®é床ãã¯ãã«ã
(<i>VX</i><sub><i>i</i></sub>, <i>VY</i><sub><i>i</i></sub>)
ã«ç¶æãããšããããšãæå³ããïŒ
ãã ãïŒ
0 = <i>T</i><sub>0</sub> ïŒ <i>T</i><sub>1</sub> ïŒ <i>T</i><sub>2</sub>
ïŒ ... ïŒ <i>T</i><sub><i>M</i></sub> ⊠10,000ïŒ
-100 ⊠<i>VX</i><sub><i>i</i></sub> ⊠100ïŒ
-100 ⊠<i>VY</i><sub><i>i</i></sub> ⊠100
ã§ããïŒ
ããªãããã¹ãŠã®ç§»åæç€ºãçµããåŸïŒããªãã¡ïŒæå»
<i>T</i><sub><i>M</i></sub> 以éïŒã¯ç§»åã忢ãïŒ
ãã®å Žã«ãšã©ãŸãç¶ãããã®ãšããïŒ
ããªãã忢ãã以éã«ã匟䞞ãšã®è¡çªãçºçããå¯èœæ§ãããïŒ
åºåã«éããŠã¯ãã®ãããªè¡çªãèæ
®ããå¿
èŠãããããšã«æ³šæããïŒ
</p>
<p>
ç¶ã <i>B</i> è¡ã§ã¯ïŒã¬ãŒãã£ã¢ã³ã®çºå°ãã <i>B</i>
åã®åŒŸäžžã«é¢ããæ
å ±ãèšè¿°ãããŠããïŒ
<i>i</i> çªç® (1 ⊠<i>i</i> ⊠<i>B</i>) ã®åŒŸäžžã«é¢ããæ
å ±ã¯5ã€ã®æŽæ°
<i>T'</i><sub><i>i</i></sub>ïŒ
<i>X'</i><sub><i>i</i></sub>ïŒ
<i>VX'</i><sub><i>i</i></sub>ïŒ
<i>VY'</i><sub><i>i</i></sub> ããã³
<i>L</i><sub><i>i</i></sub>
ã§è¡šããïŒããã¯ïŒæå» <i>T'</i><sub><i>i</i></sub>
ã«åº§æš (<i>X'</i><sub><i>i</i></sub>, 0)
ããé床ãã¯ãã«
(<i>VX'</i><sub><i>i</i></sub>, <i>VY'</i><sub><i>i</i></sub>)
ããã€é·ã <i>L</i><sub><i>i</i></sub> ã®åŒŸäžžãçºå°ãããããšãæå³ããïŒ
ãããã®å€ã¯
0 ⊠<i>T'</i><sub>1</sub> ⊠<i>T'</i><sub>2</sub> ⊠...
⊠<i>T'</i><sub><i>B</i></sub> ⊠10,000ïŒ
-10,000 ⊠<i>X'</i><sub><i>i</i></sub> ⊠10,000ïŒ
-100 ⊠<i>VX'</i><sub><i>i</i></sub> ⊠100ïŒ
0 ïŒ <i>VY'</i><sub><i>i</i></sub> ⊠100ïŒ
0 ïŒ <i>L</i><sub><i>i</i></sub> ⊠100
ãæºããïŒ
</p>
<p>
æåŸã®ããŒã¿ã»ããã®åŸãã«ïŒããŒã¿ã»ããã®çµäºãæå³ãã
"0 0 0" ãšæžããã1è¡ãäžããããïŒ
ããã¯ããŒã¿ã»ããã®äžéšã§ã¯ãªãïŒ
</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>
åããŒã¿ã»ããã«å¯Ÿããåºåã®å
é ã«ïŒããªããã¬ãŒãã£ã¢ã³ã®çºå°ãã匟䞞ã«è¡çªããåæ° <i>n</i> ãåºåããïŒç¶ã <i>n</i> è¡ã§ã¯ïŒããªããã¬ãŒãã£ã¢ã³ã®çºå°ãã匟䞞ã«è¡çªããæå»ãæé ã«èª€å·®é«ã
0.001 ã®ç²ŸåºŠã§åºåããïŒ
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>
4 1 1
1 1
1 2
-1 2
-1 1
2 1 0
0 1 0 1 2
0 0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
1
1.000
</pre>
|
p03175 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a tree with <var>N</var> vertices, numbered <var>1, 2, \ldots, N</var>.
For each <var>i</var> (<var>1 \leq i \leq N - 1</var>), the <var>i</var>-th edge connects Vertex <var>x_i</var> and <var>y_i</var>.</p>
<p>Taro has decided to paint each vertex in white or black.
Here, it is not allowed to paint two adjacent vertices both in black.</p>
<p>Find the number of ways in which the vertices can be painted, modulo <var>10^9 + 7</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 \leq 10^5</var></li>
<li><var>1 \leq x_i, y_i \leq N</var></li>
<li>The given graph is a tree.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>x_1</var> <var>y_1</var>
<var>x_2</var> <var>y_2</var>
<var>:</var>
<var>x_{N - 1}</var> <var>y_{N - 1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways in which the vertices can be painted, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 2
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>There are five ways to paint the vertices, as follows:</p>
<p><img alt="" src="https://img.atcoder.jp/dp/indep_0_muffet.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 2
1 3
1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9
</pre>
<p>There are nine ways to paint the vertices, as follows:</p>
<p><img alt="" src="https://img.atcoder.jp/dp/indep_1_muffet.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>10
8 5
10 8
6 5
1 5
4 8
2 10
3 6
9 2
1 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>157
</pre></section>
</div>
</span> |
p02334 | <!--<h1>åå12çž ãã®4:ããŒã«ã«åºå¥ãªãã»ç®±ã«åºå¥ããã»å
¥ãæ¹ã«å¶éãªã</h1>-->
<h1>Balls and Boxes 4</h1>
<table border="">
<tr><th>Balls</th><th>Boxes</th><th>Any way</th><th>At most one ball</th><th>At least one ball</th></tr>
<tr><th>Distinguishable</th><th>Distinguishable</th><td>1</td><td>2</td><td>3</td></tr>
<tr><th>Indistinguishable</th><th>Distinguishable</th><td style="background-color:#aff">4</td><td>5</td><td>6</td></tr>
<tr><th>Distinguishable</th><th>Indistinguishable</th><td>7</td><td>8</td><td>9</td></tr>
<tr><th>Indistinguishable</th><th>Indistinguishable</th><td>10</td><td>11</td><td>12</td></tr>
</table>
<h2>Problem</h2>
<p>You have $n$ balls and $k$ boxes. You want to put these balls into the boxes.</p>
<p>Find the number of ways to put the balls under the following conditions:</p>
<ul>
<li>Each ball is <b>not</b> distinguished from the other.</li>
<li>Each box is distinguished from the other.</li>
<li>Each ball can go into only one box and no one remains outside of the boxes.</li>
<li>Each box can contain an arbitrary number of balls (including zero).</li>
</ul>
<p>Note that you must print this count modulo $10^9+7$.</p>
<h2>Input</h2>
<pre>
$n$ $k$
</pre>
<p>The first line will contain two integers $n$ and $k$.</p>
<h2>Output</h2>
<p>Print the number of ways modulo $10^9+7$ in a line.</p>
<h2>Constraints</h2>
<ul>
<li>$1 \le n \le 1000$</li>
<li>$1 \le k \le 1000$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
5 3
</pre>
<h2>Sample Output 1</h2>
<pre>
21
</pre>
<h2>Sample Input 2</h2>
<pre>
10 5
</pre>
<h2>Sample Output 2</h2>
<pre>
1001
</pre>
<h2>Sample Input 3</h2>
<pre>
100 100
</pre>
<h2>Sample Output 3</h2>
<pre>
703668401
</pre>
|
p00309 |
<h1>ã¢ã«ãã³åœçã®é
æ
®</h1>
<p>
ã¢ã«ãã³åœã®åœçã«ã¯ïŒäººã®çåãããŸããåœçã¯èªåãéäœãããšãã«åœãïŒã€ã«åå²ããããããã®çåã«äžã€ãã€åœãæ²»ããããããšã«ããŸãããæ°ããåœã®ååã¯ã¢ã«åœãšãã³åœã§ããã¢ã«ãã³åœã«ã¯ <var>N</var> åã®çºãšãïŒã€ã®çºãç¹ã <var>M</var> æ¬ã®éããããŸããåœçã¯ã以äžã®æé ã§ã¢ã«ãã³åœã®çºãšäžéšã®éãïŒã€ã®åœã«é
åããããšã«ããŸããã<br>
<br>
(1) çºãïŒã€éžã³ãããããã¢ã«åœãšãã³åœã«é
åããã<br>
(2) ãã§ã«é
åãããçºsãéžã¶ãããã«ãçº <var>s</var> ããïŒæ¬ã®éã§ç¹ãã£ãŠããããŸã é
åãããŠããªãçº <var>t</var> ãéžã¶ããããŠãçº <var>s</var>ã<var>t</var> éã®éãšçº <var>t</var> ããçº <var>s</var> ãé
åãããåœã«é
åããã<br>
(3) (2)ããè¡ããªããªããŸã§ç¹°ãè¿ãã
</p>
<p>
å®ã¯ïŒäººã®çåã¯ããŸã仲ãè¯ããªãã®ã§ãåœçã¯ïŒã€ã®åœã®è·é¢ããªãã¹ã倧ããããããšèããŠããŸããããã§ãïŒã€ã®åœã®è·é¢ãšã¯ãã¢ã«åœã®çºãšãã³åœã®çºãç¹ãéã®äžã§ãæãçãéã®é·ãã§ãã
</p>
<p>
ã¢ã«ãã³åœã®çºãšéã®æ
å ±ãäžãããããšããåé
åŸã®ã¢ã«åœãšãã³åœã®è·é¢ã®æå€§å€ãšããã®ãããªè·é¢ã«ãªãé
åãäœéãããããæ±ããããã°ã©ã ãäœæããŠãã ããããã ããïŒã€ã®é
åçµæã¯ãã¢ã«åœãšãã³åœã«ç°ãªãçºãéãé
åãããå Žåã«åºå¥ãããŸãã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var> <var>M</var>
<var>s<sub>1</sub></var> <var>t<sub>1</sub></var> <var>d<sub>1</sub></var>
<var>s<sub>2</sub></var> <var>t<sub>2</sub></var> <var>d<sub>2</sub></var>
:
<var>s<sub>M</sub></var> <var>t<sub>M</sub></var> <var>d<sub>M</sub></var>
</pre>
<p>
ïŒè¡ç®ã¯ïŒã€ã®æŽæ°ãããªãã<var>N</var> (2 ≤ <var>N</var> ≤ 100) ã¯çºã®æ°ã<var>M</var> (<var>N</var>-1 ≤ <var>M</var> ≤ <var>N</var>(<var>N</var>-1)/2) ã¯éã®æ°ã衚ããç¶ã<var>M</var> è¡ã«ïŒã€ã®çºãç¹ãéãäžããããã<var>s<sub>i</sub></var> ãš <var>t<sub>i</sub></var> (1 ≤ <var>s<sub>i</sub></var> ≠ <var>t<sub>i</sub></var> ≤ <var>N</var>) 㯠<var>i</var> çªç®ã®éãç¹ãïŒã€ã®çºã®çªå·ã衚ãã<var>d<sub>i</sub></var> (1 ≤ <var>d<sub>i</sub></var> ≤ 10<sup>9</sup>) 㯠<var>i</var> çªç®ã®éã®é·ãã衚ãã
</p>
<p>
å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã
</p>
<ul>
<li> ã©ã®ïŒã€ã®çºãããã€ãã®éã䜿ãè¡ãæ¥ãå¯èœã§ããã</li>
<li> ã©ã®ïŒã€ã®çºã®éã«ãïŒæ¬ä»¥äžã®éã¯ãªãã</li>
<li> åãé·ãã®éã¯ïŒæ¬ä»¥äžã§ããã</li>
</ul>
<h2>åºå</h2>
<p>
åé
åŸã®ã¢ã«åœãšãã³åœã®è·é¢ã®æå€§å€ãšçµã¿åããã®æ°ãã空çœåºåãã§ïŒè¡ã«åºåããããã ããåé
åŸã®çµã¿åããã®æ°ã¯éåžžã«å€§ãããªãããã®ã§ã代ããã« 1,000,000,007 ã§å²ã£ãäœããåºåããã
</p>
<h2>å
¥åºåäŸ </h2>
<h2>å
¥åäŸ </h2>
<pre>
6 7
1 2 1
2 3 2
3 1 3
4 5 4
5 6 5
6 4 6
1 4 7
</pre>
<h2>åºåäŸ</h2>
<pre>
7 18
</pre>
|
p03876 | <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>Construct an <var>N</var>-gon that satisfies the following conditions:</p>
<ul>
<li>The polygon is simple (see notes for the definition).</li>
<li>Each edge of the polygon is parallel to one of the coordinate axes.</li>
<li>Each coordinate is an integer between <var>0</var> and <var>10^9</var>, inclusive.</li>
<li>The vertices are numbered <var>1</var> through <var>N</var> in counter-clockwise order.</li>
<li>The internal angle at the <var>i</var>-th vertex is exactly <var>a_i</var> degrees.</li>
</ul>
<p>In case there are multiple possible answers, you can output any.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><p>A polygon is called simple if each edge has a positive length, and no two edges have a common point (except for adjacent edges touching at a vertex).</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 †N †1000</var></li>
<li><var>a_i</var> is either <var>90</var> or <var>270</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_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>In case the answer exists, print the answer in the following format:</p>
<pre><var>x_1</var> <var>y_1</var>
:
<var>x_N</var> <var>y_N</var>
</pre>
<p>Here <var>(x_i, y_i)</var> are the coordinates of the <var>i</var>-th vertex.</p>
<p>In case the answer doesn't exist, print a single <code>-1</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>8
90
90
270
90
90
90
270
90
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0 0
2 0
2 1
3 1
3 2
1 2
1 1
0 1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
90
90
90
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre></section>
</div>
</span> |
p02764 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi wants to grill <var>N</var> pieces of meat on a grilling net, which can be seen as a two-dimensional plane. The coordinates of the <var>i</var>-th piece of meat are <var>\left(x_i, y_i\right)</var>, and its <em>hardness</em> is <var>c_i</var>.</p>
<p>Takahashi can use one heat source to grill the meat. If he puts the heat source at coordinates <var>\left(X, Y\right)</var>, where <var>X</var> and <var>Y</var> are real numbers, the <var>i</var>-th piece of meat will be ready to eat in <var>c_i \times \sqrt{\left(X - x_i\right)^2 + \left(Y-y_i\right)^2}</var> seconds.</p>
<p>Takahashi wants to eat <var>K</var> pieces of meat. Find the time required to have <var>K</var> or more pieces of meat ready if he put the heat source to minimize this time.</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 60</var></li>
<li><var>1 \leq K \leq N</var></li>
<li><var>-1000 \leq x_i , y_i \leq 1000</var></li>
<li><var>\left(x_i, y_i\right) \neq \left(x_j, y_j\right) \left(i \neq j \right)</var></li>
<li><var>1 \leq c_i \leq 100</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>x_1</var> <var>y_1</var> <var>c_1</var>
<var>\vdots</var>
<var>x_N</var> <var>y_N</var> <var>c_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
<p>It will be considered correct if its absolute or relative error from our answer is at most <var>10^{-6}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 3
-1 0 3
0 0 3
1 0 2
1 1 40
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2.4
</pre>
<p>If we put the heat source at <var>\left(-0.2, 0\right)</var>, the <var>1</var>-st, <var>2</var>-nd, and <var>3</var>-rd pieces of meat will be ready to eat within <var>2.4</var> seconds. This is the optimal place to put the heat source.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 5
-879 981 26
890 -406 81
512 859 97
362 -955 25
128 553 17
-885 763 2
449 310 57
-656 -204 11
-270 76 40
184 170 16
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>7411.2252
</pre></section>
</div>
</span> |
p00759 |
<h3><U>A Broken Door</U></h3>
<!-- end en only -->
<div> <!-- please enclose each h3 level section with div -->
<!-- begin en only -->
<p>
There is a rectangular maze consisting of a number of square rooms
arranged in grid. The maze is surrounded by
walls except for its entry and exit. The entry to the maze is at the
leftmost part of the upper side of the rectangular area, that is, the
upper side of the uppermost leftmost room of the maze is open. The
exit is located at the rightmost part of the lower side, likewise.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
There is a wall between each pair of vertically or horizontally adjacent rooms. Such a wall has either
a door with a card key lock, or no door at all. If you insert a card
to a door, the door opens and you can pass the door. The opened door
will close immediately, and the inserted card won't return. You can
open any door with any card. You cannot go
through a wall that has no door.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
When a maze map is given, you can easily determine how many cards are
needed to pass through the maze from the entry to the exit. In the
maze in Figure G-1, you can pass through it with ten cards,
following the path represented by the green arrows (<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1178_0">) in Figure G-2.
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1178_1" align="center" width="274" width="274"><br>
<!-- begin en only -->
Figure G-1: A map of a maze<br>
<!-- end en only -->
</center>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1178_2" align="center" width="274"><br>
<!-- begin en only -->
Figure G-2: One of the shortest paths<br>
<!-- end en only -->
</center>
<!-- begin en only -->
<p>
Now, you are informed that one of the doors is broken and can't be
passed. But you don't know which door is broken. If you insert a card
to a broken door, the inserted card immediately returns. However,
you can't tell a broken door from a working door just by its
appearance.
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1178_3" align="center" width="274"><br>
<!-- begin en only -->
Figure G-3: A maze that potentially can't be passed through<br>
<!-- end en only -->
</center>
<!-- begin en only -->
<p>
If the door marked with a red X (<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1178_x">) in Figure G-3 is broken, you have no way to pass through
the maze from the entry to the exit. However, you can pass the maze in
Figure G-1 whichever door is broken. When you intend to follow the
shortest path in Figure G-2, and find that the door marked with a red X in Figure G-4 is broken, you
might follow the path represented as green arrows. In this case, you
need twenty cards.
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1178_4" align="center" width="274"><br>
<!-- begin en only -->
Figure G-4: A maze with a broken door<br>
<!-- end en only -->
</center>
<!-- begin en only -->
<p>
However, you can pass through the maze with less cards. You should
follow the path in Figure G-5, until you find the broken door.
The path is not the shortest path because it needs twelve
cards at least. After you've found a broken door on the path, you
should follow the shortest path to the exit that doesn't use the broken
door. With this strategy, you can pass the maze with sixteen cards
whichever door is broken. Figure G-6 shows one of the worst cases of
this strategy; it needs sixteen cards.
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1178_5" align="center" width="274"><br>
<!-- begin en only -->
Figure G-5: The path before you find the broken door<br>
<!-- end en only -->
</center>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1178_6" align="center" width="274"><br>
<!-- begin en only -->
Figure G-6: One of the worst cases of the strategy<br>
<!-- end en only -->
</center>
<!-- begin en only -->
<p>
You are requested to write a program that prints the minimum number of
cards to pass the maze whichever door is broken.
</p>
<!-- end en only -->
</div>
<h3>Input</h3>
<div>
<!-- begin en only -->
<p>
The input consists of one or more datasets, each of which represents a
maze. The number of datasets is no more than 100.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The first line of a dataset contains two integer numbers, the
height <i>h</i> and the width <i>w</i> of the rectangular maze, in
this order. You may assume that 2 ≤ h, w ≤ 30.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The following 2 × <i>h</i> − 1 lines of a dataset describe
whether there are doors between rooms or not. The first line starts
with a space and the rest of the line contains <i>w</i> − 1
integers, 1 or 0, separated by a space. These indicate whether doors
connect horizontally adjoining rooms in the first row. An integer
0 indicates a door is placed, and 1 indicates no door is there. The
second line starts without a space and contains <i>w</i> integers, 1 or 0,
separated by a space. These indicate whether doors connect
vertically adjoining rooms in the first and the second rows. An
integer 0/1 indicates a door is placed or not. The following lines
indicate placing of doors between horizontally and vertically
adjoining rooms, alternately, in the same manner.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The end of the input is indicated by a line containing two zeros.
</p>
<!-- end en only -->
</div>
<h3>Output</h3>
<div>
<!-- begin en only -->
<p>
For each dataset, output a line having an integer indicating the
minimum number of cards needed.
If there exists no path to pass through the maze when a certain door is broken, output a line containing −1.
The line should not contain any character other than this number.
</p>
<!-- end en only -->
</div>
<h3>Sample Input</h3>
<div>
<pre>
4 8
0 0 0 0 0 0 1
0 0 0 0 0 0 0 1
0 0 0 0 1 0 0
0 1 1 1 1 0 0 0
1 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 1 0
4 8
0 0 0 0 0 0 1
0 0 0 0 0 0 0 1
0 0 0 0 1 0 0
0 1 1 1 1 0 0 0
1 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 1
2 2
0
0 0
0
3 3
0 0
0 1 0
0 1
0 0 0
0 0
2 4
1 0 1
0 0 0 0
0 1 0
6 12
0 0 0 1 1 0 0 0 0 0 0
0 1 1 0 0 0 0 0 0 1 1 0
1 0 0 1 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 1 1 0 0 1 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 1 1 0 0 1 1 0 0
0 0 0 1 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 1 1 0 0
0 0 0 0 0 1 1 0 0 1 0 0
1 0 0 0 0 0 0 1 0 0 0
20 20
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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>
</div>
<h3>Output for the Sample Input</h3>
<div>
<pre>
16
-1
4
10
-1
32
40
</pre>
</div> |
p01261 |
<H1><font color="#000">Problem B:</font> Bitwise Kingdom</H1>
<p>
In the Bitwise Kingdom, located somewhere in the universe, there are exactly 2<sup><i>N</i></sup> citizens living and each
of them has a unique identification string that represents his or her class in the society. An identification
string is a binary string of length <i>N</i> which consists of characters â<span>0</span>â or â<span>1</span>â. The order of classes is defined
among the citizens by the following criteria:
</p>
<ol>
<li>Citizens identified by a string containing a greater number of ones are ranked higher. For example,
â011â indicates a higher class than â100â.</li>
<li> Among those who have identification strings with the same number of ones, citizens identified by
a lexicographically greater identification string are ranked higher. For example, â110â indicates a
higher class than â101â.</li>
</ol>
<p>
For example, if <i>N</i> = 3, there are 8 (= 2<sup>3</sup>) people in the country, and their identification strings are â000â,
â001â, â010â, â100â, â011â, â101â, â110â, and â111â (from the lowest class to the highest).
</p>
<p>
You are given two numbers <i>N</i> (1 ≤ <i>N</i> ≤ 60) and <i>M</i> (1 ≤ <i>M</i> ≤ 2<sup><i>N</i></sup>), and you want to resolve the
identification string of the person of the <i>M</i>-th lowest class among 2<sup><i>N</i></sup> citizens. Can you write a program
to solve this problem?
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets.
</p>
<p>
Each dataset consists of a line which contains two integers <i>N</i> and <i>M</i> in this order, separated with a single
space. The input does not contain any other extra characters such as leading or trailing spaces.
</p>
<p>
The end of input is indicated by a line with two zeros. This line is not part of any datasets.
</p>
<H2>Output</H2>
<p>
For each dataset, print the identification string of the person of the <i>M</i>-th lowest class in one line. Your
program may not omit any leading zeros in the answer.
</p>
<H2>Sample Input</H2>
<pre>
3 3
3 5
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
010
011
</pre>
|
p00889 |
<H1><font color="#000">Problem F:</font> Find the Multiples</H1>
<p>
You are given a sequence <i>a</i><sub>0</sub><i>a</i><sub>1</sub>...<i>a</i><sub><i>N</i>-1</sub> digits and a prime number <i>Q</i>. For each <i>i</i> ≤ <i>j</i> with <i>a<sub>i</sub></i> ≠ 0, the subsequence <i>a</i><sub><i>i</i></sub><i>a</i><sub></i>i</i>+1</sub>...<i>a<sub>j</sub></i> can be read as a decimal representation of a positive integer. Subsequences with leading zeros are not considered. Your task is to count the number of pairs (<i>i</i>, <i>j</i>) such that the corresponding subsequence is a multiple of <i>Q</i>.
</p>
<H2>Input</H2>
<p>
The input consists of at most 50 datasets. Each dataset is represented by a line containing four integers <i>N</i>, <i>S</i>, <i>W</i>, and <i>Q</i>, separated by spaces, where 1 ≤ <i>N</i> ≤ 10<sup>5</sup>, 1 ≤ <i>S</i> ≤ 10<sup>9</sup>, 1 ≤ <i>W</i> ≤ 10<sup>9</sup>, and <i>Q</i> is a prime number less than 10<sup>8</sup>. The sequence <i>a</i><sub>0</sub>...<i>a</i><sub><i>N</i>-1</sub> of length <i>N</i> is generated by the following code, in which ai is written as <span>a[i]</span>.
</p>
<pre>
int g = S;
for(int i=0; i<N; i++) {
a[i] = (g/7) % 10;
if( g%2 == 0 ) { g = (g/2); }
else { g = (g/2) ^ W; }
}
</pre>
<p>
<b>Note:</b> the operators <span>/</span>, <span>%</span>, and <span>^</span> are the integer division, the modulo, and the bitwise exclusiveor, respectively. The above code is meant to be a random number generator. The intended solution does not rely on the way how the sequence is generated.
</p>
<p>
The end of the input is indicated by a line containing four zeros separated by spaces.
</p>
<H2>Output</H2>
<p>
For each dataset, output the answer in a line. You may assume that the answer is less than 2<sup>30</sup>.
</p>
<H2>Sample Input</H2>
<pre>
3 32 64 7
4 35 89 5
5 555 442 3
5 777 465 11
100000 666 701622763 65537
0 0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
4
6
3
68530
</pre>
<p>
In the first dataset, the sequence is 421. We can find two multiples of <i>Q</i> = 7, namely, 42 and 21.
</p>
<p>
In the second dataset, the sequence is 5052, from which we can find 5, 50, 505, and 5 being the multiples of <i>Q</i> = 5. Notice that we don't count 0 or 05 since they are not a valid representation of positive integers. Also notice that we count 5 twice, because it occurs twice in different positions.
</p>
<p>
In the third and fourth datasets, the sequences are 95073 and 12221, respectively.
</p>
|
p01631 |
<h1>Problem E: è±èªã®å匷</h1>
<h2>Problem Statement</h2>
<p>
äŒæŽ¥å宿ã«åå äºå®ã®é«æ§»ããã¯å匷ç±å¿ã§ãæè¿ã¯è±èªã®å匷ãããã°ã£ãŠããã圌女ã¯ãæºåž¯ã䜿ã£ãŠæ¬¡ã®ãããªã²ãŒã ããã¬ã€ããããšã§ãå°ãã§ãå€ãè±åèªãèŠããããšããŠããã圌女ãæã£ãŠããæºåž¯ã¯ãæã§ç»é¢ãæäœããã¿ããããã«åŒã§ããã
</p>
<p>
æºåž¯ã®ç»é¢ã«ã¯ã4 * 4ã®ãã¹ç®ãæãããŠãããåãã¹ã«ã¯ã¢ã«ãã¡ããã倧æåãæžãããŠããããã®ã²ãŒã ã¯ãå¶éæéTç§ã®éã«ããã¹ç®ã®äžã«é ãããŠããè±åèªãããããèŠã€ããçºèŠã§ããè±åèªã®çš®é¡ã«ããç¹æ°ãç«¶ããã®ã§ããã
</p>
<p>
1ã€ã®åèªãèŠã€ããæé ã¯ã次ã®ããã«ãªãããŸããåèªã®1æåç®ã«å¯Ÿå¿ããéå§ãã¹ã決ããŠãããã«æã眮ãããããŠã仿ã眮ããŠãããã¹ç®ãããäžäžå·Šå³ã»æãã®ã飿¥ãã8æ¹åã®ãã¹ã®ããããã«åãã£ãŠãæã§ãªãã£ãŠããããã ããéå§ãã¹ããçŸåšã®ãã¹ãŸã§ãã§ã«èŸ¿ã£ãããšããããã¹ã¯ãéãããšãã§ããªããåèªã®çµäºãã¹ã«éããããããã§æãé¢ãããã®ç¬éãéå§ãã¹ããçµäºãã¹ãŸã§æã§ãªãã£ãåèª1ã€ã®ç¹æ°ãå ç¹ããããxæåã®åèª1ã€ããªããããã«ã¯ãxç§ã®æéãããããããåèªããªãã£ãŠãããæ¬¡ã®åèªããªããããã®æã®ç§»åæéã¯ç¡èŠããŠããã
</p>
<p>
å
¥åã§ã¯ãå ç¹å¯Ÿè±¡ãšãªãåèªã®èŸæžãå
¥åãããããã®èŸæžã®ååèªã«ã¯ãç¹æ°ãæ¯ãããŠãããèŸæžã®äžã«æžãããŠããåèªãæã§ãªãããšããã®åèªã«å¯Ÿå¿ããç¹æ°ãå ç®ãããããã ããéå§ãã¹ããçµäºãã¹ãŸã§ãå
šãåãæã®ãªããæ¹ãããåèªã¯ãæåã®1åããç¹æ°å ç®ãããªããèŸæžã«æžãããŠããªãåèªãæã§ãªãã£ãŠãå ç¹ã¯ãããªãã
</p>
<p>
èŸæžãšã²ãŒã ã®ç€é¢ãäžããããã®ã§ãå¶éæéå
ã«åŸãããæå€§ã®ç¹æ°ãåºåããã
</p>
<h2>Input</h2>
<p>
åããŒã¿ã»ããã¯ã以äžã®åœ¢åŒã§å
¥åãããã
</p>
<pre>N
word1 score1
word2 score2
...
wordN scoreN
line1
line2
line3
line4
T
</pre>
<p>
Nã¯ãèŸæžã«å«ãŸããåèªã®æ°ã衚ããæŽæ°ã§ãããç¶ããŠNè¡ã«ããã£ãŠãèŸæžãå
¥åããããwordiã¯1ã€ã®åèªã衚ããã¢ã«ãã¡ããã倧æåã§æ§æãããæååãscoreiã¯wordiã®åèªãæã§ãªãã£ããšãã«åŸãããç¹æ°ã衚ããæŽæ°ã§ãããèŸæžã®äžã«ãåãåèªã2å以äžçŸããããšã¯ãªãã
</p>
<p>
ç¶ããŠ4è¡ã«ããã£ãŠãåãã¹ç®ã®æåãå
¥åããããlineiã¯ã4æåã®ã¢ã«ãã¡ããã倧æåã ãã§æ§æãããæååã§ãããlineiã®å·Šããjæåç®ã¯ãiè¡ç®ã®å·Šããjçªç®ã®æåã«å¯Ÿå¿ããã
</p>
<p>
äžçªæåŸã«ãå¶éæéã衚ããæŽæ°Tãå
¥åãããã
</p>
<h2>Constraints</h2>
<ul>
<li>1 <= N <= 100</li>
<li>1 <= wordiã®æååé· <= 8</li>
<li>1 <= scorei <= 100</li>
<li>1 <= T <= 10000</li>
</ul>
<h2>Output</h2>
<p>
å¶éæéå
ã«ååŸã§ããæé«ã®ç¹æ°ã1è¡ã§åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>6
AIZU 10
LINER 6
LINE 4
ALL 2
AS 1
CIEL 10
ASLA
CILI
IRZN
ELEU
21
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>40
</pre>
<p>
å³1ã«æäœäŸã瀺ããäŸãã°ã次ã®ããã«ãªãããš40ç¹ãšãªãã
<ul>
<li>"CIEL"ã¯ãæååã®é·ãã4ã§ãããã4ç§ãããŠ10ç¹ã</li>
<li>"AIZU"ã¯ãéããªããæ¹ãããã°ã2ã€çºèŠã§ããããã8ç§ãããŠ20ç¹ã</li>
<li>"LINER"ã5ç§ãããŠ6ç¹ã</li>
<li>"LINE"ã4ç§ãããŠ4ç¹ã</li>
</ul>
åèš21ç§ãããŠã40ç¹ãšãªãã
</p>
<div align="center">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2013Day1_E1">
</div> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.