question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p03673 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer sequence of length <var>n</var>, <var>a_1, ..., a_n</var>.
Let us consider performing the following <var>n</var> operations on an empty sequence <var>b</var>.</p>
<p>The <var>i</var>-th operation is as follows:</p>
<ol>
<li>Append <var>a_i</var> to the end of <var>b</var>.</li>
<li>Reverse the order of the elements in <var>b</var>.</li>
</ol>
<p>Find the sequence <var>b</var> obtained after these <var>n</var> operations.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq n \leq 2\times 10^5</var></li>
<li><var>0 \leq a_i \leq 10^9</var></li>
<li><var>n</var> and <var>a_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>a_1</var> <var>a_2</var> <var>...</var> <var>a_n</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>n</var> integers in a line with spaces in between.
The <var>i</var>-th integer should be <var>b_i</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
1 2 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4 2 1 3
</pre>
<ul>
<li>After step 1 of the first operation, <var>b</var> becomes: <var>1</var>.</li>
<li>After step 2 of the first operation, <var>b</var> becomes: <var>1</var>.</li>
<li>After step 1 of the second operation, <var>b</var> becomes: <var>1, 2</var>.</li>
<li>After step 2 of the second operation, <var>b</var> becomes: <var>2, 1</var>.</li>
<li>After step 1 of the third operation, <var>b</var> becomes: <var>2, 1, 3</var>.</li>
<li>After step 2 of the third operation, <var>b</var> becomes: <var>3, 1, 2</var>.</li>
<li>After step 1 of the fourth operation, <var>b</var> becomes: <var>3, 1, 2, 4</var>.</li>
<li>After step 2 of the fourth operation, <var>b</var> becomes: <var>4, 2, 1, 3</var>.</li>
</ul>
<p>Thus, the answer is <code>4 2 1 3</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3 1 2
</pre>
<p>As shown above in Sample Output 1, <var>b</var> becomes <var>3, 1, 2</var> after step 2 of the third operation. Thus, the answer is <code>3 1 2</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1
1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1000000000
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>6
0 6 7 6 7 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>0 6 6 0 7 7
</pre></section>
</div>
</span> |
p02432 | <h1>Deque</h1>
<p>
For a dynamic array $A = \{a_0, a_1, ...\}$ of integers, perform a sequence of the following operations:
</p>
<ul>
<li>push($d$, $x$): Add element $x$ at the begining of $A$, if $d = 0$. Add element $x$ at the end of $A$, if $d = 1$.</li>
<li>randomAccess($p$): Print element $a_p$.</li>
<li>pop($d$): Delete the first element of $A$, if $d = 0$. Delete the last element of $A$, if $d = 1$.</li>
</ul>
<p>
$A$ is a 0-origin array and it is empty in the initial state.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$q$
$query_1$
$query_2$
:
$query_q$
</pre>
<p>
Each query $query_i$ is given by
</p>
<pre>
0 $d$ $x$
</pre>
<p>or</p>
<pre>
1 $p$
</pre>
<p>or</p>
<pre>
2 $d$
</pre>
<p>
where the first digits <span>0</span>, <span>1</span> and <span>2</span> represent push, randomAccess and pop operations respectively.
</p>
<p>
randomAccess and pop operations will not be given for an empty array.
</p>
<h2>Output</h2>
<p>
For each randomAccess, print $a_p$ in a line.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq q \leq 400,000$</li>
<li>$0 \leq p < $ the size of $A$</li>
<li>$-1,000,000,000 \leq x \leq 1,000,000,000$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
11
0 0 1
0 0 2
0 1 3
1 0
1 1
1 2
2 0
2 1
0 0 4
1 0
1 1
</pre>
<h2>Sample Output 1</h2>
<pre>
2
1
3
4
1
</pre>
|
p02598 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> logs of lengths <var>A_1,A_2,\cdots A_N</var>.</p>
<p>We can cut these logs at most <var>K</var> times in total. When a log of length <var>L</var> is cut at a point whose distance from an end of the log is <var>t</var> <var>(0<t<L)</var>, it becomes two logs of lengths <var>t</var> and <var>L-t</var>.</p>
<p>Find the shortest possible length of the longest log after at most <var>K</var> cuts, and print it after rounding up to an integer.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2 \times 10^5</var></li>
<li><var>0 \leq K \leq 10^9</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>A_1</var> <var>A_2</var> <var>\cdots</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print an integer representing the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3
7 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<ul>
<li>First, we will cut the log of length <var>7</var> at a point whose distance from an end of the log is <var>3.5</var>, resulting in two logs of length <var>3.5</var> each.</li>
<li>Next, we will cut the log of length <var>9</var> at a point whose distance from an end of the log is <var>3</var>, resulting in two logs of length <var>3</var> and <var>6</var>.</li>
<li>Lastly, we will cut the log of length <var>6</var> at a point whose distance from an end of the log is <var>3.3</var>, resulting in two logs of length <var>3.3</var> and <var>2.7</var>.</li>
</ul>
<p>In this case, the longest length of a log will be <var>3.5</var>, which is the shortest possible result. After rounding up to an integer, the output should be <var>4</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 0
3 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 10
158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>292638192
</pre></section>
</div>
</span> |
p02062 | <h2>C: ç絡è©äŸ¡</h2>
<h3>åé¡</h3>
<p>
çŽå€§ãããšå倧ããã¯ã²ãŒã ãããŠããŸãã
å倧ããã¯ããŸã以äžã® BNF ã§è¡šãããè«çåŒãçæããŸãã
</p>
<pre>
<formula> ::= <or-expr>
<or-expr> ::= <and-expr>
| <or-expr> "|" <and-expr>
<and-expr> ::= <term>
| <and-expr> "&" <term>
<term> ::= "(" <or-expr> ")" | "?"
</pre>
<p>
<code>&</code> ã¯è«çç©ãã<code>|</code> ã¯è«çåã衚ãã<code>&</code> ã®æ¹ã <code>|</code> ããå
ã«è©äŸ¡ãããŸãã
</p>
<p>çŽå€§ããã¯ããã®è«çåŒãïŒæååãšããŠèŠãŠïŒå·Šããèªãã§ããã<code>?</code> ãèŠã€ãããšã以äžã®è¡åãããŸãã</p>
<ul>
<li>ãã® <code>?</code> ã <code>0</code> ã«ããŠã <code>1</code> ã«ããŠãè«çåŒã®è©äŸ¡çµæãå€ãããªãããšã確å®ããŠãããªããäœãããèªã¿é²ããã</li>
<li>ããã§ãªããªããå倧ããã« 1 åæãããã® <code>?</code> ã <code>0</code> ãŸã㯠<code>1</code> ã«æžãæããã</li>
</ul>
<p>è«çåŒã¯ä»¥äžã®ããã«è©äŸ¡ãããŸããããããæ®éã®è«çåŒã§ãã</p>
<pre>
(0 & ?) == 0
(1 & 0) == 0
(1 & 1) == 1
(0 | 0) == 0
(0 | 1) == 1
(1 | ?) == 1
</pre>
<p>çŽå€§ãããè«çåŒã®è©äŸ¡çµæã確å®ãããããã«æ¯æãå¿
èŠãããæå°éé¡ã¯ãããã§ãããïŒ è©äŸ¡çµæã <code>0</code> ã«ããå Žåãš <code>1</code> ã«ããå Žåã§ããããæ±ããŠãã ããã</p>
<h3>å
¥å圢åŒ</h3>
<p>äžã® BNF ã«åŸãè«çåŒãäžè¡ã§äžããããŸãã</p>
<h3>å¶çŽ</h3>
<p>è«çåŒã®é·ã㯠<var>2\times 10^5</var> ãè¶
ããªãã</p>
<h3>åºå圢åŒ</h3>
<p>è©äŸ¡çµæã <code>0</code>ã<code>1</code> ã«ããããã«å¿
èŠãªæå°éé¡ã空çœåºåãã§åºåããŠãã ããã</p>
<h3>å
¥åäŸ1</h3>
<pre>?&?|?&?|?&?</pre>
<h3>åºåäŸ1</h3>
<pre>3 2</pre>
<p>
<code>0</code> ã«ãããå Žå㯠<code>0 0 0</code> ã§æžãæã㊠<code>0&?|0&?|0&?</code> ãšãã
<code>1</code> ã«ãããå Žå㯠<code>1 1</code> ã§æžãæã㊠<code>1&1|?&?|?&?</code> ãšããã®ãæé©ã§ãã
</p>
<h3>å
¥åäŸ2</h3>
<pre>?&?&?|?&?&?</pre>
<h3>åºåäŸ2</h3>
<pre>2 3</pre>
<p>ãããã <code>0&?&?|0&?&?</code>ã<code>1&1&1|?&?&?</code> ãšãªããŸãã</p>
<h3>å
¥åäŸ3</h3>
<pre>(?|?|?)&?&?&?&?|?&?|?&?</pre>
<h3>åºåäŸ3</h3>
<pre>4 4</pre>
|
p02577 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>An integer <var>N</var> is a multiple of <var>9</var> if and only if the sum of the digits in the decimal representation of <var>N</var> is a multiple of <var>9</var>.</p>
<p>Determine whether <var>N</var> is a multiple of <var>9</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 \leq N < 10^{200000}</var></li>
<li><var>N</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If <var>N</var> is a multiple of <var>9</var>, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>123456789
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>The sum of these digits is <var>1+2+3+4+5+6+7+8+9=45</var>, which is a multiple of <var>9</var>, so <var>123456789</var> is a multiple of <var>9</var>.</p>
</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>Yes
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>31415926535897932384626433832795028841971693993751058209749445923078164062862089986280
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre></section>
</div>
</span> |
p02127 | <h1>Problem D: AABABCAC</h1>
<h2>Problem</h2>
<p>
æåå$s$,$t$ãäžããããã<br>
æåãæååéå$A=${$s$},$B=\phi$ãšããã<br>
ãã®ãšããæ¬¡ã®æäœãã§ããã ãããããè¡ãããã
</p>
<h3>æäœ</h3>
<p>
<h4>step1</h4>
å
šãŠã® $u â A$ ã«ã€ããŠã以äžã®åŠçãè¡ãã
</p>
<ol>
<li>$u$ã®å
šãŠã®éšåå(é£ç¶ã§ãªããŠããã)ããã$t$ãšçãããã®ãä»»æã«1ã€éžã¶ãéžãã éšååã®$u$ã«å¯Ÿå¿ããã€ã³ããã¯ã¹ããããã$z_1$, $z_2$, âŠ, $z_{|t|}$ãšãã(ãã ã1 $\le$ $z_1$ $\lt$ $z_2$ $\lt$ ⊠$\lt$ $z_{|t|}$ $\le$ $|u|$)ããã®ãããªéšååããªããã°æäœãçµäºããã
</li><br>
<li>éžãã éšååã®æå$u_{z_1}$, $u_{z_2}$, âŠ, $u_{z_{|t|}}$ã§ããšã®æååãåå²ãããããã$B$ã«è¿œå ããã
</li><br>
äŸãã°ã$u=$"abcdcd", $t=$"ac"ã®å Žåã¯æ¬¡ã®2éãã®åå²ã®æ¹æ³ãèããããã<br>
$u$ã®1çªç®ã®æåãš3çªç®ã®æåãéžãã å Žåã""ãš"b"ãš"dcd"ã«åå²ãããã<br>
$u$ã®1çªç®ã®æåãš5çªç®ã®æåãéžãã å Žåã""ãš"bcd"ãš"d"ã«åå²ãããã
</ol>
<p>
<h4>step2</h4>
$A$ã$B$ã«çœ®ãæãã$B$ã空ã«ããã<br>
æäœåæ°ã1å¢ããã
</p>
<h3>éšååã®äŸ</h3>
<p>
"abac"ã®éšååã¯ã
{ "" , "a" , "b" , "c" , "aa" ,"ab" , "ac" , "ba" , "bc" , "aac" , "aba" , "abc" , "bac" , "abac" }
ã§ããã<br>
"a"ã¯"abac"ã®1æåç®ããŸãã¯3æåç®ãæãåºãããšã«ãã£ãŠã§ããéšååã§ããã<br>
"ac"ã¯"abac"ã®1æåç®ãš4æåç®ããŸãã¯3æåç®ãš4æåç®ãæãåºãããšã«ãã£ãŠã§ããéšååã§ããã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
$s$
$t$
</pre>
<p>1è¡ç®ã«æåå$s$,2è¡ç®ã«æåå$t$ãäžããããã</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>1 $\le$ $|t|$ $\le$ $|s|$ $\le$ $10^5$</li>
<li>æåå$s$,$t$ã«å«ãŸããæåã¯ã¢ã«ãã¡ãããã®å€§æåãŸãã¯å°æå</li>
</ul>
<h2>Output</h2>
<p>
æäœåæ°ã®æå€§å€ãåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
AABABCAC
A
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<p>
1åç®ã®æäœã¯ã$A=${ "AABABCAC" }ã§å§ãŸãã<br>
step1ã§ã¯ã$u=$"AABABCAC"ã«å¯ŸããŠãäŸãã°4çªç®ã®æåã$t$ãšçããéšååãšããŠéžã³ã"AAB"ãš"BCAC"ã«åå²ãããããã$B$ã«è¿œå ããã<br>
step2ã§ã¯ã$A$ã$B$ã«çœ®ãæãã$B$ã空ã«ããæäœåæ°ã¯1ãšãªãã<br><br>
2åç®ã®æäœã¯ã$A=${ "AAB" , "BCAC" }ã§å§ãŸãã<br>
step1ã§ã¯ã$u=$"AAB"ã«å¯ŸããŠãäŸãã°1çªç®ã®æåã$t$ãšçããéšååãšããŠéžã³ã""ãš"AB"ã«åå²ãããããã$B$ã«è¿œå ãããæ¬¡ã«$u=$"BCAC"ã«å¯ŸããŠã3çªç®ã®æåã$t$ãšçããéšååãšããŠéžã³ã"BC"ãš"C"ã«åå²ãããããã$B$ã«è¿œå ããã<br>
step2ã§ã¯ã$A$ã$B$ã«çœ®ãæãã$B$ã空ã«ããæäœåæ°ã¯2ãšãªãã<br><br>
3åç®ã®æäœã¯ã$A=${ "" , "AB" , "BC" , "C" }ã§å§ãŸãã<br>
step1ã§ã¯ã$u=$""ã«å¯ŸããŠã$t$ãšçããéšååãååšããªããããããã§æäœãçµäºããã<br><br>
ãã®äŸã®å Žåã3åç®ã®æäœã§ã¯step1ã§æäœãçµäºãããããæäœåæ°ã¯2ãšãªãã
</p>
<h2>Sample Input 2</h2>
<pre>
abaabbabaabaabbabbabaabbab
ab
</pre>
<h2>Sample Output 2</h2>
<pre>
3
</pre>
<h2>Sample Input 3</h2>
<pre>
AbCdEfG
aBcDeFg
</pre>
<h2>Sample Output 3</h2>
<pre>
0
</pre>
|
p03366 | <span class="lang-en">
<p>Score : <var>1200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> apartments along a number line, numbered <var>1</var> through <var>N</var>.
Apartment <var>i</var> is located at coordinate <var>X_i</var>.
Also, the office of AtCoder Inc. is located at coordinate <var>S</var>.
Every employee of AtCoder lives in one of the <var>N</var> apartments.
There are <var>P_i</var> employees who are living in Apartment <var>i</var>.</p>
<p>All employees of AtCoder are now leaving the office all together.
Since they are tired from work, they would like to get home by the company's bus.
AtCoder owns only one bus, but it can accommodate all the employees.
This bus will leave coordinate <var>S</var> with all the employees and move according to the following rule:</p>
<ul>
<li>
<p>Everyone on the bus casts a vote on which direction the bus should proceed, positive or negative. (The bus is autonomous and has no driver.) Each person has one vote, and abstaining from voting is not allowed. Then, the bus moves a distance of <var>1</var> in the direction with the greater number of votes. If a tie occurs, the bus moves in the negative direction. If there is an apartment at the coordinate of the bus after the move, all the employees who live there get off.</p>
</li>
<li>
<p>Repeat the operation above as long as there is one or more employees on the bus.</p>
</li>
</ul>
<p>For a specific example, see Sample Input 1.</p>
<p>The bus takes one seconds to travel a distance of <var>1</var>.
The time required to vote and get off the bus is ignorable.</p>
<p>Every employee will vote so that he himself/she herself can get off the bus at the earliest possible time.
Strictly speaking, when a vote is taking place, each employee see which direction results in the earlier arrival at his/her apartment, assuming that all the employees follow the same strategy in the future.
Based on this information, each employee makes the optimal choice, but if either direction results in the arrival at the same time, he/she casts a vote to the negative direction.</p>
<p>Find the time the bus will take from departure to arrival at the last employees' apartment.
It can be proved that, given the positions of the apartments, the numbers of employees living in each apartment and the initial position of the bus, the future movement of the bus is uniquely determined, and the process will end in a finite time.</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 S \leq 10^9</var></li>
<li><var>1 \leq X_1 < X_2 < ... < X_N \leq 10^9</var></li>
<li><var>X_i \neq S</var> ( <var>1 \leq i \leq N</var> )</li>
<li><var>1 \leq P_i \leq 10^9</var> ( <var>1 \leq i \leq N</var> )</li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>S</var>
<var>X_1</var> <var>P_1</var>
<var>X_2</var> <var>P_2</var>
<var>:</var>
<var>X_N</var> <var>P_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of seconds the bus will take from departure to arrival at the last employees' apartment.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2
1 3
3 4
4 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>Assume that the bus moves in the negative direction first.
Then, the coordinate of the bus changes from <var>2</var> to <var>1</var>, and the employees living in Apartment <var>1</var> get off.
The movement of the bus after that is obvious: it just continues moving in the positive direction.
Thus, if the bus moves in the negative direction first, the coordinate of the bus changes as <var>2 â 1 â 2 â 3 â 4</var> from departure.
The time it takes to get home for the employees living in Apartment <var>1</var>, <var>2</var>, <var>3</var> are <var>1</var>, <var>3</var>, <var>4</var> seconds, respectively.</p>
<p>Next, assume that the bus moves in the positive direction first.
Then, the coordinate of the bus changes from <var>2</var> to <var>3</var>, and the employees living in Apartment <var>2</var> get off.
Afterwards, the bus starts heading to Apartment <var>1</var>, because there are more employees living in Apartment <var>1</var> than in Apartment <var>3</var>.
Then, after arriving at Apartment <var>1</var>, the bus heads to Apartment <var>3</var>.
Thus, if the bus moves in the positive direction first, the coordinate of the bus changes as <var>2 â 3 â 2 â 1 â 2 â 3 â 4</var> from departure.
The time it takes to get home for the employees living in Apartment <var>1</var>, <var>2</var>, <var>3</var> are <var>3</var>, <var>1</var>, <var>6</var> seconds, respectively.</p>
<p>Therefore, in the beginning, the employees living in Apartment <var>1</var> or <var>3</var> will try to move the bus in the negative direction.
On the other hand, the employees living in Apartment <var>2</var> will try to move the bus in the positive direction in the beginning.
There are a total of <var>3 + 2 = 5</var> employees living in Apartment <var>1</var> and <var>3</var> combined, which is more than those living in Apartment <var>2</var>, which is <var>4</var>.
Thus, the bus will move in the negative direction first, and the coordinate of the bus will change as <var>2 â 1 â 2 â 3 â 4</var> from departure.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6 4
1 10
2 1000
3 100000
5 1000000
6 10000
7 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>21
</pre>
<p>Since the numbers of employees living in different apartments are literally off by a digit, the bus consistently head to the apartment where the most number of employees on the bus lives.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>15 409904902
94198000 15017
117995501 7656764
275583856 313263626
284496300 356635175
324233841 607
360631781 148
472103717 5224
497641071 34695
522945827 816241
554305668 32
623788284 22832
667409501 124410641
876731548 12078
904557302 291749534
918215789 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2397671583
</pre></section>
</div>
</span> |
p00819 |
<H1><font color="#000">Problem A:</font> Unreliable Messengers</H1>
<p>
The King of a little Kingdom on a little island in the Pacific Ocean frequently has childish
ideas. One day he said, âYou shall make use of a message relaying game when you inform me
of something.â In response to the Kingâs statement, six servants were selected as messengers
whose names were Mr. J, Miss C, Mr. E, Mr. A, Dr. P, and Mr. M. They had to relay a message
to the next messenger until the message got to the King.
</p>
<p>
Messages addressed to the King consist of digits (â0â-â9â) and alphabet characters (âaâ-âzâ, âAâ-âZâ). Capital and small letters are distinguished in messages. For example, âke3E9Aaâ is a
message.
</p>
<p>
Contrary to Kingâs expectations, he always received wrong messages, because each messenger
changed messages a bit before passing them to the next messenger. Since it irritated the King, he
told you who are the Minister of the Science and Technology Agency of the Kingdom, âWe donât
want such a wrong message any more. You shall develop software to correct it!â In response to
the Kingâs new statement, you analyzed the messengersâ mistakes with all technologies in the
Kingdom, and acquired the following features of mistakes of each messenger. A surprising point
was that each messenger made the same mistake whenever relaying a message. The following
facts were observed.
</p>
<p>
Mr. J rotates all characters of the message to the left by one. For example, he transforms
âaB23dâ to âB23daâ.
</p>
<p>
Miss C rotates all characters of the message to the right by one. For example, she transforms
âaB23dâ to âdaB23â.
</p>
<p>
Mr. E swaps the left half of the message with the right half. If the message has an odd number
of characters, the middle one does not move. For example, he transforms âe3acâ to âace3â,
and âaB23dâ to â3d2aBâ.
</p>
<p>
Mr. A reverses the message. For example, he transforms âaB23dâ to âd32Baâ.
</p>
<p>
Dr. P increments by one all the digits in the message. If a digit is â9â, it becomes â0â. The
alphabet characters do not change. For example, he transforms âaB23dâ to âaB34dâ, and âe9acâ
to âe0acâ.
</p>
<p>
Mr. M decrements by one all the digits in the message. If a digit is â0â, it becomes â9â. The
alphabet characters do not change. For example, he transforms âaB23dâ to âaB12dâ, and âe0acâ
to âe9acâ.
</p>
<p>
The software you must develop is to infer the original message from the final message, given the
order of the messengers. For example, if the order of the messengers is A -> J -> M -> P and the
message given to the King is âaB23dâ, what is the original message? According to the features
of the messengersâ mistakes, the sequence leading to the final message is
</p>
<pre>
A J M P
â32Badâ --> âdaB23â --> âaB23dâ --> âaB12dâ --> âaB23dâ.
</pre>
<p>
As a result, the original message should be â32Badâ.
</p>
<H2>Input</H2>
<p>
The input format is as follows.
</p>
<pre><i>
n
The order of messengers
The message given to the King
.
.
.
The order of messengers
The message given to the King
</pre></i>
<p>
The first line of the input contains a positive integer n, which denotes the number of data sets.
Each data set is a pair of the order of messengers and the message given to the King. The
number of messengers relaying a message is between 1 and 6 inclusive. The same person may
not appear more than once in the order of messengers. The length of a message is between 1
and 25 inclusive.
</p>
<H2>Output</H2>
<p>
The inferred messages are printed each on a separate line.
</p>
<H2>Sample Input</H2>
<pre>
5
AJMP
aB23d
E
86AE
AM
6
JPEM
WaEaETC302Q
CP
rTurnAGundam1isdefferentf
</pre>
<H2>Output for the Sample Input</H2>
<pre>
32Bad
AE86
7
EC302QTWaEa
TurnAGundam0isdefferentfr
</pre>
|
p02824 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><var>N</var> problems are proposed for an upcoming contest. Problem <var>i</var> has an initial integer score of <var>A_i</var> points.</p>
<p><var>M</var> judges are about to vote for problems they like. Each judge will choose exactly <var>V</var> problems, independently from the other judges,
and increase the score of each chosen problem by <var>1</var>.</p>
<p>After all <var>M</var> judges cast their vote, the problems will be sorted in non-increasing order of score, and the first <var>P</var> problems will be chosen for the problemset.
Problems with the same score can be ordered arbitrarily, this order is decided by the chief judge.</p>
<p>How many problems out of the given <var>N</var> have a chance to be chosen for the problemset?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \le N \le 10^5</var></li>
<li><var>1 \le M \le 10^9</var></li>
<li><var>1 \le V \le N - 1</var></li>
<li><var>1 \le P \le N - 1</var></li>
<li><var>0 \le A_i \le 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>M</var> <var>V</var> <var>P</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 problems that have a chance to be chosen for the problemset.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6 1 2 2
2 1 1 3 0 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>If the only judge votes for problems <var>2</var> and <var>5</var>, the scores will be <var>2</var> <var>2</var> <var>1</var> <var>3</var> <var>1</var> <var>2</var>.
The problemset will consist of problem <var>4</var> and one of problems <var>1</var>, <var>2</var>, or <var>6</var>.</p>
<p>If the only judge votes for problems <var>3</var> and <var>4</var>, the scores will be <var>2</var> <var>1</var> <var>2</var> <var>4</var> <var>0</var> <var>2</var>.
The problemset will consist of problem <var>4</var> and one of problems <var>1</var>, <var>3</var>, or <var>6</var>.</p>
<p>Thus, problems <var>1</var>, <var>2</var>, <var>3</var>, <var>4</var>, and <var>6</var> have a chance to be chosen for the problemset. On the contrary, there is no way for problem <var>5</var> to be chosen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6 1 5 2
2 1 1 3 0 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
<p>Only problems <var>1</var>, <var>4</var>, and <var>6</var> have a chance to be chosen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 4 8 5
7 2 3 6 1 6 5 4 6 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>8
</pre></section>
</div>
</span> |
p03736 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> squares in a row. The squares are numbered <var>1, 2, ..., N</var> from left to right.</p>
<p>You have two pieces, initially placed on square <var>A</var> and <var>B</var>, respectively.
You will be asked to process <var>Q</var> queries of the following kind, in the order received:</p>
<ul>
<li>Given an integer <var>x_i</var>, move one of the two pieces of your choice to square <var>x_i</var>.</li>
</ul>
<p>Here, it takes you one second to move a piece one square.
That is, the time it takes to move a piece from square <var>X</var> to <var>Y</var> is <var>|X-Y|</var> seconds.</p>
<p>Your objective is to process all the queries in the shortest possible time.</p>
<p>You may only move the pieces in response to queries, and you may not move both pieces at the same time.
Also, it is not allowed to rearrange the order in which queries are given.
It is, however, allowed to have both pieces in the same square at the same time.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N, Q †200,000</var></li>
<li><var>1 †A, B †N</var></li>
<li><var>1 †x_i †N</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>Q</var> <var>A</var> <var>B</var>
<var>x_1</var> <var>x_2</var> ... <var>x_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Let the shortest possible time to process all the queries be <var>X</var> seconds. Print <var>X</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>8 3 1 8
3 5 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7
</pre>
<p>All the queries can be processed in seven seconds, by:</p>
<ul>
<li>moving the piece at square <var>1</var> to <var>3</var></li>
<li>moving the piece at square <var>8</var> to <var>5</var></li>
<li>moving the piece at square <var>3</var> to <var>1</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9 2 1 9
5 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre>
<p>The piece at square <var>9</var> should be moved first.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>9 2 1 9
5 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
</pre>
<p>The piece at square <var>1</var> should be moved first.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>11 16 8 1
1 1 5 1 11 4 5 2 5 3 3 3 5 5 6 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>21
</pre></section>
</div>
</span> |
p00233 |
<H1>峿žæŽç</H1>
<p>
æ°ã®è¡šããæ¹ã«ã¯è²ã
ãªçš®é¡ããããç§ãã¡ãæ®æ®µäœ¿ã£ãŠãã 10 鲿°ã¯äžã€ã®ä»£è¡šçãªãã®ã§ãããããŸãããã³ã³ãã¥ãŒã¿é¢é£ã®ç¥èããã人ã«ã¯ã2 鲿°ã16 鲿°ãããã¯ãšãŠã身è¿ãªãã®ã§ãã
</p>
<p>
N ããã¯åžæžè³æ Œã掻ãããŠåžæžã®ä»äºã«å°±ããŸãããæåã®ä»äºã¯å³æžæŽçã§ãããã®å³æžé€šã§ã¯ãäžåããšã«äžè²«ããŠçªå·ãäžããããŠãããããã«åŸã£ãŠæ¬ãæŽçããŠããŸãã
</p>
<p>
ãã®å³æžé€šã§ã¯æ¬ã®çªå·ããã€ãã¹å鲿°ã§è¡šãããšã«ãªã£ãŠããŸãã
</p>
<p>
ãã€ãã¹å鲿°ã¯ã<var>a<sub>n</sub>a<sub>n−1</sub>a<sub>n−2</sub></var>...<var>a<sub>2</sub>a<sub>1</sub>a<sub>0</sub></var> (å<var>a<sub>i</sub></var> 㯠0~9 ã®æ°å) ãšè¡šèšããæ¹æ³ã§ããããã®æ°ã¯æ¬¡ã®æ°ã衚ããŸãã
</p>
<p>
<var>a<sub>n</sub>×(−10)<sup>n</sup> + a<sub>n−1</sub>×(−10)<sup>n−1</sup> +</var> ... <var>+ a<sub>2</sub>×(−10)<sup>2</sup> + a<sub>1</sub>×(−10)<sup>1</sup> + a<sub>0</sub>×(−10)<sup>0</sup></var>
</p>
<p>
ããšãã°ããã€ãã¹å鲿°ã® 2156 ã¯ã以äžã®ãšããå鲿°ã®-1944 ã«å¯Ÿå¿ããŠããŸãã
</p>
<p>
2×(-10)<sup>3</sup> + 1×(-10)<sup>2</sup> + 5×(-10)<sup>1</sup> + 6×(-10)<sup>0</sup> = <br>
2×(-1000) + 1×(100) + 5×(-10) + 6×(1) = <br>
-2000 + 100 - 50 + 6 = -1944
</p>
<p>
å鲿°ã®çªå·ããã€ãã¹å鲿°ã«çŽãã®ã¯å€§å€ãªã®ã§ãN ããã¯å€§å€äžèªç±ãªæããããŠããŸãã
</p>
<p>
æ¬ã®çªå·ãå
¥åãšãã ãã®çªå·ã®ãã€ãã¹å鲿°è¡šèšãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ãããšããŠãæ¬ã®çªå·ãè¡šãæŽæ° <var>A</var> (-2<sup>31</sup> ≤ <var>A</var> < 2<sup>31</sup>) ãïŒè¡ã«äžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 1200 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
å
¥åããŒã¿ã»ããããšã«ãçªå·ã®ãã€ãã¹å鲿°è¡šèšãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
9
10
-10
-1944
-305432133
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
9
190
10
2156
1715573947
</pre>
|
p00663 |
<H1>Problem E: SAT-EN-3</H1>
<p>
åœŒå¥³ã¯æ©ãã§ãããæçžŸãè¯ããªãã®ã ã䞡芪ã«ç¡çãèšã£ãŠå
šå¯®å¶ã®åŠæ ¡ã«å
¥åŠãããã®ã®ãåœŒå¥³ã®æèœã¯äžåã«éè±ããããšã¯ãªãã£ãããããã¯æèœãªã©å
ã
ãªãã£ãã®ãããããªãããããã¯ã§ããã ãèããããªãå¯èœæ§ã ã£ãã
</p>
<p>
ããã§åœŒå¥³ãé Œã£ãã®ã¯ãã€ã³ã¿ãŒãããäžã§èŠã€ããæªãããªè³åãã¬ãŒãã³ã°ã®ææã ã£ããSAT-EN-3 (SATisifiability problem for Enhancement of Neuron: version 3) ãšéæã€ãã®åŠç¿ã¡ãœããã«ãããšãå
è¶³å¯èœæ§åé¡ã®ãããªãã®ã®ã€ã³ã¹ã¿ã³ã¹ãã²ãããæã§è§£ãããšã«ãã£ãŠãèšç®åãåäžããåŒããŠã¯è«ççæèåã»çŽæåã»æ³ååãè±ãã«ãªããéšæŽ»åã§ã掻èºã§ããŠææãããŸãããã®ã ãšããããããã«æåŸã®2ã€ã¯çåŸãã®ãããªãããªããšåœŒå¥³ã¯æã£ããããœããã³ãçŸãã¹èšç®ã®ãããªäŸãããããšã ãæç®ãåŸæã«ãªã£ããå²ããã®ããªããããã®æ°æ¥œãã§ã圌女ã¯ãã®ææã«åãçµãã§ã¿ãããšã«ããã
</p>
<p>
SAT-EN-3ã§ã¯ãå æ³æšæºåœ¢ã§è¡šãããè«çåŒã®å倿°ã«é©åã«å²ãåœãŠãè«çåŒã®å€ãçã«ããããšãã§ãããã©ããå€å®ããªããã°ãªããªããã¡ãªã¿ã«ã1ã€ä»¥äžã®å€æ° (ãŸãã¯ããã®åŠå®) ã®è«çç©ã ç¯ (clause) ãšåŒã³ãããã€ãã®ç¯ã®è«çåã§è¡šãããè«çåŒã®ã¿ãå æ³æšæºåœ¢ã«åŸã£ãŠãããäžè¬ã«å
è¶³å¯èœæ§åé¡ãšããã°è«çåŒã¯ä¹æ³æšæºåœ¢ã§è¡šãããããSAT-EN-3ã§ã¯å æ³æšæºåœ¢ã§ããããšã«æ³šæããã
</p>
<p>
圌女ã¯ãã°ãã SAT-EN-3 ã®åé¡éã«åãçµãããšããŠããµãšæãçŽãããåé¡éã«ãéãæãããããªããããã°ã©ãã³ã°ãåŸæãªèŠªåã«ããã§ã§ãã銳走ããŠã SAT-EN-3 ã®åé¡ãçæããè§£ãããã°ã©ã ãæžããŠãããããããããã°åé¡ãè§£çããããã§ãæã«ã¯ãããããªããã
</p>
<p>
ããããŠåœŒå¥³ã®èŠªåã§ããããªãã¯ãSAT-EN-3ãè§£ãããã°ã©ã ãæžãããšã«ãªã£ãã®ã§ããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯è€æ°ã®ã±ãŒã¹ãããªãã
åã±ãŒã¹ã¯ä»¥äžã®ãã©ãŒãããã§äžããããã
</p>
<pre>
<i>expression</i>
</pre>
<p>
å
¥åã®çµããã¯<b>"#"</b>ãããªãè¡ã«ãã£ãŠäžãããã
</p>
<p>
<i>expression</i>ã¯ä»¥äžã®BNFã«åŸãã<br>
ããã§ã¯æååãªãã©ã«ã""ãçšããŠå²ãã§ããã
å®éã®å
¥åã«""ã¯å«ãŸããªãã
ãŸãå
¥åã«ã¯äœèšãªç©ºçœã¯å«ãŸããŠããªãã
</p>
<pre>
<expression> ::= "("<clause>")" | "("<clause>")|("<expression>")"
<clause> ::= <literal>"&"<literal>"&"<literal>
<literal> ::= <variable> | "~"<variable>
<variable> ::= [a-z]|[A-z]
</pre>
<p>
<i>expression</i>ã®é·ãã¯500æåãè¶
ããªãã
</p>
<p>
ãã¹ãã±ãŒã¹ã®æ°ã¯1100åãè¶
ããªãã
</p>
<h2>Output</h2>
<p>
äžããããåŒãæºãã倿°ã®å²ãåœãŠãååšããã®ãªãã°yesããããã§ãªããã°noãåºåããã
</p>
<h2>Sample input</h2>
<pre>
(B&B&f)|(~d&~i&i)|(~v&i&~V)|(~g&~e&o)|(~f&d&~v)|(d&~i&o)|(g&i&~B)|(~i&f&d)|(e&~i&~V)|(~v&f&~d)
(S&X&~X)
#
</pre>
<H2>Sample output</H2>
<pre>
yes
no
</pre>
<hr>
<p>
The University of Aizu Programming Contest 2011 Summer<br>
åæ¡: Tomoya Sakai<br>
å顿: Takashi Tayama<br>
</p> |
p01971 | <h2>E: Broccoli or Cauliflower</h2>
<h3>Problem</h3>
<p>The input is a rooted tree <var>T = (V, E)</var> with <var>n</var> vertices. Note that <var>n</var> is odd and the vertex with index <var>1</var> is the root of <var>T</var>. In addition, we give a label <var>G</var> or <var>W</var> for each vertex. Let <var>T_v = (U, F)</var> be a subtree of <var>T</var> such that <var>U</var> is defined as following.</p>
<ul>
<li> <var>U = </var>$\{$<var> u \in V \ \ | \ \ u </var>$\text{ is the descendant of }$<var> v </var>$\}$</li>
</ul>
<p>We call <var>T_v</var> a subtree of <var>v</var>.</p>
<p>We consider the following operation and perform operations <var>q</var> times.</p>
<ul>
<li> Let <var>v</var> be a vertex. If a vertex <var>u \in U</var> has the label <var>G</var>, then we change the label of <var>u</var> <var>G</var> to <var>W</var>. Otherwise, we change the label of <var>u</var> <var>W</var> to <var>G</var>. </li>
</ul>
<p>After each operation, output âbroccoliâ if the number of vertices with the label <var>G</var> is greater than <var>W</var>. Otherwise, output âcauliflowerâ.</p>
<h3>Input format</h3>
<p>An input is the following format.</p>
<pre>
<var>n</var> <var>q</var>
<var>p_2</var> <var>...</var> <var>p_n</var>
<var>c_1</var> <var>...</var> <var>c_n</var>
<var>v_1</var>
$\vdots$
<var>v_q</var>
</pre>
<p>In line <var>1</var>, there are two integers <var>n</var> and <var>q</var>, where <var>n</var> is the number of vertices in <var>T</var> and <var>q</var> is the number of queries. Note that <var>n</var> is odd.</p>
<p>In line <var>2</var>, there are <var>n - 1</var> integers <var>p_2</var> to <var>p_n</var>. <var>p_i</var> represents the parent of a vertex <var>v_i</var>.</p>
<p>
In line <var>3</var>, there are <var>n</var> characters <var>c_1</var> to <var>c_n</var>. <var>c_i</var> represents the label of <var>v_i</var>.
Finally, in line <var>j + 3</var>, there is an integer <var>v_j</var>. We perform the operation for <var>T_{v_j}</var>.
</p>
<h3>Constraints</h3>
<ul>
<li> <var>1 \leq n \leq 100,000</var> ( <var>n</var> is odd. )</li>
<li> <var>1 \leq q \leq 100,000</var></li>
<li> <var>1 \leq p_i < i</var>ïŒ<var>2 \leq i \leq n</var>ïŒ</li>
<li> <var>c_j</var> is <var>G</var> or <var>W</var>. (<var>1 \leq j \leq n</var>)</li>
<li> <var>1 \leq v_i \leq n</var>ïŒ<var>1 \leq i \leq q</var>ïŒ</li>
</ul>
<h3>Output format</h3>
<p>An output consists <var>q</var> lines and output âbroccoliâ or âcauliflowerâ in each line.</p>
<h3>Input example 1</h3>
<pre>
7 4
1 1 2 2 3 3
G G W W W G G
2
1
3
4
</pre>
<h3>Output example 1</h3>
<pre>
broccoli
cauliflower
cauliflower
broccoli
</pre>
<h3>Input example 2</h3>
<pre>
17 18
1 1 1 3 1 4 2 4 3 6 10 9 3 4 5 15
W W W W W W W W G W G G W G W W W
6
7
1
9
14
6
4
5
3
7
8
13
9
6
14
12
9
13
</pre>
<h3>Output example 2</h3>
<pre>
cauliflower
cauliflower
broccoli
broccoli
broccoli
broccoli
broccoli
broccoli
broccoli
cauliflower
cauliflower
cauliflower
cauliflower
cauliflower
broccoli
cauliflower
cauliflower
cauliflower
</pre>
|
p00399 | <h1>æŽç¬ã®æ°</h1>
ã
<p>
ã€ã
ã¢å
¬åã«ã¯ã倿¹ã«ãªããšæŽç¬ã𿣿©ãã人ãã¡ãããããæ¥ãŸããæŽç¬ã«ã¯æ¯ã®è²ã«ãã£ãŠèµ€æŽã黿ŽãçœæŽãè¡éº»æŽãšããçš®é¡ããããŸããæŽç¬ããããããããšãããããã¢ãšã¡ããã¯ãããããã®æ¯è²ã®æŽç¬ãäœé ãããããã°ã£ãŠæ°ããŸãããããŸã è¶³ãç®ãã§ããªãã®ã§æŽç¬ãå
šéšã§äœé ãããããããŸããã
</p>
<p>
ããããã®æ¯è²ã®æŽç¬ã®æ°ãäžãããããšãã«ãæŽç¬ã®ç·æ°ãèšç®ããããã°ã©ã ãäœæããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
$R$ $B$ $W$ $G$
</pre>
<p>
ïŒè¡ã«èµ€æŽã®æ°$R$ ($1 \leq R \leq 100$)ã黿Žã®æ°$B$ ($1 \leq B \leq 100$)ãçœæŽã®æ°$W$ ($1 \leq W \leq 100$)ãè¡éº»æŽã®æ°$G$ ($1 \leq G \leq 100$)ãäžããããã
</p>
<h2>åºå</h2>
<p>
æŽç¬ã®ç·æ°ãïŒè¡ã«åºåããã
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸïŒ</h3>
<pre>
4 2 1 1
</pre>
<h3>åºåäŸïŒ</h3>
<pre>
8
</pre>
<h3>å
¥åäŸïŒ</h3>
<pre>
22 18 34 36
</pre>
<h3>åºåäŸïŒ</h3>
<pre>
110
</pre>
|
p01422 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<H1>Beautiful Currency</H1>
<p>
KM country has <var>N</var> kinds of coins and each coin has its value <var>a_i</var>.
</p>
<p>
The king of the country, Kita_masa, thought that the current currency system is poor,
and he decided to make it <i>beautiful</i> by changing the values of some (possibly no) coins.
</p>
<p>
A currency system is called beautiful
if each coin has an integer value and the (<var>i</var>+1)-th smallest value is divisible by the <var>i</var>-th smallest value for all <var>i</var> (<var>1 \leq i \leq N-1</var>).
</p>
<p>
For example, the set <var>{1, 5, 10, 50, 100, 500}</var> is considered as a beautiful system,
while the set <var>{1, 5, 10, 25, 50, 100}</var> is NOT,
because <var>25</var> is not divisible by <var>10</var>.
</p>
<p>
Since changing the currency system may confuse citizens,
the king, Kita_masa, wants to minimize the maximum value of the confusion ratios.
Here, the confusion ratio for the change in the <var>i</var>-th coin is defined as <var>|a_i - b_i| / a_i</var>,
where <var>a_i</var> and <var>b_i</var> is the value of <var>i</var>-th coin before and after the structure changes, respectively.
</p>
<p>
Note that Kita_masa can change the value of each existing coin,
but he cannot introduce new coins nor eliminate existing coins.
After the modification, the values of two or more coins may coincide.
</p>
<H2>Input</H2>
<p>
Each dataset contains two lines.
The first line contains a single integer, <var>N</var>,
and the second line contains <var>N</var> integers, <var>{a_i}</var>.
</p>
<p>
You may assume the following constraints:
</p>
<p>
<var>1 \leq N \leq 20</var>
</p>
<p>
<var>1 \leq a_1 \lt a_2 \lt... \lt a_N \lt 10^5</var>
</p>
<H2>Output</H2>
<p>
Output one number that represents the minimum of the maximum value of the confusion ratios.
The value may be printed with an arbitrary number of decimal digits,
but may not contain an absolute error greater than or equal to <var>10^{-8}</var>.
</p>
<H2>Sample Input 1</H2>
<pre>
3
6 11 12
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
0.090909090909
</pre>
<H2>Sample Input 2</H2>
<pre>
3
6 11 24
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
0.090909090909
</pre>
<H2>Sample Input 3</H2>
<pre>
3
6 11 30
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>
0.166666666667
</pre>
|
p01072 |
<h1>Problem A: Plants</h1>
<h2>Problem</h2>
<p>ãã£ã¡ãåã¯æšª<var>W</var>å×瞊<var>H</var>åã®ãã¹ã§åºåãããçãææããŠããã<var>x</var>åç®<var>y</var>è¡ç®ã®ãã¹ããã¹ <var>(x, y)</var> ãšåŒã¶ããšã«ãããããã€ãã®ãã¹ã®åå°ã«ã¯é«ã0cmã®æ€ç©ã1æ¬ã ãæ€ããŠããããã®ä»ã®ãã¹ã®åå°ã«ã¯äœãæ€ããããŠããªãã
</p>
<p>
ãã£ã¡ãåã¯ããæå»ã«çã«è¥æããŸããè¥æããŸããããã¹ã«æ€ç©ãæ€ããããŠãããšãããã®æ€ç©ã®é«ãã1cm䌞ã³ããæ€ç©ãæ€ããããŠããªããšãã¯ãäœãããããªããæ€ç©ã䌞ã³ãã®ã«ãããæéã¯ãšãŠãçãã®ã§ç¡èŠã§ããããã£ã¡ãåã¯åãæå»ã«è€æ°ã®ãã¹ã«è¥æããŸãããšãã§ããããã ããåãæå»ã«åããã¹ã«2床以äžè¥æããŸãããšã¯ãªãã
</p>
<p>
ãã£ã¡ãåãè¥æããŸããèšé²ãäžãããããšããæå»<var>T</var>æç¹ã§ã®çã®æ€ç©ã®é«ãã®åãèšç®ããã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
<var>W</var> <var>H</var> <var>T</var>
<var>p</var>
<var>x<sub>0</sub></var> <var>y<sub>0</sub></var> <var>t<sub>0</sub></var>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>t<sub>1</sub></var>
...
<var>x<sub>p−1</sub></var> <var>y<sub>p−1</sub></var> <var>t<sub>p−1</sub></var>
<var>s<sub>0,0</sub></var> <var>s<sub>1,0</sub></var> ⊠<var>s<sub>W−1,0</sub></var>
<var>s<sub>0,1</sub></var> <var>s<sub>1,1</sub></var> ⊠<var>s<sub>W−1,1</sub></var>
...
<var>s<sub>0,H−1</sub></var> <var>s<sub>1,H−1</sub></var> ⊠<var>s<sub>W−1,H−1</sub></var>
</pre>
<p>
1è¡ç®ã«çã®æšªå¹
<var>W</var>ãçã®çžŠå¹
<var>H</var>ãæå»<var>T</var>ãäžããããããã£ã¡ãåã¯æå»<var>T</var>ãŸã§ã«è¥æããŸããããã<br>
2è¡ç®ã«ãã£ã¡ãåãè¥æããŸããåæ°<var>p</var>ãäžããããã<br>
3è¡ç®ãã2+<var>p</var>è¡ç®ãŸã§ã«äžããããïŒã€ã®æŽæ°ã¯ããã£ã¡ãåãæå»<var>t<sub>i</sub></var>ã«ãã¹(<var>x<sub>i</sub></var>, <var>y<sub>i</sub></var>)ã«è¥æããŸããããšã衚ãã<br>
3+<var>p</var>è¡ç®ãã2+<var>p</var>+<var>H</var>è¡ç®ãŸã§ã¯ãæåã®çã®ããããã®ãã¹ã«æ€ç©ãæ€ããããŠãããã©ããã衚ã<var>W</var>×<var>H</var>åã®æŽæ°ãäžããããã<var>s<sub>j,k</sub></var>ã1ã®ãšããã¹(<var>j</var>, <var>k</var>)ã«é«ã0cmã®æ€ç©ã1æ¬ã ãæ€ããããŠããããšã衚ãã<var>s<sub>j,k</sub></var>ã0ã®ãšããã¹(<var>j</var>, <var>k</var>)ã«æ€ç©ã¯1æ¬ãæ€ããããŠããªãããšã衚ãã<br>
</p>
<h2>Constraints</h2>
<ul>
<li>1 ≤ <var>W</var>, <var>H</var>, <var>T</var> ≤ 50</li>
<li>0 ≤ <var>p</var> ≤ min(<var>W</var>×<var>H</var>×<var>T</var>, 50)</li>
<li>0 ≤ <var>x<sub>i</sub></var> < <var>W</var></li>
<li>0 ≤ <var>y<sub>i</sub></var> < <var>H</var></li>
<li>0 ≤ <var>t<sub>i</sub></var> < <var>T</var></li>
<li><var>s<sub>j,k</sub></var> = 0ãŸãã¯1</li>
</ul>
<h2>Output</h2>
<p>
æå»<var>T</var>ã§ã®çã®æ€ç©ã®é«ãã®åã1è¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
3 3 3
5
2 0 0
0 1 0
1 1 1
1 2 1
2 2 0
0 0 0
0 1 0
0 0 0
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2016Day2AIZU_A_sample1" alt="Sample1" style="width: 640px"></p>
<h2>Sample Input 2</h2>
<pre>
2 3 4
2
0 0 0
1 1 3
1 0
0 0
0 0
</pre>
<h2>Sample Output 2</h2>
<pre>
1
</pre>
<h2>Sample Input 3</h2>
<pre>
3 8 6
6
0 4 3
2 5 3
0 2 3
2 2 5
1 1 3
2 2 1
1 1 1
1 1 1
1 1 1
1 0 1
0 1 1
1 1 0
1 0 1
0 1 0
</pre>
<h2>Sample Output 3</h2>
<pre>
4
</pre>
<h2>Sample Input 4</h2>
<pre>
8 3 3
7
0 1 1
5 1 0
4 0 2
3 2 0
3 1 1
3 0 1
5 1 1
1 0 1 1 0 0 1 0
0 0 1 1 0 1 0 1
0 1 0 0 0 1 0 1
</pre>
<h2>Sample Output 4</h2>
<pre>
4
</pre>
<p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2016Day2AIZU_A_sample4" alt="Sample4" style="width: 640px"></p> |
p01588 |
<H1><font color="#000">Problem H:</font> Round Table</H1>
<p>
You are the owner of a restaurant, and you are serving for <i>N</i> customers seating in a round table.
</p>
<p>
You will distribute <i>M</i> menus to them. Each customer receiving a menu will make the order of plates, and
then pass the menu to the customer on the right unless he or she has not make the order. The customer <i>i</i> takes <i>L<sub>i</sub></i> unit time for the ordering.
</p>
<p>
Your job is to write a program to calculate the minimum time until all customers to call their orders, so you can improve your business performance.
</p>
<H2>Input</H2>
<p>
The input consists of a sequence of positive integers.
</p>
<p>
The first line of the input contains two positive integers <i>N</i> (<i>N</i> ≤ 50,000) and <i>M</i> (<i>M</i> ≤ <i>N</i>). The second line contains <i>N</i> positive integers <i>L</i><sub>1</sub>, <i>L</i><sub>2</sub>,..., <i>L<sub>N</sub></i> (<i>L<sub>i</sub></i> ≤ 600).
</p>
<H2>Output</H2>
<p>
Output the minimum possible time required for them to finish ordering.
</p>
<H2>Sample Input and Output</H2>
<H2>Input #1</H2>
<pre>
3 2
1 5 10
</pre>
<H2>Output #1</H2>
<pre>
10
</pre>
<br/>
<H2>Input #2</H2>
<pre>
4 2
1 2 3 4
</pre>
<H2>Output #2</H2>
<pre>
5
</pre> |
p01567 |
<h1>Presentation</h1>
<p>You are a researcher investigating algorithms on binary trees.
Binary tree is a data structure composed of branch nodes and leaf nodes.
Every branch nodes have left child and right child, and each child is either a branch node or a leaf node.
The root of a binary tree is the branch node which has no parent.
</p>
<p>You are preparing for your presentation and you have to make a figure of binary trees using a software.
You have already made a figure corresponding to a binary tree which is composed of one branch node and two leaf nodes (Figure 1.)
However, suddenly the function of your software to create a figure was broken.
You are very upset because in five hours you have to make the presentation in front of large audience.
</p>
<p>You decided to make the figure of the binary trees using only copy function, shrink function and paste function of the presentation tool.
That is, you can do only following two types of operations.
</p>
<ul>
<li><p> Copy the current figure to the clipboard.</p>
<ul><li><p>The figure copied to the clipboard before is removed.</p></li></ul>
</li>
<li><p> Paste the copied figure (with shrinking, if needed), putting the root of the pasted figure on a leaf node of the current figure.</p>
<ul><li><p> You can paste the copied figure multiple times.</p></li></ul>
</li>
</ul>
<p>Moreover, you decided to make the figure using the minimum number of paste operations because paste operation is very time cosuming.
Now, your job is to calculate the minimum possible number of paste operations to produce the target figure.
</p>
<p><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_sample1_0" height="149" width="178"></center></p>
<p><center><i>Figure 1: initial state</i></center></p>
<p>For example, the answer for the instance of sample 1(Figure 4) is 3, because you can produce the target figure by following operations and this is minimum.
</p>
<p><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_sample1_1" height="192" width="257"></center></p>
<p><center><i>Figure 2: intermediate 1</i></center></p>
<p><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_sample1_2" height="183" width="243"></center></p>
<p><center><i>Figure 3: intermediate 2</i></center></p>
<p><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_sample1_3" height="219" width="291"></center></p>
<p><center><i>Figure 4: Goal</i></center></p>
<h2>Input</h2>
<p>The input is a line which indicates a binary tree.
The grammar of the expression is given by the following BNF.
</p>
<blockquote>
<tree> ::= <leaf> | "(" <tree> <tree> ")"<br><leaf> ::= "()"<br></blockquote>
<p>Every input obeys this syntax.
You can assume that every tree in the input has at least 1 branch node, and that it has no more than 10^5 branch nodes.
</p>
<h2>Output</h2>
<p>A line containing the minimum possible number of paste operations to make the given binary tree.
</p>
<h2>Sample Input 1</h2>
<pre>((()())(((()())(()()))()))
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>3
</pre>
<h2>Sample Input 2</h2>
<pre>(((()())(()()))(()()))
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>4
</pre>
<h2>Sample Input 3</h2>
<pre>((()(()()))((()(()()))()))
</pre>
<h2>Output for the Sample Input 3</h2>
<pre>3
</pre>
<h2>Sample Input 4</h2>
<pre>(()())
</pre>
<h2>Output for the Sample Input 4</h2>
<pre>0
</pre> |
p01137 |
<!-- begin en only -->
<h3><U>Space Coconut Crab</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>
ã±ã³ã»ããªã³ãã«ãŒã¯ïŒå®å®ã€ã·ã¬ããæ±ããŠå
šéæ²³ãæ
ããã¹ããŒã¹ãã³ã¿ãŒã§ããïŒå®å®ã€ã·ã¬ãã¯ïŒå®å®æå€§ãšãããç²æ®»é¡ã§ããïŒæé·åŸã®äœé·ã¯ 400 ã¡ãŒãã«ä»¥äžïŒè¶³ãåºããã° 1,000 ã¡ãŒãã«ä»¥äžã«ããªããšèšãããŠããïŒæ¢ã«å€æ°ã®äººã
ãå®å®ã€ã·ã¬ããç®æããŠãããïŒèª°äžäººãšããŠæãããããšã«æåããŠããªãïŒ
</p>
<p>
ã±ã³ã¯ïŒé·æéã®èª¿æ»ã«ãã£ãŠïŒå®å®ã€ã·ã¬ãã®çæ
ã«é¢ããéèŠãªäºå®ãè§£æããïŒå®å®ã€ã·ã¬ãã¯ïŒé©ãã¹ãããšã«ïŒçžè»¢ç§»èªæ³ãšåŒã°ããææ°ã®ã¯ãŒãæè¡ãšåçã®ããšãè¡ãïŒé垞空éãšè¶
空éã®éãåŸæ¥ããªããçããŠããïŒããã«ïŒå®å®ã€ã·ã¬ããè¶
空éããé垞空éã«ã¯ãŒãã¢ãŠããããŸã§ã«ã¯é·ãæéããããïŒãŸãã¯ãŒãã¢ãŠãããŠãããã°ããã¯è¶
空éã«ç§»åã§ããªãããšãçªãæ¢ããïŒ
</p>
<p>
ããã§ïŒã±ã³ã¯ã€ãã«å®å®ã€ã·ã¬ãã®æç²ã«ä¹ãåºãããšã«ããïŒæŠç¥ã¯æ¬¡ã®ãšããã§ããïŒã¯ããã«ïŒå®å®ã€ã·ã¬ããé垞空éããè¶
空éã«çªå
¥ããéã®ãšãã«ã®ãŒã芳枬ããïŒãã®ãšãã«ã®ãŒã <i>e</i> ãšãããšãïŒå®å®ã€ã·ã¬ããè¶
空éããã¯ãŒãã¢ãŠãããåº§æš (<i>x</i>, <i>y</i>, <i>z</i>) ã¯ä»¥äžã®æ¡ä»¶ãæºããããšãããã£ãŠããïŒ
</p>
<ul>
<li><i>x</i>, <i>y</i>, <i>z</i> ã¯ããããéè² ã®æŽæ°ã§ããïŒ</li>
<li><i>x</i> + <i>y</i><sup>2</sup> + <i>z</i><sup>3</sup> = <i>e</i> ã§ããïŒ</li>
<li>äžèšã®æ¡ä»¶ã®äžã§ <i>x</i> + <i>y</i> + <i>z</i> ã®å€ãæå°ã«ããïŒ</li>
</ul>
<p>
ãããã®æ¡ä»¶ã ãã§ã¯åº§æšãäžæã«æ±ºãŸããšã¯éããªããïŒ<i>x</i> + <i>y</i> + <i>z</i> ã®æå°å€ã <i>m</i> ãšãããšãã«ïŒã¯ãŒãã¢ãŠããã座æšãå¹³é¢ <i>x</i> + <i>y</i> + <i>z</i> = <i>m</i> äžã«ããããšã¯ç¢ºãã§ããïŒããã§ïŒãã®å¹³é¢äžã«ååãªå€§ããã®ããªã¢ã匵ãïŒãããšïŒå®å®ã€ã·ã¬ãã¯ããªã¢ã®åŒµããããšããã«ã¯ãŒãã¢ãŠãããããšã«ãªãïŒããªã¢ã®åœ±é¿ãåããå®å®ã€ã·ã¬ãã¯èº«åãããšããªããªãïŒãããã±ã³ã®æäœããææ°éå®å®è¹ã§ãããŠã§ãã³ã»ãã¬ãŒã«ãŒå·ã§æç²ããããšããæ®µåãã§ããïŒ
</p>
<p>
ããªã¢ã¯äžåºŠãã匵ãããšãã§ããªãããïŒå€±æããããã«ã¯ãããªãïŒããã§ã±ã³ã¯ïŒä»»åã®éè¡ã«ããã£ãŠèšç®æ©ã®å©ããåããããšã«ããïŒããªãã®ä»äºã¯ïŒå®å®ã€ã·ã¬ããè¶
空éã«çªå
¥ããéã®ãšãã«ã®ãŒãäžãããããšãã«ïŒããªã¢ã匵ãã¹ãå¹³é¢ <i>x</i> + <i>y</i> + <i>z</i> = <i>m</i> ãæ±ããããã°ã©ã ãæžãããšã§ããïŒçšæããããã¹ãã±ãŒã¹ã®å
šãŠã«å¯ŸããŠæ£ããçµæãåºåãããšãïŒããªãã®ããã°ã©ã ã¯åãå
¥ããããã§ãããïŒ
</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ããã§æ§æãããïŒåããŒã¿ã»ãã㯠1 è¡ã®ã¿ãããªãïŒ1 ã€ã®æ£ã®æŽæ° <i>e</i> (<i>e</i> ⊠1,000,000) ãå«ãŸããïŒããã¯ïŒå®å®ã€ã·ã¬ããè¶
空éã«çªå
¥ããéã®ãšãã«ã®ãŒã衚ãïŒå
¥å㯠<i>e</i> = 0 ã®æã«çµäºãïŒããã¯ããŒã¿ã»ããã«ã¯å«ãŸããªãïŒ
</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>
åããŒã¿ã»ããã«ã€ããŠïŒ<i>m</i> ã®å€ã 1 è¡ã«åºåããªããïŒåºåã«ã¯ä»ã®æåãå«ããŠã¯ãªããªãïŒ
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>
1
2
4
27
300
1250
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
1
2
2
3
18
44
</pre>
|
p00376 | <h1>Red Dragonfly</h1>
ã
<p>
Itâs still hot every day, but September has already come. Itâs autumn according to the calendar. Looking around, I see two red dragonflies at rest on the wall in front of me. Itâs autumn indeed.
</p>
<p>
When two red dragonfliesâ positional information as measured from the end of the wall is given, make a program to calculate the distance between their heads.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$x_1$ $x_2$
</pre>
<p>
The input line provides dragonfliesâ head positions $x_1$ and $x_2$ ($0 \leq x_1, x_2 \leq 100$) as integers.
</p>
<h2>Output</h2>
<p>
Output the distance between the two red dragonflies in a line.
</p>
<h2>Sample Input 1</h2>
<pre>
20 30
</pre>
<h2>Sample Output 1</h2>
<pre>
10
</pre>
<h2>Sample Input 2</h2>
<pre>
50 25
</pre>
<h2>Sample Output 2</h2>
<pre>
25
</pre>
<h2>Sample Input 3</h2>
<pre>
25 25
</pre>
<h2>Sample output 3</h2>
<pre>
0
</pre>
|
p00726 |
<h1><font color="#000">Problem E:</font> <u>The Genome Database of All Space Life</u></h1>
<!-- end en only -->
<p>
In 2300, the Life Science Division of Federal Republic of Space starts
a very ambitious project to complete the genome sequencing of all
living creatures in the entire universe and develop the genomic
database of all space life.
Thanks to scientific research over many years, it has been known that
the genome of any species consists of at most 26 kinds of
molecules, denoted by English capital letters (<i>i.e.</i> <tt>A</tt>
to <tt>Z</tt>).
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
What will be stored into the database are plain strings consisting of
English capital letters.
In general, however, the genome sequences of space life include
frequent repetitions and can be awfully long.
So, for efficient utilization of storage, we compress <i>N</i>-times
repetitions of a letter sequence <i>seq</i> into
<i>N</i><tt>(</tt><i>seq</i><tt>)</tt>, where <i>N</i> is a natural
number greater than or equal to two and the length of <i>seq</i> is at
least one.
When <i>seq</i> consists of just one letter <i>c</i>, we may omit parentheses and write <i>Nc</i>.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
For example, a fragment of a genome sequence:
</p><blockquote>
<tt>ABABABABXYXYXYABABABABXYXYXYCCCCCCCCCC</tt>
</blockquote>
<p>can be compressed into:</p>
<blockquote>
<tt>4(AB)XYXYXYABABABABXYXYXYCCCCCCCCCC</tt>
</blockquote>
<p>by replacing the first occurrence of <tt>ABABABAB</tt> with its compressed form.
Similarly, by replacing the following repetitions of <tt>XY</tt>,
<tt>AB</tt>, and <tt>C</tt>, we get:</p>
<blockquote>
<tt>4(AB)3(XY)4(AB)3(XY)10C</tt>
</blockquote>
<p>Since <tt>C</tt> is a single letter, parentheses are omitted in this
compressed representation.
Finally, we have:</p>
<blockquote>
<tt>2(4(AB)3(XY))10C</tt>
</blockquote>
<p>by compressing the repetitions of <tt>4(AB)3(XY)</tt>.
As you may notice from this example, parentheses can be nested.
<p></p>
<!-- end en only -->
<!-- begin en only -->
<p>
Your mission is to write a program that uncompress compressed genome
sequences.
</p>
<!-- end en only -->
<h2>Input</h2>
<!-- begin en only -->
<p>The input consists of multiple lines, each of which contains a
character string <i>s</i> and an integer <i>i</i> separated by a
single space.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The character string <i>s</i>, in the aforementioned manner,
represents a genome sequence.
You may assume that the length of <i>s</i> is between 1 and 100,
inclusive.
However, of course, the genome sequence represented by <i>s</i> may be
much, much, and much longer than 100.
You may also assume that each natural number in <i>s</i> representing the
number of repetitions is at most 1,000.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The integer <i>i</i> is at least zero and at most one million.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
A line containing two zeros separated by a space follows the last input line and indicates
the end of the input.
</p>
<!-- end en only -->
<h2>Output</h2>
<!-- begin en only -->
<p>
For each input line, your program should print a line containing the
<i>i</i>-th letter in the genome sequence that <i>s</i> represents.
If the genome sequence is too short to have the <i>i</i>-th element,
it should just print a zero.
No other characters should be printed in the output lines.
Note that in this problem the index number begins from zero rather
than one and therefore the initial letter of a sequence is its zeroth element.
</p>
<!-- end en only -->
<h2>Sample Input</h2>
<pre>
ABC 3
ABC 0
2(4(AB)3(XY))10C 30
1000(1000(1000(1000(1000(1000(NM)))))) 999999
0 0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
0
A
C
M
</pre>
|
p01834 |
<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>Cube Dividing</h2>
<p>
Pablo Cubarson is a well-known cubism artist. He is producing a new piece of work using a cuboid which consists of $A \times B \times C$ unit cubes. He plans to make a beautiful shape by removing $N$ units cubes from the cuboid. When he is about to begin the work, he has noticed that by the removal the cuboid may be divided into several parts disconnected to each other. It is against his aesthetics to divide a cuboid. So he wants to know how many parts are created in his plan.
</p>
<p>
Your task is to calculate the number of connected components in the cuboid after removing the $N$ cubes. Two cubes are connected if they share one face.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case. The test case is formatted as follows:<br/>
<br/>
$A$ $B$ $C$ $N$<br/>
$X_1$ $Y_1$ $Z_1$<br/>
...<br/>
$X_N$ $Y_N$ $Z_N$<br/>
</p>
<p>
The first line contains four integers $A$, $B$, $C$ and $N$. $A$, $B$ and $C$ ($1 \leq A,B,C \leq 10^6$) denote the size of the cuboid $-$ the cuboid has an $A$ unit width from left to right and a $B$ unit height from bottom to top, and a $C$ unit depth from front to back. $N$ ($0 \leq N \leq 20,000, N \leq A \times B \times C - 1$) denotes the number of the cubes removed in the Cubarson's plan. Each of the following $N$ lines contains three integers $X_i$ ($0 \leq X_i \leq A-1$), $Y_i$ ($0 \leq Y_i \leq B-1$) and $Z_i$ ($0 \leq Z_i \leq C - 1$). They denote that the cube located at the $X_i$-th position from the left, the $Y_i$-th from the bottom and the $Z_i$-th from the front will be removed in the plan. You may assume the given positions are distinct.
</p>
<h3>Output</h3>
<p>
Print the number of the connected components in the cuboid after removing the specified cubes.
</p>
<h3>Sample Input 1</h3>
<pre>
2 2 2 4
0 0 0
1 1 0
1 0 1
0 1 1
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>
4
</pre>
<h3>Sample Input 2</h3>
<pre>
3 3 3 1
1 1 1
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>
1
</pre>
<h3>Sample Input 3</h3>
<pre>
1 1 3 2
0 0 0
0 0 2
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>
1
</pre> |
p03809 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a tree with <var>N</var> vertices, numbered <var>1</var> through <var>N</var>.
The <var>i</var>-th of the <var>N-1</var> edges connects vertices <var>a_i</var> and <var>b_i</var>.</p>
<p>Currently, there are <var>A_i</var> stones placed on vertex <var>i</var>.
Determine whether it is possible to remove all the stones from the vertices by repeatedly performing the following operation:</p>
<ul>
<li>Select a pair of different leaves. Then, remove exactly one stone from every vertex on the path between those two vertices.
Here, a <em>leaf</em> is a vertex of the tree whose degree is <var>1</var>, and the selected leaves themselves are also considered as vertices on the path connecting them.</li>
</ul>
<p>Note that the operation cannot be performed if there is a vertex with no stone on the path.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 ⊠N ⊠10^5</var></li>
<li><var>1 ⊠a_i,b_i ⊠N</var></li>
<li><var>0 ⊠A_i ⊠10^9</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>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> ⊠<var>A_N</var>
<var>a_1</var> <var>b_1</var>
:
<var>a_{N-1}</var> <var>b_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is possible to remove all the stones from the vertices, print <code>YES</code>. Otherwise, print <code>NO</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
1 2 1 1 2
2 4
5 2
3 2
1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p>All the stones can be removed, as follows:</p>
<ul>
<li>Select vertices <var>4</var> and <var>5</var>. Then, there is one stone remaining on each vertex except <var>4</var>.</li>
<li>Select vertices <var>1</var> and <var>5</var>. Then, there is no stone on any vertex.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 2 1
1 2
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
3 2 2 2 2 2
1 2
2 3
1 4
1 5
4 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>YES
</pre></section>
</div>
</span> |
p00008 |
<H1>Sum of 4 Integers</H1>
<p>
Write a program which reads an integer <var>n</var> and identifies the number of combinations of <var>a, b, c</var> and <var>d</var> (0 ≤ <var>a, b, c, d</var> ≤ 9) which meet the following equality:<br>
<br>
<var>a + b + c + d = n</var><br>
<br>
For example, for <var>n</var> = 35, we have 4 different combinations of (<var>a, b, c, d</var>): (<var>8, 9, 9, 9</var>), (<var>9, 8, 9, 9</var>), (<var>9, 9, 8, 9</var>), and (<var>9, 9, 9, 8</var>).
</p>
<H2>Input</H2>
<p>
The input consists of several datasets. Each dataset consists of <var>n</var> (1 ≤ <var>n</var> ≤ 50) in a line. The number of datasets is less than or equal to 50.
</p>
<H2>Output</H2>
<p>
Print the number of combination in a line.
</p>
<H2>Sample Input</H2>
<pre>
35
1
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
4
</pre>
|
p02035 |
<h2>F: èµ€é»ããŒãããã / Red-Black Soul Gem</h2>
<h3>åé¡</h3>
<p>
ã»ãã¡ããã¯ãããŒãããããèµ€è²ãé»è²ã«å€åããããã ç°ãªã <var>2</var> ã€ã®ããŒããããéãéæ³ã®ç³žã§æ¥ç¶ãããããäžæè°ãªåãæã£ãŠããŸãã
ãã®åã䜿ãããšã§ãã»ãã¡ããã¯ãããŒããããã«ããéæ¹é£ãäœãããšãã§ããŸãã
</p>
<p>ã»ãã¡ããã¯ã <var>1</var> ãã <var>N</var> ã§çªå·ä»ãããã <var>N</var> åã®ããŒããããããããšãã以äžã®æ¡ä»¶ãæãç«ã€ç°ãªãéæ¹é£ãããã€ããã®ãæ°ã«ãªããŸããã</p>
<ul>
<li> ã©ã® <var>2</var> ã€ã®ããŒããããéããé«ã
<var>1</var> åããæ¥ç¶ãããªãã</li>
<li> ãã¹ãŠã®ããŒããããã®è²ããèµ€è²ãé»è²ã®ããããã«ãªã£ãŠããã</li>
<li> ä»»æã®ããŒããããã«å¯ŸããŠãèªèº«ã®è²ãšç°ãªãè²ã®ããŒããããã®ãã¡ãå°ãªããšã <var>1</var> ã€ãšæ¥ç¶ãããŠããã</li>
</ul>
<p>
ãã®ãšããéæ¹é£ã¯ããŒãããããé ç¹ãšããéæ³ã®ç³žã蟺ãšããã°ã©ããšã¿ãªãããšãã§ããŸãã
ããã§ããã®ã°ã©ã㯠<b>é£çµã§ãªããŠããã</b> ããšã«æ³šæããŠãã ããã
</p>
<p>
ã»ãã¡ããã¯èšç®ãèŠæãªã®ã§ã代ããã«ããªããé«éãªããã°ã©ã ãäœã£ãŠç°ãªãéæ¹é£ã®æ°ãèšç®ããŠãããŸãããã
ãããããã®æ°ã¯éåžžã«å€ãããšãäºæ³ãããã®ã§ãããçŽ æ° <var>M</var> ã§å²ã£ãäœããæ±ããããšã«ããŸãã
</p>
<p>ãªããããéæ¹é£ <var>G</var> ãš <var>H</var> ãç°ãªããšã¯ãããããŒãããã <var>v</var> ã«ã€ã㊠<var>G</var> ãš <var>H</var> ã§ãã®è²ãç°ãªãããããã¯ããããŒããããã®çµ <var>u</var>, <var>v</var> ã <var>G</var> ãš <var>H</var> ã®äžæ¹ã§ã®ã¿æ¥ç¶ãããŠããããšãæããŸãã</p>
<h3>å
¥å圢åŒ</h3>
<pre><var>N</var> <var>M</var></pre>
<h3>å¶çŽ</h3>
<ul>
<li> <var>2 \leq N \leq 2,000</var></li>
<li> <var>10^8 \leq M \leq 10^9 + 7</var></li>
<li> <var>M</var> ã¯çŽ æ°ã§ããããšãä¿èšŒããã</li>
</ul>
<h3>åºå圢åŒ</h3>
<p>æ¡ä»¶ãæºããã°ã©ãã®åæ°ã <var>M</var> ã§å²ã£ãäœããæŽæ°ã§ <var>1</var> è¡ã«åºåããŠãã ããã</p>
<h3>å
¥åäŸ1</h3>
<pre>3 310779401</pre>
<h3>åºåäŸ1</h3>
<pre>12</pre>
<p>äŸãã°ã以äžã®ãããªéæ¹é£ã¯æ¡ä»¶ãæºãããŸãã</p>
<object data="https://judgeapi.u-aizu.ac.jp/resources/images/hupc2019_rupc2019-f-001.jpg" type="image/jpeg" width="300"></object>
<h3>å
¥åäŸ2</h3>
<pre>7 566666561</pre>
<h3>åºåäŸ2</h3>
<pre>98638848</pre>
<p>äŸãã°ã以äžã®ãããªéæ¹é£ã¯æ¡ä»¶ãæºãããŸãã</p>
<object data="https://judgeapi.u-aizu.ac.jp/resources/images/hupc2019_rupc2019-f-002.jpg" type="image/jpeg" width="400"></object>
<h3>å
¥åäŸ3</h3>
<pre>1010 1000000007</pre>
<h3>åºåäŸ3</h3>
<pre>862232855</pre>
<p><var>M</var> ã§å²ã£ãäœããåºåããããšã«æ³šæããŠãã ããã</p>
|
p00458 |
<H1>èæ°·æž¡ã</H1>
<h2>åé¡</h2>
<p>
å¬ã®å¯ãããæ¥ïŒJOI倪éåã¯åºå Žã«ã¯ã£ãèæ°·ãå²ã£ãŠéã¶ããšã«ããïŒåºå Žã¯é·æ¹åœ¢ã§ïŒæ±è¥¿æ¹åã« m åïŒååæ¹åã« n åïŒã€ãŸãïŒ m × n ã®åºç»ã«åºåãããŠããïŒãŸãïŒèæ°·ãæãåºç»ãšç¡ãåºç»ãããïŒ JOI倪éåã¯ïŒæ¬¡ã®ã«ãŒã«ã«ãããã£ãŠïŒèæ°·ãå²ããªããåºç»ãç§»åããããšã«ããïŒ
</p>
<ul>
<li> èæ°·ãããã©ã®åºç»ãããèæ°·ãå²ãå§ããããšãã§ããïŒ</li>
<li> æ±è¥¿ååã®ããããã®æ¹åã«é£æ¥ãïŒ ãŸã å²ãããŠããªãèæ°·ã®ããåºç»ã«ç§»åã§ããïŒ</li>
<li> ç§»åããå
ã®åºç»ã®èæ°·ãããªããå²ãïŒ</li>
</ul>
<p>
JOI倪éåãèæ°·ãå²ããªããç§»åã§ããåºç»æ°ã®æå€§å€ãæ±ããããã°ã©ã ãäœæããïŒãã ãïŒ 1 ≤ m ≤ 90ïŒ1 ≤ n ≤ 90 ã§ããïŒäžããããå
¥åããŒã¿ã§ã¯ïŒç§»åæ¹æ³ã¯20äžéããè¶
ããªãïŒ
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ
</p>
<p>
å
¥åã¯n+2è¡ããïŒ 1 è¡ç®ã«ã¯æŽæ° m ãæžãããŠããïŒ 2 è¡ç®ã«ã¯æŽæ° n ãæžãããŠããïŒ 3 è¡ç®ãã n+2 è¡ç®ãŸã§ã®åè¡ã«ã¯ã0 ããã㯠1 ãïŒ ç©ºçœã§åºåãã㊠m åæžãããŠããïŒååºç»ã«èæ°·ããããåŠãã衚ããŠããïŒåãã i çªç®ïŒè¥¿ããjçªç®ã®åºç»ã (i,j) ãšèšè¿°ããããšã«ãããš (1 ≤ i ≤ n, 1 ≤ j ≤ m)ïŒç¬¬ i+2 è¡ç®ã® j çªç®ã®å€ã¯ïŒåºç» (i,j) ã«èæ°·ãååšããå Žå㯠1 ãšãªãïŒåºç» (i,j) ã«èæ°·ãååšããªãå Žå㯠0 ãšãªãïŒ
</p>
<p>
m, n ããšãã« 0 ã®ãšãå
¥åã®çµäºã瀺ã. ããŒã¿ã»ããã®æ°ã¯ 5 ãè¶
ããªãïŒ
</p>
<h2>åºå</h2>
<p>
ããŒã¿ã»ããããšã«, ç§»åã§ããåºç»æ°ã®æå€§å€ãïŒè¡ã«åºåããïŒ
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ</h3>
<pre>
3
3
1 1 0
1 0 1
1 1 0
5
3
1 1 1 0 1
1 1 0 0 0
1 0 0 0 1
0
0
</pre>
<h3>åºåäŸ</h3>
<pre>
5
5
</pre>
<p>
1ã€ç®ã®å
¥åäŸã«å¯ŸããŠïŒæå€§å€ãäžããç§»åæ¹æ³ã®äŸãã<br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009-yo-t4-1" alt="å
¥åäŸ1ã®å Žå" width=230 height=230>
</p>
<p>
2ã€ç®ã®å
¥åäŸã«å¯ŸããŠïŒæå€§å€ãäžããç§»åæ¹æ³ã®äŸ <br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009-yo-t4-2" alt="å
¥åäŸ2ã®å Žå" width=324 height=194>
</p>
<p>2ã€ç®ã®å
¥åäŸã«å¯ŸããŠïŒæå€§å€ãäžããªãç§»åæ¹æ³ã®äŸ<br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009-yo-t4-2-1" alt="å
¥åäŸ2ã®å Žå1" width=324 height=194>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009-yo-t4-2-2" alt="å
¥åäŸ2ã®å Žå2" width=324 height=194>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009-yo-t4-2-3" alt="å
¥åäŸ2ã®å Žå3" width=324 height=194>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009-yo-t4-2-4" alt="å
¥åäŸ2ã®å Žå4" width=324 height=194>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009-yo-t4-2-5" alt="å
¥åäŸ2ã®å Žå5" width=324 height=194>
</p>
<div class="source">
<p class="source">
äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p02465 | <h1>Set Difference</h1>
<p>
Find the difference of two sets $A = \{a_0, a_1, ..., a_{n-1}\}$ and $B = \{b_0, b_1, ..., b_{m-1}\}$, $A - B$.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$n$
$a_0 \; a_1 \; ... \; a_{n-1}$
$m$
$b_0 \; b_1 \; ... \; b_{m-1}$
</pre>
<p>
Elements in $A$ and $B$ are given in ascending order. There are no duplicate elements in each set.
</p>
<h2>Output</h2>
<p>
Print elements in the difference in ascending order. Print an element in a line.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq n, m \leq 200,000$</li>
<li>$0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$</li>
<li>$0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
5
1 2 3 5 8
2
2 5
</pre>
<h2>Sample Output 1</h2>
<pre>
1
3
8
</pre>
|
p02936 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is a rooted tree with <var>N</var> vertices numbered <var>1</var> to <var>N</var>.
The root is Vertex <var>1</var>, and the <var>i</var>-th edge <var>(1 \leq i \leq N - 1)</var> connects Vertex <var>a_i</var> and <var>b_i</var>.</p>
<p>Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value <var>0</var>.</p>
<p>Now, the following <var>Q</var> operations will be performed:</p>
<ul>
<li>Operation <var>j</var> <var>(1 \leq j \leq Q)</var>: Increment by <var>x_j</var> the counter on every vertex contained in the subtree rooted at Vertex <var>p_j</var>.</li>
</ul>
<p>Find the value of the counter on each vertex after all operations.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 2 \times 10^5</var></li>
<li><var>1 \leq Q \leq 2 \times 10^5</var></li>
<li><var>1 \leq a_i < b_i \leq N</var></li>
<li><var>1 \leq p_j \leq N</var></li>
<li><var>1 \leq x_j \leq 10^4</var></li>
<li>The given graph is a tree.</li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>Q</var>
<var>a_1</var> <var>b_1</var>
<var>:</var>
<var>a_{N-1}</var> <var>b_{N-1}</var>
<var>p_1</var> <var>x_1</var>
<var>:</var>
<var>p_Q</var> <var>x_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the values of the counters on Vertex <var>1, 2, \ldots, N</var> after all operations, in this order, with spaces in between.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 3
1 2
2 3
2 4
2 10
1 100
3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>100 110 111 110
</pre>
<p>The tree in this input is as follows:</p>
<p><img alt="Figure" src="https://img.atcoder.jp/ghi/c771b2231be06af79a9994cbe6867552.png"/></p>
<p>Each operation changes the values of the counters on the vertices as follows:</p>
<ul>
<li>Operation <var>1</var>: Increment by <var>10</var> the counter on every vertex contained in the subtree rooted at Vertex <var>2</var>, that is, Vertex <var>2, 3, 4</var>. The values of the counters on Vertex <var>1, 2, 3, 4</var> are now <var>0, 10, 10, 10</var>, respectively.</li>
<li>Operation <var>2</var>: Increment by <var>100</var> the counter on every vertex contained in the subtree rooted at Vertex <var>1</var>, that is, Vertex <var>1, 2, 3, 4</var>. The values of the counters on Vertex <var>1, 2, 3, 4</var> are now <var>100, 110, 110, 110</var>, respectively.</li>
<li>Operation <var>3</var>: Increment by <var>1</var> the counter on every vertex contained in the subtree rooted at Vertex <var>3</var>, that is, Vertex <var>3</var>. The values of the counters on Vertex <var>1, 2, 3, 4</var> are now <var>100, 110, 111, 110</var>, respectively.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6 2
1 2
1 3
2 4
3 6
2 5
1 10
1 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>20 20 20 20 20 20
</pre></section>
</div>
</span> |
p03624 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>S</var> consisting of lowercase English letters.
Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in <var>S</var>.
If every lowercase English letter occurs in <var>S</var>, print <code>None</code> instead.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 10^5</var> (<var>|S|</var> is the length of string <var>S</var>.)</li>
<li><var>S</var> consists of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the lexicographically smallest lowercase English letter that does not occur in <var>S</var>.
If every lowercase English letter occurs in <var>S</var>, print <code>None</code> instead.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>atcoderregularcontest
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>b
</pre>
<p>The string <code>atcoderregularcontest</code> contains <code>a</code>, but does not contain <code>b</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>abcdefghijklmnopqrstuvwxyz
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>None
</pre>
<p>This string contains every lowercase English letter.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>d
</pre></section>
</div>
</span> |
p01619 |
<h1>G: Computer Onesan / ã³ã³ãã¥ãŒã¿ããããã</h1>
<p>ããæ¥ïŒãããããã¯ïŒåäŸãã¡ã«çµåãã®æ°ãæ¹ã«ã€ããŠæããŠãããããšã«ãªããŸããïŒ</p>
<p>ããã§ïŒãããããã¯ïŒæ¬¡ã®ãããªåé¡ãè§£ããŠã¿ãããšã«ããŸããïŒ</p>
<ul>
<li>瞊å¹
1 ïŒæšªå¹
1 ã®æ£æ¹åœ¢ã瞊å¹
<em>N</em> ïŒæšªå¹
<em>M</em> ã®é·æ¹åœ¢ã«æ·ãè©°ãããšãã«ïŒé·æ¹åœ¢ã®å·Šäžã®é ç¹ããå³äžã®é ç¹ãžã®éãæ¹ãäœéãããããæ°ãã</li>
<li>æ·ãè©°ããæ£æ¹åœ¢ã®èŸºã®äžããéããªã</li>
<li>ããããã®éãæ¹ã¯ïŒåãå Žæã1床ããéããªã</li>
</ul>
<p>å³1ã«ïŒ<em>N</em> = 2, <em>M</em> = 2 ã®å Žåã®å
šãŠã®éãæ¹ã瀺ããŸãïŒ å³1ã§ã¯ïŒå
šéšã§12éãã®éãæ¹ã瀺ããŠããïŒãã®çµè·¯ã¯èµ€ã倪ç·ã§è¡šããŠããŸãïŒ</p>
<div align="center">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_Rits_Camp13_Day3_G_G_fig" width="450" alt="G_fig.png" />
<p><strong>å³1:</strong> <em>N</em> = 2, <em>M</em> = 2 ã®å Žåã®å
šãŠã®éãæ¹</p>
</div>
<p>ãã®åé¡ã§ã¯ïŒ <em>N</em> ãš <em>M</em> ãå°ã倧ãããªãã ãã§ïŒçµåãã®æ°ãççºçã«å¢å ããŠããŸãïŒæã§æ°ããã®ããšãŠãé£ãããªã£ãŠããŸããŸãïŒ ããã§ïŒãããããã¯ïŒèªåã®é è³ãããããã«ç§»æ€ãïŒ25äžå¹ŽããããŠïŒ10 x 10 ã®å Žåã®çµåãã®æ°ãæ°ããèšç»ãç«ãŠãŸããïŒ</p>
<p>ã10 x 10 ãªããŠèšç®ãããšãããããæ»ããããïŒãããŠïŒã</p>
<p>æ¢ããåäŸãã¡ãããã«ïŒãããããã¯ïŒèšç®ãéå§ããŸãïŒ ãããããã¯ïŒãããŸã§ããŠã§ãïŒåäŸãã¡ã«çµåãççºã®ããããæããŠããããã®ã§ãïŒ</p>
<p>ãããããã®ç±æã«å¿æãããããã°ã©ããŒã®ããªãã¯ïŒãã®åé¡ãè§£ãããã°ã©ã ãæžããŠãããããšã«ããŸããïŒ ãšãã£ãŠãïŒãããªã 10 x 10 ãèšç®ããããã°ã©ã ãäœãã®ã¯é£ããã®ã§ïŒæå§ãã« <em>M</em> ãå°ããå Žåã®ããã°ã©ã ãæžãããšã«ããŸããïŒ</p>
<div>
<h1>Input</h1>
<p>å
¥åã¯ïŒ1è¡ã«ïŒ <em>N</em> ãš <em>M</em> ãåè§ã¹ããŒã¹ã§äžããããŸãïŒ <em>N</em> ã¯é·æ¹åœ¢ã®çžŠã®å¹
ã§ïŒ1 <= <em>N</em> <= 100ãæºãããŸãïŒ <em>M</em> ã¯é·æ¹åœ¢ã®æšªã®å¹
ã§ïŒ1 <= <em>M</em> <= 2ãæºãããŸãïŒ</p>
</div>
<div>
<h1>Output</h1>
<p>å
¥åã«å¯Ÿããéãæ¹ã®æ°ã1è¡ã«åºåããŠãã ããïŒ ãã ãïŒçããéåžžã«å€§ãããªãå Žåãããã®ã§ïŒ1,000,000ã§å²ã£ãäœããåºåããŠãã ããïŒ</p>
</div>
<div>
<h1>Sample Input 1</h1>
<pre>
1 1
</pre>
</div>
<div>
<h1>Sample Output 1</h1>
<pre>
2
</pre>
</div>
<div>
<h1>Sample Input 2</h1>
<pre>
1 2
</pre>
</div>
<div>
<h1>Sample Output 2</h1>
<pre>
4
</pre>
</div>
<div>
<h1>Sample Input 3</h1>
<pre>
2 1
</pre>
</div>
<div>
<h1>Sample Output 3</h1>
<pre>
4
</pre>
</div>
<div>
<h1>Sample Input 4</h1>
<pre>
2 2
</pre>
</div>
<div>
<h1>Sample Output 4</h1>
<pre>
12
</pre>
</div>
<div>
<h1>Sample Input 5</h1>
<pre>
3 2
</pre>
</div>
<div>
<h1>Sample Output 5</h1>
<pre>
38
</pre>
</div>
|
p03274 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> candles placed on a number line.
The <var>i</var>-th candle from the left is placed on coordinate <var>x_i</var>.
Here, <var>x_1 < x_2 < ... < x_N</var> holds.</p>
<p>Initially, no candles are burning.
Snuke decides to light <var>K</var> of the <var>N</var> candles.</p>
<p>Now, he is at coordinate <var>0</var>.
He can move left and right along the line with speed <var>1</var>.
He can also light a candle when he is at the same position as the candle, in negligible time.</p>
<p>Find the minimum time required to light <var>K</var> candles.</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 K \leq N</var></li>
<li><var>x_i</var> is an integer.</li>
<li><var>|x_i| \leq 10^8</var></li>
<li><var>x_1 < x_2 < ... < x_N</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>x_1</var> <var>x_2</var> <var>...</var> <var>x_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum time required to light <var>K</var> candles.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 3
-30 -10 10 20 50
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>40
</pre>
<p>He should move and light candles as follows:</p>
<ul>
<li>Move from coordinate <var>0</var> to <var>-10</var>.</li>
<li>Light the second candle from the left.</li>
<li>Move from coordinate <var>-10</var> to <var>10</var>.</li>
<li>Light the third candle from the left.</li>
<li>Move from coordinate <var>10</var> to <var>20</var>.</li>
<li>Light the fourth candle from the left.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 2
10 20 30
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>20
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<ul>
<li>There may be a candle placed at coordinate <var>0</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>8 5
-9 -7 -4 -3 1 2 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>10
</pre></section>
</div>
</span> |
p01249 |
<H1><font color="#000">Problem J:</font> Billion Million Thousand</H1>
<p>
A linguist, Nodvic Natharus Damenhof (commonly called <i>Dr. Usoperant</i>), invented an artificial language <i>Usoperant</i> in 2007. The word <i>usoperant</i> means âone which tiresâ. Damenhofâs goal was to create a complex and
pedantic language that would remind many difficulties in universal communications. Talking in Usoperant, you
should remember the importance of choosing your words in many conversations.
</p>
<p>
For example of the complexity, you may be confused by the way to say large numbers. Usoperant has some
words that indicate exponential numbers in decimal, described as 10<sup><i>p</i></sup> where <i>p</i> is a positive integer. In terms of
English, those words might include thousand for 10<sup>3</sup> (1,000), million for 10<sup>6</sup> (1,000,000), and <i>undecillion</i> for
10<sup>36</sup> (1,000,000,000,000,000,000,000,000,000,000,000,000).
</p>
<p>
You can concatinate those words to express larger numbers. When two words <i>w</i><sub>1</sub> and <i>w</i><sub>2</sub> mean numbers 10<sup><i>p</i><sub>1</sub></sup>
and 10<sup><i>p</i><sub>2</sub></sup> respectively, a concatinated word <i>w</i><sub>1</sub><i>w</i><sub>2</sub> means 10<sup><i>p</i><sub>1</sub>+<i>p</i><sub>2</sub></sup>. Using the above examples in English (actually
the following examples are incorrect in English), you can say 10<sup>9</sup> by <i>millionthousand</i>, 10<sup>12</sup> by <i>millionmillion</i>
and 10<sup>39</sup> by <i>undecillionthousand</i>. Note that there can be multiple different expressions for a certain number.
For example, 10<sup>9</sup> can also be expressed by <i>thousandthousandthousand</i>. It is also possible to insert separators
between the adjacent components like <i>million-thousand</i> and <i>thousand-thousand-thousand</i>.
</p>
<p>
In this problem, you are given a few of such words, their representing digits and an expression of a certain number
in Usoperant. Your task is to write a program to calculate the length of the shortest expression which represents
the same number as the given expression.
</p>
<p>
The expressions in the input do not contain any separators like <i>millionthousand</i>. In case of ambiguity, the
expressions should be interpreted as the largest number among possibles. The resultant expressions should
always contain separators like <i>million-thousand</i>, so we can distinguish, for example, <i>x</i>-<i>x</i> (a concatinated word of
two <i>x</i>'s) and <i>xx</i> (just a single word). The separators should not be counted in the length.
</p>
<H2>Input</H2>
<p>
The input consists of multiple test cases. Each test case begins with a line including an integer <i>N</i> (1 ≤ <i>N</i> ≤ 100).
The integer <i>N</i> indicates the number of words in the dictionary of exponential numbers.
</p>
<p>
The following <i>N</i> lines give the words in the dictionary. Each line contains a word <i>w<sub>i</sub></i> and an integer <i>p<sub>i</sub></i> (1 ≤ <i>i</i> ≤ <i>N</i>,
1 ≤ <i>p<sub>i</sub></i> ≤ 10), specifying that the word <i>w<sub>i</sub></i> expresses an exponential number 10<sup><i>p<sub>i</sub></i></sup> in Usoperant. Each <i>w<sub>i</sub></i> consists
of at most 100 alphabetical letters.
</p>
<p>
Then a line which contains an expression of a number in Usoperant follows. The expression consists of at most
200 alphabetical letters.
</p>
<p>
The end of the input is indicated by a line which contains only a single 0.
</p>
<H2>Output</H2>
<p>
For each test case, print a line which contains the case number and the length of the shortest expression which
represents the same number as the given expression in the input.
</p>
<H2>Sample Input</H2>
<pre>
3
billion 9
million 6
thousand 3
billionmillionthousand
3
oku 8
sen 3
man 4
okusenman
2
nico 2
video 4
niconicovideo
6
abcd 1
efgh 2
abcde 4
fgh 6
y 8
yy 10
abcdefgh
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Case 1: 14
Case 2: 9
Case 3: 10
Case 4: 2
</pre>
<H2>Note:</H2>
<p>
In the fourth case, the word <i>abcdefgh</i> can be separated as <i>abcd-efgh</i> (representing 10<sup>3</sup> ) and <i>abcde-fgh</i>
(representing 10<sup>10</sup> ), and by the rule described in the problem statement, this word should be interpreted as 10<sup>10</sup>.
As this number can be expressed by <i>yy</i>, the length of the shortest expression is two (as in the sample output). The
existence of <i>y</i>-<i>y</i> (representing 10<sup>16</sup> ) is not a problem here, because we can distinguish <i>yy</i> and <i>y</i>-<i>y</i> as long as we
always use separators.
</p>
|
p02873 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is a string <var>S</var> of length <var>N-1</var>.
Each character in <var>S</var> is <code><</code> or <code>></code>.</p>
<p>A sequence of <var>N</var> non-negative integers, <var>a_1,a_2,\cdots,a_N</var>, is said to be <em>good</em> when the following condition is satisfied for all <var>i</var> (<var>1 \leq i \leq N-1</var>):</p>
<ul>
<li>If <var>S_i=</var> <code><</code>: <var>a_i<a_{i+1}</var></li>
<li>If <var>S_i=</var> <code>></code>: <var>a_i>a_{i+1}</var></li>
</ul>
<p>Find the minimum possible sum of the elements of a good sequence of <var>N</var> non-negative integers.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 5 \times 10^5</var></li>
<li><var>S</var> is a string of length <var>N-1</var> consisting of <code><</code> and <code>></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>Find the minimum possible sum of the elements of a good sequence of <var>N</var> non-negative integers.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre><>>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p><var>a=(0,2,1,0)</var> is a good sequence whose sum is <var>3</var>.
There is no good sequence whose sum is less than <var>3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre><>>><<><<<<<>>><
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>28
</pre></section>
</div>
</span> |
p03761 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string.</p>
<p>He will receive a headline which contains one of the strings <var>S_1,...,S_n</var> tomorrow.
He is excited and already thinking of what string he will create.
Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains.</p>
<p>Find the longest string that can be created regardless of which string among <var>S_1,...,S_n</var> the headline contains.
If there are multiple such strings, find the lexicographically smallest one among them.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq n \leq 50</var></li>
<li><var>1 \leq |S_i| \leq 50</var> for every <var>i = 1, ..., n</var>.</li>
<li><var>S_i</var> consists of lowercase English letters (<code>a</code> - <code>z</code>) for every <var>i = 1, ..., n</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>n</var>
<var>S_1</var>
<var>...</var>
<var>S_n</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the lexicographically smallest string among the longest strings that satisfy the condition.
If the answer is an empty string, print an empty line.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
cbaa
daacc
acacac
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>aac
</pre>
<p>The strings that can be created from each of <code>cbaa</code>, <code>daacc</code> and <code>acacac</code>, are <code>aa</code>, <code>aac</code>, <code>aca</code>, <code>caa</code> and so forth.
Among them, <code>aac</code>, <code>aca</code> and <code>caa</code> are the longest, and the lexicographically smallest of these three is <code>aac</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
a
aa
b
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>
</pre>
<p>The answer is an empty string.</p></section>
</div>
</span> |
p03331 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi has two positive integers <var>A</var> and <var>B</var>.</p>
<p>It is known that <var>A</var> plus <var>B</var> equals <var>N</var>.
Find the minimum possible value of "the sum of the digits of <var>A</var>" plus "the sum of the digits of <var>B</var>" (in base <var>10</var>).</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 †N †10^5</var></li>
<li><var>N</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible value of "the sum of the digits of <var>A</var>" plus "the sum of the digits of <var>B</var>".</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>15
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>When <var>A=2</var> and <var>B=13</var>, the sums of their digits are <var>2</var> and <var>4</var>, which minimizes the value in question.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>100000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>10
</pre></section>
</div>
</span> |
p02170 | <h1>Problem I: Coin and Die</h1>
<h2>Problem</h2>
<p>
衚ãšè£ã®ããã³ã€ã³ãš $1$ ãã $N$ ãŸã§ã®ç®ããããµã€ã³ãããããGachoããã¯ããããçšããŠä»¥äžã®ã²ãŒã ãããŠéã¶ããšã«ããã<br><br>
ã²ãŒã ã¯æåã«åŸç¹ã $0$ ã®ç¶æ
ããå§ãŸãã以äžã®æé ã§é²ããããã<br>
</p>
<ol type="1">
<li>ãµã€ã³ãã $1$ 忝ãããã®ãšãåºãç®ã®æ°ãåŸç¹ã«å ç®ãã</li>
<li>çŸåšã®åŸç¹ã $K$ 以äžãªãã²ãŒã ã¯ãªã¢ãšãªãã²ãŒã ãçµäºãã</li>
<li>çŸåšã®åŸç¹ã $K$ æªæºãªãã³ã€ã³ãæã衚ãåºãã°1.ã«æ»ããè£ãåºãã°ã²ãŒã ãªãŒããŒãšãªãã²ãŒã ãçµäºãã</li>
</ol>
<p>
ã³ã€ã³ã¯æãããš $A\%$ã®ç¢ºçã§è¡šã«ãªãã $(100-A)\%$ã®ç¢ºçã§è£ã«ãªãããŸãããµã€ã³ãã¯æ¯ããšãããããã®ç®ãç確çã§åºçŸããã<br>
ãã®ãšããäžåºŠã®ã²ãŒã ã§Gachoãããã²ãŒã ã¯ãªã¢ããããšãã§ãã確çãæ±ããã<br>
æ±ãã確çãäºãã«çŽ ãªæŽæ° $P, Q$ ãçšã㊠$\frac{P}{Q}$ ãšè¡šãããšãã $R \times Q \equiv P\bmod 998244353$ ãšãªã $0$ ä»¥äž $998244352$ 以äžã®æŽæ° $R$ ãåºåããããã®åé¡ã®å¶çŽäžã§ããã®ãã㪠$R$ ã¯å¿
ãäžæã«ååšããã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
$N$ $K$ $A$
</pre>
<p>
$N, K, A$ ã空çœåºåãã§äžè¡ã«äžããããã<br>
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>$1 \leq N \leq 10^5 $</li>
<li>$1 \leq K \leq 10^5 $</li>
<li>$1 \leq A \leq 99 $</li>
<li>å
¥åã¯ãã¹ãп޿°</li>
</ul>
<h2>Output</h2>
<p>
ã²ãŒã ãã¯ãªã¢ããããšãã§ãã確çãäºãã«çŽ ãªæŽæ° $P, Q$ãçšã㊠$\frac{P}{Q}$ ãšè¡šãããšãã$R \times Q\equiv P\bmod 998244353$ ãšãªã $0$ ä»¥äž $998244352$ 以äžã®æŽæ° $R$ ãåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
1 1 50
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<h2>Sample Input 2</h2>
<pre>
2 2 10
</pre>
<h2>Sample Output 2</h2>
<pre>
648858830
</pre>
<h2>Sample Input 3</h2>
<pre>
6 10 99
</pre>
<h2>Sample Output 3</h2>
<pre>
650893870
</pre>
|
p01025 | <h1>Problem J: Hanimon</h1>
<p>
ããã«ã ã¢ã³ã¹ã¿ãŒã¯ããã«ã æš¡æ§ã®å
è§åœ¢ç¶ã®äžæè°ãªçãç©ã§ããã
</p>
<p>
ããã«ã ã¢ã³ã¹ã¿ãŒã«ã¯æ§ã
ãªãµã€ãºã®ãã®ããããäžèŸºã<em>N</em>åã®æ£å
è§åœ¢ã®ãã¹ããæãããã«ã ã¢ã³ã¹ã¿ãŒããµã€ãº<em>N</em>ã®ããã«ã ã¢ã³ã¹ã¿ãŒãšããã
</p>
<p>
äžæ¹ãèãªãæš¡æ§ã¯ããã«ã ã¢ã³ã¹ã¿ãŒãšåãããå
è§åœ¢ãšããŠå®çŸ©ãã1蟺ã<em>P</em>åã®æ£å
è§åœ¢ã®ãã¹ããæãèãªãæš¡æ§ããµã€ãº<em>P</em>ã®èãªãæš¡æ§ãšããã
</p>
<p>
ããã«ã ã¢ã³ã¹ã¿ãŒãšèãªãæš¡æ§ã®åœ¢ã®äŸã以äžã«ç€ºãããµã€ãºã¯1èŸºã®æ£å
è§åœ¢ã®ãã¹ã®æ°ã«å¯Ÿå¿ããã
</p>
<div align="center">
<img alt="sample1.png" src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RitsCamp14Day2_Hanimon_sample1.png" style="margin-bottom: 8px" width="50%" height="50%" /><br>
<strong>å³1:</strong>ãµã€ãºã®äŸ
<br>
<br>
<img width="680" alt="sample2.png" src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RitsCamp14Day2_Hanimon_sample2.png"/><br>
<strong>å³2:</strong>ããã«ã ã¢ã³ã¹ã¿ãŒãšèãªãæš¡æ§ã®äŸ (Sample Input 1)
</div>
<p>
ããã«ã ã¢ã³ã¹ã¿ãŒãšèãªãæš¡æ§ã®åãã¹ã«ã¯è²ãçããŠãã0ãš1ã«ãã£ãŠè¡šãããã
</p>
ãµã€ãº<em>P</em>ã®<em>Q</em>åã®èãªãæš¡æ§ã®ãã¹ãŠãå«ãããã«ã ã¢ã³ã¹ã¿ãŒã¯äŒèª¬ã®ããã¢ã³ãšåŒã°ããŠããã
<p>
ãµã€ãº<em>N</em>ã®ããã«ã ã¢ã³ã¹ã¿ãŒãšãã®æš¡æ§ã<em>Q</em>åã®ãµã€ãº<em>P</em>ã®èãªãæš¡æ§ãäžããããã®ã§ã
ãã®ããã«ã ã¢ã³ã¹ã¿ãŒãäŒèª¬ã®ããã¢ã³ã§ãããã©ãããå€å®ããããã°ã©ã ãäœæããã
</p>
<div>
<h1>Input</h1>
<p>å
¥åã¯æ¬¡ã®åœ¢åŒã§è¡šãããã</p>
<pre>
<em>N</em> <em>P</em> <em>Q</em>
(空è¡)
ããã«ã ã¢ã³ã¹ã¿ãŒã®æš¡æ§ã®æ
å ±
(空è¡)
1ã€ç®ã®èãªãæš¡æ§ã®æ
å ±
(空è¡)
2ã€ç®ã®èãªãæš¡æ§ã®æ
å ±
(空è¡)
...
<em>Q</em>ã€ç®ã®èãªãæš¡æ§ã®æ
å ±
</pre>
<p>
<em>N</em>,<em>P</em>,<em>Q</em>ã¯ããããããã«ã ã¢ã³ã¹ã¿ãŒã®ãµã€ãº,èãªãæš¡æ§ã®ãµã€ãº,èãªãæš¡æ§ã®åæ°ã衚ãã
</p>
<p>
ãµã€ãº<em>N</em>ã®ããã«ã ã¢ã³ã¹ã¿ãŒã®æš¡æ§ã®æ
å ±ã¯ä»¥äžã®æ§ã«2Ã<em>N</em>-1è¡ã§äžããããã
</p>
<pre>
<em>N</em>åã®ãã¹
<em>N</em>+1åã®ãã¹
<em>N</em>+2åã®ãã¹
.
.
2Ã<em>N</em>-2åã®ãã¹
2Ã<em>N</em>-1åã®ãã¹
2Ã<em>N</em>-2åã®ãã¹
.
.
<em>N</em>+2åã®ãã¹
<em>N</em>+1åã®ãã¹
<em>N</em>åã®ãã¹
</pre>
<p>
ãµã€ãº<em>P</em>ã®èãªãæš¡æ§ã®æ
å ±ã¯ä»¥äžã®æ§ã«2Ã<em>P</em>-1è¡ã§äžããããã
</p>
<pre>
<em>P</em>åã®ãã¹
<em>P</em>+1åã®ãã¹
<em>P</em>+2åã®ãã¹
.
.
2Ã<em>P</em>-2åã®ãã¹
2Ã<em>P</em>-1åã®ãã¹
2Ã<em>P</em>-2åã®ãã¹
.
.
<em>P</em>+2åã®ãã¹
<em>P</em>+1åã®ãã¹
<em>P</em>åã®ãã¹
</pre>
<p>
ããããã®ãã¹ã®éã«ã¯ïŒã€ã®ç©ºçœãå
¥ãããã¹ã«ã¯ïŒã1ãå
¥ãã
</p>
<h1>Constraints</h1>
<div>
<ul>
<li>1 ≤ <em>N</em> ≤ 1000 </li>
<li>1 ≤ <em>P</em> ≤ 50 </li>
<li>1 ≤ <em>Q</em> ≤ 100 </li>
<li>åãæš¡æ§ã®èãªãæš¡æ§ãè€æ°åäžããããããšã¯ç¡ãã</li>
<li>ããã«ã ã¢ã³ã¹ã¿ãŒã®ãããã¹ã«ã€ããŠã2ã€ä»¥äžã®èãªãæš¡æ§ã®äžéšåã§ããããšãããã</li>
<li>ããã«ã ã¢ã³ã¹ã¿ãŒãšèãªãæš¡æ§ã¯å転ã§ããªãã</li>
</ul>
</div>
</div>
<h1>Output</h1>
<p>äŒèª¬ã®ããã¢ã³ãªã YES ããããã§ãªããã° NO ãäžè¡ã«åºåããã</p>
<h1>Sample Input 1</h1>
<pre>
6 2 2
1 1 1 1 1 1
1 0 0 0 0 1 0
1 0 1 0 0 1 0 1
1 1 1 1 1 1 1 0 0
0 0 1 0 0 0 1 0 1 1
1 1 1 0 1 0 0 1 1 0 1
0 1 0 1 0 0 1 1 1 0
0 1 1 1 1 0 0 1 1
0 0 0 0 1 0 1 0
1 1 1 0 1 1 0
0 1 1 0 0 1
0 1
1 1 1
1 0
0 0
0 1 0
1 1
</pre>
<h1>Sample Output 1</h1>
<pre>
YES
</pre>
<h1>Sample Input 2</h1>
<pre>
6 2 2
0 0 0 1 0 0
1 0 1 1 0 0 1
1 0 1 0 0 1 1 0
0 1 0 1 0 0 0 0 0
0 0 1 1 1 1 0 0 1 1
0 0 0 1 0 0 1 1 0 0 0
0 0 1 0 0 1 1 0 1 1
1 0 0 1 1 1 1 1 1
0 1 0 0 1 0 0 0
0 0 1 0 1 0 0
0 1 1 0 1 0
1 0
1 0 0
1 1
0 1
0 0 1
0 1
</pre>
<h1>Sample Output 2</h1>
<pre>
NO
</pre>
|
p03018 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>s</var> consisting of <code>A</code>, <code>B</code> and <code>C</code>.</p>
<p>Snuke wants to perform the following operation on <var>s</var> as many times as possible:</p>
<ul>
<li>Choose a contiguous substring of <var>s</var> that reads <code>ABC</code> and replace it with <code>BCA</code>.</li>
</ul>
<p>Find the maximum possible number of operations.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |s| \leq 200000</var></li>
<li>Each character of <var>s</var> is <code>A</code>, <code>B</code> and <code>C</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>Find the maximum possible number of operations.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>ABCABC
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>You can perform the operations three times as follows: <code>ABCABC</code> â <code>BCAABC</code> â <code>BCABCA</code> â <code>BCBCAA</code>. This is the maximum result.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>C
</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>ABCACCBABCBCAABCB
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>6
</pre></section>
</div>
</span> |
p01475 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<h2>å顿</h2>
<p>1ã€ã®é°é¢æ° $Ax^2+Bxy+Cy^2+Dx+Ey+F=0$ ã§äžããããæ²ç·ãšã
$N$ åã®é°é¢æ° $A_ix+B_iy+C_i=0$ ã§äžããããçŽç·ãããã
ãããã®æ²ç·ãšçŽç·ã«ãã£ãŠå¹³é¢ãããã€ã®é åã«åå²ãããŠãããæ±ããã</p>
<p>以äžã¯Sample Inputã®ããŒã¿ã»ãããå³ç€ºãããã®ã§ããã</p>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_plane_division_sample1" width="240" height="240">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_plane_division_sample2" width="240" height="240">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_plane_division_sample3" width="240" height="240">
</p>
<h2>å
¥å</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã«åŸããäžããããæ°ã¯å
šãп޿°ã§ããã</p>
<pre>$N$
$A$ $B$ $C$ $D$ $E$ $F$
$A_1$ $B_1$ $C_1$
$...$
$A_N$ $B_N$ $C_N$</pre>
<h2>å¶çŽ</h2>
<ul><li>$1 \leq N \leq 20$</li>
<li>$-100 \leq A,B,C,D,E,F \leq 100$</li>
<li>$-100 \leq A_i,B_i,C_i \leq 100$</li>
<li>$A_i \neq 0$ ãŸã㯠$B_i \neq 0$</li>
<li>æ²ç·ã¯æ¥å(æ£åãå«ã)ãæŸç©ç·ãåæ²ç·ã®ããããã§ããã</li>
<li>åäžã®çŽç·ãååšããå Žåãããã</li></ul>
<h2>åºå</h2>
<p>é åã®æ°ã1è¡ã«åºåããã</p>
<h2>Sample Input 1</h2>
<pre>1
1 0 1 0 0 -1
1 -1 0</pre>
<h2>Output for the Sample Input 1</h2>
<pre>4</pre>
<h2>Sample Input 2</h2>
<pre>2
1 0 0 0 -1 0
2 -1 -1
6 9 1</pre>
<h2>Output for the Sample Input 2</h2>
<pre>7</pre>
<h2>Sample Input 3</h2>
<pre>2
1 0 -1 0 0 -1
3 0 6
-5 0 -10</pre>
<h2>Output for the Sample Input 3</h2>
<pre>6</pre>
|
p03448 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have <var>A</var> <var>500</var>-yen coins, <var>B</var> <var>100</var>-yen coins and <var>C</var> <var>50</var>-yen coins (yen is the currency of Japan).
In how many ways can we select some of these coins so that they are <var>X</var> yen in total?</p>
<p>Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 \leq A, B, C \leq 50</var></li>
<li><var>A + B + C \geq 1</var></li>
<li><var>50 \leq X \leq 20</var> <var>000</var></li>
<li><var>A</var>, <var>B</var> and <var>C</var> are integers.</li>
<li><var>X</var> is a multiple of <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>A</var>
<var>B</var>
<var>C</var>
<var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways to select coins.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
2
2
100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>There are two ways to satisfy the condition:</p>
<ul>
<li>Select zero <var>500</var>-yen coins, one <var>100</var>-yen coin and zero <var>50</var>-yen coins.</li>
<li>Select zero <var>500</var>-yen coins, zero <var>100</var>-yen coins and two <var>50</var>-yen coins.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
1
0
150
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>Note that the total must be exactly <var>X</var> yen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>30
40
50
6000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>213
</pre></section>
</div>
</span> |
p02609 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let <var>\mathrm{popcount}(n)</var> be the number of <code>1</code>s in the binary representation of <var>n</var>.
For example, <var>\mathrm{popcount}(3) = 2</var>, <var>\mathrm{popcount}(7) = 3</var>, and <var>\mathrm{popcount}(0) = 0</var>.</p>
<p>Let <var>f(n)</var> be the number of times the following operation will be done when we repeat it until <var>n</var> becomes <var>0</var>: "replace <var>n</var> with the remainder when <var>n</var> is divided by <var>\mathrm{popcount}(n)</var>." (It can be proved that, under the constraints of this problem, <var>n</var> always becomes <var>0</var> after a finite number of operations.)</p>
<p>For example, when <var>n=7</var>, it becomes <var>0</var> after two operations, as follows:</p>
<ul>
<li><var>\mathrm{popcount}(7)=3</var>, so we divide <var>7</var> by <var>3</var> and replace it with the remainder, <var>1</var>.</li>
<li><var>\mathrm{popcount}(1)=1</var>, so we divide <var>1</var> by <var>1</var> and replace it with the remainder, <var>0</var>.</li>
</ul>
<p>You are given an integer <var>X</var> with <var>N</var> digits in binary.
For each integer <var>i</var> such that <var>1 \leq i \leq N</var>, let <var>X_i</var> be what <var>X</var> becomes when the <var>i</var>-th bit from the top is inverted.
Find <var>f(X_1), f(X_2), \ldots, f(X_N)</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2 \times 10^5</var></li>
<li><var>X</var> is an integer with <var>N</var> digits in binary, possibly with leading zeros.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>X</var>
</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 value <var>f(X_i)</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
011
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
1
1
</pre>
<ul>
<li><var>X_1 = 7</var>, which will change as follows: <var>7 \rightarrow 1 \rightarrow 0</var>. Thus, <var>f(7) = 2</var>.</li>
<li><var>X_2 = 1</var>, which will change as follows: <var>1 \rightarrow 0</var>. Thus, <var>f(1) = 1</var>.</li>
<li><var>X_3 = 2</var>, which will change as follows: <var>2 \rightarrow 0</var>. Thus, <var>f(2) = 1</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>23
00110111001011011001110
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
1
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
3
</pre></section>
</div>
</span> |
p00634 |
<H1><font color="#000000">Problem 08:</font> Provident Housewife</H1>
<p>
䞻婊ã®çŽåã¯ãã®äžæ³ã®ããªãé£è²»ãæããããšã«éå¿ãçãããŠããŸãããæ¯ææ°èåºåãå¿
ããã§ãã¯ãè²·ãç©ãªã¹ããšæãå®ã売ãããŠãããåºããã£ãããªã¹ãã¢ããããŠããåºãã¯ããããªããããšããã³ã»ãµã³ãã«ãšããæŠéã¹ã¿ã€ã«ã§èªè»¢è»ãããããè²·ãç©ã«è¡ããŸãã
</p>
<p>
ããã§å€«ã®ããªãã¯å°ãã§ãçŽåã®åœ¹ã«ç«ãšããšãåŸæã®ããã°ã©ãã³ã°ã§å®¶èšç°¿ããã°ã©ã ãäœæããããšã«ããŸãããããã°ã©ã ã¯ãåã¹ãŒããŒã«å£²ã£ãŠããåç©ã®ååãšå€æ®µïŒåïŒãçŽåãå¿
èŠãªåç©ãå
¥åããå
šãŠã®åç©ãéããããã®æå°éé¡ãåºåããŸãã
</p>
<p>
çŽåã¯å®¶ãåºãŠå¿
èŠãªåç©ãéããå®¶ã«æ»ã£ãŠããªããã°ãªããŸããã
ããã§ãçŽåãæ°é£ã£ãããªãã¯ãæå°éé¡ãåãã«ãªãè²·ãç©ã«ãŒããè€æ°ããå Žåãèæ
®ããŠãããè·é¢ãçããªãã«ãŒãã®è·é¢ãå ±åããæ©èœã远å ããããšã«ããŸãããåŸã£ãŠãããã°ã©ã ã¯ã¹ãŒããŒã»å®¶éãç¹ãéã®æ
å ±ãå
¥åããŸãã
</p>
<p>
ã¹ãŒããŒã®æ°ã <i>n</i> ãšããåã¹ãŒããŒã«ã¯ãããã 1 ãã <i>n</i> ãŸã§ã®çªå·ãå²ãåœãŠãããŸããããã«çŽåã®å®¶ã 0 çªãšããŸããéã®æ
å ±ã¯ãããã®çªå·ã®ãã¢ãšãã®è·é¢ïŒæŽæ°ïŒã§äžããããŸãã
</p>
<H2>Input</H2>
<p>
å
¥åãšããŠè€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã®åœ¢åŒã¯ä»¥äžã®éãã§ãïŒ<br>
<br>
<i>n</i>ãïŒã¹ãŒããŒã®æ°ïŒæŽæ°ïŒ<br>
<i>k</i><sub>1</sub> <i>name</i><sub>1</sub> <i>value</i><sub>1</sub> <i>name</i><sub>2</sub> <i>value</i><sub>2</sub> . . . <i>name</i><sub><i>k</i><sub>1</sub></sub> <i>value</i><sub><i>k</i><sub>1</sub></sub>ïŒ1 çªç®ã®ã¹ãŒããŒã«ããåç©ã®çš®é¡ã®æ°ã1ã€ç®ã®åç©åãšå€æ®µã2ã€ç®ã®åç©åãšå€æ®µ,,,ïŒæŽæ°ãšæååã®ç©ºçœåºåãïŒ<br>
<i>k</i><sub>2</sub> <i>name</i><sub>1</sub> <i>value</i><sub>1</sub> <i>name</i><sub>2</sub> <i>value</i><sub>2</sub> . . . <i>name</i><sub><i>k</i><sub>2</sub></sub> <i>value</i><sub><i>k</i><sub>2</sub></sub>ïŒ2 çªç®ã®ã¹ãŒããŒã«ããåç©ã®çš®é¡ã®æ°ã1ã€ç®ã®åç©åãšå€æ®µã2ã€ç®ã®åç©åãšå€æ®µ,,,ïŒæŽæ°ãšæååã®ç©ºçœåºåãïŒ<br>
.<br>
.<br>
<i>k</i><sub><i>n</i></sub> <i>name</i><sub>1</sub> <i>value</i><sub>1</sub> <i>name</i><sub>2</sub> <i>value</i><sub>2</sub> . . . <i>name</i><sub><i>k</i><sub><i>n</i></sub></sub> <i>value</i><sub><i>k</i><sub><i>n</i></sub></sub>ïŒ<i>n</i> çªç®ã®ã¹ãŒããŒã«ããåç©ã®çš®é¡ã®æ°ã1ã€ç®ã®åç©åãšå€æ®µã2ã€ç®ã®åç©åãšå€æ®µ,,,ïŒæŽæ°ãšæååã®ç©ºçœåºåãïŒ<br>
<i>q</i>ãïŒå¿
èŠãªåç©ã®æ°ïŒæŽæ°ïŒ<br>
<i>name</i><sub>1</sub>ãïŒ1 ã€ç®ã®å¿
èŠãªåç©ã®ååïŒæååïŒ<br>
<i>name</i><sub>2</sub>ãïŒ2 ã€ç®ã®å¿
èŠãªåç©ã®ååïŒæååïŒ<br>
.<br>
.<br>
<i>name</i><sub><i>q</i></sub>ãïŒ<i>q</i> ã€ç®ã®å¿
èŠãªåç©ã®ååïŒæååïŒ<br>
<i>m</i>ãïŒéã®æ°ïŒæŽæ°ïŒ<br>
<i>s</i><sub>1</sub> <i>t</i><sub>1</sub> <i>d</i><sub>1</sub>ãïŒ1 æ¬ç®ã®éã®æ
å ±ïŒç©ºçœåºåãã®æŽæ°ïŒ<br>
<i>s</i><sub>2</sub> <i>t</i><sub>2</sub> <i>d</i><sub>2</sub>ãïŒ2 æ¬ç®ã®éã®æ
å ±ïŒç©ºçœåºåãã®æŽæ°ïŒ<br>
.<br>
.<br>
<i>s</i><sub><i>m</i></sub> <i>t</i><sub><i>m</i></sub> <i>d</i><sub><i>m</i></sub>ãïŒ<i>m</i> æ¬ç®ã®éã®æ
å ±ïŒç©ºçœåºåãã®æŽæ°ïŒ<br>
</p>
<p>
<i>s<sub>i</sub></i> <i>t<sub>i</sub></i> <i>d<sub>i</sub></i> 㯠<i>s<sub>i</sub></i>çªç®ã®ã¹ãŒããŒïŒãŸãã¯å®¶ïŒãš <i>t<sub>i</sub></i>çªç®ã®ã¹ãŒããŒïŒãŸãã¯å®¶ïŒãåæ¹åã«è¡ãæ¥ããããšãã§ãããã®è·é¢ã <i>d<sub>i</sub></i>ã§ããããšã瀺ããŸãã
</p>
<p>
å®¶ããïŒã¹ãŒããŒãçµç±ããŠïŒå
šãŠã®ã¹ãŒããŒãžè¡ãããšãã§ãããããªéãäžããããŸãã
</p>
<p>
<i>n</i> 㯠10 以äžã§ããã<i>q</i> 㯠15 以äžãšããŸãã
<i>k<sub>i</sub></i> 㯠100 以äžã§ããã
åç©åã®æåå㯠20æåãè¶ããåç©ã®å€æ®µã¯ 10000 ãè¶ããŸããã
ãŸããéã®é·ã㯠1000 ãè¶ããŸããã
</p>
<p>
<i>n</i> ã 0 ã®ãšããå
¥åã®çµãããšããŸãã
</p>
<H2>Output</H2>
<p>
åããŒã¿ã»ããã«ã€ããŠãæå°ã®éé¡ãšè·é¢ãïŒã€ã®ç©ºçœã§åºåã£ãŠïŒè¡ã«åºåããŠäžããããã ããå¿
èŠãªåç©ãå
šãŠéããããªãå Žå㯠"<span>impossible</span>" ãšåºåããŠäžããã
</p>
<H2>Sample Input</H2>
<pre>
3
3 apple 100 banana 200 egg 300
3 apple 150 banana 100 cola 200
3 apple 100 banana 150 cola 200
3
apple
banana
cola
5
0 2 4
0 1 3
0 3 3
1 2 3
2 3 5
3
3 apple 100 banana 200 egg 300
3 apple 150 banana 100 cola 200
3 apple 100 banana 150 cola 200
4
apple
banana
cola
jump
5
0 2 4
0 1 3
0 3 3
1 2 3
2 3 5
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
400 10
impossible
</pre>
|
p01926 |
<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>ã²ãŒã ãã©ã³ã¹</h3>
<p>ããªãã¯åéºã²ãŒã ãäœæããŠããïŒãã®ã²ãŒã ã®ãã¬ã€ã€ãŒã¯ïŒäž»äººå
¬ãæäœããŠæµã¢ã³ã¹ã¿ãŒãåãïŒäž»äººå
¬ã®ã¬ãã«ãäžããããšã§åéºãé²ããŠããïŒäž»äººå
¬ã®åæã¬ãã«ã¯ 1 ã§ããïŒ
</p>
<p>ãã®ã²ãŒã ã«ã¯ <i>N</i> çš®é¡ã®æµã¢ã³ã¹ã¿ãŒãçšæãããŠããïŒåŒ±ãé ã§ <i>i</i> çªç®ã®çš®é¡ã®æµã¢ã³ã¹ã¿ãŒã®åŒ·ã㯠<i>s<sub>i</sub></i> ã§ããïŒäž»äººå
¬ã 1 åã®æŠéãè¡ããšãã«ã¯ïŒæ¬¡ã«æŠãæµã¢ã³ã¹ã¿ãŒã®çš®é¡ãèªç±ã«éžã³ïŒã¡ããã© 1 äœã®æµã¢ã³ã¹ã¿ãŒãšæŠéãè¡ãïŒäž»äººå
¬ã¯åãçš®é¡ã®æµã¢ã³ã¹ã¿ãŒãšäœåã§ãæŠãããšãã§ãïŒäœåã§ãåãããšãã§ããïŒ
</p>
<p>ããªãã¯ããŸïŒãã®ã²ãŒã ã®ãã©ã³ã¹ã調æŽããããã«ïŒãããã©ã¡ãŒã¿ãŒ <i>X</i> ãæ±ºããããšããŠããïŒãã©ã¡ãŒã¿ãŒ <i>X</i> ã¯æ£ã®æŽæ°ã§ããäžèšã®ããã«äœ¿ãããïŒ
</p>
<ul><li> 䞻人å
¬ã®ã¬ãã«ã <i>L</i> ã®ãšãïŒåŒ·ã <i>s<sub>i</sub></i> ã <i>L+X</i> æªæºã®æµã¯åãããïŒããããåŒ·ãæµã¢ã³ã¹ã¿ãŒã¯åããªãïŒ
</li><li> 䞻人å
¬ã®ã¬ãã«ã <i>L</i> ã®ãšãïŒåŒ·ã <i>s<sub>i</sub></i> ã®æµãåããš <i>max(1, X-|L-s<sub>i</sub>|)</i> ã ã䞻人å
¬ã®ã¬ãã«ãäžããïŒ
</li></ul>
<p>ãã®ã²ãŒã ã¯ïŒæã匷ãïŒ<i>N</i> çš®é¡ç®ã®ïŒæµã¢ã³ã¹ã¿ãŒãåããŠåãããšãã«ã²ãŒã ã¯ãªã¢ãšãªãïŒããªãã¯ïŒã²ãŒã ã¯ãªã¢ãŸã§ã«å¿
èŠãšãªãæŠéã®åæ°ãæäœã§ã <i>M</i> å以äžãšãªãããã«ãã©ã¡ãŒã¿ãŒ <i>X</i> ãæ±ºããããšèããŠããïŒãã ãïŒæµã¢ã³ã¹ã¿ãŒã®åŒ·ãã®èšå®ã«ãã£ãŠã¯ïŒ<i>X</i> ãã©ã®ããã«èšå®ããŠã <i>M</i> åæªæºã®æŠéåæ°ã§ã²ãŒã ã¯ãªã¢ã§ããŠããŸããïŒã²ãŒã ãã¯ãªã¢ã§ããªããªã£ãŠããŸãå Žåãããããšã«æ³šæããïŒ
</p>
<p>ãã©ã¡ãŒã¿ãŒ <i>X</i> ãæ±ºãããšãïŒäžèšã®æ¡ä»¶ãæºããç¯å²ã§æå€§ã®ãã©ã¡ãŒã¿ãŒå€ <i>X<sub>max</sub></sub></i> ãèšç®ããããã°ã©ã ãäœã£ãŠã»ããïŒ
</p>
<h3>Input</h3>
<blockquote></blockquote>
<p>å
¥åã¯è€æ°ã®ããŒã¿ã»ããããæ§æãããïŒããŒã¿ã»ããã®åæ°ã¯æå€§ã§ã 50 ãè¶
ããªãïŒåããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§è¡šãããïŒ
</p><blockquote><i>N</i> <i>M</i><br><i>s<sub>1</sub></i> <i>s<sub>2</sub></i> ... <i>s<sub>N</sub></i><br></blockquote>
<p>1 è¡ç®ã¯ç©ºçœã§åºåããã 2 ã€ã®æŽæ° <i>N, M</i> ãããªãïŒ<i>N</i> ã¯çšæããæµã¢ã³ã¹ã¿ãŒã®çš®é¡ã®æ°ïŒ<i>M</i> ã¯ã²ãŒã ã¯ãªã¢ãŸã§ã«å¿
èŠãšãªãã¹ãæå°ã®æŠéã®æ°ã§ããïŒ<i>1 ≤ N ≤ 100,000</i>, <i>2 ≤ M ≤1,000,000</i> ãæºããïŒ
</p><blockquote></blockquote>
<p>2 è¡ç®ã¯ç©ºçœã§åºåããã <i>N</i> åã®æŽæ° <i>s<sub>1</sub>, s<sub>2</sub>, ..., s<sub>N</sub></i> ãããªãïŒ<i>N</i> çš®é¡ã®æµã¢ã³ã¹ã¿ãŒããããã®åŒ·ãã衚ãïŒå <i>s<sub>i</sub></i> 㯠<i>1 ≤ s<sub>i</sub> ≤ 1,000,000</i> ãæºããïŒãŸã <i>s<sub>i</sub> < s<sub>i+1</sub></i> (<i>1 ≤ i ≤ N-1</i>) ã§ããïŒ
</p><blockquote></blockquote>
<p>å
¥åã®çµããã¯ç©ºçœã§åºåããã 2 ã€ã®ãŒããããªãè¡ã§è¡šãããïŒ
</p><blockquote></blockquote>
<h3>Output</h3>
<blockquote></blockquote>
<p>åããŒã¿ã»ããã«ã€ããŠïŒã²ãŒã ã¯ãªã¢ãŸã§ã«å¿
èŠãšãªãæŠéã®åæ°ã <i>M</i> å以äžãšãªããã©ã¡ãŒã¿ãŒ <i>X</i> ã®å
ã®æå€§å€ <i>X<sub>max<sub></sub></i> ãæŽæ°ã§åºåããïŒ<i>X</i> ãã©ã®ããã«èšå®ããŠã <i>M</i> åæªæºã®æŠéåæ°ã§ã²ãŒã ã¯ãªã¢ã§ããŠããŸããã²ãŒã ãã¯ãªã¢ã§ããªããªã£ãŠããŸããã¹ãã±ãŒã¹ã®å Žåã«ã¯ <i>-1</i> ã®ã¿ãããªãè¡ãåºåããïŒ
</p><blockquote></blockquote>
<h3>Sample Input</h3>
<pre>3 4
1 5 9
1 2
1
2 10
1 1000000
2 4
1 10
0 0
</pre>
<h3>Output for Sample Input</h3>
<pre>3
-1
499996
4</pre>
<p>
2 çªç®ã®ãã¹ãã±ãŒã¹ã§ã¯ïŒ<i>X</i> = 1 ãšèšå®ãããš 1 åã®æŠéã§ã²ãŒã ãã¯ãªã¢ã§ããŠããŸãïŒ
ãã®ã±ãŒã¹ã§ã¯ïŒå¿
èŠãšãªãæŠéã®åæ°ã <i>M</i> å以äžã§ããïŒãã€ã²ãŒã ãã¯ãªã¢ã§ããããã« <i>X</i> ãèšå®ããããšãåºæ¥ãªãïŒ
ãã£ãŠ -1 ã®ã¿ãããªãè¡ãåºåããïŒ
</p> |
p02259 |
<H1>Bubble Sort</H1>
<p>
Write a program of the Bubble Sort algorithm which sorts a sequence <i>A</i> in ascending order. The algorithm should be based on the following pseudocode:
</p>
<pre>
BubbleSort(A)
1 for i = 0 to A.length-1
2 for j = A.length-1 downto i+1
3 if A[j] < A[j-1]
4 swap A[j] and A[j-1]
</pre>
<p>
Note that, indices for array elements are based on 0-origin.
</p>
<p>
Your program should also print the number of swap operations defined in line 4 of the pseudocode.
</p>
<H2>Input</H2>
<p>
The first line of the input includes an integer <i>N</i>, the number of elements in the sequence.
</p>
<p>
In the second line, <i>N</i> elements of the sequence are given separated by spaces characters.
</p>
<H2>Output</H2>
<p>
The output consists of 2 lines.
</p>
<p>
In the first line, please print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character.
</p>
<p>
In the second line, please print the number of swap operations.
</p>
<H2>Constraints</H2>
<p>
1 ≤ <i>N</i> ≤ 100
</p>
<H2>Sample Input 1</H2>
<pre>
5
5 3 2 4 1
</pre>
<H2>Sample Output 1</H2>
<pre>
1 2 3 4 5
8
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
6
5 2 4 6 1 3
</pre>
<H2>Sample Output 2</H2>
<pre>
1 2 3 4 5 6
9
</pre>
|
p00264 |
<H1>颚ããç§ã®æ¢
ã®éŠããå±ããŠãããïŒ</H1>
<p>
åŒã£è¶ããæ±ºãŸãããã®å°ãå»ãããšã«ãªã£ãããã®åå°èªäœã«æªç·Žã¯ç¡ãããïŒã€ã ãæ°ã«ãªãããšããããããã¯ãåºã«æ€ããæ¢
ã®æšã®ããšã ãç§ã¯æ¯å¹Žããã®æ¢
ãè±ãå²ããããšã楜ãã¿ã«ããŠããããããé¢ããåŸã¯æ¥ã®æ¥œãã¿ãïŒã€æžã£ãŠããŸããç§ã®æ¢
ã®éŠãã ãã§ã颚ã«ä¹ã£ãŠåŒã£è¶ãå
ã®å®¶ãŸã§å±ããæ¥ãæ¥œããŸããŠã¯ãããªããã®ãã
</p>
<p>
æ¥æ¬ã«ã¯æ¥ã象城ããïŒã€ã®è±ããããæ¢
ã»æ¡ã»æ¡ã®ïŒã€ã ãåŒã£è¶ãå
ã«ã¯ãç§ã®æ¢
以å€ã«ãããããã®è±ã®éŠããå±ãã ãããããããç§ã®æ¢
ã®éŠãã ããå±ãæ¥æ°ãæãå€ãå®¶ã«äœã¿ããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_kochi" width="380">
</center>
<br/>
<p>
å³ã®ããã«ãè±ã®éŠãã¯æç¶ã«åºããããã®é åã¯é¢šã®åããæ¹åãšåŒ·ãã«ãã£ãŠæ±ºãŸããæåœ¢ã¯é¢šã®åããæ¹å w ãäžå¿ã«ããŠå¯Ÿç§°ã«åºããã颚ã®åŒ·ã a ãååŸãšããé åããã€ãéŠããåºããè§åºŠ d ã¯è±ã®çš®é¡ã«ãã£ãŠæ±ºãŸã£ãŠãããã颚ã®åããæ¹åãšåŒ·ãã¯æ¥ã«ãã£ãŠç°ãªãããã ããåãæ¥ã§ã¯ããã¹ãŠã®å Žæã§é¢šã®åããæ¹åãšåŒ·ãã¯åãã§ããã
</p>
<p>
æå
ã«ã¯ãç§ã®æ¢
以å€ã®æ¢
ã»æ¡ã»æ¡ã®äœçœ®ãšè±ã®çš®é¡ããšã®éŠããåºããè§åºŠãåŒã£è¶ãå
ã®å®¶ã®åè£ã®ããŒã¿ããããããã«ãæ°æ¥åã®é¢šã®åããæ¹åãšåŒ·ãã®ããŒã¿ããããç§ã®æ¢
以å€ã®æ¢
ã»æ¡ã»æ¡ã®æšãšå®¶ã®äœçœ®ã¯ãç§ã®æ¢
ã®äœçœ®ãåç¹ãšãã座æšã§ç€ºãããŠããã
</p>
<p>
ãããã®ããŒã¿ã䜿ã£ãŠãç§ã®æ¢
ã®éŠãã ããå±ãæ¥æ°ã®æãå€ãå®¶ãæ¢ãããã®ããã°ã©ã ãæžããŠã¿ãããšãšããããç§ã¯æèœãªããã°ã©ããŒãªã®ã ããïŒ
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããå
¥åã®çµããã¯ãŒãïŒã€ã®è¡ã§ç€ºããããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
H R
hx<sub>1</sub> hy<sub>1</sub>
hx<sub>2</sub> hy<sub>2</sub>
:
hx<sub>H</sub> hy<sub>H</sub>
U M S du dm ds
ux<sub>1</sub> uy<sub>1</sub>
ux<sub>2</sub> uy<sub>2</sub>
:
ux<sub>U</sub> uy<sub>U</sub>
mx<sub>1</sub> my<sub>1</sub>
mx<sub>2</sub> my<sub>2</sub>
:
mx<sub>M</sub> my<sub>M</sub>
sx<sub>1</sub> sy<sub>1</sub>
sx<sub>2</sub> sy<sub>2</sub>
:
sx<sub>S</sub> sy<sub>S</sub>
w<sub>1</sub> a<sub>1</sub>
w<sub>2</sub> a<sub>2</sub>
:
w<sub>R</sub> a<sub>R</sub>
</pre>
<p>
åè¡ã§äžããããæ°å€ã¯ïŒã€ã®ç©ºçœã§åºåãããŠããã
</p>
<p>
ïŒè¡ç®ã«åŒã£è¶ãå
ã®å®¶ã®åè£ã®æ° H (1 ≤ H ≤ 100) ãšé¢šã®èšé²ã®æ° R (1 ≤ R ≤ 100) ãäžãããããç¶ãH è¡ã«åŒã£è¶ãå
ã®å®¶ã®äœçœ®ãäžãããããhx<sub>i</sub> ãšhy<sub>i</sub>㯠i çªç®ã®å®¶ã® x 座æšãš y 座æšã瀺ã-1000 以äž1000 以äžã®æŽæ°ã§ããã
</p>
<p>
ç¶ãïŒè¡ã«ãç§ã®æ¢
以å€ã®æ¢
ã®æšã®æ° U ãšãæ¡ã»æ¡ã®æšã®æ° MãSãæ¢
ã»æ¡ã»æ¡ã®éŠããåºããè§åºŠduãdmãds ãäžãããããUãMãS ã®ç¯å²ã¯ 0 以äž10 以äžã§ãããè§åºŠã®åäœã¯åºŠã§ããã1 以äž180 æªæºã®æŽæ°ã§ããã
<?p>
ç¶ã U è¡ã«ç§ã®æ¢
以å€ã®æ¢
ã®æšã®äœçœ®ãç¶ã M è¡ã«æ¡ã®æšã®äœçœ®ãç¶ã S è¡ã«æ¡ã®æšã®äœçœ®ãäžãããããuxi ãš uyiãmxi ãš myiãsxi ãš syi ã¯ãããããi çªç®ã®æ¢
ã»æ¡ã»æ¡ã®æšã® x 座æšãš y 座æšã瀺ãã-1000 ä»¥äž 1000 以äžã®æŽæ°ã§ããã
</p>
<p>
ç¶ã R è¡ã«é¢šã®èšé²ãäžãããããw<sub>i</sub> (0 ≤ w<sub>i</sub> < 360) ãš a<sub>i</sub>(0 < a<sub>i</sub> ≤ 100) 㯠i æ¥ç®ã®é¢šã®åããæ¹åãšåŒ·ããè¡šãæŽæ°ã§ããã颚ã®åããæ¹åã¯ãx è»žã®æ£ã®åãããåæèšåãã«æž¬ã£ãè§åºŠã§è¡šããåäœã¯åºŠãšããã
</p>
<p>
å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºãããšèããŠããã
</p>
<ul>
<li> å
¥åããã座æšã¯ãã¹ãŠç°ãªããã®ãšããã</li>
<li> åç¹ã«ã¯ç§ã®æ¢
以å€ç¡ãã</li>
<li> ã©ã®è±ã«ã€ããŠããè±ã®éŠããå±ãé åã®å¢çããè·é¢ã 0.001 以å
ã«ã¯å®¶ã¯ç¡ãã</li>
</ul>
<p>
ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããªãã
</p>
<h2>åºå</h2>
<p>
ããŒã¿ã»ããããšã«ãç§ã®æ¢
ã®éŠãã ããå±ãæ¥æ°ã®æãå€ãå
šãŠã®å®¶ã®çªå·ããå°ããé ã«ïŒè¡ã«åºåãããå®¶ã®çªå·ã®éã¯ç©ºçœïŒã€ã§åºåããè¡ã®çµããã«ã¯ç©ºçœæåãåºåããªãã
</p>
<p>
ãã ããã©ã®å®¶ã«ã€ããŠããç§ã®æ¢
ã®è±ã®éŠãã ããå±ãæ¥ãïŒæ¥ããªããã°ãNA ãšåºåããã
</p>
<h2>å
¥åäŸ</h2>
<pre>
6 3
2 1
1 2
5 2
1 3
1 5
-2 3
1 1 1 90 30 45
3 -4
-3 0
2 -2
45 6
90 6
135 6
2 1
1 3
5 2
0 1 1 90 30 45
-3 0
2 -2
45 6
0 0
</pre>
<h2>åºåäŸ</h2>
<pre>
5 6
NA
</pre> |
p00771 |
<h3>Anchored Balloon</h3>
<p>
A balloon placed on the ground is connected to one or more anchors on the ground with ropes.
Each rope is long enough to connect the balloon and the anchor.
No two ropes cross each other.
Figure E-1 shows such a situation.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_anchoredBalloon-1">
<br>
Figure E-1: A balloon and ropes on the ground
</center>
<p>
Now the balloon takes off, and your task is to find how high
the balloon can go up with keeping the rope connections.
The positions of the anchors are fixed.
The lengths of the ropes and the positions of the anchors are given.
You may assume that these ropes have no weight and
thus can be straightened up when pulled to
whichever directions.
Figure E-2 shows the highest position of the balloon for
the situation shown in Figure E-1.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_anchoredBalloon-2">
<br>
Figure E-2: The highest position of the balloon
</center>
<h3>Input</h3>
<p>
The input consists of multiple datasets, each in the following format.
</p>
<blockquote>
<i>n</i><br>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>l</i><sub>1</sub> <br>
... <br>
<i>x</i><sub><i>n</i></sub> <i>y</i><sub><i>n</i></sub> <i>l</i><sub><i>n</i></sub> <br>
</blockquote>
<p>
The first line of a dataset contains an integer <i>n</i> (1 ≤ <i>n</i> ≤ 10) representing the number of the ropes.
Each of the following <i>n</i> lines contains three integers,
<i>x</i><sub><i>i</i></sub>, <i>y</i><sub><i>i</i></sub>, and <i>l</i><sub><i>i</i></sub>, separated by a single space.
<i>P</i><sub><i>i</i></sub> =
(<i>x</i><sub><i>i</i></sub>, <i>y</i><sub><i>i</i></sub>) represents
the position of the anchor connecting the <i>i</i>-th rope,
and <i>l</i><sub><i>i</i></sub> represents the length of the rope.
You can assume that
−100 ≤ <i>x</i><sub><i>i</i></sub> ≤ 100,
−100 ≤ <i>y</i><sub><i>i</i></sub> ≤ 100, and
1 ≤ <i>l</i><sub><i>i</i></sub> ≤ 300.
The balloon is initially placed at (0, 0) on the ground.
You can ignore the size of the balloon and the anchors.
</p>
<p>
You can assume that <i>P</i><sub><i>i</i></sub> and <i>P</i><sub><i>j</i></sub>
represent different positions if <i>i</i> ≠ <i>j</i>.
You can also assume that the distance between
<i>P</i><sub><i>i</i></sub> and (0, 0) is less than or equal to
<i>l</i><sub><i>i</i></sub>−1.
This means that the balloon can go up at least 1 unit high.
</p>
<p>
Figures E-1 and E-2 correspond to the first dataset of Sample Input below.
</p>
<p>
The end of the input is indicated by a line containing a zero.
</p>
<h3>Output</h3>
<p>
For each dataset,
output a single line containing the maximum height that the balloon can go up.
The error of the value should be no greater than 0.00001.
No extra characters should appear in the output.
</p>
<h3>Sample Input</h3>
<pre>
3
10 10 20
10 -10 20
-10 10 120
1
10 10 16
2
10 10 20
10 -10 20
2
100 0 101
-90 0 91
2
0 0 53
30 40 102
3
10 10 20
10 -10 20
-10 -10 20
3
1 5 13
5 -3 13
-3 -3 13
3
98 97 168
-82 -80 193
-99 -96 211
4
90 -100 160
-80 -80 150
90 80 150
80 80 245
4
85 -90 290
-80 -80 220
-85 90 145
85 90 170
5
0 0 4
3 0 5
-3 0 5
0 3 5
0 -3 5
10
95 -93 260
-86 96 211
91 90 177
-81 -80 124
-91 91 144
97 94 165
-90 -86 194
89 85 167
-93 -80 222
92 -84 218
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
17.3205081
16.0000000
17.3205081
13.8011200
53.0000000
14.1421356
12.0000000
128.3928757
94.1879092
131.1240816
4.0000000
72.2251798
</pre>
|
p01863 |
<!--<script language="JavaScript" type="text/javascript" src="js/varmath.js" charset="UTF-8"></script>-->
<h2>F: ã¿ãã¿ãŒæåå - Miko Mi String -</h2>
<h3>ç©èª</h3>
<p>ã¿ã£ãã¿ã£ãã¿ãïŒã¿ããªã®ã¢ã€ãã«ïŒç°æŸ€ã¿ãã¿ãïŒä»æ¥ã¯ãïŒã¿ããšäžç·ã«ãïŒæååã¢ã«ãŽãªãºã ã®ç·Žç¿ïŒããâ</p>
<p>ã¿ãã®ãšã£ãŠããã®<s>ãã£ã©äœã</s>åèšèïŒãã¿ã£ãã¿ã£ãã¿ããã¯ïŒããŒãåã«ãããš âMikoMikoMiâ ã«ãªãã¿ãïŒã€ãŸãïŒ<var>A=</var>âMiâ, <var>B=</var>âKoâ ãšãããšïŒ<var>ABABA</var>ã®åœ¢ã§æžããã£ãŠããšãªã®ïŒãããªé¢šã«ïŒé©åã«<var>A</var>ãš<var>B</var>ãæ±ºãããš<var>ABABA</var>ã®åœ¢ã«åè§£ã§ããæååã®ããšããã¿ãã¿ãŒæååãã£ãŠèšããïŒæååã®ååã«ãŸã§ãªã£ã¡ãããªããŠïŒã¿ãã¯ã¿ããªã®äººæ°è
ã¿ããïŒ</p>
<p>ã¿ããªã§ã¿ãã¿ãŒæååãããã£ãšäœ¿ã£ãŠããããã«ïŒäžããããæååãã¿ãã¿ãŒæååãã©ããå€å®ããããã°ã©ã ãäœãããšã«ãããã ãã©ïŒã¿ãïŒFizzBuzzããé·ãããã°ã©ã ãªããŠæžããªããïŒã ãããïŒã¿ãã®ããã«ãïŒã¿ãã¿ãŒæååãå€å®ããããã°ã©ã ãæžããŠæ¬²ãããªâ</p>
<p>âŠâŠã¢ã³ã¿ïŒããŸå¯ãã£ãŠèšã£ãïŒïŒ</p>
<h3>åé¡</h3>
<p>
ã¢ã«ãã¡ããã倧æåã»å°æåãããªãæåå<var>S</var>ãäžããããïŒ
ããã§ïŒ<var>S = ABABA</var>ãšæžãããããªïŒç©ºã§ãªã2ã€ã®æåå<var>A, B</var>ãååšãããªãã°ïŒ<var>S</var>ã¯ãã¿ãã¿ãŒæååãã§ãããšããïŒ
ãã®ãšãïŒã¢ã«ãã¡ãããã®å€§æåãšå°æåã¯éãæåãšããŠåºå¥ãããã®ãšããïŒ
äžããããæååãã¿ãã¿ãŒæååã§ãããã©ãããå€å®ããããã°ã©ã ãäœæããïŒ
</p>
<h3>å
¥å圢åŒ</h3>
<p>
å
¥åã¯æåå<var>S</var>ãå«ã1è¡ã®ã¿ãããªãïŒ
<var>S</var>ã¯ä»¥äžã®æ¡ä»¶ãæºãããšä»®å®ããŠããïŒ
</p>
<ul>
<li><var>1 ≤ |S| ≤ 10^6</var>ïŒãã ãïŒ<var>|S|</var>ã¯æåå<var>S</var>ã®é·ãã衚ãïŒ</li>
<li><var>S</var>ã¯å€§æåïŒãããã¯å°æåã®ã¢ã«ãã¡ãããã®ã¿ãããªãïŒ</li>
</ul>
<p>ãªãïŒå
¥åãéåžžã«å€§ãããªãå ŽåãããããïŒå
¥åã®åãåãã«ã¯é«éãªé¢æ°ãçšããããšãæšå¥šããïŒ</p>
<h3>åºå圢åŒ</h3>
<p>
<var>S</var>ãã¿ãã¿ãŒæååã§ãããªãã°ïŒ<var>S = ABABA</var>ãæºãããããª<var>A, B</var>ã«ã€ããŠïŒâLove <var>AB</var>!âãšåºåããïŒãã ãïŒè€æ°ã®<var>A, B</var>ã®çµãæ¡ä»¶ãæºããå ŽåïŒ<var>|AB|</var>ãæå°ã®ãã®ãåºåããïŒ
<var>S</var>ãã¿ãã¿ãŒæååã§ãªããªãã°ïŒâmitomerarenaiWAâãšåºåããïŒ
</p>
<h3>å
¥åäŸ1</h3>
<pre>NicoNicoNi</pre>
<h3>åºåäŸ1</h3>
<pre>Love Nico!</pre>
<h3>å
¥åäŸ2</h3>
<pre>KashikoiKawaiiElichika</pre>
<h3>åºåäŸ2</h3>
<pre>mitomerarenaiWA</pre>
<h3>å
¥åäŸ3</h3>
<pre>LiveLiveL</pre>
<h3>åºåäŸ3</h3>
<pre>Love Live!</pre>
<h3>å
¥åäŸ4</h3>
<pre>AizunyanPeroPero</pre>
<h3>åºåäŸ4</h3>
<pre>mitomerarenaiWA</pre>
<h3>å
¥åäŸ5</h3>
<pre>AAAAAAAAAAAAAA</pre>
<h3>åºåäŸ5</h3>
<pre>Love AAAAA!</pre> |
p00321 |
<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>
<p>
䌌ããããªããšã¯ãäžç·ã«è²·ãããããšãå€ãååãè¿ãã«é
眮ããããšãã工倫ãšããŠãè¿æã®ã¹ãŒããŒããŒã±ããã§ãç®ã«ããããšãã§ããŸãïŒäŸãã°ããã³ãšãžã£ã ã®ãããªïŒãããªãã®ä»äºã¯ãååé
眮ã®å·¥å€«ãå©ããããã°ã©ã ãæžãããšã§ããä»åã¯ãããåºæºãšãªãåæ°ãèšå®ããäžç·ã«è²·ãããåæ°ãåºæºåæ°ä»¥äžã§ãããïŒã€ã®ååã®çµã¿åãããæ±ããããšæããŸãã
</p>
<p>
äžç·ã«è²·ãããååã®æ
å ±ãšåºæºåæ°ãäžãããããšããåºæºåæ°ä»¥äžäžç·ã«è²·ãããååïŒã€ã®çµã¿åãããåºåããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var> <var>F</var>
<var>info<sub>1</sub></var>
<var>info<sub>2</sub></var>
:
<var>info<sub>N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ãäžç·ã«è²·ãããååã®æ
å ±ã®æ° <var>N</var> (1 ≤ <var>N</var> ≤ 100) ãšãåºæºåæ° <var>F</var> (1 ≤ <var>F</var> ≤ 100) ãäžãããããç¶ã <var>N</var>è¡ã«ãäžç·ã«è²·ãããååã®æ
å ±ãäžãããããäžç·ã«è²·ãããååã®æ
å ± <var>info<sub>i</sub></var> ã¯ã以äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>M</var> <var>item<sub>1</sub></var> <var>item<sub>2</sub></var> ... <var>item<sub>M</sub></var>
</pre>
<p>
<var>M</var> (1 ≤ <var>M</var> ≤ 10) ã¯ããã®æ
å ±ãããã€ã®ååãå«ããã衚ãã<var>item<sub>j</sub></var> ã¯ããã®è²·ãç©ã§è²·ãããååã®ååã§ãããè±å°æåã ãããæãé·ã 1 ä»¥äž 30 以äžã®æååã§ããã<var>info<sub>i</sub></var> ã®äžã«åãååãäžããããããšã¯ãªãã
</p>
<h2>Output</h2>
<p>
ïŒè¡ç®ã«åºæºåæ°ä»¥äžäžç·ã«è²·ãããååïŒã€ã®çµã¿åããã®æ°ãåºåããïŒè¡ç®ä»¥éã«çµã¿åããããã¹ãŠåºåããããã ããçµã¿åãããäžã€ããªãå Žåã¯ïŒè¡ç®ä»¥éã«ã¯äœãåºåããªãã
</p>
<p>
åºåã®é çªã¯ãçµã¿åããå
ã®åååã©ããããèŸæžåŒé åºïŒè±åèŸæžã§åèªã䞊ãã§ããé çªïŒã§äžŠã¹ãããšãçµã¿åããã©ããã«ã€ããŠã¯ä»¥äžã®ããã«ããã
</p>
<ul>
<li> äžã€ç®ã®åååã©ãããæ¯èŒããŠãèŸæžåŒé åºã§æ©ãã»ããå
ã</li>
<li> åãå Žåã¯ãäºã€ç®ã®åååã©ãããæ¯èŒããŠãèŸæžåŒé åºã§æ©ãã»ããå
ã</li>
</ul>
<p>
åååã¯ã¹ããŒã¹äžã€ã§åºåããååã®çµã¿åããã¯æ¹è¡äžã€ã§åºåãã
</p>
<h2>Sample Input 1</h2>
<pre>
5 2
3 bread milk banana
2 milk cornflakes
3 potato bread milk
4 cornflakes bread milk butter
2 potato bread
</pre>
<h2>Sample Output 1</h2>
<pre>
3
bread milk
bread potato
cornflakes milk
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
5 5
3 bread milk banana
2 milk cornflakes
3 potato bread milk
4 cornflakes bread milk butter
2 potato bread
</pre>
<h2>Sample Output 2</h2>
<pre>
0
</pre> |
p01160 |
<H1><font color="#000">Problem F:</font> It Prefokery Pio</H1>
<p>
You are a member of a secret society named <i>Japanese Abekobe Group</i>, which is called J. A. G. for short.
Those who belong to this society often exchange encrypted messages. You received lots of encrypted
messages this morning, and you tried to decrypt them as usual. However, because you received so many
and long messages today, you had to give up decrypting them by yourself. So you decided to decrypt
them with the help of a computer program that you are going to write.
</p>
<p>
The encryption scheme in J. A. G. utilizes palindromes. A palindrome is a word or phrase that reads
the same in either direction. For example, âMADAMâ, âREVIVERâ and âSUCCUSâ are palindromes,
while âADAMâ, âREVENGEâ and âSOCCERâ are not.
</p>
<p>
Specifically to this scheme, words and phrases made of only one or two letters are not regarded as
palindromes. For example, âAâ and âMMâ are not regarded as palindromes.
</p>
<p>
The encryption scheme is quite simple: each message is encrypted by inserting extra letters in such a
way that the longest one among all subsequences forming palindromes gives the original message. In
other words, you can decrypt the message by extracting the <i>longest palindrome subsequence</i>. Here, a
subsequence means a new string obtained by picking up some letters from a string without altering the
relative positions of the remaining letters. For example, the longest palindrome subsequence of a string
âYMAOKDOAMIMHAADAMMAâ is âMADAMIMADAMâ as indicated below by underline.
</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_prefokery">
<p>
Now you are ready for writing a program.
</p>
<H2>Input</H2>
<p>
The input consists of a series of data sets. Each data set contains a line made of up to 2,000 capital
letters which represents an encrypted string.
</p>
<p>
The end of the input is indicated by EOF (end-of-file marker).
</p>
<H2>Output</H2>
<p>
For each data set, write a decrypted message in a separate line. If there is more than one decrypted
message possible (i.e. if there is more than one palindrome subsequence not shorter than any other ones),
you may write any of the possible messages.
</p>
<p>
You can assume that the length of the longest palindrome subsequence of each data set is always longer
than two letters.
</p>
<H2>Sample Input</H2>
<pre>
YMAOKDOAMIMHAADAMMA
LELVEEL
</pre>
<H2>Output for the Sample Input</H2>
<pre>
MADAMIMADAM
LEVEL
</pre>
|
p01530 |
<h1>K - XORåå»</h1>
<h2>å顿</h2>
<p>
KU倧åŠã§ã¯äžé¢šå€ãã£ãã©ãªãŒã²ãŒã ã人æ°ã§ããïŒ
ãã®ã²ãŒã ã®èå°ã§ãããµãŒãããã«ã¯ïŒ<var>N</var> åã®äŒæ©æãš <var>M</var> åã®éãããïŒ<var>i</var> çªç®ã®é㯠<var>f<sub>i</sub></var> çªç®ã®äŒæ©æãš <var>t<sub>i</sub></var> çªç®ã®äŒæ©æã®éã«ããïŒ
ãã¹ãŠã®éã«ã¯ãã§ãã¯ãã€ã³ããäžã€ãã€ååšãïŒé <var>i</var> ã®ãã§ãã¯ãã€ã³ããééãããšã©ã¡ãã®åãã§éã£ãŠã <var>p<sub>i</sub></var> ã®åŸç¹ãXORã§å ç®ãããïŒ<strong>XORã§</strong>å ç®ãããïŒå€§äºãªããšãªã®ã§2åèšããŸããïŒ
</p>
<p>
ãã®ã²ãŒã ã§ã¯ïŒåãäŒæ©æãéãäœåºŠéã£ãŠãè¯ããïŒ
ãŽãŒã«ã«ãã©ãçããŠããã®ãŸãŸã©ãªãŒãç¶è¡ããããšãã§ãããïŒ
éã®éäžã«ãããã§ãã¯ãã€ã³ããè¿åããŠå¥ã®äŒæ©æãžè¡ãããšã¯çŠæ¢ãããŠããïŒ
ãã®ããïŒã©ã®ãããªéé ããã©ãã°é«ãåŸç¹ãåãããšãã§ããããé 匵ã£ãŠèããªããã°ãªããªãç¹ã人æ°ã®ããæä»¥ã§ããïŒ
</p>
<p>
ä»å㯠<var>Q</var> 人ã®åå è
ãããŠïŒ<var>j</var> çªç®ã®åå è
㯠<var>a<sub>j</sub></var> ã®äŒæ©æããã¹ã¿ãŒãããŠïŒãŽãŒã«ã§ãã <var>b<sub>j</sub></var> ã®äŒæ©æãŸã§è¡ãããšã«ãªã£ãŠããããã ïŒ
éå¶åŽã®äººéãšããŠããããã®åå è
ã®æé«åŸç¹ãåãã£ãŠèª¿ã¹ãŠããããšã«ããïŒ
</p>
<h2>å
¥å圢åŒ</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒãªãäŒæ©æã®çªå·ã¯0-indexedã§ããïŒ</p>
<pre>
<var>N</var> <var>M</var> <var>Q</var>
<var>f<sub>1</sub></var> <var>t<sub>1</sub></var> <var>p<sub>1</sub></var>
<var>...</var>
<var>f<sub>M</sub></var> <var>t<sub>M</sub></var> <var>p<sub>M</sub></var>
<var>a<sub>1</sub></var> <var>b<sub>1</sub></var>
<var>...</var>
<var>a<sub>Q</sub></var> <var>b<sub>Q</sub></var>
</pre>
<h2>åºå圢åŒ</h2>
<p>
<var>Q</var> è¡åºåãïŒ<var>j</var> è¡ç®ã«ã¯ <var>a<sub>j</sub></var> çªç®ã®äŒæ©æãã <var>b<sub>j</sub></var> çªç®ã®äŒæ©æãžã®çµè·¯ã§åŸãããåŸç¹ã®æå€§å€ãåºåããïŒ
</p>
<h2>å¶çŽ</h2>
<ul>
<li><var>1 ≤ N ≤ 10<sup>5</sup></var></li>
<li><var>0 ≤ M ≤ 2 × 10<sup>5</sup></var></li>
<li><var>1 ≤ Q ≤ 10<sup>5</sup></var></li>
<li><var>0 ≤ f<sub>i</sub>, t<sub>i</sub> < N</var>, <var>f<sub>i</sub> ≠ t<sub>i</sub></var></li>
<li><var>0 ≤ p<sub>i</sub> < 2<sup>60</sup></var></li>
<li><var>0 ≤ a<sub>j</sub>, b<sub>j</sub> < N</var></li>
<li>ã©ã®äŒæ©æããã§ãïŒéã蟿ã£ãŠããã°ä»»æã®äŒæ©æãžãã©ãçããïŒ</li>
<li>äŒæ©æ <var>f<sub>i</sub>,t<sub>i</sub></var> éãçµã¶éã¯é«ã
äžã€ããååšããªãïŒ</li>
<li>å
¥åå€ã¯ãã¹ãп޿°ã§ããïŒ</li>
</ul>
<p>ãã®åé¡ã®å€å®ã«ã¯ïŒ60 ç¹åã®ãã¹ãã±ãŒã¹ã®ã°ã«ãŒããèšå®ãããŠããïŒãã®ã°ã«ãŒãã«å«ãŸãããã¹ãã±ãŒã¹ã¯äžèšã®å¶çŽã«å ããŠäžèšã®å¶çŽãæºããïŒ</p>
<ul>
<li><var>M ≤ 20</var></li>
</ul>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ1</h3>
<pre>
5 5 3
0 1 7
1 2 22
2 3 128
3 4 128
4 2 128
0 1
0 0
3 4
</pre>
<h3>åºåäŸ1</h3>
<pre>
135
128
128
</pre>
<hr>
<address>Writer : æ£®æ§æ</address>
<address>Tester : ç°æåç¯</address> |
p03798 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke, who loves animals, built a zoo.</p>
<p>There are <var>N</var> animals in this zoo. They are conveniently numbered <var>1</var> through <var>N</var>, and arranged in a circle.
The animal numbered <var>i (2â€iâ€N-1)</var> is adjacent to the animals numbered <var>i-1</var> and <var>i+1</var>. Also, the animal numbered <var>1</var> is adjacent to the animals numbered <var>2</var> and <var>N</var>, and the animal numbered <var>N</var> is adjacent to the animals numbered <var>N-1</var> and <var>1</var>.</p>
<p>There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies.</p>
<p>Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered <var>i</var> answered <var>s_i</var>. Here, if <var>s_i</var> is <code>o</code>, the animal said that the two neighboring animals are of the same species, and if <var>s_i</var> is <code>x</code>, the animal said that the two neighboring animals are of different species.</p>
<p>More formally, a sheep answered <code>o</code> if the two neighboring animals are both sheep or both wolves, and answered <code>x</code> otherwise.
Similarly, a wolf answered <code>x</code> if the two neighboring animals are both sheep or both wolves, and answered <code>o</code> otherwise.</p>
<p>Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print <code>-1</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 †N †10^{5}</var></li>
<li><var>s</var> is a string of length <var>N</var> consisting of <code>o</code> and <code>x</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there does not exist an valid assignment that is consistent with <var>s</var>, print <code>-1</code>.
Otherwise, print an string <var>t</var> in the following format. The output is considered correct if the assignment described by <var>t</var> is consistent with <var>s</var>.</p>
<ul>
<li><var>t</var> is a string of length <var>N</var> consisting of <code>S</code> and <code>W</code>.</li>
<li>If <var>t_i</var> is <code>S</code>, it indicates that the animal numbered <var>i</var> is a sheep. If <var>t_i</var> is <code>W</code>, it indicates that the animal numbered <var>i</var> is a wolf.</li>
</ul>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
ooxoox
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>SSSWWS
</pre>
<p>For example, if the animals numbered <var>1</var>, <var>2</var>, <var>3</var>, <var>4</var>, <var>5</var> and <var>6</var> are respectively a sheep, sheep, sheep, wolf, wolf, and sheep, it is consistent with their responses. Besides, there is another valid assignment of species: a wolf, sheep, wolf, sheep, wolf and wolf.</p>
<p>Let us remind you: if the neiboring animals are of the same species, a sheep answers <code>o</code> and a wolf answers <code>x</code>. If the neiboring animals are of different species, a sheep answers <code>x</code> and a wolf answers <code>o</code>.</p>
<div style="text-align: center;">
<img alt="b34c052fc21c42d2def9b98d6dccd05c.png" src="https://atcoder.jp/img/arc069/b34c052fc21c42d2def9b98d6dccd05c.png">
</img></div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
oox
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>Print <code>-1</code> if there is no valid assignment of species.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
oxooxoxoox
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>SSWWSSSWWS
</pre></section>
</div>
</span> |
p03262 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> cities on a number line. The <var>i</var>-th city is located at coordinate <var>x_i</var>.</p>
<p>Your objective is to visit all these cities at least once.</p>
<p>In order to do so, you will first set a positive integer <var>D</var>.</p>
<p>Then, you will depart from coordinate <var>X</var> and perform Move <var>1</var> and Move <var>2</var> below, as many times as you like:</p>
<ul>
<li>Move <var>1</var>: travel from coordinate <var>y</var> to coordinate <var>y + D</var>.</li>
<li>Move <var>2</var>: travel from coordinate <var>y</var> to coordinate <var>y - D</var>.</li>
</ul>
<p>Find the maximum value of <var>D</var> that enables you to visit all the cities.</p>
<p>Here, to visit a city is to travel to the coordinate where that city is located.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq X \leq 10^9</var></li>
<li><var>1 \leq x_i \leq 10^9</var></li>
<li><var>x_i</var> are all different.</li>
<li><var>x_1, x_2, ..., x_N \neq X</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>X</var>
<var>x_1</var> <var>x_2</var> <var>...</var> <var>x_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum value of <var>D</var> that enables you to visit all the cities.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
1 7 11
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>Setting <var>D = 2</var> enables you to visit all the cities as follows, and this is the maximum value of such <var>D</var>.</p>
<ul>
<li>Perform Move <var>2</var> to travel to coordinate <var>1</var>.</li>
<li>Perform Move <var>1</var> to travel to coordinate <var>3</var>.</li>
<li>Perform Move <var>1</var> to travel to coordinate <var>5</var>.</li>
<li>Perform Move <var>1</var> to travel to coordinate <var>7</var>.</li>
<li>Perform Move <var>1</var> to travel to coordinate <var>9</var>.</li>
<li>Perform Move <var>1</var> to travel to coordinate <var>11</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 81
33 105 57
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>24
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 1
1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>999999999
</pre></section>
</div>
</span> |
p03632 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Alice and Bob are controlling a robot. They each have one switch that controls the robot.<br/>
Alice started holding down her button <var>A</var> second after the start-up of the robot, and released her button <var>B</var> second after the start-up.<br/>
Bob started holding down his button <var>C</var> second after the start-up, and released his button <var>D</var> second after the start-up.<br/>
For how many seconds both Alice and Bob were holding down their buttons?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0â€A<Bâ€100</var></li>
<li><var>0â€C<Dâ€100</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format: </p>
<pre><var>A</var> <var>B</var> <var>C</var> <var>D</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>0 75 25 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>50
</pre>
<p>Alice started holding down her button <var>0</var> second after the start-up of the robot, and released her button <var>75</var> second after the start-up.<br/>
Bob started holding down his button <var>25</var> second after the start-up, and released his button <var>100</var> second after the start-up.<br/>
Therefore, the time when both of them were holding down their buttons, is the <var>50</var> seconds from <var>25</var> seconds after the start-up to <var>75</var> seconds after the start-up.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>0 33 66 99
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>Alice and Bob were not holding their buttons at the same time, so the answer is zero seconds.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 90 20 80
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>60
</pre></section>
</div>
</span> |
p02920 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have one slime.</p>
<p>You can set the <em>health</em> of this slime to any integer value of your choice.</p>
<p>A slime reproduces every second by spawning another slime that has strictly less health. You can freely choose the health of each new slime. The first reproduction of our slime will happen in one second.</p>
<p>Determine if it is possible to set the healths of our first slime and the subsequent slimes spawn so that the multiset of the healths of the <var>2^N</var> slimes that will exist in <var>N</var> seconds equals a multiset <var>S</var>.</p>
<p>Here <var>S</var> is a multiset containing <var>2^N</var> (possibly duplicated) integers: <var>S_1,~S_2,~...,~S_{2^N}</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 18</var></li>
<li><var>1 \leq S_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>S_1</var> <var>S_2</var> <var>...</var> <var>S_{2^N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is possible to set the healths of the first slime and the subsequent slimes spawn so that the multiset of the healths of the <var>2^N</var> slimes that will exist in <var>N</var> seconds equals <var>S</var>, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
4 2 3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>We will show one way to make the multiset of the healths of the slimes that will exist in <var>2</var> seconds equal to <var>S</var>.</p>
<p>First, set the health of the first slime to <var>4</var>.</p>
<p>By letting the first slime spawn a slime whose health is <var>3</var>, the healths of the slimes that exist in <var>1</var> second can be <var>4,~3</var>.</p>
<p>Then, by letting the first slime spawn a slime whose health is <var>2</var>, and letting the second slime spawn a slime whose health is <var>1</var>, the healths of the slimes that exist in <var>2</var> seconds can be <var>4,~3,~2,~1</var>, which is equal to <var>S</var> as multisets.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
1 2 3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Yes
</pre>
<p><var>S</var> may contain multiple instances of the same integer.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1
1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>5
4 3 5 3 1 2 7 8 7 4 6 3 7 2 3 6 2 7 3 2 6 7 3 4 6 7 3 4 2 5 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>No
</pre></section>
</div>
</span> |
p02189 | <h2>Min Element</h2>
<p>æ°å<var>a_1,a_2,..,a_N</var>ãäžããããŸãã</p>
<p>ãã®æ°åã®æå°å€ã®çªå·ãæ±ããŠãã ããã</p>
<p>æå°å€ãè€æ°ã®å Žæã«ãããšãã¯ãçªå·ã®æãå°ãããã®ãçããŠãã ããã</p>
<h3>å
¥å</h3>
<pre>
<var>N</var>
<var>a_1 a_2...a_N</var>
</pre>
<h3>åºå</h3>
<p><var>a_i</var>ãæ°åã®æå°å€ãšãªããããª<var>i</var>ã®ãã¡ãæãå°ãããã®ãåºåããã</p>
<h3>å¶çŽ</h3>
<ul>
<li><var>1 \leq N \leq 10^5 </var></li>
<li><var>1 \leq a_i \leq 10^9</var></li>
</ul>
<h3>å
¥åäŸ</h3>
<pre>
6
8 6 9 1 2 1
</pre>
<h3>åºåäŸ</h3>
<pre>
4
</pre>
|
p02473 | <h2>Difference of Big Integers</h2>
<p>
Given two integers $A$ and $B$, compute the difference, $A - B$.
</p>
<h3>Input</h3>
<p>
Two integers $A$ and $B$ separated by a space character are given in a line.
</p>
<h3>Output</h3>
<p>
Print the difference in a line.
</p>
<h3>Constraints</h3>
<ul>
<li>$-1 \times 10^{100000} \leq A, B \leq 10^{100000}$</li>
</ul>
<h3>Sample Input 1</h3>
<pre>
5 8
</pre>
<h3>Sample Output 1</h3>
<pre>
-3
</pre>
<h3>Sample Input 2</h3>
<pre>
100 25
</pre>
<h3>Sample Output 2</h3>
<pre>
75
</pre>
<h3>Sample Input 3</h3>
<pre>
-1 -1
</pre>
<h3>Sample Output 3</h3>
<pre>
0
</pre>
<h3>Sample Input 4</h3>
<pre>
12 -3
</pre>
<h3>Sample Output 4</h3>
<pre>
15
</pre>
|
p02023 | <h2>I: ç Žå£ (Ravage)</h2>
<p>ãµã³ã¿ã¯ããŒã¹ã¯ãè¡ã®ã€ã«ãããŒã·ã§ã³ã«åŒã£ããããå£ããã</p>
<p>ã€ã«ãããŒã·ã§ã³ã«ã¯Nåã®é»çãããã$i$ çªç®ã®é»çã¯é»å§ã $A_i$ ä»¥äž $B_i$ 以äžã®ãšãã«ããä»ããªããªã£ãŠããŸã£ãã</p>
<p>é»å§ã¯ã€ã«ãããŒã·ã§ã³ã®ã©ãã§ãåãã«ããå¿
èŠãããã</p>
<p>é»å§ã調ç¯ããããšã§ãæå€§ããã€ã®é»çãåæã«å
ãããããšãã§ãããæ±ããã</p>
<h3>å
¥å</h3>
<p>1 è¡ç®ã«ã¯æŽæ° $N$ ãäžããããã</p>
<p>ç¶ã $N$ è¡ã®ãã¡ $i$ è¡ç®ã«ã¯ $A_i, B_i$ ã空çœåºåãã§äžããããã</p>
<h3>åºå</h3>
<p>åæã«å
ãããããšãã§ããé»çã®åæ°ã®æå€§å€ãåºåããã</p>
<h3>å¶çŽ</h3>
<ul>
<li>$N$ 㯠$1$ ä»¥äž $100 \ 000$ 以äžã®æŽæ°</li>
<li>$A_1, A_2, A_3, \dots, A_N$ 㯠$1$ ä»¥äž $1 \ 000 \ 000 \ 000$ 以äžã®æŽæ°</li>
<li>$B_1, B_2, B_3, \dots, B_N$ 㯠$1$ ä»¥äž $1 \ 000 \ 000 \ 000$ 以äžã®æŽæ°</li>
<li>ãã¹ãŠã®é»ç $i$ ã«ã€ããŠã$A_i \leq B_i$ ãæºãã</li>
</ul>
<h3>å
¥åäŸ1</h3>
<pre>
4
1 4
3 6
2 7
5 8
</pre>
<h3>åºåäŸ1</h3>
<pre>
3
</pre>
<p>é»å§ã $5$ ã $3.14$ ã®ãšãã« $3$ ã€ã®é»çãã€ããŸãã</p>
<h3>å
¥åäŸ2</h3>
<pre>
2
1 2
2 3
</pre>
<h3>åºåäŸ2</h3>
<pre>
2
</pre>
|
p02536 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> cities numbered <var>1</var> through <var>N</var>, and <var>M</var> bidirectional roads numbered <var>1</var> through <var>M</var>.
Road <var>i</var> connects City <var>A_i</var> and City <var>B_i</var>.</p>
<p>Snuke can perform the following operation zero or more times:</p>
<ul>
<li>Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities.</li>
</ul>
<p>After he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times).</p>
<p>What is the minimum number of roads he must build to achieve the goal?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 100,000</var></li>
<li><var>1 \leq M \leq 100,000</var></li>
<li><var>1 \leq A_i < B_i \leq N</var></li>
<li>No two roads connect the same pair of cities.</li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>A_1</var> <var>B_1</var>
<var>:</var>
<var>A_M</var> <var>B_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 1
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>Initially, there are three cities, and there is a road between City <var>1</var> and City <var>2</var>.</p>
<p>Snuke can achieve the goal by building one new road, for example, between City <var>1</var> and City <var>3</var>.
After that,</p>
<ul>
<li>We can travel between <var>1</var> and <var>2</var> directly.</li>
<li>We can travel between <var>1</var> and <var>3</var> directly.</li>
<li>We can travel between <var>2</var> and <var>3</var> by following both roads (<var>2</var> - <var>1</var> - <var>3</var>).</li>
</ul></section>
</div>
</span> |
p02166 | <h1>Problem E: Cyclic Shift Sort</h1>
<h2>Problem</h2>
<p>
é·ã $N$ ã®é å $P = \{ P_1, P_2, \ldots, P_N \} $ ãšæŽæ° $K$ ãäžããããã<br>
以äžã®æäœã $0$ å以äžä»»æã®åæ°ç¹°ãè¿ãããšã§ãé å $P$ ãå調å¢å ã«ããããšãã§ãããã©ããå€å®ããã
</p>
<ul>
<li>æŽæ° $x \ (0 \le x \le N-K)$ ãéžã¶ã $ P_{x+1}, \ldots, P_{x+K} $ ãå·¡åå³ã·ãããã</li>
</ul>
<p>
ãã ããéšåå $U=U_1, \ldots, U_M$ ã®å·¡åå³ã·ãããšã¯ã $U=U_1, \ldots, U_M$ ã $U=U_M, U_1, \ldots, U_{M-1}$ ã«å€æŽããããšãæå³ããã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
$N$ $K$
$P_1$ $\ldots$ $P_N$
</pre>
<p>
1è¡ç®ã«é åã®é·ã $N$ ãæŽæ° $K$ ã空çœåºåãã§äžããããã<br>
2è¡ç®ã«é å $P$ ã®èŠçŽ ã空çœåºåãã§äžããããã<br>
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>$2 \leq K \leq N \leq 10^5 $</li>
<li>$ 1 \leq P_i \leq N \ (1 \leq i \leq N) $</li>
<li>$ P_i \neq P_j \ (i \neq j) $</li>
<li>å
¥åã¯ãã¹ãп޿°</li>
</ul>
<h2>Output</h2>
<p>
$P$ ãå調å¢å ã«ããããšãã§ãããªã"Yes"ããã§ããªãã®ã§ããã°"No"ã $1$ è¡ã«åºåããã<br>
</p>
<h2>Sample Input 1</h2>
<pre>
3 3
2 3 1
</pre>
<h2>Sample Output 1</h2>
<pre>
Yes
</pre>
<p>
$ x = 0 $ ãšããŠæäœã $1$ åè¡ããšã $P$ ãå調å¢å ã«ããããšãã§ããã
</p>
<h2>Sample Input 2</h2>
<pre>
3 2
1 2 3
</pre>
<h2>Sample Output 2</h2>
<pre>
Yes
</pre>
<p>
$P$ ãåãããå調å¢å ã§ããå Žåãããã
</p>
<h2>Sample Input 3</h2>
<pre>
3 3
3 2 1
</pre>
<h2>Sample Output 3</h2>
<pre>
No
</pre>
<p>
ã©ã®ããã«æäœãè¡ãªã£ããšããŠãã $P$ ãå調å¢å ã«ããããšã¯ã§ããªãã
</p> |
p03327 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Decades have passed since the beginning of AtCoder Beginner Contest.</p>
<p>The contests are labeled as <code>ABC001</code>, <code>ABC002</code>, <var>...</var> from the first round, but after the <var>999</var>-th round <code>ABC999</code>, a problem occurred: how the future rounds should be labeled?</p>
<p>In the end, the labels for the rounds from the <var>1000</var>-th to the <var>1998</var>-th are decided: <code>ABD001</code>, <code>ABD002</code>, <var>...</var>, <code>ABD999</code>.</p>
<p>You are given an integer <var>N</var> between <var>1</var> and <var>1998</var> (inclusive). Print the first three characters of the label of the <var>N</var>-th round of AtCoder Beginner Contest.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 1998</var></li>
<li><var>N</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the first three characters of the label of the <var>N</var>-th round of AtCoder Beginner Contest.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>ABC
</pre>
<p>The <var>999</var>-th round of AtCoder Beginner Contest is labeled as <code>ABC999</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>ABD
</pre>
<p>The <var>1000</var>-th round of AtCoder Beginner Contest is labeled as <code>ABD001</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1481
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>ABD
</pre>
<p>The <var>1481</var>-th round of AtCoder Beginner Contest is labeled as <code>ABD482</code>.</p></section>
</div>
</span> |
p03777 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Two deer, AtCoDeer and TopCoDeer, are playing a game called <em>Honest or Dishonest</em>.
In this game, an honest player always tells the truth, and an dishonest player always tell lies.
You are given two characters <var>a</var> and <var>b</var> as the input. Each of them is either <code>H</code> or <code>D</code>, and carries the following information:</p>
<p>If <var>a</var>=<code>H</code>, AtCoDeer is honest; if <var>a</var>=<code>D</code>, AtCoDeer is dishonest.
If <var>b</var>=<code>H</code>, AtCoDeer is saying that TopCoDeer is honest; if <var>b</var>=<code>D</code>, AtCoDeer is saying that TopCoDeer is dishonest.</p>
<p>Given this information, determine whether TopCoDeer is honest.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>a</var>=<code>H</code> or <var>a</var>=<code>D</code>.</li>
<li><var>b</var>=<code>H</code> or <var>b</var>=<code>D</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>a</var> <var>b</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If TopCoDeer is honest, print <code>H</code>. If he is dishonest, print <code>D</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>H H
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>H
</pre>
<p>In this input, AtCoDeer is honest. Hence, as he says, TopCoDeer is honest.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>D H
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>D
</pre>
<p>In this input, AtCoDeer is dishonest. Hence, contrary to what he says, TopCoDeer is dishonest.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>D D
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>H
</pre></section>
</div>
</span> |
p02865 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>How many ways are there to choose two distinct positive integers totaling <var>N</var>, disregarding the order?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^6</var></li>
<li><var>N</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>There is only one way to choose two distinct integers totaling <var>4</var>: to choose <var>1</var> and <var>3</var>. (Choosing <var>3</var> and <var>1</var> is not considered different from this.)</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>999999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>499999
</pre></section>
</div>
</span> |
p00858 |
<H1><font color="#000">Problem E:</font> Geometric Map</H1>
<p>
Your task in this problem is to create a program that finds the shortest path between two given
locations on a given street map, which is represented as a collection of line segments on a plane.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_geometricMap">
</center>
<p>
Figure 4 is an example of a street map, where some line segments represent streets and the
others are signs indicating the directions in which cars cannot move. More concretely, <span>AE</span>, <span>AM</span>, <span>MQ</span>, <span>EQ</span>, <span>CP</span> and <span>HJ</span> represent the streets and the others are signs in this map. In general, an end point of a sign touches one and only one line segment representing a street and the other end point is open. Each end point of every street touches one or more streets, but no signs.
</p>
<p>
The sign <span>BF</span>, for instance, indicates that at <span>B</span> cars may move left to right but may not in the
reverse direction. In general, cars may not move from the obtuse angle side to the acute angle
side at a point where a sign touches a street (note that the angle <span>CBF</span> is obtuse and the angle <span>ABF</span> is acute). Cars may directly move neither from <span>P</span> to <span>M</span> nor from <span>M</span> to <span>P</span> since cars moving left
to right may not go through <span>N</span> and those moving right to left may not go through <span>O</span>. In a special
case where the angle between a sign and a street is rectangular, cars may not move in either
directions at the point. For instance, cars may directly move neither from <span>H</span> to <span>J</span> nor from <span>J</span> to <span>H</span>.
</p>
<p>
You should write a program that finds the shortest path obeying these traffic rules. The length of a line segment between (<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>) and (<i>x</i><sub>2</sub>, <i>y</i><sub>2</sub>) is √{(<i>x</i><sub>2</sub> â <i>x</i><sub>1</sub>)<sup>2</sup> + (<i>y</i><sub>2</sub> â <i>y</i><sub>1</sub> )<sup>2</sup>} .
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets, each in the following format.
</p>
<pre>
<i>n</i>
<i>x<sub>s</sub> y<sub>s</sub></i>
<i>x<sub>g</sub> y<sub>g</sub></i>
<i>x</i><sub>1</sub><sup>1</sup> <i>y</i><sub>1</sub><sup>1</sup> <i>x</i><sub>2</sub><sup>1</sup> <i>y</i><sub>2</sub><sup>1</sup>
.
.
.
<i>x</i><sub>1</sub><sup><i>k</i></sup> <i>y</i><sub>1</sub><sup><i>k</i></sup> <i>x</i><sub>2</sub><sup><i>k</i></sup> <i>y</i><sub>2</sub><sup><i>k</i></sup>
.
.
.
<i>x</i><sub>1</sub><sup><i>n</i></sup> <i>y</i><sub>1</sub><sup><i>n</i></sup> <i>x</i><sub>2</sub><sup><i>n</i></sup> <i>y</i><sub>2</sub><sup><i>n</i></sup>
</pre>
<p>
<i>n</i>, representing the number of line segments, is a positive integer less than or equal to 200.
</p>
<p>
(<i>x<sub>s</sub></i>, <i>y<sub>s</sub></i>) and (<i>x<sub>g</sub></i>, <i>y<sub>g</sub></i>) are the start and goal points, respectively. You can assume that (<i>x<sub>s</sub></i>, <i>y<sub>s</sub></i>) ≠ (<i>x<sub>g</sub></i>, <i>y<sub>g</sub></i>) and that each of them is located on an end point of some line segment representing a street. You can also assume that the shortest path from (<i>x<sub>s</sub></i>, <i>y<sub>s</sub></i>) to (<i>x<sub>g</sub></i>, <i>y<sub>g</sub></i>) is unique.
</p>
<p>
(<i>x</i><sub>1</sub><sup><i>k</i></sup>, <i>y</i><sub>1</sub><sup><i>k</i></sup>) and (<i>x</i><sub>2</sub><sup><i>k</i></sup>, <i>y</i><sub>2</sub><sup><i>k</i></sup> ) are the two end points of the kth line segment. You can assume that
(<i>x</i><sub>1</sub><sup><i>k</i></sup>, <i>y</i><sub>1</sub><sup><i>k</i></sup>) ≠(<i>x</i><sub>2</sub><sup><i>k</i></sup>, <i>y</i><sub>2</sub><sup><i>k</i></sup> ).
Two line segments never cross nor overlap. That is, if they share a point, it is always one of their end points.
</p>
<p>
All the coordinates are non-negative integers less than or equal to 1000. The end of the input is indicated by a line containing a single zero.
</p>
<H2>Output</H2>
<p>
For each input dataset, print every street intersection point on the shortest path from the start
point to the goal point, one in an output line in this order, and a zero in a line following
those points. Note that a street intersection point is a point where at least two line segments
representing streets meet. An output line for a street intersection point should contain its <i>x</i>- and <i>y</i>-coordinates separated by a space.
</p>
<p>
Print <span>-1</span> if there are no paths from the start point to the goal point.
</p>
<H2>Sample Input</H2>
<pre>
8
1 1
4 4
1 1 4 1
1 1 1 4
3 1 3 4
4 3 5 3
2 4 3 5
4 1 4 4
3 3 2 2
1 4 4 4
9
1 5
5 1
5 4 5 1
1 5 1 1
1 5 5 1
2 3 2 4
5 4 1 5
3 2 2 1
4 2 4 1
1 1 5 1
5 3 4 3
11
5 5
1 0
3 1 5 1
4 3 4 2
3 1 5 5
2 3 2 2
1 0 1 2
1 2 3 4
3 4 5 5
1 0 5 2
4 0 4 1
5 5 5 1
2 3 2 4
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1 1
3 1
3 4
4 4
0
-1
5 5
5 2
3 1
1 0
0
</pre>
|
p00272 |
<H1>ãã±ããã®å£²ãäžã</H1>
<p>
仿¥ã¯ãã¢ã€ã
ã»ãšã³ã¿ãŒãã€ã³ã¡ã³ã瀟ã€ããªã·ã®ã¢ã€ãã«ã°ã«ãŒããã¢ã«ãã³ïŒã³ããŠã·ãã®ãã±ããçºå£²æ¥ã§ãããã±ããã«ã¯ä»¥äžã®ïŒçš®é¡ããããŸãã<br/>
<br/>
ïŒ³åž 6000å<br>
ïŒ¡åž 4000å<br>
ïŒ¢åž 3000å<br>
ïŒ£åž 2000å<br>
<br/>
販売責任è
ã®ããªãã¯ãããããããªããçºå£²éå§ãåŸ
ã£ãŠããŸããããããçºå£²éå§ã売ãè¡ã絶奜調ã§ãïŒ
</p>
<p>
çºå£²éå§ãããã°ããçµã£ããšããã§ããããŸã§ã®æ³šæããŸãšãã衚ãåãåããŸããã衚ã®åè¡ã«ã¯ããããŸã§ã«å£²ãããã±ããã®çš®é¡ãšææ°ãæžããŠãããŸãããã ãããã±ããã®çš®é¡ãïŒïŒ¡ïŒïŒ¢ïŒïŒ£ã®é ã«çŸãããšã¯éããŸããããã®è¡šã®è¡ããšã®å£²äžéé¡ãæ±ããããã°ã©ã ãäœæããŠãã ããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åããŒã¿ã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>t<sub>1</sub></var> <var>n<sub>1</sub></var>
<var>t<sub>2</sub></var> <var>n<sub>2</sub></var>
<var>t<sub>3</sub></var> <var>n<sub>3</sub></var>
<var>t<sub>4</sub></var> <var>n<sub>4</sub></var>
</pre>
<p>
å
¥åã¯4è¡ãããªããiè¡ç®ã«ã¯ããã±ããã®çš®é¡ãè¡šãæŽæ° <var>t<sub>i</sub></var> (1 ≤ <var>t<sub>i</sub></var> ≤ 4)ãšææ°ãè¡šãæŽæ° <var>n<sub>i</sub></var> (0 ≤ <var>n<sub>i</sub></var> ≤ 10000)ãäžããããããã±ããã®çš®é¡ãè¡šãæŽæ°1, 2, 3, 4ã¯ãããããåžãåžãåžãåžã衚ãã<var>t<sub>1</sub></var>, <var>t<sub>2</sub></var>, <var>t<sub>3</sub></var>, <var>t<sub>4</sub></var> ã®å€ãšããŠ1ãã4ãŸã§ã®æ°ã¯å¿
ãïŒåºŠã ãçŸãããã1, 2, 3, 4ã®é ã§äžãããããšã¯éããªãã
</p>
<h2>åºå</h2>
<p>
è¡ããšã«å£²äžéé¡ãåºåããã
</p>
<h2>å
¥åäŸ 1</h2>
<pre>
3 10
1 4
4 1
2 5
</pre>
<h2>åºåäŸ 1</h2>
<pre>
30000
24000
2000
20000
</pre>
<br/>
<h2>å
¥åäŸ 2</h2>
<pre>
1 1
2 0
3 1
4 1
</pre>
<h2>åºåäŸ 2</h2>
<pre>
6000
0
3000
2000
</pre> |
p00788 |
<H1><font color="#000">Problem A:</font> Rational Irrationals</H1>
<p>
Rational numbers are numbers represented by ratios of two integers. For a prime number <i>p</i>, one of the elementary theorems in the number theory is that there is no rational number equal to √<i>p</i>. Such numbers are called irrational numbers. It is also known that there are rational numbers arbitrarily close to √<i>p</i>
</p>
<p>
Now, given a positive integer <i>n</i>, we define a set <i>Q<sub>n</sub></i> of all rational numbers whose elements are represented by ratios of two positive integers both of which are less than or equal to <i>n</i>. For example, <i>Q</i><sub>4</sub> is a set of 11 rational numbers {1/1, 1/2, 1/3, 1/4, 2/1, 2/3, 3/1, 3/2, 3/4, 4/1, 4/3}. 2/2, 2/4, 3/3, 4/2 and 4/4 are not included here because they are equal to 1/1, 1/2, 1/1, 2/1 and 1/1, respectively.
</p>
<p>
Your job is to write a program that reads two integers <i>p</i> and <i>n</i> and reports two rational numbers <i>x / y</i> and <i>u / v</i>, where <i>u / v</i> < √<i>p</i> < <i>x / y</i> and there are no other elements of <i>Q<sub>n</sub></i> between <i>u/v</i> and <i>x/y</i>. When <i>n</i> is greater than √<i>p</i>, such a pair of rational numbers always exists.
</p>
<H2>Input</H2>
<p>
The input consists of lines each of which contains two positive integers, a prime number <i>p</i> and an integer <i>n</i> in the following format.
</p>
<pre>
<i>p n</i>
</pre>
<p>
They are separated by a space character. You can assume that <i>p</i> and <i>n</i> are less than 10000, and that <i>n</i> is greater than √<i>p</i>. The end of the input is indicated by a line consisting of two zeros.
</p>
<H2>Output</H2>
<p>
For each input line, your program should output a line consisting of the two rational numbers <i>x / y</i> and <i>u / v</i> (<i>x / y</i> > <i>u / v</i>) separated by a space character in the following format.
</p>
<pre>
<i>x/y u/v</i>
</pre>
<p>
They should be irreducible. For example, 6/14 and 15/3 are not accepted. They should be reduced to 3/7 and 5/1, respectively.
</p>
<H2>Sample Input</H2>
<pre>
2 5
3 10
5 100
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
3/2 4/3
7/4 5/3
85/38 38/17
</pre>
|
p01930 |
<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>Big Maze</h3>
<p>ããªã㯠Jumbo Amusement GardenïŒç¥ããŠãJAGããšåŒã°ãã巚倧ãªéåå°ã§åããŠããïŒãã®éåå°ã®æ·å°ã¯åºå€§ã§ïŒã¢ãã©ã¯ã·ã§ã³ãããšããšã巚倧ãªãã®ãèšçœ®ãããïŒ
</p>
<p>ãã®åºŠJAGã«ïŒæ°ããªå·šå€§è¿·è·¯ã¢ãã©ã¯ã·ã§ã³ãBig Mazeããå°å
¥ãããããšã«ãªã£ãïŒ
Big Maze ã®åœ¢ç¶ã¯ïŒå¹³é¢å³ã§èŠããšïŒçžŠæšªå
±ã« <i>N</i> ãã¹ã®æ£æ¹åœ¢ç¶ã®è¿·è·¯ <i>M</i> åãïŒé£æ¥ããå·Šå³ã®èŸºå士ãç¹ãåããïŒçžŠ <i>N</i> ãã¹ïŒæšª <i>NM</i> ãã¹ã®é·æ¹åœ¢ç¶ã«ãªãäºå®ã§ããïŒ
</p>
<p><i>M</i> åã®è¿·è·¯ãå·Šããã©ã®é çªã§ç¹ãåããããã¯ãããããæ±ºãŸã£ãŠãããïŒé£ãåãè¿·è·¯ã®ã©ã®èŸºå士ãç¹ãåããããã¯æªå®ã§ããïŒ
<i>M</i> åã®è¿·è·¯ãç¹ãåãããåã«ïŒåè¿·è·¯ã90 床å転ãããäºãåºæ¥ãïŒå転ã¯äœåºŠã§ãè¡ãããšãã§ãïŒåæ°ã¯è¿·è·¯æ¯ã«å¥ã
ã«æ±ºããŠããïŒå転ãããªãè¿·è·¯ããã£ãŠãããŸããªãïŒ
</p>
<p>åãã¹ã¯éè¡å¯èœãªãéè·¯ããïŒéè¡äžå¯èœãªãå£ãã®ããããã§ããïŒBig Maze ã®å
éšã§ã®ç§»åã¯ïŒäžäžå·Šå³ã® 4 æ¹åã«é£æ¥ããéè·¯ã®ãã¹ã«éãå¯èœã§ããïŒ
</p>
<p>Big Maze ã®å·Šç«¯ã® <i>N</i> ç®æã«äœçœ®ãïŒãã€éè·¯ã§ãããã¹ãã¹ã¿ãŒãå°ç¹ãšãïŒå³ç«¯ã® <i>N</i> ç®æã«äœçœ®ãïŒãã€éè·¯ã§ãããã¹ããŽãŒã«å°ç¹ãšããïŒ
</p>
<p><i>M</i> åã®è¿·è·¯ãç¹ãåããã蟺ã®éžã³æ¹ã«ãã£ãŠã¯ïŒã¹ã¿ãŒãå°ç¹ããŽãŒã«å°ç¹ãè€æ°ååšããå ŽåãïŒååšããªãå ŽåãããåŸãïŒ
ãŸãïŒã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ãžã®çµè·¯ãè€æ°ååšããå ŽåãïŒååšããªãå ŽåãããåŸãïŒ
</p>
<p>ããªãã®ä»äºã¯ïŒ å·Šããç¹ãåãããé çªããããããæ±ºãŸã£ãŠãã <i>M</i> åã®è¿·è·¯ãé©åã«å転ããïŒç¹ãåããã蟺ãäžæãéžã¶ããšã§ïŒã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ãžéè·¯ãç§»åããŠå°éå¯èœãªçžŠ <i>N</i> ãã¹ïŒæšª <i>NM</i> ãã¹ã®é·æ¹åœ¢ç¶ã® Big Maze ãäœãããšãåºæ¥ãã確èªããããšã§ããïŒ
</p>
<h3>Input</h3>
<p>å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ãããé£ç¶ããŠäžããããïŒ
ããŒã¿ã»ããã®æ°ã¯æå€§ã§ 50 ã§ããïŒ
åããŒã¿ã»ããã¯ïŒæ¬¡ã®åœ¢åŒã§è¡šãããïŒ
</p><blockquote><i>N</i> <i>M</i><br><i>maze<sub>1</sub></i><br><i>maze<sub>2</sub></i><br><i>...</i><br><i>maze<sub>M</sub></i><br></blockquote>
<p>æåã®è¡ã¯ãµãã€ã®æŽæ° <i>N</i>ïŒ<i>M</i> ã空çœåºåãã§äžãããïŒçžŠæšª <i>N</i> ãã¹ã®è¿·è·¯ã <i>M</i> åäžããããããšã瀺ãïŒ<i>1 ≤ N ≤ 12</i> ã〠<i>1 ≤ M ≤ 1,</sub>000</i> ã§ããïŒ
</p><blockquote></blockquote>
<p>ç¶ããŠïŒç©ºçœç¡ãã® <i>N</i> æåã 1 è¡ãšãã <i>N</i> è¡ã®å
¥å <i>maze<sub>i</sub></i> ã <i>M</i> åç¶ãïŒ
ããã§ïŒ<i>1 ≤ i ≤ M</i> ã§ããïŒ
</p><blockquote></blockquote>
<p><i>N</i> è¡ã®å
¥å <i>maze<sub>i</sub></i> ã¯ïŒå·Šããç¹ãåãããé çªã§æ°ãããšãã® <i>i</i> çªç®ã®è¿·è·¯ã®æ
å ±ã衚ãïŒä»¥äžã®åœ¢åŒã§äžããããïŒ
</p><blockquote><i>c<sub>1, 1</sub> c<sub>1, 2</sub> ... c<sub>1, N</sub></i><br><i>c<sub>2, 1</sub> c<sub>2, 2</sub> ... c<sub>2, N</sub></i><br><i>...</i><br><i>c<sub>N, 1</sub> c<sub>N, 2</sub> ... c<sub>N, N</sub></i><br></blockquote>
<p>å<i>c<sub>j, k</sub></i> ã¯ïŒâ.â ãŸã㯠â#â ã®ãããã 1 æåã§ïŒäžãã <i>j</i> çªç®ãã€å·Šãã <i>k</i> çªç®ã®ãã¹ã®æ
å ±ã衚ãïŒâ.â ã®ãšãéè·¯ïŒâ#âã®ãšãå£ã§ããïŒ
ããã§ïŒ<i>1 ≤ j, k ≤ N</i> ã§ããïŒ
</p><blockquote></blockquote>
<p>å
¥åã®çµããã¯ïŒç©ºçœã§åºåããã 2 åã®ãŒããããªãè¡ã§ç€ºãããïŒ
</p><blockquote></blockquote>
<h3>Output</h3>
<p>åããŒã¿ã»ããã«ã€ããŠïŒã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ãžç§»åå¯èœãªçµè·¯ãå°ãªããšãã²ãšã€ååšãã Big Maze ãäœãããšãå¯èœãªã âYesâïŒäžå¯èœãªã âNoâ ã 1 è¡ã§åºåããïŒ
</p><blockquote></blockquote>
<h3>Sample Input</h3>
<pre>3 2
#.#
...
#.#
###
...
###
3 2
#.#
...
#.#
###
#.#
###
3 3
#..
..#
###
..#
#.#
#..
#..
..#
###
5 3
.....
#####
##...
##.##
##...
.....
#####
.....
#####
.....
...##
##.##
...##
#####
.....
3 2
#.#
...
#.#
#.#
#.#
#.#
0 0
</pre>
<h3>Output for Sample Input</h3>
<pre>Yes
No
Yes
Yes
Yes</pre>
<p>以äžã«ïŒãµã³ãã«ããŒã¿ã»ããã®å³ã瀺ãïŒ</p>
<br><div style="text-align:center">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2017_fig_h_sample_00" height="160">
</div><br>
<br><div style="text-align:center">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2017_fig_h_sample_01" height="160">
</div><br>
<br><div style="text-align:center">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2017_fig_h_sample_02" height="160">
</div><br>
<br><div style="text-align:center">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2017_fig_h_sample_03" height="160">
</div><br>
<br><div style="text-align:center">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2017_fig_h_sample_04" height="160">
</div><br> |
p00622 |
<H1><font color="#000000">Problem B:</font> Monster Factory</H1>
<p>
æ ªåŒäŒç€Ÿå倩å ã¯, Packet Monster ãšããã²ãŒã ãœãããçºå£²ããŠãã. ãã®ã²ãŒã ã¯ã¢ã³ã¹ã¿ãŒãæãŸã, è²ãŠ, æŠããããšããè¶£æšã®ãã®ã§, äžçäžã§å€§äººæ°ã®ã²ãŒã ã§ãã£ã.
</p>
<p>
ãã®ã²ãŒã ã«ã¯åŸæ¥ã®ã²ãŒã ã«ã¯ç¡ãç¹åŸŽããã£ã. ãã®ã²ãŒã ã«ã¯ Red ãš Green ãšãã2ã€ã®ããŒãžã§ã³ããã, ããããã®ã²ãŒã ã§æãŸããããã¢ã³ã¹ã¿ãŒãç°ãªãã®ã . Red ã§ããæãŸããããªãã¢ã³ã¹ã¿ãŒã Green ã§å
¥æããã«ã¯, é信亀æãšããã·ã¹ãã ã䜿ã. ã€ãŸã, èªåã®ãœããå
ã®ã¢ã³ã¹ã¿ãŒãšåéã®ãœããå
ã®ã¢ã³ã¹ã¿ãŒã亀æããããšãã§ããã®ã . ãã®ã·ã¹ãã 㯠Packet Monster ã®äººæ°ã«å€§ããè²¢ç®ããŠãã.
</p>
<p>
ããã, ãã®ã²ãŒã ã®ããã±ãŒãžã®è£œé å·¥çšã¯, 2ã€ã®ããŒãžã§ã³ã®ããã«å°ã
è€éã«ãªã£ã. ããã±ãŒãžã補é ããŠããå·¥å Žã«ã¯2ã€ã®çç£ã©ã€ã³ããã, çæ¹ã®ã©ã€ã³ã§ã¯ Red ã, ããäžæ¹ã®ã©ã€ã³ã§ã¯ Green ã補é ããŠãã. åã©ã€ã³ã§è£œé ãããããã±ãŒãžã¯, å·¥å Žå
ã§äžæãªè£œé çªå·ãå²ãåœãŠãã, äžç®æã«éãããã. ãããŠä»¥äžã®ãããªæªæïŒããã¯ãïŒè£
眮ã«ãã£ãŠæ··ããã, åºè·ãããã®ã .
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_churn1">
</center>
<p>
Red ã®ããã±ãŒãžã¯äžåŽãã, Green ã®ããã±ãŒãžã¯å·ŠåŽãã, ãã«ãã³ã³ãã¢ã«ãã£ãŠãã®æªæè£
眮ã«å±ãããã. æªæè£
眮ã¯ååã®åœ¢ããã2æ¬ã®ãã«ãã³ã³ãã¢ããåºæ¥ãŠãã, "push_down", "push_right" ãšãã2ã€ã®åœä»€ãåãä»ãã. "push_down"ã¯ãäžäžæ¹åã«èµ°ããã«ãã³ã³ãã¢ãããã±ãŒãž1ååäžæ¹åã«åããã, "push_right"ã¯ãå·Šå³æ¹åã«èµ°ããã«ãã³ã³ãã¢ãããã±ãŒãž1åå峿¹åã«åããããšããåœä»€ã§ãã. æªæã¯, Red ã®ããã±ãŒãžãšåãæ°ã® push_down åœä»€ãš Green ã®ããã±ãŒãžã®æ°ããïŒã€å€ã push_right åœä»€ã, ã©ã³ãã ãªé çªã§å®è¡ããããšã«ãã£ãŠè¡ããã. ãã ã, æåã«å®è¡ãããåœä»€ãšæåŸã«å®è¡ãããåœä»€ã¯ "push_right" ãšæ±ºãŸã£ãŠãã. ãã®å¶çŽã®å
ã§ã¯, Red ã®ããã±ãŒãžã®æ°ãšæªæè£
眮ã®äžç«¯ã«å±ãããã±ãŒãžã®æ°ãäžèŽã, Green ã®ããã±ãŒãžã®æ°ãšæªæè£
眮ã®å³ç«¯ã«å±ãããã±ãŒãžã®æ°ãäžèŽãã.
</p>
<p>
æªæãããããã±ãŒãžã¯æçµçã«ãã«ãã³ã³ãã¢ã®äžç«¯ãŸãã¯å³ç«¯ã«å±ã, å±ããé ã«å
è£
ãããŠåºè·ããã.
</p>
<p>
以äžã«, äžé£ã®æªæã®æç¶ãã®äŸã瀺ã.
ç°¡åã®ãã, 1ã€ã®ããã±ãŒãžã1æåã®ã¢ã«ãã¡ããããšããŠè¡šã.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_churn2">
</center>
<p>
ããŠ, ãã®å·¥å Žã§ã¯äžè¯åã®è¿œè·¡ãªã©ã®ç®çã§, ãã«ãã³ã³ãã¢ã®äžç«¯ã»å³ç«¯ã«å±ããããã±ãŒãžãšãã®é çªãèšé²ããŠãã.ããããã®èšé²ã«ã¯ã³ã¹ããæãããã, å·¥å Žé·ã¯äžç«¯ã«å±ããããã±ãŒãžã«ã€ããŠã®ã¿èšé²ãåãããšãèãã.å³ç«¯ã«å±ããããã±ãŒãžã¯, äžç«¯ã»å·Šç«¯ã«éãããããã±ãŒãžãšäžç«¯ã«å±ããããã±ãŒãžã®èšé²ããæ±ããããã®ã§ã¯ãªãããšæã£ãã®ã .
</p>
<p>
å·¥å Žé·ãå©ããŠ, å³ç«¯ã«å±ããããã±ãŒãžã®èšé²ãäœæããããã°ã©ã ãäœã£ãŠã»ãã.
</p>
<H2>Input</H2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªã. å
¥åã®çµãã㯠- (ãã€ãã³)ïŒã€ã®è¡ã§ç€ºããã.
</p>
<p>
1ã€ã®å
¥åã¯3è¡ã®ã¢ã«ãã¡ãããã®å€§æåã»å°æåã®ã¿ãå«ãæååãããªã.
ãããã¯ãããã, Red ã®ããã±ãŒãž, Green ã®ããã±ãŒãž, äžç«¯ã«å±ããããã±ãŒãžã衚ã.1æåã®ã¢ã«ãã¡ãããã1åã®ããã±ãŒãžã衚ã.倧æåãšå°æåã¯åºå¥ãããããšã«æ³šæãã.
</p>
<p>
ã©ã®è¡ã«ã, åãæåã2å以äžçŸããããšã¯ç¡ã.
1è¡ç®ãš2è¡ç®ã«å
±éããŠå«ãŸããæåãååšããªã.
</p>
<p>
å顿äžã§èª¬æãããã±ãŒã¹ã¯, Sample Inputã®1ã€ç®ã®äŸã«å¯Ÿå¿ããŠãã.
</p>
<H2>Output</H2>
<p>
å³ç«¯ã«å±ããããã±ãŒãžã, å±ããé çªã®ãšããã«åºåãã.
</p>
<H2>Sample Input</H2>
<pre>
CBA
cba
cCa
X
ZY
Z
-
</pre>
<H2>Output for the Sample Input</H2>
<pre>
BbA
XY
</pre>
|
p01463 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<H1>Runaway Domino</H1>
<p>
``Domino effect'' is a famous play using dominoes.
A player sets up a chain of dominoes stood.
After a chain is formed, the player topples one end of the dominoes.
The first domino topples the second domino, the second topples the third and so on.
</p>
<p>
You are playing domino effect.
Before you finish to set up a chain of domino,
a domino block started to topple, unfortunately.
You have to stop the toppling as soon as possible.
</p>
<p>
The domino chain forms a polygonal line on a two-dimensional coordinate system without self intersections.
The toppling starts from a certain point on the domino chain
and continues toward the both end of the chain.
If the toppling starts on an end of the chain, the toppling continue toward the other end.
The toppling of a direction stops when you touch the toppling point or the toppling reaches an end of the domino chain.
</p>
<p>
You can assume that:
</p>
<ul>
<li> You are a point without volume on the two-dimensional coordinate system.</li>
<li> The toppling stops soon after touching the toppling point.</li>
<li> You can step over the domino chain without toppling it.</li>
</ul>
<p>
You will given the form of the domino chain, the starting point of the toppling,
your coordinates when the toppling started, the toppling velocity and the your velocity.
You are task is to write a program that calculates your optimal move to stop the toppling at the earliest timing and
calculates the minimum time to stop the toppling.
</p>
<H2>Input</H2>
<p>
The first line contains one integer <var>N</var>,
which denotes the number of vertices in the polygonal line of the domino chain <var>(2 \leq N \leq 1000)</var>.
Then <var>N</var> lines follow, each consists of two integers <var>x_{i}</var> and <var>y_{i}</var>,
which denote the coordinates of the <var>i</var>-th vertex <var>(-10,000 \leq x, y \leq 10000)</var>.
The next line consists of three integers <var>x_{t}</var>, <var>y_{t}</var> and <var>v_{t}</var>,
which denote the coordinates of the starting point and the velocity of the toppling.
The last line consists of three integers <var>x_{p}</var>, <var>y_{p}</var> and <var>v_{p}</var>,
which denotes the coordinates of you when the toppling started and the velocity <var>(1 \leq v_{t} \lt v_{p} \leq 10)</var>.
You may assume that the starting point of the toppling lies on the polygonal line.
</p>
<H2>Output</H2>
<p>
Print the minimum time to stop the toppling.
The output must have a relative or absolute error less than <var>10^{-6}</var>.
</p>
<H2>Sample Input 1</H2>
<pre>
2
0 0
15 0
5 0 1
10 10 2
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
5.0
</pre>
<H2>Sample Input 2</H2>
<pre>
3
-10 0
0 0
0 10
-1 0 1
3 0 2
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
4.072027
</pre>
<H2>Sample Input 3</H2>
<pre>
2
0 0
10 0
5 0 1
9 0 3
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>
2.0
</pre>
|
p01199 |
<H1><font color="#000"></font>Flame of Nucleus</H1>
<!-- Problem D -->
<p>
Year 20XX â a nuclear explosion has burned the world. Half the people on the planet have died. Fearful.
</p>
<p>
One city, fortunately, was not directly damaged by the explosion. This city consists of <i>N</i> domes (numbered 1
through <i>N</i> inclusive) and <i>M</i> bidirectional transportation pipelines connecting the domes. In dome <i>i</i>, <i>P<sub>i</sub></i> citizens
reside currently and there is a nuclear shelter capable of protecting <i>K<sub>i</sub></i> citizens. Also, it takes <i>D<sub>i</sub></i> days to travel
from one end to the other end of pipeline <i>i</i>.
</p>
<p>
It has been turned out that this city will be polluted by nuclear radiation in <i>L</i> days after today. So each citizen
should take refuge in some shelter, possibly traveling through the pipelines. Citizens will be dead if they reach
their shelters in exactly or more than <i>L</I> days.
</p>
<p>
How many citizens can survive at most in this situation?
</p>
<H2>Input</H2>
<p>
The input consists of multiple test cases. Each test case begins with a line consisting of three integers <i>N</i>, <i>M</i>
and <i>L</i> (1 ≤ <i>N</i> ≤ 100, <i>M</i> ≥ 0, 1 ≤ <i>L</i> ≤ 10000). This is followed by <i>M</i> lines describing the configuration of
transportation pipelines connecting the domes. The <i>i</i>-th line contains three integers <i>A<sub>i</sub></i>, <i>B<sub>i</sub></i> and <i>D<sub>i</sub></i> (1 ≤ <i>A<sub>i</sub></i> < <i>B<sub>i</sub></i> ≤
<i>N</i>, 1 ≤ <i>D<sub>i</sub></i> ≤ 10000), denoting that the <i>i</i>-th pipeline connects dome <i>A<sub>i</sub></i> and <i>B<sub>i</sub></i>. There is at most one pipeline
between any pair of domes. Finally, there come two lines, each consisting of <i>N</i> integers. The first gives <i>P</i><sub>1</sub> , . . .,
<i>P<sub>N</sub></i> (0 ≤ <i>P<sub>i</sub></i> ≤ 10<sup>6</sup>) and the second gives <i>K</i><sub>1</sub> , . . ., <i>K<sub>N</sub></i> (0 ≤ <i>K<sub>i</sub></i> ≤ 10<sup>6</sup>).
</p>
<p>
The input is terminated by EOF. All integers in each line are separated by a whitespace.
</p>
<H2>Output</H2>
<p>
For each test case, print in a line the maximum number of people who can survive.
</p>
<H2>Sample Input</H2>
<pre>
1 0 1
51
50
2 1 1
1 2 1
1000 0
0 1000
4 3 5
1 2 4
1 3 1
3 4 2
0 1000 1000 1000
3000 0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
50
0
3000
</pre>
|
p01033 | <h1>Problem F: Coupling</h1>
<h2>Problem</h2>
<p>
ææŽ¥å€§åŠã§ã¯æ¯å¹Žå€§èŠæš¡ãªåã³ã³ãè¡ãããŠããŸãã<br>
ä»å¹Žã¯<var>N</var>人ã®ç·æ§ãš<var>M</var>人ã®å¥³æ§ãåå ããŸãã<br>
ããããç·æ§ã¯0ããé ã«<var>N</var>−1ãŸã§IDãå²ãæ¯ããããã女æ§ã¯0ããé ã«<var>M</var>−1ãŸã§IDãå²ãæ¯ãããŠããŸãã
</p>
<p>
ãã®åã³ã³ã§ã¯èªåã®ã倧奜ããªäººããšããããã奜ããªäººãã®IDãæç€ºããŸãã<br>
ç·æ§ã¯ãããã女æ§ã®IDãã女æ§ã¯ããããç·æ§ã®IDãæç€ºããŸãã<br>
</p>
<p>
ãã®åŸã以äžã®ã«ãŒã«ã«åŸã£ãŠã«ããã«ãæç«ããŸãã
</p>
<ol>
<li>ç·æ§ã¯è€æ°ã®å¥³æ§ã女æ§ã¯è€æ°ã®ç·æ§ãšã«ããã«ã«ãªã£ãŠã¯ãããªãã</li>
<li>äºãã«ã倧奜ããªäººããšæç€ºããç·æ§ãšå¥³æ§ã§ãã¢ãã§ããã<br>ãããããä»»æã®ãã¢ãéžã³ã«ããã«ãäœãããšãã§ããã</li>
<li>çæ¹ãã倧奜ããªäººããããçæ¹ãããããã奜ããªäººããšæç€ºããç·æ§ãšå¥³æ§ã§ãã¢ãã§ããã<br> ãããããä»»æã®ãã¢ãéžã³ã«ããã«ãäœãããšãã§ããã</li>
<li>äºãã«ããããã奜ããªäººããšæç€ºããç·æ§ãšå¥³æ§ã§ãã¢ãã§ããã<br> ãããããä»»æã®ãã¢ãéžã³ã«ããã«ãäœãããšãã§ããã</li>
<li>ã«ãŒã«2ã§åºæ¥ãã«ããã«ãã«ãŒã«3ã§åºæ¥ãã«ããã«ãã«ãŒã«4ã§åºæ¥ãã«ããã«ã®é ã«ã«ããã«ã®æ°ãæå€§ã«ãªãããã«ã«ããã«ãæç«ããã</li>
</ol>
<p>
ãµãžåã¯ãã®åã³ã³ã®äž»å¬è
ã§ãã
è¿å¹Žã§ã¯åå è
ã®æ°ãå€ããªãæåã§ã«ããã«ã®æ°ãææ¡ããã®ã倧å€ã«ãªã£ãŠããŸãããããã§ããã°ã©ããŒã§ããããªãã¯ããµãžåã®æäŒããããããšã«ããŸãããäžèšã®ã«ãŒã«ã«åŸã£ãŠã«ããã«ãäœã£ãæã®ã倧奜ããªäººãå士ã®ã«ããã«ã®æ°ãšã倧奜ããªäººããšããããã奜ããªäººãã«ããã«ããã«ã®æ°ãšããããã奜ããªäººãå士ã®ã«ããã«ã®æ°ãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var> <var>M</var>
<var>L1</var>
<var>a<sub>1</sub></var> <var>b<sub>1</sub></var>
<var>a<sub>2</sub></var> <var>b<sub>2</sub></var>
:
<var>a<sub>L1</sub></var> <var>b<sub>L1</sub></var>
<var>L2</var>
<var>c<sub>1</sub></var> <var>d<sub>1</sub></var>
<var>c<sub>2</sub></var> <var>d<sub>2</sub></var>
:
<var>c<sub>L2</sub></var> <var>d<sub>L2</sub></var>
<var>L3</var>
<var>e<sub>1</sub></var> <var>f<sub>1</sub></var>
<var>e<sub>2</sub></var> <var>f<sub>2</sub></var>
:
<var>e<sub>L3</sub></var> <var>f<sub>L3</sub></var>
<var>L4</var>
<var>g<sub>1</sub></var> <var>h<sub>1</sub></var>
<var>g<sub>2</sub></var> <var>h<sub>2</sub></var>
:
<var>g<sub>L4</sub></var> <var>h<sub>L4</sub></var>
</pre>
<p>
1è¡ç®ã«ããããç·æ§ã®åå è
ã®æ°ãšå¥³æ§ã®åå è
ã®æ°ã衚ã2ã€ã®æŽæ°<var>N</var>,<var>M</var>ãäžãããããæ¬¡ã«ç·æ§åŽã®å€§å¥œããªäººã衚ãããŒã¿ã®æ°<var>L1</var>ãäžãããããç¶ãL1è¡ã«<var>a<sub>i</sub></var>ãš<var>b<sub>i</sub></var>ã空çœåºåãã§äžããããããããããID<var>a<sub>i</sub></var>ã®ç·æ§ãID<var>b<sub>i</sub></var>ã®å¥³æ§ãã倧奜ããã§ããããšã瀺ãã
</p>
<p>
ç¶ãè¡ã«ç·æ§åŽã®ãããã奜ããªäººã衚ãããŒã¿ã®æ°<var>L2</var>ãäžãããããç¶ãL2è¡ã«<var>c<sub>i</sub></var>ãš<var>d<sub>i</sub></var>ã空çœåºåãã§äžããããããããããID<var>c<sub>i</sub></var>ã®ç·æ§ãID<var>d<sub>i</sub></var>ã®å¥³æ§ãããããã奜ããã§ããããšã瀺ããæ¬¡ã«å¥³æ§åŽã®å€§å¥œããªäººã衚ãããŒã¿ã®æ°<var>L3</var>ãäžãããããç¶ãL3è¡ã«<var>e<sub>i</sub></var>ãš<var>f<sub>i</sub></var>ã空çœåºåãã§äžããããããããããID<var>e<sub>i</sub></var>ã®å¥³æ§ãIDã®<var>f<sub>i</sub></var>ã®ç·æ§ãã倧奜ããã§ããããšã瀺ãã
</p>
<p>
ç¶ãè¡ã«å¥³æ§åŽã®ãããã奜ããªäººã衚ãããŒã¿ã®æ°<var>L4</var>ãäžãããããç¶ãL4è¡ã«<var>g<sub>i</sub></var>ãš<var>h<sub>i</sub></var>ã空çœåºåãã§äžããããããããããID<var>g<sub>i</sub></var>ã®å¥³æ§ãID<var>h<sub>i</sub></var>ã®ç·æ§ãããããã奜ããã§ããããšã瀺ãã
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>1 ≤ <var>N</var>,<var>M</var> ≤ 100</li>
<li>0 ≤ <var>a<sub>i</sub></var>,<var>c<sub>i</sub></var>,<var>f<sub>i</sub></var>,<var>h<sub>i</sub></var> ≤ <var>N</var>−1</li>
<li>0 ≤ <var>b<sub>i</sub></var>,<var>d<sub>i</sub></var>,<var>e<sub>i</sub></var>,<var>g<sub>i</sub></var> ≤ <var>M</var>−1</li>
<li>0 ≤ <var>L1</var>,<var>L2</var>,<var>L3</var>,<var>L4</var> ≤ 2000</li>
<li><var>L1</var> > 0, <var>L2</var> > 0 ã«ãã㊠(<var>a<sub>i</sub></var>,<var>b<sub>i</sub></var>) â (<var>c<sub>j</sub></var>, <var>d<sub>j</sub></var>) ( 0 ≤ <var>i</var> < <var>L1</var>, 0 ≤ <var>j</var> < <var>L2</var> )</li>
<li><var>L3</var> > 0, <var>L4</var> > 0 ã«ãã㊠(<var>e<sub>i</sub></var>,<var>f<sub>i</sub></var>) â (<var>g<sub>j</sub></var>, <var>h<sub>j</sub></var>) ( 0 ≤ <var>i</var> < <var>L3</var>, 0 ≤ <var>j</var> < <var>L4</var> )</li>
<li> (<var>a<sub>i</sub></var>,<var>b<sub>i</sub></var>) â (<var>a<sub>j</sub></var>, <var>b<sub>j</sub></var>) ( <var>i</var> â <var>j</var> )ã( 0 ≤ <var>i</var> < <var>L1</var>, 0 ≤ <var>j</var> < <var>L1</var> )</li>
<li> (<var>c<sub>i</sub></var>,<var>d<sub>i</sub></var>) â (<var>c<sub>j</sub></var>, <var>d<sub>j</sub></var>) ( <var>i</var> â <var>j</var> )ã( 0 ≤ <var>i</var> < <var>L2</var>, 0 ≤ <var>j</var> < <var>L2</var> )</li>
<li> (<var>e<sub>i</sub></var>,<var>f<sub>i</sub></var>) â (<var>e<sub>j</sub></var>, <var>f<sub>j</sub></var>) ( <var>i</var> â <var>j</var> )ã( 0 ≤ <var>i</var> < <var>L3</var>, 0 ≤ <var>j</var> < <var>L3</var> )</li>
<li> (<var>g<sub>i</sub></var>,<var>h<sub>i</sub></var>) â (<var>g<sub>j</sub></var>, <var>h<sub>j</sub></var>) ( <var>i</var> â <var>j</var> )ã( 0 ≤ <var>i</var> < <var>L4</var>, 0 ≤ <var>j</var> < <var>L4</var> )</li>
</ul>
<h2>Output</h2>
<p>å顿ã®ã«ãŒã«ã«åŸã£ãŠã«ããã«ãæç«ããæã®ãã倧奜ããªäººãå士ã®ãã¢ã®æ°ãšã倧奜ããªäººããšããããã奜ããªäººãã®ãã¢ã®æ°ãšããããã奜ããå士ã®ãã¢ã®æ°ã空çœåºåãã§1è¡ã«åºåããã</p>
<h2>Sample Input 1</h2>
<pre>
3 3
3
0 0
1 1
2 2
2
1 0
2 1
3
1 1
2 2
0 1
2
1 0
2 0
</pre>
<h2>Sample Output 1</h2>
<pre>
2 0 0
</pre>
<p>
ãã®å Žåç·æ§1ãšå¥³æ§1ãç·æ§2ãšå¥³æ§2ã倧奜ãå士ã§ã«ããã«ãšãªãã倧奜ãå士ãã®ãã¢æ°ã2ã«ãªãã
ãããšãç·æ§0ã®ããšãã倧奜ãããªå¥³æ§ãããããã奜ãããªå¥³æ§ãããªããªã£ãŠããŸããŸãã
ãŸãã女æ§0ã®ããšãã倧奜ãããªç·æ§ãããããã奜ãããªç·æ§ãããªããªã£ãŠããŸããã以éã«ããã«ã¯æç«ããªããªããŸãã
</p>
<h2>Sample input 2</h2>
<pre>5 5
5
4 1
2 2
1 4
1 3
4 2
5
1 1
1 2
3 3
3 0
3 4
5
2 3
2 2
0 3
0 2
4 1
5
2 0
4 0
1 0
4 3
2 1
</pre>
<h2>Sample Output2</h2>
<pre>2 1 0</pre>
|
p01526 |
<h1>G - æ</h1>
<h2>å顿</h2>
<p>
ãã€ãã®ãããã¯ïŒäŒæã§ãšããå°ããªæã蚪ããŠããïŒåœŒå¥³ãé©ããã®ã¯ïŒãã®æã®è¡šæããã€æ§è³ªã§ããïŒ
</p>
<p>
æã«ã¯ <var>N</var> åã®å®¶å±ãããïŒããã§ã¯ç°¡åã®ããïŒæã¯ 2 次å
å¹³é¢ã§ãããšãïŒå®¶å±ã¯ãã®å¹³é¢äžã®ç¹ã§ãããšèŠãªãïŒ
ããããã®å®¶å±ã«ã¯è¡šæã 1 åèšããããŠããïŒãã®å®¶ã®èåã衚ããŠããïŒãããã¯æã®äžã蚪åããã«ã€ããŠïŒãã®æã®è¡šæã次ã®ãããªæ§è³ªãæã£ãŠããããšã«æ°ä»ããïŒ
</p>
<ul>
<li>ãã宿° <var>R</var> ãååšããïŒ</li>
<li>ãã 2 ã€ã®å®¶å±ã®è·é¢ã <var>R</var> 以äžã§ãããªãïŒãã® 2 ã€ã®å®¶å±ã¯åã衚æãæã€ïŒ</li>
<li>ãã 2 ã€ã®å®¶å±ã®è·é¢ã <var>3R</var> 以äžã§ãããªãïŒãã® 2 ã€ã®å®¶å±ã¯ç°ãªã衚æãæã€ïŒ</li>
<li>ä»»æã® 2 ã€ã®å®¶å±ã®è·é¢ã¯ <var>R</var> 以äžã§ããã <var>3R</var> 以äžã§ãããã®ã©ã¡ããã§ããïŒ</li>
</ul>
<p>
ããã§ïŒå®¶å±å士ã®è·é¢ã¯ïŒå¹³é¢äžã®ãŠãŒã¯ãªããè·é¢ã«ãã£ãŠèšæž¬ãããã®ãšããïŒ
</p>
<p>
ãããã¯ãã®æã«è¡šæãå
šéšã§äœçš®é¡ããã®ããæ°ã«ãªã£ããïŒãã®æã¯æå€ã«åºããšããããšã«æ°ä»ããã®ã§ïŒèšç®æ©ã䜿ã£ãŠãã®çããæš¡çŽ¢ããããšã«ããïŒ
</p>
<h2>å
¥å圢åŒ</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ
</p>
<pre><var>N</var> <var>R</var>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var>
<var>x<sub>2</sub></var> <var>y<sub>2</sub></var>
...
<var>x<sub>N</sub></var> <var>y<sub>N</sub></var>
</pre>
<p>
<var>N</var> ã¯å®¶å±ã®åæ°ã§ããïŒ<var>R</var> ã¯å®¶å±ã®é
眮ã®å¶çŽã«é¢ããå€ã§ããïŒ<var></var>
<var>(x<sub>i</sub>, y<sub>i</sub>)</var> ã¯å®¶å± <var>i</var> ã®åº§æšã衚ãïŒ
</p>
<h2>åºå圢åŒ</h2>
<p>
æã«ååšãã衚æã®çš®é¡ã®æ°ãæ±ããïŒ
</p>
<h2>å¶çŽ</h2>
<ul>
<li><var>1 ≤ N ≤ 2 × 10<sup>5</sup></var></li>
<li><var>1 ≤ R ≤ 10<sup>3</sup></li>
<li><var>|x<sub>i</sub>|, |y<sub>i</sub>| ≤ 10<sup>6</sup></var></li>
<li><var>N</var> ã¯æŽæ°ã§ããïŒ<var>R, x<sub>i</sub>, y<sub>i</sub></var> ã¯å®æ°ã§ïŒå°æ°ç¬¬ 3 äœãŸã§è¡šãããïŒ</li>
<li>ä»»æã® <var>1 ≤ i < j ≤ N</var> ã«å¯Ÿã㊠<var>d<sub>ij</sub> = √{(x<sub>i</sub> - x<sub>j</sub>)<sup>2</sup> + (y<sub>i</sub> - y<sub>j</sub>)<sup>2</sup>}</var> ãšãããšãïŒ<var>d<sub>ij</sub> ≤ R</var> ã <var>3R ≤ d<sub>ij</sub></var> ã®ã©ã¡ãããæºããããïŒ</li>
</ul>
<p>ãã®åé¡ã®å€å®ã«ã¯ïŒ15 ç¹åã®ãã¹ãã±ãŒã¹ã®ã°ã«ãŒããèšå®ãããŠããïŒ ãã®ã°ã«ãŒãã«å«ãŸãããã¹ãã±ãŒã¹ã¯äžèšã®å¶çŽã«å ããŠäžèšã®å¶çŽãæºããïŒ</p>
<ul>
<li>çã㯠10 以äžã§ããïŒ</li>
</ul>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
5 3.000
1.000 0.000
0.000 0.000
-1.000 0.000
10.000 0.000
-10.000 0.000
</pre>
<h3>åºåäŸ 1</h3>
<pre>
3
</pre>
<p>
å®¶å± 1,2,3 ãšå®¶å± 4 ãšå®¶å± 5 ã§è¡šæãç°ãªãïŒå
šäœã§ 3 ã€ã®è¡šæãååšããïŒ
</p>
<h3>å
¥åäŸ 2</h3>
<pre>
12 1.234
0.500 0.000
-0.500 0.000
0.000 0.000
0.000 -0.500
55.500 55.000
-55.500 55.000
55.000 55.000
55.000 -55.500
99.500 99.000
-99.500 99.000
99.000 99.000
99.000 -99.500
</pre>
<h3>åºåäŸ 2</h3>
<pre>
7
</pre>
<h3>å
¥åäŸ 3</h3>
<pre>
5 99.999
0.000 0.000
49.999 0.001
0.000 0.000
-49.999 -0.001
0.000 0.000
</pre>
<h3>åºåäŸ 3</h3>
<pre>
1
</pre>
<hr>
<address>Writer: æ¥ æ¬å
</address>
<address>Tester: å°æµç¿å€ªé</address> |
p01176 |
<H1><font color="#000">Problem F:</font> Controlled Tournament</H1>
<p>
National Association of Tennis is planning to hold a tennis competition among professional
players. The competition is going to be a knockout tournament, and you are assigned the task
to make the arrangement of players in the tournament.
</p>
<p>
You are given the detailed report about all participants of the competition. The report contains
the results of recent matches between all pairs of the participants. Examining the data, youâve
noticed that it is only up to the opponent whether one player wins or not.
</p>
<p>
Since one of your special friends are attending the competition, you want him to get the best
prize. So you want to know the possibility where he wins the gold medal. However it is not so
easy to figure out because there are many participants. You have decided to write a program
which calculates the number of possible arrangements of tournament in which your friend wins
the gold medal.
</p>
<p>
In order to make your trick hidden from everyone, you need to avoid making a factitive tourna-
ment tree. So you have to minimize the height of your tournament tree.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset has the format as described below.
</p>
<pre>
<i>N M</i>
<i>R</i><sub>11</sub> <i>R</i><sub>12</sub> . . . <i>R</i><sub>1<i>N</i></sub>
<i>R</i><sub>21</sub> <i>R</i><sub>22</sub> . . . <i>R</i><sub>2<i>N</i></sub>
...
<i>R</i><sub><i>N</i>1</sub> <i>R</i><sub><i>N</i>2</sub> . . . <i>R</i><sub><i>NN</i></sub>
</pre>
<p>
<i>N</i> (2 ≤ <i>N</i> ≤ 16) is the number of player, and <i>M</i> (1 ≤ <i>M</i> ≤ <i>N</i>) is your friendâs ID (numbered
from 1). <i>R<sub>ij</sub></i> is the result of a match between the <i>i</i>-th player and the <i>j</i>-th player. When <i>i</i>-th
player always wins, <i>R<sub>ij</sub></i> = 1. Otherwise, <i>R<sub>ij</sub></i> = 0. It is guaranteed that the matrix is consistent:
for all <i>i</i> ≠ <i>j</i>, <i>R<sub>ij</sub></i> = 0 if and only if <i>R<sub>ji</sub></i> = 1. The diagonal elements <i>R<sub>ii</sub></i> are just given for
convenience and are always 0.
</p>
<p>
The end of input is indicated by a line containing two zeros. This line is not a part of any
datasets and should not be processed.
</p>
<H2>Output</H2>
<p>
For each dataset, your program should output in a line the number of possible tournaments in
which your friend wins the first prize.
</p>
<H2>Sample Input</H2>
<pre>
2 1
0 1
0 0
2 1
0 0
1 0
3 3
0 1 1
0 0 1
0 0 0
3 3
0 1 0
0 0 0
1 1 0
3 1
0 1 0
0 0 0
1 1 0
3 3
0 1 0
0 0 1
1 0 0
6 4
0 0 0 0 0 1
1 0 1 0 1 0
1 0 0 1 1 0
1 1 0 0 1 0
1 0 0 0 0 0
0 1 1 1 1 0
7 2
0 1 0 0 0 1 0
0 0 1 0 1 1 1
1 0 0 1 1 0 0
1 1 0 0 0 1 0
1 0 0 1 0 0 1
0 0 1 0 1 0 0
1 0 1 1 0 1 0
8 6
0 0 0 0 1 0 0 0
1 0 1 1 0 0 0 0
1 0 0 0 1 0 0 0
1 0 1 0 0 1 0 1
0 1 0 1 0 0 1 0
1 1 1 0 1 0 0 1
1 1 1 1 0 1 0 0
1 1 1 0 1 0 1 0
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1
0
0
3
0
1
11
139
78
</pre>
|
p00337 |
<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>
<p>
ãããšãããã¹ãŠã®éèœãäžã€ã®æã«ãŸãšãŸãããšã決ãŸããæãå²ãå¢çç·ãåŒãããšã«ãªããŸãããåœã®æ±ºãŸãã§ã¯ãæãæ§æããã©ã®ïŒã€ã®éèœãçµãã ãŸã£ãããªç·ããæã®å€ãéã£ãŠã¯ãããŸããïŒå¢çç·äžãéãããšã¯èš±ãããŸãïŒãããã«ãäŒæŽ¥åœã§ã¯æãå²ãå¢çç·äžã«éããªããã°ãªããŸãããå¢çç·äžã«éããªãå Žæã«ã¯ãåœãæ°ãã«éãäœã£ãŠãããŸãã
</p>
<p>
ããããéã®ç¶æè²»ã¯æãæ¯æãã®ã§ãæäººéã¯å¢çç·ãã§ããã ãçãããããšèããŠããŸããããã«ãæäººéã¯ãã¹ãŠã®éèœã®éãè¡ãæ¥ã§ããç¶æ
ãç¶æãã€ã€ãå¢çç·äžã«ãªãéã廿¢ããããšã§ãéã®é·ãã®åèšãæå°ã«ããããšã«ããŸããã
</p>
<p>
éèœã®äœçœ®ãšå
ã
ãã£ãéã®æ
å ±ãäžãããããå¢çç·äžã«éã眮ãããã€ããã¹ãŠã®éèœãè¡ãæ¥ã§ããããã«ããå Žåã®ãéã®é·ãã®åèšã®æå°å€ãèšç®ããããã°ã©ã ãäœæããããã ããéèœã¯å€§ããã®ãªãç¹ãéã¯å¹
ã®ãªãç·åãšããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>V</var> <var>R</var>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var>
<var>x<sub>2</sub></var> <var>y<sub>2</sub></var>
:
<var>x<sub>V</sub></var> <var>y<sub>V</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<sub>R</sub></var> <var>t<sub>R</sub></var>
</pre>
<p>
ïŒè¡ç®ã«éèœã®æ° <var>V</var> (3 ≤ <var>V</var> ≤ 100) ãšéã®æ° <var>R</var> (2 ≤ <var>R</var> ≤ 1000) ãäžããããã
</p>
<p>
ç¶ã <var>V</var> è¡ã«éèœã衚ãç¹ã®æ
å ±ãäžãããããåè¡ã«äžããããïŒã€ã®æŽæ° <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> (-1000 ≤ <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> ≤ 1000)ã¯ããããã <var>i</var> çªç®ã®éèœã® <var>x</var> 座æšã<var>y</var>座æšã衚ãã
</p>
<p>
ç¶ã <var>R</var> è¡ã«å
ã
ãã£ãéã®æ
å ±ãäžãããããåè¡ã«äžããããïŒã€ã®æŽæ° <var>s<sub>i</sub></var>, <var>t<sub>i</sub></var> (1 ≤ <var>s<sub>i</sub></var> < <var>t<sub>i</sub></var> ≤ <var>V</var>)ã¯ã<var>i</var> çªç®ã®éã <var>s<sub>i</sub></var> çªç®ã®éèœãš <var>t<sub>i</sub></var> çªç®ã®éèœãã€ãªãã§ããããšã衚ãã
</p>
<p>
å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã
</p>
<ul>
<li> <var>i</var> ≠ <var>j</var> ãªãã°ã<var>i</var> çªç®ã®éèœãš <var>j</var> çªç®ã®éèœã®åº§æšã¯ç°ãªãã</li>
<li> ã©ã®ïŒã€ã®éèœã«ã€ããŠããããããçŽæ¥çµã¶éã¯é«ã
ïŒã€ããçŸããªãã</li>
<li>ïŒã€ã®ç°ãªãéã端ç¹ä»¥å€ã®ç¹ãå
±æããããšã¯ãªãã</li>
<li> ïŒã€ä»¥äžã®éèœãåäžçŽç·äžã«äžŠãã§ããããšã¯ãªãã </li>
</ul>
<h2>Output</h2>
<p>
æ¡ä»¶ãæºããéã®é·ãã®åèšã®æå°å€ãïŒè¡ã«å®æ°ã§åºåããããã ãã誀差ããã©ã¹ãã€ãã¹ 0.001 ãè¶
ããŠã¯ãªããªãããã®æ¡ä»¶ãæºããã°å°æ°ç¹ä»¥äžäœæ¡è¡šç€ºããŠãããã
</p>
<h2>Sample Input 1</h2>
<pre>
5 5
0 0
1 1
3 0
3 2
0 2
1 2
2 3
2 4
3 4
1 5
</pre>
<h2>Sample Output 1</h2>
<pre>
11.4142
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
7 6
0 2
3 0
2 2
1 0
4 1
2 3
3 5
1 3
2 4
2 3
3 5
3 7
6 7
</pre>
<h2>Sample Output 2</h2>
<pre>
18.2521
</pre> |
p03848 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> people, conveniently numbered <var>1</var> through <var>N</var>.
They were standing in a row yesterday, but now they are unsure of the order in which they were standing.
However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person.
According to their reports, the difference above for person <var>i</var> is <var>A_i</var>.</p>
<p>Based on these reports, find the number of the possible orders in which they were standing.
Since it can be extremely large, print the answer modulo <var>10^9+7</var>.
Note that the reports may be incorrect and thus there may be no consistent order.
In such a case, print <var>0</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1âŠNâŠ10^5</var></li>
<li><var>0âŠA_iâŠN-1</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the possible orders in which they were standing, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
2 4 4 0 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>There are four possible orders, as follows:</p>
<ul>
<li><var>2,1,4,5,3</var></li>
<li><var>2,5,4,1,3</var></li>
<li><var>3,1,4,5,2</var></li>
<li><var>3,5,4,1,2</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7
6 4 0 2 4 0 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>Any order would be inconsistent with the reports, thus the answer is <var>0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8
7 5 1 1 7 3 5 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>16
</pre></section>
</div>
</span> |
p01875 |
<h2>D: Complex Oracle - Complex Oracle -</h2>
<h3>åé¡</h3>
<p>
â»ãã®åé¡ã¯ãªã¢ã¯ãã£ãåé¡ã§ãïŒããªãã¡ïŒãµãŒããŒåŽã«çšæãããããã°ã©ã ãšå¯Ÿè©±çã«å¿çããããšã§æ£çãå°ãããã°ã©ã ãäœæããå¿
èŠããããŸãïŒ
ãŸãããµãŒããŒåŽã®ããã°ã©ã ãèšç®æ©è³æºãå
±æããé¢ä¿äžããµãŒããŒã ãã§æå€§ 3 secçšåºŠã®å®è¡æéãæå€§ 300 MBçšåºŠã®ã¡ã¢ãªã䜿çšããå ŽåããããŸãã®ã§ãTLEã»MLEã«ãæ°ãã€ããã ããã
</p>
<p>ãããã«ããã¯è¥ã¶æŸé«æ ¡ã®ããã°ã©ãã³ã°ã³ã³ãã¹ãéšãéç§°ã·ãããéšã«æå±ãã2幎çã§ãããèŠç®éºããããããã«ããã¯ãã®å°ããªäœãç¡éã«ååšãããã£ãŒã ãã€ã³ãã®1ã€ã§ããããæ¬äººã¯ã³ã³ãã¬ãã¯ã¹ãæããŠããããã ããã®ããããäžåã«äžŠãã§ãã人ãã¡ãèŠããšãããããã®äººã®åæ¹ã«ãã®äººãã身é·ãé«ã人ãäœäººäžŠãã§ããããç¬æã«æ°ããããèœåãæã£ãŠããã</p>
<p>ããã³ã³ã®åéã»åŸåœé€šå€§åŠäžçéšåã®ãšãªãŒãç«¶æããã°ã©ãã§ãããã·ãããéšã®éšé·ã§ãããã£ã€ã¡ããã¯ããããã«ããã®ãã®èœåã䜿ãã°ã䞊ãã§ãã人ãã¡ãããããäœçªç®ã«èãé«ãã®ããåœãŠãããšãã§ããã®ã§ã¯ãªãããšèããã</p>
<p>ä»ããã£ã€ã¡ããã¯<var>N</var>人ã䞊ãã§ããåããããã«ããã«èŠããŠããããã£ã€ã¡ããã¯ã人ã<var>N</var>人䞊ãã§ããããšã¯ç¥ã£ãŠãããããã®äžŠã³é ãã©ããªã£ãŠãããã¯ããããªãããã£ã€ã¡ããã¯ãããã«ããã« â<var>l</var>çªç®ã®äººãã<var>r</var>çªç®ã®äººãŸã§ã³ã³ãã¬ãã¯ã¹åºŠâ ãæããŠãããããšãã§ãããããã§ã<var>l</var>çªç®ã®äººãã<var>r</var>çªç®ã®äººãŸã§ã®ã³ã³ãã¬ãã¯ã¹åºŠãšã¯ã<var>i</var> (<var>l \≤ i \≤ r</var>) çªç®ã®äººããããã«é¢ããŠã<var>l</var>çªç®ãã<var>i − 1</var>çªç®ãŸã§ã®éã«ããèªå (<var>i</var>) ããèãé«ã人ã®äººæ°ã®ç·åã§ããã(ããå³å¯ãªå®çŸ©ã¯å
¥åºå圢åŒãåç
§ã®ããš)</p>
<p>(ããããŸããããšã«) ã·ãããéšã®éšå¡ã§ããããªãã¯ã(ãšãŠãããšãŠãå¿èŠããã) ãããã«ããããªã©ã¯ã«ãšããŠå©çšããããšã§èº«é·é ãåœãŠãããã°ã©ã ãæžããããã£ã€ã¡ããã«åœãããããã€ããããããŠãããã«ããã«è² æ
ããããªããããå°ãªã質ååæ°ã§æ±ããããããé 匵ããã</p>
<h3>å
¥ååºå圢åŒ</h3>
<p>ãµãŒããŒã¯èã®é ã衚ãé·ã<var>N</var>ã®æ°å<var>p</var>ãä¿æããŠãããããã¯å
¥åãšããŠäžããããªãã<var>p</var>ã®åèŠçŽ <var>p_i</var>ã¯<var>1</var>以äž<var>N</var>以äžã§ãããããããå€ã¯ç°ãªãã<var>p_i</var>ã倧ããå€ãæã€æ¹ãèãé«ãããšã衚ãã</p>
<p>ãµãŒããŒã¯ãŸãã<var>p</var>ã®é·ã<var>N</var>ã衚ã<var>1</var>ã€ã®æŽæ°ãããªã<var>1</var>è¡ãå
¥åãšããŠè§£çããã°ã©ã ã«äžããã</p>
<p>次ã«è§£çããã°ã©ã ã<var>2</var>ã€ã®æŽæ° <var>l, r</var> (<var>1 \≤ l \≤ r \≤ N</var>) ãããªãã¯ãšãªããµãŒããŒã«éããã¯ãšãªã®åºå圢åŒã¯</p>
<pre>? <var>l</var> <var>r</var></pre>
<p>ã§ãããããã¯äŸãã°C/C++ã ãšã</p>
<pre>printf("? %d %d\n", l, r); fflush(stdout);</pre>
<p>ãªã©ãšæžãã°ãããåºåã®åºŠã«ãã©ãã·ã¥ããããšãæšå¥šããã</p>
<p>ãããšããµãŒããŒåŽã¯ä»¥äžã®å€ã衚ã<var>1</var>ã€ã®æŽæ°<var>C</var>ãããªã1è¡ãå
¥åãšããŠè§£çããã°ã©ã ã«äžããã</p>
<pre><var>C = (\{ (i, j) | p_i > p_j</var> <var>{\rm for}</var> <var>l \≤ i<j \≤ r \}ã®èŠçŽ æ°)</var></pre>
<p>ãã ããã¯ãšãªãšããŠæ£ãããªã<var>l, r</var> (<var>l, r</var>ã<var>1</var>以äž<var>N</var>以äžã®æ°ã§ã¯ãªãããŸãã¯<var>l>r</var>ã§ãã) ãäžããããå ŽåããµãŒããŒã¯<var>−1</var>ã<var>C</var>ãšããŠè¿ãã</p>
<p>ãã®å¿çãäœåºŠãç¹°ãè¿ããè§£çããã°ã©ã ã<var>p</var>ãæšå®ã§ãããªãã°ã<var>p</var>ã以äžã®åœ¢åŒã§åºåããã</p>
<pre>! <var>p_1</var> ... <var>p_N</var></pre>
<p>æšå®ããé åã®åºåã¯1床ããã§ããããã®åºåã<var>p</var>ãšç°ãªãå Žåã誀çãšãªãã200,000å以å
ã®ã¯ãšãªã§æ£ãã<var>p</var>ãåºåã§ããå Žåãæ£çãšãªãã</p>
<p>åã¯ãšãªã§æ¹è¡ãè¡ãããæ°ãã€ããããšã</p>
<h3>å
¥åå¶çŽ</h3>
<ul>
<li><var>1 \≤ N \≤ 100,000</var></li>
<li>æšå®ãããé·ã<var>N</var>ã®æ°å<var>p</var>ã¯é åãããªãã¡ã<var>p_i \in \{1, </var> ... <var>, N\}</var> <var>{\rm for}</var> <var>1 \≤ i \≤ N</var>ãããã³<var>p_i \neq p_j</var> <var>{\rm for}</var> <var>1 \≤ i < j \≤ N</var> ãæºãã</li>
<li>ãµãŒããŒãžã®ã¯ãšãªåæ°ã¯200,000åãŸã§</li>
<li>ãµãŒããŒããè¿çããã<var>C</var>ã¯32bitæŽæ°åã§ã¯åãŸããªã倧ããã«ãªãããããšã«æ³šæãã</li>
</ul>
<h3>å
¥ååºåäŸ</h3>
<pre>
<table width="600" class="withborder"><tbody>
<tr><th>ãµãŒããŒã®åºå </th><th> ãµãŒããŒãžã®å
¥å</th></tr>
<tr><td>4 </td><td> </td></tr>
<tr><td> </td><td> ? 1 3 </td></tr>
<tr><td> 2 </td><td> </td></tr>
<tr><td> </td><td> ? 2 4 </td></tr>
<tr><td> 1 </td><td> </td></tr>
<tr><td> ... </td><td> ... </td></tr>
<tr><td> </td><td> ! 4 1 3 2 </td></tr>
</tbody></table>
</pre> |
p00767 |
<h3>Integral Rectangles</h3>
<p>
Let us consider rectangles whose height, <i>h</i>, and
width, <i>w</i>, are both integers. We call such rectangles <em>
integral rectangles</em>. In this problem, we consider only wide
integral rectangles, i.e., those with <i>w</i> > <i>h</i>.
</p>
<p>
We define the following ordering of wide integral rectangles. Given
two wide integral rectangles,
</p>
<ol>
<li>
The one shorter in its diagonal line is smaller, and
</li>
<li>
If the two have diagonal lines with the same length, the one shorter
in its height is smaller.
</li>
</ol>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_integralRectangles-en">
</center>
<p>
Given a wide integral rectangle, find the smallest wide integral
rectangle bigger than the given one.
</p>
<h3>Input</h3>
<p>The entire input consists of multiple datasets. The number of
datasets is no more than 100. Each dataset describes a wide integral
rectangle by specifying its height and width, namely <i>h</i>
and <i>w</i>, separated by a space in a line, as follows.
</p>
<blockquote>
<i>h</i> <i>w</i>
</blockquote>
<p>
For each dataset, <i>h</i> and <i>w</i> (><i>h</i>) are both
integers greater than 0 and no more than 100.
</p>
<p>
The end of the input is indicated by a line of two zeros separated by a space.
</p>
<h3>Output</h3>
<p>
For each dataset, print in a line two numbers describing the
height and width, namely <i>h</i> and <i>w</i> (> <i>h</i>), of the
smallest wide integral rectangle bigger than the one described in the
dataset. Put a space between the numbers. No other
characters are allowed in the output.
</p>
<p>
For any wide integral rectangle given in the input, the width and
height of the smallest wide integral rectangle bigger than the given
one are both known to be not greater than 150.
</p>
<p>
In addition, although
the ordering of wide integral rectangles uses the comparison of
lengths of diagonal lines, this comparison can be replaced with that
of squares (self-products) of lengths of diagonal lines, which can
avoid unnecessary troubles possibly caused by the use of floating-point
numbers.
</p>
<h3>Sample Input</h3>
<pre>
1 2
1 3
2 3
1 4
2 4
5 6
1 8
4 7
98 100
99 100
0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
1 3
2 3
1 4
2 4
3 4
1 8
4 7
2 8
3 140
89 109
</pre>
|
p02074 | <style type="text/css">
blockquote {
font-family: Menlo, Monaco, "Courier New", monospace;
display: block;
margin: 10px 0 10px 30px;
font-size: 16px;
line-height: 18px;
white-space: pre;
white-space: pre-wrap;
word-break: break-all;
word-wrap: break-word;
}
table.ioexample {
width: 100%;
border-collapse: collapse;
}
table.ioexample td {
width: 50%;
border: 1px solid rgba(0, 0, 0, 0.15);
vertical-align: top;
padding: 5px;
}
.no-page-break {
page-break-inside: avoid;
}
.page-break {
page-break-before: always;
}
</style>
<h3>Problem Statement</h3>
<p>Have you experienced $10$-by-$10$ grid calculation? It's a mathematical exercise common in Japan. In this problem, we consider the generalization of the exercise, $N$-by-$M$ grid calculation.</p>
<p>In this exercise, you are given an $N$-by-$M$ grid (i.e. a grid with $N$ rows and $M$ columns) with an additional column and row at the top and the left of the grid, respectively. Each cell of the additional column and row has a positive integer. Let's denote the sequence of integers on the column and row by $a$ and $b$, and the $i$-th integer from the top in the column is $a_i$ and the $j$-th integer from the left in the row is $b_j$, respectively.</p>
<p>Initially, each cell in the grid (other than the additional column and row) is blank. Let $(i, j)$ be the cell at the $i$-th from the top and the $j$-th from the left. The exercise expects you to fill all the cells so that the cell $(i, j)$ has $a_i \times b_j$. You have to start at the top-left cell. You repeat to calculate the multiplication $a_i \times b_j$ for a current cell $(i, j)$, and then move from left to right until you reach the rightmost cell, then move to the leftmost cell of the next row below.</p>
<p>At the end of the exercise, you will write a lot, really a lot of digits on the cells. Your teacher, who gave this exercise to you, looks like bothering to check entire cells on the grid to confirm that you have done this exercise. So the teacher thinks it is OK if you can answer the $d$-th <strong><em>digit</em></strong> (not <strong><em>integer</em></strong>, see an example below), you have written for randomly chosen $x$. Let's see an example.</p>
<p><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/JAGSummer19Day1_H_nmgrid_001.png" width="400pt"></center></p>
<p>For this example, you calculate values on cells, which are $8$, $56$, $24$, $1$, $7$, $3$ in order. Thus, you would write digits 8, 5, 6, 2, 4, 1, 7, 3. So the answer to a question $4$ is $2$.</p>
<p>You noticed that you can answer such questions even if you haven't completed the given exercise. Given a column $a$, a row $b$, and $Q$ integers $d_1, d_2, \dots, d_Q$, your task is to answer the $d_k$-th digit you would write if you had completed this exercise on the given grid for each $k$. Note that your teacher is not so kind (unfortunately), so may ask you numbers greater than you would write. For such questions, you should answer 'x' instead of a digit. </p>
<hr />
<h3>Input</h3>
<p>The input consists of a single test case formatted as follows. </p>
<blockquote>$N$ $M$
$a_1$ $\ldots$ $a_N$
$b_1$ $\ldots$ $b_M$
$Q$
$d_1$ $\ldots$ $d_Q$</blockquote>
<p>The first line contains two integers $N$ ($1 \le N \le 10^5$) and $M$ ($1 \le M \le 10^5$), which are the number of rows and columns of the grid, respectively.</p>
<p>The second line represents a sequence $a$ of $N$ integers, the $i$-th of which is the integer at the $i$-th from the top of the additional column on the left. It holds $1 \le a_i \le 10^9$ for $1 \le i \le N$.</p>
<p>The third line represents a sequence $b$ of $M$ integers, the $j$-th of which is the integer at the $j$-th from the left of the additional row on the top. It holds $1 \le b_j \le 10^9$ for $1 \le j \le M$.</p>
<p>The fourth line contains an integer $Q$ ($1 \le Q \le 3\times 10^5$), which is the number of questions your teacher would ask.</p>
<p>The fifth line contains a sequence $d$ of $Q$ integers, the $k$-th of which is the $k$-th question from the teacher, and it means you should answer the $d_k$-th digit you would write in this exercise. It holds $1 \le d_k \le 10^{15}$ for $1 \le k \le Q$.</p>
<h3>Output</h3>
<p>Output a string with $Q$ characters, the $k$-th of which is the answer to the $k$-th question in one line, where the answer to $k$-th question is the $d_k$-th digit you would write if $d_k$ is no more than the number of digits you would write, otherwise 'x'.</p>
<p><div class="no-page-break"><h3>Examples</h3><table class="ioexample"><tr><th>Input</th><th>Output</th></tr><tr><td><pre>2 3
8 1
1 7 3
5
1 2 8 9 1000000000000000
</pre></td><td><pre>853xx
</pre></td></tr><tr><td><pre>3 4
271 828 18
2845 90 45235 3
7
30 71 8 61 28 90 42
</pre></td><td><pre>7x406x0
</pre></td></tr></table></div></p>
|
p00049 |
<H1>è¡æ¶²å</H1>
<p>
ããåŠçŽã®çåŸã®åºåžçªå·ãš ABO è¡æ¶²åãä¿åããããŒã¿ãèªã¿èŸŒãã§ããã®ãã®ã®è¡æ¶²åã®äººæ°ãåºåããããã°ã©ã ãäœæããŠãã ããããªããABO è¡æ¶²åã«ã¯ãA åãB åãAB åãO åã®ïŒçš®é¡ã®è¡æ¶²åããããŸãã
</p>
<H2>Input</H2>
<p>
ã«ã³ãã§åºåãããåºåžçªå·ãšè¡æ¶²åã®çµããè€æ°è¡ã«æž¡ã£ãŠäžããããŸããåºåžçªå·ã¯ 1 ä»¥äž 50 以äžã®æŽæ°ãè¡æ¶²åã¯æåå "A", "B", "AB" ãŸã㯠"O" ã®ããããã§ããçåŸã®äººæ°ã¯ 50 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ïŒè¡ç®ã« A åã®äººæ°<br/>
ïŒè¡ç®ã« B åã®äººæ°<br/>
ïŒè¡ç®ã« AB åã®äººæ°<br/>
ïŒè¡ç®ã« O åã®äººæ°<br/>
ãåºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
1,B
2,A
3,B
4,AB
5,B
6,O
7,A
8,O
9,AB
10,A
11,A
12,B
13,AB
14,A
</pre>
<H2>Output for the Sample Input</H2>
<pre>
5
4
3
2
</pre>
|
p02424 | <h1>Bit Operation II</h1>
<p>
Given two non-negative decimal integers $a$ and $b$, calculate their AND (logical conjunction), OR (logical disjunction) and XOR (exclusive disjunction) and print them in binary representation of 32 bits.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$a \; b$
</pre>
<h2>Output</h2>
<p>
Print results of AND, OR and XOR in a line respectively.
</p>
<h2>Constraints</h2>
<ul>
<li>$0 \leq a, b \leq 2^{32} - 1$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
8 10
</pre>
<h2>Sample Output 1</h2>
<pre>
00000000000000000000000000001000
00000000000000000000000000001010
00000000000000000000000000000010
</pre>
|
p00419 | <h1>å±±ãžåž°ãã</h1>
<p>ã
è¿å¹Žã€ãºã¢åœã§ã¯ãå±±ããè¡ã«éããŠããåç©ã«æ©ãŸãããŠãããããªãã¯åç©ãå±±ãžåž°ãããšç ç©¶ãéãã以äžã®ããšãæããã«ããã
</p>
<ul>
<li> ããããã®åç©ã«ã¯åºæã®ååãã€ããŠããã</li>
<li> ïŒäœã®åç©ã«ã€ããŠãäžæ¹ã®åç©ã®ååã®ã©ããã®äœçœ®ã«ïŒæåãæ¿å
¥ãããšãããäžæ¹ã®åç©ã®ååãšäžèŽããå Žåããããããã¢ã«ããŠå±±ãžåž°ãããšãã§ããã</li>
<li> äžåºŠå±±ãžåž°ã£ãåç©ããåã³è¡ã«éããŠããããšã¯ãªãã</li>
</ul>
<p>
ããªãã¯ãè¡ã«éããŠããåç©ãããã®æ¹æ³ã§ã©ã®ãããå±±ãžåž°ãããšãã§ããããèšç®ããããšã«ããã
</p>
<p>
è¡ã«éããŠããåç©ã®ååãäžãããããšãããã®æ¹æ³ã§æå€§ããã€ã®ãã¢ãå±±ãžåž°ãããšãã§ããããæ±ããããã°ã©ã ãäœæããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
$N$
$str_1$
$str_2$
:
$str_N$
</pre>
<p>
ïŒè¡ç®ã«åç©ã®æ°$N$ ($2 \leq N \leq 100,000$)ãäžãããããç¶ã$N$è¡ã«$i$çªç®ã®åç©ã®ååã衚ãæåå$str_i$ãäžããããããã ã$str_i$ã¯è±å°æåãšè±å€§æåã§æ§æããã10æå以äžã®æååã§ããããŸãããã¹ãŠã®åç©ã®ååã¯ç°ãªã($i \ne j$ãªã$str_i \ne str_j$)ã
</p>
<h2>åºå</h2>
<p>
å±±ãžåž°ãããšãã§ããåç©ã®ãã¢ã®æ°ã®æå€§å€ãåºåããã
â</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸïŒ</h3>
<pre>
4
aedb
aeb
ebCd
cdE
</pre>
<h3>åºåäŸïŒ</h3>
<pre>
1
</pre>
<h3>å
¥åäŸïŒ</h3>
<pre>
4
bcD
bD
AbD
bc
</pre>
<h3>åºåäŸïŒ</h3>
<pre>
2
</pre>
â
|
p01658 |
<h2>C - ãã§ã³ã¬ãŒã</h2>
<p>
ç®ã®åã« <var>M \times N</var> åã®ããŒã¹ã§ã§ããæ¿ãã§ã³ãããïŒ
ããŒã¹ã«ã¯çãããŒã¹ãšèŸãããŒã¹ã®2çš®é¡ãããïŒã§ããã ãå€ãã®çãããŒã¹ãé£ã¹ããïŒ
</p>
<p>
ãããïŒæ¿ãã§ã³ã®é£ã¹æ¹ã«ã¯ã«ãŒã«ãããïŒä»¥äžã®ã«ãŒã«ãå®ããªããã°ãªããªãïŒ
</p>
<ul>
<li> ããããŒã¹ãé£ã¹ãããã«ã¯ïŒãã®ããŒã¹ã®çäžã«é£æ¥ããããŒã¹ãååšããïŒå ããŠãã®ããŒã¹ã®å°ãªããšãå·Šå³ã©ã¡ããã«ã¯ããŒã¹ãååšããªãå¿
èŠãããïŒ </li>
</ul>
<p>
äŸãã°ïŒå³ã®ãããªåœ¢ã®ãã§ã³ã¬ãŒãã§ã¯ïŒèµ€ãè²ä»ããããããŒã¹ã次ã«é£ã¹ãããšãã§ããïŒ
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_KUPC2013_chocolate"></img>
</center>
<br/>
<p>
ãŸãå¥åŠãªããšã«ïŒããããŒã¹ãé£ã¹ããšãã®ããŒã¹ã®äžäžå·Šå³ã«é£æ¥ããŠããŠãã€ãŸã é£ã¹ãããŠããªãããŒã¹ã®å³ãå€åããïŒ (çãããŒã¹ã¯èŸãïŒèŸãããŒã¹ã¯çããªã£ãŠããŸã)
</p>
<p>
äžæããã§ã³ã¬ãŒããé£ã¹ããšæå€§ã§ããã€ã®çãããŒã¹ãé£ã¹ãããšãã§ããã ããã?
</p>
<div class="io-style">
<h2>å
¥å圢åŒ</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ</p>
<pre>
<var>M</var> <var>N</var>
<var>a_{11}</var> ⊠<var>a_{1N}</var>
<var>a_{21}</var> ⊠<var>a_{2N}</var>
:
<var>a_{M1}</var> ⊠<var>a_{MN}</var>
</pre>
<p>
<var>a_{ij} = 0</var> ã®ãšãäžããiçªç®ïŒå·Šããjçªç®ã®ããŒã¹ãèŸãïŒ
<var>a_{ij} = 1</var> ã®ãšãäžããiçªç®ïŒå·Šããjçªç®ã®ããŒã¹ãçãããšã衚ãããŠããïŒ
</p>
<h2>åºå圢åŒ</h2>
<p>
é£ã¹ãããšã®ã§ããçãããŒã¹ã®åæ°ã®æå€§å€ãäžè¡ã«åºåããïŒ
</p>
<h2>å¶çŽ</h2>
<ul>
<li><var>1 \leq NïŒM \leq 100</var></li>
<li><var>0 \leq a_{ij} \leq 1</var></li>
<li>å
¥åå€ã¯ãã¹ãп޿°ã§ããïŒ</li>
</ul>
</div>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ1</h3>
<pre>
2 3
1 1 1
1 1 1
</pre>
<h3>åºåäŸ1</h3>
<pre>
5
</pre>
<h3>å
¥åäŸ2</h3>
<pre>
4 2
1 0
0 1
0 1
0 1
</pre>
<h3>åºåäŸ2</h3>
<pre>
8
</pre> |
p03665 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> bags of biscuits. The <var>i</var>-th bag contains <var>A_i</var> biscuits.</p>
<p>Takaki will select some of these bags and eat all of the biscuits inside.
Here, it is also possible to select all or none of the bags.</p>
<p>He would like to select bags so that the total number of biscuits inside is congruent to <var>P</var> modulo <var>2</var>.
How many such ways to select bags there are?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 50</var></li>
<li><var>P = 0</var> or <var>1</var></li>
<li><var>1 \leq A_i \leq 100</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>P</var>
<var>A_1</var> <var>A_2</var> ... <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways to select bags so that the total number of biscuits inside is congruent to <var>P</var> modulo <var>2</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 0
1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>There are two ways to select bags so that the total number of biscuits inside is congruent to <var>0</var> modulo <var>2</var>:</p>
<ul>
<li>Select neither bag. The total number of biscuits is <var>0</var>.</li>
<li>Select both bags. The total number of biscuits is <var>4</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 1
50
</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>3 0
1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
</pre>
<p>Two bags are distinguished even if they contain the same number of biscuits.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>45 1
17 55 85 55 74 20 90 67 40 70 39 89 91 50 16 24 14 43 24 66 25 9 89 71 41 16 53 13 61 15 85 72 62 67 42 26 36 66 4 87 59 91 4 25 26
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>17592186044416
</pre></section>
</div>
</span> |
p02977 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer <var>N</var>. Determine if there exists a tree with <var>2N</var> vertices numbered <var>1</var> to <var>2N</var> satisfying the following condition, and show one such tree if the answer is yes.</p>
<ul>
<li>Assume that, for each integer <var>i</var> between <var>1</var> and <var>N</var> (inclusive), Vertex <var>i</var> and <var>N+i</var> have the weight <var>i</var>. Then, for each integer <var>i</var> between <var>1</var> and <var>N</var>, the bitwise XOR of the weights of the vertices on the path between Vertex <var>i</var> and <var>N+i</var> (including themselves) is <var>i</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>N</var> is an integer.</li>
<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>If there exists a tree satisfying the condition in the statement, print <code>Yes</code>; otherwise, print <code>No</code>.
Then, if such a tree exists, print the <var>2N-1</var> edges of such a tree in the subsequent <var>2N-1</var> lines, in the following format:</p>
<pre><var>a_{1}</var> <var>b_{1}</var>
<var>\vdots</var>
<var>a_{2N-1}</var> <var>b_{2N-1}</var>
</pre>
<p>Here each pair (<var>a_i</var>, <var>b_i</var>) means that there is an edge connecting Vertex <var>a_i</var> and <var>b_i</var>. The edges may be printed in any order.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
1 2
2 3
3 4
4 5
5 6
</pre>
<ul>
<li>The sample output represents the following graph:
<div style="text-align: center;">
<img alt="d004b05438497d50637b534e89f7a511.png" src="https://img.atcoder.jp/agc035/d004b05438497d50637b534e89f7a511.png">
</img></div></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<ul>
<li>There is no tree satisfying the condition.</li>
</ul></section>
</div>
</span> |
p01208 |
<H1><font color="#000">Problem B:</font> Turn Left</H1>
<p>
Taro got a driverâs license with a great effort in his campus days, but unfortunately there had
been no opportunities for him to drive. He ended up obtaining a gold license.
</p>
<p>
One day, he and his friends made a plan to go on a trip to Kyoto with you. At the end of their
meeting, they agreed to go around by car, but there was a big problem; none of his friends was
able to drive a car. Thus he had no choice but to become the driver.
</p>
<p>
The day of our departure has come. He is going to drive but would never turn to the right for
fear of crossing an opposite lane (note that cars keep left in Japan). Furthermore, he cannot
U-turn for the lack of his technique. The car is equipped with a car navigation system, but the
system cannot search for a route without right turns. So he asked to you: âI hate right turns,
so, could you write a program to find the shortest left-turn-only route to the destination, using
the road map taken from this navigation system?â
</p>
<H2>Input</H2>
<p>
The input consists of multiple data sets. The first line of the input contains the number of data
sets. Each data set is described in the format below:
</p>
<pre>
<i>m n</i>
<i>name</i><sub>1</sub> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub>
...
<i>name</i><sub><i>m</i></sub> <i>x</i><sub><i>m</i></sub> <i>y</i><sub><i>m</i></sub>
<i>p</i><sub>1</sub> <i>q</i><sub>1</sub>
...
<i>p</i><sub><i>n</i></sub> <i>q</i><sub><i>n</i></sub>
<i>src dst</i>
</pre>
<p>
<i>m</i> is the number of intersections. <i>n</i> is the number of roads. <i>name<sub>i</sub></i> is the name of the <i>i</i>-th
intersection. (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>) are the integer coordinates of the <i>i</i>-th intersection, where the positive <i>x</i>
goes to the east, and the positive <i>y</i> goes to the north. <i>p<sub>j</sub></i> and <i>q<sub>j</sub></i> are the intersection names
that represent the endpoints of the <i>j</i>-th road. All roads are bidirectional and either vertical or
horizontal. <i>src</i> and <i>dst</i> are the names of the source and destination intersections, respectively.
</p>
<p>
You may assume all of the followings:
</p>
<ul>
<li> 2 ≤ <i>m</i> ≤ 1000, 0 ≤ <i>x<sub>i</sub></i> ≤ 10000, and 0 ≤ <i>y<sub>i</sub></i> ≤ 10000;</li>
<li> each intersection name is a sequence of one or more alphabetical characters at most 25
character long;</li>
<li> no intersections share the same coordinates;</li>
<li> no pair of roads have common points other than their endpoints;</li>
<li> no road has intersections in the middle;</li>
<li> no pair of intersections has more than one road;</li>
<li> Taro can start the car in any direction; and</li>
<li> the source and destination intersections are different.</li>
</ul>
<p>
Note that there may be a case that an intersection is connected to less than three roads in
the input data; the rode map may not include smaller roads which are not appropriate for the
non-local people. In such a case, you still have to consider them as intersections when you go
them through.
</p>
<H2>Output</H2>
<p>
For each data set, print how many times <i>at least</i> Taro needs to pass intersections when he drive
the route of the shortest distance without right turns. The source and destination intersections
must be considered as âpassedâ (thus should be counted) when Taro starts from the source or
arrives at the destination. Also note that there may be more than one shortest route possible.
</p>
<p>
Print âimpossibleâ if there is no route to the destination without right turns.
</p>
<H2>Sample Input</H2>
<pre>
2 1
KarasumaKitaoji 0 6150
KarasumaNanajo 0 0
KarasumaNanajo KarasumaKitaoji
KarasumaKitaoji KarasumaNanajo
3 2
KujoOmiya 0 0
KujoAburanokoji 400 0
OmiyaNanajo 0 1150
KujoOmiya KujoAburanokoji
KujoOmiya OmiyaNanajo
KujoAburanokoji OmiyaNanajo
10 12
KarasumaGojo 745 0
HorikawaShijo 0 870
ShijoKarasuma 745 870
ShijoKawaramachi 1645 870
HorikawaOike 0 1700
KarasumaOike 745 1700
KawaramachiOike 1645 1700
KawabataOike 1945 1700
KarasumaMarutamachi 745 2445
KawaramachiMarutamachi 1645 2445
KarasumaGojo ShijoKarasuma
HorikawaShijo ShijoKarasuma
ShijoKarasuma ShijoKawaramachi
HorikawaShijo HorikawaOike
ShijoKarasuma KarasumaOike
ShijoKawaramachi KawaramachiOike
HorikawaOike KarasumaOike
KarasumaOike KawaramachiOike
KawaramachiOike KawabataOike
KarasumaOike KarasumaMarutamachi
KawaramachiOike KawaramachiMarutamachi
KarasumaMarutamachi KawaramachiMarutamachi
KarasumaGojo KawabataOike
8 9
NishikojiNanajo 0 0
NishiojiNanajo 750 0
NishikojiGojo 0 800
NishiojiGojo 750 800
HorikawaGojo 2550 800
NishiojiShijo 750 1700
Enmachi 750 3250
HorikawaMarutamachi 2550 3250
NishikojiNanajo NishiojiNanajo
NishikojiNanajo NishikojiGojo
NishiojiNanajo NishiojiGojo
NishikojiGojo NishiojiGojo
NishiojiGojo HorikawaGojo
NishiojiGojo NishiojiShijo
HorikawaGojo HorikawaMarutamachi
NishiojiShijo Enmachi
Enmachi HorikawaMarutamachi
HorikawaGojo NishiojiShijo
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
impossible
13
4
</pre>
|
p03235 | <span class="lang-en">
<p>Score : <var>1400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given <var>P</var>, a permutation of <var>(1,\ 2,\ ...\ N)</var>.</p>
<p>A string <var>S</var> of length <var>N</var> consisting of <code>0</code> and <code>1</code> is a <em>good string</em> when it meets the following criterion:</p>
<ul>
<li>The sequences <var>X</var> and <var>Y</var> are constructed as follows:<ul>
<li>First, let <var>X</var> and <var>Y</var> be empty sequences.</li>
<li>For each <var>i=1,\ 2,\ ...\ N</var>, in this order, append <var>P_i</var> to the end of <var>X</var> if <var>S_i=</var> <code>0</code>, and append it to the end of <var>Y</var> if <var>S_i=</var> <code>1</code>.</li>
</ul>
</li>
<li>If <var>X</var> and <var>Y</var> have the same number of <em>high</em> elements, <var>S</var> is a good string.
Here, the <var>i</var>-th element of a sequence is called <em>high</em> when that element is the largest among the elements from the <var>1</var>-st to <var>i</var>-th element in the sequence.</li>
</ul>
<p>Determine if there exists a good string. If it exists, find the lexicographically smallest such string.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2 \times 10^5</var></li>
<li><var>1 \leq P_i \leq N</var></li>
<li><var>P_1,\ P_2,\ ...\ P_N</var> are all distinct.</li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>P_1</var> <var>P_2</var> <var>...</var> <var>P_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If a good string does not exist, print <code>-1</code>.
If it exists, print the lexicographically smallest such string.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
3 1 4 6 2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>001001
</pre>
<p>Let <var>S=</var> <code>001001</code>. Then, <var>X=(3,\ 1,\ 6,\ 2)</var> and <var>Y=(4,\ 5)</var>.
The high elements in <var>X</var> is the first and third elements, and the high elements in <var>Y</var> is the first and second elements.
As they have the same number of high elements, <code>001001</code> is a good string.
There is no good string that is lexicographically smaller than this, so the answer is <code>001001</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
1 2 3 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7
1 3 2 5 6 4 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0001101
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>30
1 2 6 3 5 7 9 8 11 12 10 13 16 23 15 18 14 24 22 26 19 21 28 17 4 27 29 25 20 30
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>000000000001100101010010011101
</pre></section>
</div>
</span> |
p03720 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> cities and <var>M</var> roads.
The <var>i</var>-th road <var>(1â€iâ€M)</var> connects two cities <var>a_i</var> and <var>b_i</var> <var>(1â€a_i,b_iâ€N)</var> bidirectionally.
There may be more than one road that connects the same pair of two cities.
For each city, how many roads are connected to the city?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2â€N,Mâ€50</var></li>
<li><var>1â€a_i,b_iâ€N</var></li>
<li><var>a_i â b_i</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format: </p>
<pre><var>N</var> <var>M</var>
<var>a_1</var> <var>b_1</var>
<var>:</var>
<var>a_M</var> <var>b_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer in <var>N</var> lines.
In the <var>i</var>-th line <var>(1â€iâ€N)</var>, print the number of roads connected to city <var>i</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 3
1 2
2 3
1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
2
1
1
</pre>
<ul>
<li>City <var>1</var> is connected to the <var>1</var>-st and <var>3</var>-rd roads.</li>
<li>City <var>2</var> is connected to the <var>1</var>-st and <var>2</var>-nd roads.</li>
<li>City <var>3</var> is connected to the <var>2</var>-nd road.</li>
<li>City <var>4</var> is connected to the <var>3</var>-rd road.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 5
1 2
2 1
1 2
2 1
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
5
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8 8
1 2
3 4
1 5
2 8
3 7
5 2
4 1
6 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3
3
2
2
2
1
1
2
</pre></section>
</div>
</span> |
p02832 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> bricks arranged in a row from left to right.</p>
<p>The <var>i</var>-th brick from the left <var>(1 \leq i \leq N)</var> has an integer <var>a_i</var> written on it.</p>
<p>Among them, you can break at most <var>N-1</var> bricks of your choice.</p>
<p>Let us say there are <var>K</var> bricks remaining. Snuke will be satisfied if, for each integer <var>i</var> <var>(1 \leq i \leq K)</var>, the <var>i</var>-th of those brick from the left has the integer <var>i</var> written on it.</p>
<p>Find the minimum number of bricks you need to break to satisfy Snuke's desire. If his desire is unsatisfiable, print <code>-1</code> instead.</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 200000</var></li>
<li><var>1 \leq a_i \leq N</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of bricks that need to be broken to satisfy Snuke's desire, or print <code>-1</code> if his desire is unsatisfiable.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
2 1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>If we break the leftmost brick, the remaining bricks have integers <var>1</var> and <var>2</var> written on them from left to right, in which case Snuke will be satisfied.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
2 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>In this case, there is no way to break some of the bricks to satisfy Snuke's desire.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
3 1 4 1 5 9 2 6 5 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>7
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>0
</pre>
<p>There may be no need to break the bricks at all.</p></section>
</div>
</span> |
p02998 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> dots in a two-dimensional plane. The coordinates of the <var>i</var>-th dot are <var>(x_i, y_i)</var>.</p>
<p>We will repeat the following operation as long as possible:</p>
<ul>
<li>Choose four integers <var>a</var>, <var>b</var>, <var>c</var>, <var>d</var> <var>(a \neq c, b \neq d)</var> such that there are dots at exactly three of the positions <var>(a, b)</var>, <var>(a, d)</var>, <var>(c, b)</var> and <var>(c, d)</var>, and add a dot at the remaining position.</li>
</ul>
<p>We can prove that we can only do this operation a finite number of times. Find the maximum number of times we can do the operation.</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 x_i, y_i \leq 10^5</var></li>
<li>If <var>i \neq j</var>, <var>x_i \neq x_j</var> or <var>y_i \neq y_j</var>.</li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>x_1</var> <var>y_1</var>
<var>:</var>
<var>x_N</var> <var>y_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum number of times we can do the operation.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 1
5 1
5 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>By choosing <var>a = 1</var>, <var>b = 1</var>, <var>c = 5</var>, <var>d = 5</var>, we can add a dot at <var>(1, 5)</var>. We cannot do the operation any more, so the maximum number of operations is <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
10 10
20 20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>There are only two dots, so we cannot do the operation at all.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>9
1 1
2 1
3 1
4 1
5 1
1 2
1 3
1 4
1 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>16
</pre>
<p>We can do the operation for all choices of the form <var>a = 1</var>, <var>b = 1</var>, <var>c = i</var>, <var>d = j</var> <var>(2 \leq i,j \leq 5)</var>, and no more. Thus, the maximum number of operations is <var>16</var>.</p></section>
</div>
</span> |
p03370 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Akaki, a patissier, can make <var>N</var> kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut <var>1</var>, Doughnut <var>2</var>, <var>...,</var> Doughnut <var>N</var>. In order to make one Doughnut <var>i</var> <var>(1 †i †N)</var>, she needs to consume <var>m_i</var> grams of Moto. She cannot make a non-integer number of doughnuts, such as <var>0.5</var> doughnuts.</p>
<p>Now, she has <var>X</var> grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition:</p>
<ul>
<li>For each of the <var>N</var> kinds of doughnuts, make at least one doughnut of that kind.</li>
</ul>
<p>At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 †N †100</var></li>
<li><var>1 †m_i †1000</var></li>
<li><var>m_1 + m_2 + ... + m_N †X †10^5</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
<var>m_1</var>
<var>m_2</var>
<var>:</var>
<var>m_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum number of doughnuts that can be made under the condition.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 1000
120
100
140
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>9
</pre>
<p>She has <var>1000</var> grams of Moto and can make three kinds of doughnuts. If she makes one doughnut for each of the three kinds, she consumes <var>120 + 100 + 140 = 360</var> grams of Moto. From the <var>640</var> grams of Moto that remains here, she can make additional six Doughnuts <var>2</var>. This is how she can made a total of nine doughnuts, which is the maximum.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 360
90
90
90
90
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre>
<p>Making one doughnut for each of the four kinds consumes all of her Moto.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 3000
150
130
150
130
110
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>26
</pre></section>
</div>
</span> |
p02131 | <h1>Problem H: Hth Number</h1>
<h2>Problem</h2>
<p>
é·ã$N$ã®æåå$S$ãããã$S$ã«å«ãŸããæåã¯ãã¹ãŠ0以äž9以äžã®æ°åã§ããã<br>
$S$ã®ãã¹ãŠã®éšåæååããäœãããæ°ãå
šåæããŠã§ããé
æ°$\frac{N\times(N+1)}{2}$ã®æ°åãäœã£ãæã
ãã®æ°åã®äžã§$H$çªç®ã«å°ããå€ãæ±ããã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
$N$ $H$
$S$
</pre>
<p>
å
¥åã¯ãã¹ãп޿°ã§äžããããã<br>
1è¡ç®ã«$N$ãš$H$ã空çœåºåãã§äžããããã<br>
2è¡ç®ã«é·ã$N$ã®æåå$S$ãäžããããã<br>
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>$1 \leq N \leq 10^5$</li>
<li>$1 \leq H \leq \frac{N \times (N+1)}{2}$
<li>$|S| = N$
<li>$S$ã«å«ãŸããæåã¯ãã¹ãŠ0, 1, 2, 3, 4, 5, 6, 7, 8, 9ã®ããããã§ãã
</ul>
<h2>Output</h2>
<p>
$H$çªç®ã®å€ã1è¡ã«åºåããã<br>
(åºåã®å
é ã«äœèšãª0ã¯å«ãã§ã¯ãªããªãã)
</p>
<h2>Sample Input 1</h2>
<pre>
2 3
00
</pre>
<h2>Sample Output 1</h2>
<pre>
0
</pre>
<h2>Sample Input 2</h2>
<pre>
4 9
0012
</pre>
<h2>Sample Output 2</h2>
<pre>
12
</pre>
<h2>Sample Input 3</h2>
<pre>
5 13
10031
</pre>
<h2>Sample Output 3</h2>
<pre>
100
</pre>
<p>
Sample Input3ã®å Žåã10031ã®éšåæååããäœãããæ°ã¯ä»¥äžã®éãã§ããã<br>
1, 0, 0, 3, 1<br>
10, 00, 03, 31<br>
100, 003, 031<br>
1003, 0031<br>
10031<br>
ãããããå°ããé ã«äžŠã¹ããš
0, 0, 0, 1, 1, 3, 3, 3, 10, 31, 31, 31, 100, 1003, 10031 ã«ãªãã13çªç®ã«å°ããå€ã¯100ã§ããã<br>
</p>
|
p02561 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a grid of <var>N</var> rows and <var>M</var> columns. The square at the <var>i</var>-th row and <var>j</var>-th column will be denoted as <var>(i,j)</var>.
Some of the squares contain an object. All the remaining squares are empty.
The state of the grid is represented by strings <var>S_1,S_2,\cdots,S_N</var>. The square <var>(i,j)</var> contains an object if <var>S_{i,j}=</var> <code>#</code> and is empty if <var>S_{i,j}=</var> <code>.</code>.</p>
<p>Consider placing <var>1 \times 2</var> tiles on the grid. Tiles can be placed vertically or horizontally to cover two adjacent empty squares.
Tiles must not stick out of the grid, and no two different tiles may intersect. Tiles cannot occupy the square with an object.</p>
<p>Calculate the maximum number of tiles that can be placed and any configulation that acheives the maximum.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 100</var></li>
<li><var>1 \leq M \leq 100</var></li>
<li><var>S_i</var> is a string with length <var>M</var> consists of <code>#</code> and <code>.</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>S_1</var>
<var>S_2</var>
<var>\vdots</var>
<var>S_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>On the first line, print the maximum number of tiles that can be placed.</p>
<p>On the next <var>N</var> lines, print a configulation that achieves the maximum.
Precisely, output the strings <var>t_1,t_2,\cdots,t_N</var> constructed by the following way.</p>
<ul>
<li><var>t_i</var> is initialized to <var>S_i</var>.</li>
<li>For each <var>(i,j)</var>, if there is a tile that occupies <var>(i,j)</var> and <var>(i+1,j)</var>, change <var>t_{i,j}</var>:=<code>v</code>, <var>t_{i+1,j}</var>:=<code>^</code>.</li>
<li>For each <var>(i,j)</var>, if there is a tile that occupies <var>(i,j)</var> and <var>(i,j+1)</var>, change <var>t_{i,j}</var>:=<code>></code>, <var>t_{i,j+1}</var>:=<code><</code>.</li>
</ul>
<p>See samples for further information.</p>
<p>You may print any configulation that maximizes the number of tiles.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
#..
..#
...
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
#><
vv#
^^.
</pre>
<p>The following output is also treated as a correct answer.</p>
<pre>3
#><
v.#
^><
</pre></section>
</div>
</span> |
p03059 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A biscuit making machine produces <var>B</var> biscuits at the following moments: <var>A</var> seconds, <var>2A</var> seconds, <var>3A</var> seconds and each subsequent multiple of <var>A</var> seconds after activation.</p>
<p>Find the total number of biscuits produced within <var>T + 0.5</var> seconds after activation.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq A, B, T \leq 20</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>T</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total number of biscuits produced within <var>T + 0.5</var> seconds after activation.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 5 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
</pre>
<ul>
<li>Five biscuits will be produced three seconds after activation.</li>
<li>Another five biscuits will be produced six seconds after activation.</li>
<li>Thus, a total of ten biscuits will be produced within <var>7.5</var> seconds after activation.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 2 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>6
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>20 20 19
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p01064 |
<h1>Array Update 2</h1>
<h2>Problem</h2>
<p>
é
æ° <var>N</var> ãåé
<var>a</var> ãå
¬å·®<var>d</var>ã®çå·®æ°å <var>A</var> ãããã
以äžã®åœ¢åŒã§ãæ°åãæžãæãã <var>M</var> åã®åœä»€æãäžããããã®ã§ãäžããããé åºã§ <var>M</var> å
æ°å <var>A</var> ãæžãæãããšãã®æ°å <var>A</var> ã® <var>K</var>é
ç®ã®å€ãæ±ããªããã
</p>
<ul>
<li>
<var>i</var> çªç®ã®åœä»€æã¯3ã€ã®æŽæ°<var> x<sub>i</sub> , y<sub>i</sub> , z<sub>i</sub> </var>ã§äžããããã(1 ≤ <var>i</var> ≤ <var>M</var>)<br>
</li>
<li>
<var>x<sub>i</sub></var>ã0ã ã£ãå Žåã<var>y<sub>i</sub></var>é
ç®ãã
<var>z<sub>i</sub></var>é
ç®ãŸã§ã®åºéã«ãããŠãå€ã®é åºãå転ããã<br>
</li>
<li>
<var>x<sub>i</sub></var>ã1ã ã£ãå Žåã<var>y<sub>i</sub></var>é
ç®ãã
<var>z<sub>i</sub></var>é
ç®ãŸã§ã®åºéã«ãããŠãããããã®å€ã1å¢å ãããã <br>
</li>
<li>
<var>x<sub>i</sub></var>ã2ã ã£ãå Žåã<var>y<sub>i</sub></var>é
ç®ãã
<var>z<sub>i</sub></var>é
ç®ãŸã§ã®åºéã«ãããŠãããããã®å€ãååã«ããïŒå°æ°ç¹ä»¥äžã¯åãæšãŠãïŒã<br>
</li>
</ul>
<h2>Input</h2>
<pre>
<var>N</var>
<var>a</var> <var>d</var>
<var>M</var>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>z<sub>1</sub></var>
<var>x<sub>2</sub></var> <var>y<sub>2</sub></var> <var>z<sub>2</sub></var>
...
<var>x<sub>M</sub></var> <var>y<sub>M</sub></var> <var>z<sub>M</sub></var>
<var>K</var>
</pre>
<p>
1è¡ç®ã«ã1ã€ã®æŽæ° <var>N</var> ãäžããããã
2è¡ç®ã«ã2ã€ã®æŽæ° <var>a</var> ãš <var>d</var> ã空çœåºåãã§äžããããã
3è¡ç®ã«ã1ã€ã®æŽæ° <var>M</var> ãäžããããã
4è¡ç®ããã® <var>M</var> è¡ã®ãã¡ <var>i</var> è¡ç®ã«ã¯ <var>i</var> çªç®ã®åœä»€æã衚ã 3 ã€ã®æŽæ° <var>x<sub>i</sub>, y<sub>i</sub>, z<sub>i</sub></var> ã空çœåºåãã§äžããããã
æåŸã®è¡ã«ã1ã€ã®æŽæ° <var>K</var> ãäžããããã
</p>
<h2>Constraints</h2>
<ul>
<li>2 ≤ <var>N</var> ≤ 200000</li>
<li>1 ≤ <var>a</var> ≤ 5</li>
<li>1 ≤ <var>d</var> ≤ 5</li>
<li>1 ≤ <var>M</var> ≤ 200000</li>
<li>0 ≤ <var>x<sub>i</sub></var> ≤ 2 (1 ≤ <var>i</var> ≤ <var>M</var>)</li>
<li>1 ≤ <var>y<sub>i</sub></var> ≤ <var>N</var> (1 ≤ <var>i</var> ≤ <var>M</var>)</li>
<li>1 ≤ <var>z<sub>i</sub></var> ≤ <var>N</var> (1 ≤ <var>i</var> ≤ <var>M</var>)</li>
<li><var>y<sub>i</sub></var> < <var>z<sub>i</sub></var> (1 ≤ <var>i</var> ≤ <var>M</var>)</li>
<li>1 ≤ <var>K</var> ≤ <var>N</var></li>
</ul>
<h2>Output</h2>
<p>
å
¥åã§äžããããé çªã§æ°å<var>A</var>ã<var>M</var>åæŽæ°ãããšãã®<var>K</var>é
ç®ãåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
4
2 1
3
0 1 2
1 1 4
2 2 4
3
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<p>
{ 2 , 3 , 4 , 5 }<br><br>
â 0 1 2 ... 1é
ç®ãã2é
ç®ãŸã§ã®åºéã®å€ã®é åºãå転ãã<br><br>
{ 3 , 2 , 4 , 5 }<br><br>
â 1 1 4 ... 1é
ç®ãã4é
ç®ãŸã§ã®åºéã®å€ããããã1å¢ãã<br><br>
{ 4 , 3 , 5 , 6 }<br><br>
â 2 2 4 ... 2é
ç®ãã4é
ç®ãŸã§ã®åºéã®å€ãããããååã«ããïŒå°æ°ç¹ä»¥äžåãæšãŠãïŒ<br><br>
{ 3 , 1 , 2 , 3 }<br><br>
ãã£ãŠ3é
ç®ã®å€ã¯2ã§ããã<br>
</p>
<h2>Sample Input 2</h2>
<pre>
5
1 2
3
1 2 3
2 3 5
0 1 5
1
</pre>
<h2>Sample Output 2</h2>
<pre>
4
</pre>
<p>
{ 1 , 3 , 5 , 7 , 9 }<br><br>
â 1 2 3 ... 2é
ç®ãã3é
ç®ãŸã§ã®åºéã®å€ããããã1å¢ãã<br><br>
{ 1 , 4 , 6 , 7 , 9 }<br><br>
â 2 3 5 ... 3é
ç®ãã5é
ç®ãŸã§ã®åºéã®å€ãããããååã«ããïŒå°æ°ç¹ä»¥äžåãæšãŠãïŒ<br><br>
{ 1 , 4 , 3 , 3 , 4 }<br><br>
â 0 1 5 ... 1é
ç®ãã5é
ç®ãŸã§ã®åºéã®å€ã®é åºãå転ãã<br><br>
{ 4 , 3 , 3 , 4 , 1 }<br><br>
ãã£ãŠ1é
ç®ã®å€ã¯4ã§ããã
</p> |
p03409 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>On a two-dimensional plane, there are <var>N</var> red points and <var>N</var> blue points.
The coordinates of the <var>i</var>-th red point are <var>(a_i, b_i)</var>, and the coordinates of the <var>i</var>-th blue point are <var>(c_i, d_i)</var>.</p>
<p>A red point and a blue point can form a <em>friendly pair</em> when, the <var>x</var>-coordinate of the red point is smaller than that of the blue point, and the <var>y</var>-coordinate of the red point is also smaller than that of the blue point.</p>
<p>At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All input values are integers.</li>
<li><var>1 \leq N \leq 100</var></li>
<li><var>0 \leq a_i, b_i, c_i, d_i < 2N</var></li>
<li><var>a_1, a_2, ..., a_N, c_1, c_2, ..., c_N</var> are all different.</li>
<li><var>b_1, b_2, ..., b_N, d_1, d_2, ..., d_N</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>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
<var>:</var>
<var>a_N</var> <var>b_N</var>
<var>c_1</var> <var>d_1</var>
<var>c_2</var> <var>d_2</var>
<var>:</var>
<var>c_N</var> <var>d_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum number of friendly pairs.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
2 0
3 1
1 3
4 2
0 4
5 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>For example, you can pair <var>(2, 0)</var> and <var>(4, 2)</var>, then <var>(3, 1)</var> and <var>(5, 5)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
0 0
1 1
5 2
2 3
3 4
4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
<p>For example, you can pair <var>(0, 0)</var> and <var>(2, 3)</var>, then <var>(1, 1)</var> and <var>(3, 4)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
2 2
3 3
0 0
1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>It is possible that no pair can be formed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>5
0 0
7 3
2 2
4 8
1 6
8 5
6 9
5 4
9 1
3 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>5
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>5
0 0
1 1
5 5
6 6
7 7
2 2
3 3
4 4
8 8
9 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>4
</pre></section>
</div>
</span> |
p01434 |
<script type="text/javascript" src="./varmath.js" charset="UTF-8"></script>
<h2>å顿</h2>
<p>
å§å¡é·ã®é女 PATRICIA ã¯ïŒèèã®ãããªç³žãåãçµçã®äžã§æ®ãããŠããïŒäœ¿ãéã® MATHIEU ã¯ïŒå§å¡é·ã®é女ãåãã糞ãåŒã£ã±ãèªåšã«ç©ºãé£ãã§ããïŒç³žã¯ç©ºéäžã®ç·åãšã¿ãªãããšã«ããïŒ
</p>
<p>
<i>æçŸã»ãã</i>ã¯å§å¡é·ã®é女ã«å¯ŸããŠæ»æã仿ããããšãïŒç匟ãšééããŠè±ç«çãæã蟌ãã§ããŸã£ãïŒãã®çµæïŒããããã®ç³žã«ã€ããŠïŒé女ããè·é¢ <var>p_1, ..., p_M</var> ã®äœçœ®ã«ããéšåãåããã ããšãªã£ãŠããŸã£ãïŒè±ç«çãæããåïŒããããã®ç³žã«ã€ããŠïŒç³žã® <var>2</var> ã€ã®ç«¯ç¹ãšé女ã¯ãã®é çªã§åäžçŽç·äžã«äžŠãã§ããïŒç«¯ç¹ã®ã©ã¡ããäžæ¹ã䜿ãéãåŒã£åŒµã£ãŠããïŒççºã§ç³žã¯åãïŒäœ¿ãéãæã£ãŠããéšåãšããããäžã€çœ®ãã®éšåãæ®ããŠç³žã®äžéšã¯æ¶ããŠããŸã£ãïŒ
<p>
<i>ã»ãã</i>ã¯æ¬¡ã®æŠç¥ãèããããã«ïŒæ®ã£ã糞ã«ã€ããŠã®æ
å ±ãç¥ããããšæã£ãŠããïŒæ®ã£ã糞ã®é·ãã®åèšå€ãæ±ããïŒ
<h2>å
¥å圢åŒ</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ
</p>
<pre><var>
N\ M\\
s_1\ t_1\\
...\\
s_N\ t_N\\
p_1\\
...\\
p_M\\
</var></pre>
<p>
<var>N</var> ã¯ç©ºéäžã®ç³žã®åæ°ïŒ<var>M</var> ã¯è±ç«çã«ãã£ãŠçºçãã糞ã®åæã®ç®æã®åæ°ã§ããïŒ
</p>
<p>
<var>s_i, t_i</var> ã¯ç³žã®æ
å ±ã§ããïŒ<var>s_i</var> ã¯äœ¿ãéãåŒã£åŒµã£ãŠããåŽã®ç«¯ç¹ïŒ<var>t_i</var> ã¯ããã§ãªãåŽã®ç«¯ç¹ã®é女ããã®è·é¢ã§ããïŒ
<p>
<var>p_i</var> ã¯è±ç«çã«ãã£ãŠåæãããäœçœ®ã®æ
å ±ã§ããïŒ
<h2>åºå圢åŒ</h2>
<p>
è±ç«çãæããåŸïŒæ®ã£ã糞ã®é·ãã®åèšå€ã1è¡ã«åºåããïŒ
</p>
<h2>å¶çŽ</h2>
<ul>
<li><var>1 ≤ N ≤ 10<sup>5</sup></var></li>
<li><var>1 ≤ M ≤ 10<sup>5</sup></var></li>
<li><var>1 ≤ s_i ≤ 10^9</var></li>
<li><var>1 ≤ t_i ≤ 10^9</var></li>
<li><var>1 ≤ p_i ≤ 10^9</var></li>
<li>å
¥åå€ã¯å
šãп޿°ã§ããïŒ</li>
<li><var>s_1, ..., s_N, t_1, ..., t_N, p_1, ..., p_M</var> ã¯å
šãŠçžç°ãªãïŒ</li>
</ul>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
2 3
1 8
20 5
3
7
15
</pre>
<h3>åºåäŸ1</h3>
<pre>10</pre>
<p>
ççºã®åŸïŒ<var>1</var> ã€ç®ã®ã²ãã¯ç«¯ç¹ã®é女ããã®è·é¢ããããã <var>(1,3), (7,8)</var> ã® <var>2</var> ã€ã®ã²ãã«ïŒ<var>2</var> ã€ç®ã®ã²ã㯠<var>(20, 15), (7, 5)</var> ã® <var>2</var> ã€ã®ã²ãã«åãããïŒçµæïŒæ®ã£ãã²ãã®é·ãã®åèšã¯ <var>2+1+5+2 = 10</var> ãšãªãïŒ
</p>
<h3>å
¥åäŸ 2</h3>
<pre>
1 1
100 1
70
</pre>
<h3>åºåäŸ 2</h3>
<pre>30</pre>
<h3>å
¥åäŸ 3</h3>
<pre>
6 8
1 10
11 23
99 2
56 58
66 78
88 49
5
15
25
35
45
55
65
75
</pre>
<h3>åºåäŸ 3</h3>
<pre>99</pre>
<hr>
<address>Problem Setter: Flat35</address> |
p01967 | <h2>AïŒæ²¢å±±ã®çš®é¡ã®ææª (Many Kinds of Apples)</h2>
<h3>Problem Statement</h3>
<p>Apple Farmer Mon has two kinds of tasks: "harvest apples" and "ship apples".</p>
<p>There are <var>N</var> different species of apples, and <var>N</var> distinguishable boxes. Apples are labeled by the species, and boxes are also labeled, from <var>1</var> to <var>N</var>. The <var>i</var>-th species of apples are stored in the <var>i</var>-th box.</p>
<p>For each <var>i</var>, the <var>i</var>-th box can store at most <var>c_i</var> apples, and it is initially empty (no apple exists).</p>
<p>Mon receives Q instructions from his boss Kukui, and Mon completely follows in order. Each instruction is either of two types below.</p>
<ul>
<li> "harvest apples": put <var>d</var> <var>x</var>-th apples into the <var>x</var>-th box.</li>
<li> "ship apples": take <var>d</var> <var>x</var>-th apples out from the <var>x</var>-th box.</li>
</ul>
<p>However, not all instructions are possible to carry out. Now we call an instruction which meets either of following conditions "impossible instruction":</p>
<ul>
<li> When Mon harvest apples, the amount of apples exceeds the capacity of that box.</li>
<li> When Mon tries to ship apples, there are not enough apples to ship.</li>
</ul>
<p>Your task is to detect the instruction which is impossible to carry out.</p>
<h3>Input</h3>
<p>Input is given in the following format.</p>
<pre>
<var>N</var>
<var>c_1</var> <var>c_2</var> $\cdots$ <var>c_N</var>
<var>Q</var>
<var>t_1</var> <var>x_1</var> <var>d_1</var>
<var>t_2</var> <var>x_2</var> <var>d_2</var>
$\vdots$
<var>t_Q</var> <var>x_Q</var> <var>d_Q</var>
</pre>
<p>In line 1, you are given the integer <var>N</var>, which indicates the number of species of apples.</p>
<p>In line 2, given <var>c_i</var> (<var>1 \leq i \leq N</var>) separated by whitespaces. <var>c_i</var> indicates the capacity of the <var>i</var>-th box.</p>
<p>In line 3, given <var>Q</var>, which indicates the number of instructions.</p>
<p>Instructions are given successive <var>Q</var> lines. <var>t_i</var> <var>x_i</var> <var>d_i</var> means what kind of instruction, which apple Mon handles in this instruction, how many apples Mon handles, respectively. If <var>t_i</var> is equal to <var>1</var>, it means Mon does the task of "harvest apples", else if <var>t_i</var> is equal to <var>2</var>, it means Mon does the task of "ship apples".</p>
<h3>Constraints</h3>
<p>All input values are integers, and satisfy following constraints.</p>
<ul>
<li> <var>1 \leq N \leq 1,000</var></li>
<li> <var>1 \leq c_i \leq 100,000</var> (<var>1 \leq i \leq N</var>)</li>
<li> <var>1 \leq Q \leq 100,000</var></li>
<li> <var>t_i \in \{1, 2\}</var> (<var>1 \leq i \leq Q</var>)</li>
<li> <var>1 \leq x_i \leq N</var> (<var>1 \leq i \leq Q</var>)</li>
<li> <var>1 \leq d_i \leq 100,000</var> (<var>1 \leq i \leq Q</var>)</li>
</ul>
<h3>Output</h3>
<p>If there is "impossible instruction", output the index of the apples which have something to do with the first "impossible instruction".</p>
<p>Otherwise, output <var>0</var>.</p>
<h3>Sample Input 1</h3>
<pre>
2
3 3
4
1 1 2
1 2 3
2 1 3
2 2 3
</pre>
<h3>Sample Output 1</h3>
<pre>1</pre>
<p>In this case, there are not enough apples to ship in the first box.</p>
<h3>Sample Input 2</h3>
<pre>
2
3 3
4
1 1 3
2 1 2
1 2 3
1 1 3
</pre>
<h3>Sample Output 2</h3>
<pre>1</pre>
<p>In this case, the amount of apples exceeds the capacity of the first box.</p>
<h3>Sample Input 3</h3>
<pre>
3
3 4 5
4
1 1 3
1 2 3
1 3 5
2 2 2
</pre>
<h3>Sample Output 3</h3>
<pre>0</pre>
<h3>Sample Input 4</h3>
<pre>
6
28 56 99 3 125 37
10
1 1 10
1 1 14
1 3 90
1 5 10
2 3 38
2 1 5
1 3 92
1 6 18
2 5 9
2 1 4
</pre>
<h3>Sample Output 4</h3>
<pre>3</pre>
|
p00675 |
<h1>Problem G: Sports Days</h1>
<p>
äŒæŽ¥å€§åŠéå±å°åŠæ ¡ïŒäŒæŽ¥å€§å°ïŒã¯æ¥æ¬ææ°ã®ç«¶æããã°ã©ããŒé€ææ ¡ãšããŠæåã§ããã
ãã¡ãããéåäŒã«åå ããŠãããšãã§ããã¢ã«ãŽãªãºã ã®ä¿®è¡ãæ¬ ãããªãã
</p>
<p>
ç«¶æããã°ã©ãã³ã°éšéšé·ã®ããªãã¯ãã¡ãããã®å€§äŒã§ãåå©ãããã
ä»åã¯ããç«¶æã«æ³šç®ããã
</p>
<p>
ããç«¶æãšã¯äŒæŽ¥å€§å°ã§è¡ãããŠããäŒçµ±çãªç«¶æã ã
æ ¡åºã«ã³ãŒã³ãnå眮ããŠããã
ã³ãŒã³ã¯4è²çšæãããŠããã
ã³ãŒã³ã®ããã€ãã®ãã¢ã¯çœç·ã§æãããç¢å°ã§çµã°ããŠããã
ç¢å°ã¯çåŽã ãã«ã€ããŠãããæŽæ°ã䜵èšãããŠããã
</p>
<p>
ç«¶æè
ã¯k人1ããŒã ãšããŠè¡åããã
ããã¹ã¿ãŒãå°ç¹ã®ã³ãŒã³ãããŽãŒã«å°ç¹ã®ã³ãŒã³ãŸã§ç¢å°ã®äžããã®åãã«ç§»åããã
ãã ããk人ããããããŽãŒã«å°ç¹ãŸã§ã®çµè·¯ã¯ç°ãªãå¿
èŠãããã
</p>
<p>
çµè·¯1ãšçµè·¯2ãç°ãªããšããã®ã¯ã
</p>
<ul>
<li>æ¡ä»¶1ãçµè·¯1ãšçµè·¯2ã§çµç±ããç¢å°ã®æ¬æ°ãçããå Žåãçµè·¯1ã§içªç®ã«çµç±ããç¢å°ãšçµè·¯2ã§içªç®ã«çµç±ããç¢å°ãç°ãªããããªiãååšããããšã</li>
<li>æ¡ä»¶2ãçµè·¯1ãšçµè·¯2ã§çµç±ããç¢å°ã®æ¬æ°ãç°ãªã£ãŠããããšã</li>
</ul>
<p>
ã®ãããããæºããã°çµè·¯ãç°ãªã£ãŠãããšèšããã
</p>
<p>
ããã«ãã³ãŒã³ã®èŸ¿ãæ¹ã«ã¯çŠæ¢ãããè²ã®ãã¿ãŒã³ããããã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ãŸã§ã®çµè·¯ã§ãã®ãã¿ãŒã³ãå«ãã§ããŸã£ãéžæã¯ãªã¿ã€ã¢ãšãªãã
ãã ãããã以å€ã®çµè·¯ã¯ã©ã®ãããªçµè·¯ã蟿ã£ãŠããããäœåºŠãåãã³ãŒã³ïŒã¹ã¿ãŒãå°ç¹ããŽãŒã«å°ç¹ã®ã³ãŒã³ãå«ãïŒãéã£ãŠè¯ãã
ãŸããç¢å°ã«äœµèšãããæ°åãã¹ã³ã¢ãšããŠå ç®ãããŠããã
ãã®ç«¶æã¯ããå€ãã®ããŒã ã¡ã€ããããå°ããªåèšã¹ã³ã¢ã§ãŽãŒã«å°ç¹ã®ã³ãŒã³ã«èŸ¿ãã€ããããŒã ãåå©ãšãªãã
</p>
<p>
éšé·ã®ããªãã¯ãã¡ããããã°ã©ãã³ã°ã§ãã®åé¡ã解決ã§ããã¯ãã ã
ãŽãŒã«ãŸã§ç§»åå¯èœãªæå€§ã®äººæ°ãæ±ããã
ãŸããæå€§äººæ°ã§èŸ¿ãçããæã®æå°ã¹ã³ã¢ãæ±ããã
</p>
<p>
ãã ãããããã§ãã¹ã³ã¢ãå°ããåºæ¥ãå Žå㯠-1 ãåºåããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯è€æ°ã®ãã¹ãã±ãŒã¹ããæãç«ã£ãŠããã
ãã¹ãã±ãŒã¹ã®æ°ã¯20ã±ãŒã¹ãè¶
ããªãã
</p>
<pre>
n
col<sub>1</sub>
col<sub>2</sub>
...
col<sub>n</sub>
m
a<sub>1</sub> b<sub>1</sub> c<sub>1</sub>
a<sub>2</sub> b<sub>2</sub> c<sub>2</sub>
...
a<sub>m</sub> b<sub>m</sub> c<sub>m</sub>
k
pattern
</pre>
<p>
n( 2 ≤ n ≤ 100)ã¯ã³ãŒã³ã®æ°ã衚ãã
col<sub>i</sub>(1 ≤ col<sub>i</sub> ≤ 4)ã¯içªç®ã®ã³ãŒã³ã®è²ã瀺ãã
m(0 ≤ m ≤ 1,000) ã¯ç¢å°ã®æ°ã衚ãã
a<sub>i</sub> ã¯ç¢å°ã®å§ç¹ã®ã³ãŒã³ã®çªå·, b<sub>i</sub>ã¯çµç¹ã®ã³ãŒã³ã®çªå·ã衚ããc<sub>i</sub>ã¯ãã®ç¢å°ã®ã¹ã³ã¢ã衚ã.
ãŸããã²ãšã€ã®ã³ãŒã³ãã䌞ã³ãç¢å°ã¯10æ¬ãŸã§ã§ããã
(1 ≤ a<sub>i</sub>, b<sub>i</sub> ≤ n, -1,000 ≤ c<sub>i</sub> ≤ 1,000)
kã¯ç«¶æãè¡ãããŒã ã®äººæ°ã瀺ãã
(1 ≤ k ≤ 10)
pattern
ã¯é·ãã10以äžã®1~4ãŸã§ã®æ°åãããªãæååã§ã
ç§»åãçŠæ¢ãããŠãããã¿ãŒã³ã瀺ãã
ã¹ã¿ãŒãå°ç¹ã®ã³ãŒã³ã¯1çªç®ã®ã³ãŒã³ã§ããã
nçªç®ã®ã³ãŒã³ããŽãŒã«ã§ããã
å
¥åã§äžããããæ°(n, col, m, a, b, c, k)ã¯ãã¹ãп޿°ã§ããã
å
¥åã®çµããã¯0ãå«ã1è¡ã§ç€ºãããã
</p>
<h2>Output</h2>
<p>
åºåã¯ç©ºçœã§åºåãããäºã€ã®æŽæ°ãããªãã
1ã€ç®ã¯å°éã§ãã人æ°ã§ã2ã€ç®ã¯ãã®æå°ã³ã¹ãã§ããã
ããããããã§ãã¹ã³ã¢ãå°ããåºæ¥ãå Žåã¯-1ã®ã¿ãå«ãïŒè¡ãåºåããã
äžäººãå°éã§ããªãå Žåã¯0 0ãåºåããã
</p>
<h2>Sample Input</h2>
<pre>
2
1
1
2
1 2 1
2 1 1
1
1111
2
1
1
2
1 2 1
2 1 1
1
11
2
1
1
2
1 2 1
2 1 1
10
1111
2
1
1
2
1 2 1
2 1 1
10
111111
2
1
1
2
1 2 -1
2 1 0
10
11
2
1
1
2
1 2 -1
2 1 0
10
1111
2
1
1
2
1 2 -1
2 1 0
10
12
2
1
1
2
1 2 -1
2 1 0
10
1111111111
0
</pre>
<h2>Sample Output</h2>
<pre>
1 1
0 0
1 1
2 4
0 0
1 -1
-1
4 -10
</pre> |
p02648 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a rooted binary tree with <var>N</var> vertices, where the vertices are numbered <var>1</var> to <var>N</var>.
Vertex <var>1</var> is the root, and the parent of Vertex <var>i</var> (<var>i \geq 2</var>) is Vertex <var>\left[ \frac{i}{2} \right]</var>.</p>
<p>Each vertex has one item in it. The item in Vertex <var>i</var> has a value of <var>V_i</var> and a weight of <var>W_i</var>.
Now, process the following query <var>Q</var> times:</p>
<ul>
<li>Given are a vertex <var>v</var> of the tree and a positive integer <var>L</var>.
Let us choose some (possibly none) of the items in <var>v</var> and the ancestors of <var>v</var> so that their total weight is at most <var>L</var>.
Find the maximum possible total value of the chosen items.</li>
</ul>
<p>Here, Vertex <var>u</var> is said to be an ancestor of Vertex <var>v</var> when <var>u</var> is an indirect parent of <var>v</var>, that is, there exists a sequence of vertices <var>w_1,w_2,\ldots,w_k</var> (<var>k\geq 2</var>) where <var>w_1=v</var>, <var>w_k=u</var>, and <var>w_{i+1}</var> is the parent of <var>w_i</var> for each <var>i</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 < 2^{18}</var></li>
<li><var>1 \leq Q \leq 10^5</var></li>
<li><var>1 \leq V_i \leq 10^5</var></li>
<li><var>1 \leq W_i \leq 10^5</var></li>
<li>For the values <var>v</var> and <var>L</var> given in each query, <var>1 \leq v \leq N</var> and <var>1 \leq L \leq 10^5</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Let <var>v_i</var> and <var>L_i</var> be the values <var>v</var> and <var>L</var> given in the <var>i</var>-th query.
Then, Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>V_1</var> <var>W_1</var>
<var>:</var>
<var>V_N</var> <var>W_N</var>
<var>Q</var>
<var>v_1</var> <var>L_1</var>
<var>:</var>
<var>v_Q</var> <var>L_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>For each integer <var>i</var> from <var>1</var> through <var>Q</var>,
the <var>i</var>-th line should contain the response to the <var>i</var>-th query.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 2
2 3
3 4
3
1 1
2 5
3 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0
3
3
</pre>
<p>In the first query, we are given only one choice: the item with <var>(V, W)=(1,2)</var>. Since <var>L = 1</var>, we cannot actually choose it, so our response should be <var>0</var>.</p>
<p>In the second query, we are given two choices: the items with <var>(V, W)=(1,2)</var> and <var>(V, W)=(2,3)</var>. Since <var>L = 5</var>, we can choose both of them, so our response should be <var>3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>15
123 119
129 120
132 112
126 109
118 103
115 109
102 100
130 120
105 105
132 115
104 102
107 107
127 116
121 104
121 115
8
8 234
9 244
10 226
11 227
12 240
13 237
14 206
15 227
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>256
255
250
247
255
259
223
253
</pre></section>
</div>
</span> |
p00225 |
<H1>ãã¶ãã¬ãã€ãã</H1>
<p>
Aåããã®å®¶ã«èŠªæã®Bç·åããã£ãŠããŸããã圌ã¯3æ³ã§æã倧奜ãã§ãã圌ã¯å¹Œçšåã§ãªãã£ãããã¶ãã¬ãã€ããã(å±±æ¬çŽçŽäœè©ã»äœæ²)ãšããæãäžçæžåœã«æã£ãŠããŸãããã®æã§ã¯ã4ã€ã®ããšã°ããã¶ãã ããã¬ãã ããã€ãããããããé ã«ãããšãã«ãªã£ãŠããŠãããã«æåŸã®é³ãšæåã®é³ãåãã«ãªã£ãŠããŸããBç·åã¯ãAåããã«ãåããããªãããšãããBç·åãèšã£ãåèªããäœãããæããŠæ¬²ãããšèšãããŸããã
</p>
<p>
ããã§ãAåãããå©ããããã«ãäžããããåèªããããã®åèªããã¹ãŠäœ¿ã£ãŠãé ã«ãããšããã€ããããã®äžã§ã 第1 ã®åèªã®æåã®æåãšæçµã®åèªã®æåŸã®æåãåãã§ããããã«ã§ãããåŠããå€å®ããããã°ã©ã ãäœæããŸãããã
</p>
<p>
<var>n</var> åã®åèªãå
¥åãšãããããã®åèªã®çµãããããšããäœæã§ãããåŠããå€å®ããå¯èœãªå Žåã¯OK ãšãäžå¯èœãªå Žå㯠NG ãšåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã
åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var>
<var>word<sub>1</sub></var>
<var>word<sub>2</sub></var>
:
<var>word<sub>n</sub></var>
</pre>
<p>
1 è¡ç®ã«åèªã®åæ° <var>n</var> (2 ≤ <var>n</var> ≤ 10000) ãäžããããŸããç¶ã <var>n</var> è¡ã« <var>n</var> åã®åèª <var>word<sub>i</sub></var> (32 æå以äžã®åè§è±å°æåã ããããªãæåå) ãäžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
å
¥åããŒã¿ã»ããããšã«ãå€å®çµæãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
5
apple
yellow
georgia
king
email
7
apple
yellow
georgia
king
email
wink
lucky
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
NG
OK
</pre>
|
p02218 | <span class="lang">
<span class="lang-ja">
<h1>G: äžçªé ãçº</h1>
<div class="part">
<section>
<h3>å顿</h3><p>$N$ åã®çºãš $N-1$ åã®éããããŸãã</p>
<p>ãã¹ãŠã®çºãšéã«ã¯ãããã $1$ ãã $N$, $1$ ãã $N-1$ ã®çªå·ãã€ããŠããŸãã</p>
<p>é $i$ ã¯çº $a_i$ ãšçº $b_i$ ãè·é¢ $d_i$ ã§åæ¹åã«ã€ãªãã§ããŸãã</p>
<p>æåã¯ãã¹ãŠã®éãéè¡å¯èœãªç¶æ
ã§ãããã©ã®çºãããããã€ãã®éãéãããšã§ãã¹ãŠã®çºã«è¡ãããšãã§ããŸãã</p>
<p>ããã°ãããã¯æåãçº $1$ ã«ããŸãã</p>
<p>$Q$ åã®ã¯ãšãªãäžããããã®ã§é çªã«åŠçããŠãã ãããã¯ãšãªã¯ $3$ çš®é¡ããã以äžã®åœ¢åŒã§äžããããŸãã</p>
<ul>
<li>ã¯ãšãª $1$ : <code>1 x</code> â ããã°ããããçº $x$ ã«ç§»åããããã ãããã®ã¯ãšãªæç¹ã§ãããã°ããããããçºãšçº $x$ ã¯éè¡å¯èœãª $1$ ã€ã®éã§çŽæ¥ã€ãªãããŠããããšãä¿èšŒãããã</li>
<li>ã¯ãšãª $2$ : <code>2 y</code> â é $y$ ãå°éãããããã ãããã®ã¯ãšãªæç¹ã§ãé $y$ ã¯éè¡å¯èœã§ããããšãä¿èšŒãããã</li>
<li>ã¯ãšãª $3$ : <code>3 z</code> â é $z$ ãéè¡å¯èœã«ãªãããã ãããã®ã¯ãšãªæç¹ã§ãé $z$ ã¯å°éãããŠããããšãä¿èšŒãããã</li>
</ul>
<p>ããã«ãåã¯ãšãªãè¡ã£ãçŽåŸã«ãããã°ãããããã®æç¹ã§éè¡å¯èœãªéã®ã¿ã䜿ã£ãŠå°éå¯èœãªçºã®ãã¡ãããã°ããããããçºããäžçªé ãçºã®çªå·ãæé ã§ãã¹ãŠåºåããŠãã ããã</p>
</section>
</div>
<div class="part">
<section>
<h3>å¶çŽ</h3><ul>
<li>$1 \leq N \leq 2 \times 10^5$</li>
<li>$1 \leq a_i, b_i \leq N$, $a_i \neq b_i$</li>
<li>$1 \leq d_i \leq 10^6$</li>
<li>$1 \leq Q \leq 2 \times 10^5$</li>
<li>ã¯ãšãª $1$ ã«ãããŠã$1 \leq x \leq N$ ãæºããããŸãããã®ã¯ãšãªæç¹ã§ãããã°ããããããçºãšçº $x$ ã¯éè¡å¯èœãª $1$ ã€ã®éã§çŽæ¥ã€ãªãããŠããã</li>
<li>ã¯ãšãª $2$ ã«ãããŠã$1 \leq y \leq N-1$ ãæºããããŸãããã®ã¯ãšãªæç¹ã§ãé $y$ ã¯éè¡å¯èœã§ããã</li>
<li>ã¯ãšãª $3$ ã«ãããŠã$1 \leq z \leq N-1$ ãæºããããŸãããã®ã¯ãšãªæç¹ã§ãé $z$ ã¯å°éãããŠããã</li>
<li>$i$ çªç®ã®ã¯ãšãªã§åºåãã¹ãçºã®åæ°ã $c_i$ ãšãããšãã$\sum_{i=1}^{Q}c_i \leq 4 \times 10^5$ ãæºããã</li>
<li>å
¥åã¯ãã¹ãп޿°ã§ããã</li>
</ul>
</section>
</div>
<hr />
<div class="io-style">
<div class="part">
<section>
<h3>å
¥å</h3><p>以äžã®åœ¢åŒã§æšæºå
¥åããäžããããã</p>
<pre>$N$
$a_1$ $b_1$ $d_1$
$a_2$ $b_2$ $d_2$
$:$
$a_{N-1}$ $b_{N-1}$ $d_{N-1}$
$Q$
$Query_1$
$Query_2$
$:$
$Query_Q$
</pre>
<p>$Query_i$ ã¯å顿ã«ãã $3$ çš®é¡ã®ã¯ãšãªã®ããããã®åœ¢åŒã§äžããããã</p>
</section>
</div>
<div class="part">
<section>
<h3>åºå</h3><p>$Q$ è¡åºåããã
$i$ è¡ç®ã«ã¯ã$i$ çªç®ã¯ãšãªåŸã®åºåãã¹ãçºã®çªå·ãæé ã§ $v_1$, $v_2$, $...$, $v_c$ ã® $c$ åã§ãããšãã以äžã®ããã«ç©ºçœåºåãã§åºåããã</p>
<pre>$c$ $v_1$ $v_2$ $...$ $v_c$
</pre>
</section>
</div>
</div>
<hr />
<div class="part">
<section>
<h3>å
¥åäŸ 1</h3><pre>6
2 4 1
1 2 1
4 6 1
2 3 1
4 5 1
5
2 5
2 3
1 2
3 5
1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>åºåäŸ 1</h3><pre>1 6
2 3 4
3 1 3 4
1 5
2 1 3
</pre>
<ul>
<li>
<p>$1$ ã€ç®ã®ã¯ãšãªã§ãé $5$ ãå°éãããŸãããã®çŽåŸã«ãããã°ããããå°éå¯èœãªçºã¯ $1$, $2$, $3$, $4$, $6$ ã§ãããããã°ããããããçº $1$ ããã®è·é¢ã¯ãããã $0$, $1$, $2$, $2$, $3$ ãªã®ã§ãçãã¯çº $6$ ã«ãªããŸãã</p>
</li>
<li>
<p>$2$ ã€ç®ã®ã¯ãšãªã§ãé $3$ ãå°éãããŸãããã®çŽåŸã«ãããã°ããããå°éå¯èœãªçºã¯ $1$, $2$, $3$, $4$ ã§ãããããã°ããããããçº $1$ ããã®è·é¢ã¯ãããã $0$, $1$, $2$, $2$ ãªã®ã§ãçãã¯çº $3$, $4$ ã«ãªããŸãã</p>
</li>
<li>
<p>$3$ ã€ç®ã®ã¯ãšãªã§ãããã°ãããã¯çº $2$ ã«ç§»åããŸãããã®çŽåŸã«ãããã°ããããå°éå¯èœãªçºã¯ $1$, $2$, $3$, $4$ ã§ãããããã°ããããããçº $2$ ããã®è·é¢ã¯ãããã $1$, $0$, $1$, $1$ ãªã®ã§ãçãã¯çº $1$, $3$, $4$ ã«ãªããŸãã</p>
</li>
<li>
<p>$4$ ã€ç®ã®ã¯ãšãªã§ãé $5$ ãéè¡å¯èœã«ãªããŸãããã®çŽåŸã«ãããã°ããããå°éå¯èœãªçºã¯ $1$, $2$, $3$, $4$, $5$ ã§ãããããã°ããããããçº $2$ ããã®è·é¢ã¯ãããã $1$, $0$, $1$, $1$, $2$ ãªã®ã§ãçãã¯çº $5$ ã«ãªããŸãã</p>
</li>
<li>
<p>$5$ ã€ç®ã®ã¯ãšãªã§ãããã°ãããã¯çº $4$ ã«ç§»åããŸãããã®çŽåŸã«ãããã°ããããå°éå¯èœãªçºã¯ $1$, $2$, $3$, $4$, $5$ ã§ãããããã°ããããããçº $4$ ããã®è·é¢ã¯ãããã $2$, $1$, $2$, $0$, $1$ ãªã®ã§ãçãã¯çº $1$, $3$ ã«ãªããŸãã</p>
</li>
</ul>
</section>
</div>
<hr />
<div class="part">
<section>
<h3>å
¥åäŸ 2</h3><pre>5
3 4 1
2 1 1
4 5 1
3 2 1
6
2 2
3 2
1 2
1 3
2 4
1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>åºåäŸ 2</h3><pre>1 1
1 5
1 5
2 1 5
1 5
2 3 5
</pre></section>
</div>
</span>
</span>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.