question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p02728 | <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 numbered <var>1</var> to <var>N</var>. The <var>i</var>-th edge in this tree connects Vertex <var>a_i</var> and <var>b_i</var>.
For each <var>k=1, ..., N</var>, solve the problem below:</p>
<ul>
<li>Consider writing a number on each vertex in the tree in the following manner:<ul>
<li>First, write <var>1</var> on Vertex <var>k</var>.</li>
<li>Then, for each of the numbers <var>2, ..., N</var> in this order, write the number on the vertex chosen as follows:<ul>
<li>Choose a vertex that still does not have a number written on it and is adjacent to a vertex with a number already written on it. If there are multiple such vertices, choose one of them at random.</li>
</ul>
</li>
</ul>
</li>
<li>Find the number of ways in which we can write the numbers on the vertices, modulo <var>(10^9+7)</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>2 \leq N \leq 2 \times 10^5</var></li>
<li><var>1 \leq a_i,b_i \leq N</var></li>
<li>The given graph is a tree.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>b_1</var>
<var>:</var>
<var>a_{N-1}</var> <var>b_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>For each <var>k=1, 2, ..., N</var> in this order, print a line containing the answer to the problem.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 2
1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
1
1
</pre>
<p>The graph in this input is as follows:</p>
<p><img alt="Figure" src="https://img.atcoder.jp/ghi/1c88b0eb716ba399b1c5d6565ab62337.png"/></p>
<p>For <var>k=1</var>, there are two ways in which we can write the numbers on the vertices, as follows:</p>
<ul>
<li>Writing <var>1, 2, 3</var> on Vertex <var>1, 2, 3</var>, respectively</li>
<li>Writing <var>1, 3, 2</var> on Vertex <var>1, 2, 3</var>, respectively</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>1
1
</pre>
<p>The graph in this input is as follows:</p>
<p><img alt="Figure" src="https://img.atcoder.jp/ghi/c47c7798f88e7bfec30fbd664dc9ad50.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
1 2
2 3
3 4
3 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
8
12
3
3
</pre>
<p>The graph in this input is as follows:</p>
<p><img alt="Figure" src="https://img.atcoder.jp/ghi/e9c09403f8d96ae4e679a226993defa6.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>8
1 2
2 3
3 4
3 5
3 6
6 7
6 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>40
280
840
120
120
504
72
72
</pre>
<p>The graph in this input is as follows:</p>
<p><img alt="Figure" src="https://img.atcoder.jp/ghi/a85459a03d436560bfe2e911d8cec4e6.png"/></p></section>
</div>
</span> |
p01807 |
<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>
<!-- begin en only -->
<h3><u>Stamp Rally</u></h3>
<!-- end en only -->
<!-- begin ja only -->
<h3><u>ã¹ã¿ã³ãã©ãªãŒ</u></h3>
<!-- end ja only -->
<!-- end en only -->
<!-- begin ja only -->
<p>æ¥æ¬ã¢ãã¥ãŒãºã¡ã³ãã°ã«ãŒã (Japan Amusement Group, JAG) ã§ã¯ïŒå³¶åœãæš¡ããããŒãããŒã¯ã§ã®ã€ãã³ããäŒç»ããŠããïŒ
ãã®ã€ãã³ãã§ã¯ïŒåå è
ã¯æ©ãæž¡ããã³ã«æ©ããšã«æ±ºããããã¹ã¿ã³ããã¹ã¿ã³ãåž³ã«é çªã«æŒããŠããïŒ
çšæãããã¹ã¿ã³ãã¯ä»¥äžã®7çš®é¡ã®ã©ããã§ããïŒ
</p><pre>a ( ) [ ] + *</pre><p>ã¹ã¿ãŒããããŽãŒã«ãŸã§æ©ãæž¡ãæ©ããŠïŒæŒãããã¹ã¿ã³ãã®åãæ£ããæ°åŒã«ãªãã°ã¯ãªã¢ã§ããïŒ
ãã ãæ©ãæž¡ãåãã¯æ±ºãŸã£ãŠããŠïŒéåãã«æž¡ãããšã¯ã§ããªãïŒ
åãæ©ãäœåºŠãæž¡ã£ãŠããïŒæçµçã«ãŽãŒã«å°ç¹ã«å°çããã®ã§ããã°äžåºŠãŽãŒã«å°ç¹ã«çããåŸã«åŒãç¶ãã¹ã¿ã³ããéããŠãããïŒ
æ£ããæ°åŒãšã¯ä»¥äžã® BNF ã§å®çŸ©ããã <expression> ã§ããïŒ
</p>
<pre><expression> ::= <term> | <expression> "+" <term>
<term> ::= <factor> | <term> "*" <factor>
<factor> ::= "a" | "(" <expression> ")" | "[" <expression> "]"</pre>
<p>ã¹ã¿ãŒãã»ãŽãŒã«ãšæ©ããšã®ã¹ã¿ã³ããæ±ºããã®ã§ïŒé¢ä¿è
ã§è©Šãã«ãã£ãŠã¿ãããªããªãã¯ãªã¢ãã人ãçŸããªãïŒ
ããããããïŒãã®èšå®ã§ã¯ã¯ãªã¢ããããšãã§ããªãã®ãããããªãïŒ
</p>
<p>ã¹ã¿ãŒãã»ãŽãŒã«ãšæ©ã®æ
å ±ãäžããããã®ã§ïŒã¯ãªã¢å¯èœãã©ãããå€å®ããããã°ã©ã ãæžããªããïŒ
</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>å
¥åã¯50å以äžã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§è¡šãããïŒ
</p>
<blockquote><var>n</var> <var>m</var> <var>s</var> <var>t</var><br><var>a</var><sub>1</sub> <var>b</var><sub>1</sub> <var>c</var><sub>1</sub><br>...<br><var>a<sub>m</sub></var> <var>b<sub>m</sub></var> <var>c<sub>m</sub></var></blockquote>
<p>ããŒã¿ã»ããã®æåã®è¡ã¯ïŒç©ºçœæå1åã§åºåããã4åã®æŽæ° <var>n</var>, <var>m</var>, <var>s</var>, <var>t</var> ãããªãïŒ
<var>n</var> ã¯å³¶ã®æ°ã§ããïŒ 1 ≤ <var>n</var> ≤ 200 ãšä»®å®ããŠããïŒ
ããããã®å³¶ã«ã¯ 1 ãã <var>n</var> ãŸã§ã®çªå·ãä»ããããŠããïŒ
<var>m</var> ã¯æ©ã®æ°ã§ããïŒ 1 ≤ <var>m</var> ≤ 100,000 ãšä»®å®ããŠããïŒ
<var>s</var> ã¯ã¹ã¿ãŒãã®å³¶ã®çªå·ïŒ <var>t</var> ã¯ãŽãŒã«ã®å³¶ã®çªå·ã§ããïŒã¹ã¿ãŒããšãŽãŒã«ãåãå³¶ã§ããããšãããïŒ
ç¶ã <var>m</var> è¡ã®ããããã¯ïŒç©ºçœæå1åã§åºåããã2åã®æŽæ°ãš1åã®æåãããªãïŒ
<var>a<sub>i</sub></var>ïŒ <var>b<sub>i</sub></var> 㯠<var>i</var> çªç®ã®æ©ã«ãã£ãŠå³¶ <var>a<sub>i</sub></var> ããå³¶ <var>b<sub>i</sub></var> ãžæž¡ããããšã衚ãïŒ <var>c<sub>i</sub></var> 㯠<var>i</var> çªç®ã®æ©ã§æŒãã¹ã¿ã³ãã衚ãïŒãã2ã€ã®å³¶ã®éã«è€æ°ã®æ©ãããã£ãŠãããïŒ1ã€ã®å³¶ã®äžã§æ©ãããã£ãŠãããããããšãããïŒ
</p>
<p>å
¥åã®çµããã¯ïŒ4ã€ã®ãŒããããªã1è¡ã§ç€ºãããïŒ
</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>åããŒã¿ã»ããã«å¯ŸããŠïŒã¯ãªã¢ã§ãããªãã°"<samp>Yes</samp>"ãïŒã§ããªããªãã°"<samp>No</samp>"ã1è¡ã«åºåããïŒ
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>4 5 1 4
1 2 (
1 3 a
2 4 a
3 4 )
3 2 +
4 4 1 2
1 3 (
3 4 a
4 1 +
3 2 a
3 4 1 1
1 2 a
2 2 +
2 3 a
3 1 a
5 8 1 5
1 1 [
1 2 (
2 1 *
2 2 a
2 3 a
3 3 )
3 4 ]
4 5 )
2 14 1 1
1 2 a
1 2 (
1 2 )
1 2 [
1 2 ]
1 2 +
1 2 *
2 1 a
2 1 (
2 1 )
2 1 [
2 1 ]
2 1 +
2 1 *
0 0 0 0</pre>
<h3>Output for Sample Input</h3>
<pre>Yes
No
No
Yes
No</pre> |
p02682 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>A</var> cards, each of which has an integer <var>1</var> written on it. Similarly, we also have <var>B</var> cards with <var>0</var>s and <var>C</var> cards with <var>-1</var>s.</p>
<p>We will pick up <var>K</var> among these cards. What is the maximum possible sum of the numbers written on the cards chosen?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>0 \leq A, B, C</var></li>
<li><var>1 \leq K \leq A + B + C \leq 2 \times 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>A</var> <var>B</var> <var>C</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible sum of the numbers written on the cards chosen.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 1 1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>Consider picking up two cards with <var>1</var>s and one card with a <var>0</var>.
In this case, the sum of the numbers written on the cards is <var>2</var>, which is the maximum possible value.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 2 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2000000000 0 0 2000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2000000000
</pre></section>
</div>
</span> |
p03990 | <span class="lang-en">
<p>Score : <var>1400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Sigma and Sugim are playing a game.</p>
<p>The game is played on a graph with <var>N</var> vertices numbered <var>1</var> through <var>N</var>. The graph has <var>N-1</var> red edges and <var>N-1</var> blue edges, and the <var>N-1</var> edges in each color forms a tree. The red edges are represented by pairs of integers <var>(a_i, b_i)</var>, and the blue edges are represented by pairs of integers <var>(c_i, d_i)</var>.</p>
<p>Each player has his own piece. Initially, Sigma's piece is at vertex <var>X</var>, and Sugim's piece is at vertex <var>Y</var>.</p>
<p>The game is played in turns, where turns are numbered starting from turn <var>1</var>. Sigma takes turns <var>1, 3, 5, ...</var>, and Sugim takes turns <var>2, 4, 6, ...</var>.</p>
<p>In each turn, the current player either moves his piece, or does nothing. Here, Sigma can only move his piece to a vertex that is directly connected to the current vertex by a red edge. Similarly, Sugim can only move his piece to a vertex that is directly connected to the current vertex by a blue edge.</p>
<p>When the two pieces come to the same vertex, the game ends immediately. If the game ends just after the operation in turn <var>i</var>, let <var>i</var> be the total number of turns in the game.</p>
<p>Sigma's objective is to make the total number of turns as large as possible, while Sugim's objective is to make it as small as possible.</p>
<p>Determine whether the game will end in a finite number of turns, assuming both players plays optimally to achieve their respective objectives. If the answer is positive, find the number of turns in the game.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 ⊠N ⊠200,000</var></li>
<li><var>1 ⊠X, Y ⊠N</var></li>
<li><var>X \neq Y</var></li>
<li><var>1 ⊠a_i, b_i, c_i, d_i ⊠N</var></li>
<li>The <var>N-1</var> edges in each color (red and blue) forms a tree.</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>X</var> <var>Y</var>
<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
<var>:</var>
<var>a_{N-1}</var> <var>b_{N-1}</var>
<var>c_1</var> <var>d_1</var>
<var>c_2</var> <var>d_2</var>
<var>:</var>
<var>c_{N-1}</var> <var>d_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the game will end in a finite number of turns, print the number of turns.
Otherwise, print <code>-1</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 1 2
1 2
1 3
1 4
2 1
2 3
1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p><img alt="" src="https://atcoder.jp/img/agc005/0f55f48518cb9031ee9f1cc30f686228.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3 1
1 2
2 3
1 2
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre>
<p><img alt="" src="https://atcoder.jp/img/agc005/df982a9959ce46d5d5f63800f8972bff.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 1 2
1 2
3 4
2 4
1 2
3 4
1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
</pre>
<p><img alt="" src="https://atcoder.jp/img/agc005/11ce9a2283a853025b7075769439d745.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>4 2 1
1 2
3 4
2 4
1 2
3 4
1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>-1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>5 1 2
1 2
1 3
1 4
4 5
2 1
1 3
1 5
5 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>6
</pre></section>
</div>
</span> |
p00345 |
<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>
宿°ã®ãã¡ãå°æ°éšã埪ç°ãããã®ãšæéæ¡ã®ãã®ã¯åæ°ãšããŠè¡šãããšãã§ããŸãã
</p>
<br/>
<p>
åæ°ã§è¡šãããšãã§ãã宿°ãäžãããããšãããã®å®æ°ãšçããæ¢çŽåæ°ïŒãã以äžçŽåã§ããªãåæ°ïŒãåºåããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>str</var>
</pre>
<p>
ïŒè¡ã«ã倿ããã宿°ã衚ãæåå <var>str</var> ãäžããããã宿°ã®å€ã¯ 0 ãã倧ãããæååã¯æ°åãã.ããã(ããã)ããå«ããé·ãã 3 ä»¥äž 8 以äžã®æååã§ãããã.ãã¯å°æ°ç¹ãã(ãã¯æ°åã®åŸªç°ã®å§ãŸããã)ãã¯æ°åã®åŸªç°ã®çµããã瀺ããæŽæ°éšã«ãå°æ°éšã«ããå¿
ãïŒæ¡ä»¥äžã®æ°åãäžãããããšããããã ãã埪ç°å°æ°ãäžããããå Žåãæååã¯ä»¥äžã®æ¡ä»¶ãæºããã
</p>
<ul>
<li> 埪ç°ã®å§ãŸããšçµããã®ãã¢ã¯ãå°æ°ç¹ã®å³åŽã«äžåºŠã ãçŸããã </li>
<li> 埪ç°ã®çµããã瀺ãã)ãã¯ãæååã®æ«å°Ÿã«çŸããã</li>
<li> 埪ç°ã®å§ãŸããšçµããã®éã«ã¯ãå¿
ãïŒæ¡ä»¥äžã®æ°åãäžããããã</li>
</ul>
<h2>Output</h2>
<p>
宿°ãæ¢çŽåæ°ã§è¡šãã圢åŒïŒååã®æŽæ°ã«ç¶ããŠã/ãåºåãã§åæ¯ã®æŽæ°ã䞊ã¹ããã®ïŒã§åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
0.(3)
</pre>
<h2>Sample Output 1</h2>
<pre>
1/3
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
1.0
</pre>
<h2>Sample Output 2</h2>
<pre>
1/1
</pre>
<br/>
<h2>Sample Input 3</h2>
<pre>
5.2(143)
</pre>
<h2>Sample Output 3</h2>
<pre>
52091/9990
</pre>
<br/>
<h2>Sample Input 4</h2>
<pre>
0.0739
</pre>
<h2>Sample Output 4</h2>
<pre>
739/10000
</pre>
<br/>
|
p02378 |
<H1>Bipartite Matching</H1>
<p>
A bipartite graph <var>G = (V, E)</var> is a graph in which the vertex set <var>V</var> can be divided into two disjoint subsets <var>X</var> and <var>Y</var> such that every edge <var>e ∈ E</var> has one end point in <var>X</var> and the other end point in <var>Y</var>.
</p>
<p>
A matching <var>M</var> is a subset of edges such that each node in <var>V</var> appears in at most one edge in <var>M</var>.
</p>
<p>
Given a bipartite graph, find the size of the matching which has the largest size.
</p>
<H2>Input</H2>
<pre>
<var>|X|</var> <var>|Y|</var> <var>|E|</var>
<var>x<sub>0</sub></var> <var>y<sub>0</sub></var>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var>
:
<var>x<sub>|E|-1</sub></var> <var>y<sub>|E|-1</sub></var>
</pre>
<p>
<var>|X|</var> and <var>|Y|</var> are the number of vertices in <var>X</var> and <var>Y</var> respectively, and <var>|E|</var> is the number of edges in the graph <var>G</var>. The vertices in <var>X</var> are named with the numbers 0, 1,..., <var>|X|</var>-1, and vertices in <var>Y</var> are named with the numbers 0, 1,..., <var>|Y|</var>-1, respectively.
</p>
<p>
<var>x<sub>i</sub></var> and <var>y<sub>i</sub></var> are the node numbers from <var>X</var> and <var>Y</var> respectevely which represent the end-points of the <var>i</var>-th edge.
</p>
<H2>Output</H2>
<p>
Print the largest size of the matching.
</p>
<H2>Constraints</H2>
<ul>
<li>1 ≤ <var>|X|</var>, <var>|Y|</var> ≤ 100</li>
<li>0 ≤ <var>|E|</var> ≤ 10,000</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
3 4 6
0 0
0 2
0 3
1 1
2 1
2 3
</pre>
<H2>Sample Output 1</H2>
<pre>
3
</pre>
|
p03139 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We conducted a survey on newspaper subscriptions.
More specifically, we asked each of the <var>N</var> respondents the following two questions:</p>
<ul>
<li>Question <var>1</var>: Are you subscribing to Newspaper X?</li>
<li>Question <var>2</var>: Are you subscribing to Newspaper Y?</li>
</ul>
<p>As the result, <var>A</var> respondents answered "yes" to Question <var>1</var>, and <var>B</var> respondents answered "yes" to Question <var>2</var>.</p>
<p>What are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y?</p>
<p>Write a program to answer this question.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 100</var></li>
<li><var>0 \leq A \leq N</var></li>
<li><var>0 \leq B \leq N</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible number and the minimum possible number of respondents subscribing to both newspapers, in this order, with a space in between.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>10 3 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3 0
</pre>
<p>In this sample, out of the <var>10</var> respondents, <var>3</var> answered they are subscribing to Newspaper X, and <var>5</var> answered they are subscribing to Newspaper Y.</p>
<p>Here, the number of respondents subscribing to both newspapers is at most <var>3</var> and at least <var>0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5 2
</pre>
<p>In this sample, out of the <var>10</var> respondents, <var>7</var> answered they are subscribing to Newspaper X, and <var>5</var> answered they are subscribing to Newspaper Y.</p>
<p>Here, the number of respondents subscribing to both newspapers is at most <var>5</var> and at least <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100 100 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>100 100
</pre></section>
</div>
</span> |
p01104 |
<h3><u>Making Lunch Boxes</u></h3>
<p>
Taro has been hooked on making lunch boxes recently.
Taro has obtained a new lunch box recipe book today, and wants to try as many of the recipes listed in the book as possible.
</p>
<p>
Enough of the ingredients for all the recipes are at hand, but they all are in vacuum packs of two.
If only one of them is used leaving the other, the leftover will be rotten easily, but making two of the same recipe is not interesting.
Thus he decided to make a set of lunch boxes, each with different recipe, that wouldn't leave any unused ingredients.
</p>
<p>
Note that the book may include recipes for different lunch boxes made of the same set of ingredients.
</p>
<p>
How many lunch box recipes can Taro try today at most following his dogma?
</p>
<h3>Input</h3>
<p>
The input consists of at most 50 datasets, each in the following format.
</p>
<pre>
<i>n</i> <i>m</i>
<i>b</i><sub>1,1</sub>...<i>b</i><sub>1,<i>m</i></sub>
...
<i>b</i><sub><i>n,</i>1</sub>...<i>b</i><sub><i>n,m</i></sub>
</pre>
<p>
The first line contains <i>n</i>, which is the number of recipes listed in the book, and <i>m</i>, which is the number of ingredients.
Both <i>n</i> and <i>m</i> are positive integers and satisfy 1 ≤ <i>n</i> ≤ 500, 1 ≤ <i>m</i> ≤ 500 and <b>1 ≤ <i>n</i> Ã <i>m</i> ≤ 500</b>.
The following <i>n</i> lines contain the information for each recipe with the string of length <i>m</i> consisting of 0 or 1.
<i>b<sub>i,j</sub></i> implies whether the <i>i</i>-th recipe needs the <i>j</i>-th ingredient.
1 means the ingredient is needed for the recipe and 0 means not.
Each line contains at least one 1.
</p>
<p>
The end of the input is indicated by a line containing two zeros.
</p>
<h3>Output</h3>
<p>
For each dataset, output the maximum number of recipes Taro can try.
</p>
<h3>Sample Input</h3>
<pre>4 3
110
101
011
110
7 1
1
1
1
1
1
1
1
4 5
10000
01000
00100
00010
6 6
111111
011000
100000
000010
100001
100100
0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>3
6
0
6
</pre>
|
p03093 | <span class="lang-en">
<p>Score : <var>1200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let <var>M</var> be a positive integer.</p>
<p>You are given <var>2 N</var> integers <var>a_1, a_2, \ldots, a_{2 N}</var>, where <var>0 \leq a_i < M</var> for each <var>i</var>.</p>
<p>Consider dividing the <var>2 N</var> integers into <var>N</var> pairs.
Here, each integer must belong to exactly one pair.</p>
<p>We define the <em>ugliness</em> of a pair <var>(x, y)</var> as <var>(x + y) \mod M</var>.
Let <var>Z</var> be the largest ugliness of the <var>N</var> pairs. Find the minimum possible value of <var>Z</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 M \leq 10^9</var></li>
<li><var>0 \leq a_i < M</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>a_1</var> <var>a_2</var> <var>\cdots</var> <var>a_{2N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible value of <var>Z</var>, where <var>Z</var> is the largest ugliness of the <var>N</var> pairs.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 10
0 2 3 4 5 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>One solution is to form pairs <var>(0, 5), (2, 3)</var> and <var>(4, 9)</var>, with ugliness <var>5, 5</var> and <var>3</var>, respectively.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 10
1 9 1 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>Pairs <var>(1, 9)</var> and <var>(1, 9)</var> should be formed, with ugliness both <var>0</var>.</p></section>
</div>
</span> |
p03569 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a string <var>s</var> consisting of lowercase English letters.
Snuke can perform the following operation repeatedly:</p>
<ul>
<li>Insert a letter <code>x</code> to any position in <var>s</var> of his choice, including the beginning and end of <var>s</var>.</li>
</ul>
<p>Snuke's objective is to turn <var>s</var> into a palindrome.
Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><p>A <em>palindrome</em> is a string that reads the same forward and backward.
For example, <code>a</code>, <code>aa</code>, <code>abba</code> and <code>abcba</code> are palindromes, while <code>ab</code>, <code>abab</code> and <code>abcda</code> are not.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |s| \leq 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>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 the objective is achievable, print the number of operations required.
If it is not, print <code>-1</code> instead.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>xabxa
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>One solution is as follows (newly inserted <code>x</code> are shown in bold):</p>
<p>xabxa â xa<strong>x</strong>bxa â xaxbxa<strong>x</strong></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>ab
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>No sequence of operations can turn <var>s</var> into a palindrome.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>a
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p><var>s</var> is a palindrome already at the beginning.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>oxxx
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>3
</pre>
<p>One solution is as follows:</p>
<p>oxxx â <strong>x</strong>oxxx â <strong>x</strong>xoxxx â <strong>x</strong>xxoxxx</p></section>
</div>
</span> |
p01554 |
<h1>Kagisys</h1>
<p>ããéšå±ã§ã¯ICã«ãŒããçšããŠéµãéãéãããé»åé ã·ã¹ãã ãçšããŠããã
ãã®ã·ã¹ãã ã¯ä»¥äžã®ããã«åäœããã
</p>
<p>åãŠãŒã¶ãŒãæã€ICã«ãŒããæã«ããããšããã®ICã«ãŒãã®IDãã·ã¹ãã ã«æž¡ãããã
ã·ã¹ãã ã¯IDãç»é²ãããŠããæãæœé ãããŠãããªãéé ããããã§ãªãã®ãªãæœé ããããããã¡ãã»ãŒãžãåºåãããã
IDãç»é²ãããŠããªãå Žåã¯ãç»é²ãããŠããªããšããã¡ãã»ãŒãžãåºåããéé åã³æœé ã¯ãããªãããªãã
</p>
<p>ããŠãçŸåšã·ã¹ãã ã«ã¯Nåã®ID(U<sub>1</sub>, U<sub>2</sub>, âŠâŠ, U<sub>N</sub>)ãç»é²ãããŠãããæœé ãããŠããã
MåICã«ãŒããæã«ããããããã®IDã¯ããããé çªã«T<sub>1</sub>, T<sub>2</sub>, âŠâŠ, T<sub>M</sub>ã§ãããšããã
ãã®æã®ã·ã¹ãã ãã©ã®ãããªã¡ãã»ãŒãžãåºåãããæ±ããã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p><blockquote>
N<br>U<sub>1</sub><br>U<sub>2</sub><br>âŠâŠ<br>U<sub>N</sub><br>M<br>T<sub>1</sub><br>T<sub>2</sub><br>âŠâŠ<br>T<sub>M</sub><br></blockquote>
<h2>Constraints</h2>
<ul><li><p>N, Mã¯æŽæ°ã§ãã
</p></li><li><p>1 ≤ N ≤ 256
</p></li><li><p>U<sub>i</sub>ã¯1æå以äž10æå以äžã®å°æåè±åã®ã¿ãããªãæååã§ãã
</p></li><li><p>U<sub>i</sub>ã¯ãŠããŒã¯ã§ãã(i ≠ jãªãã°U<sub>i</sub> ≠ U<sub>j</sub>)
</p></li><li><p>1 ≤ M ≤ 256
</p></li><li><p>T<sub>i</sub>ã¯1æå以äž10æå以äžã®å°æåè±åã®ã¿ãããªãæååã§ãã
</p></li></ul>
<h2>Output</h2>
<p>åT<sub>1</sub>, T<sub>2</sub>, âŠâŠ, T<sub>M</sub>ã«ã€ããŠã
</p><ul><li><p>éé ãããæã¯ã"Opened by "ã®åŸã«ç¶ããŠIDãã
</p></li><li><p>æœé ãããæã¯ã"Closed by "ã®åŸã«ç¶ããŠIDãã
</p></li><li><p>IDãç»é²ãããŠããªããã®ã ã£ãå Žåã¯"Unknown "ã®åŸã«ç¶ããŠIDã
ãããã1è¡ã«åºåããã
</p></li></ul>
<p>åæç¶æ
ã§ã¯æœé ãããç¶æ
ã§ããã
</p>
<h2>Sample Input 1</h2>
<pre>4
abcd
efgh
ijkl
mnop
5
abcd
abcc
efgh
abcd
mnop
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>Opened by abcd
Unknown abcc
Closed by efgh
Opened by abcd
Closed by mnop
</pre>
<h2>Sample Input 2</h2>
<pre>2
a
abcdefghij
9
c
bcdefghijk
abcdefghij
b
a
b
a
bcdefghijk
c
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>Unknown c
Unknown bcdefghijk
Opened by abcdefghij
Unknown b
Closed by a
Unknown b
Opened by a
Unknown bcdefghijk
Unknown c
</pre>
<h2>Sample Input 3</h2>
<pre>2
z
x
2
z
x
</pre>
<h2>Output for the Sample Input 3</h2>
<pre>Opened by z
Closed by x
</pre>
|
p00596 |
<H1><font color="#000000">Problem B:</font> Dominoes Arrangement</H1>
<pre>
[0, 0]
[0, 1] [1, 1]
[0, 2] [1, 2] [2, 2]
[0, 3] [1, 3] [2, 3] [3, 3]
[0, 4] [1, 4] [2, 4] [3, 4] [4, 4]
[0, 5] [1, 5] [2, 5] [3, 5] [4, 5] [5, 5]
[0, 6] [1, 6] [2, 6] [3, 6] [4, 6] [5, 6] [6, 6]
</pre>
<p>
Consider the standard set of 28 western dominoes as shown in the above figure. Given a subset of the standard set dominoes, decide whether this subset can be arranged in a straight row in accordance with the familiar playing rule that touching ends must match. For example, the subset [1, 1], [2, 2], [1, 2] can be arranged in a row (as [1, 1] followed by [1, 2] followed by [2, 2]), while the subset [1, 1], [0, 3], [1, 4] can not be arranged in one row. Note that as in usual dominoes playing any pair [i, j] can also be treated as [j, i].
</p>
<p>
Your task is to write a program that takes as input any subset of the dominoes and output either yes (if the input subset can be arranged in one row) or no (if the input set can not be arranged in one row).
</p>
<H2>Input</H2>
<p>
Input file consists of pairs of lines. The first line of each pair is the number of elements N (1 ≤ N ≤ 18) in the subset, and the second line is the elements of the subset separated by blanks, see the input sample below.
</p>
<p>
The number of pairs (datasets) is less than 30.
</p>
<H2>Output</H2>
<p>
For each pair of lines of the input file, the corresponding output is either Yes or No, based on whether the input subset can be arranged in one line or not.
</p>
<H2>Sample Input</H2>
<pre>
6
13 23 14 24 15 25
10
00 01 11 02 12 22 03 13 23 33
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Yes
No
</pre> |
p02051 | <h3>äžæè°ãªãã¿ã³</h3>
<!-- begin ja only -->
<p>ããªãã¯ïŒçºå€ãã«ãããã³ãžã§ã³ã§ã³ã€ã³ã皌ãããšã«ããïŒãã®ãã³ãžã§ã³ã«ã¯ <i>N</i> åã®éšå±ãååšãïŒ<i>1</i> ãã <i>N</i> ãŸã§ã®çªå·ãã€ããããŠããïŒãŸãïŒãã³ãžã§ã³å
ã«ã¯ãã³ã€ã³ãã¿ã³ããè±åºãã¿ã³ããã¯ãŒããã¿ã³ããšåŒã°ããäžæè°ãªãã¿ã³ãååšããïŒããããã®ãã¿ã³ã®è©³çŽ°ã¯æ¬¡ã®éãã§ããïŒ</p>
<ul>
<li>ã³ã€ã³ãã¿ã³ã¯åéšå±ã«ã¡ããã© <i>1</i> åååšããïŒã³ã€ã³ãã¿ã³ã¯äœåã§ãæŒãããšãã§ãïŒãã®ãã³ã«ã³ã€ã³ã <i>1</i> ææã«å
¥ãïŒ</li>
<li>è±åºãã¿ã³ã¯åéšå±ã«ã¡ããã© <i>1</i> åååšããïŒè±åºãã¿ã³ãæŒããšããªãã¯ãã ã¡ã«ãã³ãžã§ã³ããè±åºãïŒãã®åéºãçµäºããïŒ</li>
<li>ã¯ãŒããã¿ã³ã¯åèšã§ <i>M</i> åååšããïŒãã®ãã¡ <i>i</i> åç®ã®ã¯ãŒããã¿ã³ã¯éšå± <i>a<sub>i</sub></i> ã«ååšãïŒæŒãããšã§ããªãã¯éšå± <i>b<sub>i</sub></i> ã«ã¯ãŒããïŒããã«ã³ã€ã³ã <i>c<sub>i</sub></i> ææã«å
¥ãïŒãã ãïŒ<strong><i>a<sub>i</sub> < b<sub>i</sub></i></strong> ããã³ <strong><i>1 ≤ c<sub>i</sub> ≤ 3</i></strong> ãæºããïŒãªãïŒã¯ãŒããã¿ã³ã 1 ã€ã®éšå±ã«è€æ°ããå ŽåãïŒã¯ãŒããã¿ã³ã®ãŸã£ããç¡ãéšå±ãååšããå ŽåãããïŒ</li>
</ul>
<p>ãªãïŒãã¿ã³ãæŒã以å€ã®æ¹æ³ã§éšå±ãç§»åããããšã¯ã§ããïŒè€æ°ã®ãã¿ã³ãåæã«æŒãããšãã§ããªãïŒãŸãïŒãããã®ãã¿ã³ãäºãã«åºå¥å¯èœã§ããïŒ</p>
<p>ããªãã¯ãã®ãã³ãžã§ã³ã <i>Q</i> ååéºããïŒããªãã®èšæ¶ãæ£ãããã°ïŒ<i>j</i> åç®ã®åéºã¯éšå± <i>1</i> ããå§ãŸãïŒæåŸã«éšå± <i>d<sub>j</sub></i> ã«ããè±åºãã¿ã³ãæŒãïŒã³ã€ã³ã®åèšç²åŸææ°ã¯ã¡ããã© <i>e<sub>j</sub></i> æã ã£ãã¯ãã§ããïŒ<i>Q</i> åã®åéºããããã«ã€ããŠïŒãã®ãããªãã¿ã³ã®æŒãæ¹ãäœéãããããæ±ããïŒçãã¯å€§ãããªãå¯èœæ§ãããã®ã§ïŒ<i>10<sup>9</sup>+7</i> ããªãã¡ <i>1000000007</i> ã§å²ã£ãäœããæ±ããïŒ</p>
<p>ãã ãïŒ2 éãã®ããã¿ã³ã®æŒãæ¹ããç°ãªããšã¯ïŒãã¿ã³ãæŒããåèšåæ°ãç°ãªããïŒãŸãã¯ããæŽæ° <i>k</i> ãååšãïŒ<i>k</i> åç®ã«æŒãããã¿ã³ãç°ãªãããšãæãïŒ</p>
<p>ãªãïŒããããããããªãã®èšæ¶ã¯ééã£ãŠããïŒãã®ãããªãã¿ã³ã®æŒãæ¹ã¯ååšããªããããããªãïŒãã®å Žåã«ã¯ <i>0</i> ãåºåããïŒ</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒ åããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§è¡šãããïŒ</p>
<blockquote><i>N</i> <i>M</i>
<i>a<sub>1</sub></i> <i>b<sub>1</sub></i> <i>c<sub>1</sub></i>
<i>a<sub>2</sub></i> <i>b<sub>2</sub></i> <i>c<sub>2</sub></i>
...
<i>a<sub>M</sub></i> <i>b<sub>M</sub></i> <i>c<sub>M</sub></i>
<i>Q</i>
<i>d<sub>1</sub></i> <i>e<sub>1</sub></i>
<i>d<sub>2</sub></i> <i>e<sub>2</sub></i>
...
<i>d<sub>Q</sub></i> <i>e<sub>Q</sub></i></blockquote>
<p>ããŒã¿ã»ããã® 1 è¡ç®ã«ã¯ïŒéšå±ã®æ°ãè¡šãæŽæ° <i>N</i> ãšïŒã¯ãŒããã¿ã³ã®æ°ãè¡šãæŽæ° <i>M</i> ãäžãããïŒ<i>1 ≤ N, M ≤ 2 000</i> ãæºããïŒç¶ã <i>M</i> è¡ã«ã¯ã¯ãŒããã¿ã³ã®æ
å ±ãäžããããïŒ<i>M</i> è¡ã®ãã¡ <i>i</i> è¡ç®ã«ã¯ïŒ<i>i</i> çªç®ã®ã¯ãŒããã¿ã³ã®ååšããéšå±çªå· <i>a<sub>i</sub></i>ïŒã¯ãŒãå
ã®éšå±çªå· <i>b<sub>i</sub></i> ããã³æã«å
¥ãã³ã€ã³ã®ææ° <i>c<sub>i</sub></i> ãäžãããïŒ<i>1 ≤ a<sub>i</sub> < b<sub>i</sub> ≤ N</i> ããã³ <i>1 ≤ c<sub>i</sub> ≤ 3</i> ãæºããïŒ<i>M+2</i> è¡ç®ã«ã¯åéºã®åæ°ãè¡šãæŽæ° <i>Q</i> ãäžãããïŒ<i>1 ≤ Q ≤ 2 000</i> ãæºããïŒç¶ã <i>Q</i> è¡ã«ã¯ããªãã®èšæ¶ã«ããåéºã®æ
å ±ãäžããããïŒ<i>Q</i> è¡ã®ãã¡ <i>j</i> è¡ç®ã«ã¯ïŒ<i>j</i> çªç®ã®åéºã§ããªããè±åºãã¿ã³ãæŒããéšå±çªå· <i>d<sub>j</sub></i> ããã³ã³ã€ã³ã®ç²åŸææ° <i>e<sub>j</sub></i> ãäžãããïŒ<i>1 ≤ d<sub>j</sub> ≤ N</i> ããã³ <i>1 ≤ e<sub>j</sub> ≤ 10<sup>9</sup></i> ãæºããïŒ</p>
<p>å
¥åã®çµããã¯ïŒ2 åã®ãŒãã ããããªãè¡ã§è¡šãããïŒå
šããŒã¿ã»ããã®ç·æ°ã¯ 50 ãè¶
ããªãïŒ</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>åããŒã¿ã»ããã«ã€ããŠåºå㯠<i>Q</i> è¡ãããªãïŒãã®ãã¡ <i>j</i> è¡ç®ã«ã¯ïŒéšå± <i>1</i> ããå§ãŸãïŒæåŸã«éšå± <i>d<sub>j</sub></i> ã«ããè±åºãã¿ã³ãæŒãïŒã³ã€ã³ã®åèšç²åŸææ°ãã¡ããã© <i>e<sub>j</sub></i> æã§ãããããªãã¿ã³ã®æŒãæ¹ã®ç·æ°ãïŒ<i>10<sup>9</sup>+7</i> ã§å²ã£ãäœããåºåããïŒ</p>
<!-- end ja only -->
<h3>Sample Input</h3><pre>4 9
1 2 1
1 2 2
1 3 1
1 3 2
1 3 3
2 3 1
2 3 2
1 4 1
3 4 2
8
1 5
2 5
3 5
4 5
1 1234567
2 1234567
3 1234567
4 1234567
4 8
1 2 1
1 2 1
1 2 3
3 4 3
1 4 2
2 4 1
2 4 3
2 4 3
8
1 3
2 6
3 8
4 12
1 31415926
2 53589793
3 23846
4 26433832
0 0
</pre><h3>Output for the Sample Input</h3><pre>1
9
37
21
1
2469133
307629943
60012504
1
16
0
424
1
160769377
0
43581113
</pre>
|
p02401 | <H1>Simple Calculator</H1>
<p>
Write a program which reads two integers <var>a</var>, <var>b</var> and an operator <var>op</var>, and then prints the value of <var>a</var> <var>op</var> <var>b</var>.
</p>
<p>
The operator <var>op</var> is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset is given in the following format.
</p>
<pre>
<var>a</var> <var>op</var> <var>b</var>
</pre>
<p>
The input ends with a dataset where <var>op</var> = '?'. Your program should not process for this dataset.
</p>
<H2>Output</H2>
<p>
For each dataset, print the value in a line.
</p>
<h2>Constraints</h2>
<ul>
<li> 0 ≤ <var>a</var>, <var>b</var> ≤ 20000</sup></li>
<li>No divisions by zero are given.</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
1 + 2
56 - 18
13 * 2
100 / 10
27 + 81
0 ? 0
</pre>
<H2>Sample Output 1</H2>
<pre>
3
38
26
10
108
</pre>
|
p01387 |
<div>
<h1 class="title">åé¡ L : <span style="font-size:110%;font-family:times new roman;"><i>L</i></span> çªç®ã®æ°å</h1>
<p>åä¹±ãå
ãã€ããå€ãã® Gââgle ã®ã³ãŒããŒãæã
ãåãæŒããã«ãã£ãŠããïŒ
ããªãã®æ°ã ïŒ
ãã®äžã«ã¯ïŒæ±äº¬å€§åп代ã«åããåªããæå°ããŠãããå
茩ãã¡ãå€ãèŠåããããïŒ
æ®å¿µãªããïŒä»ã§ã¯æµå士ã ïŒ</p>
<dl class="docutils">
<dt>wata</dt>
<dd>ãäºæ³ä»¥äžã®æ°ã âŠã</dd>
<dt>(iwi)</dt>
<dd>ãããïŒæã
ãè¶
é«éææ°æéã¢ã«ãŽãªãºã ãæã£ãŠãããããšèšã£ãŠïŒããã¯åœŒãã«ãããã䞊ãã ã«éããªãïŒãã®æ°ã§ã¯âŠã</dd>
<dt>ïŒïŒ</dt>
<dd>ãå¿é
èŠããªãïŒåãã¡ïŒã¢ã«ãŽãªãºã ããã£ã¡ã«æž¡ããã ïŒã</dd>
</dl>
<p>声ãããçªã®å€ãèŠããšïŒGââgle ã®å»ºç©ã«åãããéå£ãããïŒ
é»ã®çå°ã«èµ€ã§ IïŒç·ã§ âïŒé»è²ã§ M ãšæžããã T ã·ã£ã ⊠圌ã㯠IâM ãïŒïŒ
ãããŠå¥åŠãªããšã«ïŒåœŒãã¯ïŒåãã£ãŠãã Gââgle ã®ã³ãŒããŒéãïŒ
ããŒããŒãã«è§ŠããããšãªãåããŠããïŒ
ã©ããªã£ãŠããïŒ</p>
<dl class="docutils">
<dt>(iwi)</dt>
<dd>ãâŠïŒ ã€ãã« Watsân 2 ã¯å®æããã®ãïŒã</dd>
<dt>wata</dt>
<dd>ãã©ãããããšã ïŒã</dd>
</dl>
<p>2011 幎ïŒIâM ã¯åœŒãã®é«ãæè¡åãæŽ»çšãïŒ
èªç¶èšèªã§åºé¡ãããã¯ã€ãºã«é«éãã€æ£ç¢ºã«å¿çããã·ã¹ãã ã§ãã Watsân ã宿ããïŒ
ã¯ã€ãºçªçµã«ãŠã¯ã€ãºçãšåŒã°ããŠãã人éãã¡ã«åå©ããïŒ
ãã㊠20XX 幎ã®ä»ïŒWatsân ã¯ïŒ
ããã°ã©ãã³ã°ã³ã³ãã¹ãã®åé¡ã«å¯Ÿãè§£çã®ããã°ã©ã ãäœæããã·ã¹ãã ãšããŠçãŸãå€ãã£ãã®ã ïŒ</p>
<p>IâM ã®ç»å Žã«ããïŒæã
ãåãå²ã人æ°ãæžã£ãŠããïŒ</p>
<dl class="docutils">
<dt>wata</dt>
<dd>ããã£ã³ã¹ã ïŒååã¯ä»»ãããããïŒã</dd>
<dt>(iwi)</dt>
<dd>ããã¡ããã ïŒã</dd>
</dl>
<p>åã¯ïŒåŠæ³ãšæ±ºå¥ããããšã«ããïŒå
šãŠãæãåºããŠããïŒ
åœç¶ïŒåœæã®ç¥èãçµéšã¯ïŒä»ããèŠãã°ã¬ãã«ãäœãããŠåœ¹ã«ç«ããªãïŒ
ãããïŒäžçªå€§åãªãã®ãæãåºãããšãã§ããïŒ
ããã¯ïŒããã°ã©ãã³ã°ã³ã³ãã¹ããæããæ°æã¡ã§ããïŒ
åé¡ãéãç¬éã®ã¯ã¯ã¯ã¯æïŒãµã³ãã«ãéã£ãç¬éã®çãäžããïŒ
ã¹ããŒã¿ã¹ãæŽæ°ãããç¬éã®ç·åŒµïŒåå©ã®ç¬éã®åã³ïŒ</p>
<dl class="docutils">
<dt>(iwi)</dt>
<dd>ãå¿
ã kita_masa ã®åŸ©è®ãæããïŒãã®çã£ãäžçãçµããããïŒã</dd>
</dl>
<p>ãããŠïŒåã¯èªä¿¡ã® 1 é¡ãç¹°ãåºãïŒ
ããã¯ïŒæ±äº¬å€§åп代ã®èªåãæããåé¡ã<span style="font-size:110%;font-family:times new roman;"><i>K</i></span> çªç®ã®æ°åããç¬èªã®ãã¯ããã¯ã«ããäžè¬åãã€å€§èŠæš¡åããåé¡ã§ããïŒ</p>
<div>
<h1>åé¡</h1>
<p>ã°ã©ããäžããããïŒ</p>
<ul class="simple">
<li><span style="font-size:110%;font-family:times new roman;"><i>N</i></span> åã®é ç¹ãããïŒé ç¹ã« <span style="font-size:110%;font-family:times new roman;">1</span> ãã <span style="font-size:110%;font-family:times new roman;"><i>N</i></span> ã®çªå·ãä»ããŠããïŒ</li>
<li>ãããã®é ç¹ã¯ïŒ<span style="font-size:110%;font-family:times new roman;"><i>N</i> - 1</span> æ¬ã®èŸºã«ããããªãŒç¶ã«æ¥ç¶ãããŠããïŒ</li>
<li>åé ç¹ <span style="font-size:110%;font-family:times new roman;"><i>v</i></span> ã«ã¯æ°å <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>v</i></sub></span> ãå®ãŸã£ãŠããïŒ</li>
</ul>
<p>äžå³ã¯ïŒäžããããã°ã©ãã®äŸã§ããïŒ
åé ç¹ã«ã¯äžéšã«é ç¹ã®çªå·ãïŒäžéšã«ãã®é ç¹ã«å®ããããæ°å (<span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>v</i></sub></span>) ãæžãããŠããïŒ</p>
<div>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_2270" alt="äžããããã°ã©ãã®äŸ" />
<p class="caption">äžããããã°ã©ãã®äŸ</p>
</div>
<p>次ã«ïŒ<span style="font-size:110%;font-family:times new roman;"><i>Q</i></span> åã®ä»¥äžã®ãããªã¯ãšãªãäžããããïŒ</p>
<ul class="simple">
<li>åã¯ãšãª <span style="font-size:110%;font-family:times new roman;"><i>q</i></span> ã«ã¯ïŒé ç¹ <span style="font-size:110%;font-family:times new roman;"><i>v</i><sub><i>q</i></sub>, <i>w</i><sub><i>q</i></sub></span> ãšæŽæ° <span style="font-size:110%;font-family:times new roman;"><i>l</i><sub><i>q</i></sub></span> ãæå®ãããïŒ</li>
<li>é ç¹ <span style="font-size:110%;font-family:times new roman;"><i>v</i><sub><i>q</i></sub></span> ããé ç¹ <span style="font-size:110%;font-family:times new roman;"><i>w</i><sub><i>q</i></sub></span> ãžã®çµè·¯ã«å«ãŸããé ç¹ã®æ°åã®ãã¡ <span style="font-size:110%;font-family:times new roman;"><i>l</i><sub><i>q</i></sub></span> çªç®ã«å°ãããã®ãæ±ããïŒ<ul>
<li>çµè·¯ã¯åçŽãªãã®ã®ã¿ãèããïŒåçŽãªçµè·¯ãšã¯ïŒåãé ç¹ãäºåºŠéããªãçµè·¯ã®ããšã§ããïŒã°ã©ããããªãŒç¶ã§ããããšããïŒåçŽãªçµè·¯ã¯äžæã§ããïŒ</li>
<li>çµè·¯ã«ã¯äž¡ç«¯ç¹ïŒããªãã¡é ç¹ <span style="font-size:110%;font-family:times new roman;"><i>v</i><sub><i>q</i></sub>, <i>w</i><sub><i>q</i></sub></span>ïŒãå«ããã®ãšããïŒ</li>
</ul>
</li>
</ul>
<p>äŸãã°ïŒäžå³ã®ã°ã©ããäžããããŠããæïŒ
<span style="font-size:110%;font-family:times new roman;">(<i>v</i><sub><i>q</i></sub>, <i>w</i><sub><i>q</i></sub>, <i>l</i><sub><i>q</i></sub>) = (1, 6, 3)</span> ãªãã¯ãšãª <span style="font-size:110%;font-family:times new roman;"><i>q</i></span> ã«å¯Ÿããçã㯠7 ã§ããïŒ
ããã¯ïŒé ç¹ 1 ããé ç¹ 6 ãžã®çµè·¯ã«ã¯é ç¹ 1, 3, 4, 6 ãå«ãŸããŠããïŒ
ãããã«å®ãŸã£ãæ°å 2, 5, 8, 7 ã® 3 çªç®ãã«å°ããªæ°å㯠7 ã§ããããšã«ããïŒ</p>
<p>ã°ã©ããšã¯ãšãªãåãåãïŒçµæãåºåããããã°ã©ã ãäœæããïŒ</p>
</div>
<div>
<h1>å
¥å</h1>
<p>å
¥åã®æåã®è¡ã¯ 2 ã€ã®æŽæ° <span style="font-size:110%;font-family:times new roman;"><i>N</i>, <i>Q</i></span> ãå«ãïŒ
ããã¯ïŒé ç¹æ°ãšã¯ãšãªã®æ°ã衚ãïŒ</p>
<p>ç¶ã <span style="font-size:110%;font-family:times new roman;"><i>N</i></span> è¡ã¯ïŒåé ç¹ã®æã€æ°åã衚ãïŒ
ãããã®è¡ã®ãã¡ã® <span style="font-size:110%;font-family:times new roman;"><i>v</i></span> è¡ç®ã¯ 1 ã€ã®æŽæ° <span style="font-size:110%;font-family:times new roman;"><i>x</i><sub><i>v</i></sub></span> ãæžãããŠããïŒ
ããã¯é ç¹ <span style="font-size:110%;font-family:times new roman;"><i>v</i></span> ã®æã€æ°åã衚ãïŒ</p>
<p>ç¶ã <span style="font-size:110%;font-family:times new roman;"><i>N</i> - 1</span> è¡ã¯ïŒèŸºã®æ
å ±ã衚ãïŒ
ãããã®è¡ã®ãã¡ã® <span style="font-size:110%;font-family:times new roman;"><i>e</i></span> è¡ç®ã¯ 2 ã€ã®æŽæ° <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>e</i></sub>, <i>b</i><sub><i>e</i></sub></span> ãæžãããŠããïŒ
ãããã¯èŸº <span style="font-size:110%;font-family:times new roman;"><i>e</i></span> ãçµã¶ 2 ã€ã®é ç¹ã衚ãïŒ</p>
<p>ç¶ã <span style="font-size:110%;font-family:times new roman;"><i>Q</i></span> è¡ã¯ïŒã¯ãšãªã®æ
å ±ã衚ãïŒ
ãããã®è¡ã®ãã¡ã® <span style="font-size:110%;font-family:times new roman;"><i>q</i></span> è¡ç®ã¯ 3 ã€ã®æŽæ°
<span style="font-size:110%;font-family:times new roman;"><i>v</i><sub><i>q</i></sub>, <i>w</i><sub><i>q</i></sub>, <i>l</i><sub><i>q</i></sub></span> ãæžãããŠããïŒ
ãããã¯ã¯ãšãª <span style="font-size:110%;font-family:times new roman;"><i>q</i></span> ã®æ
å ±ã衚ãïŒ</p>
</div>
<div>
<h1>åºå</h1>
<p>åºå㯠<span style="font-size:110%;font-family:times new roman;"><i>Q</i></span> è¡ãããªãïŒ<span style="font-size:110%;font-family:times new roman;"><i>q</i></span> è¡ç®ã«ã¯ãšãª <span style="font-size:110%;font-family:times new roman;"><i>q</i></span> ã®çããåºåããïŒ</p>
</div>
<div>
<h1>å
¥åã«é¢ããå¶çŽ</h1>
<ul class="simple">
<li><span style="font-size:110%;font-family:times new roman;">1 ≤ <i>N</i>, <i>Q</i> ≤ 10<sup>5</sup></span></li>
<li><span style="font-size:110%;font-family:times new roman;">1 ≤ <i>x</i><sub><i>v</i></sub> ≤ 10<sup>9</sup></span></li>
<li><span style="font-size:110%;font-family:times new roman;">1 ≤ <i>a</i><sub><i>e</i></sub>, <i>b</i><sub><i>e</i></sub> ≤ <i>N</i></span></li>
<li><span style="font-size:110%;font-family:times new roman;">1 ≤ <i>v</i><sub><i>q</i></sub>, <i>w</i><sub><i>q</i></sub> ≤ <i>N</i></span></li>
<li>é ç¹ <span style="font-size:110%;font-family:times new roman;"><i>v</i><sub><i>q</i></sub></span> ããé ç¹ <span style="font-size:110%;font-family:times new roman;"><i>w</i><sub><i>q</i></sub></span> ãžã®çµè·¯ã«ã¯ <span style="font-size:110%;font-family:times new roman;"><i>l</i><sub><i>q</i></sub></span> å以äžã®é ç¹ãååšããïŒ</li>
</ul>
</div>
<div>
<h1>å
¥åºåäŸ</h1>
<p>å
¥åäŸ:</p>
<pre class="literal-block">
6 11
2
4
5
8
9
7
1 3
2 3
3 4
4 5
4 6
1 6 1
1 6 2
1 6 3
1 6 4
1 2 1
1 2 2
1 2 3
2 5 1
2 5 2
2 5 3
2 5 4
</pre>
<p>å
¥åäŸã«å¯Ÿããåºå:</p>
<pre class="literal-block">
2
5
7
8
2
4
5
4
5
8
9
</pre>
</div>
</div>
|
p02952 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is an integer <var>N</var>. Find the number of positive integers less than or equal to <var>N</var> that have an odd number of digits (in base ten without leading zeros).</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of positive integers less than or equal to <var>N</var> that have an odd number of digits.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>11
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>9
</pre>
<p>Among the positive integers less than or equal to <var>11</var>, nine integers have an odd number of digits: <var>1, 2, \ldots, 9</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>136
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>46
</pre>
<p>In addition to <var>1, 2, \ldots, 9</var>, another <var>37</var> integers also have an odd number of digits: <var>100, 101, \ldots, 136</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>90909
</pre></section>
</div>
</span> |
p03640 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a grid with <var>H</var> rows and <var>W</var> columns of squares.
Snuke is painting these squares in colors <var>1</var>, <var>2</var>, <var>...</var>, <var>N</var>.
Here, the following conditions should be satisfied:</p>
<ul>
<li>For each <var>i</var> (<var>1 †i †N</var>), there are exactly <var>a_i</var> squares painted in Color <var>i</var>. Here, <var>a_1 + a_2 + ... + a_N = H W</var>.</li>
<li>For each <var>i</var> (<var>1 †i †N</var>), the squares painted in Color <var>i</var> are <em>4-connected</em>. That is, every square painted in Color <var>i</var> can be reached from every square painted in Color <var>i</var> by repeatedly traveling to a horizontally or vertically adjacent square painted in Color <var>i</var>.</li>
</ul>
<p>Find a way to paint the squares so that the conditions are satisfied.
It can be shown that a solution always exists.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †H, W †100</var></li>
<li><var>1 †N †H W</var></li>
<li><var>a_i ⥠1</var></li>
<li><var>a_1 + a_2 + ... + a_N = H W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var>
<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 one way to paint the squares that satisfies the conditions.
Output in the following format:</p>
<pre><var>c_{1 1}</var> <var>...</var> <var>c_{1 W}</var>
<var>:</var>
<var>c_{H 1}</var> <var>...</var> <var>c_{H W}</var>
</pre>
<p>Here, <var>c_{i j}</var> is the color of the square at the <var>i</var>-th row from the top and <var>j</var>-th column from the left.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
3
2 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1 1
2 3
</pre>
<p>Below is an example of an invalid solution:</p>
<pre>1 2
3 1
</pre>
<p>This is because the squares painted in Color <var>1</var> are not 4-connected.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 5
5
1 2 3 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1 4 4 4 3
2 5 4 5 3
2 5 5 5 3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 1
1
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre></section>
</div>
</span> |
p03210 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><em>Shichi-Go-San</em> (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.</p>
<p>Takahashi is now <var>X</var> years old. Will his growth be celebrated in Shichi-Go-San this time?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †X †9</var></li>
<li><var>X</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If Takahashi's growth will be celebrated, print <code>YES</code>; if it will not, print <code>NO</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p>The growth of a five-year-old child will be celebrated.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre>
<p>See you next year.</p></section>
</div>
</span> |
p02817 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are two strings <var>S</var> and <var>T</var> consisting of lowercase English letters. Concatenate <var>T</var> and <var>S</var> in this order, without space in between, and print the resulting string.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>S</var> and <var>T</var> are strings consisting of lowercase English letters.</li>
<li>The lengths of <var>S</var> and <var>T</var> are between <var>1</var> and <var>100</var> (inclusive).</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var> <var>T</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the resulting string.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>oder atc
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>atcoder
</pre>
<p>When <var>S = </var> <code>oder</code> and <var>T = </var> <code>atc</code>, concatenating <var>T</var> and <var>S</var> in this order results in <code>atcoder</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>humu humu
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>humuhumu
</pre></section>
</div>
</span> |
p01738 |
<p>
You are practicing a juggle that involves in a number of square tiles.
They all look the same in their size, but actually there are three different kinds of the tiles, A, B and X.
The kind of a tile can be distinguishable by its mass.
All the tiles of the same kind have exactly the same mass.
The mass of type A tiles is within the range <var>[mA1, mA2]</var>.
The mass of type B tiles is similarly within the range <var>[mB1, mB2]</var>.
You donât know the exact numbers for type A and B. The mass of type X tiles is exactly <var>mX</var>.
</p>
<p>
You have just got one big object consists of the tiles.
The tiles are arranged in an <var>H \times W</var> grid.
All the adjacent tiles are glued together on the edges.
Some cells in the <var>H \times W</var> grid can be empty.
</p>
<p>
You wanted to balance the object on a pole.
You started to wonder the center of gravity of the object, then.
You cannot put the object on a pole if the center of gravity is on an empty cell.
The center of gravity of each single square tile is at the center of the square.
The center of gravity of an object which combines two objects with masses <var>m_{1}</var> and <var>m_{2}</var> is the point dividing the line segment between those centers in the ratio <var>m_{2} : m_{1}</var> internally.
</p>
<p>
Your task is to write a program that computes the probability that the center of gravity of the big object is actually on the object, not on a hole in the object.
Although the exact mass is unknown for tile A and B, the probability follows the continuous uniform distribution within the range mentioned above.
You can assume the distribution is independent between A and B.
</p>
<h3>Input</h3>
<p>The input is formatted as follows.
</p>
<pre>
<var>H</var> <var>W</var>
<var>mA1</var> <var>mA2</var> <var>mB1</var> <var>mB2</var> <var>mX</var>
<var>M_{1,1}M_{1,2}...M_{1,W}</var>
<var>M_{2,1}M_{2,2}...M_{2,W}</var>
:
:
<var>M_{H,1}M_{H,2}...M_{H,W}</var></pre>
<p>The first line of the input contains two integers <var>H</var> and <var>W</var> (<var>1 \leq H, W \leq 50</var>) separated by a space, where <var>H</var> and <var>W</var> are the numbers of rows and columns of given matrix.
</p>
<p>The second line of the input contains five integers <var>mA1</var>, <var>mA2</var>, <var>mB1</var>, <var>mB2</var> and <var>mX</var> (<var>1 \leq mA1 \lt mA2 \leq 100</var>, <var>1 \leq mB1 \lt mB2 \leq 100</var> and <var>1 \leq mX \leq 100</var>) separated by a space.
</p>
<p>The following <var>H</var> lines, each consisting of <var>W</var> characters, denote given matrix.
In those <var>H</var> lines, <code>A</code>, <code>B</code> and <code>X</code> denote a piece of type A, type B and type X respectively, and <code>.</code> denotes empty cell to place no piece.
There are no other characters in those H lines.
</p>
<p>Of the cell at <var>i</var>-th row in <var>j</var>-th column, the coordinate of the left top corner is <var>(i, j)</var>, and the coordinate of the right bottom corner is <var>(i+1, j+1)</var>.
</p>
<p>You may assume that given matrix has at least one <code>A</code>, <code>B</code> and <code>X</code> each and all pieces are connected on at least one edge.
Also, you may assume that the probability that the x-coordinate of the center of gravity of the object is an integer is equal to zero and the probability that the y-coordinate of the center of gravity of the object is an integer is equal to zero.
</p>
<h3>Output</h3>
<p>Print the probability that the center of gravity of the object is on the object.
The output should not contain an error greater than <var>10^{-8}</var>.
</p>
<h3>Sample Input 1</h3>
<pre>3 3
2 4 1 2 1
XAX
B.B
XAX
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>0.0000000000000
</pre>
<h3>Sample Input 2</h3>
<pre>4 2
1 100 1 100 50
AX
XB
BA
XB
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>1.0
</pre>
<h3>Sample Input 3</h3>
<pre>2 3
1 2 3 4 2
X.B
AXX
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>0.500
</pre>
<h3>Sample Input 4</h3>
<pre>10 10
1 100 1 100 1
AXXXXXXXXX
X........X
X........X
X..XXXXXXX
X........X
XXXXXX...X
X........X
X......X.X
X......X.X
XXXXXXXXXB
</pre>
<h3>Output for the Sample Input 4</h3>
<pre>0.4930639462354
</pre>
<h3>Sample Input 5</h3>
<pre>25 38
42 99 40 89 3
...........X...............X..........
...........XXX..........XXXX..........
...........XXXXX.......XXXX...........
............XXXXXXXXXXXXXXX...........
............XXXXXXXXXXXXXXX...........
............XXXXXXXXXXXXXX............
.............XXXXXXXXXXXXX............
............XXXXXXXXXXXXXXX...........
...........XXXXXXXXXXXXXXXXX..........
.......X...XXXXXXXXXXXXXXXXX...X......
.......XX.XXXXXXXXXXXXXXXXXX..XX......
........XXXXXXXXXXXXXXXXXXXX.XX.......
..........XXXXXXXXXXXXXXXXXXXX........
.........XXXXX..XXXXXXXX..XXXXX.......
.......XXXXXX....XXXXX....XXXXXX......
......XXXXXXXX...XXXXX..XXXXXXXX.X....
....XXXXXXX..X...XXXXX..X..XXXXXXXX...
..BBBXXXXXX.....XXXXXXX......XXXAAAA..
...BBBXXXX......XXXXXXX........AAA....
..BBBB.........XXXXXXXXX........AAA...
...............XXXXXXXXX..............
..............XXXXXXXXXX..............
..............XXXXXXXXXX..............
...............XXXXXXXX...............
...............XXXXXXXX...............
</pre>
<h3>Output for the Sample Input 5</h3>
<pre>0.9418222212582
</pre> |
p03705 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has <var>N</var> integers. Among them, the smallest is <var>A</var>, and the largest is <var>B</var>.
We are interested in the sum of those <var>N</var> integers. How many different possible sums there are?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N,A,B †10^9</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>N</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the different possible sums.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 4 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>There are five possible sums: <var>18=4+4+4+6</var>, <var>19=4+4+5+6</var>, <var>20=4+5+5+6</var>, <var>21=4+5+6+6</var> and <var>22=4+6+6+6</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 7 10
</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 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>1
</pre></section>
</div>
</span> |
p01368 |
<H1><font color="#000">Problem J:</font> Merry Christmas</H1>
<p>
International Christmas Present Company (ICPC) is a company to employ Santa and deliver
presents on Christmas. Many parents request ICPC to deliver presents to their children at
specified time of December 24. Although same Santa can deliver two or more presents, because
it takes time to move between houses, two or more Santa might be needed to finish all the
requests on time.
</p>
<p>
Employing Santa needs much money, so the president of ICPC employed you, a great program-
mer, to optimize delivery schedule. Your task is to write a program to calculate the minimum
number of Santa necessary to finish the given requests on time. Because each Santa has been
well trained and can conceal himself in the town, you can put the initial position of each Santa
anywhere.
</p>
<H2>Input</H2>
<p>
The input consists of several datasets. Each dataset is formatted as follows.
</p>
<p>
<i>N M L</i><br>
<i>u</i><sub>1</sub> <i>v</i><sub>1</sub> <i>d</i><sub>1</sub><br>
<i>u</i><sub>2</sub> <i>v</i><sub>2</sub> <i>d</i><sub>2</sub><br>
.<br>
.<br>
.<br>
<i>u</i><sub><i>M</i></sub> <i>v</i><sub><i>M</i></sub> <i>d</i><sub><i>M</i></sub><br>
<i>p</i><sub>1</sub> <i>t</i><sub>1</sub><br>
<i>p</i><sub>2</sub> <i>t</i><sub>2</sub><br>
.<br>
.<br>
.<br>
<i>p</i><sub><i>L</i></sub> <i>t</i><sub><i>L</i></sub><br>
</p>
<p>
The first line of a dataset contains three integer, <i>N</i> , <i>M</i> and <i>L</i> (1 ≤ <i>N</i> ≤ 100, 0 ≤ <i>M</i> ≤ 1000,
1 ≤ <i>L</i> ≤ 1000) each indicates the number of houses, roads and requests respectively.
</p>
<p>
The following <i>M</i> lines describe the road network. The <i>i</i>-th line contains three integers, <i>u<sub>i</sub></i> , <i>v<sub>i</sub></i> ,
and <i>d<sub>i</sub></i> (0 ≤ <i>u<sub>i</sub></i> < <i>v<sub>i</sub></i> ≤ <i>N</i> - 1, 1 ≤ <i>d<sub>i</sub></i> ≤ 100) which means that there is a road connecting houses
<i>u<sub>i</sub></i> and <i>v<sub>i</sub></i> with <i>d<sub>i</sub></i> length. Each road is bidirectional. There is at most one road between same
pair of houses. Whole network might be disconnected.
</p>
<p>
The next <i>L</i> lines describe the requests. The <i>i</i>-th line contains two integers, <i>p<sub>i</sub></i> and <i>t<sub>i</sub></i> (0 ≤ <i>p<sub>i</sub></i> ≤
<i>N</i> - 1, 0 ≤ <i>t<sub>i</sub></i> ≤ 10<sup>8</sup> ) which means that there is a delivery request to house <i>p<sub>i</sub></i> on time <i>t<sub>i</sub></i> . There
is at most one request for same place and time. You can assume that time taken other than
movement can be neglectable, and every Santa has the same speed, one unit distance per unit
time.
</p>
<p>
The end of the input is indicated by a line containing three zeros separated by a space, and you
should not process this as a test case.
</p>
<H2>Output</H2>
<p>
Print the minimum number of Santa necessary to finish all the requests on time.
</p>
<H2>Sample Input</H2>
<pre>
3 2 3
0 1 10
1 2 10
0 0
1 10
2 0
3 2 4
0 1 10
1 2 10
0 0
1 10
2 20
0 40
10 10 10
0 1 39
2 3 48
3 5 20
4 8 43
3 9 10
8 9 40
3 4 5
5 7 20
1 7 93
1 3 20
0 0
1 100000000
2 100
3 543
4 500
5 400
6 300
7 200
8 100
9 100
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
1
4
</pre>
|
p03355 | <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>.
Among the <strong>different</strong> substrings of <var>s</var>, print the <var>K</var>-th lexicographically smallest one.</p>
<p>A substring of <var>s</var> is a string obtained by taking out a non-empty contiguous part in <var>s</var>.
For example, if <var>s</var> <var>=</var> <code>ababc</code>, <code>a</code>, <code>bab</code> and <code>ababc</code> are substrings of <var>s</var>, while <code>ac</code>, <code>z</code> and an empty string are not.
Also, we say that substrings are different when they are different as strings.</p>
<p>Let <var>X = x_{1}x_{2}...x_{n}</var> and <var>Y = y_{1}y_{2}...y_{m}</var> be two distinct strings. <var>X</var> is lexicographically larger than <var>Y</var> if and only if <var>Y</var> is a prefix of <var>X</var> or <var>x_{j} > y_{j}</var> where <var>j</var> is the smallest integer such that <var>x_{j} \neq y_{j}</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1</var> <var>â€</var> <var>|s|</var> <var>â€</var> <var>5000</var></li>
<li><var>s</var> consists of lowercase English letters.</li>
<li><var>1</var> <var>â€</var> <var>K</var> <var>â€</var> <var>5</var></li>
<li><var>s</var> has at least <var>K</var> different substrings.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li><var>200</var> points will be awarded as a partial score for passing the test set satisfying <var>|s|</var> <var>â€</var> <var>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>s</var>
<var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the <var>K</var>-th lexicographically smallest substring of <var>K</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>aba
4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>b
</pre>
<p><var>s</var> has five substrings: <code>a</code>, <code>b</code>, <code>ab</code>, <code>ba</code> and <code>aba</code>.
Among them, we should print the fourth smallest one, <code>b</code>.
Note that we do not count <code>a</code> twice.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>atcoderandatcodeer
5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>andat
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>z
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>z
</pre></section>
</div>
</span> |
p00980 | <h2>Estimating the Flood Risk</h2>
<p>
Mr. Boat is the owner of a vast extent of land. As many typhoons have struck Japan this year, he became concerned of flood risk of his estate and he wants to know the average altitude of his land. The land is too vast to measure the altitude at many spots. As no steep slopes are in the estate, he thought that it would be enough to measure the altitudes at only a limited number of sites and then approximate the altitudes of the rest based on them.
</p>
<p>
Multiple approximations might be possible based on the same measurement results, in which case he wants to know the worst case, that is, one giving the lowest average altitude.
</p>
<p>
Mr. Boatâs estate, which has a rectangular shape, is divided into grid-aligned rectangular areas of the same size. Altitude measurements have been carried out in some of these areas, and the measurement results are now at hand. The altitudes of the remaining areas are to be approximated on the assumption that altitudes of two adjoining areas sharing an edge differ at most 1.
</p>
<p>
In the first sample given below, the land is divided into 5 × 4 areas. The altitudes of the areas at (1, 1) and (5, 4) are measured 10 and 3, respectively. In this case, the altitudes of all the areas are uniquely determined on the assumption that altitudes of adjoining areas differ at most 1.
</p>
<p>
In the second sample, there are multiple possibilities, among which one that gives the lowest average altitude should be considered.
</p>
<p>
In the third sample, no altitude assignments satisfy the assumption on altitude differences.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCAsia2019_estimating_the_flood_risk" width="640"/>
</center>
<p>
Your job is to write a program that approximates the average altitude of his estate. To be precise, the program should compute the total of approximated and measured altitudes of all the mesh-divided areas. If two or more different approximations are possible, the program should compute the total with the severest approximation, that is, one giving the lowest total of the altitudes.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case of the following format.
</p>
<pre>
$w$ $d$ $n$
$x_1$ $y_1$ $z_1$
.
.
.
$x_n$ $y_n$ $z_n$
</pre>
<p>
Here, $w$, $d$, and $n$ are integers between $1$ and $50$, inclusive. $w$ and $d$ are the numbers of areas in the two sides of the land. $n$ is the number of areas where altitudes are measured. The $i$-th line of the following $n$ lines contains three integers, $x_i$, $y_i$, and $z_i$ satisfying $1 \leq x_i \leq w$, $1 \leq y_i \leq d$, and $â100 \leq z_i \leq 100$. They mean that the altitude of the area at $(x_i
, y_i)$ was measured to be $z_i$. At most one measurement result is given for the same area, i.e., for $i \ne j$, $(x_i, y_i) \ne (x_j , y_j)$.
</p>
<h3>Output</h3>
<p>
If all the unmeasured areas can be assigned their altitudes without any conflicts with the measured altitudes assuming that two adjoining areas have the altitude difference of at most 1, output an integer that is the <i>total</i> of the measured or approximated altitudes of all the areas. If more than one such altitude assignment is possible, output the minimum altitude total among the possible assignments.
</p>
<p>
If no altitude assignments satisfy the altitude difference assumption, output <span>No</span>.
</p>
<h3>Sample Input 1 </h3>
<pre>
5 4 2
1 1 10
5 4 3
</pre>
<h3>Sample Output 1</h3>
<pre>
130
</pre>
<h3>Sample Input 2 </h3>
<pre>
5 4 3
2 2 0
4 3 0
5 1 2
</pre>
<h3>Sample Output 2</h3>
<pre>
-14
</pre>
<h3>Sample Input 3 </h3>
<pre>
3 3 2
1 1 8
3 3 3
</pre>
<h3>Sample Output 3</h3>
<pre>
No
</pre>
<h3>Sample Input 4 </h3>
<pre>
2 2 1
1 1 -100
</pre>
<h3>Sample Output 4</h3>
<pre>
-404
</pre>
|
p01692 |
<h2>F - Dangerous Delivery / å±éºãªèŒžé</h2>
<h3>Story</h3>
<p>Dã®ã²ãšã¯é倧ãªäœ¿åœãèè² ã£ãŠãããããã¯DAtaCoDer瀟é·ã®Dhokudaiæ°ãžã次ã®DAtaCoDer Regular Contest(DARC)ã®Dåé¡ãå±ããããšã ãDã®ã²ãšã®ã¢ãžããããéœåž<var>1</var>ããDAtaCoDeræ¬ç€Ÿãããéœåž<var>N</var>ãŸã§ã¯<var>N</var>åã®éœåžãäžçŽç·ã«äžŠãã§ããããã®ç§»åã®éãäžæ£ãäŒãç·ã®äžè§åœ¢ã®éå£ãDåé¡ãçã£ãŠããããã®éã®æããDåé¡ãå®ããã°ãªããªãã</p>
<p>幞ããDã®ã²ãšã¯æ¬¡å
(ãã£ã¡ã³ãžã§ã³)ã®å£ãè¶
ããŠç§»åããèœåãæã£ãŠãããããç°¡åã«æãŸããããªããšã¯ãªããããããã®ç§»åæ³ã«ã¯ããã€ãã®æ¬ ç¹ãããã第äžã«ãç§»åãéå§ããéã«ã¯éãã§ããŠããŸãããŸããã®ç¬éãèŠã€ãããšãç§»åå
ãŸã§ãã¬ãŠããŸããç·ã®äžè§åœ¢éã¯ãããããè€æ°ã®éœåžãèŠæž¡ããããã«ç£èŠãç¶ããŠããããããDã®ã²ãšã®ç§»åãèªã¿ãå°ããã€éœåž<var>N</var>ã®æ¹åãžç§»åããŠããããã ããã£ãŠãå€ãã®ç·ã®äžè§åœ¢éã«ç£èŠãããŠããéœåžããã®ç§»åããé·ãè·é¢ã®ç§»åã¯çºèŠã®ãªã¹ã¯ãé«ãŸã£ãŠããŸãããŸã第äºã®æ¬ ç¹ãšããŠã次å
ã®å£ãè¶
ããç§»åã¯äœãžã®è² æ
ããããããã<var>1</var>æ¥ã«<var>1</var>床ãã䜿ããªããæ¬¡ã®DARCãéå¬ããã<var>D</var>æ¥åŸãŸã§ã«éã«åããããããããŒã¹é
åãèããå¿
èŠããããç·ã®äžè§åœ¢ããšãã«Dã®ã²ãšãææãããããšãªã©ãŸãããããªãããæ
éæŽŸã§ããDã®ã²ãšã¯ã<var>D</var>æ¥åŸãŸã§ã«éœåž<var>1</var>ããéœåž<var>N</var>ã«ç§»åããããã®ãªã¹ã¯ãæå°åããããšèããã</p>
<h3>Problem</h3>
<p>äºæ¬¡å
å¹³é¢äžã«<var>N</var>åã®éœåžããããéœåž<var>1</var>ãã<var>N</var>ã¯å·Šããå³ãžäžçŽç·äžã«äžŠãã§ãããéœåž<var>i</var>ã¯äœçœ®<var>(p_i,0)</var>ã«ããã<var>p_i<p_{i+1}</var> (<var>1 \leq i < N</var>)ãæºããã</p>
<p>ãŸãããã®äºæ¬¡å
å¹³é¢äžã«ã¯<var>M</var>äººã®æµããããæµ<var>j</var>ã¯åœåãäœçœ®<var>(a_j,b_j)</var>ã«ãããæµ<var>j</var>ã¯å·Šæ¹åã«ã€ããŠãäžäž<var>45</var>°ã®ç¯å²ãèŠåŒµã£ãŠãããããªãã¡ãçŽç· <var>y=x-a_j+b_j</var> 以äžã§ããã€ãçŽç·<var>y=-x+a_j+b_j</var> 以äžã®é åã«å«ãŸããå
šãŠã®éœåžãèŠçã«å
¥ã£ãŠããããŸãããã¹ãŠã®æµã¯<var>1</var>æ¥ããšã«ã¡ããã©<var>X</var>ã ã峿¹åã«ç§»åãããããªãã¡ã<var>d</var>æ¥ç®ã®æµ<var>j</var>ã®äœçœ®ã¯<var>(a_j+X(d-1),b_j)</var>ã§ããã</p>
<p>ããã§ã<var>d</var>æ¥ç®ã«ãããéœåž<var>i</var>ã®ç£èŠåºŠ<var>w_{d,i}</var>ã¯ã<var>d</var>æ¥ç®ã«ãããŠéœåž<var>i</var>ãèŠçã«å
¥ããŠããæµã®ç·æ°ã«ããå®çŸ©ãããããã®ãšãã<var>d</var>æ¥ç®ã®éœåž<var>i</var>ããéœåž<var>k</var>ãžã®ç§»åã¯ã<var>w_{d,i} \times |p_i-p_k|</var>ã®ãªã¹ã¯ãè² ãã<var>1</var>æ¥ã«<var>1</var>床ããç§»åã§ããªããšãããšãã<var>D</var>æ¥åŸãŸã§ã«éœåž<var>1</var>ããéœåž<var>N</var>ãŸã§ç§»åããéã®ãªã¹ã¯ã®ç·åãæå°åããã</p>
<h3>Input</h3>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒãããªãã</p>
<pre><var>N</var> <var>M</var> <var>D</var> <var>X</var>
<var>p_1</var> <var>p_2</var> <var>...</var> <var>p_N</var>
<var>a_1</var> <var>b_1</var>
<var>...</var>
<var>a_M</var> <var>b_M</var></pre>
<p><var>1</var>è¡ç®ã¯<var>4</var>ã€ã®æŽæ°ãããªããéœåžã®æ°<var>N</var>ãæµã®æ°<var>M</var>ãç§»åã«ãããŠããæ¥æ°ã®äžé<var>D</var>ã<var>1</var>æ¥ããšã®æµã®ç§»åè·é¢<var>X</var>ããããã空çœ<var>1</var>æååºåãã§äžããããã <var>2</var>è¡ç®ã¯<var>N</var>åã®æŽæ°ãããªãã<var>i</var>çªç®ã®æŽæ°ã¯éœåž<var>i</var>ã®äœçœ®ã®<var>x</var>座æš<var>p_i</var>ã空çœ<var>1</var>æååºåãã§äžããããã ç¶ã<var>M</var>è¡ã¯æµã®äœçœ®æ
å ±ãäžããããã <var>j+2</var>è¡ç®(<var>1 \leq j \leq M</var>)ã¯<var>2</var>ã€ã®æŽæ°ãããªããæµ<var>j</var>ã®<var>1</var>æ¥ç®ã®äœçœ®ã®<var>x</var>座æš<var>a_j</var>ã<var>y</var>座æš<var>b_j</var>ã空çœ<var>1</var>æååºåãã§äžããããã</p>
<p>å¶çŽ:</p>
<ul>
<li><var>1 \leq N \leq 10^4</var></li>
<li><var>1 \leq M \leq 10^4</var></li>
<li><var>1 \leq D \leq 10^2</var></li>
<li><var> 1 \leq X \leq 10^6</var></li>
<li><var>0 \leq p_i, a_j \leq 10^6, -10^6 \leq b_j \leq 10^6</var></li>
<li><var>p_i<p_{i+1}</var></li>
</ul>
<h3>Output</h3>
<p><var>D</var>æ¥ç®ãŸã§ã«éœåž<var>N</var>ã«ããããã®ãªã¹ã¯ã®ç·åã®æå°å€ã<var>1</var>è¡ã«åºåãããè¡ã®æåŸã§ã¯å¿
ãæ¹è¡ãè¡ãããšã</p>
<h3>Sample Input 1</h3>
<pre>3 2 2 1
0 3 6
1 1
3 -2</pre>
<h3>Sample Output 1</h3>
<pre>6</pre>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2014_DangerousDelivery_sample1-1" alt="DangerousDelivery_sample1-1.png" />
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2014_DangerousDelivery_sample1-2" alt="DangerousDelivery_sample1-2.png" />
<p>1æ¥ç®ãéœåž1ã¯2人ãéœåž2ã¯0人ãéœåž3ã¯0人ã«ç£èŠãããŠããã 2æ¥ç®ãåæ§ã«ãéœåž1ã¯2人ãéœåž2ã¯0人ãéœåž3ã¯0人ã«ç£èŠãããŠããã ãã£ãŠã1æ¥ç®ã«éœåž1ããéœåž2ã«ç§»åããŠãªã¹ã¯ã<var>2 \times |3-0|=6</var>ã2æ¥ç®ã«éœåž2ããéœåž3ãžç§»åããŠãªã¹ã¯ã<var>0 \times |6-3|=0</var>ã®åèš6ãæå°ã§ããã</p>
<h3>Sample Input 2</h3>
<pre>3 2 2 1
0 3 6
2 1
3 -1</pre>
<h3>Sample Output 2</h3>
<pre>9</pre>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2014_DangerousDelivery_sample2-1" alt="DangerousDelivery_sample2-1.png" />
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2014_DangerousDelivery_sample2-2" alt="DangerousDelivery_sample2-2.png" />
<p>ç§»åã®ä»æ¹ã¯1ã€ç®ã®ãµã³ãã«ãšåãã ãã2æ¥ç®ã¯æµã®ç§»åã«ããéœåž2ã®ç£èŠäººæ°ã1人å¢ãããããã³ã¹ãã<var>1 \times |6-3|=3</var>ã«å€åããã ãã£ãŠãæå°ãªã¹ã¯ã¯9ã§ããã</p>
<h3>Sample Input 3</h3>
<pre>10 8 5 3
0 8 10 13 17 20 21 29 30 45
18 2
50 -20
17 1
38 21
40 -11
0 0
0 0
22 -1</pre>
<h3>Sample Output 3</h3>
<pre>222</pre> |
p02114 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<h1>Problem D: Fissure Puzzle Easy</h1>
<h2>Problem</h2>
<p>$N \times N$åã®ãã¹ããæãã°ãªããããããæåãã¹ãŠã®ãã¹ã¯çœè²ã§ããã以äžã®æé ã«åŸã£ãŠé»è²ã®ãã¹ãå¢ãããŠããã</p>
<p>äžããå¶æ°çªç®ãã€ãå·Šããå¶æ°çªç®ã§ãããã¹ã®äžã§ãçœè²ã®ãã¹ã1ã€éžã¶ãéžãã ãã¹ã¯é»è²ã«å€åãããããã«ããã®ãã¹ã®äžäžå·Šå³ããããã®æ¹åã«ã€ããŠã飿¥ããŠããçœè²ã®ãã¹ãé£éçã«é»è²ã«å€åããããã®é£éã¯ãã®æ¹åã«çœè²ã®ãã¹ãååšããªããªããŸã§ç¶ãã(以äžã«äŸã瀺ã)</p>
<p>
â¡â¡â¡â¡â¡â¡â¡â¡â¡<br>
â¡â¡â¡â¡â¡â¡â¡â¡â¡<br>
â¡â¡â¡â¡â¡â¡â¡â¡â¡<br>
â¡â¡â¡â¡â¡â¡â¡â¡â¡<br>
â¡â¡â¡â¡â¡â¡â¡â¡â¡<br>
â¡â¡â¡â¡â¡â¡â¡â¡â¡<br>
â¡â¡â¡â¡â¡â¡â¡â¡â¡<br>
â¡â¡â¡â¡â¡â¡â¡â¡â¡<br>
â¡â¡â¡â¡â¡â¡â¡â¡â¡<br>
âäžãã4çªç®ãå·Šãã6çªç®ãéžã¶<br>
â¡â¡â¡â¡â¡â â¡â¡â¡<br>
â¡â¡â¡â¡â¡â â¡â¡â¡<br>
â¡â¡â¡â¡â¡â â¡â¡â¡<br>
â â â â â â â â â <br>
â¡â¡â¡â¡â¡â â¡â¡â¡<br>
â¡â¡â¡â¡â¡â â¡â¡â¡<br>
â¡â¡â¡â¡â¡â â¡â¡â¡<br>
â¡â¡â¡â¡â¡â â¡â¡â¡<br>
â¡â¡â¡â¡â¡â â¡â¡â¡<br>
âäžãã2çªç®ãå·Šãã2çªç®ãéžã¶<br>
â¡â â¡â¡â¡â â¡â¡â¡<br>
â â â â â â â¡â¡â¡<br>
â¡â â¡â¡â¡â â¡â¡â¡<br>
â â â â â â â â â <br>
â¡â¡â¡â¡â¡â â¡â¡â¡<br>
â¡â¡â¡â¡â¡â â¡â¡â¡<br>
â¡â¡â¡â¡â¡â â¡â¡â¡<br>
â¡â¡â¡â¡â¡â â¡â¡â¡<br>
â¡â¡â¡â¡â¡â â¡â¡â¡<br>
âäžãã6çªç®ãå·Šãã8çªç®ãéžã¶<br>
â¡â â¡â¡â¡â â¡â¡â¡<br>
â â â â â â â¡â¡â¡<br>
â¡â â¡â¡â¡â â¡â¡â¡<br>
â â â â â â â â â <br>
â¡â¡â¡â¡â¡â â¡â â¡<br>
â¡â¡â¡â¡â¡â â â â <br>
â¡â¡â¡â¡â¡â â¡â â¡<br>
â¡â¡â¡â¡â¡â â¡â â¡<br>
â¡â¡â¡â¡â¡â â¡â â¡<br>
</p>
<p>
ããªãã¯äžãã$i$çªç®ã§å·Šãã$j$çªç®ã®ãã¹ã®è²ã$A_{i,j}$ã§ããã°ãªãããäœãããããã¹ãéžã¶æå°ã®åæ°ãæ±ããã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<p>
$N$<br>
$A_{1,1}$ $A_{1,2}$ ... $A_{1,N}$<br>
$A_{2,1}$ $A_{2,2}$ ... $A_{2,N}$<br>
...<br>
$A_{N,1}$ $A_{N,2}$ ... $A_{N,N}$<br>
</p>
<p>
$A_{i,j}$ã'o'ã§ãããšãã¯äžãã$i$çªç®ãå·Šãã$j$çªç®ã®ãã¹ãçœè²ã§ããããšã衚ãã'x'ã®ãšãã¯é»è²ã®ãã¹ã§ããããšã衚ãã
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>$3 \le N \le 127$</li>
<li>$N$ã¯å¥æ°ã§ãã</li>
<li>$A_{i,j}$ã¯'o'ã'x'ã§ãã</li>
<li>å¿
ãäœãããšãã§ãããããªå
¥åããäžããããªã</li>
</ul>
<h2>Output</h2>
<p>
1è¡ç®ã«ãã¹ãéžã¶åæ°ã®æå°å€ãåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
5
oxooo
oxooo
oxooo
xxxxx
oxooo
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<h2>Sample Input 2</h2>
<pre>
9
oxoooooxo
oxxxxxxxx
oxoooooxo
xxxxxxxxx
oxoxooooo
oxxxxxxxx
oxoxoxooo
oxoxxxxxx
oxoxoxooo
</pre>
<h2>Sample Output 2</h2>
<pre>
4
</pre> |
p00129 |
<h1>ãããããŒã</H1>
<p>
ãããåã¯ãããããŒããèŠæã§ããé ãããšããèŠã€ãã£ã¡ããããé ããŠããåããªããªãèŠã€ããããšãã§ããŸãããèŠããããç¶ããã¯ãè¶
髿§èœäœçœ®æ¢çŽ¢ã·ã¹ãã ãäœã£ãŠãããŸãããããã䜿ããšèªåã®äœçœ®ãå«ããŠãåéã®äœçœ®ãæ£ç¢ºã«ç¥ãããšãã§ããŸãã鬌ã«ãªã£ãããé ããŠããåãæ¢ãããšãç°¡åã«ã§ããããã«ãªããŸããã
</p>
<!--
èŠã€ãããåã®äœçœ®ã«è¡ãã°ãããã§ OK ã®ã¯ãã§ããããã䜿ã£ãŠããããšãã°ãããšéãã§ããããªããªãã®ã§å
ç·ã§äœ¿ããŸãã
-->
<p>
ãããåã¯ããã«ãã®ã·ã¹ãã ãé²åããã鬌ããèªåãèŠãããåŠããå€å®ããæ©èœãä»å ããããšãæãã€ããŸããããããã§ããã°ããããããããããšèšãããŠããèŠããäœçœ®ã«ããã°ããŸãã ã ããã ããèŠããªãäœçœ®ã«ããã°ãããããããã§ããããã€ãéãã§ããå
¬åã«ã¯å€§å°ããŸããŸãªåç圢ã®å£ããããŸãããã®å£ã¯å€ããã¯äžã¯èŠããªãããäžããå€ãèŠããŸããã鬌ãšäžç·ã«äžã«å
¥ããšå¥ã®å£ããªããã°èŠãã¡ãããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hideandseek">
</center>
<br/>
<p>
ãããåã¯ã¢ã€ãã¢ã¯ããã®ã§ããããœãããäœãã®ãèŠæã§ããããã§èŠªåã®ããªãã¯ãããåã«ä»£ãã£ãŠãã鬌ããèŠããªãããšç¢ºèªã·ã¹ãã ãã®ãœãããŠã§ã¢ãäœãããšã«ãªããŸãããå
¬åã®å£ã¯åºå®ãããŠããŸããããããåãšé¬Œã®ãããããªäœçœ®æ
å ±ã«å¯ŸããŠèŠãããåŠããå€å®ããå¿
èŠããããŸãã
</p>
<p>
å
¬åã«ããå£ã®æ
å ±(äžå¿ã®åº§æš (<var>wx</var>, <var>wy</var>) ãš ååŸ <var>r</var>) ãšãããåãšé¬Œã®äœçœ®æ
å ±(ãããåã®äœçœ®ã®åº§æš (<var>tx</var>, <var>ty</var>) ãšé¬Œã®äœçœ®ã®åº§æš (<var>sx</var>, <var>sy</var>) ) ãå
¥åãšãããã®äœçœ®ã§é¬ŒãããããåãèŠãããåŠããå€å®ããããã°ã©ã ãäœæããŠãã ããã
</p>
<p>
ãªãã鬌ãããããåãèŠããå Žåã«ã¯ DangerãèŠããªãå Žåã«ã¯ Safe ãšåºåããŠãã ããã鬌ãšãããåã®äœçœ®ãçµãã ç·åäžã«å£ãããå Žåã«ã¯èŠããªããã®ãšãã鬌ããããåãå£ã®äžã«ã¯ããªããã®ãšããŸãã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var>
<var>wx<sub>1</sub></var> <var>wy<sub>1</sub></var> <var>r<sub>1</sub></var>
<var>wx<sub>2</sub></var> <var>wy<sub>2</sub></var> <var>r<sub>2</sub></var>
:
<var>wx<sub>n</sub></var> <var>wy<sub>n</sub></var> <var>r<sub>n</sub></var>
<var>m</var>
<var>tx<sub>1</sub></var> <var>ty<sub>1</sub></var> <var>sx<sub>1</sub></var> <var>sy<sub>1</sub></var>
<var>tx<sub>2</sub></var> <var>ty<sub>2</sub></var> <var>sx<sub>2</sub></var> <var>sy<sub>2</sub></var>
:
<var>tx<sub>m</sub></var> <var>ty<sub>m</sub></var> <var>sx<sub>m</sub></var> <var>sy<sub>m</sub></var>
</pre>
<p>
1 è¡ç®ã«åç圢ã®å£ã®æ° <var>n</var> (0 ≤ <var>n</var> ≤ 100)ãç¶ã <var>n</var> è¡ã«å£ <var>i</var> ã®äžå¿ã®åº§æšãè¡šãæŽæ° <var>wx<sub>i</sub></var>, <var>wy<sub>i</sub></var> (0 ≤ <var>wx<sub>i</sub></var>, <var>wy<sub>i</sub></var> ≤ 255) ãšååŸãè¡šãæŽæ° <var>r<sub>i</sub></var> (1 ≤ <var>r<sub>i</sub></var> ≤ 255) ãäžããããŸãã
</p>
<p>
ç¶ãè¡ã«ãããåãšé¬Œã®äœçœ®æ
å ±ã®åæ° <var>m</var> (m ≤ 100)ãç¶ã <var>m</var> è¡ã«äœçœ®æ
å ± <var>i</var> ã®ãããåã®äœçœ®ã®åº§æšãè¡šãæŽæ° <var>tx<sub>i</sub></var>, <var>ty<sub>i</sub></var> (0 ≤ <var>tx<sub>i</sub></var>, <var>ty<sub>i</sub></var> ≤ 255) ãšé¬Œã®äœçœ®ã®åº§æšãè¡šãæŽæ° <var>sx<sub>i</sub></var>, <var>sy<sub>i</sub></var> (0 ≤ <var>sx<sub>i</sub></var>, <var>sy<sub>i</sub></var> ≤ 255) ãäžããããŸãã
</p>
<p>
ãŸããåç圢ã®å£ã®äžéšã ããå
¬åã«ãããšããããšã¯ãªããå
šãŠã®å£ã¯åçãšããŠãå
¬åã®å
éšã«å
¥ã£ãŠããŸãã
</p>
<p>
<var>n</var> ã 0 ã®ãšãå
¥åã®çµããã瀺ããŸããããŒã¿ã»ããã®æ°ã¯ 20 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
åããŒã¿ã»ããã«ã€ããŠãäœçœ®æ
å ± <var>i</var> ã®å€å®çµæ Danger ãŸã㯠Safe ã <var>i</var> è¡ç®ã«åºåããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
3
6 6 3
19 7 4
21 8 1
6
5 4 2 11
12 4 2 11
11 9 2 11
14 3 20 5
17 9 20 5
20 10 20 5
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Safe
Safe
Danger
Safe
Danger
Safe
</pre>
|
p02544 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are a permutation <var>p_1, p_2, \dots, p_N</var> of <var>(1, 2, ..., N)</var> and an integer <var>K</var>. Maroon performs the following operation for <var>i = 1, 2, \dots, N - K + 1</var> in this order:</p>
<ul>
<li>Shuffle <var>p_i, p_{i + 1}, \dots, p_{i + K - 1}</var> uniformly randomly.</li>
</ul>
<p>Find the expected value of the inversion number of the sequence after all the operations are performed, and print it modulo <var>998244353</var>.</p>
<p>More specifically, from the constraints of this problem, it can be proved that the expected value is always a rational number, which can be represented as an irreducible fraction <var>\frac{P}{Q}</var>, and that the integer <var>R</var> that satisfies <var>R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353</var> is uniquely determined. Print this <var>R</var>.</p>
<p>Here, the inversion number of a sequence <var>a_1, a_2, \dots, a_N</var> is defined to be the number of ordered pairs <var>(i, j)</var> that satisfy <var>i < j, a_i > a_j</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 200,000</var></li>
<li><var>2 \leq K \leq N</var></li>
<li><var>(p_1, p_2, \dots, p_N)</var> is a permutation of <var>(1, 2, \dots, N)</var>.</li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>p_1</var> <var>p_2</var> ... <var>p_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the expected value modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2
1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>The final sequence is one of <var>(1, 2, 3)</var>, <var>(2, 1, 3)</var>, <var>(1, 3, 2)</var>, <var>(2, 3, 1)</var>, each with probability <var>\frac{1}{4}</var>.
Their inversion numbers are <var>0, 1, 1, 2</var> respectively, so the expected value is <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 3
1 8 4 9 2 3 7 10 5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>164091855
</pre></section>
</div>
</span> |
p00579 | <h1>ã€ã«ãããŒã·ã§ã³ (Illumination)</h1>
<!--ããæéå¶é : 2sec / ã¡ã¢ãªå¶é : 256MB-->
<h2>å顿</h2>
<p>
JOI æ°ã¯ïŒèªå®
ã®æ·å°ã« <var>N</var> æ¬ã®æšãææããŠããïŒãããã®æšã¯äžåã«äžŠãã§ããïŒé ã« <var>1</var> ãã <var>N</var> ãŸã§ã®æŽæ°ã§çªå·ãä»ããããŠããïŒ
</p>
<p>
ãã®å¬ïŒJOI æ°ã¯ããã€ãã®æšãéžãã§ïŒã€ã«ãããŒã·ã§ã³ã食ãä»ããããšã«ããïŒã€ã«ãããŒã·ã§ã³ã«ã¯<strong>çŸãã</strong>ãšåŒã°ããå€ãå®ãŸã£ãŠããïŒæš <var>i</var> ã«ã€ã«ãããŒã·ã§ã³ã食ãä»ããå Žåã®çŸãã㯠<var>A_i</var> ã§ããïŒ
</p>
<p>
JOI æ°ã¯ïŒããŸãã«è¿ã <var>2</var> ã€ã®æšã®äž¡æ¹ã«ã€ã«ãããŒã·ã§ã³ã食ãä»ããŠããŸããšïŒç©ããããå Žåãããããšã«æ°ãã€ããïŒå
·äœçã«ã¯ïŒ<var>j = 1, 2, ..., M</var> ã«å¯ŸããŠïŒæš <var>L_j</var>, <var>L_j + 1</var>, <var>...</var>, <var>R_j</var> ã®ãã¡ <var>2</var> ã€ä»¥äžã«ã€ã«ãããŒã·ã§ã³ã食ãä»ããã¹ãã§ã¯ãªããšããããšã倿ããïŒ
</p>
<p>
ãã®æ¡ä»¶ã«åŸã£ãŠã€ã«ãããŒã·ã§ã³ã食ãä»ãããšãã®ïŒçŸããã®åèšã®æå€§å€ãæ±ããïŒ
</p>
<h2>å¶çŽ</h2>
<ul>
<li><var>1 ⊠N ⊠200000 (= 2Ã10^5)</var></li>
<li><var>1 ⊠M ⊠200000 (= 2Ã10^5)</var></li>
<li><var>1 ⊠A_i ⊠1000000000 (= 10^9)</var> (<var>1 ⊠i ⊠N</var>)</li>
<li><var>1 ⊠L_j ⊠R_j ⊠N</var> (<var>1 ⊠j ⊠M</var>)</li>
</ul>
<h2>å
¥åã»åºå</h2>
<p>
<b>å
¥å</b><br>
å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããïŒ<br>
<var>N</var> <var>M</var><br>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var><br>
<var>L_1</var> <var>R_1</var><br>
<var>L_2</var> <var>R_2</var><br>
<var>â®</var><br>
<var>L_M</var> <var>R_M</var>
</p>
<p>
<b>åºå</b><br>
ã€ã«ãããŒã·ã§ã³ã®çŸããã®åèšã®æå€§å€ã <var>1</var> è¡ã§åºåããïŒ
</p>
<!--
<h2>å°èª²é¡</h2>
<p style="line-height: 200%; margin-left: 30px; margin-right: 30px;">
</p>
<p style="line-height: 200%; margin-left: 30px; margin-right: 30px;">
<ol style="line-height: 200%; margin-left: 30px; margin-right: 30px;">
<li>(<var>10</var> ç¹) <var>N ⊠16</var>ïŒ<var>M ⊠16</var></li>
<li>(<var>30</var> ç¹) <var>N ⊠300</var>ïŒ<var>M ⊠300</var></li>
<li>(<var>30</var> ç¹) <var>N ⊠4000</var>ïŒ<var>M ⊠4000</var></li>
<li>(<var>30</var> ç¹) 远å ã®å¶éã¯ãªãïŒ</li>
</ol>
</p>
-->
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
4 1
1 2 3 8
2 4
</pre>
<h3>åºåäŸ 1</h3>
<pre>
9
</pre>
<p>
ãã®å
¥åäŸã§ã¯ïŒæš <var>1</var>, <var>4</var> ã«ã€ã«ãããŒã·ã§ã³ã食ãä»ãããšïŒçŸããã®åèšã <var>9</var> ãšãªãæå€§ãšãªãïŒ<var>L_1 = 2</var>, <var>R_1 = 4</var> ãªã®ã§ïŒæš <var>2</var>, <var>3</var>, <var>4</var> ã®ãã¡ <var>2</var> ã€ä»¥äžã«ã€ã«ãããŒã·ã§ã³ã食ãä»ããããšã¯ã§ããªãïŒäŸãã°æš <var>1</var>, <var>2</var>, <var>4</var> ã«ã€ã«ãããŒã·ã§ã³ã食ãä»ããããšã¯ã§ããªãããšã«æ³šæããïŒ
</p>
<h3>å
¥åäŸ 2</h3>
<pre>
5 2
2 3 9 5 6
1 3
2 4
</pre>
<h3>åºåäŸ 2</h3>
<pre>
15
</pre>
<h3>å
¥åäŸ 3</h3>
<pre>
20 10
870851814 594414687 615919461 65033245 460143082 617460823 881870957 126041265 623075703 34130727 27054628 853567651 483228744 491145755 220689940 148007930 229257101 790404982 612186806 281076231
15 19
20 20
12 13
1 4
19 19
9 13
3 6
9 12
16 16
18 19
</pre>
<h3>åºåäŸ 3</h3>
<pre>
4912419478
</pre>
<br/>
<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/2018/2019-yo/index.html">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第 18 åæ¥æ¬æ
å ±ãªãªã³ãã㯠JOI 2018/2019 äºéžç«¶æèª²é¡ã</a>
</p>
</div>
|
p00083 |
<H1>西æŠåæŠå€æ</H1>
<p>
西æŠã§è¡šãããå¹Žææ¥ããå
å·ãçšããåæŠã«å€æãããã®å¹Žææ¥ãåºåããããã°ã©ã ãäœæããŠãã ãããå
¥åã¯äŸã«ç€ºãããã« 3 ã€ã®æŽæ°ã§ãããé ã«è¥¿æŠå¹Žãæãæ¥ã§ããããããåºåäŸã«ç€ºãããã«å€æããŠãã ããããªããææ²»ä»¥åã®å¹Žææ¥ãå
¥åãããå Žåã¯ãpre-meijiããšè¡šç€ºããŠãã ããã
</p>
<p>
å幎å·ã®æåã®å¹Žã¯ãå
幎ãã§ã¯ãªããïŒå¹ŽããšåºåããããšãšããŸãã
</p>
<center>
<table border=1>
<tr><td align=center width=100>å
å·</td><td align=center width=240>æé</td></tr>
<tr><td align=center >meiji</td><td>1868. 9. 8 ã 1912. 7.29</td></tr>
<tr><td align=center >taisho</td><td>1912. 7.30 ã 1926.12.24</td></tr>
<tr><td align=center >showa</td><td>1926.12.25 ã 1989. 1. 7</td></tr>
<tr><td align=center >heisei</td><td>1989. 1. 8 ã</td></tr>
</table>
</center>
<br/>
<H2>å
¥å</H2>
<p>
è€æ°ã®ããŒã¿ãäžããããŸããåããŒã¿ãšããŠå¹Žãæãæ¥ã衚ãïŒã€ã®æŽæ°ã空çœåºåãã§ïŒè¡ã«äžããããŸãã
</p>
<p>
å
¥åã®çµãããŸã§åŠçããŠãã ãããããŒã¿ã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<H2>åºå</H2>
<p>
空çœåºåãã®å
å·ã幎ãæãæ¥ããŸãã¯ãpre-meijiããïŒè¡ã«åºåããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
2005 9 3
1868 12 2
1868 9 7
</pre>
<H2>Output for the Sample Input</H2>
<pre>
heisei 17 9 3
meiji 1 12 2
pre-meiji
</pre>
|
p00216 |
<H1>æ°Žéæé</H1>
<p>
<!--ããã¥åŠåéœåžã«äœãã§ãã-->æŸå¹³ããã¯ãæ®æ®µãããšã³ã«æ°ãä»ããŠç掻ãããŠããŸããå
æã®æ°Žéæéã 4280 åãšãªãããã€ãç®æšãšããŠãã 4000 åãè¶
ããŠããŸã£ãã®ã§ã仿ã¯ç¯æ°Žã«åªããŠããŸãããå
æãšæ¯ã¹ãŠæ°Žéæéã¯ã©ã®ãããç¯çŽã§ããã®ã§ããããã
</p>
<p>
仿ã®äœ¿çšæ°Žé <var>w</var> [m<sup>3</sup>] ãå
¥åãšããå
æã®æ°Žéæéã§ãã 4280 åãšæ¯èŒããŠãã©ã®ãããæ°Žéæéãç¯çŽã§ããããåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<p>
ãªããæ°Žéæéã¯æ¬¡ã®ããã«èšç®ãããŸãã
</p>
<p>
(æ°Žéæé) = (åºæ¬æé) + (æ°Žéã«ããæé)
</p>
<p>
æ°Žéã«ããæéã¯äžè¡šã®ããã«äœ¿çšéã«å¿ããŠèšç®ãããŸãã
</p>
<center>
<table>
<tr>
<th width="180"> 段é</th><th width="240"> æ°Žé </th><th width="240"> æé</th>
</tr>
<tr>
<td>第 1 段éæé </td><td> 10 [m<sup>3</sup>] ãŸã§ </td><td> åºæ¬æé 1150 å </td>
</tr>
<tr>
<td>第 2 段éæé </td><td> 10 [m<sup>3</sup>] è¶
é 20 [m<sup>3</sup>] ãŸã§</td><td> 1 [m<sup>3</sup>] ããã 125 å </td>
</tr>
<tr>
<td>第 3 段éæé </td><td> 20 [m<sup>3</sup>] è¶
é 30 [m<sup>3</sup>] ãŸã§ </td><td>1 [m<sup>3</sup>] ããã 140 å </td>
</tr>
<tr>
<td>第 4 段éæé </td><td> 30 [m<sup>3</sup>] è¶
éå </td><td> 1 [m<sup>3</sup>] ããã 160 å </td>
</tr>
</table>
</center>
<br/>
<p>
äŸãã°ãäœ¿çšæ°Žé 40 [m<sup>3</sup>] ã®å Žåã¯ã
åºæ¬æé 1150 å(第 1 段é) + 10 [m<sup>3</sup>] × 125 å(第 2 段é) + 10 [m<sup>3</sup>] × 140 å(第 3 段é) + 10 [m<sup>3</sup>] × 160 å(第 4 段é) = 5400 å
ãšãªããŸãã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµãã㯠-1 ã²ãšã€ã®è¡ã§ç€ºãããŸãã
</p>
<p>
åããŒã¿ã»ãããšããŠã 仿ã®äœ¿çšæ°Žéãè¡šãæŽæ° <var>w</var> (0 ≤ <var>w</var> ≤ 100) ãïŒè¡ã«äžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 200 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
å
¥åããŒã¿ã»ããããšã«ãå
æã®æ°Žéæéãšã®å·®ã1è¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
29
40
0
-1
</pre>
<H2>Output for the Sample Input</H2>
<pre>
620
-1120
3130
</pre>
|
p02381 |
<H1>Standard Deviation</H1><br>
<p>
You have final scores of an examination for <var>n</var> students. Calculate standard deviation of the scores <var>s<sub>1</sub></var>, <var>s<sub>2</sub></var> ... <var>s<sub>n</sub></var>.
</p>
<p>
The variance α<sup>2</sup> is defined by
</p>
<p>
α<sup>2</sup> = (∑<sup>n</sup><sub><i>i</i>=1</sub>(s<sub><i>i</i></sub> - m)<sup>2</sup>)/n
</p>
<p>
where <var>m</var> is an average of <var>s<sub>i</sub></var>.
The standard deviation of the scores is the square root of their variance.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset is given in the following format:
</p>
<pre>
<var>n</var>
<var>s</var><sub>1</sub> <var>s</var><sub>2</sub> ... <var>s</var><sub><var>n</var></sub>
</pre>
<p>
The input ends with single zero for <var>n</var>.
</p>
<H2>Output</H2>
<p>
For each dataset, print the standard deviation in a line. The output should not contain an absolute error greater than 10<sup>-4</sup>.
</p>
<H2>Constraints</H2>
<ul>
<li><var>n</var> ≤ 1000</li>
<li>0 ≤ <var>s<sub>i</sub></var> ≤ 100 </li>
</ul>
<H2>Sample Input</H2>
<pre>
5
70 80 100 90 20
3
80 80 80
0
</pre>
<H2>Sample Output</H2>
<pre>
27.85677655
0.00000000
</pre>
|
p01954 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }});
</script>
<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"></script>
<H1>
Sum Source Detection
</H1>
<p>
JAG members began a game with integers. The game consists of $N + M + 1$ players: $N$ open number holders, $M$ secret number holders, and one answerer, you.
</p>
<p>
In the preparation, an integer $K$ is told to all $N + M + 1$ players. $N + M$ number holders choose their own integers per person under the following restrictions:
</p>
<ul>
<li>Each holder owns a positive integer.</li>
<li>The sum of all the integers equals $K$.</li>
<li>Every integer owned by secret number holders is strictly less than any integers owned by open number holders.</li>
</ul>
<p>
After the choices, $N$ open number holders show their integers $O_1, ..., O_N$ to the answerer while secret number holders do not.
</p>
<p>
The game has $Q$ rounds. At the beginning of each round, $M$ secret number holders can change their numbers under
the above restrictions, while open number holders cannot. Then $N + M$ number holders select part of members among
them arbitrary, calculate the sum $X$ of the integers owned by the selected members, and tell $X$ to the answerer. For
each round, the answerer tries to identify the definitely selected open number holders from the information $K$, $X$, and $O_1, ..., O_N$: The answerer will get points per actually selected open number holder in the answer. On the other hand, if the answer contains at least one non-selected member, you lose your points got in the round. Thus, the answerer, you, must answer only the open number holders such that the holders are definitely selected.
</p>
<p>
Your task in this problem is to write a program to determine all the open number holders whose integers are necessary to the sum for each round in order to maximize your points.
</p>
<H2>Input</H2>
<p>
The input consists of a single test case formatted as follows.
</p>
<pre>
$N$ $M$ $K$ $Q$
$O_1$ ... $O_N$
$X_1$ ... $X_Q$
</pre>
<p>
The first line consists of four integers $N, M, K,$ and $Q$. $N$ and $M$ are the numbers of open number holders and secret number holders respectively ($1 \leq N, 0 \leq M, N + M \leq 40$). $K$ is an integer ($1 \leq K \leq 200,000$). $Q$ is the number of rounds of the game ($1 \leq Q \leq 10,000$).
</p>
<p>
The second line contains $N$ integers $O_1, ..., O_N$, as the $i$-th open number holder owns $O_i$ ($1 \leq O_1 \leq ... \leq O_N \leq K$).
</p>
<p>
The third line indicates $Q$ integers $X_1, ..., X_Q$ ($0 \leq X_i \leq K$). $X_i$ is the sum of the integers owned by the selected members in the $i$-th round.
</p>
<p>
It is guaranteed that there is at least one way to compose $X_i$. In other words, you can assume that there is at least one integer sequence $S_1, ..., S_M$, which represents integers owned by secret number holders, satisfying the followings:
</p>
<ul>
<li>$0 < S_j < O_1$ for $1 \leq j \leq M$. Note that $O_1 = min_{1\leq k \leq N}O_k$ holds.</li>
<li>$\sum_{j=1}^N O_j + \sum_{k=1}^M S_k = K$.</li>
<li>There is at least one pair of subsets $U \subseteq \{1,...,N\}$ and $V \subseteq \{1, ..., M\}$ such that $\sum_{j\in U} O_j + \sum_{k\in V}S_k = X_i$ holds.</li>
</ul>
<H2>Output</H2>
<p>
On each sum $X_i$, print the indices of the open number holders whose integers are required to make up $X_i$. The output for each sum has to be printed in one line, in ascending order, and separated by a single space. If there is no open number holder whose integer is certainly used for $X_i$, print $-1$ in one line.
</p>
<H2>Sample Input 1</H2>
<pre>
2 2 23 2
7 10
9 10
</pre>
<H2>Output for Sample Input 1</H2>
<pre>
1
-1
</pre>
<p>
The first sum 9 can be achieved only by the first open number holder's 7 plus 2 of a secret number holder. In this case, secret number holders have 2 and 4. The second open number holder's 10 is a candidate for the second sum 10. The first open holder's 7 plus 3 is also possible one, as secret number holders have two 3s.
</p>
<H2>Sample Input 2</H2>
<pre>
1 1 100 3
51
49 51 100
</pre>
<H2>Output for Sample Input 2</H2>
<pre>
-1
1
1
</pre>
<p>
The only secret number holder owns 49. The output for the first sum is $-1$ because the open number holder's 51 is not selected.
</p>
<H2>Sample Input 3</H2>
<pre>
2 1 58152 4
575 57500
575 57577 77 0
</pre>
<H2>Output for Sample Input 3</H2>
<pre>
1
2
-1
-1
</pre>
<p>
In this case, the only secret number holder definitely has 77. The output for the last sum 0 is -1 because no integer of open number holders is needed to form 0.
</p>
<H2>Sample Input 4</H2>
<pre>
3 2 1500 1
99 300 1000
99
</pre>
<H2>Output for Sample Input 4</H2>
<pre>
1
</pre>
<p>
The only way to compose 99 is to select the first open number holder only; secret number holders have two integers
between 1 and 98, while the sum of them must be 101.
</p>
<H2>Sample Input 5</H2>
<pre>
3 2 20 19
3 3 11
1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 18 19 20
</pre>
<H2>Output for Sample Input 5</H2>
<pre>
-1
-1
-1
-1
-1
-1
1 2
1 2
1 2
3
3
3
3
3
3
3
1 2 3
1 2 3
1 2 3
</pre>
<p>
The numbers owned by the two secret number holders are 1 and 2. At least one open number holder's 3 is required to
compose 5 and 6 respectively, but it is impossible to determine the definitely selected open number holder(s). On the other hand, 7 needs the two open number holders who both own 3.
</p>
|
p03969 | <span class="lang-en">
<p>Score : <var>1300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>One day, AtCoDeer the deer found a simple graph (that is, a graph without self-loops and multiple edges) with <var>N</var> vertices and <var>M</var> edges, and brought it home.
The vertices are numbered <var>1</var> through <var>N</var> and mutually distinguishable, and the edges are represented by <var>(a_i,b_i) (1âŠiâŠM)</var>.</p>
<p>He is painting each edge in the graph in one of the <var>K</var> colors of his paint cans. As he has enough supply of paint, the same color can be used to paint more than one edge.</p>
<p>The graph is made of a special material, and has a strange property. He can choose a simple cycle (that is, a cycle with no repeated vertex), and perform a circular shift of the colors along the chosen cycle. More formally, let <var>e_1</var>, <var>e_2</var>, <var>...</var>, <var>e_a</var> be the edges along a cycle in order, then he can perform the following simultaneously: paint <var>e_2</var> in the current color of <var>e_1</var>, paint <var>e_3</var> in the current color of <var>e_2</var>, <var>...</var>, paint <var>e_a</var> in the current color of <var>e_{a-1}</var>, and paint <var>e_1</var> in the current color of <var>e_{a}</var>.</p>
<div style="text-align: center;">
<img src="https://atcoder.jp/img/arc062/5fd1cd3003603ab14774f9342ccf2290.png">
<p>Figure <var>1</var>: An example of a circular shift</p>
</img></div>
<p>Two ways to paint the edges, <var>A</var> and <var>B</var>, are considered the same if <var>A</var> can be transformed into <var>B</var> by performing a finite number of circular shifts. Find the number of ways to paint the edges. Since this number can be extremely large, print the answer modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1âŠNâŠ50</var></li>
<li><var>1âŠMâŠ100</var></li>
<li><var>1âŠKâŠ100</var></li>
<li><var>1âŠa_i,b_iâŠN (1âŠiâŠM)</var></li>
<li>The graph has neither self-loops nor multiple edges.</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>b_1</var>
<var>a_2</var> <var>b_2</var>
<var>:</var>
<var>a_M</var> <var>b_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways to paint the edges, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 4 2
1 2
2 3
3 1
3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 2 3
1 2
4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>11 12 48
3 1
8 2
4 9
5 4
1 6
2 9
8 3
10 8
4 10
8 6
11 7
1 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>569519295
</pre></section>
</div>
</span> |
p00646 |
<H1><font color="#000000">Problem J:</font> No Story</H1>
<p>
Since I got tired to write long problem statements, I decided to make this problem statement short. For given positive integer <i>L</i>, how many pairs of positive integers <i>a</i>, <i>b</i> (<i>a</i> ≤ <i>b</i>) such that LCM(<i>a</i>, <i>b</i>) = <i>L</i> are there? Here, LCM(<i>a</i>, <i>b</i>) stands for the least common multiple of <i>a</i> and <i>b</i>.
</p>
<H2>Input</H2>
<p>
For each dataset, an integer <i>L</i> is given in a line. Input terminates when <i>L</i> = 0.
</p>
<H2>Output</H2>
<p>
For each dataset, output the number of pairs of <i>a</i> and <i>b</i>.
</p>
<H2>Constraints</H2>
<ul>
<li>1 ≤ <i>L</i> ≤ 10<sup>12</sup></li>
</ul>
<H2>Sample Input</H2>
<pre>
12
9
2
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
8
3
2
</pre>
|
p01407 |
<H1>A: Attack the Moles</H1>
<p>
ICPC ã§è¯ãæçžŸãåããã«ã¯ä¿®è¡ãæ¬ ãããªãïŒããã㯠ICPC ã§åã¡ããã®ã§ïŒä»æ¥ãä¿®è¡ãããããšã«ããïŒ
</p>
<p>
仿¥ã®ä¿®è¡ã¯ïŒãããããããäœåãè¡ã£ãŠïŒåå°ç¥çµãšèšæ¶åãé«ããããšãããã®ã§ããïŒåºãŠããããããæ¬¡ã
ã«å©ãïŒåºæ¥ãã ãå€ãã®ãã€ã³ããç²åŸãããïŒ
</p>
<p>
ããããåºãŠããå¯èœæ§ã®ããå Žæã¯çŽç·ç¶ã«äžŠãã§ããŠïŒåºæºç¹ããã®è·é¢ã«ãã£ãŠåº§æšãå®ãŸã£ãŠããïŒãããã¯ãã°ããä¿®è¡ãç¶ãããã¡ã«ïŒãããã®åºçŸããå Žæãšæéãåžžã«äžç·ã§ããããšã«æ°ãä»ããïŒãããã¯ïŒãã®æ
å ±ããã¹ãŠèšé²ãïŒã³ã³ãã¥ãŒã¿ã§è§£æãè¡ãããšã«ããïŒ
</p>
<p>
ããããå©ãã«ã¯ïŒãããã®åºçŸäœçœ®ã«æãåãããåŸïŒãããã®åºãŠããã¿ã€ãã³ã°ã«ãŽã£ããåãããŠããããå©ããªããã°ãªããªãïŒããããããŸãå©ãããšïŒãã®ãããã«å¿ããŠãã€ã³ããåŸãããšãåºæ¥ãïŒããããå©ãåäœã¯äžç¬ã§è¡ãããšãåºæ¥ããïŒæãç§»åãããéãã«ã¯éçãããïŒãããã¯ããããå©ãã«ããã£ãŠå·Šå³äž¡æ¹ã®æãçšããããšãã§ããïŒå·Šæãšå³æã¯ç¬ç«ã«åããããšãå¯èœã§ãããïŒå·Šæã¯åžžã«å³æãã座æšãå°ããäœçœ®ã«ååšããªããã°ãªããªãïŒãã®ãããªæ¡ä»¶äžã§ïŒæå€§ã§ã©ãã ãã®ãã€ã³ããåŸããããã調ã¹ããïŒ
</p>
<H2>Input</H2>
<pre>
<i>N</i> <i>V</i> <i>X</i><sub><i>Left</i></sub> <i>X</i><sub><i>Right</i></sub>
<i>X</i><sub>1</sub> <i>T</i><sub>1</sub> <i>P</i><sub>1</sub>
...
<i>X</i><sub><i>N</i></sub> <i>T</i><sub><i>N</i></sub> <i>P</i><sub><i>N</i></sub>
</pre>
<p>
<i>N</i> ã¯åºãŠãããããã®æ°ïŒ<i>V</i> ã¯æãç§»åãããããæå€§ã®éãïŒ<i>X</i><sub><i>Left</i></sub>, <i>X</i><sub><i>Right</i></sub> ã¯ããããïŒå·ŠæïŒå³æã®åæäœçœ®ã®åº§æšã§ããïŒ<i>X</i><sub><i>i</i></sub>, <i>T</i><sub><i>i</i></sub>, <i>P</i><sub><i>i</i></sub> ã¯ããããïŒ<i>i</i> çªç®ã®ãããã®ïŒåºçŸããäœçœ®ã®åº§æšïŒã²ãŒã éå§ããåºçŸãŸã§ã®æéïŒå©ããéã«åŸããããã€ã³ãã§ããïŒ
</p>
<p>
1 ≤ <i>N</i> ≤ 3,000ïŒ1 ≤ <i>V</i> ≤ 10,000ïŒ1 ≤ <i>X</i><sub><i>Left</i></sub> < <i>X</i><sub><i>Right</i></sub> ≤ 100,000ïŒ1 ≤ <i>X</i><sub>1</sub> ≤ <i>X</i><sub>2</sub> ≤ ... ≤ <i>X</i><sub><i>N</i></sub> ≤ 100,000ïŒ1 ≤ <i>T</i><sub><i>i</i></sub> ≤ 100,000ïŒ1 ≤ <i>P</i><sub><i>i</i></sub> ≤ 100,000 ãæºããïŒ(<i>X</i><sub><i>i</i></sub>, <i>T</i><sub><i>i</i></sub>) ãšããŠåäžã®çµã¯è€æ°åçŸããªãïŒ
</p>
<H2>Output</H2>
<p>
ããããåŸãããæå€§ã®ãã€ã³ãã 1 è¡ã«åºåããïŒ
</p>
<H2>Sample Input 1</H2>
<pre>
3 10 150 250
100 20 123
201 10 67
202 10 45
</pre>
<H2>Sample Output 1</H2>
<pre>
190
</pre>
<H2>Sample Input 2</H2>
<pre>
1 7 20 90
55 5 73
</pre>
<H2>Sample Output 2</H2>
<pre>
73
</pre>
<H2>Sample Input 3</H2>
<pre>
10 2 1000 2000
400 300 1
600 200 1
700 800 1
700 500 1
900 600 1
1000 700 1
1300 900 1
1400 400 1
1500 1000 1
2000 100 1
</pre>
<H2>Sample Output 3</H2>
<pre>
10
</pre> |
p03590 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><em>Seisu-ya</em>, a store specializing in non-negative integers, sells <var>N</var> non-negative integers. The <var>i</var>-th integer is <var>A_i</var> and has a <em>utility</em> of <var>B_i</var>.
There may be multiple equal integers with different utilities.</p>
<p>Takahashi will buy some integers in this store. He can buy a combination of integers whose <em>bitwise OR</em> is less than or equal to <var>K</var>. He wants the sum of utilities of purchased integers to be as large as possible.</p>
<p>Find the maximum possible sum of utilities of purchased integers.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>0 \leq K < 2^{30}</var></li>
<li><var>0 \leq A_i < 2^{30}(1\leq i\leq N)</var></li>
<li><var>1 \leq B_i \leq 10^9(1\leq i\leq N)</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>A_1</var> <var>B_1</var>
:
<var>A_N</var> <var>B_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>Print the maximum possible sum of utilities of purchased integers.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 5
3 3
4 4
2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p>Buy <var>2</var> and <var>3</var> to achieve the maximum possible total utility, <var>8</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 6
3 3
4 4
2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9
</pre>
<p>Buy <var>2</var> and <var>4</var> to achieve the maximum possible total utility, <var>9</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>32
</pre></section>
</div>
</span> |
p01057 |
<h1>String Crossing</h1>
<h2>Problem</h2>
<p>
<var>N</var>åã®æåå{ <var>S<sub>1</sub></var>, <var>S<sub>2</sub></var>, ..., <var>S<sub>N</sub></var> } ãäžããããã
ç¶ããŠ<var>Q</var>åã®ã¯ãšãªãäžããããã
ã¯ãšãªã®çš®é¡ã¯ä»¥äžã®2ã€ã§ããã
</p>
<ol>
<li>
<var>a</var>,<var>b</var>,<var>c</var>,<var>d</var>ãå
¥åãã<var>S<sub>a</sub></var> ã® <var>b</var>æåç®ããã® substring ã <var>S<sub>c</sub></var> ã® <var>d</var>-1æåãŸã§ã® substring ã®åŸã«ç¹ããããããæ°ãã<var>S<sub>c</sub></var>ãšããã
å
ã®<var>S<sub>c</sub></var> ã® <var>d</var>æåç®ããã® substring ã <var>S<sub>a</sub></var> ã® <var>b</var>-1æåãŸã§ã® substring ã®åŸã«ç¹ããããããæ°ãã<var>S<sub>a</sub></var>ãšããã
</li>
<li>
<var>a</var>,<var>b</var>,<var>c</var>ãå
¥åãã <var>S<sub>a</sub></var> ã® <var>b</var>æåç®ã <var>c</var> ã«å€æŽããã
</li>
</li>
</ol>
<p>
äŸãã°<var>S<sub>1</sub></var>="abcd",<var>S<sub>2</sub></var>="efgh"ããã
ã¯ãšãªã®çš®é¡ã1ã§<var>a</var>=1,<var>b</var>=2,<var>c</var>=2,<var>d</var>=3ã®ãšã
</p>
<pre>
a - -> bcd
X
ef - -> gh
</pre>
<p>
<var>S<sub>1</sub></var>="agh",<var>S<sub>2</sub></var>="efbcd"ãšãªãã
</p>
<p>
å
šãŠã®ã¯ãšãªãåŠçããåŸã®æåå<var>S<sub>1</sub></var>ãã<var>S<sub>N</sub></var>ãå
šãŠåºåããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var> <var>Q</var>
<var>S<sub>1</sub></var>
<var>S<sub>2</sub></var>
...
<var>S<sub>N</sub></var>
<var>query<sub>1</sub></var>
<var>query<sub>2</sub></var>
...
<var>query<sub>Q</sub></var>
</pre>
å<var>query</var>ã¯æ¬¡ã®ããããã§ããã
<pre>
1 <var>a</var> <var>b</var> <var>c</var> <var>d</var>
</pre>
<p>or</p>
<pre>
2 <var>a</var> <var>b</var> <var>c</var>
</pre>
<h2>Constraints</h2>
<ul>
<li>1 ≤ <var>N</var> ≤ 10<sup>5</sup></li>
<li>1 ≤ <var>Q</var> ≤ 10<sup>5</sup></li>
<li><var>N</var>åã®æååã®é·ãã®åèšã¯2×10<sup>6</sup>ãè¶ããªãã</li>
<li>æåå<var>S<sub>i</sub></var>ã¯å
šãŠè±å°æåã§ããããšãä¿èšŒãããã</li>
<li>ã¯ãšãªã®çš®é¡ã1ã®ãšã
<ul>
<li><var>a</var> ≠ <var>c</var></li>
<li>1 ≤ <var>b</var> ≤ |<var>S<sub>a</sub></var>|</li>
<li>1 ≤ <var>d</var> ≤ |<var>S<sub>c</sub></var>|</li>
</ul>
</li>
<li>ã¯ãšãªã®çš®é¡ã2ã®ãšã
<ul>
<li>1 ≤ <var>b</var> ≤ |<var>S<sub>a</sub></var>|</li>
<li><var>c</var>ã¯è±å°æåã§ããããšãä¿èšŒãããã</li>
</ul>
</li>
</ul>
<p>
é«éãªå
¥åºåãæšå¥šããã
</p>
<h2>Output</h2>
<p>
åã¯ãšãªãåŠçããåŸã®æååã<var>S<sub>1</sub></var>ãã<var>S<sub>N</sub></var>ãŸã§1è¡ãã€åºåããã
</p>
<pre>
<var>S<sub>1</sub></var>
<var>S<sub>2</sub></var>
...
<var>S<sub>N</sub></var>
</pre>
<h2>Sample Input 1</h2>
<pre>
2 1
abcd
efgh
1 1 2 2 3
</pre>
<h2>Sample Output 1</h2>
<pre>
agh
efbcd
</pre>
<h2>Sample Input 2</h2>
<pre>
2 3
abcd
efgh
1 1 2 2 3
2 1 3 x
2 2 4 x
</pre>
<h2>Sample Output 2</h2>
<pre>
agx
efbxd
</pre>
<h2>Sample Input 3</h2>
<pre>
10 10
sjcvpauokb
fmeaowomscy
sepeqqfcosrjmonfsv
zapc
aromazjzqoeiqswvcaf
clifpa
dusudcz
qeqdzdtdzlkhc
gkpsjvdvadmf
xrtyxnkolluagwxp
1 4 4 6 3
1 7 1 8 1
2 2 6 o
1 4 4 3 7
2 1 2 i
1 6 3 3 2
1 6 5 1 9
2 10 9 j
1 2 2 7 3
2 3 2 b
</pre>
<h2>Sample Output 3</h2>
<pre>
sicvpauoeqqifpa
fqdzdtdzlkhc
sb
zapfcosrjmonfsv
aromazjzqoeiqswvcaf
clepkb
qemeaooomscy
dusudcz
gkpsjvdvadmf
xrtyxnkojluagwxp
</pre>
|
p01542 |
<h1>倱ãããæ°</h1>
<p>
æã¯3xxx幎ãé«åºŠã«çºéããææã¯åæ»æãè¿ããŠãããæŽå²å®¶ãã¡ã¯ãã®ç¶æ³ãæéããããšéå»ã®å¡æºãåŠã¶ããšã«ãããæ³šç®ããã®ã¯ã³ã³ãã¥ãŒã¿åµäžæã®å€©æãæ®ããè³æã§ããããã®è³æã«ã¯èšç®åŒãæžãããŠãããã®èšç®çµæãç¥ãããã®ã ããæ®å¿µãªãããã®äžéšã®æåãèããŠèªããªããªã£ãŠããã仿¹ããªãã®ã§èšç®çµæãšããŠããããæã倧ããæ°ãæ±ããããšã«ããã
èšç®åŒã¯2鲿°ã§æžãããŠãããæŒç®ã¯è¶³ãç®ã»åŒãç®ã»æãç®ã®3çš®é¡ã§ãããæ¬åŒ§ãçšããããŠãããæ¬åŒ§å
ãæ°åã®ã¿ã§ããããšã¯ãªããæ£ç¢ºã«ã¯ä»¥äžã®BNFã§å®çŸ©ãããææ³ãæºãããŠããå¿
èŠãããã
</p>
<pre><expression> ::= <number> | <expression> <operation> <expression>
| ( <expression> <operation> <expression> )
<number> ::= <digit> | <number> <digit>
<operation> ::= + | - | *
<digit> ::= 0 | 1
</pre>
<p>
åœæã®ã³ã³ãã¥ãŒã¿ã®èšç®èœåã®éçã«ãããæ°åã¯0以äž<var>2<sup>10</sup></var>æªæºã®æŽæ°ã§ããèšç®äžããã®ç¯å²ãåºãããšã¯ãªãããã ãèšç®ã¯æ¬åŒ§å
ãå
ã«è¡ããæãç®ã¯è¶³ãç®ã»åŒãç®ããå
ã«è¡ãããã以å€ã®å Žåã¯å·Šããé ã«èšç®ããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯1è¡ãããªããè§£èªãã¹ãæ°åŒã1ã€äžãããããæ°åŒã¯1æå以äž100æå以äžã§ããã1ã€ã®æ°åŒã«ã€ããŠæå€§5æåãèªããªããªã£ãŠããŠãã.ãã§è¡šçŸãããŠãããäžããããæ°åŒã«å«ãŸããæåã¯01+-*().ã®ããããã§ããã
</p>
<h2>Constraints</h2>
<ul>
<li>æ°åŒã¯1æå以äž100æå以äž
</li><li>æ¹è¡ãé€ããã¹ãŠã®æåã¯01+-*().ã®ãããã
</li><li>.ã®åæ°ã¯5å以äž
</li></ul>
<h2>Output</h2>
<p>
å
ã®æ°åŒãšããŠèãããããã®ã®å
ãèšç®çµæãæå€§ãšãªããã®ãæ±ããèšç®çµæã10鲿³ã§åºåãããèªããªããªã£ãŠããæåãã©ã®ããã«åããŠãå
ã®æ°åŒãšèãããããã®ãäœããªããšãã¯-1ãåºåããã
</p>
<H2>Sample Input 1</H2>
<pre>000
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>0
</pre>
<H2>Sample Input 2</H2>
<pre>0.0
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>2
</pre>
<H2>Sample Input 3</H2>
<pre>...
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>7
</pre>
<H2>Sample Input 4</H2>
<pre>(1.1)
</pre>
<H2>Output for the Sample Input 4</H2>
<pre>2
</pre>
<H2>Sample Input 5</H2>
<pre>0-1.
</pre>
<H2>Output for the Sample Input 5</H2>
<pre>-1
</pre> |
p03085 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>On the Planet AtCoder, there are four types of bases: <code>A</code>, <code>C</code>, <code>G</code> and <code>T</code>. <code>A</code> bonds with <code>T</code>, and <code>C</code> bonds with <code>G</code>.</p>
<p>You are given a letter <var>b</var> as input, which is <code>A</code>, <code>C</code>, <code>G</code> or <code>T</code>. Write a program that prints the letter representing the base that bonds with the base <var>b</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>b</var> is one of the letters <code>A</code>, <code>C</code>, <code>G</code> and <code>T</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>b</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the letter representing the base that bonds with the base <var>b</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>A
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>T
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>G
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>C
</pre></section>
</div>
</span> |
p01112 | <h3>Playoff by all the teams</h3>
<!-- end en only -->
<!-- begin en only -->
<p>
The Minato Mirai Football Association hosts its annual championship
as a single round-robin tournament,
in which each team plays a single match against all the others.
Unlike many other round-robin tournaments of football,
matches never result in a draw in this tournament.
When the regular time match is a tie,
overtime is played, and, when it is a tie again,
a penalty shootout is played to decide the winner.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
If two or more teams won the most number of matches in the round-robin,
a playoff is conducted among them to decide the champion.
However, if the number of teams is an odd number,
it is possible that all the teams may have
the same number of wins and losses,
in which case all the teams participate in the playoff,
called a "full playoff" here.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Now, some of the tournament matches have already been played and we know
their results.
Whether or not a full playoff will be required may
depend on the results of the remaining matches.
Write a program that computes the number of win/loss combination patterns
of the remaining matches that lead to a full playoff.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The first datatset of the Sample Input represents the results of the
first three matches in a round-robin tournament of five teams, shown
in the following table.
In the table, gray cells indicate the matches not played yet.
</p>
<!-- end en only -->
<table border="">
<tbody><tr><th><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dtitle" alt="Team \ Against"></th><th>Team<sub>1</sub></th><th>Team<sub>2</sub></th><th>Team<sub>3</sub></th><th>Team<sub>4</sub></th><th>Team<sub>5</sub></th></tr>
<tr><th>Team<sub>1</sub></th><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td bgcolor="#cccccc"> </td><td bgcolor="#cccccc"> </td><td align="center">lost</td><td align="center">lost</td></tr>
<tr><th>Team<sub>2</sub></th><td bgcolor="#cccccc"> </td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td align="center">lost</td><td bgcolor="#cccccc"> </td><td bgcolor="#cccccc"> </td></tr>
<tr><th>Team<sub>3</sub></th><td bgcolor="#cccccc"> </td><td align="center">won</td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td bgcolor="#cccccc"> </td><td bgcolor="#cccccc"> </td></tr>
<tr><th>Team<sub>4</sub></th><td align="center">won</td><td bgcolor="#cccccc"> </td><td bgcolor="#cccccc"> </td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td bgcolor="#cccccc"> </td></tr>
<tr><th>Team<sub>5</sub></th><td align="center">won</td><td bgcolor="#cccccc"> </td><td bgcolor="#cccccc"> </td><td bgcolor="#cccccc"> </td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td></tr>
</tbody></table>
<!-- begin en only -->
<p>
In this case,
all the teams win the same number of matches
with only two win/loss combination patterns
of the remaining matches,
which lead to a full playoff,
as shown below.
In the two tables, the differences are indicated in light yellow.
</p>
<!-- end en only -->
<table border="">
<tbody><tr><th><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dtitle" alt="Team \ Against"></th><th>Team<sub>1</sub></th><th>Team<sub>2</sub></th><th>Team<sub>3</sub></th><th>Team<sub>4</sub></th><th>Team<sub>5</sub></th></tr>
<tr><th>Team<sub>1</sub></th><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td align="center">won</td><td align="center">won</td><td align="center">lost</td><td align="center">lost</td></tr>
<tr><th>Team<sub>2</sub></th><td align="center">lost</td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td align="center">lost</td><td align="center">won</td><td align="center">won</td></tr>
<tr><th>Team<sub>3</sub></th><td align="center">lost</td><td align="center">won</td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td align="center" bgcolor="#ffffcc">won</td><td align="center" bgcolor="#ffffcc">lost</td></tr>
<tr><th>Team<sub>4</sub></th><td align="center">won</td><td align="center">lost</td><td align="center" bgcolor="#ffffcc">lost</td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td align="center" bgcolor="#ffffcc">won</td></tr>
<tr><th>Team<sub>5</sub></th><td align="center">won</td><td align="center">lost</td><td align="center" bgcolor="#ffffcc">won</td><td align="center" bgcolor="#ffffcc">lost</td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td></tr>
</tbody></table>
<table border="">
<tbody><tr><th><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dtitle" alt="Team \ Against"></th><th>Team<sub>1</sub></th><th>Team<sub>2</sub></th><th>Team<sub>3</sub></th><th>Team<sub>4</sub></th><th>Team<sub>5</sub></th></tr>
<tr><th>Team<sub>1</sub></th><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td align="center">won</td><td align="center">won</td><td align="center">lost</td><td align="center">lost</td></tr>
<tr><th>Team<sub>2</sub></th><td align="center">lost</td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td align="center">lost</td><td align="center">won</td><td align="center">won</td></tr>
<tr><th>Team<sub>3</sub></th><td align="center">lost</td><td align="center">won</td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td align="center" bgcolor="#ffffcc">lost</td><td align="center" bgcolor="#ffffcc">won</td></tr>
<tr><th>Team<sub>4</sub></th><td align="center">won</td><td align="center">lost</td><td align="center" bgcolor="#ffffcc">won</td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td align="center" bgcolor="#ffffcc">lost</td></tr>
<tr><th>Team<sub>5</sub></th><td align="center">won</td><td align="center">lost</td><td align="center" bgcolor="#ffffcc">lost</td><td align="center" bgcolor="#ffffcc">won</td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td></tr>
</tbody></table>
<h3>Input</h3>
<!-- begin en only -->
<p>
The input consists of multiple datasets, each in the following format.
</p>
<!-- end en only -->
<blockquote>
<p>
<i>n</i><br>
<i>m</i><br>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <br>
... <br>
<i>x<sub>m</sub></i> <i>y<sub>m</sub></i> <br>
</p>
</blockquote>
<!-- begin en only -->
<p>
<i>n</i> is an odd integer, 3, 5, 7, or 9,
indicating the number of teams participating in the tournament.
<i>m</i> is a positive integer less than <i>n</i>(<i>n</i>−1)/2,
which is the number of matches already finished.
<i>x<sub>i</sub></i> and <i>y<sub>i</sub></i> give
the result of the <i>i</i>-th match that has already taken place,
indicating that team <i>x<sub>i</sub></i> defeated team
<i>y<sub>i</sub></i>.
Each of <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i> is an integer 1 through <i>n</i>
which indicates the team number.
No team plays against itself, that is, for any <i>i</i>,
<i>x<sub>i</sub></i> ≠ <i>y<sub>i</sub></i>.
The match result of the same team pair appears at most once.
That is, if <i>i</i> ≠ <i>j</i>,
then
(<i>x<sub>i</sub></i>,<i>y<sub>i</sub></i>) ≠
(<i>x<sub>j</sub></i>,<i>y<sub>j</sub></i>) and
(<i>x<sub>i</sub></i>,<i>y<sub>i</sub></i>) ≠
(<i>y<sub>j</sub></i>,<i>x<sub>j</sub></i>) hold.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The end of the input is indicated by a line containing a zero.
The number of datasets does not exceed 100.
</p>
<!-- end en only -->
<h3>Output</h3>
<!-- begin en only -->
<p>
For each dataset, output a single line containing one integer
which indicates the number of possible future win/loss patterns
that a full playoff will be required.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>5
3
3 2
4 1
5 1
3
1
1 2
3
2
1 2
3 2
5
4
4 1
4 2
5 1
5 2
5
3
4 1
4 2
5 1
5
4
3 2
4 1
5 1
5 2
9
11
6 1
6 4
7 2
7 3
7 4
8 2
8 3
8 4
9 1
9 3
9 5
9
10
6 1
6 4
7 2
7 3
7 4
8 2
8 3
8 4
9 1
9 3
5
6
4 3
2 1
5 1
2 4
1 3
2 3
9
1
1 2
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>2
1
0
0
1
0
0
16
0
1615040
</pre>
|
p00353 | <H1>Shopping</H1>
<p>
You are now in a bookshop with your friend Alice to buy a book, "The Winning Strategy for the Programming Koshien Contest,â just released today. As you definitely want to buy it, you are planning to borrow some money from Alice in case the amount you have falls short of the price. If the amount you receive from Alice still fails to meet the price, you have to abandon buying the book this time.
</p>
<p>
Write a program to calculate the minimum amount of money you need to borrow from Alice given the following three items of data: the money you and Alice have now and the price of the book.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>m</var> <var>f</var> <var>b</var>
</pre>
<p>
A line containing the three amounts of money is given: the amount you have with you now <var>m</var> (0 ≤ <var>m</var> ≤ 10000), the money Alice has now <var>f</var> (0 ≤ <var>f</var> ≤ 10000) and the price of the book <var>b</var> (100 ≤ <var>b</var> ≤ 20000).
</p>
<h2>Output</h2>
<p>
Output a line suggesting the minimum amount of money you need to borrow from Alice. Output "NA" if all the money Alice has with him now is not a sufficient amount for you to buy the book.
</p>
<h2>Sample Input 1</h2>
<pre>
1000 3000 3000
</pre>
<h2>Sample Output 1</h2>
<pre>
2000
</pre>
<h2>Sample Input 2</h2>
<pre>
5000 3000 4500
</pre>
<h2>Sample Output 2</h2>
<pre>
0
</pre>
<h2>Sample Input 3</h2>
<pre>
500 1000 2000
</pre>
<h2>Sample Output 3</h2>
<pre>
NA
</pre>
|
p03986 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a string <var>X</var>, which has an even number of characters. Half the characters are <code>S</code>, and the other half are <code>T</code>.</p>
<p>Takahashi, who hates the string <code>ST</code>, will perform the following operation <var>10^{10000}</var> times:</p>
<ul>
<li>Among the occurrences of <code>ST</code> in <var>X</var> as (contiguous) substrings, remove the leftmost one. If there is no occurrence, do nothing.</li>
</ul>
<p>Find the eventual length of <var>X</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 ⊠|X| ⊠200,000</var></li>
<li>The length of <var>X</var> is even.</li>
<li>Half the characters in <var>X</var> are <code>S</code>, and the other half are <code>T</code>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Scores</h3><ul>
<li>In test cases worth <var>200</var> points, <var>|X| ⊠200</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>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the eventual length of <var>X</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>TSTTSS
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>In the <var>1</var>-st operation, the <var>2</var>-nd and <var>3</var>-rd characters of <code>TSTTSS</code> are removed.
<var>X</var> becomes <code>TTSS</code>, and since it does not contain <code>ST</code> anymore, nothing is done in the remaining <var>10^{10000}-1</var> operations.
Thus, the answer is <var>4</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>SSTTST
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p><var>X</var> will eventually become an empty string: <code>SSTTST</code> â <code>STST</code> â <code>ST</code> â ``.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>TSSTTTSS
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
</pre>
<p><var>X</var> will become: <code>TSSTTTSS</code> â <code>TSTTSS</code> â <code>TTSS</code>.</p></section>
</div>
</span> |
p02694 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Takahashi has a deposit of <var>100</var> yen (the currency of Japan) in AtCoder Bank.</p>
<p>The bank pays an annual interest rate of <var>1</var> % compounded annually. (A fraction of less than one yen is discarded.)</p>
<p>Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach <var>X</var> yen or above for the first time?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var> 101 \le X \le 10^{18} </var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the number of years it takes for Takahashi's balance to reach <var>X</var> yen or above for the first time.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>103
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<ul>
<li>The balance after one year is <var>101</var> yen.</li>
<li>The balance after two years is <var>102</var> yen.</li>
<li>The balance after three years is <var>103</var> yen.</li>
</ul>
<p>Thus, it takes three years for the balance to reach <var>103</var> yen or above.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1000000000000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3760
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1333333333
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1706
</pre></section>
</div>
</span> |
p01811 |
<h2>ABC Gene</h2>
<p>æåå <code>ABC</code> ã§è¡šãããéºäŒåé
åããããããªãã¯æ¬¡ã®æäœãäœåãè¡ãããã®éºäŒåé
åãæžãæããŠããããšãã§ããã</p>
<ul>
<li>æå <code>A</code>ïŒ<code>B</code>ïŒ<code>C</code> ã®ãã¡ <var>1</var> ã€ãéžã¶ãããã <var>x</var> ãšãããéºäŒåé
åã«å«ãŸãããã¹ãŠã® <var>x</var> ããããã <code>ABC</code> ãžåæã«çœ®ãæããã</li>
</ul>
<p><code>A</code>ïŒ<code>B</code>ïŒ<code>C</code> ã ããããªãæåå <var>S</var> ãäžãããããéºäŒåé
åã <var>S</var> ã«äžèŽããããããå€å®ããã</p>
<h3>Constraints</h3>
<ul>
<li><var>1</var> ≤ <var>|S|</var> ≤ <var>5,000</var></li>
<li><var>S</var> 㯠<code>A</code>ïŒ<code>B</code>ïŒ<code>C</code> ã ããããªãã</li>
</ul>
<h3>Input Format</h3>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã</p>
<pre>
<var>S</var>
</pre>
<h3>Output Format</h3>
<p>éºäŒåé
åã <var>S</var> ã«äžèŽããããããªãã° <code>Yes</code> ããäžèŽãããããªããªãã° <code>No</code> ãäžè¡ã«åºåããã</p>
<h3>Sample Input 1</h3>
<pre>
ABC
</pre>
<h3>Sample Output 1</h3>
<pre>
Yes
</pre>
<p>éºäŒåé
åã¯ã¯ãããã <code>ABC</code> ã§ããã</p>
<h3>Sample Input 2</h3>
<pre>
AABCC
</pre>
<h3>Sample Output 2</h3>
<pre>
Yes
</pre>
<p><code>B</code> ãéžãã§æäœãè¡ããš <code>ABC</code> â <code>AABCC</code> ãšãªãã</p>
<h3>Sample Input 3</h3>
<pre>
AABCABC
</pre>
<h3>Sample Output 3</h3>
<pre>
No
</pre>
<p>äŸãã°ã<code>C</code> ãéžãã§æäœãè¡ã£ãŠã <code>AABCC</code> â <code>AABCABC</code> ãšã¯ãªããªãããã¹ãŠã® <code>C</code> ããããã <code>ABC</code> ãžåæã«çœ®ãæããã®ã§ãå®é㯠<code>AABCC</code> â <code>AABABCABC</code> ãšãªãã</p> |
p00703 |
<h1>
What is the Number in my Mind ?
</h1>
<p>Let us enjoy a number guess game. </p>
<p>A number containing L digits is in my mind (where 4 <= L <= 10). You
should guess what number it is. It is composed of any of the following ten
digits:<br></p><pre> "0","1","2","3","4","5","6","7","8", and "9".
</pre>
<p></p>
<p>No digits appear twice in the number. For example, when L = 4, "1234" is a
legitimate candidate but "1123" is not (since "1" appears twice). </p>
<p>The number may begin with "0", and a number "05678" should be distinct from a
number "5678", for example. </p>
<p>If you and your computer cannot see through my mind by telepathy, a group of
<b>hints</b> will be needed in order for you to identify the number in my mind.
A <b>hint</b> is a triple of numbers named <b>try</b>, <b>hit</b>, and
<b>blow</b>. </p>
<p>The <b>try</b> is a number containing L decimal digits. No digits appear
twice in the <b>try</b>, and this number may also begin with "0". </p>
<p>The <b>hit</b> value indicates the count of digits that the <b>try</b> and
the number in my mind have in common, and that are exactly in the same position.
</p>
<p>The <b>blow</b> value indicates the count of digits that the <b>try</b> and
the number in my mind have in common, but that are NOT in the same position.
</p>
<p>They are arranged in one line as follows.<br></p><pre> <b>try hit blow</b>
</pre>
<p></p>
<p>For example, if L = 4 and the number in my mind is <b>9876</b>, then the
following is an example of hint-set consisting of legitimate hints.<br></p><pre> <b>7360 0 2</b>
<b>2507 0 1</b>
<b>9713 1 1</b>
<b>9678 2 2</b>
</pre>
<p>
The above hint-set should be sufficient for you to guess the number and
the answer should be <b>9876</b>.<br>
<p></p>
<p>In contrast, the following hint-set is not sufficient to guess the
number.<br></p><pre> <b>7360 0 2</b>
<b>9713 1 1</b>
<b>9678 2 2</b>
</pre>
<p>
No number is consistent with the following hint-set.<br><pre> <b>9678 2 2</b>
<b>1234 2 2</b>
</pre>
<p>
Answers for last two hint-sets should be <b>NO</b>.<br>
<p></p>
<p>Your job is to write a program identifying the numbers in my mind using given
hint-sets. </p>
<h2>Input</h2>
<p>The input consists of multiple hint-sets as follows. Each of them corresponds
to a number in my mind. </p><pre><i>< HINT-SET<sub></sub></i><sub>1<i></i></sub><i> ></i>
<i>< HINT-SET<sub></sub></i><sub>2<i></i></sub><i> ></i>
<i>. . .</i>
<i>< HINT-SET<sub>i</sub> ></i>
<i>. . .</i>
<i>< HINT-SET<sub>n</sub> ></i>
</pre>
<p>A <i><HINT-SET<sub>i</sub> ></i> is composed of one header line in the
following format (<i>L</i> and <i>H</i> should be separated by a single space
character.):<br></p><pre><i>L</i> <i>H</i>
</pre>
<p>
and <i>H</i> lines of hints in the following format (1 <= j <=
<i>H</i> ) :<br><pre><i>TRY</i><sub>1</sub> <i>HIT</i><sub>1</sub> <i>BLOW</i><sub>1</sub>
<i>TRY</i><sub>2</sub> <i>HIT</i><sub>2</sub> <i>BLOW</i><sub>2</sub>
<i>. . .</i>
<i>TRY<sub>j</sub></i> <i>HIT<sub>j</sub></i> <i>BLOW<sub>j</sub></i>
<i>. . .</i>
<i>TRY<sub>H</sub></i> <i>HIT<sub>H</sub></i> <i>BLOW<sub>H</sub></i>
</pre><p><i>L</i> indicates the number of digits of the number in my mind and
<i>TRY<sub>j</sub></i> . <i>HIT<sub>j</sub></i> and <i>BLOW<sub>j</sub></i>
indicate hit and blow values between the <i>TRY<sub>j</sub></i> and the number
in my mind. (They are separated by a single space character.)
<p>The end of the input is indicated by a header line with <i>L</i> = 0 and
<i>H</i> = 0.<br></p>
<h2>Output</h2>
<p>For each hint-set, the answer should be printed, each in a separate line. If
you can successfully identify the number for a given hint-set, the answer should
be the number. If you cannot identify the number, the answer should be
<b>NO</b>. </p>
<h2>Sample Input</h2>
<pre>
6 4
160348 0 4
913286 2 3
431289 3 1
671283 3 3
10 8
3827690415 2 8
0482691573 1 9
1924730586 3 7
1378490256 1 9
6297830541 1 9
4829531706 3 7
4621570983 1 9
9820147536 6 4
4 4
2713 0 3
1247 2 0
1230 1 1
1387 2 1
6 5
605743 0 4
593026 2 2
792456 1 2
143052 1 3
093614 3 3
5 2
12345 5 0
67890 0 5
0 0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
637281
7820914536
3287
NO
NO
</pre>
|
p03206 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In some other world, today is December <var>D</var>-th.</p>
<p>Write a program that prints <code>Christmas</code> if <var>D = 25</var>, <code>Christmas Eve</code> if <var>D = 24</var>, <code>Christmas Eve Eve</code> if <var>D = 23</var> and <code>Christmas Eve Eve Eve</code> if <var>D = 22</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>22 \leq D \leq 25</var></li>
<li><var>D</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>D</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the specified string (case-sensitive).</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>25
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Christmas
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>22
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Christmas Eve Eve Eve
</pre>
<p>Be sure to print spaces between the words.</p></section>
</div>
</span> |
p04039 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p>
<p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p>
<p>Find the amount of money that she will hand to the cashier.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ⊠N < 10000</var></li>
<li><var> 1 ⊠K < 10</var></li>
<li><var> 0 ⊠D_1 < D_2 < ⊠< D_KâŠ9</var></li>
<li><var>\{D_1,D_2,...,D_K\} â \{1,2,3,4,5,6,7,8,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>K</var>
<var>D_1</var> <var>D_2</var> ⊠<var>D_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000 8
1 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2000
</pre>
<p>She dislikes all digits except <var>0</var> and <var>2</var>.</p>
<p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9999
</pre></section>
</div>
</span> |
p03656 | <span class="lang-en">
<p>Score : <var>1700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are two rooted trees, each with <var>N</var> vertices.
The vertices of each tree are numbered <var>1</var> through <var>N</var>.
In the first tree, the parent of Vertex <var>i</var> is Vertex <var>A_i</var>.
Here, <var>A_i=-1</var> if Vertex <var>i</var> is the root of the first tree.
In the second tree, the parent of Vertex <var>i</var> is Vertex <var>B_i</var>.
Here, <var>B_i=-1</var> if Vertex <var>i</var> is the root of the second tree.</p>
<p>Snuke would like to construct an integer sequence of length <var>N</var>, <var>X_1</var> , <var>X_2</var> , <var>...</var> , <var>X_N</var>, that satisfies the following condition:</p>
<ul>
<li>For each vertex on each tree, let the indices of its descendants including itself be <var>a_1</var> , <var>a_2</var> , <var>...</var>, <var>a_k</var>. Then, <var>abs(X_{a_1} + X_{a_2} + ... + X_{a_k})=1</var> holds.</li>
</ul>
<p>Determine whether it is possible to construct such a sequence. If the answer is possible, find one such sequence.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq A_i \leq N</var>, if Vertex <var>i</var> is not the root in the first tree.</li>
<li><var>A_i = -1</var>, if Vertex <var>i</var> is the root in the first tree.</li>
<li><var>1 \leq B_i \leq N</var>, if Vertex <var>i</var> is not the root in the second tree.</li>
<li><var>B_i = -1</var>, if Vertex <var>i</var> is the root in the second tree.</li>
<li>Input corresponds to valid rooted trees.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> <var>..</var> <var>A_N</var>
<var>B_1</var> <var>B_2</var> <var>..</var> <var>B_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is not possible to construct an integer sequence that satisfies the condition, print <code>IMPOSSIBLE</code>.
If it is possible, print <code>POSSIBLE</code> in the first line.
Then, in the second line, print <var>X_1</var> , <var>X_2</var> , <var>...</var> , <var>X_N</var>, an integer sequence that satisfies the condition.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
3 3 4 -1 4
4 4 1 -1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>POSSIBLE
1 -1 -1 3 -1
</pre>
<p>For example, the indices of the descendants of Vertex <var>3</var> of the first tree including itself, is <var>3,1,2</var>.
It can be seen that the sample output holds <var>abs(X_3+X_1+X_2)=abs((-1)+(1)+(-1))=abs(-1)=1</var>.
Similarly, the condition is also satisfied for other vertices.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6
-1 5 1 5 1 3
6 5 5 3 -1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>IMPOSSIBLE
</pre>
<p>In this case, constructing a sequence that satisfies the condition is <code>IMPOSSIBLE</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8
2 7 1 2 2 1 -1 4
4 -1 4 7 4 4 2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>POSSIBLE
1 2 -1 0 -1 1 0 -1
</pre></section>
</div>
</span> |
p00979 | <h2>Fast Forwarding</h2>
<p>
Mr. Anderson frequently rents video tapes of his favorite classic films. Watching the films so many times, he has learned the precise start times of his favorite scenes in all such films. He now wants to find how to wind the tape to watch his favorite scene as quickly as possible on his video player.
</p>
<p>
When the <b><span>[play]</span></b> button is pressed, the film starts at the normal playback speed. The video player has two buttons to control the playback speed: The <b><span>[3x]</span></b> button triples the speed, while the <b><span>[1/3x]</span></b> button reduces the speed to one third. These speed control buttons, however, do not take effect on the instance they are pressed. Exactly one second after playback starts and every second thereafter, the states of these speed control buttons are checked. If the <b><span>[3x]</span></b> button is pressed on the timing of the check, the playback speed becomes three times the current speed. If the <b><span>[1/3x]</span></b> button is pressed, the playback speed becomes one third of the current speed, unless it is already the normal speed.
</p>
<p>
For instance, assume that his favorite scene starts at 19 seconds from the start of the film. When the <b><span>[3x]</span></b> button is on at one second and at two seconds after the playback starts, and the <b><span>[1/3x]</span></b> button is on at three seconds and at five seconds after the start, the desired scene can be watched in the normal speed five seconds after starting the playback, as depicted in the following chart.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCAsia2019_fast_forwarding" width="600"/>
</center>
<p>
Your task is to compute the shortest possible time period after the playback starts until the desired scene starts. The playback of the scene, of course, should be in the normal speed.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case of the following format.
</p>
<pre>
$t$
</pre>
<p>
The given single integer $t$ ($0 \leq t < 2^{50}$) is the start time of the target scene.
</p>
<h3>Output</h3>
<p>
Print an integer that is the minimum possible time in seconds before he can start watching the target scene in the normal speed.
</p>
<h3>Sample Input 1</h3>
<pre>
19
</pre>
<h3>Sample Output 1</h3>
<pre>
5
</pre>
<h3>Sample Input 2</h3>
<pre>
13
</pre>
<h3>Sample Output 2</h3>
<pre>
5
</pre>
<h3>Sample Input 3</h3>
<pre>
123456789098765
</pre>
<h3>Sample Output 3</h3>
<pre>
85
</pre>
<h3>Sample Input 4</h3>
<pre>
51
</pre>
<h3>Sample Output 4</h3>
<pre>
11
</pre>
<h3>Sample Input 5</h3>
<pre>
0
</pre>
<h3>Sample Output 5</h3>
<pre>
0
</pre>
<h3>Sample Input 6</h3>
<pre>
3
</pre>
<h3>Sample Output 6</h3>
<pre>
3
</pre>
<h3>Sample Input 7</h3>
<pre>
4
</pre>
<h3>Sample Output 7</h3>
<pre>
2
</pre>
|
p02944 | <span class="lang-en">
<p>Score : <var>1800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>For a sequence <var>S</var> of positive integers and positive integers <var>k</var> and <var>l</var>, <var>S</var> is said to belong to <em>level</em> <var>(k,l)</var> when one of the following conditions is satisfied:</p>
<ul>
<li>The length of <var>S</var> is <var>1</var>, and its only element is <var>k</var>.</li>
<li>There exist sequences <var>T_1,T_2,...,T_m</var> (<var>m \geq l</var>) belonging to level <var>(k-1,l)</var> such that the concatenation of <var>T_1,T_2,...,T_m</var> in this order coincides with <var>S</var>.</li>
</ul>
<p>Note that the second condition has no effect when <var>k=1</var>, that is, a sequence belongs to level <var>(1,l)</var> only if the first condition is satisfied.</p>
<p>Given are a sequence of positive integers <var>A_1,A_2,...,A_N</var> and a positive integer <var>L</var>.
Find the number of subsequences <var>A_i,A_{i+1},...,A_j</var> (<var>1 \leq i \leq j \leq N</var>) that satisfy the following condition:</p>
<ul>
<li>There exists a positive integer <var>K</var> such that the sequence <var>A_i,A_{i+1},...,A_j</var> belongs to level <var>(K,L)</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2 \times 10^5</var></li>
<li><var>2 \leq L \leq N</var></li>
<li><var>1 \leq 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>L</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 number of subsequences <var>A_i,A_{i+1},...,A_j</var> (<var>1 \leq i \leq j \leq N</var>) that satisfy the condition.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>9 3
2 1 1 1 1 1 1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>22
</pre>
<p>For example, both of the sequences <var>(1,1,1)</var> and <var>(2)</var> belong to level <var>(2,3)</var>, so the sequence <var>(2,1,1,1,1,1,1)</var> belong to level <var>(3,3)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9 2
2 1 1 1 1 1 1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>41
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>15 3
4 3 2 1 1 1 2 3 2 2 1 1 1 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>31
</pre></section>
</div>
</span> |
p01391 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<h1><font color="#000">åé¡ D </font> åã®æ§æ</h1>
<h2>å顿</h2>
<p><var>1</var> ãã <var>N</var> ãŸã§ã®çžç°ãªãæŽæ°ã <var>N / 2</var> åæžãããã«ãŒããããã€ãäžããããã®ã§ïŒæ¬¡ã®æ¡ä»¶ãæºãããããªé·ã <var>N</var> ã®æ°å <var>seq</var> ã <var>1</var> ã€äœã£ãŠåºåããŠæ¬²ããïŒ</p>
<ul>
<li><var>seq</var> ã®åèŠçŽ ã¯ <var>0</var> ã <var>1</var> ã§ããïŒ</li>
<li>ãã¹ãŠã®ã«ãŒãã«ã€ããŠä»¥äžãæãç«ã€ïŒ ã«ãŒãã«æžãããæ°åã<var>card[1], ..., card[N/2]</var>ãšããïŒãã®ãšãã«ãŒãã«æžãããéšåã®å: <var>seq[card[1]] + ... + seq[card[N/2]]</var> ã <var>N / 8</var> 以äžã〠<var>3N / 8</var> 以äžã«ãªã£ãŠããïŒ</li>
</ul>
<p></p>
<p>äŸãã°ïŒ<var>N = 8</var> ã§ã«ãŒãã <var>2</var> ææž¡ããïŒã«ãŒãã«æžãããŠããæ°åããããã <var>[1, 2, 7, 8]</var>ïŒ<var>[4, 5, 7, 8]</var> ã§ãã£ããšããïŒãã®ãšã <var>seq=[0, 1, 0, 1, 0, 1, 0, 1]</var> ã <var>seq=[0, 0, 0, 0, 1, 1, 1, 1]</var> ãšãããšæ¡ä»¶ãæºããããã«ã§ããŠããïŒ</p>
<h2>å
¥å圢åŒ</h2>
å
¥åã¯æ¬¡ã®åœ¢åŒã§äžããããïŒ
<pre><var>N</var> <var>K</var>
<var>card<sub>1</sub>[1]</var> <var>card<sub>1</sub>[2]</var> ... <var>card<sub>1</sub>[N/2]</var>
<var>card<sub>2</sub>[1]</var> <var>card<sub>2</sub>[2]</var> ... <var>card<sub>2</sub>[N/2]</var>
...
<var>card<sub>K</sub>[1]</var> <var>card<sub>K</sub>[2]</var> ... <var>card<sub>K</sub>[N/2]</var>
</pre>
<p>
<var>1</var> è¡ç®ã«ãã㊠<var>N</var> ã¯æ§æããã¹ãæ°åã®é·ãïŒ<var>K</var> ã¯ã«ãŒãã®ææ°ã§ããïŒ
ç¶ã <var>K</var> è¡ã«ã¯åã«ãŒãã®æ
å ±ãäžããããïŒ<var>card<sub>i</sub>[1], ..., card<sub>i</sub>[N/2]</var> ã <var>i</var> çªç®ã®ã«ãŒãã«æžãããŠããæ°åã§ããïŒ
</p>
<h2>åºå圢åŒ</h2>
<p><var>seq</var> ã® <var>i</var> çªç®ã®èŠçŽ ã <var>i</var> æåç®ã«å¯Ÿå¿ããããã«æ°å <var>seq</var> ã <var>1</var> è¡ã«åºåããïŒ</p>
<p>ãªãïŒã©ã®å
¥åã«å¯ŸããŠãè§£ã¯å¿
ãå°ãªããšã <var>1</var> ã€ã¯ååšããïŒ</p>
<h2>å¶çŽ</h2>
<ul>
<li><var>8 ≤ N ≤ 1,000</var>, <var>1≤ K ≤ N / 2</var></li>
<li><var>N</var> 㯠<var>8</var> ã®åæ°</li>
<li><var>1 ≤ card<sub>i</sub>[1] < card<sub>i</sub>[2] < ... < card<sub>i</sub>[N/2] ≤ N</var></li>
</ul>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
8 2
1 2 7 8
4 5 7 8
</pre>
<h3>åºåäŸ 1</h3>
<pre>
01010101
</pre>
<h3>å
¥åäŸ 2</h3>
<pre>
8 3
2 3 4 6
3 4 5 8
3 4 6 8
</pre>
<h3>åºåäŸ 2</h3>
<pre>
01110011
</pre>
|
p02417 |
<H1>Counting Characters</H1><br>
<p>
Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters.
</p>
<H2>Input</H2>
<p>
A sentence in English is given in several lines.
</p>
<H2>Output</H2>
<p>
Prints the number of alphabetical letters in the following format:
</p>
<pre>
a : <i>The number of 'a'</i>
b : <i>The number of 'b'</i>
c : <i>The number of 'c'</i>
.
.
z : <i>The number of 'z'</i>
</pre>
<h2>Constraints</h2>
<ul>
<li>The number of characters in the sentence < 1200</li>
</ul>
<H2>Sample Input</H2>
<pre>
This is a pen.
</pre>
<H2>Sample Output</H2>
<pre>
a : 1
b : 0
c : 0
d : 0
e : 1
f : 0
g : 0
h : 1
i : 2
j : 0
k : 0
l : 0
m : 0
n : 1
o : 0
p : 1
q : 0
r : 0
s : 2
t : 1
u : 0
v : 0
w : 0
x : 0
y : 0
z : 0
</pre>
|
p02047 | <h3>æååã®éæ³</h3>
<!-- begin ja only -->
<p>éæ³äœ¿ãã§ããããªãã¯ïŒä»æ¥ãéæ³ã®ä¿®è¡ã«å±ãã§ããïŒããªãã¯ä»ïŒæå
ã«è±å°æåãããªãæåå <i>X</i> ãæã£ãŠããïŒããªãã®ä»æ¥ã®ä¿®è¡ã®èª²é¡ã¯ïŒãã®æååãïŒå¥ã®æåå <i>Y</i> ã«å€åãããããšã§ããïŒ</p>
<p>ããªãã¯ïŒæååãå€åãããéæ³ã 4 çš®é¡ç¿åŸããŠããŠïŒãããã奜ããªé åºã§äœåã§ãå±ããããšãã§ããïŒãã ãïŒéæ³ãå±ãããã³ã«ïŒéæ³ç³ãšåŒã°ããç¹å¥ãªç³ãæ¶è²»ããïŒããªããç¿åŸããŠããéæ³ã¯æ¬¡ã®éãã§ããïŒ</p>
<ul>
<li>éæ³ç³ã <i>A</i> åæ¶è²»ããïŒæå
ã®æååã®å¥œããªäœçœ®ã«ïŒå¥œããªè±å°æå 1 æåã远å ããïŒäŸãã°ïŒå
ã®æååã bcbd ã§ãã£ãå ŽåïŒabcbd, bcebd, bcbdf ãªã©ã®æååã«å€åãããããšãã§ããïŒ</li>
<li>éæ³ç³ã <i>E</i> åæ¶è²»ããïŒæå
ã®æååã®å¥œã㪠1 æåãåãé€ãïŒäŸãã°ïŒå
ã®æååã bcbd ã§ãã£ãå ŽåïŒcbd, bbd, bcd, bcb ã®ããããã«å€åãããããšãã§ããïŒãªãïŒå
ã®æååã®é·ãã 0 ã§ããå ŽåïŒãã®éæ³ãå±ããããšã¯ã§ããªãïŒ</li>
<li>éæ³ç³ã <i>S</i> åæ¶è²»ããïŒæå
ã®æååã®å¥œã㪠1 æåãïŒå¥ã®å¥œããªè±å°æå 1 æåã«çœ®ãæããïŒäŸãã°ïŒå
ã®æååã bcbd ã§ãã£ãå ŽåïŒacbd ã bebd ãªã©ã®æååã«å€åãããããšãã§ããïŒãªãïŒå
ã®æååã®é·ãã 0 ã§ããå ŽåïŒãã®éæ³ãå±ããããšã¯ã§ããªãïŒ</li>
<li>éæ³ç³ã <i>R</i> åæ¶è²»ããïŒæå
ã®æååã®å
é ã® 1 æåãæ«å°Ÿã«ç§»åãããïŒäŸãã°ïŒå
ã®æååã bcbd ã§ãã£ãå ŽåïŒcbdb ã«å€åãããããšãã§ããïŒãªãïŒå
ã®æååã®é·ãã 0 ã§ããå ŽåïŒãã®éæ³ãå±ããããšã¯ã§ããªãïŒ</li>
</ul>
<p>éæ³ç³ã¯é«äŸ¡ãªã®ã§ïŒããªãã¯éæ³ç³ã®æ¶è²»ãæå°éã«ããããšèããŠããïŒæåå <i>X</i> ãæåå <i>Y</i> ã«å€åãããããã«å¿
èŠãªéæ³ç³ã®åæ°ã®æå°å€ãæ±ããïŒ</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§è¡šãããïŒ</p>
<blockquote><i>X</i>
<i>Y</i>
<i>A</i>
<i>E</i>
<i>S</i>
<i>R</i></blockquote>
<p><i>X</i>, <i>Y</i> ã¯è±å°æåã®ã¿ãããªãç°ãªãæååã§ããïŒããããé·ã㯠<i>1</i> ä»¥äž <i>100</i> 以äžã§ããïŒ<i>A</i>, <i>E</i>, <i>S</i>, <i>R</i> ã¯ãããã <i>1</i> ä»¥äž <i>10<sup>6</sup></i> 以äžã®æŽæ°ã§ããïŒ</p>
<p>å
¥åã®çµãã㯠'#' äžã€ã®ã¿ãããªãè¡ã§ç€ºãããïŒå
¥åã«å«ãŸããããŒã¿ã»ããã®æ°ã¯é«ã
50 ã§ããïŒ</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>åããŒã¿ã»ããã«ã€ããŠïŒæåå <i>X</i> ãæåå <i>Y</i> ã«å€åãããããã«å¿
èŠãªéæ³ç³ã®åæ°ã®æå°å€ãïŒ1 è¡ã«åºåããïŒ</p>
<!-- end ja only -->
<h3>Sample Input</h3><pre>typewriter
periodicity
100010
100100
101000
110000
periodicity
typewriter
100010
100100
101000
110000
periodicity
typewriter
100010
100100
101000
1
domestic
contest
100010
100100
101000
110000
#
</pre><h3>Output for the Sample Input</h3><pre>823120
1001540
603217
502210
</pre>
|
p00580 | <h1>åº§åž (Seats)ã</h1>
<!--ããæéå¶é : 5sec / ã¡ã¢ãªå¶é : 256MB -->
<h2> å顿</h2>
<p>
2XXX 幎ïŒäžçã®åœã¯çŽç·ç¶ã«äžŠãã§ããïŒ<var>N</var> åã®åœãããïŒ<var>1, 2, ..., N</var> ã®çªå·ãä»ããããŠããïŒ<var>i = 1, 2, ..., N - 1</var> ã«å¯ŸãïŒåœ <var>i</var> ãšåœ <var>i + 1</var> ãäºãã«é£åœã§ããïŒ
</p>
<p>
ãã®å¹Žã®åœéæ
å ±ãªãªã³ããã¯ã§ã¯ïŒåœ <var>i</var> ãã㯠<var>A_i</var> 人ã®éžæãåå ããïŒåœéæ
å ±ãªãªã³ããã¯ã®æè¡å§å¡ã®ããªãã¯ïŒç«¶æã§ã®åº§åžè¡šãäœæããæ
åœã§ããïŒç«¶æäŒå Žã现é·ãããïŒäžåã«äžŠãã <var>A_1 + A_2 + ... + A_N</var> åã®åº§åžã«éžæãã¡ãå²ãåœãŠãããšã«ãªã£ãïŒäžæ£é²æ¢ã®ããïŒåãåœã®éžæãé£åœã®éžæãé£ãåãåžã«å²ãåœãŠãŠã¯ãªããªãïŒ
</p>
<p>
éžæãã¡ã座åžã«å²ãåœãŠãæ¹æ³ã¯äœéãããã ãããïŒãã®æ°ã¯éåžžã«å€§ãããªãå¯èœæ§ãããã®ã§ïŒããã <var>10007</var> ã§å²ã£ãäœããæ±ãããïŒ
</p>
<h2>å¶çŽ</h2>
<ul>
<li><var>1 ⊠N ⊠100</var></li>
<li><var>1 ⊠A_i ⊠4</var> (<var>1 ⊠i ⊠N</var>)</li>
</ul>
<h2> å
¥åã»åºå</h2>
<p>
<b>å
¥å</b><br>
å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããïŒ<br>
<var>N</var><br>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
</p>
<p>
<b>åºå</b><br>
éžæãã¡ã座åžã«å²ãåœãŠãæ¹æ³ã®æ°ã <var>10007</var> ã§å²ã£ãäœãã <var>1</var> è¡ã§åºåããïŒ
</p>
<!--
<h2>å°èª²é¡</h2>
<p style="line-height: 200%; margin-left: 30px; margin-right: 30px;">
</p>
<p style="line-height: 200%; margin-left: 30px; margin-right: 30px;">
<ol style="line-height: 200%; margin-left: 30px; margin-right: 30px;">
<li>(<var>6</var> ç¹) <var>N ⊠5</var>ïŒ<var>A_i ⊠2</var> (<var>1 ⊠i ⊠N</var>)</li>
<li>(<var>14</var> ç¹) <var>N ⊠10</var>ïŒ<var>A_i ⊠3</var> (<var>1 ⊠i ⊠N</var>)</li>
<li>(<var>80</var> ç¹) 远å ã®å¶çŽã¯ãªãïŒ</li>
</ol>
</p>
-->
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
4
2 1 1 1
</pre>
<h3>åºåäŸ 1</h3>
<pre>
4
</pre>
<p>
åœ <var>1</var> ããåå ãã <var>2</var> 人ã®éžæã <var>1</var> ãš <var>1'</var>ïŒåœ <var>2</var> ããåå ãã <var>1</var> 人ã®éžæã <var>2</var>ïŒåœ <var>3</var> ããåå ãã <var>1</var> 人ã®éžæã <var>3</var>ïŒåœ <var>4</var> ããåå ãã <var>1</var> 人ã®éžæã <var>4</var> ã§è¡šãããšã«ãããšïŒéžæãã¡ã座åžã«å²ãåœãŠãæ¹æ³ãšããŠã¯ïŒä»¥äžã® <var>4</var> éãã®äžŠã¹æ¹ãèããããïŒ
</p>
<ul>
<li><var>1</var>, <var>3</var>, <var>1'</var>, <var>4</var>, <var>2</var></li>
<li><var>1'</var>, <var>3</var>, <var>1</var>, <var>4</var>, <var>2</var></li>
<li><var>2</var>, <var>4</var>, <var>1</var>, <var>3</var>, <var>1'</var></li>
<li><var>2</var>, <var>4</var>, <var>1'</var>, <var>3</var>, <var>1</var></li>
</ul>
<h3>å
¥åäŸ 2</h3>
<pre>
5
1 2 3 2 1
</pre>
<h3>åºåäŸ 2</h3>
<pre>
0
</pre>
<p>
ãã®å
¥åäŸã§ã¯ïŒæ¡ä»¶ãæºãã座åžè¡šã¯ååšããªãïŒ
</p>
<h3>å
¥åäŸ 3</h3>
<pre>
6
1 2 3 3 2 1
</pre>
<h3>åºåäŸ 2</h3>
<pre>
4754
</pre>
<p>
ãã®å
¥åäŸã§ã¯ïŒéžæãã¡ã座åžã«å²ãåœãŠãæ¹æ³ã¯ <var>24768</var> éãããããïŒããã <var>10007</var> ã§å²ã£ãäœãã§ãã <var>4754</var> ãåºåããïŒ
</p>
<br/>
<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/2018/2019-yo/index.html">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第 18 åæ¥æ¬æ
å ±ãªãªã³ãã㯠JOI 2018/2019 äºéžç«¶æèª²é¡ã</a>
</p>
</div>
|
p00095 |
<H1>ã¯ã«ãµã®é£ã倧äŒ</H1>
<p>
æ¡§åæ¹ã§ã¯ã«ãµã®é£ã倧äŒãè¡ãããŸãããäžçªå€ãã®ã¯ã«ãµã®ãç²åŸãã人ãåªåè
ã§ãã
</p>
<p>
åå è
çªå·ãšé£ã£ã广°ã®ãªã¹ããèªã¿èŸŒã¿ãåªåè
ã®çªå·ãšé£ã£ã广°ãåºåããããã°ã©ã ãäœæããŠãã ãããåªåè
ãè€æ°ããå Žåã¯ã<!--æåã®-->ãã®äžã§åå è
çªå·ãæãå°ããäžäººãåºåããŠãã ããã
</p>
<H2>å
¥å</H2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>n</var>
<var>a<sub>1</sub></var> <var>v<sub>1</sub></var>
<var>a<sub>2</sub></var> <var>v<sub>2</sub></var>
:
<var>a<sub>n</sub></var> <var>v<sub>n</sub></var>
</pre>
<p>
<var>n</var> (1 ≤ <var>n</var> ≤ 20) ã¯åå è
ã®æ°ã<var>a<sub>i</sub></var> ã¯åå è
çªå·ã衚ããåå è
çªå·ã¯ 1 ä»¥äž <var>n</var> 以äžã®ç°ãªãæŽæ°ã§ããã<var>v<sub>i</sub></var> ( 0 ≤ <var>v<sub>i</sub></var> ≤ 100) ã¯åå è
<var>a<sub>i</sub></var> ãç²åŸãã广°ã§ããã
</p>
<H2>åºå</H2>
<p>
åªåè
ã®åå è
çªå·ãšé£ã£ã广°ã空çœåºåãã§ïŒè¡ã«åºåããã
</p>
<H2>å
¥åäŸ</H2>
<pre>
6
1 14
2 25
3 42
4 11
5 40
6 37
</pre>
<H2>åºåäŸ</H2>
<pre>
3 42
</pre>
|
p02552 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is an integer <var>x</var> that is greater than or equal to <var>0</var>, and less than or equal to <var>1</var>.
Output <var>1</var> if <var>x</var> is equal to <var>0</var>, or <var>0</var> if <var>x</var> is equal to <var>1</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 \leq x \leq 1</var></li>
<li><var>x</var> is an integer</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>x</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>1</var> if <var>x</var> is equal to <var>0</var>, or <var>0</var> if <var>x</var> is equal to <var>1</var>.</p>
</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>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre></section>
</div>
</span> |
p02102 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<h1>Problem E: Tangled Cables</h1>
<h2>Problem</h2>
<p>ãšããäŒç€Ÿã®ãããã¯ãŒã¯äžã«ã¯$n$å°ã®ã³ã³ãã¥ãŒã¿ãšãããããã€ãªã$m$æ¬ã®éä¿¡ã±ãŒãã«ããããã³ã³ãã¥ãŒã¿ã¯$0$ãã$n - 1$ãŸã§ã®èå¥åã§åºå¥ãããéä¿¡ã±ãŒãã«ããŸã$0$ãã$m - 1$ãŸã§ã®èå¥åããã€ã</p>
<p>çŸåšãã®äŒç€Ÿã«ããä»»æã®ç°ãªã2å°ã®ã³ã³ãã¥ãŒã¿ã¯ãããã€ãã®éä¿¡ã±ãŒãã«ãä»ããŠçžäºã«éä¿¡ããããšãã§ããããéä¿¡çµè·¯ããã äžã€ã«å®ãŸããšã¯éããªãã</p>
<p>ãã®ãããã¯ãŒã¯ã«ã¯ãéä¿¡ã±ãŒãã«ãå€ãããŠçµ¡ãŸã£ãŠããŸããšããåé¡ããããããã§ããªãã¯ãä»»æã®éä¿¡ã«ã€ããŠéä¿¡çµè·¯ããã äžã€ã«ãªãããã«ããã€ãã®éä¿¡ã±ãŒãã«ãåãé€ãããšã«ããã</p>
<p>éä¿¡ã±ãŒãã«$i$ã¯ã³ã³ãã¥ãŒã¿$a_i$ãš$b_i$ãåæ¹åã«ã€ãªãããã®é·ãã¯$c_i$ã§ããããŸããããªããéä¿¡ã±ãŒãã«$i$ãåãé€ãéã«ãããåŽåã¯$d_i$ã§ããã</p>
<p>äœæ¥ãå§ããåã«ãããªãã¯åãé€ãéä¿¡ã±ãŒãã«ã®é·ãã®åã«å¯Ÿãããäœæ¥ãçµãããŸã§ã«ãããåŽåã®åã®æ¯ãããã£ããæããšããæå°ã®ãã£ããæãèŠç©ããããšã«ããã<br>
ãã ããäžã€ãåãé€ããªãå Žåã®ãã£ããæã¯$0$ã§ããã</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<p>
$n$ $m$<br/>
$a_1$ $b_1$ $c_1$ $d_1$<br/>
$a_2$ $b_2$ $c_2$ $d_2$<br/>
...<br/>
$a_m$ $b_m$ $c_m$ $d_m$<br/>
</p>
<p>å
¥åã¯ãã¹ãп޿°ã§äžããããã<br>
1è¡ç®ã«ã¯ã³ã³ãã¥ãŒã¿ã®æ°$n$ãšéä¿¡ã±ãŒãã«ã®æ°$m$ã空çœåºåãã§äžããããã<br>
2è¡ç®ä»¥éã®$m$è¡ã«ã¯ãéä¿¡ã±ãŒãã«ã®æ
å ±ã空çœåºåãã§äžããããã$i$çªç®ã®éä¿¡ã±ãŒãã«ã®æ
å ±ã¯ãéä¿¡ã±ãŒãã«$i$ã®æ
å ±ã衚ãã</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>$2 \leq n \leq 10^4$</li>
<li>$n-1 \leq m \leq min(\frac{n \times (n - 1)}{2}, 10^4)$</li>
<li>$0 \leq a_i, b_i \leq n - 1 (a_i â b_i)$</li>
<li>$1 \leq c_i \leq 10^6$</li>
<li>$0 \leq d_i \leq 10^6$</li>
</ul>
<h2>Output</h2>
<p>ãã£ããæã®æå°å€ã宿°ã§1è¡ã«åºåããããã ãã$10^{-5}$ãè¶
ãã誀差ãå«ãã§ã¯ãªããªãã</p>
<h2>Sample Input 1</h2>
<pre>
4 5
0 2 22 13
0 3 15 25
1 2 3 3
1 3 28 5
2 3 5 22
</pre>
<h2>Sample Output 1</h2>
<pre>
0.36000
</pre>
<p>éä¿¡ã±ãŒãã«$0$ãšéä¿¡ã±ãŒãã«$3$ãåãé€ããšããã£ããæã¯$(\frac{13 + 5}{22 + 28}) = 0.36$ãšãªããããããã£ããæã®æå°å€ãšãªãã</p>
<h2>Sample Input 2</h2>
<pre>
5 6
0 1 22 33
0 2 43 11
0 3 92 10
1 3 50 12
2 3 88 2
3 4 58 89
</pre>
<h2>Sample Output 2</h2>
<pre>
0.06667
</pre>
<h2>Sample Input 3</h2>
<pre>
2 1
0 1 1 1
</pre>
<h2>Sample Output 3</h2>
<pre>
0
</pre> |
p01684 |
<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>
<h3>Problem Statement</h3>
<p>Alice is a private teacher.
One of her job is to prepare the learning materials for her student.
Now, as part of the materials, she is drawing a Venn diagram between two sets $A$ and $B$.
</p>
<p>Venn diagram is a diagram which illustrates the relationships among one or more sets.
For example, a Venn diagram between two sets $A$ and $B$ is drawn as illustrated below.
The rectangle corresponds to the universal set $U$.
The two circles in the rectangle correspond to two sets $A$ and $B$, respectively.
The intersection of the two circles corresponds to the intersection of the two sets, i.e. $A \cap B$.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAG2013_venn_diagram" height="134" width="200" /><br/>
Fig: Venn diagram between two sets
</center>
<br/>
<p>Alice, the mathematics personified, came up with a special condition to make her Venn diagram more beautiful.
Her condition is that the area of each part of her Venn diagram is equal to the number of elements in its corresponding set.
In other words, one circle must have the area equal to $|A|$, the other circle must have the area equal to $|B|$, and their intersection must have the area equal to $|A \cap B|$. Here, $|X|$ denotes the number of elements in a set $X$.
</p>
<p>Alice already drew a rectangle, but has been having a trouble figuring out where to draw the rest, two circles, because she cannot even stand with a small error human would make.
As an old friend of Alice's, your task is to help her by writing a program to determine the centers and radii of two circles so that they satisfy the above condition.
</p>
<h3>Input</h3>
<p>The input is a sequence of datasets.
The number of datasets is not more than $300$.
</p>
<p>Each dataset is formatted as follows.
</p><blockquote>$U_W$ $U_H$ $|A|$ $|B|$ $|A \cap B|$</blockquote>
<p>The first two integers $U_W$ and $U_H$ ($1 \le U_W, U_H \le 100$) denote the width and height of the rectangle which corresponds to the universal set $U$, respectively.
The next three integers $|A|$, $|B|$ and $|A \cap B|$ ($1 \le |A|, |B| \le 10{,}000$ and $0 \le |A \cap B| \le \min\{|A|,|B|\}$) denote the numbers of elements of the set $A$, $B$ and $A \cap B$, respectively.
The input is terminated by five zeroes.
</p>
<p>You may assume that, even if $U_W$ and $U_H$ would vary within $\pm 0.01$, it would not change whether you can draw two circles under the Alice's condition.
</p>
<h3>Output</h3>
<p>For each dataset, output the centers and radii of the two circles that satisfy the Alice's condition as follows:
</p><blockquote>$X_A$ $Y_A$ $R_A$ $X_B$ $Y_B$ $R_B$</blockquote>
<p>$X_A$ and $Y_A$ are the coordinates of the center of the circle which corresponds to the set $A$.
$R_A$ is the radius of the circle which corresponds to the set $A$.
$X_B$, $Y_B$ and $R_B$ are the values for the set B.
These values must be separated by a space.
</p>
<p>If it is impossible to satisfy the condition, output:
</p><blockquote>impossible</blockquote>
<p>The area of each part must not have an absolute error greater than $0.0001$.
Also, the two circles must stay inside the rectangle with a margin of $0.0001$ for error, or more precisely, all of the following four conditions must be satisfied:
</p><ul><li><p> $X_A - R_A \ge -0.0001$
</p></li><li><p> $X_A + R_A \le U_W + 0.0001$
</p></li><li><p> $Y_A - R_A \ge -0.0001$
</p></li><li><p> $Y_A + R_A \le U_H + 0.0001$
</p></li></ul>
<p>The same conditions must hold for $X_B$, $Y_B$ and $R_B$.
</p>
<h3>Sample Input</h3>
<pre>10 5 1 1 0
10 5 2 2 1
10 10 70 70 20
0 0 0 0 0</pre>
<h3>Output for the Sample Input</h3>
<pre>1 1 0.564189584 3 1 0.564189584
1 1 0.797884561 1.644647246 1 0.797884561
impossible</pre> |
p00996 |
<h1>Problem G: Dice</h1>
<p>
ãµã€ã³ãïŒå
åŒã¯äžã€åã§ããäžå¿åäœãïŒã€ã§ã²ãšã€ãšãèšã£ãŠããããäžã€åã§ããããèŠåããã€ããªãã»ã©äŒŒãŠããããããªãµã€ã³ãïŒå
åŒã¯Aåã®ãæ°ã«å
¥ãã®ããã¡ãã ãAåã¯ãã€ãïŒã€ïŒã»ããã§ãµã€ã³ãã転ãããŠéãã§ããããã®ããã«Aåãæ¥œããéã¶ããã¡ãã ããå®ã¯å€§ããªç§å¯ããã£ãã圌ãã¯å®ã¯çããŠããŠã話ãããèªç±ã«åãããã§ããã®ã ãåã©ãéšå±ã¯ <i>r</i > à <i> c </i> ã®å€§ããã®ã°ãªããã§è¡šãããšãã§ãããšãŠã倧ãããã®ãæ£ä¹±ããŠããã
</p>
<p>
ãµã€ã³ãïŒå
åŒã¯å®€å
ãæ±è¥¿ååã®ïŒæ¹åãžé²è¡æ¹åã«åãã£ãŠè»¢ãããªããç§»åããããã®åœ¢ããã«æãç§»åãã§ããªãã®ããå°ãæ°ã®æ¯ã§ãããé²è¡æ¹åã«ãšãŠã倧ãããã®ãããå Žåããµã€ã³ãã¯é²è¡æ¹åã«é²ãããšãã§ããªãã
ãµã€ã³ãïŒå
åŒã¯ïŒã€ã§ïŒã»ããã§ãããããäžåºŠã«ã²ãšã€ã®ãµã€ã³ãããç§»åããããšãã§ããªãããŸãããµã€ã³ããã¡ã¯ãã®å Žã§å転ãããªã©ãšããåšçšãªèœåã¯æã£ãŠããªãã
</p>
<p>
圌ãã話ãããåãããããŠããäºå®ã¯äººéã«ã¯ç¥ãããŠã¯ãããªããšããã®ããããã¡ãã®ã«ãŒã«ãã§ããããã®ã«ãŒã«ãç Žã£ãããã¡ãã¯ãã®äžããæ¶æ»
ããŠããŸããAåãåºãããŠãããšãã«åããã話ãããããŠããããã¡ããã¡ã ããAåãåž°å®
ããŠåã©ãéšå±ã«å
¥ã£ãŠãããšãã«ããšã®äœçœ®ã«æ»ã£ãŠããªããã°ãªããªããAåãåž°å®
ããçŽåŸã¯ç·æ¥äºæ
ã§ãããAåãåã©ãéšå±ã«ãã©ãçãåã«ããããããã¡ãã¯å³åº§ã«ããšã®å Žæãžæ»ããªããã°ãªããªãã
Aåã¯åºãèŠäžããããã¡ã«ãªãããããµã€ã³ãã®å ŽæãšäžãåããŠããæ°åãæ£ãããã°ãç§»åããããšã«æ°ã¥ãããšã¯ãªãããŸãããµã€ã³ããã¡ã¯èŠåããã€ããªãã»ã©äŒŒãŠããã®ã§ãã©ã®åçŽå Žæã«ã©ã®ãµã€ã³ããåãã£ãŠãæ¯éã¯ãªãã
</p>
<p>
ãããªããæ¥ãAåã®ããã¡ãç®±ã®äžã§æãåªç§ãªããã°ã©ããŒã§ããããªãã«ãäžãããããµã€ã³ãã®äœçœ®æ
å ±ãšåçŽå Žæããæçäœæã§ãµã€ã³ãéãåçŽå Žæã«æ»ããããèšç®ããä»»åãäžããããã
ãµã€ã³ãïŒå
åŒã溺æããŠããAåã®æãããµã€ã³ãïŒå
åŒãæ¶ããŠããŸã£ãããAåã¯æ³£ããŠããŸãã®ã§ããšãŠãéèŠãªä»»åã§ããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®ãã©ãŒãããã§äžããããã
</p>
<pre>
<i>r</i> <i>c</i>
<i>grid<sub>1</sub></i>
.
.
.
<i>grid<sub>r</sub></i>
</pre>
<p>
<i>grid<sub>i</sub></i> ã¯é·ã <i>c </i> ã®æååã§ã1ãã6ãŸã§ã®æ°åã"."ãâxâãâoâãããªãã<br>
æ°åã¯åçŽå Žæãã€ãå°çæã®ãµã€ã³ãã®äžã®å€ã瀺ããŠããã<br>
â.âã¯æ®éã®åºã瀺ããŠããã<br>
âxâã¯ãšãŠãããããªãã®ã瀺ããŠããã<br>
âoâã¯ãµã€ã³ãã瀺ããŠããã<br>
</p>
<p>
å
¥åã¯ä»¥äžã®å¶çŽãæºãã<br>
1 ≤ r,c ≤ 20<br>
</p>
<p>
åæç¶æ
ã§ã®ãµã€ã³ãã®åãã¯ä»¥äžã®å³ã«åŸãã<br>
</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2012Day2_img_dice_Dice1" height="300" witdh="300">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2012Day2_img_dice_Dice2" height="300" witdh="300">
<h2>Output</h2>
<p>
ããããã®å
¥åã«å¯Ÿãããåãµã€ã³ãããã¹ãŠåçŽã§ãããŸã§ã®æçææ°ãæ±ããã
</p>
<h2>Sample Input 1</h2>
<pre>
3 3
4o.
4o.
4o.
</pre>
<h2>Sample Output 1</h2>
<pre>
ïŒ
</pre>
<p>
åãµã€ã³ãã西æ¹åã«ç§»åããã°ããã
</p>
<h2>Sample Input 2</h2>
<pre>
4 4
4o..
.o3.
.o..
.5..
</pre>
<h2>Sample Output2</h2>
<pre>
3
</pre>
<p>
1è¡ç®ã®ã«ãããµã€ã³ãã西æ¹å<br>
2è¡ç®ã®ã«ãããµã€ã³ããæ±æ¹å<br>
3è¡ç®ã®ã«ãããµã€ã³ããåæ¹åã«ç§»åããã°ããã<br>
</p>
<h2>Sample Input 3</h2>
<pre>
6 10
1xxxxxxxxx
o.......o.
xxxx.xxxx4
xoxx.xxxx.
x....3xx..
x..xxxxx..
</pre>
<h2>Sample Output 3</h2>
<pre>
34
</pre>
|
p03343 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer sequence <var>A</var> of length <var>N</var> and an integer <var>K</var>.
You will perform the following operation on this sequence <var>Q</var> times:</p>
<ul>
<li>Choose a contiguous subsequence of length <var>K</var>, then remove the smallest element among the <var>K</var> elements contained in the chosen subsequence (if there are multiple such elements, choose one of them as you like).</li>
</ul>
<p>Let <var>X</var> and <var>Y</var> be the values of the largest and smallest element removed in the <var>Q</var> operations. You would like <var>X-Y</var> to be as small as possible.
Find the smallest possible value of <var>X-Y</var> when the <var>Q</var> operations are performed optimally.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2000</var></li>
<li><var>1 \leq K \leq N</var></li>
<li><var>1 \leq Q \leq N-K+1</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var> <var>Q</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 smallest possible value of <var>X-Y</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 3 2
4 3 1 5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>In the first operation, whichever contiguous subsequence of length <var>3</var> we choose, the minimum element in it is <var>1</var>.
Thus, the first operation removes <var>A_3=1</var> and now we have <var>A=(4,3,5,2)</var>.
In the second operation, it is optimal to choose <var>(A_2,A_3,A_4)=(3,5,2)</var> as the contiguous subsequence of length <var>3</var> and remove <var>A_4=2</var>.
In this case, the largest element removed is <var>2</var>, and the smallest is <var>1</var>, so their difference is <var>2-1=1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 1 6
1 1 2 3 5 8 13 21 34 55
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>7
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>11 7 5
24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>451211184
</pre></section>
</div>
</span> |
p03713 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a bar of chocolate with a height of <var>H</var> blocks and a width of <var>W</var> blocks.
Snuke is dividing this bar into exactly three pieces.
He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle.</p>
<p>Snuke is trying to divide the bar as evenly as possible.
More specifically, he is trying to minimize <var>S_{max}</var> - <var>S_{min}</var>, where <var>S_{max}</var> is the area (the number of blocks contained) of the largest piece, and <var>S_{min}</var> is the area of the smallest piece.
Find the minimum possible value of <var>S_{max} - S_{min}</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 †H, W †10^5</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible value of <var>S_{max} - S_{min}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0
</pre>
<p>In the division below, <var>S_{max} - S_{min} = 5 - 5 = 0</var>.</p>
<div style="text-align: center;">
<img alt="2a9b2ef47b750c0b7ba3e865d4fb4203.png" src="https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png">
</img></div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
<p>In the division below, <var>S_{max} - S_{min} = 8 - 6 = 2</var>.</p>
<div style="text-align: center;">
<img alt="a42aae7aaaadc4640ac5cdf88684d913.png" src="https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png">
</img></div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
</pre>
<p>In the division below, <var>S_{max} - S_{min} = 10 - 6 = 4</var>.</p>
<div style="text-align: center;">
<img alt="eb0ad0cb3185b7ae418e21c472ff7f26.png" src="https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png"/>
</div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>100000 100000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>50000
</pre></section>
</div>
</span> |
p02801 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is a lowercase English letter <var>C</var> that is not <code>z</code>. Print the letter that follows <var>C</var> in alphabetical order.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>C</var> is a lowercase English letter that is not <code>z</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>C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the letter that follows <var>C</var> in alphabetical order.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>a
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>b
</pre>
<p><code>a</code> is followed by <code>b</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>y
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>z
</pre>
<p><code>y</code> is followed by <code>z</code>.</p></section>
</div>
</span> |
p01000 |
<h1>Problem B: Independent Research</h1>
<h2>Problem</h2>
<!--
<p>
é·æäŒæã®èª²é¡ãšã¯ãé·æäŒæã䜿ã£ãŠãããŸã§ã®å匷ã®åŸ©ç¿ãããã<del>ããšã建ãŠåã«ãèšç»åããããã«ããŠçºçããããçåŸã«äœéšããã</del>ãããé·æäŒæã«èª²ããã詊緎ã®ããšã§ããã
ãã®äžã§ããèªç±ç ç©¶ãšã¯ãé·æäŒæã®èª²é¡ã®äžã§ãæãéé
·ãªèª²é¡ã§ããã
ãèªç±ç ç©¶ããšèšãåã«åããŠåŒ·å¶ã§ããå Žåãå€ããç ç©¶ããªããšããéžæè¢ã¯ååšããªãã
çµµãå·¥äœãçãç©èгå¯ãªã©ãæ§ã
ãªåéã®èª²é¡ãããããšããããåã¯ãçãç©èгå¯ãèªç±ç ç©¶ã®ããŒããšããã
</p>
-->
<p>
åã¯å€äŒã¿ã®èªç±ç ç©¶ã®ããŒããšããŠãçãç©èгå¯ãéžæããçãç©èгå¯ãããã賌å
¥ããã
</p>
<p>
ãã®çãç©ã¯3次å
ã°ãªããç¶ã®ç©ºéã奜ãã§çæ¯ããã
åã»ã«ã«ã¯æå€§1å¹ãŸã§ããå
¥ããªãã
åšå²ã®ç°å¢ã«åãã1æ¥ãçµéããããšã«èªçãšæ»æ»
ãç¹°ãè¿ãã
<!--èªçãšæ»æ»
ã®æ¡ä»¶ã¯é£Œè²ç®±ã«ãã£ãŠç°ãªããããããããã¯ã»ã«ã«é£æ¥ããçãç©ã®æ°ã«äŸåããã-->
èªçãšæ»æ»
ã®æ¡ä»¶ã¯ãã»ã«ã«é£æ¥ããçãç©ã®æ°ã«äŸåããã
ããã§ãããã»ã«ã«çãç©ã飿¥ãããšã¯ãããã»ã«ãšçãç©ãçæ¯ããŠããããäžã€ã®ã»ã«ãé¢ã蟺ããŸãã¯ç¹ãå
±æããŠããããšãèšãã
èªçãšæ»æ»
ã®ã«ãŒã«ã¯æ¬¡ã®ããã«ãªãã
</p>
<ul>
<li>
çãç©ãçæ¯ããŠããªãã»ã«ã«ãããŠã飿¥ããçãç©ã®æ°ã
<var> a<sub>i</sub> </var>(1 ≤<var> i </var>≤<var> M<sub>1</sub> </var>) å¹ã§ãããããª
<var> i </var>ãããå Žåããã®ã»ã«ã«çãç©ãèªçããã
</li>
<li>
çãç©ãçæ¯ããŠããã»ã«ã«ãããŠã飿¥ããçãç©ã®æ°ã
<var> b<sub>j</sub> </var>(1 ≤<var> j </var>≤<var> M<sub>2</sub> </var>) å¹ã§ãããããª
<var> j </var>ããªãå Žåããã®ã»ã«ã®çãç©ã¯æ»æ»
ããã
</li>
</ul>
<p>
ä»å賌å
¥ãã飌è²ç®±ã¯ã»ã«ã®æ°ã5*5*5ã§ããç«æ¹äœã®é£Œè²ç®±ã ã
ãã®é£Œè²ç®±ã§ã¯ãã®çãç©ã¯ã©ã®ãããªæ¯ãèããããã®ã ãããâŠïŒããšãŠã楜ãã¿ã§ããã
</p>
<p>
ãæ°æ¥åŸã
</p>
<p>
ãšããããã飌è²ããŠã¿ããâŠã
æ¯æ¥èгå¯ãããªããŠæéããããããåã«ã¯ããã©ããããŠããæ°ããããªãã
ããã ãã³ã³ãã¥ãŒã¿ãŒãšããã°ã©ã ã䜿ã£ãŠã·ãã¥ã¬ãŒããããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãã
åããŒã¿ã»ããã¯ä»¥äžã®ãã©ãŒãããã§äžããããã
</p>
<pre>
<var>N</var>
(<var>z</var> = 0 ã®é£Œè²ç®±ã®ç¶æ
)
(空è¡)
(<var>z</var> = 1 ã®é£Œè²ç®±ã®ç¶æ
)
(空è¡)
(<var>z</var> = 2 ã®é£Œè²ç®±ã®ç¶æ
)
(空è¡)
(<var>z</var> = 3 ã®é£Œè²ç®±ã®ç¶æ
)
(空è¡)
(<var>z</var> = 4 ã®é£Œè²ç®±ã®ç¶æ
)
(空è¡)
<var>M<sub>1</sub></var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> âŠã<var>a<sub>M<sub>1</sub></sub></var>
<var>M<sub>2</sub></var> <var>b<sub>1</sub></var> <var>b<sub>2</sub></var> âŠã<var>b<sub>M<sub>2</sub></sub></var>
</pre>
<p>
æåã«ã·ãã¥ã¬ãŒãããæ¥æ°<var> N </var>ãäžããããã</br>
</br>
次ã«é£Œè²ç®±ã®åæç¶æ
ã®æ
å ±ãäžãããããããã¯5ã€ã®5*5ã®2次å
ã°ãªããã§äžããããã</br>
å2次å
ã°ãªããã¯0ãš1ããæãç«ã¡ã1ã¯çãç©ãããããšã瀺ãã0ã¯äœãããªãããšã瀺ãã</br>
äŸãã°ã<var> z </var> = 0ã®ã»ã«ã®ç¶æ
ã®2次å
ã°ãªããã®4è¡2åç®ã®å€ã1ã ã£ãå Žåã飌è²ç®±ã®åº§æš(1, 3, 0)ã®äœçœ®ã«çãç©ãããããšã衚ãã<br>
</br>
次ã«ãæŽæ°<var> M<sub>1</sub> </var>ãäžãããããã®ããšã«<var> M<sub>1</sub> </var>åã®æ°å<var> a<sub>i</sub> </var>ãäžããããã<br>
次ã«ãæŽæ°<var> M<sub>2</sub> </var>ãäžãããããã®ããšã«<var> M<sub>2</sub> </var>åã®æ°å<var> b<sub>j</sub> </var>ãäžããããã<br>
<br>
å
¥åã®çµããã¯<var> N </var>= 0ã§è¡šãããã</br>
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>1 ≤<var> N </var> ≤ 100</li>
<!--
<li>1 ≤<var> x,y,z </var> ≤ 5</li>
<li>0 ≤<var> grid(x,y,z) </var> ≤ 1</li>
-->
<li>0 ≤<var> M<sub>1</sub> </var>,<var> M<sub>2</sub> </var> ≤ 27</li>
<li>0 ≤<var> a<sub>i</sub> </var>,<var> b<sub>j</sub> </var> ≤ 26
(1 ≤<var> i </var>≤<var> M<sub>1</sub> </var>, 1 ≤<var> j </var>≤<var> M<sub>2</sub> </var>)</li>
<li>ä»»æã®<var> i </var>,<var> j </var>(1 ≤<var> i </var><<var> j </var>≤<var> M<sub>1</sub> </var>)
ã«ãããŠã<var> a<sub>i</sub> </var>≠<var> a<sub>j</sub> </var></li>
<li>ä»»æã®<var> i </var>,<var> j </var>(1 ≤<var> i </var><<var> j </var>≤<var> M<sub>2</sub> </var>)
ã«ãããŠã<var> b<sub>i</sub> </var>≠<var> b<sub>j</sub> </var></li>
</ul>
<h2>Output</h2>
<p>
åããŒã¿ã»ããã«å¯Ÿãã<var> N </var>æ¥çµéåŸã®ç¶æ
ãåºåããã<br>
åºåã¯ä»¥äžã®ãã©ãŒãããã«åŸãã
</p>
<pre>
Case (ãã¹ãã±ãŒã¹ã®çªå·):
(<var>z</var> = 0 ã®é£Œè²ç®±ã®ç¶æ
)
(空è¡)
(<var>z</var> = 1 ã®é£Œè²ç®±ã®ç¶æ
)
(空è¡)
(<var>z</var> = 2 ã®é£Œè²ç®±ã®ç¶æ
)
(空è¡)
(<var>z</var> = 3 ã®é£Œè²ç®±ã®ç¶æ
)
(空è¡)
(<var>z</var> = 4 ã®é£Œè²ç®±ã®ç¶æ
)
</pre>
<p>
1è¡ç®ã«ãã¹ãã±ãŒã¹çªå·ãåºåããæ¬¡ã®è¡ãã<var> N </var>æ¥çµéåŸã®ç¶æ
ãšããŠã5*5ã®2次å
ã°ãªããã5ã€åºåããã</br>
åãã¹ãã±ãŒã¹ã®åºåéã«ã¯ç©ºè¡ãåºåããªããã</br>
</p>
<h2>Sample Input</h2>
<pre>
5
00000
01010
00000
00100
00000
00000
01010
00000
01010
00000
00000
00100
00000
01010
00000
00000
01010
00000
00100
00000
00000
00000
00100
00000
00000
1 2
2 3 4
4
01110
00100
00100
00100
01110
01110
10001
10000
10001
01110
11111
10001
11111
10000
10000
01110
10001
10000
10001
01110
00000
00000
00000
00000
00000
2 3 4
1 2
100
00100
01010
01110
10001
10001
01110
00100
00100
00100
01110
00000
00000
00000
00000
00000
11111
00010
00100
01000
11111
10001
10001
10001
10001
01110
5 1 3 5 7 9
5 0 2 4 6 8
0
</pre>
<h2>Sample Output</h2>
<pre>
Case 1:
00000
00000
01010
01110
10101
00000
10001
00000
00000
00000
00000
00000
11111
10001
00000
00000
00000
00000
00000
01010
00000
00000
01110
00100
11111
Case 2:
00010
10110
00000
11000
10000
00001
00000
10101
00010
00100
10001
00000
00000
00000
00010
01110
10001
00000
00001
10000
00000
00000
00111
01001
01000
Case 3:
00000
00000
00000
00000
00000
00000
00000
00000
00000
00000
00000
00000
00000
00000
00000
00000
00000
00000
00000
00000
00000
00000
00000
00000
00000
</pre> |
p01450 |
<H1>Problem D: åã®åéã¯å°ãã</H1>
<p>
åã«ã¯ãããããã®åéããããã©ã®åéãããšãŠãå°ããã<br>
åã¯ãããåéãšäžç·ã«åºããããäœäººãã®åéããªã¥ãã¯ã«å
¥ããŠãäžç·ã«åºãããã<br>
åã¯æ¯æããã®æ¥äžç·ã«åºãããåéãæ±ºããã空ã®ãªã¥ãã¯ã«ãïŒäººãã€åéãå
¥ããŠããã<br>
åã¯ãããŸãåã匷ããªããã ãããåæã«éã¹ãåéã®éãã«ã¯éçãããã<br>
åã¯ãéãã®éçãè¶
ããªãããã«åéãå
¥ããŠãããã©ã®é çªã§å
¥ããŠãããã¯æ°å次第ã<br>
åã¯ãå
¥ããããåéããŸã æ®ã£ãŠããéããå
¥ããã®ãæ¢ããªããæ±ºããŠæ¢ããªãã<br>
</p>
<p>
âŠâŠãšããã§ããªã¥ãã¯ã«å
¥ã£ãåéã®çµã¿åããã¯ãå
šéšã§äœãã¿ãŒã³ãããã ããïŒ
</p>
<H2>Input</H2>
<p>
<i>N W</i><br>
<i>w</i><sub>1</sub><br>
<i>w</i><sub>2</sub><br>
.<br>
.<br>
.<br>
<i>w<sub>n</sub></i><br>
</p>
<p>
å
¥åã®ïŒè¡ç®ã«ã¯ãæŽæ°<i>N</i>ïŒ1 ≤ <i>N</i> ≤ 200ïŒãšæŽæ°<i>W</i>ïŒ1 ≤ <i>W</i> ≤ 10,000ïŒãããã®é ã«ç©ºçœåºåãã§æžãããŠãããæŽæ°<i>N</i> ã¯åéã®æ°ããæŽæ°<i>W</i> ã¯åæã«éã¹ãéãã®éçããããããéãã®åèšã<i>W</i> ãã倧ãããšéã¶ããšã¯ã§ããªãã
</p>
<p>
ç¶ã<i>N</i> è¡ã«ã¯ãåéã®éããããããæŽæ°ãæžãããŠãããæŽæ°<i>w<sub>i</sub></i>ïŒ1 ≤ <i>w<sub>i</sub></i> ≤ 10,000ïŒãã<i>i</i> çªç®ã®åéã®éããããããã
</p>
<H2>Output</H2>
<p>
æçµçã«ãªã¥ãã¯ã«å
¥ã£ãŠããåéã®çµã¿åããã¯äœéãèãããããããã®ç·æ°ã1,000,000,007
ã§å²ã£ãäœããåºåããããªã1,000,000,007 ã¯çŽ æ°ã§ããã
</p>
<p>
ã誰ããªã¥ãã¯ã«å
¥ã£ãŠããªãããïŒéããšããŠæ°ããããšã«æ³šæããã
</p>
<h2>Sample Input 1</h2>
<pre>
4 8
1
2
7
9
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<h2>Sample Input 2</h2>
<pre>
4 25
20
15
20
15
</pre>
<h2>Sample Output 2</h2>
<pre>
4
</pre>
<h2>Sample Input 3</h2>
<pre>
6 37
5
9
13
18
26
33
</pre>
<h2>Sample Output 3</h2>
<pre>
6
</pre> |
p03197 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is an apple tree that bears apples of <var>N</var> colors. The <var>N</var> colors of these apples are numbered <var>1</var> to <var>N</var>, and there are <var>a_i</var> apples of Color <var>i</var>.</p>
<p>You and Lunlun the dachshund alternately perform the following operation (starting from you):</p>
<ul>
<li>Choose one or more apples from the tree and eat them. Here, the apples chosen at the same time must all have different colors.</li>
</ul>
<p>The one who eats the last apple from the tree will be declared winner. If both you and Lunlun play optimally, which will win?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq a_i \leq 10^9</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var>
<var>a_2</var>
<var>:</var>
<var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If you will win, print <code>first</code>; if Lunlun will win, print <code>second</code>.</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>first
</pre>
<p>Let Color <var>1</var> be red, and Color <var>2</var> be blue. In this case, the tree bears one red apple and two blue apples.</p>
<p>You should eat the red apple in your first turn. Lunlun is then forced to eat one of the blue apples, and you can win by eating the other in your next turn.</p>
<p>Note that you are also allowed to eat two apples in your first turn, one red and one blue (not a winning move, though).</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
100000
30000
20000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>second
</pre></section>
</div>
</span> |
p01903 |
<link rel="stylesheet" href="css/description.css" type="text/css" />
<script language="JavaScript" type="text/javascript" src="js/varmath.js" charset="UTF-8"></script>
<h2>F: 颚åããªãŒããŒãã㌠- Overflow of Furo -</h2>
<h3>ç©èª</h3>
<p>
æž©æ³å®¿ã»ããã¯èªæ
¢ã®æž©æ³ã«å
šãŠã®æ
ç±ã泚ãã§ããã颚åã®ãããã§ãã·ã§ãã«ãéããŠããã
颚åã®ãããã¡ã¯äž»ã«æž©æ³ã®é
管ã管çããŠãããè€æ°ã®æºæ³ãã1ã€ã®å€§æµŽå Žãžãšç¹ãããè€éã«å
¥ãçµãã é
管網ã管çã»èª¿æŽããŠããã
</p>
<p>
é
管網ã®ç®¡çã»èª¿æŽæ¥åããªããªãã«å€§å€ãªã®ã ãã颚åã®ãããã¡ã¯ãã®åéãçž«ã£ãŠãããã«å€ãã®æ¹¯ã济槜ãžãšäŸçµŠã§ããããæ¥ã
åªåãç©ã¿éããŠããã
çµæã颚åã®ãããã¡ã¯ã1æ¬ã ãé
管ããªãŒããŒãããŒãããããšãã§ããããšããèæãç¿åŸããã
ããªãã¡ãèªç±ã«é
管1æ¬ãéžã³ããã®é
ç®¡ã®æ¹¯éã®å¶éããªããããšãã§ããããã«ãªã£ãã®ã ã
</p>
<p>ä»ãŸã§æå€§æ¹¯éãå®çŸããé
管網ã®èšå®ãããªãã®ããã°ã©ã ã«äŸåããŠãã颚åã®ãããã¡ã¯ããã®æè¡ã䜿ã£ãŠããã«æµŽæ§œãžã®äŸçµŠæ¹¯éãå¢ããã«ã¯ã©ãããã°ããããããªãã«åã³ããã°ã©ã ãæžãããäŸé ŒããŠããã</p>
<h3>åé¡</h3>
<p>
<var>1</var>ã€ã®æµŽæ§œã<var>K</var>åã®æºæ³ã<var>N</var>åã®çµåç¹ãå«ãé
管網ãããã
é
管網ã¯<var>M</var>æ¬ã®é
管ãããªããé
管1ã€1ã€ã¯æµãããšã®ã§ããæ¹¯éã®å¶éãæã€ã
é
管ããããã¯æ¹¯ãæµãæ¹åãæ±ºããããŠããªãã®ã§ãèªç±ã«æ±ºããŠäœ¿ã£ãŠããã
<var>N</var>åã®çµåç¹ã§ã¯äœæ¬ãã®é
管ããæµããŠããæ¹¯ããã以å€ã®äœæ¬ãã®é
管ãžãšèªç±ãªé
åã§æµãããšãã§ããã
ãã¹ãŠã®æºæ³ãããã³æµŽæ§œã¯äžéšã®é
管ã®ç«¯ç¹ã«ãªã£ãŠãããæºæ³ããã®æ¹¯éãããã³çµåç¹ã§ã®æ¹¯éã調æŽããããšã§æºæ³ããæµŽæ§œãžã𿹝ãäŸçµŠããŠããã
</p>
<p>
<var>M</var>åã®é
管ã®ãã¡1æ¬ã ããªãŒããŒãããŒããããããªãã¡æµããæ¹¯éãç¡éã«å¢ããããšã§æµŽæ§œã«äŸçµŠã§ããããã«ãªãæå€§æ¹¯éã¯ããããã
ãã ããæå€§äŸçµŠæ¹¯éãç¡éã«å¢ããããšãã§ããå Žåãèãããããããã®å Žåã¯é¢šåããªãŒããŒãããŒããŠããŸãã®ã§ã"overfuro"ãšåºåããããšã
</p>
<h3>å
¥å圢åŒ</h3>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
<var>K</var> <var>N</var> <var>M</var>
<var>a_1</var> <var>b_1</var> <var>c_1</var>
...
<var>a_M</var> <var>b_M</var> <var>c_M</var>
</pre>
<p>
å
¥åã¯å
šãп޿°ãããªãã
æåã®è¡ã§ã¯æºæ³ã®æ°<var>K</var>ãçµåç¹ã®æ°<var>N</var>ãé
ç®¡ã®æ°<var>M</var>ãäžããããã
ç¶ã<var>M</var>è¡ã®ãã¡<var>i</var>è¡ç®ã«ã¯ã<var>i</var>çªç®ã®é
ç®¡ã®æ
å ±ã衚ã3ã€ã®æŽæ° <var>a_i</var>, <var>b_i</var>, <var>c_i</var> ãäžããããã
ããã¯<var>i</var>çªç®ã®é
管ã®äž¡ç«¯ç¹ããããã<var>a_i</var>ãš<var>b_i</var>ã§ãããæ¹¯éã®å¶éã<var>c_i</var>ã§ããããšã瀺ãã
ããã§ãé
管ã®ç«¯ç¹ <var>x</var> ã<var>0</var>ã®ãšãã¯å€§æµŽå Žã<var>1</var>ãã<var>K</var>ãŸã§ã®ãšã㯠<var>x</var> çªç®ã®æºæ³ã<var>K+1</var>ãã<var>K+N</var>ãŸã§ã®ãšã㯠<var>x − K</var> çªç®ã®çµåç¹ã§ããããšã衚ãã
</p>
<h3>å¶çŽ</h3>
<ul>
<li><var>1 ≤ K</var></li>
<li><var>0 ≤ N</var></li>
<li><var>N+K ≤ 100</var></li>
<li><var>1 ≤ M ≤ (N+K+1)(N+K)</var>/<var>2</var></li>
<li><var>0 ≤ a_i, b_i ≤ K+N</var></li>
<li><var>a_i ≠ b_i</var></li>
<li><var>1 ≤ c_i ≤ 5{,}000</var></li>
<li>åã2端ç¹ãæã€é
管ã¯2ã€ä»¥äžååšããªãããšãä¿èšŒãããã</li>
<li>äžããããé
管網ã¯ãé
管ããªãŒããŒãããŒãããããšãªãæäœ1以äžã®æ¹¯ãæºæ³ããæµŽæ§œã«äŸçµŠã§ããããšãä¿èšŒãããã</li>
</ul>
<h3>åºå圢åŒ</h3>
<p>
1æ¬ã ãé
管ããªãŒããŒãããŒãããŠæºæ³ããæµŽæ§œãžã®äŸçµŠæ¹¯éãæå€§åãããšãã®æå€§äŸçµŠæ¹¯éã1è¡ã«åºåããã
ãã ããæå€§æ¹¯éãç¡éã«å¢ããããšãã¯ã"overfuro"ãš1è¡ã«åºåããã
</p>
<h3>å
¥åäŸ1</h3>
<pre>
2 2 4
1 3 4
2 4 2
0 3 3
4 0 5
</pre>
<h3>åºåäŸ1</h3>
<pre>8</pre>
<h3>å
¥åäŸ2</h3>
<pre>
2 3 7
1 0 8
2 0 9
3 0 3
0 4 5
5 0 2
1 3 2
2 4 9
</pre>
<h3>åºåäŸ2</h3>
<pre>overfuro</pre>
<h3>å
¥åäŸ3</h3>
<pre>
1 1 2
0 2 1
1 2 1
</pre>
<h3>åºåäŸ3</h3>
<pre>1</pre>
<h3>å
¥åäŸ4</h3>
<pre>
5 0 5
0 1 1
0 2 1
0 3 1
0 4 1
0 5 1
</pre>
<h3>åºåäŸ4</h3>
<pre>overfuro</pre> |
p00611 |
<H1><font color="#000000">Problem G:</font> Building Water Ways</H1>
<p>
In ancient times, Romans constructed numerous water ways to supply water to cities and industrial sites. These water ways were amongst the greatest engineering feats of the ancient world.
</p>
<p>
These water ways contributed to social infrastructures which improved people's quality of life. On the other hand, problems related to the water control and the water facilities are still interesting as a lot of games of water ways construction have been developed.
</p>
<p>
Your task is to write a program which reads a map and computes the minimum possible cost of constructing water ways from sources to all the cities.
</p>
<br><br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_waterWay">
</center>
<br><br>
<p>
As shown in Figure 1, the map is represented by <i>H</i> × <i>W</i> grid cells, where each cell represents source, city, flatland, or obstacle.
</p>
<p>
You can construct only one water way from a source, but there are no limitations on the length of that water way and it can provide water to any number of cities located on its path. You can not construct water ways on the obstacles.
</p>
<p>
Your objective is to bring water to all the city and minimize the number of cells which represent water ways. In the Figure 1, water ways are constructed in 14 cells which is the minimum cost.
</p>
<p>
The water ways must satisfy the following conditions:
</p>
<ul>
<li>a water way cell is adjacent to at most 2 water way cells in four cardinal points.</li>
<li>a source cell is adjacent to at most 1 water way cell in four cardinal points.</li>
<li>there is no path from a source to other sources through water ways.</li>
</ul>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset consists of:
</p>
<pre>
<i>H W</i>
<i>H</i> × <i>W</i> characters
</pre>
<p>
The integers <i>H</i> and <i>W</i> are the numbers of rows and columns of the map. <i>H</i> × <i>W</i> characters denote the cells which contain:
</p>
<ul>
<li>'<span>P</span>': source</li>
<li>'<span>*</span>': city</li>
<li>'<span>.</span>': flatland</li>
<li>'<span>#</span>': obstacle</li>
</ul>
<p>
The end of input is indicated by a line containing two zeros separated by a space.
</p>
<H2>Output</H2>
<p>
For each dataset, print the minimum cost to construct the water ways.
</p>
<H2>Constraints</H2>
<ul>
<li>Judge data contains at most 60 data sets.</li>
<li>3 ≤ <i>H</i>, <i>W</i> ≤ 10</li>
<li>1 ≤ the number of sources, the number of cities ≤ 8</li>
<li>The map is surrounded by obstacles.</li>
<li>Sources are not adjacent each other(on the left, right, top and bottom)</li>
<li>There is a solution.</li>
</ul>
<H2>Sample Input</H2>
<pre>
3 8
########
#P....*#
########
10 10
##########
#P.......#
#..#*....#
#..#*.#.*#
#.....#*.#
#*.......#
#..##....#
#...#.P..#
#P......P#
##########
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
5
14
</pre>
|
p00241 |
<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>åå
æ°ã®ããç®</H1>
<p>
è€çŽ æ°ãæ¡åŒµãããã®ã«åå
æ°ãšåŒã°ãããã®ããããŸããç©äœã®å転ãªã©ã衚çŸããã®ã«äŸ¿å©ãªã®ã§ãããããã®è
ã®å¶åŸ¡ãªã©ã«äœ¿ãã䟿å©ãªæ°ã§ããåå
æ°ã¯ãïŒã€ã®å®æ° $x$ã$y$ã$z$ã$w$ ãšç¹å¥ãªæ°ïŒèæ°ãæ¡åŒµãããã®ïŒ$i$ã$j$ã$k$ ãçšããŠã$x + yi + zj + wk$ ãšè¡šãããŸãããã®ãããªåå
æ°ã®åã¯æ¬¡ã®ããã«å®çŸ©ãããŸãã<br>
<br>
$(x_1 + y_1 i + z_1 j + w_1 k) + (x_2 + y_2 i + z_2 j + w_2 k) = (x_1 + x_2) + (y_1 + y_2)i + (z_1 + z_2)j + (w_1 + w_2)k$
</p>
<!--
<p>
(x<sub>1</sub> + y<sub>1</sub>i+z<sub>1</sub>j+w<sub>1</sub>k) + (x<sub>2</sub> + y<sub>2</sub>i + z<sub>2</sub>j + w<sub>2</sub>k) = (x<sub>1</sub> + x<sub>2</sub>) + (y<sub>1</sub> + y<sub>2</sub>)i + (z<sub>1</sub> + z<sub>2</sub>)j + (w<sub>1</sub> + w<sub>2</sub>)k
</p>
-->
<p>
äžæ¹ã1ã$i$ã$j$ã$k$ ã®éã®ç©ã¯æ¬¡ã®ããã«äžããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_0241_1">
</center>
<br>
<p>
ãã®è¡šã¯ãïŒã€ã®ç¹å¥ãªæ° $A$ ãš $B$ ã®ç© $AB$ ã衚ããŠããŸããäŸãã°ã $i$ ãš $j$ ã®ç© $ij$ 㯠$k$ ã§ããã $j$ ãš $i$ ã®ç© $ji$ 㯠$-k$ ã§ããããšã衚ããŠããŸãã
</p>
<p>
äžè¬ã®åå
æ°ã®ç©ã¯ããã®é¢ä¿ãæºããããã«èšç®ãããŸããäŸãã°ã2ã€ã®åå
æ°ã$1+2i+3j+4k$ ãš$7+6i+7j+8k$ ã®ç©ã¯æ¬¡ã®ããã«èšç®ããŸãã
</p>
<p>
$(1+2i+3j+4k) \times (7+6i+7j+8k)=$<br>
$7+6i+7j+8k$<br>
$+14i+12i^2+14ij+16ik$<br>
$+21j+18ji+21j^2+24jk$<br>
$+28k+24ki+28kj+32k^2$
</p>
<p>
äžã®è¡šãé©çšããããšã«ãã
</p>
<p>
$= -58+16i+36j+32k$
</p>
<p>
ãšãªããŸãã
</p>
<p>
4ã€ã®ä¿æ°$x$ã$y$ã$z$ã$w$ ãæŽæ°ã§ãã€ãã¹ãŠããŒããšã¯ãªããªã2ã€ã®åå
æ° ($x_1+y_1 i+z_1 j+w_1 k$) ãš($x_2+y_2 i+z_2 j+w_2 k$)ãå
¥åãšãããã®ç©ã($x_3+y_3 i+z_3 j+w_3 k$)ãšããæã®$x_3$ã$y_3$ã$z_3$ã$w_3$ ãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<h2>å
¥å</h2>
<p>
è€æ°ã®ããŒã¿ã»ãããäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã<br>
<br>
$n$<br>
$data_1$<br>
$data_2$<br>
:<br>
$data_n$<br>
</p>
<p>
1è¡ç®ã«åŠçãè¡ãåå
æ°ã®çµã®åæ° $n$ ($ n \leq 10$) ãäžããããŸããç¶ã $n$ è¡ã« $i$ çªç®ã®åå
æ°ã®çµã®æ
å ± $data_i$ ãæ¬¡ã®åœ¢åŒã§äžããããŸãã<br>
<br>
$x_1$ $y_1$ $z_1$ $w_1$ $x_2$ $y_2$ $z_2$ $w_2$
</p>
<p>
äžããããä¿æ°ã¯ãã¹ãŠ-1000 以äž1000 以äžãšããŸããããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<h2>åºå</h2>
<p>
ããŒã¿ã»ããããšã«ãäžããããåå
æ°ã®çµã®ç©ãåºåããŸãã
</p>
<h2>å
¥åäŸ</h2>
<pre>
2
1 2 3 4 7 6 7 8
5 6 7 8 3 2 3 4
0
</pre>
<h2>åºåäŸ</h2>
<pre>
-58 16 36 32
-50 32 28 48
</pre> |
p03894 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have <var>N</var> cups and <var>1</var> ball.</p>
<p>The cups are arranged in a row, from left to right.</p>
<p>You turned down all the cups, then inserted the ball into the leftmost cup.</p>
<p>Then, you will perform the following <var>Q</var> operations:</p>
<ul>
<li>The <var>i</var>-th operation: swap the positions of the <var>A_i</var>-th and <var>B_i</var>-th cups from the left. If one of these cups contains the ball, the ball will also move.</li>
</ul>
<p>Since you are a magician, you can cast a magic described below:</p>
<ul>
<li>Magic: When the ball is contained in the <var>i</var>-th cup from the left, teleport the ball into the adjacent cup (that is, the <var>(i-1)</var>-th or <var>(i+1)</var>-th cup, if they exist).</li>
</ul>
<p>The magic can be cast before the first operation, between two operations, or after the last operation, but you are allowed to cast it at most once during the whole process.</p>
<p>Find the number of cups with a possibility of containing the ball after all the operations and possibly casting the magic.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10^5</var></li>
<li><var>1 \leq Q \leq 10^5</var></li>
<li><var>1 \leq A_i < B_i \leq N</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>Q</var>
<var>A_1</var> <var>B_1</var>
<var>A_2</var> <var>B_2</var>
:
<var>A_Q</var> <var>B_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of cups with a possibility of eventually containing the ball.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>10 3
1 3
2 4
4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>20 3
1 7
8 20
1 19
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre></section>
</div>
</span> |
p02786 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Caracal is fighting with a monster.</p>
<p>The <em>health</em> of the monster is <var>H</var>.</p>
<p>Caracal can attack by choosing one monster. When a monster is attacked, depending on that monster's health, the following happens:</p>
<ul>
<li>If the monster's health is <var>1</var>, it drops to <var>0</var>.</li>
<li>If the monster's health, <var>X</var>, is greater than <var>1</var>, that monster disappears. Then, two new monsters appear, each with the health of <var>\lfloor X/2 \rfloor</var>.</li>
</ul>
<p>(<var>\lfloor r \rfloor</var> denotes the greatest integer not exceeding <var>r</var>.)</p>
<p>Caracal wins when the healths of all existing monsters become <var>0</var> or below.</p>
<p>Find the minimum number of attacks Caracal needs to make before winning.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq H \leq 10^{12}</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>H</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Find the minimum number of attacks Caracal needs to make before winning.</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>3
</pre>
<p>When Caracal attacks the initial monster, it disappears, and two monsters appear, each with the health of <var>1</var>.</p>
<p>Then, Caracal can attack each of these new monsters once and win with a total of three attacks.</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>7
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1000000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1099511627775
</pre></section>
</div>
</span> |
p02293 |
<H1>Parallel/Orthogonal</H1>
<br/>
<p>
For given two lines <var>s1</var> and <var>s2</var>, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise.
</p>
<p>
<var>s1</var> crosses points <var>p0</var> and <var>p1</var>, and
<var>s2</var> crosses points <var>p2</var> and <var>p3</var>.
</p>
<H2>Input</H2>
<p>
The entire input looks like:
</p>
<pre>
<var>q</var> (the number of queries)
1st query
2nd query
...
<var>q</var>th query
</pre>
<p>
Each query consists of integer coordinates of the points <var>p0</var>, <var>p1</var>, <var>p2</var>, <var>p3</var> in the following format:
</p>
<pre>
<var>x<sub>p0</sub></var> <var>y<sub>p0</sub></var> <var>x<sub>p1</sub></var> <var>y<sub>p1</sub></var> <var>x<sub>p2</sub></var> <var>y<sub>p2</sub></var> <var>x<sub>p3</sub></var> <var>y<sub>p3</sub></var>
</pre>
<H2>Output</H2>
<p>
For each query, print "2", "1" or "0".
</p>
<H2>Constraints</H2>
<ul>
<li>
1 ≤ <var>q</var> ≤ 1000
</li>
<li>
-10000 ≤ <var>x<sub>p<sub>i</sub></sub></var>, <var>y<sub>p<sub>i</sub></sub></var> ≤ 10000
</li>
<li>
<var>p0 ≠ p1</var> and
<var>p2 ≠ p3</var>.
</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2
</pre>
<H2>Sample Output 1</H2>
<pre>
2
1
0
</pre>
<br/> |
p01846 |
<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-AMS_HTML">
</script>
<h3>jfen</h3>
<p><i>H × W</i> ã®ç€é¢ã§éã¶äžäººçšã²ãŒã ãããïŒãã®ã²ãŒã ã¯ããããã®ã»ã«ã« 0 ã 1 åã®ããŒã«ãããã®ã§ãããç§»åãããã²ãŒã ã§ããïŒããªãã¯ãã®ã²ãŒã ã§éãã§ãããïŒããŒã«ã¯éåžžã«äžžãããïŒã»ã«ããã»ã«ãžæ£ç¢ºã«ããŒã«ãç§»åãããã®ãé£ããããšã«æ°ã¥ããïŒããã§ããªãã¯ïŒåœä»€éãã«ããŒã«ãåãããŠããããããããäœãããšã«ããïŒããã§ïŒã»ã«ã衚ã衚èšãšã㊠(<i>y, x</i>) ãšãã衚èšãçšããïŒãã㯠<i>y</i> è¡ç®ã® <i>x</i> åç®ã®ã»ã«ã衚ãïŒ
</p>
<p>ãããããžã®åœä»€ã¯ 4 ã€ã®æŽæ° <i>a, b, c, d</i> ã§äžããããïŒãã㯠(<i>a, b</i>) ã«ããããŒã«ã (<i>c, d</i>) ã«ç§»åããããšã衚ãïŒãã®ãšãïŒ(<i>a, b</i>) ã«ããŒã«ãååšãïŒ (<i>c, d</i>) ã«ããŒã«ãååšããªãããšãä¿èšŒãããïŒ
</p>
<p>ç€é¢ã®ç¶æ
ã¯ïŒ"jfen" ãšåŒã°ããæ¬¡ã®èšæ³ã§è¡šãããïŒ
</p><pre>[1 è¡ç®ã®ããŒã¿]/[2 è¡ç®ã®ããŒã¿]/.../[H è¡ç®ã®ããŒã¿] </pre>
<p>ãã®èšæ³ã¯ç€é¢ã®åè¡ã衚ãããŒã¿ãã¹ã©ãã·ã¥åºåãã§é£çµãããã®ã§ããïŒåè¡ã®ããŒã¿ã¯æååã§è¡šããïŒ1 åç®ãã<i>W</i>åç®ã«ããã»ã«ã®ç¶æ
ãå·Šããé ã«èšè¿°ããŠããïŒãã®æååã¯æ°åãšæå 'b' ã§è¡šããïŒæ°åãè¡šãæŽæ°ã¯é£ç¶ãã空çœã®ã»ã«æ°ãïŒ'b' ã¯ããŒã«ãååšããã»ã«ã衚ããŠããïŒããã§ïŒåè¡ã®ããŒã¿ã§æŽæ°ãé£ç¶ããŠã¯ãªããªãïŒãŸãïŒåè¡ã®ããŒã¿ã«æžãããŠããæŽæ°ã®ç·åãš 'b' ã®åæ°ã®åã¯å¿
ã <i>W</i> ã«ãªãïŒ
</p>
<p>äŸãšããŠïŒæ¬¡ã®ãããªç€é¢ç¶æ
ãèããïŒç©ºçœã®ã»ã«ã '.' ã§è¡šãïŒããŒã«ãååšããã»ã«ã 'b' ã§è¡šçŸããŠããïŒãã®äŸã® <i>i</i> è¡ç®ã®å·Šãã <i>j</i> æåç®ã¯ç€é¢ã® <i>i</i> è¡ç®ã® <i>j</i> åç®ã®ã»ã«ã®ç¶æ
ã衚ãïŒ
</p>
<pre>
....
.b.b
....
</pre>
<p>äžèšã®ç€é¢ã jfen ã§è¡šèšãããšæ¬¡ã®ããã«ãªãïŒ
</p>
<pre>4/1b1b/4</pre>
<p>ããããã«çŸåšã®ç€é¢ã®ç¶æ
ãš 1 ã€ã®ããŒã«ãåããåœä»€ãäžããæã«ïŒãããããããŒã«ãåãããåŸã®ç€é¢ãåºåããããã°ã©ã ãäœæããïŒãã®ãšãïŒåºåããç€é¢ã¯ jfen èšæ³ã§åºåããïŒ
</p>
<h3>Input</h3>
<p>å
¥åã¯è€æ°ããŒã¿ã»ãããããªãïŒ
åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒãããªãïŒ
</p>
<blockquote><i>S</i><br><i>a</i> <i>b</i> <i>c</i> <i>d</i></blockquote>
<p>åããŒã¿ã»ãã㯠2 è¡ãããªãïŒæåã®è¡ã«ã¯ç€é¢ã®ç¶æ
ã衚ã jfen 圢åŒã®æåå <i>S</i> ãäžããããïŒããã§ïŒ ç€é¢ã®ãµã€ãºã¯ <i>2 ≤ W, H ≤ 9</i> ãæºããïŒç¶ãè¡ã«ã¯ãããããžã®åœä»€ãäžããããïŒãã㯠(<i>a, b</i>) ã«ããããŒã«ã (<i>c, d</i>) ã«ç§»åãããåœä»€ã衚ãïŒãŸãïŒå
¥åã®çµãã㯠# ã§è¡šãããïŒ
</p>
<h3>Output</h3>
<p>åºåã¯åããŒã¿ã»ããããšã«åœä»€ãå®è¡ããããšã®ç€é¢ã®ç¶æ
ã jfen èšæ³ã§è¡šããæåå 1 è¡ã§ããïŒåºåè¡ã«ã¯ä»ã®æåããã£ãŠã¯ãªããªãïŒ
</p>
<h3>Sample Input</h3>
<pre>b1/1b
1 1 1 2
b5/bbbbbb
2 4 1 4
b2b2b/7
1 4 2 4
#</pre>
<h3>Output for Sample Input</h3>
<pre>
1b/1b
b2b2/bbb1bb
b5b/3b3
</pre>
<p>
1çªç®ã®å
¥åã®åæç¶æ
ã¯æ¬¡ã®ããã«ãªãïŒ
</p>
<pre>
bïŒ
.b
</pre>
<p>
(1,1) ã®ããŒã«ã (1,2) ã«ç§»åãããã®ã§åœä»€åŸã®ç€é¢ã¯æ¬¡ã®ããã«ãªãïŒ
</p>
<pre>
.b
.b
</pre>
|
p02769 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a building with <var>n</var> rooms, numbered <var>1</var> to <var>n</var>.</p>
<p>We can move from any room to any other room in the building.</p>
<p>Let us call the following event a <strong>move</strong>: a person in some room <var>i</var> goes to another room <var>j~ (i \neq j)</var>.</p>
<p>Initially, there was one person in each room in the building.</p>
<p>After that, we know that there were exactly <var>k</var> moves happened up to now.</p>
<p>We are interested in the number of people in each of the <var>n</var> rooms now. How many combinations of numbers of people in the <var>n</var> rooms are possible?</p>
<p>Find the count 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>3 \leq n \leq 2 \times 10^5</var></li>
<li><var>2 \leq k \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>k</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of possible combinations of numbers of people in the <var>n</var> rooms now, modulo <var>(10^9 + 7)</var>.</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>10
</pre>
<p>Let <var>c_1</var>, <var>c_2</var>, and <var>c_3</var> be the number of people in Room <var>1</var>, <var>2</var>, and <var>3</var> now, respectively. There are <var>10</var> possible combination of <var>(c_1, c_2, c_3)</var>:</p>
<ul>
<li><var>(0, 0, 3)</var></li>
<li><var>(0, 1, 2)</var></li>
<li><var>(0, 2, 1)</var></li>
<li><var>(0, 3, 0)</var></li>
<li><var>(1, 0, 2)</var></li>
<li><var>(1, 1, 1)</var></li>
<li><var>(1, 2, 0)</var></li>
<li><var>(2, 0, 1)</var></li>
<li><var>(2, 1, 0)</var></li>
<li><var>(3, 0, 0)</var></li>
</ul>
<p>For example, <var>(c_1, c_2, c_3)</var> will be <var>(0, 1, 2)</var> if the person in Room <var>1</var> goes to Room <var>2</var> and then one of the persons in Room <var>2</var> goes to Room <var>3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>200000 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>607923868
</pre>
<p>Print the count modulo <var>(10^9 + 7)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>15 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>22583772
</pre></section>
</div>
</span> |
p00754 |
<h3><U>The Balance of the World</U></h3>
<!-- end en only -->
<div> <!-- please enclose each h3 level section with div -->
<!-- begin en only -->
<p>
The world should be finely balanced. Positive vs. negative,
light vs. shadow, and left vs. right brackets.
Your mission is to write a program that judges whether a string is balanced
with respect to brackets so that we can observe the balance of the
world.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
A string that will be given to the program may have two kinds of brackets,
round (“( )”) and square (“[ ]”).
A string is balanced if and only if the following conditions hold.
<ul>
<li>For every left round bracket (“(”), there is a corresponding
right round bracket (“)”) in the following part of the string.</li>
<li>For every left square bracket (“[”), there is a corresponding
right square bracket (“]”) in the following part of the string.</li>
<li>For every right bracket, there is a left bracket corresponding to it.</li>
<li>Correspondences of brackets have to be one to one, that is, a
single bracket never corresponds to two or more brackets.</li>
<li>For every pair of corresponding left and right brackets,
the substring between them is balanced.</li>
</ul>
</p>
<!-- end en only -->
</div>
<h3>Input</h3>
<div>
<!-- begin en only -->
<p>
The input consists of one or more lines, each of which being a dataset.
A dataset is a string that consists of English alphabets,
space characters, and two kinds of brackets, round (“( )”) and square (“[ ]”),
terminated by a period. You can assume that every line has 100
characters or less.
The line formed by a single period indicates the end of the input,
which is not a dataset.
</p>
<!-- end en only -->
</div>
<h3>Output</h3>
<div>
<!-- begin en only -->
<p>
For each dataset, output “yes” if the
string is balanced, or “no” otherwise, in a line.
There may not be any extra characters in the output.
</p>
<!-- end en only -->
</div>
<h3>Sample Input</h3>
<div>
<pre>
So when I die (the [first] I will see in (heaven) is a score list).
[ first in ] ( first out ).
Half Moon tonight (At least it is better than no Moon at all].
A rope may form )( a trail in a maze.
Help( I[m being held prisoner in a fortune cookie factory)].
([ (([( [ ] ) ( ) (( ))] )) ]).
.
.
</pre>
</div>
<h3>Output for the Sample Input</h3>
<div>
<pre>
yes
yes
no
no
no
yes
yes
</pre>
</div> |
p02339 | <!--<h1>åå12çž ãã®9:ããŒã«ã«åºå¥ããã»ç®±ã«åºå¥ãªãã»ç®±ã®äžèº«ã¯1ã€ä»¥äž</h1>-->
<h1>Balls and Boxes 9</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>4</td><td>5</td><td>6</td></tr>
<tr><th>Distinguishable</th><th>Indistinguishable</th><td>7</td><td>8</td><td style="background-color:#aff">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 distinguished from the other.</li>
<li>Each box is <b>not</b> 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 must contain at least one ball.</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>
4 3
</pre>
<h2>Sample Output 1</h2>
<pre>
6
</pre>
<h2>Sample Input 2</h2>
<pre>
10 5
</pre>
<h2>Sample Output 2</h2>
<pre>
42525
</pre>
<h2>Sample Input 3</h2>
<pre>
100 30
</pre>
<h2>Sample Output 3</h2>
<pre>
203169470
</pre>
|
p00304 |
<h1>æ°è¬éçº</h1>
<p>
è±äžåå£«ã¯æ¥ã
ç ç©¶ãè¡ããæ°ããè¬ãéçºããããšããŠããŸããæ°è¬ãéçºããããã«ã¯ãè²ã
ãªç©è³ªãçµã¿åãããŠè¬ãäœã詊éšãè¡ããè¯ãè¬ãèŠã€ããªããã°ãªããŸãããæ§ã
ãªçµã¿åããã詊ããŠãããã¡ã«ãè±äžå士ã¯ç©è³ªã®çµã¿åãããæš¹åœ¢å³ã§è¡šããããšãçªãæ¢ããŸããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_drugDevelopment">
</center>
<br>
<p>
å³ã®å³ã¯ãè¬ã®èª¿åãè¡šãæš¹åœ¢å³ã®äŸã§ããå³ã®äžã§äžžãå²ãŸãããã®ãç©è³ªããŒããäžè§ã§å²ãŸãããã®ãéžæããŒããšåŒã³ãŸããç©è³ªããŒãã¯ç©è³ªã衚ããŸããéžæããŒãã¯ãç©è³ªã®éžæã衚ããã®ã§ãããèªäœã¯ç©è³ªã衚ããŸãããéžæããŒãã«ã¯ or åïŒ∨ãä»ãããã®ïŒãš alt åïŒ⇔ãä»ãããã®ïŒã®ïŒçš®é¡ããããŸãããŸã ? ãä»ããããŒãã¯ãããããªãã·ã§ã³ã§ããããšã衚ããŸãããã ããéžæããŒãã®åããŒãïŒäžåãã®æã®å
ã«ããããŒãïŒããªãã·ã§ã³ã«ãªãããšã¯ãããŸãããæš¹åœ¢å³ã«çŸããç°ãªãç©è³ªããŒãã¯ãããããå¥ã®ç©è³ªã衚ããã®ãšããŸãã
</p>
<p>
è¬ã®èª¿åãè¡ããšãã¯ã暹圢å³ã®äžçªäžã®ããŒãããã¯ãããŠãé ã
ã«ããŒãããã©ã£ãŠãããªãã以äžã®ããã«ããŠããŒããéžãã§ãããŸãã
</p>
<ul>
<li> ãã©ãçããããŒãããªãã·ã§ã³ã§ãªãç©è³ªããŒããªãããããå¿
ãéžã¶ã</li>
<li> ãªãã·ã§ã³ã®ç©è³ªããŒããªãããããéžã¶ãã©ããã¯ä»»æã</li>
<li> or åã®éžæããŒããªãããã®åããå°ãªããšãäžã€ãéžã¶ããã ãããã®éžæããŒãããªãã·ã§ã³ãªããåãäžã€ãéžã°ãªããŠãããã</li>
<li> alt åã®éžæããŒããªãããã®åããäžã€ã ããéžã¶ããã ãããã®éžæããŒãããªãã·ã§ã³ãªããåãéžã°ãªããŠãããã</li>
</ul>
<p>
ããããŒããéžã°ãããšãã ãããã®ããŒãããäžã«åããæããããããã©ã£ãŠãããŸããéžã°ããªããã°ããããããã©ãããšã¯ãããŸããã
</p>
<p>
ããªãã¯è±äžå士ãããè¬ã®ç©è³ªã®çµã¿åãããè¡šãæš¹åœ¢å³ãåãåããçµã¿åããã®æ°ãå
šéšã§äœéããããæ±ããããæç€ºãããŸãããæš¹åœ¢å³ãäžãããããšããçµã¿åããã®ç·æ°ãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>node<sub>1</sub></var>
<var>node<sub>2</sub></var>
:
<var>node<sub>N</sub></var>
<var>s<sub>1</sub></var> <var>t<sub>1</sub></var>
<var>s<sub>2</sub></var> <var>t<sub>2</sub></var>
:
<var>s</var><sub><var>N</var>-1</sub> <var>t</var><sub><var>N</var>-1</sub>
</pre>
<p>
ïŒè¡ç®ã«ããŒãã®æ° <var>N</var> (1 ≤ <var>N</var> ≤ 1000) ãäžãããããç¶ã <var>N</var> è¡ã«ã<var>i</var> çªç®ã®ããŒãã®æ
å ± <var>node<sub>i</sub></var> ãäžãããããïŒçªç®ã®ããŒããæš¹åœ¢å³ã®äžçªäžã®ããŒããšãããç¶ã <var>N</var>-1 è¡ã« <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>t</var><sub>1</sub> ãã <var>t</var><sub><var>N</var>-1</sub> ãŸã§ã«ã¯ã2 ãã <var>N</var> ãŸã§ã®æ°ãäžåºŠã ãçŸããã<br>
<br>
ããŒãã®æ
å ±ã¯ä»¥äžã®åœ¢åŒã§ããã
</p>
<ul>
<li> <span>E</span> ãªãã·ã§ã³ã§ãªãç©è³ªããŒãã</li>
<li> <span>E?</span> ãªãã·ã§ã³ã§ããç©è³ªããŒãã</li>
<li> <var>type</var> ãªãã·ã§ã³ã§ãªãéžæããŒãã<var>type</var> 㯠<span>A</span> ã <span>R</span> ã®ããããã§ã<span>A</span> 㯠altåã<span>R</span> 㯠or åã衚ãã</li>
<li> <var>type</var><span>?</span> ãªãã·ã§ã³ã§ããéžæããŒãã<var>type</var> ã®åœ¢åŒã¯åäžã</li>
</ul>
<p>
å
¥åããåŸãããæš¹åœ¢å³ã¯ã以äžã®æ¡ä»¶ãæºããã
</p>
<ul>
<li> éžæããŒãã¯ïŒã€ä»¥äžã®åããŒããæã€ã</li>
<li> éžæããŒãã®åããŒãã¯ãªãã·ã§ã³ã§ãªãã</li>
<li> 暹圢å³ã®äžçªäžã®ããŒãã¯ãªãã·ã§ã³ã§ãªãã</li>
<li> ã©ã®ããŒãã«ã€ããŠããåããŒãã®æ°ã¯ 10 ãè¶
ããªãã</li>
</ul>
<h2>åºå</h2>
<p>
äžããããæš¹åœ¢å³ããåŸããããã¹ãŠã®çµã¿åããã®ç·æ°ãïŒè¡ã«åºåããããã ããåºåãã¹ãå€ã¯éåžžã«å€§ãããªãããã®ã§ã代ããã« 1,000,000,007 ã§å²ã£ãäœããåºåããã
</p>
<h2>å
¥åºåäŸ</h2>
<h2>å
¥åäŸïŒ </h2>
<pre>
12
A
E
E
E
R?
E?
E?
E
E
E
E?
E
1 2
1 3
1 4
2 5
4 6
4 7
5 8
5 9
7 10
7 11
11 12
</pre>
<h2>åºåäŸïŒ</h2>
<pre>
11
</pre>
<br>
<h2>å
¥åäŸïŒ</h2>
<pre>
10
E
R?
E
R
E
E
A
E
E
E
1 2
1 7
2 3
2 4
4 5
4 6
7 8
7 9
7 10
</pre>
<h2> åºåäŸïŒ</h2>
<pre>
24
</pre> |
p03482 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>S</var> consisting of <code>0</code> and <code>1</code>.
Find the maximum integer <var>K</var> not greater than <var>|S|</var> such that we can turn all the characters of <var>S</var> into <code>0</code> by repeating the following operation some number of times.</p>
<ul>
<li>Choose a contiguous segment <var>[l,r]</var> in <var>S</var> whose length is at least <var>K</var> (that is, <var>r-l+1\geq K</var> must be satisfied). For each integer <var>i</var> such that <var>l\leq i\leq r</var>, do the following: if <var>S_i</var> is <code>0</code>, replace it with <code>1</code>; if <var>S_i</var> is <code>1</code>, replace it with <code>0</code>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1\leq |S|\leq 10^5</var></li>
<li><var>S_i(1\leq i\leq N)</var> is either <code>0</code> or <code>1</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum integer <var>K</var> such that we can turn all the characters of <var>S</var> into <code>0</code> by repeating the operation some number of times.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>010
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We can turn all the characters of <var>S</var> into <code>0</code> by the following operations:</p>
<ul>
<li>Perform the operation on the segment <var>S[1,3]</var> with length <var>3</var>. <var>S</var> is now <code>101</code>.</li>
<li>Perform the operation on the segment <var>S[1,2]</var> with length <var>2</var>. <var>S</var> is now <code>011</code>.</li>
<li>Perform the operation on the segment <var>S[2,3]</var> with length <var>2</var>. <var>S</var> is now <code>000</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>100000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>8
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>00001111
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
</pre></section>
</div>
</span> |
p01145 |
<!-- begin en only -->
<h3><U> Princess' Japanese </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>
<p>
ãŸãïŒæ¥æ¬èªã®çºé³äœç³»ã«ã€ããŠå€§ãŸãã«èª¬æããå¿
èŠãããã ããïŒæ¥æ¬èªã§ã¯æïŒã¢ãŒã©ïŒãåäœãšããŠçºé³ããªãããïŒæã¯ä»¥äžã®ããããã®åœ¢ãããŠããïŒ
</p>
<ol>
<li>ïŒæ¯é³ïŒ</li>
<li>ïŒåé³ïŒ+ïŒæ¯é³ïŒ</li>
<li>ïŒãyããwã以å€ã®åé³ïŒ+ãyã+ïŒæ¯é³ïŒ</li>
<li>ä¿é³ïŒãã£ãïŒ</li>
<li>æ¥é³ïŒãããïŒ</li>
<li>é·é³ïŒããŒãïŒ</li>
</ol>
<p>
ããã§ïŒæ¯é³ã¯ãaããiããuããeããoãã®ããããïŒåé³ã¯ãkããsããtããnããhããmããyããrããwããgããzããdããbããpãã®ããããã§ããïŒãã ãïŒãyãã®çŽåŸã«çŸããæ¯é³ã¯ãaããuããoãã«éãããïŒãŸãïŒãwãã®çŽåŸã«çŸããæ¯é³ã¯ãaãã«éãããïŒ
</p>
<p>
ä¿é³ã¯çŽåŸã®æã®åé³ãéããŠè¡šèšãããïŒããšãã°ïŒãse<b>k</b>kiãïŒç³åšïŒã¯ä¿é³ãå«ãèªå¥ã®ã²ãšã€ã§ããïŒä¿é³ã¯æ¯é³ãããã¯ãnããyããwãã®åã«ã¯çŸããªãïŒãŸãã«ä¿é³ãæç¯æ«ã«çŸããããšã¯ãããïŒããã§ã¯ãã®ãããªäŸã¯èããªãïŒ
</p>
<p>
æ¥é³ã¯åç¬ã®ãnãã«ãã£ãŠè¡šèšãããïŒãã ãïŒæ¯é³ãŸãã¯ãyãã®çŽåã«çŸãããšãã¯ïŒäžèšã®2.ãŸãã¯3.ãšã®åºå¥ãã€ããªããªãããïŒãnãã®çŽåŸã«ã¢ãã¹ãããã£ãŒãã€ããïŒä»¥äžã«ããã€ãã®äŸããããïŒ
</p>
<blockquote>
ta<b>n</b>goïŒåèªïŒïŒni<b>n</b>genïŒäººéïŒïŒha<b>n</b>'eiïŒç¹æ ïŒ
</blockquote>
<p>
ç¹ã«ïŒä»¥äžã®éãã«ã¯æ³šæããããïŒ
</p>
<blockquote>
zeninïŒæ¯èªïŒïŒzen'inïŒå
šå¡ïŒïŒzenninïŒåä»»ïŒ
</blockquote>
<p>
é·é³ã¯åç¬ã§é³ç¯ãæ§æããããã§ã¯ãªããïŒåžžã«1æãäœåã«äœ¿ã£ãŠïŒããªãã¡2æã§ïŒçºé³ãããïŒæ¥æ¬èªã§ã¯é·é³ãšçé³ã®å¯Ÿç«ãããïŒãããé·é³ãšçé³ã®éãã«ãã£ãŠèªå¥ãåºå¥ãããããïŒé·é³ãšçé³ã®éãã¯éèŠã§ããïŒããã§ã¯é·é³ã¯æ¯é³ïŒãaããiããuãã®ããããïŒãéããŠè¡šèšããããšãšããïŒä»¥äžã«ããã€ãã®äŸããããïŒ
</p>
<blockquote>
ra<b>a</b>menïŒã©ãŒã¡ã³ïŒïŒbi<b>i</b>ruïŒããŒã«ïŒïŒkyu<b>u</b>syu<b>u</b>ïŒä¹å·ïŒïŒkare<b>i</b>ïŒã«ã¬ãŒïŒïŒkyo<b>u</b>toïŒäº¬éœïŒ
</blockquote>
<p>
æ¥é³ïŒä¿é³ïŒé·é³ã¯å
é ã«çŸããïŒãŸãé£ç¶ããŠçŸããªãïŒãŸãæ¥é³ãšä¿é³ãäºãã«é£ãåã£ãŠçŸããããšããªãïŒ
</p>
<p>
ããŠïŒæ¥æ¬èªã§ã¯ç¹å®ã®æ¡ä»¶äžã«ãããŠæ¯é³ããã¡ããšçºé³ãããªãããšãããïŒãããæ¯é³ã®ç¡å£°åãšåŒã°ããçŸè±¡ã§ããïŒæ¯é³ãç¡å£°åãããæ¡ä»¶ã«é¢ããŠã¯è«žèª¬ãããïŒããã§ã¯æ¯èŒçç°¡åã§ãã€æ©æ¢°çé©çšãå¯èœã§ãã以äžã®ãããªå Žåã«ã€ããŠèããããšã«ããïŒãã ãïŒç¡å£°åé³ãšã¯ãkããsããtããhããpãã®ããšã§ããïŒãŸãïŒãããã«ãyããç¶ãããã®ïŒãkyããªã©ïŒã䟿å®çã«ç¡å£°åé³ãšã¿ãªãïŒ
</p>
<ol>
<li>æ¯é³ãiããuãã®çé³ã«ã€ããŠïŒãã®æ¯é³ãç¡å£°åé³ã«ã¯ããŸãããšãïŒãŸãã¯ç¡å£°åé³ã®çŽåŸã§ãããèªå¥ã®æ«å°Ÿã«ãããšãïŒãã®èŠåã¯ïŒæ¯é³ãiããuãã®çŽåŸã®æãä¿é³ã§ãã£ãŠãé©çšãããïŒä»¥äžã«ããã€ãã®äŸã瀺ãïŒ</li>
<blockquote>
k<b>u</b>saïŒèïŒïŒhat<b>i</b>ïŒèïŒïŒk<b>i</b>k<b>u</b>ïŒèïŒïŒk<b>i</b>tteïŒåæïŒïŒk<b>i</b>pp<b>u</b>ïŒå笊ïŒïŒsuup<b>u</b>ïŒã¹ãŒãïŒ
</blockquote>
<li>æ¯é³ãaããoãã«ã€ããŠïŒåäžã®æ¯é³ãç¡å£°åé³ãšãšãã«é£ç¶ãã2ã€ä»¥äžã®æã§çŸãããšãïŒãã ãïŒãã®é£ç¶ããæã®ãã¡ã§æåŸã®ãã®ã«ã€ããŠã¯é€å€ãããïŒä»¥äžã«ããã€ãã®äŸã瀺ãïŒä¿é³ããã³é·é³ã¯ã²ãšã€ã®æãæ§æããããšããïŒé£ç¶éšåã®å
é ãŸãã¯éäžã«ïŒä¿é³ãŸãã¯é·é³ããã£ãŠã¯ãªããªããšããç¹ã«ã¯æ³šæããããšïŒ </li>
<blockquote>
h<b>a</b>haïŒæ¯ïŒïŒk<b>o</b>toïŒçŽïŒïŒh<b>a</b>k<b>a</b>taïŒåå€ïŒïŒs<b>a</b>kanaïŒéïŒïŒk<b>a</b>katoïŒãããšïŒ
</blockquote>
</ol>
<p>
ãã ãïŒäžèšã«è©²åœããå
šéšã®æ¯é³ãç¡å£°åãããããã§ã¯ãªãïŒããã¯ïŒè€æ°ã®æ¯é³ãç¶ããŠç¡å£°åãããããšã¯ãªãããšã«ããïŒæ¯é³ãç¡å£°åãããã®ã¯ïŒæåã®æ¯é³ã§ããå ŽåïŒãŸãã¯çŽè¿ã®æ¯é³ãç¡å£°åãããªãã£ãå Žåã§ããïŒãŸããããã®å Žåã«ãããïŒããšãã°ïŒãh<b>a</b>k<b>a</b>taãã«ã€ããŠã¯ïŒæåã®ãaãã¯ç¡å£°åããããïŒ2çªç®ã®ãaãã¯ç¡å£°åãããªãïŒåæ§ã«ããŠïŒãk<b>i</b>pp<b>u</b>ãã«ã€ããŠã¯ïŒèªäžã®ãiãã¯ç¡å£°åããããïŒèªå°Ÿã®ãuãã¯ç¡å£°åãããã«çºé³ãããïŒ
</p>
<p>
ãhott<b>o</b>kouhiiãïŒãããã³ãŒããŒïŒã¯ãããã«ããäŸã®ã²ãšã€ã§ããïŒãããæã«åè§£ãããšãho-ïŒä¿é³ïŒ-to-ko-ïŒé·é³ïŒ-hi-ïŒé·é³ïŒãã®ããã«ãªãïŒæåã®ãoãã¯ïŒçŽåŸã®æãä¿é³ã§ããããïŒäžèšã®æ³šææžãã«ããããã«ãç¡å£°åé³ + oããé£ç¶ããŠãããšã¯ã¿ãªãããªãïŒããªãã¡ïŒæåïŒ1æç®ïŒã®ãoãã¯ç¡å£°åãããªãïŒãšãããïŒæ¬¡ã®ãoãã«ã€ããŠã¯ïŒçŽåŸã«é·é³ããããã®ã®ãtoããkoããšããããã«ãç¡å£°åé³ + oããé£ç¶ããŠçŸããŠããïŒãããã£ãŠïŒ2çªç®ïŒ3æç®ïŒã®ãoãã¯ç¡å£°åãããïŒãŸãïŒèªå°Ÿä»è¿ã«ç¡å£°åé³ãhãã®åŸã«çŸãããiããååšãããïŒããã¯é·é³ã§ããããç¡å£°åãããªãïŒ
</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒããããã®ããŒã¿ã»ããã¯100æå以äžã®1ã€ã®èªå¥ãå«ãŸãã1è¡ã ããããªãïŒããããã®èªå¥ã«ã¯è±å°æåãšã¢ãã¹ãããã£ãŒã ããå«ãŸããïŒãŸãïŒããããã®èªå¥ã¯ïŒå顿äžã§èª¬æããæã ãããæ§æããããïŒæšæºæ¥æ¬èªã®èªå¥ã§ãããšã¯éããªãïŒ
</p>
<p>
å
¥åã®çµããã¯ã#ãã®ã¿ãå«ãŸããè¡ã«ãã£ãŠè¡šãããïŒããã¯ããŒã¿ã»ããã«å«ãŸããªãïŒ
</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>
ããããã®ããŒã¿ã»ããã«ã€ããŠïŒäžããããèªå¥ãïŒç¡å£°åãããæ¯é³ãæ¬åŒ§ã§å²ãã ããã§äžè¡ã«åºåããªããïŒ
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>
kusa
haha
hakata
kippu
sasakisan
sosonokasu
hottokouhii
i
#
</pre>
<h3>Output for the Sample Input</h3>
<pre>
k(u)sa
h(a)ha
h(a)kata
k(i)ppu
s(a)sak(i)san
s(o)sonokas(u)
hott(o)kouhii
i
</pre>
|
p03178 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Find the number of integers between <var>1</var> and <var>K</var> (inclusive) satisfying the following condition, modulo <var>10^9 + 7</var>:</p>
<ul>
<li>The sum of the digits in base ten is a multiple of <var>D</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq K < 10^{10000}</var></li>
<li><var>1 \leq D \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>K</var>
<var>D</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of integers satisfying the condition, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>30
4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>Those six integers are: <var>4, 8, 13, 17, 22</var> and <var>26</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1000000009
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
<p>Be sure to print the number modulo <var>10^9 + 7</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>98765432109876543210
58
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>635270834
</pre></section>
</div>
</span> |
p01515 |
<!-- begin en only -->
<h3><u>Equation
</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>
è«çæŒç®ã§ã¯ïŒå€ã¯ T ãš F ã®2çš®é¡ã ããæ±ãïŒ
</p>
<p>
"-"ãåé
æŒç®åïŒå
¥åã 1 ã€ã®æŒç®ã衚ãèšå·ïŒïŒ
"*", "+", "->" ã 2 é
æŒç®åïŒå
¥åã 2 ã€ã®æŒç®ã衚ãèšå·ïŒãšããïŒ
"-" ã¯è«çåŠå®(NOT)ïŒ
"*" ã¯è«çç©(AND)ïŒ
"+" ã¯è«çå(OR)ïŒ
"->" ã¯è«çå
å«(IMP)ãè¡šãæŒç®åã§ããïŒ
ãããã®è«çæŒç®ã®ççå€è¡šãäžã®è¡šã«ç€ºãïŒ
</p>
<table>
<thead><tr><th style="padding: .5em; background: #069; color: #fff">x</th><th style="padding: .5em; background: #069; color: #fff">y</th><th style="padding: .5em; background: #069; color: #fff">-x</th><th style="padding: .5em; background: #069; color: #fff">(x*y)</th><th style="padding: .5em; background: #069; color: #fff">(x+y)</th><th style="padding: .5em; background: #069; color: #fff">(x->y)</th></tr></thead>
<tbody><tr><td style="padding: .5em; background: #0cf">T</td><td style="padding: .5em; background: #0cf">T</td><td style="padding: .5em; background: #0cf">F</td><td style="padding: .5em; background: #0cf">T</td><td style="padding: .5em; background: #0cf">T</td><td style="padding: .5em; background: #0cf">T</td></tr></tbody>
<tbody><tr><td style="padding: .5em; background: #0cf">T</td><td style="padding: .5em; background: #0cf">F</td><td style="padding: .5em; background: #0cf">F</td><td style="padding: .5em; background: #0cf">F</td><td style="padding: .5em; background: #0cf">T</td><td style="padding: .5em; background: #0cf">F</td></tr></tbody>
<tbody><tr><td style="padding: .5em; background: #0cf">F</td><td style="padding: .5em; background: #0cf">T</td><td style="padding: .5em; background: #0cf">T</td><td style="padding: .5em; background: #0cf">F</td><td style="padding: .5em; background: #0cf">T</td><td style="padding: .5em; background: #0cf">T</td></tr></tbody>
<tbody><tr><td style="padding: .5em; background: #0cf">F</td><td style="padding: .5em; background: #0cf">F</td><td style="padding: .5em; background: #0cf">T</td><td style="padding: .5em; background: #0cf">F</td><td style="padding: .5em; background: #0cf">F</td><td style="padding: .5em; background: #0cf">T</td></tr></tbody>
</table>
<p>
è«çåŒã¯ä»¥äžã®ããããã®åœ¢åŒã§ããïŒ
X, Yã¯è«çåŒãšãïŒ 2 é
æŒç®åã¯å¿
ãæ¬åŒ§ã§å²ããã®ãšããïŒ
</p>
<ul>
<li>宿°: T, F</li>
<li>倿°: a, b, c, d, e, f, g, h, i, j, k</li>
<li>è«çåŠå®: -X</li>
<li>è«çç©: (X*Y)</li>
<li>è«çå: (X+Y)</li>
<li>è«çå
å«: (X->Y)</li>
</ul>
<p>
2 ã€ã®è«çåŒãçå· "=" ã§çµåããçåŒãäžããããïŒ
æçåŒãšã¯ïŒåŒã«çŸãã倿°ãã©ã®ãããªå€ã§ãã£ãŠãæç«ããçåŒã®ããšã§ããïŒ
äžããããçåŒãæçåŒã§ããããå€å®ããããã°ã©ã ãäœãããïŒ
</p>
<!-- end ja only -->
</div>
<h3>Input</h3>
<div>
<!-- begin ja only -->
<p>
å
¥åã¯è€æ°ã®è¡ã§æ§æããïŒåè¡ã¯ 1 ã€ã®ããŒã¿ã»ããã§ããïŒ
ããŒã¿ã»ããã¯T, F, a, b, c, d, e, f, g, h, i, j, k, (, ), =, -, +, *, > ããæãæååã§ããïŒ ç©ºçœãªã©ä»ã®æåãå«ãŸãªãïŒ
1 è¡ã®æåæ°ã¯ 1000 æå以äžãšä»®å®ããŠããïŒ
</p>
<p>
1 ã€ã®ããŒã¿ã»ããã¯çåŒã²ãšã€ãå«ãïŒ
çåŒã®ææ³ã¯æ¬¡ã® BNF ã§äžããããïŒ
ãã¹ãŠã®çåŒã¯ãã®æ§æèŠåã«åŸãïŒ
</p>
<pre>
<equation> ::= <formula> "=" <formula>
<formula> ::= "T" | "F" |
"a" | "b" | "c" | "d" | "e" | "f" |
"g" | "h" | "i" | "j" | "k" |
"-" <formula> |
"(" <formula> "*" <formula> ")" |
"(" <formula> "+" <formula> ")" |
"(" <formula> "->" <formula> ")"
</pre>
<p>
å
¥åã®çµãã㯠"#" ã ããããªãè¡ã§ç€ºãããŠããïŒãã®è¡ã¯ããŒã¿ã»ããã§ã¯ãªãïŒ
</p>
<!-- end ja only -->
</div>
<h3>Output</h3>
<div>
<!-- begin ja only -->
<p>
åããŒã¿ã»ããã«ã€ããŠïŒçåŒãæçåŒã§ããã°âYESâãïŒ ããã§ãªããã°âNOâããããã1è¡ã«åºåããªããïŒ åºåã«ã¯äœåãªæåãå«ãã§ã¯ãªããªãïŒ
</p>
<!-- end ja only -->
</div>
<h3>Sample Input</h3>
<div>
<pre>
-(a+b)=(-a*-b)
(a->b)=(-a+b)
((a*T)+b)=(-c+(a*-b))
#
</pre>
<!-- begin ja only -->
<!-- end ja only -->
</div>
<h3>Output for Sample Input</h3>
<div>
<pre>
YES
YES
NO
</pre>
<!-- begin ja only -->
<!-- end ja only -->
</div> |
p03528 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Select any integer <var>N</var> between <var>1000</var> and <var>2000</var> (inclusive), and any integer <var>K</var> not less than <var>1</var>, then solve the problem below.</p>
<h4>Problem</h4>
<p>We have <var>N</var> sheets of paper.
Write <var>K</var> integers on each of them to satisfy the following conditions:</p>
<ul>
<li>Each integer written must be between <var>1</var> and <var>N</var> (inclusive).</li>
<li>The <var>K</var> integers written on the same sheet must be all different.</li>
<li>Each of the integers between <var>1</var> and <var>N</var> must be written on exactly <var>K</var> sheets.</li>
<li>For any two sheet, there is exactly one integer that appears on both.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>There is no input in this problem.</p>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>In the first line, print <var>N</var> and <var>K</var> separated by a space.</p>
<p>In the subsequent <var>N</var> lines, print your solution.
The <var>i</var>-th of these lines must contain the <var>K</var> integers written on the <var>i</var>-th sheet, with spaces in between.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Output</h3><pre>3 2
1 2
2 3
3 1
</pre>
<p>This is an example of a solution for <var>N = 3</var> and <var>K = 2</var>.</p>
<p>Note that this output will be judged as incorrect, since the constraint on <var>N</var> is not satisfied.</p></section>
</div>
</span> |
p02010 | <h1>Problem G. Additions</h1>
<!--
Time Limit: 2 sec
Memory Limit: 512 MB
-->
<p>
You are given an integer $N$ and a string consisting of '<span>+</span>' and digits. You are asked to transform the string into a valid formula whose calculation result is smaller than or equal to $N$ by modifying some characters. Here, you replace one character with another character any number of times, and the converted string should still consist of '<span>+</span>' and digits. Note that leading zeros and unary positive are prohibited.
</p>
<p>
For instance, '<span>0123+456</span>' is assumed as invalid because leading zero is prohibited. Similarly, '<span>+1+2</span>' and '<span>2++3</span>' are also invalid as they each contain a unary expression. On the other hand, '<span>12345</span>', '<span>0+1+2</span>' and '<span>1234+0+0</span>' are all valid.
</p>
<p>
Your task is to find the minimum number of the replaced characters. If there is no way to make a valid formula smaller than or equal to $N$, output $-1$ instead of the number of the replaced characters.
</p>
<h2>Input</h2>
<p>
The input consists of a single test case in the following format.
</p>
<pre>
$N$
$S$
</pre>
<p>
The first line contains an integer $N$, which is the upper limit of the formula ($1 \leq N \leq 10^9$). The second line contains a string $S$, which consists of '<span>+</span>' and digits and whose length is between $1$ and $1,000$, inclusive. Note that it is <b><i>not</i></b> guaranteed that initially $S$ is a valid formula.
</p>
<h2>Output</h2>
<p>
Output the minimized number of the replaced characters. If there is no way to replace, output $-1$ instead.
</p>
<h2>Examples</h2>
<h2>Sample Input 1</h2>
<pre>
100
+123
</pre>
<h2>Output for Sample Input 1</h2>
<pre>
2
</pre>
<h2>Sample Input 2</h2>
<pre>
10
+123
</pre>
<h2>Output for Sample Input 2</h2>
<pre>
4
</pre>
<h2>Sample Input 3</h2>
<pre>
1
+123
</pre>
<h2>Output for Sample Input 3</h2>
<pre>
-1
</pre>
<h2>Sample Input 4</h2>
<pre>
10
++1+
</pre>
<h2>Output for Sample Input 4</h2>
<pre>
2
</pre>
<h2>Sample Input 5</h2>
<pre>
2000
1234++7890
</pre>
<h2>Output for Sample Input 5</h2>
<pre>
2
</pre>
<p>
In the first example, you can modify the first two characters and make a formula '<span>1+23</span>', for instance. In the second example, you should make '<span>0+10</span>' or '<span>10+0</span>' by replacing all the characters. In the third example, you cannot make any valid formula less than or equal to $1$.
</p>
|
p00187 |
<H1>æç³ãã¿ãã</H1>
<p>
ãèªåã®éã¯èªåã§åãéãããã¢ãããŒã«ãããç¥ç€Ÿãèªåèªèº«ã®æã§éå¢ã決ãããã¿ãããäœããŸããããã®ãã¿ãããåŒã人ã«ã¯ãŸã6ã€ã®ç³ãæããŠãããããã®æããç³ã®äžã€ç®ãšäºã€ç®ãçµã¶ ç·åãäžã€ç®ãšåã€ç®ãçµã¶ ç·åãäºã€ç®ãšå
ã€ç®ãçµã¶ ç·åã®3æ¬ã®ç·åã®äº€ç¹ãé ç¹ãšãã äžè§åœ¢ã®é¢ç©ããéå¢ã決ãããšãããã®ã§ããåéå¢ãšäžè§åœ¢ã®é¢ç©ãšã®é¢ä¿ã¯ä»¥äžã®ãšããã§ãã
</p>
<center>
<table>
<tr><th width="300">ç·åã®äº€ç¹ãé ç¹ãšããäžè§åœ¢ã®é¢ç©</th><th> éå¢</th></tr>
<tr><td> 1,900,000ä»¥äž </td><td>倧å (dai-kichi)</td></tr>
<tr><td> 1,000,000以äž1,900,000æªæº </td><td>äžå (chu-kichi)</td></tr>
<tr><td> 100,000以äž1,000,000æªæº </td><td> å (kichi)</td></tr>
<tr><td> 0ãã倧ãã 100,000æªæº </td><td> å°å (syo-kichi)</td></tr>
<tr><td> äžè§åœ¢ãªã </td><td> å¶ (kyo)</td></tr>
</table>
</center>
<br/>
<p>
ããããäžè§åœ¢ã®é¢ç©ã®å€§ããã®å€å®ã¯ç¥äž»ãããæèšç®ã§ãã£ãŠããã®ã§æ£ç¢ºãšã¯ããããæéãããã£ãŠããŸããŸããããã§è¿æã«äœãåªç§ãªããã°ã©ãã§ããããªãã¯ãäžå»ã§ãæ©ãããã°ã©ã ãæžããŠç¥äž»ãããå©ããŠãããããšã«ããŸããã
</p>
<p>
3 æ¬ã®ç·åã®æ
å ±ãå
¥åãšããç·åã®äº€ç¹ãé ç¹ãšãã äžè§åœ¢ã®é¢ç©ããéå¢ãåºåããããã°ã©ã ãäœæããŠãã ãããç·åã®æ
å ±ã¯å§ç¹ã®åº§æš (<var>x<sub>1</sub></var>, <var>y<sub>1</sub></var>) ãšãçµç¹ã®åº§æš (<var>x<sub>2</sub></var>, <var>y<sub>2</sub></var>) ãäžããããå§ç¹ãšçµç¹ã®åº§æšã¯å¿
ãç°ãªãããšãšããŸãããŸãã2 ã€ä»¥äžã®ç·åãåäžçŽç·äžã«ããå Žåã亀ç¹ãæããªã 2 ã€ã®ç·åãããå Žåã3 ã€ã®ç·åã 1 ç¹ã§äº€ããå Žåã¯ããäžè§åœ¢ãªãããšãªããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_stoning">
</center>
<br/><br/>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒã4ã€ã®è¡ã§ç€ºãããŸãã
åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>line<sub>1</sub></var>
<var>line<sub>2</sub></var>
<var>line<sub>3</sub></var>
</pre>
<p>
<var>i</var> è¡ç®ã« <var>i</var> çªç®ã®ç·åã®æ
å ±ãäžããããŸããåç·åã®æ
å ±ã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var>
</pre>
<p>
ç·åã®ç«¯ç¹ã®åº§æšãè¡šãæŽæ° (<var>x<sub>1</sub></var>, <var>y<sub>1</sub></var>), (<var>x<sub>2</sub></var>, <var>y<sub>2</sub></var>) (-1000 ≤ <var>x<sub>1</sub></var>, <var>y<sub>1</sub></var>, <var>x<sub>2</sub></var>, <var>y<sub>2</sub></var> ≤ 1000 ) ã空çœåºåãã§äžããããŸãã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããæ¯ã«ããã¿ããã®çµæãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
-3 -2 9 6
3 -2 7 6
-1 0 5 0
2 2 -1 -1
0 1 2 1
-3 -1 3 1
0 0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
syo-kichi
kyo
</pre>
|
p02440 | <h1>Min-Max Element</h1>
<p>
Write a program which manipulates a sequence $A = \{a_0, a_1, ..., a_{n-1}\}$ by the following operations:
</p>
<ul>
<li>min($b, e$): report the minimum element in $a_b, a_{b+1}, ..., a_{e-1}$</li>
<li>max($b, e$): report the maximum element in $a_b, a_{b+1}, ..., a_{e-1}$</li>
</ul>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$n$
$a_0 \; a_1, ..., \; a_{n-1}$
$q$
$com_1 \; b_1 \; e_1$
$com_2 \; b_2 \; e_2$
:
$com_{q} \; b_{q} \; e_{q}$
</pre>
<p>
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given in the following $q$ lines. $com_i$ denotes a type of query. <span>0</span> and <span>1</span> represents min($b, e$) and max($b, e$) respectively.
</p>
<h2>Output</h2>
<p>
For each query, print the minimum element or the maximum element in a line.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq n \leq 1,000$</li>
<li>$-1,000,000,000 \leq a_i \leq 1,000,000,000$</li>
<li>$1 \leq q \leq 1,000$</li>
<li>$0 \leq b < e \leq n$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
7
8 3 7 1 9 1 4
3
0 0 3
0 1 5
1 0 7
</pre>
<h2>Sample Output 1</h2>
<pre>
3
1
9
</pre>
|
p03601 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is making sugar water in a beaker.
Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations.</p>
<ul>
<li>Operation 1: Pour <var>100A</var> grams of water into the beaker.</li>
<li>Operation 2: Pour <var>100B</var> grams of water into the beaker.</li>
<li>Operation 3: Put <var>C</var> grams of sugar into the beaker.</li>
<li>Operation 4: Put <var>D</var> grams of sugar into the beaker.</li>
</ul>
<p>In our experimental environment, <var>E</var> grams of sugar can dissolve into <var>100</var> grams of water.</p>
<p>Snuke will make sugar water with the highest possible density.</p>
<p>The beaker can contain at most <var>F</var> grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker.
Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it.
If there is more than one candidate, any of them will be accepted.</p>
<p>We remind you that the sugar water that contains <var>a</var> grams of water and <var>b</var> grams of sugar is <var>\frac{100b}{a + b}</var> percent.
Also, in this problem, pure water that does not contain any sugar is regarded as <var>0</var> percent density sugar water.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq A < B \leq 30</var></li>
<li><var>1 \leq C < D \leq 30</var></li>
<li><var>1 \leq E \leq 100</var></li>
<li><var>100A \leq F \leq 3</var> <var>000</var></li>
<li><var>A</var>, <var>B</var>, <var>C</var>, <var>D</var>, <var>E</var> and <var>F</var> are all integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>C</var> <var>D</var> <var>E</var> <var>F</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>Print two integers separated by a space.
The first integer should be the mass of the desired sugar water, and the second should be the mass of the sugar dissolved in it.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 2 10 20 15 200
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>110 10
</pre>
<p>In this environment, <var>15</var> grams of sugar can dissolve into <var>100</var> grams of water, and the beaker can contain at most <var>200</var> grams of substances.</p>
<p>We can make <var>110</var> grams of sugar water by performing Operation 1 once and Operation 3 once.
It is not possible to make sugar water with higher density.
For example, the following sequences of operations are infeasible:</p>
<ul>
<li>If we perform Operation 1 once and Operation 4 once, there will be undissolved sugar in the beaker.</li>
<li>If we perform Operation 2 once and Operation 3 three times, the mass of substances in the beaker will exceed <var>200</var> grams.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 2 1 2 100 1000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>200 100
</pre>
<p>There are other acceptable outputs, such as:</p>
<pre>400 200
</pre>
<p>However, the output below is not acceptable:</p>
<pre>300 150
</pre>
<p>This is because, in order to make <var>300</var> grams of sugar water containing <var>150</var> grams of sugar, we need to pour exactly <var>150</var> grams of water into the beaker, which is impossible.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>17 19 22 26 55 2802
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2634 934
</pre></section>
</div>
</span> |
p02913 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is a string <var>S</var> of length <var>N</var>.</p>
<p>Find the maximum length of a non-empty string that occurs twice or more in <var>S</var> as contiguous substrings without overlapping.</p>
<p>More formally, find the maximum positive integer <var>len</var> such that there exist integers <var>l_1</var> and <var>l_2</var> ( <var>1 \leq l_1, l_2 \leq N - len + 1</var> ) that satisfy the following:</p>
<ul>
<li>
<p><var>l_1 + len \leq l_2</var></p>
</li>
<li>
<p><var>S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)</var></p>
</li>
</ul>
<p>If there is no such integer <var>len</var>, print <var>0</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 5 \times 10^3</var></li>
<li><var>|S| = N</var></li>
<li><var>S</var> consists of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum length of a non-empty string that occurs twice or more in <var>S</var> as contiguous substrings without overlapping. If there is no such non-empty string, print <var>0</var> instead.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
ababa
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>The strings satisfying the conditions are: <code>a</code>, <code>b</code>, <code>ab</code>, and <code>ba</code>. The maximum length among them is <var>2</var>, which is the answer.
Note that <code>aba</code> occurs twice in <var>S</var> as contiguous substrings, but there is no pair of integers <var>l_1</var> and <var>l_2</var> mentioned in the statement such that <var>l_1 + len \leq l_2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
xy
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>No non-empty string satisfies the conditions.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>13
strangeorange
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>5
</pre></section>
</div>
</span> |
p01796 |
<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
JAG-channel II</h2>
<p>
JAG (Japan Alumni Group) is a group of $N$ members that devotes themselves to activation of the competitive programming world. The JAG staff members talk every day on the BBS called JAG-channel. There are several threads in JAG-channel and these are kept sorted by the time of their latest posts in descending order.
</p>
<p>
One night, each of the $N$ members, identified by the first $N$ uppercase letters respectively, created a thread in JAG-channel. The next morning, each of the $N$ members posted in exactly $K$ different threads which had been created last night. Since they think speed is important, they viewed the threads from top to bottom and posted in the thread immediately whenever they came across an interesting thread. Each member viewed the threads in a different period of time, that is, there was no post of other members while he/she was submitting his/her $K$ posts.
</p>
<p>
Your task is to estimate the order of the members with respect to the periods of time when members posted in the threads. Though you do not know the order of the threads created, you know the order of the posts of each member. Since the threads are always kept sorted, there may be invalid orders of the members such that some members cannot post in the top-to-bottom order of the threads due to the previous posts of other members. Find out the lexicographically smallest valid order of the members.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case. The first line contains two integers separated by a space: $N$ $(4 \leq N \leq 16)$ and $K$ $(N - 3 \leq K \leq N - 1)$. Then $N$ lines of strings follow. Each of the $N$ lines consists of exactly $K$ distinct characters. The $j$-th character of the $i$-th line denotes the $j$-th thread in which the
member denoted by the $i$-th uppercase letter posted. Each thread is represented by its creator (e.g. '<span>B</span>' represents the thread created by member B, the second member).
</p>
<p>
It is guaranteed that at least one valid order exists.
</p>
<h3>Output</h3>
<p>
Display a string that consists of exactly $N$ characters in a line, which denotes the valid order in which the members posted in the threads. The $i$-th character of the output should represent the member who posted in the $i$-th period. In case there are multiple valid orders, output the lexicographically smallest one.
</p>
<h3>Sample Input 1</h3>
<pre>7 4
DEFG
FEDA
EFGB
BGEA
AGFD
DABC
CADE</pre>
<h3>Output for the Sample Input 1</h3>
<pre>ABCDEFG</pre>
<h3>Sample Input 2</h3>
<pre>4 3
CDB
DAC
BAD
ABC</pre>
<h3>Output for the Sample Input 2</h3>
<pre>DCBA</pre>
<h3>Sample Input 3</h3>
<pre>16 13
NDHPFJIBLMCGK
CMDJKPOLGIHNE
MOLBIEJFPHADN
KPNAOHBLMCGEI
FCMLBHDOANJPK
NHIGLOAPKJDMC
KMLBIPHDEOANJ
IEGCMLBOAPKJD
JNAOEDHBLMCGF
OEDHPFIBLMGKC
GMLBIFPHDNAEO
ENHGOPKJDMCAF
JKPAOBLGEIHNF
HPKFGJEIBLCOM
LBINEJDAGFKPH
FGMOCADJENIBL</pre>
<h3>Output for the Sample Input 3</h3>
<pre>PONCAKJGIEDHMFBL</pre>
|
p00884 |
<H1><font color="#000">Problem A:</font> Membership Management</H1>
<p>
Peter is a senior manager of Agile Change Management (ACM) Inc., where each employee is a member of one or more task groups. Since ACM is agile, task groups are often reorganized and their members frequently change, so membership management is his constant headache.
</p>
<p>
Peter updates the membership information whenever any changes occur: for instance, the following line written by him means that Carol and Alice are the members of the Design Group.
</p>
<pre>
design:carol,alice.
</pre>
<p>
The name preceding the colon is the group name and the names following it specify its members.
</p>
<p>
A smaller task group may be included in a larger one. So, a group name can appear as a member of another group, for instance, as follows.
</p>
<pre>
development:alice,bob,design,eve.
</pre>
<p>
Simply unfolding the design above gives the following membership specification, which is equivalent to the original.
</p>
<pre>
development:alice,bob,carol,alice,eve.
</pre>
<p>
In this case, however, alice occurs twice. After removing one of the duplicates, we have the following more concise specification.
</p>
<pre>
development:alice,bob,carol,eve.
</pre>
<p>
Your mission in this problem is to write a program that, given group specifications, identifies group members.
</p>
<p>
Note that Peter's specifications can include deeply nested groups. In the following, for instance, the group one contains a single member dave.
</p>
<pre>
one:another.
another:yetanother.
yetanother:dave.
</pre>
<H2>Input</H2>
<p>
The input is a sequence of datasets, each being in the following format.
</p>
<p>
<i>n</i><br>
<i>group</i><sub>1</sub><span>:</span><i>member</i><sub>1,1</sub>,...,<i>member</i><sub>1,<i>m</i><sub>1</sub></sub><span>.</span><br>
<span>.</span><br>
<span>.</span><br>
<span>.</span><br>
<i>group</i><sub><i>i</i></sub><span>:</span><i>member</i><sub><i>i</i>,1</sub>,...,<i>member</i><sub><i>i</i>,<i>m</i><sub><i>i</i></sub></sub><span>.</span><br>
<span>.</span><br>
<span>.</span><br>
<span>.</span><br>
<i>group</i><sub><i>n</i></sub><span>:</span><i>member</i><sub><i>n</i>,1</sub>,...,<i>member</i><sub><i>n</i>,<i>m</i><sub><i>n</i></sub></sub><span>.</span><br>
</p>
<p>
The first line contains n, which represents the number of groups and is a positive integer no more than 100. Each of the following n lines contains the membership information of a group: <i>group</i><sub><i>i</i></sub> (1 ≤ <i>i</i> ≤ <i>n</i>) is the name of the <i>i</i>-th task group and is followed by a colon (<span>:</span>) and then the list of its <i>m<sub>i</sub></i> member s that are delimited by a comma (<span>,</span>) and terminated by a period (<span>.</span>).
</p>
<p>
Those group names are mutually different. Each <i>m<sub>i</sub></i> (1 ≤ <i>i</i> ≤ <i>n</i>) is between 1 and 10, inclusive. A <i>member</i> is another group name if it is one of <i>group</i><sub>1</sub>, <i>group</i><sub>2</sub>,..., or groupn. Otherwise it is an employee name.
</p>
<p>
There are no circular (or recursive) definitions of group(s). You may assume that <i>m<sub>i</sub></i> member names of a group are mutually different.
</p>
<p>
Each group or employee name is a non-empty character string of length between 1 and 15, inclusive, and consists of lowercase letters.
</p>
<p>
The end of the input is indicated by a line containing a zero.
</p>
<H2>Output</H2>
<p>
For each dataset, output the number of employees included in the first group of the dataset, that is <i>group</i><sub>1</sub>, in a line. No extra characters should occur in the output.
</p>
<H2>Sample Input</H2>
<pre>
2
development:alice,bob,design,eve.
design:carol,alice.
3
one:another.
another:yetanother.
yetanother:dave.
3
friends:alice,bob,bestfriends,carol,fran,badcompany.
bestfriends:eve,alice.
badcompany:dave,carol.
5
a:b,c,d,e.
b:c,d,e,f.
c:d,e,f,g.
d:e,f,g,h.
e:f,g,h,i.
4
aa:bb.
cc:dd,ee.
ff:gg.
bb:cc.
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
6
4
2
</pre>
|
p03251 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Our world is one-dimensional, and ruled by two empires called Empire A and Empire B.</p>
<p>The capital of Empire A is located at coordinate <var>X</var>, and that of Empire B is located at coordinate <var>Y</var>.</p>
<p>One day, Empire A becomes inclined to put the cities at coordinates <var>x_1, x_2, ..., x_N</var> under its control, and Empire B becomes inclined to put the cities at coordinates <var>y_1, y_2, ..., y_M</var> under its control.</p>
<p>If there exists an integer <var>Z</var> that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out.</p>
<ul>
<li><var>X < Z \leq Y</var></li>
<li><var>x_1, x_2, ..., x_N < Z</var></li>
<li><var>y_1, y_2, ..., y_M \geq Z</var></li>
</ul>
<p>Determine if war will break out.</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 100</var></li>
<li><var>-100 \leq X < Y \leq 100</var></li>
<li><var>-100 \leq x_i, y_i \leq 100</var></li>
<li><var>x_1, x_2, ..., x_N \neq X</var></li>
<li><var>x_i</var> are all different.</li>
<li><var>y_1, y_2, ..., y_M \neq Y</var></li>
<li><var>y_i</var> are all different.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var> <var>X</var> <var>Y</var>
<var>x_1</var> <var>x_2</var> <var>...</var> <var>x_N</var>
<var>y_1</var> <var>y_2</var> <var>...</var> <var>y_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If war will break out, print <code>War</code>; otherwise, print <code>No War</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2 10 20
8 15 13
16 22
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>No War
</pre>
<p>The choice <var>Z = 16</var> satisfies all of the three conditions as follows, thus they will come to an agreement.</p>
<ul>
<li><var>X = 10 < 16 \leq 20 = Y</var></li>
<li><var>8, 15, 13 < 16</var></li>
<li><var>16, 22 \geq 16</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 2 -48 -1
-20 -35 -91 -23
-22 66
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>War
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 3 6 8
-10 3 1 5 -100
100 6 14
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>War
</pre></section>
</div>
</span> |
p03744 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are in charge of controlling a dam. The dam can store at most <var>L</var> liters of water. Initially, the dam is empty. Some amount of water flows into the dam every morning, and any amount of water may be discharged every night, but this amount needs to be set so that no water overflows the dam the next morning.</p>
<p>It is known that <var>v_i</var> liters of water at <var>t_i</var> degrees Celsius will flow into the dam on the morning of the <var>i</var>-th day.
You are wondering about the maximum possible temperature of water in the dam at noon of each day, under the condition that there needs to be exactly <var>L</var> liters of water in the dam at that time. For each <var>i</var>, find the maximum possible temperature of water in the dam at noon of the <var>i</var>-th day. Here, consider each maximization separately, that is, the amount of water discharged for the maximization of the temperature on the <var>i</var>-th day, may be different from the amount of water discharged for the maximization of the temperature on the <var>j</var>-th day <var>(jâ i)</var>.</p>
<p>Also, assume that the temperature of water is not affected by anything but new water that flows into the dam. That is, when <var>V_1</var> liters of water at <var>T_1</var> degrees Celsius and <var>V_2</var> liters of water at <var>T_2</var> degrees Celsius are mixed together, they will become <var>V_1+V_2</var> liters of water at <var>\frac{T_1*V_1+T_2*V_2}{V_1+V_2}</var> degrees Celsius, and the volume and temperature of water are not affected by any other factors.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1†N †5*10^5</var></li>
<li><var>1†L †10^9</var></li>
<li><var>0†t_i †10^9(1â€iâ€N)</var></li>
<li><var>1†v_i †L(1â€iâ€N)</var></li>
<li><var>v_1 = L</var></li>
<li><var>L</var>, each <var>t_i</var> and <var>v_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>L</var>
<var>t_1</var> <var>v_1</var>
<var>t_2</var> <var>v_2</var>
<var>:</var>
<var>t_N</var> <var>v_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 maximum temperature such that it is possible to store <var>L</var> liters of water at that temperature in the dam at noon of the <var>i</var>-th day.</p>
<p>Each of these values is accepted if the absolute or relative error is at most <var>10^{-6}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 10
10 10
20 5
4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10.0000000
15.0000000
13.2000000
</pre>
<ul>
<li>
<p>On the first day, the temperature of water in the dam is always <var>10</var> degrees: the temperature of the only water that flows into the dam on the first day.</p>
</li>
<li>
<p><var>10</var> liters of water at <var>15</var> degrees of Celsius can be stored on the second day, by discharging <var>5</var> liters of water on the night of the first day, and mix the remaining water with the water that flows into the dam on the second day.</p>
</li>
<li>
<p><var>10</var> liters of water at <var>13.2</var> degrees of Celsius can be stored on the third day, by discharging <var>8</var> liters of water on the night of the first day, and mix the remaining water with the water that flows into the dam on the second and third days.</p>
</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 15
0 15
2 5
3 6
4 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0.0000000
0.6666667
1.8666667
2.9333333
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 15
1000000000 15
9 5
8 6
7 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1000000000.0000000
666666669.6666666
400000005.0000000
293333338.8666667
</pre>
<p>Although the temperature of water may exceed <var>100</var> degrees Celsius, we assume that water does not vaporize.</p></section>
</div>
</span> |
p01779 |
<h2>H : Typing Game / ã¿ã€ãã³ã°ã²ãŒã </h2>
<h3>ç©èª</h3>
<p>
ããããã¯ïŒã¿ã€ãã³ã°åãéããæéã§ãïŒçããã¯æ©ãæ£ç¢ºãªã¿ã€ãã³ã°ãããããšãã§ããŸããïŒ
Letâs enjoy Typing Game!
</p>
<h3>åé¡</h3>
<p>ã¿ã€ãã³ã°ã²ãŒã ã®ã²ãŒã ã·ã¹ãã ãšããŠïŒãžã£ããžåŽãçšæããAIã®åºåã«å¯ŸããŠå¯Ÿè©±çã«åäœããããã°ã©ã ãäœæããïŒ</p>
<p>AI㯠<var>N</var> åã®æååãã¿ã€ãããã²ãŒã ããã¬ã€ããïŒAIã¯äœåãæã£ãŠããïŒãã®åæå€ã¯ <var>H</var> ã§ããïŒAIã¯äœåãããéãæåã®ã¿ã€ããè¡ãïŒã·ã¹ãã ã¯AIãã¿ã€ããã¹ãæååãæç€ºããïŒã·ã¹ãã ã¯AIãã¿ã€ãããæåãåãåãïŒæ¬¡ã«ã¿ã€ããã¹ãæåãšäžèŽãããå€å®ããïŒAIãæååã<var>1</var>ã€ã¿ã€ããçµãããšïŒã·ã¹ãã ã¯æ¬¡ã®æååãæç€ºããïŒ</p>
<p>ãŸãïŒåæååã«ã¯ãã¹ã¿ã€ãã®èš±å®¹åæ°ãå®ããããŠããïŒAIã®ããæååã«ããããã¹ã¿ã€ãã®åæ°ãèš±å®¹åæ°ãè¶
ããŠããŸããšAIã®äœåã<var>1</var>æžãïŒã·ã¹ãã ã¯åŒ·å¶çã«æ¬¡ã®æååãæç€ºããïŒAIã®äœåã<var>0</var>ã«ãªã£ããã²ãŒã ãªãŒããŒãšãªãïŒæåŸã®æååã«ãããŠïŒã¿ã€ãã®æåãŸãã¯ãã¹ã¿ã€ãåæ°ã®è¶
éãèµ·ãã£ãåŸã§ïŒAIã®äœåãæ®ã£ãŠããã°ã²ãŒã ã¯ãªã¢ãšãªãïŒ</p>
<h3>å
¥åºå圢åŒ</h3>
<p>ãŸãïŒå
¥åã以äžã®åœ¢åŒã§äžããããïŒ</p>
<pre>
<var>N</var> <var>H</var>
<var>S_1</var> <var>T_1</var>
...
<var>S_N</var> <var>T_N</var>
</pre>
<p>1è¡ç®ã«æååã®æ° <var>N</var> ãšAIã®äœå <var>H</var> ã空çœåºåãã§äžããããïŒ</p>
<p>ç¶ã <var>N</var> è¡ã«ã¯ <var>i</var> è¡ç®ã« <var>i</var> çªç®ã®æåå <var>S_i</var> ãšïŒãã®æååã«å¯Ÿãããã¹ã¿ã€ãã®èš±å®¹åæ° <var>T_i</var> ã空çœåºåãã§äžããããïŒ</p>
<p>
ãã®å
¥åã¯ä»¥äžã®å¶çŽãæºããïŒ
</p>
<ul>
<li> <var>1 ≤ N ≤ 100</var> </li>
<li> <var>1 ≤ H ≤ 10</var> </li>
<li> <var>1 ≤ |S_i| ≤ 15</var> </li>
<li> <var>S_i</var> ã¯ã¢ã«ãã¡ããã'a'-'z'ïŒãŸãã¯'A'-'Z'ã®ã¿ãå«ãïŒ </li>
<li> <var>0 ≤ T_i ≤ 20</var> </li>
</ul>
<p>ã·ã¹ãã ã¯æåå <var>S_1</var> ããæåå <var>S_N</var> ãŸã§é çªã«åŠçãããïŒ<var>i</var> çªç®ã®æåå <var>S_i</var> ã«ã€ããŠïŒAIã <var>j</var> æåç®ãŸã§ã¿ã€ããæåãããŠããå ŽåïŒä»¥äžã®åŠçãããïŒ</p>
<p>ã·ã¹ãã ã¯AIã«å¯ŸããŠïŒ<var>S_i</var> ãåºåããïŒãã®ãšãïŒ<var>S_i</var> ã®1æåç®ãã <var>j</var> æåç®ã"_" (ã¢ã³ããŒã¹ã³ã¢) ã«çœ®ãæããïŒã·ã¹ãã ãééã£ãæååãåºåãããšïŒAIã¯åäœãäžæãWrong AnswerãšãªãïŒã·ã¹ãã ãåºåããæååã S ã§ããå ŽåïŒC/C++ã§ã®åºåäŸã¯ä»¥äžã®ããã«ãªãïŒ</p>
<pre>printf("? %s\n", S); fflush(stdout);</pre>
<p>AIã¯ã·ã¹ãã ã®åºåãåãåããšïŒ</p>
<pre><var>c</var></pre>
<p>ã®åœ¢åŒã§è¿çããïŒ<var>c</var> ã¯AIãã¿ã€ãããæåã§ããïŒ<var>c</var> ã¯ã¢ã«ãã¡ããã'a'-'z'ãããªãïŒC/C++ã§ã®è¿çã®åãåãæ¹ã®äŸã¯ä»¥äžã®ããã«ãªãïŒ</p>
<pre>
char c[2];
scanf("%s", c);
/*
char c;
scanf("%c", &c);
ã¯ç©ºçœæåèªã¿èŸŒã¿ã®ä»æ§äžã®çç±ã§éæšå¥šã§ãïŒ
*/
</pre>
<p>ã·ã¹ãã ã¯AIã®åºåãåãåããšãŸãAIãã¿ã€ãããæåãš <var>S_i</var> ã® <var>j+1</var> æåç®ãäžèŽããŠãããå€å®ããïŒãã®å€å®ã®éïŒå€§æåãšå°æåã¯åºå¥ããªãããšã«æ³šæããïŒäžèŽããŠãããšãã¯ïŒ<var>j+1</var> æåç®ãŸã§ã¿ã€ãã«æåãããšããïŒããã§ <var>j+1</var> æåç®ã <var>S_i</var> ã®æåŸã®æåã ã£ãå ŽåïŒ<var>S_i</var> ã®ã¿ã€ãã«æåãããšã <var>S_i</var> ã®åŠçãçµããïŒAIãã¿ã€ãããæåãš <var>S_i</var> ã® <var>j+1</var> æåç®ãäžèŽããŠããªããã°ïŒ<var>S_i</var> ã«å¯Ÿãããã¹ã¿ã€ãåæ°ã1ã ãå¢ããïŒãã®ãšã <var>T_i</var> ãè¶
ããŠããã°AIã®äœåã<var>1</var>æžããïŒ<var>S_i</var> ã®åŠçãçµããïŒ<var>S_i</var> ã®åŠçãçµãããšãïŒAIã®äœåã<var>0</var>ã§ããã°ã²ãŒã ãªãŒããŒãšããïŒã²ãŒã ãªãŒããŒã§ãªããã° <var>i</var> ã <var>N</var> ã®ãšãã²ãŒã ã¯ãªã¢ãšãïŒããã§ãªããã° <var>S_{i+1}</var> ã®åŠçã«ç§»ãïŒ</p>
<p>ãŸãïŒã²ãŒã ãªãŒããŒã®éã«ã¯"! Game Over"ãïŒã²ãŒã ã¯ãªã¢ã®éã«ã¯"! Game Clear [ã¿ã€ãæåç]"ãåºåããïŒã¿ã€ãæåç㯠(æåã¿ã€ãæ°) / (åèšã¿ã€ãæ°) <var>× 100</var> ã§èšç®ãããå€ãå°æ°ç¹ä»¥äžç¬¬2äœã§åãæšãŠãå€ãšããïŒå°æ°ç¹ä»¥äžç¬¬1äœã0ã§ãã£ãŠãå°æ°ç¹ä»¥äžç¬¬1äœãŸã§åºåããïŒC/C++ã§ã®åºåäŸã¯ä»¥äžã®ããã«ãªãïŒ</p>
<pre>printf("! Game Over\n"); fflush(stdout);</pre>
<pre>printf("! Game Clear %.1lf\n", success_type_rate); fflush(stdout);</pre>
<p><b>â»printfã®æžåŒã"%.1lf"ãšããå ŽåïŒåºåãããæµ®åå°æ°ç¹æ°ã¯å°æ°ç¹ä»¥äžç¬¬2äœãåæšäºå
¥ãããïŒãã®ããïŒã¿ã€ãæåçãæµ®åå°æ°ç¹æ°ãšããŠèšç®ãïŒäžèšã®ææ³ã§åºåããå ŽåïŒæ£ããåºåçµæãåŸãããªãããšãããããšã«æ³šæããïŒ</b></p>
<h3>å
¥åºåäŸ1</h3>
<pre>
<table width="600" class="withborder">
<tr><th>ã·ã¹ãã ã®åºå</th><th>ã·ã¹ãã ãžã®å
¥åã»AIã®è¿ç</th></tr>
<tr><td></td><td>
2 5<br/>ICPC 2<br/>Tsurai 5
</td></tr>
<tr><td>? ICPC</td><td></td></tr>
<tr><td></td><td>i</td></tr>
<tr><td>? _CPC</td><td></td></tr>
<tr><td></td><td>g</td></tr>
<tr><td>? _CPC</td><td></td></tr>
<tr><td></td><td>p</td></tr>
<tr><td>? _CPC</td><td></td></tr>
<tr><td></td><td>c</td></tr>
<tr><td>? __PC</td><td></td></tr>
<tr><td></td><td>p</td></tr>
<tr><td>? ___C</td><td></td></tr>
<tr><td></td><td>c</td></tr>
<tr><td>? Tsurai</td><td></td></tr>
<tr><td></td><td>t</td></tr>
<tr><td>? _surai</td><td></td></tr>
<tr><td></td><td>s</td></tr>
<tr><td>? __urai</td><td></td></tr>
<tr><td></td><td>u</td></tr>
<tr><td>? ___rai</td><td></td></tr>
<tr><td></td><td>r</td></tr>
<tr><td>? ____ai</td><td></td></tr>
<tr><td></td><td>a</td></tr>
<tr><td>? _____i</td><td></td></tr>
<tr><td></td><td>i</td></tr>
<tr><td>! Game Clear 83.3</td><td></td></tr>
</table>
</pre>
<h3>å
¥åºåäŸ2</h3>
<pre>
<table width="600" class="withborder">
<tr><th>ã·ã¹ãã ã®åºå </th><th>ã·ã¹ãã ãžã®å
¥åã»AIã®è¿ç</th></tr>
<tr><td></td><td>
2 1<br/>ICPC 1<br/>Tsurai 1
</td></tr>
<tr><td>? ICPC</td><td></td></tr>
<tr><td></td><td>i</td></tr>
<tr><td>? _CPC</td><td></td></tr>
<tr><td></td><td>c</td></tr>
<tr><td>? __PC</td><td></td></tr>
<tr><td></td><td>o</td></tr>
<tr><td>? __PC</td><td></td></tr>
<tr><td></td><td>p</td></tr>
<tr><td>? ___C</td><td></td></tr>
<tr><td></td><td>d</td></tr>
<tr><td>! Game Over</td><td></td></tr>
<tr><td></td><td></td></tr>
</table>
</pre> |
p02856 | <span class="lang-en">
<p>Score: <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p><var>N</var> programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most <var>9</var> contestants can participate in the finals.</p>
<p>The preliminary stage consists of several rounds, which will take place as follows:</p>
<ul>
<li>All the <var>N</var> contestants will participate in the first round.</li>
<li>When <var>X</var> contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:<ul>
<li>The organizer will choose two consecutive digits in the decimal notation of <var>X</var>, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round.<br/>
For example, when <var>X = 2378</var>, the number of contestants advancing to the next round will be <var>578</var> (if <var>2</var> and <var>3</var> are chosen), <var>2108</var> (if <var>3</var> and <var>7</var> are chosen), or <var>2315</var> (if <var>7</var> and <var>8</var> are chosen).<br/>
When <var>X = 100</var>, the number of contestants advancing to the next round will be <var>10</var>, no matter which two digits are chosen.</li>
</ul>
</li>
<li>The preliminary stage ends when <var>9</var> or fewer contestants remain.</li>
</ul>
<p>Ringo, the chief organizer, wants to hold as many rounds as possible.
Find the maximum possible number of rounds in the preliminary stage.</p>
<p>Since the number of contestants, <var>N</var>, can be enormous, it is given to you as two integer sequences <var>d_1, \ldots, d_M</var> and <var>c_1, \ldots, c_M</var>, which means the following: the decimal notation of <var>N</var> consists of <var>c_1 + c_2 + \ldots + c_M</var> digits, whose first <var>c_1</var> digits are all <var>d_1</var>, the following <var>c_2</var> digits are all <var>d_2</var>, <var>\ldots</var>, and the last <var>c_M</var> digits are all <var>d_M</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq M \leq 200000</var></li>
<li><var>0 \leq d_i \leq 9</var></li>
<li><var>d_1 \neq 0</var></li>
<li><var>d_i \neq d_{i+1}</var></li>
<li><var>c_i \geq 1</var></li>
<li><var>2 \leq c_1 + \ldots + c_M \leq 10^{15}</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>M</var>
<var>d_1</var> <var>c_1</var>
<var>d_2</var> <var>c_2</var>
<var>:</var>
<var>d_M</var> <var>c_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the maximum possible number of rounds in the preliminary stage.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
2 2
9 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>In this case, <var>N = 229</var> contestants will participate in the first round. One possible progression of the preliminary stage is as follows:</p>
<ul>
<li><var>229</var> contestants participate in Round <var>1</var>, <var>49</var> contestants participate in Round <var>2</var>, <var>13</var> contestants participate in Round <var>3</var>, and <var>4</var> contestants advance to the finals.</li>
</ul>
<p>Here, three rounds take place in the preliminary stage, which is the maximum possible number. </p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 1
0 8
7 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9
</pre>
<p>In this case, <var>1000000007</var> will participate in the first round. </p></section>
</div>
</span> |
p01283 |
<H1><font color="#000">Problem A:</font> Strange String Manipulation</H1>
<p>
A linear congruential generator produces a series R(⋅) of pseudo-random numbers by the following for-
mulas:
</p>
<!--
<p>
R(0) = S , R(i) = (A · R(i â 1) + C) mod M (for i = 1, 2, . . .),
</p>
-->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_strangeString1">
</center>
<p>
where <i>S</i>, <i>A</i>, <i>C</i>, and <i>M</i> are all parameters. In this problem, 0 ≤ <i>S</i>, <i>A</i>, <i>C</i> ≤ 15 and <i>M</i> = 256.
</p>
<p>
Now suppose we have some input string <i>I</i>(⋅), where each character in the string is an integer between 0
and (<i>M</i> - 1). Then, using the pseudo-random number series <i>R</i>(⋅), we obtain another string <i>O</i>(⋅) as the
output by the following formula:
</p>
<!--
<p>
O(i) = (I(i) + R(i)) mod M (for i = 1, 2, . . .),
</p>
-->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_strangeString2">
</center>
<p>
Your task is to write a program that shows the parameters <i>S</i>, <i>A</i>, and <i>C</i> such that the information entropy of the output string <i>O</i>(⋅) is minimized. Here, the information entropy <i>H</i> is given by the following formula:
</p>
<!--
#(x) #(x)
log
H=â
N N
x
-->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_strangeString3">
</center>
<p>
where <i>N</i> is the length of the string and #(<i>x</i>) is the number of occurences of the alphabet <i>x</i>.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset has the following format:
</p>
<p>
<i>N</i><br>
<i>I</i>(1) <i>I</i>(2) ... <i>I</i>(<i>N</i>)<br>
</p>
<p>
<i>N</i> does not exceed 256.
</p>
<p>
The last dataset is followed by a line containing one zero. This line is not a part of any dataset and should not be processed.
</p>
<H2>Output</H2>
<p>
For each dataset, print in a line the values of the three parameters <i>S</i>, <i>A</i>, and <i>C</i> separated by a single space. If more than one solution gives the same minimum entropy, choose the solution with the smallest <i>S</i>, <i>A</i>, and then <i>C</i>.
</p>
<H2>Sample Input</H2>
<pre>
5
5 4 3 2 1
5
7 7 7 7 7
10
186 8 42 24 154 40 10 56 122 72
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0 1 1
0 0 0
8 7 14
</pre>
|
p03314 | <span class="lang-en">
<p>Score : <var>1100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given integers <var>N, K</var>, and an integer sequence <var>A</var> of length <var>M</var>.</p>
<p>An integer sequence where each element is between <var>1</var> and <var>K</var> (inclusive) is said to be <em>colorful</em> when there exists a contiguous subsequence of length <var>K</var> of the sequence that contains one occurrence of each integer between <var>1</var> and <var>K</var> (inclusive).</p>
<p>For every colorful integer sequence of length <var>N</var>, count the number of the contiguous subsequences of that sequence which coincide with <var>A</var>, then find the sum of all the counts.
Here, the answer can be extremely large, so find the sum modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 25000</var></li>
<li><var>1 \leq K \leq 400</var></li>
<li><var>1 \leq M \leq N</var></li>
<li><var>1 \leq A_i \leq K</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var> <var>M</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>For every colorful integer sequence of length <var>N</var>, count the number of the contiguous subsequences of that sequence which coincide with <var>A</var>, then print the sum of all the counts modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2 1
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>9
</pre>
<p>There are six colorful sequences of length <var>3</var>: <var>(1,1,2)</var>, <var>(1,2,1)</var>, <var>(1,2,2)</var>, <var>(2,1,1)</var>, <var>(2,1,2)</var> and <var>(2,2,1)</var>.
The numbers of the contiguous subsequences of these sequences that coincide with <var>A=(1)</var> are <var>2</var>, <var>2</var>, <var>1</var>, <var>2</var>, <var>1</var> and <var>1</var>, respectively.
Thus, the answer is their sum, <var>9</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 2 2
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>12
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7 4 5
1 2 3 1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>17
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>5 4 3
1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>10 3 5
1 1 2 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>1458
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 6</h3><pre>25000 400 4
3 7 31 127
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 6</h3><pre>923966268
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 7</h3><pre>9954 310 12
267 193 278 294 6 63 86 166 157 193 168 43
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 7</h3><pre>979180369
</pre></section>
</div>
</span> |
p01329 |
<h1><font color="#000">Problem I:</font> çãŸããå®ç³</h1>
<p>ãã«çåœã®åœå®ã§ããå®ç³ãçè³ãã¡ã«çãŸããã åéºè
ã®ããªãã¯ãã®åãèãã€ããŠçè³ã®ã¢ãžãã«åããããªããšãå®ç³ãåãæ»ãããšãåºæ¥ãã</p>
<p>ãšããããå®ç³ããã«çåœã®åãžè¿ãã«åºåãããšãããåã®å®è¡å
µããã ãæãçã¯ãŸã ããªããå®å
šã«ä¿¡çšããŠããªãããã®å®ç³ãæ¬ç©ãã©ããæªããããããããå®ç³ãåãæ»ãããšããã®ããŠãœã§ãçã®åœãçãçè³ã®ä»²éãªã®ã§ã¯ãªããïŒãšçã£ãŠãããããã ãšããããã</p>
<p>ããªãã¯ãå®è¡å
µããæ¬åœã«ä¿¡é Œã§ãã人ç©ãã©ãã詊ãããã®è©Šç·Žãäžããããã詊緎ã®å
容ã¯ã ãåã®å°äžå庫ãžè¡ãæå®ãããå Žæã«å®ç³ã眮ããããã«å®ç³ãæ¬ç©ã ã£ããšãã«åå¿ããéæ³é£ãæžãããŠããããã ãããªããæªããè¡åãèµ·ãããªãããã«ãããããå°äžå庫ã®å
¥ãå£ããæå®ãããå Žæã«åãããŸã§ãå®è¡å
µãèšã£ãç§»åãã¿ãŒã³ããšã£ãŠã¯ãªããªããã ãšãããã®ã ã£ãã</p>
<p>äŸãã°ãäžå³ã«ããå°äžå庫ã®åœ¢ç¶ãçŠæ¢ãã¿ãŒã³ã«å¯Ÿããå³ã«ããããŠãããããªç§»åãã¿ãŒã³ãåã£ãŠã¯ãªããªããç§»åãã¿ãŒã³ã®äžéš(èµ€ããã€ã©ã€ããããŠãã)ããçŠæ¢ãã¿ãŒã³ã®äžã«å«ãŸããããã§ããã(ãŸãããã®ç§»åãã¿ãŒã³ã®äžã®2,3çªç®ã®åãã↓↓ããçŠæ¢ãã¿ãŒã³ã®äžã«å«ãŸãã)</p>
<center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_stolenjewel1"></center>
<p>äžæ¹ã äžå³ã®ãããªç§»åãã¿ãŒã³ã¯ãç§»åãã¿ãŒã³ã®ã©ã®éšåãçŠæ¢ãã¿ãŒã³ã®äžã«å«ãŸããªãã®ã§èš±ãããã</p>
<center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_stolenjewel2"></center>
<p>å
¥åãšããŠãå°äžå庫ã®åœ¢ç¶ãçŠæ¢ãã¿ãŒã³ãäžãããããçŠæ¢ãã¿ãŒã³ãåããã«ãå
¥ãå£ããéæ³é£ãžç§»åããã®ã«æäœéå¿
èŠãªç§»ååæ°ãæ±ããã</p>
<h2>Input</h2>
<p>å
¥åã«ã¯ãå°äžå庫ã®åœ¢ç¶ãšçŠæ¢ãã¿ãŒã³ãå«ãŸããã</p>
<p>å°äžå庫ã®åœ¢ç¶ã¯ã以äžã®ããã«è¡šãããã ãŸããäºã€ã®æŽæ° N,M ãäžãããããããããå°äžå庫ã®è¡æ°ãšåæ°ãæå³ããã(1 ≤ N,M ≤ 50)</p>
<p>ç¶ããŠãããããMåã®æåãããªãæååãNè¡äžããããã å«ãŸããæåãšãã®æå³ã¯ä»¥äžã®éãã§ããã</p>
<center>
<table>
<tr><th>æå</th><th>æå³</th></tr>
<tr><td><span style="font-family: monospace">S</span></td><td>å°äžå庫ã®å
¥ãå£ãäžã€ã®å°äžå庫ã«ã€ãå¿
ãäžã€ã ãå«ãŸããã</td></tr>
<tr><td><span style="font-family: monospace">G</span></td><td>éæ³é£ãäžã€ã®å°äžå庫ã«ã€ãå¿
ãäžã€ã ãå«ãŸããã</td></tr>
<tr><td><span style="font-family: monospace">.</span></td><td>éè·¯ã(çŠæ¢ãã¿ãŒã³ããšããªããã°)éãããšãåºæ¥ãã</td></tr>
<tr><td><span style="font-family: monospace">#</span></td><td>å£ãå£ã®äžãéãããšã¯ã§ããªãã</td></tr>
</table>
</center>
<p>次ã«ãçŠæ¢ãã¿ãŒã³ãäžãããããçŠæ¢ãã¿ãŒã³ã¯ä»¥äžã®ããã«è¡šãããã ãŸããäžã€ã®æŽæ° P ãäžãããããçŠæ¢ãã¿ãŒã³ã®æ°ãæå³ããã(0 ≤ P ≤ 10)</p>
<p>ç¶ããŠãçŠæ¢ãã¿ãŒã³ãæå³ããæååãPè¡ã«ããã£ãŠäžããããã çŠæ¢ãã¿ãŒã³ã«å«ãŸããæåãšãã®æå³ã¯ä»¥äžã®éãã§ããã</p>
<center>
<table>
<tr><th>æå</th><th>æå³</th></tr>
<tr><td><span style="font-family: monospace">U</span></td><td>↑ã®ç§»åã</td></tr>
<tr><td><span style="font-family: monospace">R</span></td><td>→ã®ç§»åã</td></tr>
<tr><td><span style="font-family: monospace">D</span></td><td>↓ã®ç§»åã</td></tr>
<tr><td><span style="font-family: monospace">L</span></td><td>←ã®ç§»åã</td></tr>
</table>
</center>
<p>çŠæ¢ãã¿ãŒã³ã®é·ãã¯1以äžã10以äžã§ããã ããçŠæ¢ãã¿ãŒã³ããå¥ã®çŠæ¢ãã¿ãŒã³ã®éšåæååãšãªã£ãŠããããšãããããŸããåäžã®çŠæ¢ãã¿ãŒã³ãå«ãŸããããšãããã
</p>
<h2>Output</h2>
<p>æäœéå¿
èŠãªç§»ååæ°ãæå³ããæŽæ°ãåºåãããéæ³é£ãžèŸ¿ãã€ããªãå Žå㯠-1 ãåºåããã
</p>
<h2>Notes on Test Cases</h2>
<p>
äžèšå
¥å圢åŒã§è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã«å¯ŸããŠäžèšåºå圢åŒã§åºåãè¡ãããã°ã©ã ãäœæããŠäžããã
</p>
<p>
n, m ã 0 ã®ãšãå
¥åã®çµããã瀺ããŸãã
</p>
<!--
<h2>Sample Input 1</h2>
<pre>
7 6
......
.####.
.####.
...S#.
...##.
...##.
.....G
3
LD
DD
LLL
</pre>
<h2>Output for Sample Input 1</h2>
<pre>13
</pre>
<h2>Sample Input 2</h2>
<pre>7 8
S#......
.#.####.
.#.#G.#.
.#.##.#.
.#....#.
.######.
........
8
DDDD
DDDU
UUUU
UUUD
RRRR
RRRL
LLLL
LLLR
</pre>
<h2>Output for Sample Input 2</h2>
<pre>60
</pre>
<h2>Sample Input 3</h2>
<pre>3 8
########
S......G
########
2
U
D
</pre>
<h2>Output for Sample Input 3</h2>
<pre>7
</pre>
<h2>Sample Input 4</h2>
<pre>6 10
..........
.S........
..........
..........
........G.
..........
0
</pre>
<h2>Output for Sample Input 4</h2>
<pre>10
</pre>
<h2>Sample Input 5</h2>
<pre>6 7
.......
...#...
...#.S.
...###.
.G.....
.......
2
LL
DD
</pre>
<h2>Output for Sample Input 5</h2>
<pre>-1
</pre>
-->
<h2>Sample Input</h2>
<pre>
7 6
......
.####.
.####.
...S#.
...##.
...##.
.....G
3
LD
DD
LLL
7 8
S#......
.#.####.
.#.#G.#.
.#.##.#.
.#....#.
.######.
........
8
DDDD
DDDU
UUUU
UUUD
RRRR
RRRL
LLLL
LLLR
3 8
########
S......G
########
2
U
D
6 10
..........
.S........
..........
..........
........G.
..........
0
6 7
.......
...#...
...#.S.
...###.
.G.....
.......
2
LL
DD
0 0
</pre>
<h2>Output for Sample Input</h2>
<pre>
13
60
7
10
-1
</pre>
|
p00168 |
<H1>芳é³å </H1>
<p>
äžéåã®å®¶ã®è£å±±ã«ã¯èгé³å ããããŸãããã®èгé³å ãŸã§ã¯ãµããšãã 30 段ã®é段ããããäžéåã¯ãæ¯æ¥ã®ããã«èгé³å ãŸã§éã³ã«è¡ããŸããäžéåã¯é段ãïŒè¶³ã§ïŒæ®µãŸã§äžããããšãã§ããŸããéãã§ãããã¡ã«é段ã®äžãæ¹ã®çš®é¡ïŒæ®µã®é£ã°ãæ¹ã®åæ°ïŒãéåžžã«ããããããããšã«æ°ãã€ããŸããã
</p>
<p>
ããã§ãäžæ¥ã« 10 çš®é¡ã®äžãæ¹ããããã¹ãŠã®äžãæ¹ã詊ãããšèããŸããããããæ°åŠãçç¥ããŠããããªãã¯ãããªããšã§ã¯äžéåã®å¯¿åœãå°œããŠããŸãããšãç¥ã£ãŠããã¯ãã§ãã
</p>
<p>
äžéåã®èšç»ãå®çŸäžå¯èœã§ããããšãäžéåã«çŽåŸãããããã«ãéæ®µã®æ®µæ° <var>n</var> ãå
¥åãšããäžæ¥ã« 10 çš®é¡ã®äžãæ¹ããããšããŠãäžéåããã¹ãŠã®äžãæ¹ãå®è¡ããã®ã«èŠãã幎æ°ãåºåããããã°ã©ã ãäœæããŠãã ãããäžå¹Žã¯ 365 æ¥ãšããŠèšç®ããŠãã ãããäžæ¥ã§ãå¿
èŠãªãäžå¹ŽãšããŸãã365 æ¥ãªã 1 幎ã§ããã366 æ¥ãªã 2 幎ãšãªããŸãã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã
åããŒã¿ã»ãããšããŠã段æ°ã衚ãïŒã€ã®æŽæ° <var>n</var> (1 ≤ <var>n</var> ≤ 30) ãïŒè¡ã«äžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 30 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããããšã«äžéåããã¹ãŠã®äžãæ¹ãå®è¡ããã®ã«å¿
èŠãªå¹Žæ°ïŒæŽæ°ïŒãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
1
10
20
25
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1
1
34
701
</pre>
|
p02155 | <h1>Problem G: First Kiss</h1>
<h2>Problem</h2>
<p>
ãããåã®éãç·åæ ¡ã§ã¯æŒäŒã¿ã«ããããŒã²ãŒã ãè¡ãããŠããã<br>
ãã®åŠæ ¡ã®ããããŒã²ãŒã ã¯å°ãå€ãã£ãŠããããšã§æåã ã<br>
ãŸãã$N$æ¬ã®ããããŒãçšæããã$i$æ¬ç®ã®ããããŒã®é·ãã¯$a_i$ã§ããã<br>
å
æãšåŸæã亀äºã«ããããŒãé£ã¹ãã<br>
ãããé·ãã®ããããŒãäžæ°ã«é£ã¹ããšåã«åºãã£ãŠããŸãã®ã§ã$1$以äž$D$以äžã®å¥œããªé·ãã ãé£ã¹ãã<br>
圌ãã¯äžåšçšãªã®ã§ãæŽæ°é·ã§ã®ã¿ããããŒãé£ã¹ãããšãã§ããã<br>
æåã«ããããã®ããããŒãé£ã¹ã€ãããããšããé£ã¹ãã£ã人ã®è² ããšãªãã<br>
äž¡è
ãæé©ã«è¡åãããšããå
æãåã€ãªã"First"ãåŸæãåã€ãªã"Second"ãåºåããã<br>
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
$N$ $D$
$a_1$ $a_2$ $...$ $a_N$
</pre>
<p>
å
¥åã¯ãã¹ãп޿°ã§äžããããã
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>$1 \le N \le 3\times 10^5$</li>
<li>$1 \le D \le 10^9$</li>
<li>$1 \le a_i \le 10^9$</li>
</ul>
<h2>Output</h2>
<p>
äž¡è
ãæé©ã«è¡åãããšããã©ã¡ããåã€ãåºåããã<br>
å
æãåã€ãªã"First"ãåŸæãåã€ãªã"Second"ãåºåããã<br>
</p>
<h2>Sample Input 1</h2>
<pre>
1 1
2
</pre>
<h2>Sample Output 1</h2>
<pre>
First
</pre>
<h2>Sample Input 2</h2>
<pre>
2 25
19 19
</pre>
<h2>Sample Output 2</h2>
<pre>
Second
</pre>
<h2>Sample Input 3</h2>
<pre>
3 5
10 8 4
</pre>
<h2>Sample Output 3</h2>
<pre>
First
</pre>
<h2>Sample Input 4</h2>
<pre>
4 10
3 8 5 2
</pre>
<h2>Sample Output 4</h2>
<pre>
Second
</pre>
|
p00492 |
<H1>ã€ã«ãããŒã·ã§ã³ (Illumination) </H1>
<h2> åé¡</h2>
<p>
JOI 瀟ã®å»ºç©ã¯å³ã®ãã㪠1 蟺 1 ã¡ãŒãã«ã®æ£å
è§åœ¢ãã€ãªãåããã圢ã§ããïŒã¯ãªã¹ãã¹ãè¿ã¥ããŠããã®ã§ïŒJOI 瀟ã§ã¯å»ºç©ã®å£é¢ãã€ã«ãããŒã·ã§ã³ã§é£Ÿãä»ããããšã«ããïŒãã ãïŒå€ããèŠããªãéšåã«ã€ã«ãããŒã·ã§ã³ãæœãã®ã¯ç¡é§ãªã®ã§ïŒã€ã«ãããŒã·ã§ã³ã¯å€ãã建ç©ã®äžãéããã«è¡ãããšã®ã§ããå£é¢ã«ã®ã¿é£Ÿãä»ããããšã«ããïŒ
</p>
<center>
<p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_2012-yo-t5-fig01"><br>å³: JOI 瀟ã®å»ºç©ã®é
眮ã®äŸ</p>
</center>
<p>
äžã®å³ã¯äžç©ºããèŠã JOI 瀟ã®å»ºç©ã®é
眮ã®äŸã§ããïŒæ£å
è§åœ¢å
ã®æ°åã¯åº§æšã衚ãïŒç°è²ã®æ£å
è§åœ¢ã¯å»ºç©ãããå Žæã衚ãïŒçœè²ã®æ£å
è§åœ¢ã¯å»ºç©ããªãå Žæã衚ãïŒãã®äŸã§ã¯ïŒèµ€ã®å®ç·ã§ç€ºãããéšåãã€ã«ãããŒã·ã§ã³ã§é£Ÿãä»ããè¡ãå£é¢ãšãªãïŒãã®å£é¢ã®é·ãã®åèšã¯ 64 ã¡ãŒãã«ãšãªãïŒ
</p>
<p>
JOI 瀟ã®å»ºç©ã®é
眮ã衚ãå°å³ãäžãããããšãïŒé£Ÿãä»ããè¡ãå£é¢ã®é·ãã®åèšãæ±ããããã°ã©ã ãäœæããïŒãã ãïŒå°å³ã®å€åŽã¯èªç±ã«è¡ãæ¥ã§ãããã®ãšãïŒé£æ¥ãã建ç©ã®éã¯éãããšã¯ã§ããªããã®ãšããïŒ
</p>
<h2> å
¥å</h2>
<p>
å
¥åãã¡ã€ã«ã® 1 è¡ç®ã«ã¯ 2 ã€ã®æŽæ° W, H (1 ⊠W ⊠100ïŒ1 ⊠H ⊠100) ã空çœãåºåããšããŠæžãããŠããïŒç¶ã H è¡ã«ã¯ JOI 瀟ã®å»ºç©ã®é
çœ®ãæžãããŠããïŒi + 1 è¡ç® (1 ⊠i ⊠H) ã«ã¯ W åã®æŽæ°ã空çœãåºåããšããŠæžãããŠããïŒj åç® (1 ⊠j ⊠W) ã®æŽæ°ã¯åº§æš (j, i) ã®æ£å
è§åœ¢ã«å»ºç©ãããæã¯ 1 ã§ããïŒãªãæã¯ 0 ã§ããïŒãŸãïŒäžããããå
¥åããŒã¿ã«ã¯å»ºç©ãå¿
ã 1 ã€ä»¥äžããïŒ
</p>
<p>
å°å³ã¯ä»¥äžã®èŠåã«ãã£ãŠèšè¿°ãããŠããïŒ
</p>
<ul>
<li>å°å³ã®æãåã®è¡ã®æãè¥¿ã®æ£å
è§åœ¢ã¯åº§æš (1, 1) ã§ããïŒ</li>
<li>åº§æš (x, y) ã®æ£å
è§åœ¢ã«é£æ¥ããæ±é£ã®æ£å
è§åœ¢ã¯åº§æš (x + 1, y) ã§ããïŒ</li>
<li>y ã奿°ã®æïŒåº§æš (x, y) ã®æ£å
è§åœ¢ã«é£æ¥ããåè¥¿ã®æ£å
è§åœ¢ã®åº§æšã¯ (x, y + 1) ã§ããïŒ</li>
<li>y ãå¶æ°ã®æïŒåº§æš (x, y) ã®æ£å
è§åœ¢ã«é£æ¥ããåæ±ã®æ£å
è§åœ¢ã®åº§æšã¯ (x, y + 1) ã§ããïŒ</li>
</ul>
<h2> åºå</h2>
<p>
ã€ã«ãããŒã·ã§ã³ã§é£Ÿãä»ããè¡ãå£é¢ã®é·ãã®åèšã 1 è¡ã§åºåããïŒ
</p>
<h2> å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
8 4
0 1 0 1 0 1 1 1
0 1 1 0 0 1 0 0
1 0 1 0 1 1 1 1
0 1 1 0 1 0 1 0
</pre>
<h3>åºåäŸ 1</h3>
<pre>
64
</pre>
<p>
å
¥åºåäŸ 1 ã¯å顿äžã®äŸã«å¯Ÿå¿ããŠããïŒã€ã«ãããŒã·ã§ã³ã§é£Ÿãä»ããè¡ãå£é¢ã®é·ãã®åèšã¯ 64 ã¡ãŒãã«ã§ããïŒ
</p>
<h3>å
¥åäŸ 2</h3>
<pre>
8 5
0 1 1 1 0 1 1 1
0 1 0 0 1 1 0 0
1 0 0 1 1 1 1 1
0 1 0 1 1 0 1 0
0 1 1 0 1 1 0 0
</pre>
<h3>åºåäŸ 2</h3>
<pre>
56
</pre>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p00538 |
<h2>ã±ãŒãã®åãåãïŒ (Cake 2)</h2>
<p>
JOI ãããš IOI ã¡ããã¯ååã®å
効ã§ããïŒJOI ããã¯æè¿ãèåäœãã«åã£ãŠããŠïŒä»æ¥ã JOI ããã¯ã±ãŒããçŒããŠé£ã¹ãããšããã®ã ãïŒçŒãããã£ããšããã§åããããã€ãã IOI ã¡ãããæ¥ãã®ã§ 2人ã§ã±ãŒããåããããšã«ãªã£ãïŒ
</p>
<p>
ã±ãŒãã¯å圢ã§ããïŒããç¹ããæŸå°ç¶ã«åãç®ãå
¥ãïŒã±ãŒãã <var>N</var> åã®ããŒã¹ã«åãåãïŒããŒã¹ã« 1 ãã <var>N</var> ãŸã§åæèšåãã«çªå·ãã€ããïŒã€ãŸãïŒ1 ≤ <var>i</var> ≤ <var>N</var> ã«å¯ŸãïŒ<var>i</var> çªç®ã®ããŒã¹ã¯ <var>i</var> â 1 çªç®ãš <var>i</var> + 1 çªç®ã®ããŒã¹ãšé£æ¥ããŠãã (ãã ã 0 çªç®ã¯ <var>N</var> çªç®ïŒ<var>N</var> + 1 çªç®ã¯ 1 çªç®ãšã¿ãªã) ïŒ<var>i</var> çªç®ã®ããŒã¹ã®å€§ãã㯠<var>A<sub>i</sub></var> ã ã£ããïŒåãæ¹ããšãŠãäžæã ã£ãã®ã§ <var>A<sub>i</sub></var> ã¯ãã¹ãŠç°ãªãå€ã«ãªã£ãïŒ
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2014_cake2"><br>
å³ 1: ã±ãŒãã®äŸ (<var>N</var> = 5, <var>A<sub>1</sub></var> = 2, <var>A<sub>2</sub></var> = 8, <var>A<sub>3</sub></var> = 1, <var>A<sub>4</sub></var> = 10, <var>A<sub>5</sub></var> = 9)
</center>
<br>
<p>
ãã® <var>N</var> åã JOI ãããš IOI ã¡ããã§åããããšã«ããïŒåãæ¹ã¯æ¬¡ã®ããã«ããããšã«ããïŒ
</p>
<ol>
<li> ãŸã JOI ããã <var>N</var> åã®ãã¡ã®å¥œã㪠1 ã€ãéžãã§åãïŒ</li>
<li> ãã®åŸïŒIOI ã¡ããããã¯ãã㊠IOI ã¡ãããš JOI ããã亀äºã«æ®ãã®ããŒã¹ã 1 ã€ãã€åã£ãŠããïŒãã ãïŒäž¡é£ã®ããŒã¹ã®ãã¡å°ãªããšãäžæ¹ãæ¢ã«åãããŠãããããªããŒã¹ããåãããšãã§ããïŒåããããŒã¹ãè€æ°ãããšãã¯ïŒIOI ã¡ããã¯ãã®ãã¡æã倧ãããã®ãéžãã§åãïŒJOI ããã¯ãã®ãã¡ã§å¥œããªãã®ãéžãã§åãããšãã§ããïŒ
</li>
</ol>
<p>
JOI ããã¯ïŒèªåãæçµçã«åãããŒã¹ã®å€§ããã®åèšãæå€§åãããïŒ
</p>
<h3>課é¡</h3>
<p>
ã±ãŒãã®ããŒã¹ã®æ° <var>N</var> ãšïŒ<var>N</var> åã®ããŒã¹ã®å€§ããã®æ
å ±ãäžãããããšãïŒJOI ãããåããããŒã¹ã®å€§ããã®åèšã®æå€§å€ãæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h3>å
¥å</h3>
<p>
æšæºå
¥åãã以äžã®å
¥åãèªã¿èŸŒãïŒ
</p>
<ul>
<li> 1 è¡ç®ã«ã¯æŽæ° <var>N</var> ãæžãããŠããïŒã±ãŒãã <var>N</var> åã®ããŒã¹ã«åãåããããŠããããšã衚ãïŒ</li>
<li> ç¶ã <var>N</var> è¡ã®ãã¡ã® <var>i</var> è¡ç® (1 ≤ <var>i</var> ≤ <var>N</var>) ã«ã¯æŽæ° <var>A<sub>i</sub></var> ãæžãããŠããïŒ<var>i</var> çªç®ã®ããŒã¹ã®å€§ããã <var>A<sub>i</sub></var> ã§ããããšã衚ãïŒ
</li>
</ul>
<h3>åºå</h3>
<p>
æšæºåºåã«ïŒJOI ãããåããããŒã¹ã®å€§ããã®åèšã®æå€§å€ãè¡šãæŽæ°ã 1 è¡ã§åºåãã.
</p>
<h3>å¶é</h3>
<p>
ãã¹ãŠã®å
¥åããŒã¿ã¯ä»¥äžã®æ¡ä»¶ãæºããïŒ
</p>
<ul>
<li> 1 ≤ <var>N</var> ≤ 2 000ïŒ </li>
<li> 1 ≤ <var>A<sub>i</sub></var> ≤ 1 000 000 000ïŒ</li>
<li> <var>A<sub>i</sub></var> ã¯ãã¹ãŠç°ãªãïŒ</li>
</ul>
<h3>å
¥åºåäŸ</h3>
<h3>å
¥åäŸ 1 </h3>
<pre>
5
2
8
1
10
9
</pre>
<h3>åºåäŸ 1</h3>
<pre>
18
</pre>
<p>
JOI ããã¯ïŒæ¬¡ã®ããã«ããŒã¹ãåãã®ãæé©ã§ããïŒ
</p>
<ol>
<li> JOI ãã㯠2 çªç®ã®ããŒã¹ãåãïŒãã®ããŒã¹ã®å€§ãã㯠8 ã§ããïŒ</li>
<li> IOI ã¡ãã㯠1 çªç®ã®ããŒã¹ãåãïŒãã®ããŒã¹ã®å€§ãã㯠2 ã§ããïŒ</li>
<li> JOI ãã㯠5 çªç®ã®ããŒã¹ãåãïŒãã®ããŒã¹ã®å€§ãã㯠9 ã§ããïŒ</li>
<li> IOI ã¡ãã㯠4 çªç®ã®ããŒã¹ãåãïŒãã®ããŒã¹ã®å€§ãã㯠10 ã§ããïŒ</li>
<li> JOI ãã㯠3 çªç®ã®ããŒã¹ãåãïŒãã®ããŒã¹ã®å€§ãã㯠1 ã§ããïŒ</li>
</ol>
<p>
æçµçã«ïŒJOI ãããåã£ãããŒã¹ã®å€§ããã®åèšã¯ïŒ8 + 9 + 1 = 18 ãšãªã.
</p>
<h3>å
¥åäŸ 2 </h3>
<pre>
8
1
10
4
5
6
2
9
3
</pre>
<h3>åºåäŸ 2</h3>
<pre>
26
</pre>
<h3>å
¥åäŸ 3</h3>
<pre>
15
182243672
10074562
977552215
122668426
685444213
3784162
463324752
560071245
134465220
21447865
654556327
183481051
20041805
405079805
564327789
</pre>
<h3>åºåäŸ 3</h3>
<pre>
3600242976
</pre>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.