id
stringlengths 6
6
| slug_name
stringlengths 1
105
| pretty_content
stringlengths 1
27.2k
| test_cases
sequencelengths 1
1
|
---|---|---|---|
p00300 | Yuekis' Audio Room |
<h1>æçæ°ã®ãªãŒãã£ãªã«ãŒã </h1>
<p>
æ°åŠè
ã§ããæçæ°ã®è¶£å³ã¯é³æ¥œéè³ã§ã家ã«å¿µé¡ã®ãªãŒãã£ãªã«ãŒã ãäœããŸãããå®æãããªãŒãã£ãªã«ãŒã ã§ãå人ãæããŠãæ«é²ç®äŒãéããããšèããŠããŸããå
šå¡ã«ã§ããã ãè¯ãé³ã§èŽããŠãããããã®ã§ãéšå±ã®äžã®äœãæãã§é³ãèšæž¬ããå人ãã¡ã®äœçœ®ã§ã®é³ã®è³ªãèšç®ããã€ããã§ãã
</p>
<p>
èšæž¬ç¹ã¯ãäžã®å³ã®å匧ãšç·åã®äº€ç¹ã§ãã 1 çªãã 35 çªãŸã§ã®ç¹ããéžæããŸããïŒã€ã®ç·åäžã«ããç¹ã¯ããªãŒãã£ãªã·ã¹ãã ããã®è·é¢ã 100ïœïœãã 500ïœïœãŸã§ 100ïœïœãã€é¢ããŠäžŠãã§ããŸããïŒã€ã®å匧ç¶ã«ããç¹ã¯ããã£ãšãå³ã®ãã®ïŒ1 çªãã 5 çªãŸã§ã®ç¹ïŒããåæèšåãã«ã0°ãã 180°
ã®ç¯å²ã§ 30°床å»ã¿ã«äžŠãã§ããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_audio1">
</center>
<br>
<p>
ãã®ãããªå匧ãšç·åã«å²ãŸããé åå
ã®ã©ããã«å人ãå±
ãããšã«ãªãã®ã§ãå人ã®å±
ãäœçœ®ã«ãã£
ãŠå¿
èŠãªèšæž¬ç¹ãéžæããŸããå人ã®äœçœ®ã¯ãå匧ã«æ²¿ã£ãŠåæèšåãã«æž¬ã£ãè§åºŠãšãªãŒãã£ãªã·ã¹
ãã ããã®è·é¢ã§äžããããŸããå¿
èŠãªèšæž¬ç¹ã¯ä»¥äžã®ããã«ïŒç¹ããïŒç¹ããïŒç¹ãéžã°ããŸãã
</p>
<table>
<tr valign="top">
<td valign="top">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_audio2"></td>
<td valign="top">
å人ãã¡ããã©èšæž¬ç¹ã®äœçœ®ã«ããã°ããã®ïŒç¹ãéžã³ãŸãããã®å³ã®äŸã®å Žåãéžã°ããã®ã¯ 23 çªã®ç¹ã§ãã
</td>
</tr>
<tr valign="top">
<td valign="top">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_audio3"></td>
<td valign="top">
å人ãå匧ïŒãŸãã¯ç·åïŒã®äžã«ã¡ããã©ä¹ã£ãŠããã°ããã®å匧ïŒãŸãã¯ç·åïŒäžã«ãããå人ã«æãè¿ãïŒç¹ãéžã³ãŸãããã®å³ã®äŸã®å Žåãéžã°ããã®ã¯ 18 çªãš 23 çªã®ç¹ã§ãã
</td>
</tr>
<tr valign="top">
<td valign="top">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_audio4"></td>
<td valign="top">
å人ãå匧ãšç·åã«ãã£ãŠå²ãŸããåºç»ã®å
åŽïŒå匧ãç·åã®äžã§ã¯ãªãïŒã«ããã°ãåºç»ãäœã£ãŠããïŒç¹ãéžã³ãŸãããã®å³ã®äŸã®å Žåãéžã°ããã®ã¯ 17ã18ã22ã23 çªã®ç¹ã§ãã
</td>
</tr>
</table>
<br>
<p>
æçæ°ãå©ããããã«ãå¿
èŠãªèšæž¬ç¹ã®çªå·ãæ±ããããã°ã©ã ãäœæããŠãã ããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>r<sub>1</sub></var> <var>t<sub>1</sub></var>
<var>r<sub>2</sub></var> <var>t<sub>2</sub></var>
:
<var>r<sub>N</sub></var> <var>t<sub>N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«å人ã®æ° <var>N</var> (1 ≤ <var>N</var> ≤ 50)ãäžãããããç¶ã <var>N</var> è¡ã«ãå人ã®äœçœ®ãäžãããããå人ã®äœçœ® <var>r<sub>i</sub></var> (100 ≤ <var>r<sub>i</sub></var> ≤ 500) ã¯ãªãŒãã£ãªã·ã¹ãã ããã®è·é¢ãè¡šãæŽæ°ã<var>t<sub>i</sub></var> (0 ≤ <var>t<sub>i</sub></var> ≤ 180) ã¯å匧ã«æ²¿ã£ãŠåæèšåãã«æž¬ã£ãè§åºŠãè¡šãæŽæ°ã§ããã
</p>
<h2>åºå</h2>
<p>
åå人ã®äœçœ®ã«ã€ããŠãèšæž¬ç¹ã®çªå·ãæé ã§ïŒè¡ã«åºåããã
</p>
<h2>å
¥åºåäŸ</h2>
<h2>å
¥åäŸ </h2>
<pre>
4
300 120
300 105
250 105
250 90
</pre>
<h2>åºåäŸ</h2>
<pre>
23
18 23
17 18 22 23
17 18
</pre>
| [
[
"4\n300 120\n300 105\n250 105\n250 90\n",
"4\n300 120\n300 105\n250 105\n250 90\n"
]
] |
p00301 | Symmetric Ternary Number |
<h1>察称ïŒé²æ°</h1>
<p>
1 ã°ã©ã ã3 ã°ã©ã ã9 ã°ã©ã ã27 ã°ã©ã ã®ããããïŒã€ãã€ããã°ã倩ã³ãã䜿ã£ãŠ 1 ã°ã©ã ãã 40ã°ã©ã ãŸã§ 1 ã°ã©ã å»ã¿ã§éããããšãç¥ãããŠããŸããããšãã°ã倩ã³ãã®äžæ¹ã®ç¿ã«éããéããããã®ãš 3 ã°ã©ã ã®ããããèŒããããäžæ¹ã®ç¿ã« 27 ã°ã©ã ãš 1 ã°ã©ã ã®ããããèŒããŠé£ãåãã°ãéããããã®ã®éã㯠27-3+1=25 ã°ã©ã ã ãšããããŸãã ããã«ã1(=3<sup>0</sup>)ã°ã©ã ã3<sup>1</sup> ã°ã©ã ã... ã3<sup>n-1</sup> ã°ã©ã ã3<sup>n</sup> ã°ã©ã ãŸã§ã®ããããïŒã€ãã€ããã°ã倩ã³ãã䜿ã£ãŠ(3<sup>n+1</sup>-1)/2ã°ã©ã ãŸã§éããããšãç¥ãããŠããŸãããŸãã倩ã³ããé£ãåããããªãããã®çœ®ãæ¹ã¯äžéããããªãããšãç¥ãããŠããŸãã
</p>
<p>
éããããã®ãšãããã倩ã³ãã«çœ®ããŠãé£ãåããããªãããã®çœ®ãæ¹ãæååã§è¡šãããšãã§ããŸãã3<sup><var>i</var></sup> ã°ã©ã ã®ããããéããããã®ãšåãç¿ã«èŒãããšãã¯ã<span>-</span>ããããäžæ¹ã®ç¿ã«èŒãããšãã¯ã<span>+</span>ããã©ã¡ãã«ãèŒããªãã£ããšãã¯ã0ããæååã®å³ç«¯ããiçªç®ã«æžããŸãïŒå³ç«¯ãïŒçªç®ãšæ°ããŸãïŒãããšãã°ãå
ã»ã©ã® 25 ã°ã©ã ã®äŸã¯ <span>+0-+</span> ãšè¡šãããŸãã
</p>
<p>
ããã§ã¯ãéããããã®ã®éããäžãããããšãã倩ã³ããé£ãåããããªãããã®çœ®ãæ¹ãè¡šãæååãåºåããããã°ã©ã ãäœæããŠãã ããããã ããïŒã®ã¹ãä¹ã°ã©ã ã®ãããã¯ãã©ã®ãããªéãã®ãã®ã§ãå¿
ãïŒã€ãããã®ãšããŸãã
</p>
<p>
ïŒè£è¶³ïŒ 察称ïŒé²æ°ã«ã€ããŠïŒ<br>
éããããã®ã®éããwã®ãšãããããã®çœ®ãæ¹ãè¡šãæååã¯wã®å¯Ÿç§°ïŒé²æ°ã«ãªã£ãŠããŸãã察称ïŒé²æ°ãšã¯ãïŒã®ã¹ãä¹ã®æ°ã§äœåããè¡ããåäœã«æ° 1ã0ã-1 ãè¡šãæåãæžãããšã§è¡šããæ°ã®ããšã§ããäžã®æååã§ã¯ãæåã<span>+</span>ããã<span>0</span>ããã<span>-</span>ããããããæ° 1ã0ã-1 ã«å¯Ÿå¿ããŸããããšãã°ã25 ã°ã©ã ã®ãã®ãéããšãã®ãããã®çœ®ãæ¹ã <span>+0-+</span> ã§ãã察称ïŒé²æ°ãè¡šãæ°ã¯ã1 × 3<sup>3</sup> + 0 × 3<sup>2</sup> - 1× 3<sup>1</sup> + 1 × 3<sup>0</sup> = 25 ãšãªããŸãã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>w</var>
</pre>
<p>
<var>w</var> (1 ≤ <var>w</var> ≤ 100000) ã¯éããããã®ã®éããè¡šãæŽæ°ã§ããã
</p>
<h2>åºå</h2>
<p>
ãããã®çœ®ãæ¹ãè¡šãæååãåºåããããã ãæååã®å·Šç«¯ã 0 ã«ããŠã¯ãªããªãã
</p>
<h2>å
¥åºåäŸ </h2>
<h2>å
¥åäŸïŒ</h2>
<pre>
25
</pre>
<h2>åºåäŸïŒ</h2>
<pre>
+0-+
</pre>
<br>
<h2>å
¥åäŸïŒ </h2>
<pre>
2
</pre>
<h2>åºåäŸïŒ</h2>
<pre>
+-
</pre>
<br>
<h2>å
¥åäŸïŒ </h2>
<pre>
5
</pre>
<h2>åºåäŸïŒ</h2>
<pre>
+--
</pre>
| [
[
"25\n",
"25\n"
]
] |
p00302 | Nisshinkan Marathon Club |
<h1>ããã·ã³é€šãã©ãœã³éš</h1>
<p>
ã¢ã€ã
åžç«ããã·ã³é€šã¯ãææŠäž¡éãæ²ããæŽå²ããåŠæ ¡ã§ããããã·ã³é€šãã©ãœã³éšã¯ç±è¡æå°ã§æåã§ããã決ããããç·Žç¿æéã®éãåšåã³ãŒã¹ãã²ãããèµ°ããšãã鬌ã®ç¹èšãè¡ããŸãããã®ãšããè±æ°Žçç¶ã§åããéšå¡ãããªãããã«ãéšå¡ã®å®åã«åãããŠé£²ã¿ç©ãæäŸãã絊氎æãèšããŠããŸãã
</p>
<p>
åéšå¡ãïŒåäœæéãããã«èµ°ããè·é¢(ããŒã¹)ã¯éšå¡ããšã«æ±ºãŸã£ãŠãããå
šå¡ãïŒåäœæéããšã«å¿
ã絊氎ã§ããããã«çµŠæ°Žæãèšããããã§ç¹èšãè¡ããŸããéšå¡ã¯ 1 åäœæéã§çãã絊氎æã§å¿
ãäžèº«ã®å
¥ã£ã容åšãåãããã®ãŸãŸèµ°ãç¶ããŸããããã«ã次ã®ïŒåäœæéã§çãã絊氎æã§ç©ºã®å®¹åšã眮ããäžèº«ã®å
¥ã£ã容åšãåã£ãŠèµ°ãç¶ãããšããããšãç¹°ãè¿ããŸãããŸãã空ã®å®¹åšã¯ã眮ããŠãã 1 åäœæéã®æç¹ã§é£²æãè£å
ããããã®ç¬éãã誰ã«ã§ãæäŸã§ããããã«ãªããŸãã
</p>
<p>
éšå¡ã¯å
šå¡åãå°ç¹ããã容åšãæããã«åºçºããŸãã決ããããç·Žç¿æéãŸã§èµ°ããšç·Žç¿ãçµããŸã(ãã®ãšãã絊氎ãå¿
èŠã§ã)ãè€æ°ã®éšå¡ãåæã«åã絊氎æã«å°çããå Žåãããã®ã§ãäžãæã®çµŠæ°Žæã§åæã«è€æ°ã®å®¹åšãå¿
èŠã«ãªãããšããããŸãã
</p>
<p>
鬌ã®ç¹èšãå®å
šã«è¡ãããã«ãæäœããã€ã®çµŠæ°Žå®¹åšãå¿
èŠã«ãªããæ±ããããã°ã©ã ãäœæããŠãã ããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var> <var>R</var> <var>T</var>
<var>p<sub>1</sub></var>
<var>p<sub>2</sub></var>
:
<var>p<sub>N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«éšå¡ã®æ° <var>N</var> (1 ≤ <var>N</var> ≤ 100)ãåšåã³ãŒã¹ã®é·ã <var>R</var> (1 ≤ <var>R</var> ≤ 1000)ã決ããããç·Žç¿æé <var>T</var> (1 ≤ <var>T</var> ≤ 1000) ãäžãããããç¶ã <var>N</var> è¡ã«ãéšå¡ <var>i</var> ã®ããŒã¹ <var>p<sub>i</sub></var> (1 ≤ <var>p<sub>i</sub></var> ≤ 1000) ãäžããããã
</p>
<h2>åºå</h2>
<p>
æäœããã€ã®çµŠæ°Žå®¹åšãå¿
èŠã«ãªãããïŒè¡ã«åºåããã
</p>
<h2>å
¥åºåäŸ</h2>
<h2>å
¥åäŸïŒ </h2>
<pre>
1 10 20
1
</pre>
<h2>åºåäŸïŒ</h2>
<pre>
11
</pre>
<br>
<h2>å
¥åäŸïŒ </h2>
<pre>
2 5 12
1
2
</pre>
<h2>åºåäŸïŒ</h2>
<pre>
8
</pre>
| [
[
"1 10 20\n1\n",
"1 10 20\n1\n"
]
] |
p00303 | Deadlock |
<h1>ãããããã¯ãæ€åºãã</h1>
<p>
ã³ã³ãã¥ãŒã¿ã«ããããããŒã¿ããŒã¹ããšã¯ãæ
å ±ã管çããããã®å
¥ãç©ã§ããããŒã¿ããŒã¹ãããžã¡ã³ãã·ã¹ãã (DBMS)ããšã¯ããã®ç®¡çãããä»çµã¿ã§ããè€æ°ã®ãŠãŒã¶ãå©çšããããŒã¿ããŒã¹ã§ã¯ãDBMS ã¯æ
éã«æ§ç¯ããå¿
èŠããããŸãã
</p>
<p>
äŸãã°ãå庫ããååãïŒã€åãåºãã人ããããŒã¿ããŒã¹ã«å¯ŸããŠä»¥äžã®åŠçãè¡ããšããŸãããã<br>
(1) ååã®åæ° <var>N</var> ãããŒã¿ããŒã¹ããèªãã<br>
(2) æ°ããªååã®åæ° <var>N</var>-1 ãããŒã¿ããŒã¹ã«æžã蟌ãã<br>
</p>
<p>
ãŠãŒã¶ïŒã(1)ãçµããŠ(2)ãå§ããåã«ãå¥ã®ãŠãŒã¶ïŒãå庫ããååãåãåºããŠ(1)ãè¡ã£ããšããŸãããŠãŒã¶ïŒããŠãŒã¶ïŒãšåãåæ°ãèªãã®ã§ãïŒäººã(2)ãçµãããšãã«ã¯ååã¯ïŒåæžãã®ã«ããŒã¿ããŒã¹äžã§ã¯ïŒåããæžããªããšããããããªçµæã«ãªããŸãããã®ãããªåé¡ãé²ãããã«ãDBMS ã¯ç¹å®ã®ããŒã¿ãæäœäžã®ãŠãŒã¶ã«ããã®ããŒã¿ããããã¯ãããæš©å©ãäžããŸããããã¯ãããŠããã°ãä»ã®ãŠãŒã¶ã¯ãã®å€ãæäœã§ããªããªãã®ã§ãããããªçµæãè¿ãããšã¯ãªããªããŸãã
</p>
<p>
ããã§å®å
šã«æäœã§ããããšã¯ä¿èšŒãããŸãããä»åºŠã¯å¥ã®åé¡ãèµ·ãããŸããäŸãã°ããŠãŒã¶ïŒãšãŠãŒã¶ïŒã以äžã®ãããªé çªã§ããŒã¿ïŒ¡ãšïŒ¢ãããã¯ããããšãããã©ããªãã§ããããïŒ<br>
(1) ãŠãŒã¶ïŒãããŒã¿ïŒ¡ã®ããã¯ãè©Šã¿ã â æåïŒããŒã¿ïŒ¡ãããã¯äžã«ãªãïŒ<br>
(2) ãŠãŒã¶ïŒãããŒã¿ïŒ¢ã®ããã¯ãè©Šã¿ã â æåïŒããŒã¿ïŒ¢ãããã¯äžã«ãªãïŒ<br>
(3) ãŠãŒã¶ïŒãããŒã¿ïŒ¢ã®ããã¯ãè©Šã¿ã â ããŒã¿ïŒ¢ãããã¯äžãªã®ã§ãŠãŒã¶ïŒã¯åŸ
ã€<br>
(4) ãŠãŒã¶ïŒãããŒã¿ïŒ¡ã®ããã¯ãè©Šã¿ã â ããŒã¿ïŒ¡ãããã¯äžãªã®ã§ãŠãŒã¶ïŒã¯åŸ
ã€<br>
<br>
(4)ãå®è¡ããæç¹ã§ã¯ããŠãŒã¶ïŒãããŠãŒã¶ïŒããããã¯ããŠããã®ã§ã(3)(4)ã¯æ°žä¹
ã«æåããŸã
ãããããããããããã¯ããšåŒã³ãŸããDBMS ã¯ãããæ€åºããªããã°ãªããŸããã
</p>
<p>
ããæç¹ã§ãããããã¯ãèµ·ããŠãããã©ããã¯ããã®æç¹ã§ã®ãã¹ãŠã®ãŠãŒã¶ãšããŒã¿ã®äŸåé¢ä¿ãæžãã埪ç°ãã§ããŠãããã©ããã§å€æã§ããŸããäŸåé¢ä¿ã¯ïŒãŠãŒã¶ãããŒã¿ãããã¯æžã¿ã®å Žåã¯ããŒã¿ãããŠãŒã¶ã®åãã«ç¢å°ãããŠãŒã¶ãããŒã¿ã®ããã¯ãè©Šè¡ããŠããŠåŸ
ã¡ç¶æ
ã«ãªã£ãŠããå Žåã¯ãŠãŒã¶ããããŒã¿ã®åãã«ç¢å°ãæžãããšã§è¡šããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_dbms">
</center>
<br>
<p>
äžã®(1)ãã(4)ã®äŸã§ããã°ã(4)ãå®è¡ããæç¹ã§ã®äŸåé¢ä¿ã¯å³äžã®ãããªå³ã«ãªããŸãããã®ãšããç¢å°ã®æ¹åã«é²ããšããŠãŒã¶ïŒâããŒã¿ïŒ¢âãŠãŒã¶ïŒâããŒã¿ïŒ¡âãŠãŒã¶ïŒãšãã埪ç°ãã§ããŠããããããããããã¯ãèµ·ããŠããããšãããããŸããDBMS ã®èŠåŽãäœéšãããããããªãã«ããã§ãã£ãŠãããããã®ã¯ããã®ãããªãããããã¯ãæ€åºããããã°ã©ã ãäœæããããšã§ãã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>rel<sub>1</sub></var>
<var>rel<sub>2</sub></var>
:
<var>rel<sub>N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ãŠãŒã¶ãšããŒã¿ã®äŸåé¢ä¿ã®æ° <var>N</var> (1 ≤ <var>N</var> ≤ 1000) ãäžãããããç¶ã <var>N</var> è¡ã«ããŠãŒã¶ãšããŒã¿ã®äŸåé¢ä¿ <var>rel<sub>i</sub></var> ãäžãããããäŸåé¢ä¿ã¯ lock ãš wait ã®ïŒçš®é¡ãããå <var>rel<sub>i</sub></var> ã¯ä»¥äžã®ããããã®åœ¢åŒã§äžããããã
</p>
<pre>
u lock d
</pre>
<p>
ãŸãã¯
</p>
<pre>
u wait d
</pre>
<p>
<span>u lock d</span> ã¯ããŠãŒã¶ <var>u</var> (1 ≤ <var>u</var> ≤ 100) ããããŒã¿ <var>d</var> (1 ≤ <var>d</var> ≤ 100) ãããã¯æžã¿ã§ããããšãè¡šãã<br>
<span>u wait d</span> ã¯ããŠãŒã¶ <var>u</var> (1 ≤ <var>u</var> ≤ 100) ããããŒã¿ <var>d</var> (1 ≤ <var>d</var> ≤ 100) ã®ããã¯ãè©Šè¡ããŠããŠåŸ
ã¡ç¶æ
ã§ããããšãè¡šãã<br>
<br>
ãã ããå
¥åã¯ä»¥äžã®æ¡ä»¶ãæºãããŠãããšä»®å®ããŠããã
</p>
<ul>
<li> ããã¯ãããŠããªãããŒã¿ã«å¯ŸããŠããŠãŒã¶ãåŸ
ã¡ç¶æ
ã§ã¯ãªãã</li>
<li> äºäººä»¥äžã®ãŠãŒã¶ã«ããã¯ãããŠããããŒã¿ã¯ãªãã</li>
<li> ãŠãŒã¶èªèº«ãããã¯ããŠããããŒã¿ã«å¯ŸããŠãåŸ
ã¡ç¶æ
ã§ã¯ãªãã</li>
<li> åãäŸåé¢ä¿ã¯äžããããªãã</li>
</ul>
<h2>åºå</h2>
<p>
ãããããã¯ãçºçããŠãããªã 1ãçºçããŠããªããªã 0 ãïŒè¡ã«åºåããã
</p>
<h2>å
¥åºåäŸ </h2>
<h2>å
¥åäŸïŒ </h2>
<pre>
4
1 lock 1
2 lock 2
1 wait 2
2 wait 1
</pre>
<h2>åºåäŸïŒ</h2>
<pre>
1
</pre>
<br>
<h2>å
¥åäŸïŒ </h2>
<pre>
4
3 lock 3
2 wait 3
3 lock 4
2 wait 4
</pre>
<h2>åºåäŸïŒ</h2>
<pre>
0
</pre>
| [
[
"4\n1 lock 1\n2 lock 2\n1 wait 2\n2 wait 1\n",
"4\n1 lock 1\n2 lock 2\n1 wait 2\n2 wait 1\n"
]
] |
p00304 | New Drug Development |
<h1>æ°è¬éçº</h1>
<p>
è±äžå士ã¯æ¥ã
ç 究ãè¡ããæ°ããè¬ãéçºããããšããŠããŸããæ°è¬ãéçºããããã«ã¯ãè²ã
ãªç©è³ªãçµã¿åãããŠè¬ãäœãè©Šéšãè¡ããè¯ãè¬ãèŠã€ããªããã°ãªããŸãããæ§ã
ãªçµã¿åãããè©ŠããŠãããã¡ã«ãè±äžå士ã¯ç©è³ªã®çµã¿åããã暹圢å³ã§è¡šããããšãçªãæ¢ããŸããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_drugDevelopment">
</center>
<br>
<p>
å³ã®å³ã¯ãè¬ã®èª¿åãè¡šã暹圢å³ã®äŸã§ããå³ã®äžã§äžžãå²ãŸãããã®ãç©è³ªããŒããäžè§ã§å²ãŸãããã®ãéžæããŒããšåŒã³ãŸããç©è³ªããŒãã¯ç©è³ªãè¡šããŸããéžæããŒãã¯ãç©è³ªã®éžæãè¡šããã®ã§ãããèªäœã¯ç©è³ªãè¡šããŸãããéžæããŒãã«ã¯ or åïŒ∨ãä»ãããã®ïŒãš alt åïŒ⇔ãä»ãããã®ïŒã®ïŒçš®é¡ããããŸãããŸã ? ãä»ããããŒãã¯ãããããªãã·ã§ã³ã§ããããšãè¡šããŸãããã ããéžæããŒãã®åããŒãïŒäžåãã®æã®å
ã«ããããŒãïŒããªãã·ã§ã³ã«ãªãããšã¯ãããŸããã暹圢å³ã«çŸããç°ãªãç©è³ªããŒãã¯ãããããå¥ã®ç©è³ªãè¡šããã®ãšããŸãã
</p>
<p>
è¬ã®èª¿åãè¡ããšãã¯ã暹圢å³ã®äžçªäžã®ããŒãããã¯ãããŠãé ã
ã«ããŒãããã©ã£ãŠãããªãã以äžã®ããã«ããŠããŒããéžãã§ãããŸãã
</p>
<ul>
<li> ãã©ãçããããŒãããªãã·ã§ã³ã§ãªãç©è³ªããŒããªãããããå¿
ãéžã¶ã</li>
<li> ãªãã·ã§ã³ã®ç©è³ªããŒããªãããããéžã¶ãã©ããã¯ä»»æã</li>
<li> or åã®éžæããŒããªãããã®åããå°ãªããšãäžã€ãéžã¶ããã ãããã®éžæããŒãããªãã·ã§ã³ãªããåãäžã€ãéžã°ãªããŠãããã</li>
<li> alt åã®éžæããŒããªãããã®åããäžã€ã ããéžã¶ããã ãããã®éžæããŒãããªãã·ã§ã³ãªããåãéžã°ãªããŠãããã</li>
</ul>
<p>
ããããŒããéžã°ãããšãã ãããã®ããŒãããäžã«åããæããããããã©ã£ãŠãããŸããéžã°ããªããã°ããããããã©ãããšã¯ãããŸããã
</p>
<p>
ããªãã¯è±äžå士ãããè¬ã®ç©è³ªã®çµã¿åãããè¡šã暹圢å³ãåãåããçµã¿åããã®æ°ãå
šéšã§äœéããããæ±ããããæ瀺ãããŸããã暹圢å³ãäžãããããšããçµã¿åããã®ç·æ°ãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>node<sub>1</sub></var>
<var>node<sub>2</sub></var>
:
<var>node<sub>N</sub></var>
<var>s<sub>1</sub></var> <var>t<sub>1</sub></var>
<var>s<sub>2</sub></var> <var>t<sub>2</sub></var>
:
<var>s</var><sub><var>N</var>-1</sub> <var>t</var><sub><var>N</var>-1</sub>
</pre>
<p>
ïŒè¡ç®ã«ããŒãã®æ° <var>N</var> (1 ≤ <var>N</var> ≤ 1000) ãäžãããããç¶ã <var>N</var> è¡ã«ã<var>i</var> çªç®ã®ããŒãã®æ
å ± <var>node<sub>i</sub></var> ãäžãããããïŒçªç®ã®ããŒãã暹圢å³ã®äžçªäžã®ããŒããšãããç¶ã <var>N</var>-1 è¡ã« <var>s<sub>i</sub></var> çªç®ã®ããŒããããã®åã§ãã <var>t<sub>i</sub></var> çªç®ã®ããŒã (1 ≤ <var>s<sub>i</sub></var> ≠ <var>t<sub>i</sub></var> ≤ <var>N</var>) ãžåããæãäžããããã<var>t</var><sub>1</sub> ãã <var>t</var><sub><var>N</var>-1</sub> ãŸã§ã«ã¯ã2 ãã <var>N</var> ãŸã§ã®æ°ãäžåºŠã ãçŸããã<br>
<br>
ããŒãã®æ
å ±ã¯ä»¥äžã®åœ¢åŒã§ããã
</p>
<ul>
<li> <span>E</span> ãªãã·ã§ã³ã§ãªãç©è³ªããŒãã</li>
<li> <span>E?</span> ãªãã·ã§ã³ã§ããç©è³ªããŒãã</li>
<li> <var>type</var> ãªãã·ã§ã³ã§ãªãéžæããŒãã<var>type</var> 㯠<span>A</span> ã <span>R</span> ã®ããããã§ã<span>A</span> 㯠altåã<span>R</span> 㯠or åãè¡šãã</li>
<li> <var>type</var><span>?</span> ãªãã·ã§ã³ã§ããéžæããŒãã<var>type</var> ã®åœ¢åŒã¯åäžã</li>
</ul>
<p>
å
¥åããåŸããã暹圢å³ã¯ã以äžã®æ¡ä»¶ãæºããã
</p>
<ul>
<li> éžæããŒãã¯ïŒã€ä»¥äžã®åããŒããæã€ã</li>
<li> éžæããŒãã®åããŒãã¯ãªãã·ã§ã³ã§ãªãã</li>
<li> 暹圢å³ã®äžçªäžã®ããŒãã¯ãªãã·ã§ã³ã§ãªãã</li>
<li> ã©ã®ããŒãã«ã€ããŠããåããŒãã®æ°ã¯ 10 ãè¶
ããªãã</li>
</ul>
<h2>åºå</h2>
<p>
äžãããã暹圢å³ããåŸããããã¹ãŠã®çµã¿åããã®ç·æ°ãïŒè¡ã«åºåããããã ããåºåãã¹ãå€ã¯éåžžã«å€§ãããªãããã®ã§ã代ããã« 1,000,000,007 ã§å²ã£ãäœããåºåããã
</p>
<h2>å
¥åºåäŸ</h2>
<h2>å
¥åäŸïŒ </h2>
<pre>
12
A
E
E
E
R?
E?
E?
E
E
E
E?
E
1 2
1 3
1 4
2 5
4 6
4 7
5 8
5 9
7 10
7 11
11 12
</pre>
<h2>åºåäŸïŒ</h2>
<pre>
11
</pre>
<br>
<h2>å
¥åäŸïŒ</h2>
<pre>
10
E
R?
E
R
E
E
A
E
E
E
1 2
1 7
2 3
2 4
4 5
4 6
7 8
7 9
7 10
</pre>
<h2> åºåäŸïŒ</h2>
<pre>
24
</pre> | [
[
"12\nA\nE\nE\nE\nR?\nE?\nE?\nE\nE\nE\nE?\nE\n1 2\n1 3\n1 4\n2 5\n4 6\n4 7\n5 8\n5 9\n7 10\n7 11\n11 12\n",
"12\nA\nE\nE\nE\nR?\nE?\nE?\nE\nE\nE\nE?\nE\n1 2\n1 3\n1 4\n2 5\n4 6\n4 7\n5 8\n5 9\n7 10\n7 11\n11 12\n"
]
] |
p00305 | Frame |
<h1>æ </h1>
<p>
ç»åã®äžããæçãªæ
å ±ãæœåºããç»åèªèã¯ã³ã³ãã¥ãŒã¿ãµã€ãšã³ã¹ã®äžã§ãéèŠãªç 究ããŒãã®ã²ãšã€ã§ããããžã¿ã«ã«ã¡ã©ãé転æ¯æŽã·ã¹ãã ãé²ç¯ã·ã¹ãã ãªã©ã«å¹
åºãå¿çšãããŠããŸãã
</p>
<p>
ãã®ãããªç 究ã®ãããã§ãç§ãã¡ã¯ç»å解æãè¡ãããã®å€ãã®ãœãããŠã§ã¢ãããã°ã©ã éã䜿ãæ§ã
ãªåŠçãè¡ãããšãã§ããŸããäžæ¹ãèªåã§ããã°ã©ã ãæžããŠè§£æããããšã§ããã®ä»çµã¿ãç¥ãã楜ããæéãéããããšãã§ããŸããããã§ã¯ãäžé¢šå€ãã£ãç»åèªèãããŠã¿ãŸãããã
</p>
<p>
ç»åãšããŠæ¬¡ã®ãããªåãã¯ã»ã«ãæŽæ°ã®å€ãæ〠<var>N</var> × <var>N</var> ã®ãã¯ã»ã«ãå
¥åãšããŠäžããããŸãããã®ç»åã®äžãããç·ã®å€ªããïŒãã¯ã»ã«ã®é·æ¹åœ¢ã®æ ïŒããïŒãïŒã€æœåºããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_frame1" width="380">
</center>
<br>
<p>
æ ãèŠããã¯ã»ã«ã®å€ã®åãæ倧ãšãªããããªæ ãæœåºããŠããã®åãå ±åããããã°ã©ã ãäœæããŠ
äžããããã ããäžã®å³ã®ããã«ã瞊ã暪ã®ãã¯ã»ã«æ°ãïŒã€ãïŒã€ã®å Žåãæ ãšã¿ãªããã®ãšããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_frame2" width="560">
</center>
<br>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>p<sub>1,1</sub></var> <var>p<sub>1,2</sub></var> ... <var>p<sub>1,N</sub></var>
<var>p<sub>2,1</sub></var> <var>p<sub>2,2</sub></var> ... <var>p<sub>2,N</sub></var>
:
<var>p<sub>N,1</sub></var> <var>p<sub>N,2</sub></var> ... <var>p<sub>N,N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«çžŠãšæšªã®ãã¯ã»ã«æ° <var>N</var> (1 ≤ <var>N</var> ≤ 300) ãäžãããããç¶ã <var>N</var> è¡ã«ã<var>i</var> è¡ <var>j</var> åç®ã®ãã¯ã»ã«ã®å€ãè¡šãæŽæ° <var>p<sub>i,j</sub></var> (-1000 ≤ <var>p<sub>i,j</sub></var> ≤ 1000)ãäžããããã
</p>
<h2>åºå</h2>
<p>
ãã¯ã»ã«å€ã®åãæ倧ãšãªããããªæ ã®ããã¯ã»ã«å€ã®åãïŒè¡ã«åºåããã
</p>
<h2>å
¥åºåäŸ</h2>
<br>
<h2>å
¥åäŸïŒ</h2>
<pre>
5
2 0 0 2 0
0 1 0 2 0
0 0 0 -1 0
0 4 0 3 0
-1 0 0 1 0
</pre>
<h2> åºåäŸïŒ </h2>
<pre>
12
</pre>
<h2>å
¥åäŸïŒ</h2>
<pre>
3
0 0 0
0 -1 0
0 0 0
</pre>
<h2>åºåäŸïŒ</h2>
<pre>
0
</pre>
| [
[
"5\n2 0 0 2 0\n0 1 0 2 0\n0 0 0 -1 0\n0 4 0 3 0\n-1 0 0 1 0\n",
"5\n2 0 0 2 0\n0 1 0 2 0\n0 0 0 -1 0\n0 4 0 3 0\n-1 0 0 1 0\n"
]
] |
p00306 | Kaguya |
<h1>ããã</h1>
<p>
ããããä»ææ«ã«ãã¯ãã¶ãïŒããæã¡äžããããŸããïŒå¹Žåã«ãã¯ãã¶ãããåž°ã£ãŠãããšãã¯ãæ¥æ¬äžãçãäžãã£ãã®ãèŠããŠãã人ãå€ããšæããŸããïŒå¹Žåã«ã¯ãããããããæã¡äžããããæã®åšããåããªããããããã®é®®æãªç»åãå°çã«éã£ãŠãããŸããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_kaguya">
</center>
<br>
<p>
äžã®å³ã¯ãå°çãåç¹ãšãã空é座æšïŒz軞ã¯çŽé¢ããåçŽã«äžããäžã«åããŠãããã®ãšããŸãïŒã«ãæã®è»éãšããã€ãã®æã®äœçœ®ãæã®åšããåããããã®è»éãæãããã®ã§ããæã®è»éã¯ãx軞ãšy軞ãéãå¹³é¢äžã«ãããåç¹ãäžå¿ãšããåãšããŸããæã®åšããåããããã®è»éã¯ãx軞ãšz軞ãéãå¹³é¢ã«å¹³è¡ãªå¹³é¢äžã«ããåãšãããã®äžå¿ã¯æã®äžå¿ãšäžèŽããŸããæã¯ããã®è»éã«æ²¿ã£ãŠæãããç¢å°ã®æ¹åã«åã£ãŠãããã®ãšããŸãã
</p>
<p>
å³ã®å³ã§ãæã®äœçœ®ã¯ïŒ¡ïŒïŒ¢ïŒïŒ£ã®ïŒã€ãæãããŠããŸããæã暪åãçŽç·ããããã®è»éã§ãããããã¯æã®åšããåã£ãŠããã®ã§è»éã¯åã§ãããz軞ã®æ£ã®æ¹åããèŠãŠããã®ã§ãå³ã®x軞ã«å¹³è¡ãªçŽç·ã«èŠããŸãïŒæã®äœçœ®ãå€ãã£ãŠããã€ãã«x軞ã«å¹³è¡ã§ããããšã«æ³šæããŠãã ããïŒããããã¯ããã®è»éäžã«æãããç¢å°ã®æ¹åã«åã£ãŠãããã®ãšããŸãã
</p>
<p>
ããããå°çããèŠãŠæã®è£åŽã«é ããŠããŸããšãå°çãšçŽæ¥éä¿¡ãã§ããªããªããŸãããããã®ç®¡å¶ãæ
åœããããªãã¯ãããããæã®è£åŽã«é ããæéããäžããããæéã®äžã§ã©ãã ãã«ãªãããããã°ã©ã ã§æ±ããããšããŠããŸãã
</p>
<p>
æã®å°çã«å¯Ÿããäœçœ®ãšååäœã§ã®æétãäžãããããšãããã®äœçœ®ããå§ããŠtååŸãŸã§ã®éã«ãããããæã®è£åŽã«é ããæéãæ±ããããã°ã©ã ãäœæããŠãã ããããã ããå°çãšãããã¯ç¹ãæã¯ååŸ 1800 km ã®çãšèããŸããæã¯ååŸ 380000 km ã®è»éã 2500000 ç§ã§äžåšãããããã¯æã®è¡šé¢ããé«åºŠ 100 km ã®åäžãïŒæéã§äžåšãããã®ãšããŸãããããã®æåã®äœçœ®ã¯ããããã®è»éãz座æšã§æ倧ã®å€ããšãäœçœ®ãšããŸãã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>m</var> <var>t</var>
</pre>
<p>
<var>m</var> (0 ≤ <var>m</var> < 360) ã¯æã®äœçœ®ãäžã®å³ã®x軞ã®æ£ã®éšåããy軞ã®æ£ã®éšåã«åãã£ãŠåæèšåãã«æž¬ã£ãè§åºŠãæŽæ°ã§è¡šãããã®ã§ããã<var>t</var> (1 ≤ <var>t</var> ≤ 10000) ã¯åã§æž¬ã£ãæéãè¡šãæŽæ°ã§ããã
</p>
<h2>åºå</h2>
<p>
ã¯ããã®äœçœ®ãã <var>t</var> åçµéãããŸã§ã®éã«ãããããæã®è£åŽã«é ããæéïŒåïŒãå®æ°ã§åºåããããã ãã誀差ããã©ã¹ãã€ãã¹ 1.0 åãè¶
ããŠã¯ãªããªãããã®æ¡ä»¶ãæºããã°å°æ°ç¹ä»¥äžäœæ¡è¡šç€ºããŠãããã
</p>
<h2>å
¥åºåäŸ </h2>
<h2>å
¥åäŸïŒ </h2>
<pre>
90 10
</pre>
<h2>åºåäŸïŒ</h2>
<pre>
0.0
</pre>
<br>
<h2>å
¥åäŸïŒ </h2>
<pre>
0 120
</pre>
<h2>åºåäŸïŒ</h2>
<pre>
47.73
</pre> | [
[
"90 10\n",
"90 10\n"
]
] |
p00307 | Net Cafe |
<h1>ãããã«ãã§</h1>
<p>
ããªãã¯ãããã«ãã§ãçµå¶ããŠããŸããä»æ¥ããªãã¯ã顧客ã«ææããç¶ããŠããåé¡ã解決ããããšåãçµãã§ããŸãããã®åé¡ãšã¯ãåºèã®æ¬æ£ã®åè¡æ¬ãå·»æ°é ã«äžŠãã§ããããç®çã®åè¡æ¬ãæ¢ãã ãã®ãé¢åã ãšããèŠæ
ã§ãã
</p>
<p>
ããªãã®åºèã§äžçªå·»æ°ã®å€ãåè¡æ¬ã¯ãåæ¢åµ èµ€ãã³ãïŒé称ãèµ€ãã³ãïŒã§ããããŸãã«é·ç·šãªã®ã§ãç¹å¥ãªæ¬æ£ããèµ€ãã³ãã®ããã«çšæããŸããã
</p>
<p>
åè¡æ¬ã®åå·»ã®éããšåãã¯æ§ã
ã§ãæ¬æ£ã®å段ã®å¹
ãšãå段ã«äžŠã¹ãããšãã§ããæ¬ã®éãã®äžéãæ§ã
ã§ããããªãã¯ã次ã®æ¡ä»¶ãæºè¶³ããããã«æ¬æ£ã«æ¬ã䞊ã¹ãããšã«ããŸããã
</p>
<ul>
<li> 1 å·»ããããå·»ãŸã§ã®ãèµ€ãã³ããæ¬æ£ã«äžŠãã§ããã</li>
<li> ããããã®æ®µã«ã¯ãå·»æ°é ã«ïŒéäžã§æããŠããå·»ããªãããã«ïŒæ¬ã䞊ã¶ã</li>
<li> å段ã«äžŠã¹ãæ¬ã®éãã®åèšãããã®æ®µã§å®ããããéãã®äžéãè¶
ããªãã</li>
<li> å段ã«äžŠã¹ãæ¬ã®åãã®åèšãããã®æ®µã®å¹
ãè¶
ããªãã</li>
</ul>
<p>
ãããã®æ¡ä»¶ãæºããããšãïŒãã®æ¬æ£ã«æ倧ã§äœå·»ãŸã§ãèµ€ãã³ãã䞊ã¹ãããšãã§ããããæ±ããããã°ã©ã ãäœæããŠãã ããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>M</var> <var>N</var>
<var>w<sub>1</sub></var> <var>t<sub>1</sub></var>
<var>w<sub>2</sub></var> <var>t<sub>2</sub></var>
:
<var>w<sub>M</sub></var> <var>t<sub>M</sub></var>
<var>c<sub>1</sub></var> <var>b<sub>1</sub></var>
<var>c<sub>2</sub></var> <var>b<sub>2</sub></var>
:
<var>c<sub>N</sub></var> <var>b<sub>N</sub></var>
</pre>
<p>
æåã®ïŒè¡ã«ãèµ€ãã³ãã®å·»æ° <var>M</var> (1 ≤ <var>M</var> ≤ 200000) ãšæ¬æ£ã®æ®µæ° <var>N</var> (1 ≤ <var>N</var> ≤ 15) ãäžãããããç¶ã <var>M</var> è¡ã«ããèµ€ãã³ãã®åè¡æ¬ <var>i</var> å·»ç®ã®éã <var>w<sub>i</sub></var> (1 ≤ <var>w<sub>i</sub></var> ≤ 100) ãšåã <var>t<sub>i</sub></var> (1 ≤ <var>t<sub>i</sub></var> ≤ 100) ãè¡šãæŽæ°ãäžãããããç¶ã <var>N</var> è¡ã«ãæ¬æ£ã® <var>i</var> 段ç®ã®éãã®äžé <var>c<sub>i</sub></var> (1 ≤ <var>c<sub>i</sub></var> ≤ 10<sup>8</sup>)ãšå¹
<var>b<sub>i</sub></var> (1 ≤ <var>b<sub>i</sub></var> ≤ 10<sup>8</sup>) ãè¡šãæŽæ°ãäžããããã
</p>
<h2>åºå</h2>
<p>
æ¬æ£ã«äžŠã¹ãããšãã§ããæ倧ã®ãèµ€ãã³ãå·»æ°ãïŒè¡ã«åºåããã
</p>
<h2>å
¥åºåäŸ</h2>
<h2>å
¥åäŸïŒ</h2>
<pre>
3 4
2 2
3 3
4 4
3 3
4 4
1 1
2 2
</pre>
<h2>åºåäŸïŒ</h2>
<pre>
3
</pre>
<br>
<h2>å
¥åäŸïŒ</h2>
<pre>
2 2
1 2
2 1
2 1
2 1
</pre>
<h2> åºåäŸïŒ</h2>
<pre>
0
</pre>
<br>
<h2>å
¥åäŸïŒ</h2>
<pre>
3 2
1 2
2 2
2 1
3 3
2 2
</pre>
<h2> åºåäŸïŒ</h2>
<pre>
2
</pre>
<br>
<h2>å
¥åäŸïŒ</h2>
<pre>
3 2
1 2
2 1
2 2
2 2
3 3
</pre>
<h2>åºåäŸïŒ</h2>
<pre>
3
</pre> | [
[
"3 4\n2 2\n3 3\n4 4\n3 3\n4 4\n1 1\n2 2\n",
"3 4\n2 2\n3 3\n4 4\n3 3\n4 4\n1 1\n2 2\n"
]
] |
p00308 | Unknown Germ |
<h2>æªç¥ã®ç
åè</h2>
<p>
è±äžå士ã¯æªç¥ã®ç
åèãçºèŠããŸããããã®ç
åèã¯ãã¢ã¯ãããã³ãšãŒã³ãããã³ãšåŒã°ããäºçš®é¡ã®èããäžçŽç·ã«é£ãªã£ãéç¶ã®æ§é ãããŠããŸãã人é¡ã®ããã«ããã®ç
åèãç¡å®³åããããšèããŠããŸãã
</p>
<p>ãã®ç
åèã¯ãé·ããïŒä»¥äžã«ãªããšåã匱ãŸããå
ç«åã«ãã£ãŠç¡å®³åãããããšãåãã£ãŠããŸããè±äžå士ã¯ããã®ç
åèãä»»æã®å Žæã§åæããŠãååãšåŸåã®ïŒã€ã®éã«ããããšãã§ããŸãããŸããïŒã€ã®éãé£çµããŠïŒã€ã®éã«ããããšãã§ããŸãã
</p>
<p>
ããã泚æããªããã°ãããªãã®ã¯ãã¢ã¯ãããã³ã®æ°ãå€ãéã¯ããããŠæ害ã ãšããããšã§ããããéã«ãããŠã¢ã¯ãããã³ã®æ°ããŒã³ãããã³ã®æ°ãããå€ããªããšããã®ç¬éã¢ã¯ãããã³ã¯ç¡å¶éã«å¢æ®ãå§ããŸããããã¯é·ãïŒä»¥äžã®éã«ã€ããŠãäŸå€ã§ã¯ãªãã®ã§ãæ
éã«éãåæããŠãããªããã°ãªããŸããã
</p>
<p>
ã©ã®ç¬éã«ãããŠãã¢ã¯ãããã³ã®æ°ã®æ¹ãå€ããããªéãäœãããšãªããäžæ¬ã®éãé·ãïŒä»¥äžã«ããŠç¡å®³åããããšã¯å¯èœã§ãããããè±äžå士ã¯ãå©æã§ããããªãã«ç¡å®³åãå¯èœãã©ããå€å®ããããã°ã©ã ãäœæããããæ瀺ããŸãããç¡å®³åãå¯èœãªãã°ãã®æäœãåºåããäžå¯èœãªãã°äžå¯èœã§ãããšåºåããããã°ã©ã ãäœæããŠãã ããããã ãããã®æäœã®ã¹ãããæ°ãæå°ã§ããå¿
èŠã¯ãããŸããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>Q</var>
<var>str<sub>1</sub></var>
<var>str<sub>2</sub></var>
:
<var>str<sub>Q</sub></var>
</pre>
<p>
1 è¡ç®ã«ç
åèã®æ° <var>Q</var> (1 ≤ <var>Q</var> ≤ 300) ãäžãããããç¶ã <var>Q</var> è¡ã«åç
åèã®åæç¶æ
ãè¡šã '<span>o</span>' (ãŒã³ãããã³) ããã³ '<span>x</span>' (ã¢ã¯ãããã³) ãããªãïŒã€ã®æåå <var>str<sub>i</sub></var> ãäžãããããæåå <var>str<sub>i</sub></var> ã®é·ã㯠1 ä»¥äž 100 以äžã§ããã
</p>
<h2>åºå</h2>
<p>
<var>str<sub>i</sub></var> ã«ã€ããŠãèŠæ±ãæºããåæã»çµåæäœã®åãååšããå Žåãåºåã®æåã®è¡ã«ã¯ãã®æäœåã®é·ããè¡šãæŽæ° <var>n</var> ãåºåããç¶ã <var>n</var> è¡ã«æäœã®å
容ãïŒè¡ã«ïŒæäœãã€ãæåã®æäœããé ã«åºåããã
</p>
<p>
åææäœã¯ä»¥äžã®åœ¢åŒã§è¡šãããšã
</p>
<pre>
split <var>a</var> <var>p</var>
</pre>
<p>
<var>a</var> ã¯åæããéã®èå¥çªå·ãè¡šãæŽæ°ã§ããã<var>p</var> ã¯ãã®éãåæããäœçœ®ã§ããããã®æäœã®çµæãé <var>a</var> ã¯å
é ãã <var>p</var> çªç®ïŒå
é ã 0 ããå§ããéãçªå·)ã®èã®çŽåŸã§åæããããæ°ããã§ããïŒã€ã®éã®ãã¡ãååã®ãã®ã«èå¥çªå· <var>m</var>+1 ããåŸåã®ãã®ã«èå¥çªå· <var>m</var>+2 ãä»äžãããïŒããã§ã<var>m</var> ã¯ãããŸã§ã«ä»äžãããæã倧ããªèå¥çªå·ãè¡šãïŒããŸããé <var>a</var> ã¯æ¶æ»
ããã
</p>
<p>
çµåæäœã¯ä»¥äžã®åœ¢åŒã§è¡šãããšã
</p>
<pre>
join <var>a</var> <var>b</var>
</pre>
<p>
<var>a</var>, <var>b</var> ã¯çµåããéã®èå¥çªå·ãè¡šãæŽæ°ã§ããããã®æäœã®çµæãé <var>a</var> ã®æ«å°Ÿã«é <var>b</var> ã®å
é ãçµåããæ°ããéãäœããããæ°ããäœãããéã«ã¯ãèå¥çªå· <var>m</var>+1 ãä»äžããã(ããã§ã<var>m</var> ã¯ãããŸã§ã«ä»äžãããæã倧ããªèå¥çªå·ãè¡šã)ããŸããé <var>a</var>, <var>b</var> ã¯æ¶æ»
ããã
</p>
<p>
å
¥åãšããŠäžããããæåã®éã«ã¯ãèå¥çªå· 0 ãä»äžãããŠããã
</p>
<p>
æäœã®çµæãåé¡ã®èŠæ±ãæºããããã«éãå解ãããŠããå Žåãã©ã®ãããªæäœã§ãæ£çãšå€å®ããããæäœåã®é·ããå¿
ãããæçã§ããå¿
èŠã¯ãªãããã ããæäœåã®é·ã㯠20000 以äžã§ãªããã°ãªããªããããŒã¿ã»ããã«ãããŠãéãå解å¯èœãªå Žåãå¿
ããã®æ¡ä»¶ãæºããæäœåãååšããããšãä¿èšŒãããã
</p>
<p>
äžæ£ãªæäœåãåºåãããå Žåã誀çãšå€å®ããããäžæ£ãªæäœåã«ã¯ã以äžã®å Žåãå«ãŸããã
</p>
<ul>
<li> åææäœ <span>split</span> <var>a</var> <var>p</var> ã«ãããŠã0 ≤ <var>p</var> < (é <var>a</var> ã®é·ã)-1 ãæºããããŠããªãå Žåã</li>
<li> åæã»çµåæäœã®å¯Ÿè±¡ãšãªãéã®èå¥çªå·ããŸã çæãããŠããªããã®ã§ããå Žåããæ¢ã«å¥ã®æäœã®å¯Ÿè±¡ãšãªã£ãããæ¶æ»
ããŠããå Žåã</li>
<li> çµåæäœ <span>join</span> <var>a</var> <var>b</var> ã«ãããŠã<var>a</var> ãš <var>b</var> ãçããå Žåã</li>
</ul>
<p>
èŠæ±ãæºããåæã»çµåæäœã®åãååšããªãå Žåã"<span>-1</span>"ãšåºåããã
</p>
<h2>å
¥åºåäŸ </h2>
<h2>å
¥åäŸ</h2>
<pre>
6
oooxxxx
ooooxxx
oxxooxxo
ooxx
oo
ooo
</pre>
<h2> åºåäŸ</h2>
<pre>
-1
7
split 0 0
join 2 1
split 3 4
split 4 0
join 7 6
split 8 2
split 9 0
3
split 0 1
split 2 1
split 4 1
-1
0
1
split 0 0
</pre>
<p>
äŸãã°ãå
¥åäŸã®ïŒçªç®ã®ç
åè <span>ooooxxx</span> ã¯ã<br>
<span>split</span> 0 0 ã«ãã <span>o</span>(1) ãš <span>oooxxx</span>(2) ãã§ãããããã§ã()å
ã®æ°åã¯èå¥çªå·ãè¡šãã<br>
<span>join</span> 2 1 ã«ãã <span>oooxxxo</span>(3) ãã§ã 1 ãš 2 ã¯æ¶æ»
ããã<br>
<span>split</span> 3 4 ã«ãã <span>oooxx</span>(4) ãš <span>xo</span>(5) ãã§ããããã®ãšã{ <span>oooxx</span>(4), <span>xo</span>(5) }ã®éãååšããã<br>
<span>split</span> 4 0 ã«ãã <span>o</span>(6) ãš <span>ooxx</span>(7) ãã§ããã{ <span>xo</span>(5), <span>o</span>(6), <span>ooxx</span>(7)}<br>
<span>join</span> 7 6 ã«ãã <span>ooxxo</span>(8) ãã§ããã{ <span>xo</span>(5), <span>ooxxo</span>(8)}<br>
<span>split</span> 8 2 ã«ãã <span>oox</span>(9) ãš <span>xo</span>(10) ãã§ããã{<span>xo</span>(5), <span>oox</span>(9), <span>xo</span>(10) }<br>
<span>split</span> 9 0 ã«ãã { <span>xo</span>(5), <span>xo</span>(10), <span>o</span>(11), <span>ox</span>(12) } ãšãªã£ãŠçµäºããã
</p> | [
[
"6\noooxxxx\nooooxxx\noxxooxxo\nooxx\noo\nooo\n",
"6\noooxxxx\nooooxxx\noxxooxxo\nooxx\noo\nooo\n"
]
] |
p00309 | The Kingdom of Akabeko |
<h1>ã¢ã«ãã³åœçã®é
æ
®</h1>
<p>
ã¢ã«ãã³åœã®åœçã«ã¯ïŒäººã®çåãããŸããåœçã¯èªåãéäœãããšãã«åœãïŒã€ã«åå²ããããããã®çåã«äžã€ãã€åœãæ²»ããããããšã«ããŸãããæ°ããåœã®ååã¯ã¢ã«åœãšãã³åœã§ããã¢ã«ãã³åœã«ã¯ <var>N</var> åã®çºãšãïŒã€ã®çºãç¹ã <var>M</var> æ¬ã®éããããŸããåœçã¯ã以äžã®æé ã§ã¢ã«ãã³åœã®çºãšäžéšã®éãïŒã€ã®åœã«é
åããããšã«ããŸããã<br>
<br>
(1) çºãïŒã€éžã³ãããããã¢ã«åœãšãã³åœã«é
åããã<br>
(2) ãã§ã«é
åãããçºsãéžã¶ãããã«ãçº <var>s</var> ããïŒæ¬ã®éã§ç¹ãã£ãŠããããŸã é
åãããŠããªãçº <var>t</var> ãéžã¶ããããŠãçº <var>s</var>ã<var>t</var> éã®éãšçº <var>t</var> ããçº <var>s</var> ãé
åãããåœã«é
åããã<br>
(3) (2)ããè¡ããªããªããŸã§ç¹°ãè¿ãã
</p>
<p>
å®ã¯ïŒäººã®çåã¯ããŸã仲ãè¯ããªãã®ã§ãåœçã¯ïŒã€ã®åœã®è·é¢ããªãã¹ã倧ããããããšèããŠããŸããããã§ãïŒã€ã®åœã®è·é¢ãšã¯ãã¢ã«åœã®çºãšãã³åœã®çºãç¹ãéã®äžã§ãæãçãéã®é·ãã§ãã
</p>
<p>
ã¢ã«ãã³åœã®çºãšéã®æ
å ±ãäžãããããšããåé
åŸã®ã¢ã«åœãšãã³åœã®è·é¢ã®æ倧å€ãšããã®ãããªè·é¢ã«ãªãé
åãäœéãããããæ±ããããã°ã©ã ãäœæããŠãã ããããã ããïŒã€ã®é
åçµæã¯ãã¢ã«åœãšãã³åœã«ç°ãªãçºãéãé
åãããå Žåã«åºå¥ãããŸãã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var> <var>M</var>
<var>s<sub>1</sub></var> <var>t<sub>1</sub></var> <var>d<sub>1</sub></var>
<var>s<sub>2</sub></var> <var>t<sub>2</sub></var> <var>d<sub>2</sub></var>
:
<var>s<sub>M</sub></var> <var>t<sub>M</sub></var> <var>d<sub>M</sub></var>
</pre>
<p>
ïŒè¡ç®ã¯ïŒã€ã®æŽæ°ãããªãã<var>N</var> (2 ≤ <var>N</var> ≤ 100) ã¯çºã®æ°ã<var>M</var> (<var>N</var>-1 ≤ <var>M</var> ≤ <var>N</var>(<var>N</var>-1)/2) ã¯éã®æ°ãè¡šããç¶ã<var>M</var> è¡ã«ïŒã€ã®çºãç¹ãéãäžããããã<var>s<sub>i</sub></var> ãš <var>t<sub>i</sub></var> (1 ≤ <var>s<sub>i</sub></var> ≠ <var>t<sub>i</sub></var> ≤ <var>N</var>) 㯠<var>i</var> çªç®ã®éãç¹ãïŒã€ã®çºã®çªå·ãè¡šãã<var>d<sub>i</sub></var> (1 ≤ <var>d<sub>i</sub></var> ≤ 10<sup>9</sup>) 㯠<var>i</var> çªç®ã®éã®é·ããè¡šãã
</p>
<p>
å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã
</p>
<ul>
<li> ã©ã®ïŒã€ã®çºãããã€ãã®éã䜿ãè¡ãæ¥ãå¯èœã§ããã</li>
<li> ã©ã®ïŒã€ã®çºã®éã«ãïŒæ¬ä»¥äžã®éã¯ãªãã</li>
<li> åãé·ãã®éã¯ïŒæ¬ä»¥äžã§ããã</li>
</ul>
<h2>åºå</h2>
<p>
åé
åŸã®ã¢ã«åœãšãã³åœã®è·é¢ã®æ倧å€ãšçµã¿åããã®æ°ãã空çœåºåãã§ïŒè¡ã«åºåããããã ããåé
åŸã®çµã¿åããã®æ°ã¯éåžžã«å€§ãããªãããã®ã§ã代ããã« 1,000,000,007 ã§å²ã£ãäœããåºåããã
</p>
<h2>å
¥åºåäŸ </h2>
<h2>å
¥åäŸ </h2>
<pre>
6 7
1 2 1
2 3 2
3 1 3
4 5 4
5 6 5
6 4 6
1 4 7
</pre>
<h2>åºåäŸ</h2>
<pre>
7 18
</pre>
| [
[
"6 7\n1 2 1\n2 3 2\n3 1 3\n4 5 4\n5 6 5\n6 4 6\n1 4 7\n",
"6 7\n1 2 1\n2 3 2\n3 1 3\n4 5 4\n5 6 5\n6 4 6\n1 4 7\n"
]
] |
p00310 | The Number of Participants |
<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>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>p</var> <var>m</var> <var>c</var>
</pre>
<p>
å
¥åã¯ïŒè¡ã§ãããããã°ã©ãã³ã°éšéã®åå è
æ° <var>p</var> (0 ≤ <var>p</var> ≤ 10000)ãã¢ãã€ã«éšéã®åå è
æ° <var>m</var> (0 ≤ <var>m</var> ≤ 10000)ããã¡ãŸãã®çµµïŒ£ïŒ§éšéã®åå è
æ° <var>c</var> (0 ≤ <var>c</var> ≤ 10000) ãäžããããã
</p>
<h2>Output</h2>
<p>
åå è
ã®ç·æ°ãïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
10 10 20
</pre>
<h2>Sample Output 1</h2>
<pre>
40
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
100 0 0
</pre>
<h2>Sample Output 2</h2>
<pre>
100
</pre>
<br/>
<h2>Sample Input 3</h2>
<pre>
1000 1000 1000
</pre>
<h2>Sample Output 3</h2>
<pre>
3000
</pre> | [
[
"10 10 20\n",
"10 10 20\n"
]
] |
p00311 | Fishing Competition |
<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>
<ul>
<li>ã€ã¯ãã¯ïŒå¹ <var>a</var> ç¹</li>
<li>ã€ãã¡ã¯ïŒå¹ <var>b</var> ç¹</li>
<li>ã€ã¯ãïŒïŒå¹ããšã« <var>c</var> ç¹è¿œå </li>
<li>ã€ãã¡ïŒïŒå¹ããšã« <var>d</var>ç¹è¿œå </li>
</ul>
<p>
浩ãšå¥æ¬¡éãé£ãäžããéã®æ°ãããšã«ãã©ã¡ããåã¡ãããããã¯åŒãåããå€å®ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>h<sub>1</sub></var> <var>h<sub>2</sub></var>
<var>k<sub>1</sub></var> <var>k<sub>2</sub></var>
<var>a</var> <var>b</var> <var>c</var> <var>d</var>
</pre>
<p>
ïŒè¡ç®ã«ã¯ã浩ãé£ãäžããã€ã¯ãã®æ° <var>h<sub>1</sub></var> (0 ≤ <var>h<sub>1</sub></var> ≤ 100) ãšã€ãã¡ã®æ° <var>h<sub>2</sub></var> (0 ≤ <var>h<sub>2</sub></var> ≤ 100) ãäžãããããïŒè¡ç®ã«ã¯ãå¥æ¬¡éãé£ãäžããã€ã¯ãã®æ° <var>k<sub>1</sub></var> (0 ≤ <var>k<sub>1</sub></var> ≤ 100) ãšã€ãã¡ã®æ° <var>k<sub>2</sub></var> (0 ≤ <var>k<sub>2</sub></var> ≤ 100) ãäžãããããïŒè¡ç®ã«ã¯ãã€ã¯ãïŒå¹ããšã®ç¹æ° <var>a</var>(1 ≤ <var>a</var> ≤ 100)ãã€ãã¡ïŒå¹ããšã®ç¹æ° <var>b</var> (1 ≤ <var>b</var> ≤ 100)ãã€ã¯ãïŒïŒå¹ããšã®è¿œå ç¹æ° <var>c</var> (0 ≤ <var>c</var> ≤ 100)ãã€ãã¡ïŒïŒå¹ããšã®è¿œå ç¹æ° <var>d</var> (0 ≤ <var>d</var> ≤ 100) ãäžããããã
</p>
<h2>Output</h2>
<p>
浩ãåã¡ãªã <span>hiroshi</span>ãå¥æ¬¡éãåã¡ãªã <span>kenjiro</span> ãåŒãåããªã <span>even</span> ãšïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
5 1
3 1
1 2 5 5
</pre>
<h2>Sample Output 1</h2>
<pre>
hiroshi
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
5 1
4 2
1 2 5 5
</pre>
<h2>Sample Output 2</h2>
<pre>
kenjiro
</pre>
<br/>
<h2>Sample Input 3</h2>
<pre>
0 20
10 0
1 1 10 0
</pre>
<h2>Sample Output 3</h2>
<pre>
even
</pre> | [
[
"5 1\n3 1\n1 2 5 5\n",
"5 1\n3 1\n1 2 5 5\n"
]
] |
p00312 | Frog Going Straight |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>ã«ãšã«ã¯ãŸã£ããåž°ã</H1>
<p>
äžå¹ã®ã«ãšã«ã巣穎ã«åž°ãããšããŠããŸãã巣穎ã¯ã«ãšã«ã® <var>D</var> ã»ã³ãã¡ãŒãã«åæ¹ã«ãã£ãŠãã«ãšã«ã¯å·£ç©Žã«åãã£ãŠãŸã£ããé²ã¿ãŸããã«ãšã«ãã§ããè¡åã¯ã以äžã®ïŒã€ã ãã§ãã
</p>
<ul>
<li> 倧ãžã£ã³ãïŒ<var>L</var> ã»ã³ãã¡ãŒãã«åæ¹ã«é²ãïŒ</li>
<li> å°ãžã£ã³ãïŒïŒã»ã³ãã¡ãŒãã«åæ¹ã«é²ãïŒ</li>
</ul>
<p>
ã«ãšã«ã¯å·£ç©Žãè·³ã³è¶ãããšãªããã¡ããã©å·£ç©Žã«çå°ããããšãããã£ãŠããŸãã
</p>
<p>
ã«ãšã«ã巣穎ã«åž°ãããã«ãæäœäœåè·³ã¶å¿
èŠãããããæ±ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>D</var> <var>L</var>
</pre>
<p>
å
¥åã¯ïŒè¡ã§ããã巣穎ãŸã§ã®è·é¢ <var>D</var> (1 ≤ <var>D</var> ≤ 10000) ãšå€§ãžã£ã³ãã§ã«ãšã«ãé²ãè·é¢ <var>L</var> (2 ≤ <var>L</var> ≤ 10000) ãäžããããã
</p>
<h2>Output</h2>
<p>
ã«ãšã«ãæäœäœåè·³ã¶å¿
èŠããããããïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
10 5
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
7 4
</pre>
<h2>Sample Output 2</h2>
<pre>
4
</pre> | [
[
"10 5\n",
"10 5\n"
]
] |
p00313 | Secret Investigation |
<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>
ç§å¯ã®çµç¹ã¢ã€ã
ã¢ããªãã£ã¯ã¹(AiZu AnalyticS)ã¯ã極ç§ã®èª¿æ»ãéå§ãããã¿ãŒã²ããã«ãªã£ãŠãã人ç©ã¯ <var>N</var> 人ããŠã1 ãã <var>N</var> ã®èå¥çªå·ãä»ããããŠãããAZAS æ
å ±æŠç¥èª¿æ»å¡ã§ããããªãã¯ã
ã¿ãŒã²ããã®äžããã以äžã®æ¡ä»¶ãå°ãªããšãäžã€æºãã人ç©ã®æ°ãå²ãåºãããšã«ããã
</p>
<ul>
<li> çµç¹ $A$ ã«å±ããããã€ãåå $C$ ãææããŠããè
ã</li>
<li> çµç¹ $B$ ã«å±ãããã€ãåå $C$ ãææããŠããè
ã</li>
</ul>
<p>
çµç¹ $A$ ã«å±ããŠããè
ãçµç¹ $B$ ã«å±ããŠããè
ãåå $C$ ãææããŠããè
ã®èå¥çªå·ãå
¥åãšããŠäžãããããšããæ¡ä»¶ãæºãã人ç©ã®æ°ãå²ãåºãããã°ã©ã ãäœæããããã ããã©ã¡ãã®æ¡ä»¶ãæºãã人ç©ãéè€ããŠæ°ããªãããã«æ³šæããã
</p>
<p>
ïŒè£è¶³ïŒäžèšã®æ¡ä»¶ã«ã€ããŠïŒ<br>
1 ãã $N$ ãŸã§ã®èªç¶æ°ã®éåãããããã€ãã®èŠçŽ ãéžãã éåã $A$ïŒ$B$ïŒ$C$ ãšãããæ¡ä»¶ãæºãã人ç©ã®æ°ã¯ã$(\bar{A} \cap C) \cup (B \cap C)$ (å³ã®å¡ãããéšå) ãæºããèŠçŽ ã®åæ°ã§ããããã ãã$\bar{A}$ ã¯éå $A$ ã®è£éåãšããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2015_azas">
</center>
<br/>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>X</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> ... <var>a<sub>X</sub></var>
<var>Y</var> <var>b<sub>1</sub></var> <var>b<sub>2</sub></var> ... <var>b<sub>Y</sub></var>
<var>Z</var> <var>c<sub>1</sub></var> <var>c<sub>2</sub></var> ... <var>c<sub>Z</sub></var>
</pre>
<p>
å
¥åã¯ïŒè¡ã§ãããïŒè¡ç®ã«èª¿æ»å¯Ÿè±¡ã®äººæ° <var>N</var> (1 ≤ <var>N</var> ≤ 100) ãäžãããããïŒè¡ç®ã«ãçµç¹ $A$ ã«å±ããŠããè
ã®æ° <var>X</var> (0 ≤ <var>X</var> ≤ <var>N</var>)ãšãããã«ç¶ããŠçµç¹ $A$ ã«å±ããŠããè
ã®èå¥çªå· <var>a<sub>i</sub></var> (1 ≤ <var>a<sub>i</sub></var> ≤ <var>N</var>) ãäžãããããïŒè¡ç®ã«ãçµç¹ $B$ ã«å±ããŠããè
ã®æ° <var>Y</var> (0 ≤ <var>Y</var> ≤ <var>N</var>) ãšãããã«ç¶ããŠçµç¹ $B$ ã«å±ããŠããè
ã®èå¥çªå· <var>b<sub>i</sub></var> (1 ≤ <var>b<sub>i</sub></var> ≤ <var>N</var>) ãäžãããããïŒè¡ç®ã«ãåå $C$ ãææããŠããè
ã®æ° <var>Z</var> (0 ≤ <var>Z</var> ≤ <var>N</var>) ãšãããã«ç¶ããŠåå $C$ ãææããŠããè
ã®èå¥çªå· <var>c<sub>i</sub></var> (1 ≤ <var>c<sub>i</sub></var> ≤ <var>N</var>) ãäžããããã
</p>
<h2>Output</h2>
<p>
æ¡ä»¶ãæºãã人ç©ã®æ°ãïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
5
3 1 2 3
2 4 5
2 3 4
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
100
3 1 100 4
0
2 2 3
</pre>
<h2>Sample Output 2</h2>
<pre>
2
</pre> | [
[
"5\n3 1 2 3\n2 4 5\n2 3 4\n",
"5\n3 1 2 3\n2 4 5\n2 3 4\n"
]
] |
p00314 | Programming Contest |
<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>
ãããããŒã ãæ£è§£ããåé¡ã®ãã¡ãåŸç¹ã <var>A</var> 以äžã§ãããã®ã <var>A</var> å以äžããããšãæºãããããªæ倧㮠<var>A</var> ãããã®ããŒã ã®ã¹ã³ã¢ãšããã
</p>
<p>
ããããŒã ãæ£è§£ããåé¡ã®æ°ãšããããã®åé¡ã®åŸç¹ãããããŒã ã®ã¹ã³ã¢ãèšç®ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>p<sub>1</sub></var> <var>p<sub>2</sub></var> ... <var>p<sub>N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ããŒã ãæ£è§£ããåé¡ã®æ° <var>N</var> (1 ≤ <var>N</var> ≤ 100) ãäžãããããïŒè¡ç®ã«æ£è§£ããååé¡ã®åŸç¹ <var>p<sub>i</sub></var>(1 ≤ <var>p<sub>i</sub></var> ≤ 100) ãäžããããã
</p>
<h2>Output</h2>
<p>
ããŒã ã®ã¹ã³ã¢ãïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
7
5 4 3 10 2 4 1
</pre>
<h2>Sample Output 1</h2>
<pre>
4
</pre>
<p>
åŸç¹ã 4 以äžã®åé¡ã 4 å以äžæ£è§£ããŠããã®ã§ãã¹ã³ã¢ã¯ 4 ãšãªãã
</p>
<br/>
<h2>Sample Input 2</h2>
<pre>
3
1 1 100
</pre>
<h2>Sample Output 2</h2>
<pre>
1
</pre>
<p>
åŸç¹ã 1 以äžã®åé¡ã 1 å以äžæ£è§£ããŠããã®ã§ãã¹ã³ã¢ã¯ 1 ãšãªãã
</p>
<br/>
<h2>Sample Input 3</h2>
<pre>
4
11 15 58 1
</pre>
<h2>Sample Output 3</h2>
<pre>
3
</pre>
<p>
åŸç¹ã 3 以äžã®åé¡ã 3 å以äžæ£è§£ããŠããã®ã§ãã¹ã³ã¢ã¯ 3 ãšãªãã
</p>
| [
[
"7\n5 4 3 10 2 4 1\n",
"7\n5 4 3 10 2 4 1\n"
]
] |
p00315 | Quality Management |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>å質管ç</H1>
<p>
äŒæŽ¥ã¿ã«ãåžãçç£è²©å£²ããåžè£œã³ãŒã¹ã¿ãŒã¯ã察称ãªãã¶ã€ã³ã§ãšãŠãçŸããããšã§ç¥ãããŠãããäŒæŽ¥ã¿ã«ãåžã§ã¯å質管çã®äžç°ãšããŠã補é ã©ã€ã³ã«ã«ã¡ã©ãèšçœ®ããåã³ãŒã¹ã¿ãŒãæ®åœ±ããŠåŸãããç»åã察称ã«ãªã£ãŠããããèªåã§æ€èšŒããŠãããåã³ãŒã¹ã¿ãŒã¯ <var>N</var> × <var>N</var> ãã¯ã»ã«ã®æ£æ¹åœ¢ã®çœé»ç»åãšããŠè¡šããããåãã¯ã»ã«ã¯çœãŸãã¯é»ã®ç»åã«å¯Ÿå¿ããŠã0 ãŸã㯠1 ã®å€ããšãã
</p>
<p>
ãã®åºŠãçç£ã©ã€ã³ã®æ©åšæŽæ°ã«ãšããªã£ãŠãç»å解æã·ã¹ãã ã®ãœãããŠã§ã¢ãæŽæ°ããããšã«ãªã£ããæ°ã·ã¹ãã ã§ã¯ãéä¿¡ããŒã¿éãåæžãã工倫ããªããã以äžã®æ¹æ³ã§ã«ã¡ã©ãã解æã·ã¹ãã ã«ããŒã¿ãéãããŠããã
</p>
<ul>
<li> ã©ã€ã³ã«æµããŠããæåã®ã³ãŒã¹ã¿ãŒã®æ
å ±ã¯ã<var>N</var> × <var>N</var> ãã¯ã»ã«ã®ç»åãšããŠã·ã¹ãã ã«éãããŠããã</li>
<li> ïŒæç®ä»¥éã®ã³ãŒã¹ã¿ãŒã®æ
å ±ã¯ãïŒã€åã«éãããç»åãšã®å·®åã ããéãããŠãããå·®åã¯ãã0 ãã 1 ããŸãã¯ã1 ãã 0 ããžãšå€åãããã¯ã»ã«ã®äœçœ®ã®éåãšããŠäžããããã</li>
</ul>
<p>
<var>C</var> æã®ã³ãŒã¹ã¿ãŒã«ã€ããŠãïŒæç®ã®ç»åã®ãã¯ã»ã«æ
å ±ãšç¶ã <var>C</var> - 1 æåã®å·®åæ
å ±ãå
¥åããäžäžå¯Ÿç§°ãã€å·Šå³å¯Ÿç§°ãšãªã£ãŠããã³ãŒã¹ã¿ãŒã®ææ°ãå ±åããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>C</var> <var>N</var>
<var>p<sub>11</sub>p<sub>12</sub></var>...<var>p<sub>1N</sub></var>
<var>p<sub>21</sub>p<sub>22</sub></var>...<var>p<sub>2N</sub></var>
:
<var>p<sub>N1</sub>p<sub>N2</sub></var>...<var>p<sub>NN</sub></var>
<var>diff<sub>1</sub></var>
<var>diff<sub>2</sub></var>
:
<var>diff<sub>C−1</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ã³ãŒã¹ã¿ãŒã®ææ° <var>C</var> (1 ≤ <var>C</var> ≤ 10000) ãšç»åã®çžŠãšæšªã®ãã¯ã»ã«æ° <var>N</var> (2 ≤ <var>N</var> ≤ 1000 ã〠<var>N</var> ã¯å¶æ°) ãäžãããããïŒè¡ç®ãã <var>N</var> + 1 è¡ç®ã«æåã®ã³ãŒã¹ã¿ãŒã®ç»åã®ãã¯ã»ã«ãè¡šã <var>N</var>è¡ × <var>N</var> åã®æ°å <var>p<sub>ij</sub></var> (<var>p<sub>ij</sub></var> 㯠0 ãŸã㯠1)ãäžããããã
</p>
<p>
<var>N</var> + 2 è¡ç®ä»¥éã«ãïŒæç®ä»¥éã®ã³ãŒã¹ã¿ãŒã®æ
å ±ãè¡šãå·®å <var>diff<sub>i</sub></var> ã次ã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>D</var>
<var>r<sub>1</sub></var> <var>c<sub>1</sub></var>
<var>r<sub>2</sub></var> <var>c<sub>2</sub></var>
:
<var>r<sub>D</sub></var> <var>c<sub>D</sub></var>
</pre>
<p>
ïŒè¡ç®ã«å€åãããã¯ã»ã«ã®æ° <var>D</var> (0 ≤ <var>D</var> ≤ 100) ãäžãããããç¶ã<var>D</var> è¡ã«å€åãããã¯ã»ã«ã®è¡ãšåã®çªå·ãããããè¡šã <var>r<sub>i</sub></var> ãš<var>c<sub>i</sub></var> (1 ≤ <var>r<sub>i</sub></var>, <var>c<sub>i</sub></var> ≤ <var>N</var>) ãäžããããã<var>diff<sub>i</sub></var> ã®äžã«ãåãäœçœ®ã¯ïŒå以äžäžããããªãã
</p>
<h2>Output</h2>
<p>
äžäžå¯Ÿç§°ãã€å·Šå³å¯Ÿç§°ãšãªã£ãŠããã³ãŒã¹ã¿ãŒã®ææ°ãïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
7 8
00100000
00011000
10111101
01100110
01000110
10111101
00011000
00100100
2
5 3
1 6
1
6 8
3
6 8
3 3
3 6
2
6 3
6 6
0
2
3 8
6 8
</pre>
<h2>Sample Output 1</h2>
<pre>
3
</pre>
<p>
å
¥åäŸïŒã®ã³ãŒã¹ã¿ãŒã®ç»åã以äžã«ç€ºãããã®å ŽåãïŒæç®ãïŒæç®ãïŒæç®ã®ã³ãŒã¹ã¿ãŒãäžäžå¯Ÿç§°ãã€å·Šå³å¯Ÿç§°ãšãªãããã3ãšå ±åããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2015_checking" width="680">
</center>
<br/>
<h2>Sample Input 2</h2>
<pre>
1 6
000000
000000
010010
010010
000000
000000
</pre>
<h2>Sample Output 2</h2>
<pre>
1
</pre>
<br/>
<h2>Sample Input 3</h2>
<pre>
2 2
00
00
4
1 1
1 2
2 1
2 2
</pre>
<h2>Sample Output 3</h2>
<pre>
2
</pre> | [
[
"7 8\n00100000\n00011000\n10111101\n01100110\n01000110\n10111101\n00011000\n00100100\n2\n5 3\n1 6\n1\n6 8\n3\n6 8\n3 3\n3 6\n2\n6 3\n6 6\n0\n2\n3 8\n6 8\n",
"7 8\n00100000\n00011000\n10111101\n01100110\n01000110\n10111101\n00011000\n00100100\n2\n5 3\n1 6\n1\n6 8\n3\n6 8\n3 3\n3 6\n2\n6 3\n6 6\n0\n2\n3 8\n6 8\n"
]
] |
p00316 | Investigation of Club Activities |
<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>
A é«æ ¡ã®çåŸäŒé·ã§ããæã¯ãA é«æ ¡ã®çåŸãã©ã®éšæŽ»åã«æå±ããŠãããã調æ»ããããšã«ãããAé«æ ¡ã«ã¯ 1 ãã <var>N</var> ã®çªå·ãä»ãããã <var>N</var> 人ã®çåŸãšã1 ãã <var>M</var> ã®çªå·ãä»ãããã <var>M</var> çš®é¡ã®éšæŽ»åããããåéšæŽ»åã«äººæ°å¶éã¯ãªãã0 人ã®éšæŽ»åãããããããã ããA é«æ ¡ã®æ ¡åã§ã¯çåŸã¯ã²ãšã€ã®éšæŽ»åãŸã§ããæå±ã§ããªããçåŸã¯å
šå¡ãã®æ ¡åãå®ã£ãŠããã
</p>
<p>
æã¯çåŸäŒå¡ã«èª¿æ»ãäŸé Œããåè¡ã次ã®ããããã§ãããã㪠<var>K</var> è¡ã®èšé²ãå
¥æããã
</p>
<ul>
<li> çåŸ <var>a</var> ãšçåŸ <var>b</var> ã¯åãéšæŽ»åã«æå±ããŠããã</li>
<li> çåŸ <var>c</var> ã¯éšæŽ»å <var>x</var> ã«æå±ããŠããã</li>
</ul>
<p>
ãããããã®èšé²ã«ã¯èª°ããæ ¡åéåã«ãªã£ãŠããŸããããªççŸããããããããªããæã¯ïŒè¡ç®ããé ã«èŠãŠãããççŸããããšå€æã§ããæåã®è¡ãæ¢ãããšã«ããã
</p>
<p>
<var>K</var> è¡ã®èšé²ãäžãããããšããççŸããããšå€æã§ããæåã®è¡ã®çªå·ãæ±ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var> <var>M</var> <var>K</var>
<var>record<sub>1</sub></var>
<var>record<sub>2</sub></var>
:
<var>record<sub>K</sub></var>
</pre>
<p>
ïŒè¡ç®ã«çåŸã®äººæ° <var>N</var> (1 ≤ <var>N</var> ≤ 100000)ãéšæŽ»åã®çš®é¡ã®æ° <var>M</var> (1 ≤ <var>M</var> ≤ 100000)ãèšé²ã®è¡æ° <var>K</var> (1 ≤ <var>K</var> ≤ 200000) ãäžãããããç¶ã <var>K</var> è¡ã«èšé²ã®åè¡ <var>record<sub>i</sub></var> ãã以äžã®ããããã®åœ¢åŒã§äžããããã
</p>
<pre>
1 <var>a</var> <var>b</var>
</pre>
<p>
ãŸãã¯
</p>
<pre>
2 <var>c</var> <var>x</var>
</pre>
<p>
å
é ã®æ°åãã1ãã®ãšããçåŸ <var>a</var> (1 ≤ <var>a</var> ≤ <var>N</var>) ãšçåŸ <var>b</var> (1 ≤ <var>b</var> ≤ <var>N</var>) ãåãéšæŽ»åã«æå±ããŠããããšã瀺ãããã ãã<var>a</var> ≠ <var>b</var> ã§ããã
</p>
<p>
å
é ã®æ°åãã2ãã®ãšããçåŸ <var>c</var> (1 ≤ <var>c</var> ≤ <var>N</var>) ãéšæŽ»å <var>x</var> (1 ≤ <var>x</var> ≤ <var>M</var>) ã«æå±ããŠããããšã瀺ãã
</p>
<h2>Output</h2>
<p>
ççŸããããšå€æã§ããæåã®è¡ã®çªå·ãïŒè¡ã«åºåãããèŠã€ãããªãå Žå㯠0 ãïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
3 2 5
1 1 2
1 2 3
2 1 1
2 3 2
2 2 1
</pre>
<h2>Sample Output 1</h2>
<pre>
4
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
3 2 4
1 1 2
2 1 1
2 3 2
2 2 1
</pre>
<h2>Sample Output 2</h2>
<pre>
0
</pre>
<br/>
<h2>Sample Input 3</h2>
<pre>
3 2 2
1 1 2
2 1 1
</pre>
<h2>Sample Output 3</h2>
<pre>
0
</pre>
| [
[
"3 2 5\n1 1 2\n1 2 3\n2 1 1\n2 3 2\n2 2 1\n",
"3 2 5\n1 1 2\n1 2 3\n2 1 1\n2 3 2\n2 2 1\n"
]
] |
p00317 | Slates |
<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>
<ul>
<li> ç³çã«æžãããŠããåèªã®äžã€ã®æåã ãã è(ãã)ã§èŠãããŠããå Žåãããããã®æåãææ¡ããããšãã§ããªãã
</li>
<li> ç³çã®å·ŠåŽãæ¬ ããŠãããããã«äœãæååãæžãããŠãããããããªãïŒç³çã®å·ŠåŽïŒæå以äžãææ¡ããããšãã§ããªãïŒã</li>
<li> ç³çã®å³åŽãæ¬ ããŠãããããã«äœãæååãæžãããŠãããããããªãïŒç³çã®å³åŽïŒæå以äžãææ¡ããããšãã§ããªãïŒã
</li>
</ul>
<p>
ç³çã«èãçããŠããå Žæã¯å€ããŠãäžãæãããªãããŸããæ¬ ããç³çã«èãçããŠããããšã¯ããããç³çã®äž¡åŽãåæã«æ¬ ããŠããããšã¯ãªãã
</p>
<p>
ç 究è
ã¯ãç³ççºèŠä»¥åã®èª¿æ»ã§ããã£ãŠããåèªããŸãšããèŸæžãæã£ãŠããããããã颚åã®åœ±é¿ã«ããèãšæ¬ ããããç³çããå
ã®åèªãæšæž¬ãããšããèŸæžã®äžã®åèªã«åœãŠã¯ãŸããã®ãããã€ããããããã«ã¯åãããªãã
</p>
<p>
ç³çã®æ
å ±ãäžãããããšããäžããããèŸæžã®äžã«åœãŠã¯ãŸããããªåèªãããã€ããããæ°ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var> <var>M</var>
<var>word<sub>1</sub></var>
<var>word<sub>2</sub></var>
:
<var>word<sub>N</sub></var>
<var>slate<sub>1</sub></var>
<var>slate<sub>2</sub></var>
:
<var>slate<sub>M</sub></var>
</pre>
<p>
ïŒè¡ç®ã«èŸæžã«èŒã£ãŠããåèªã®æ° <var>N</var> (1 ≤ <var>N</var> ≤ 50000)ãç³çã®æ° <var>M</var> (1 ≤ <var>M</var> ≤ 50000) ãäžãããããç¶ã <var>N</var> è¡ã«åèª <var>word<sub>i</sub></var> ãäžãããããåèªã¯è±å°æåã®ã¿ãå«ãé·ãã 1 ä»¥äž 200 以äžã®æååã§ããããã ãã<var>N</var> åã®åèªã¯å
šãŠç°ãªããç¶ã <var>M</var> è¡ã«ãåç³çã®æ
å ±ãè¡šãæåå <var>slate<sub>i</sub></var> ãäžããããã<var>slate<sub>i</sub></var> ã¯è±å°æåãã?ããã*ããå«ãé·ãã 1 ä»¥äž 200 以äžã®æååã§ããã? ã¯èã«èŠãããæåãè¡šãã? ã¯äžã€ã®æååã«ãå€ããšãäžã€ããçŸããªããæååã®å
é ã * ã®å Žåãç³çã®å·ŠåŽãæ¬ ããŠããããšã瀺ããæååã®æ«å°Ÿã * ã®å Žåãç³çã®å³åŽãæ¬ ããŠããããšã瀺ãã* ã¯ãæååã®å
é ãæ«å°Ÿä»¥å€ã«ã¯çŸãããåæã«äž¡åŽã«çŸããããšã¯ãªãã* ãäžã€ã ãã®æååãäžããããããšã¯ãªãã
</p>
<p>
å
¥åã§äžããããæååã®æåã®ç·æ°ã¯ 3000000 ãè¶
ããªãã
</p>
<h2>Output</h2>
<p>
åç³çã«ã€ããŠãåèªã®æ°ãïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
5 4
aloe
apple
apricot
cactus
cat
apple
ap*
*e
ca?*
</pre>
<h2>Sample Output 1</h2>
<pre>
1
2
2
2
</pre> | [
[
"5 4\naloe\napple\napricot\ncactus\ncat\napple\nap*\n*e\nca?*\n",
"5 4\naloe\napple\napricot\ncactus\ncat\napple\nap*\n*e\nca?*\n"
]
] |
p00318 | Ruins |
<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>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2015_hibara" width="700">
</center>
<br/>
<p>
äžå³ã®ãããªçŽç·ã§è¡šããã海岞ç·äžã«èŠ³æž¬ç¹ãèšçœ®ããæ¢æ»ã¬ãŒãã眮ããæ¢æ»ã¬ãŒãã§ã¯ã芳枬ç¹ãäžå¿ãšããããã倧ããã®ååã®ç¯å²ã«éºè·¡ããããšããããšããããããªããããããè€æ°ã®èŠ³æž¬ããŒã¿ãçµã¿åãããããšã§ãããçãç¯å²ã«çµã蟌ãããšãã§ããã
</p>
<p>
芳枬ç¹ã®äœçœ®ãšæ¢æ»ã¬ãŒãã瀺ãååŸãããªãããã€ãã®èŠ³æž¬ããŒã¿ãäžãããããšãã海岞ç·ããæ倧ã§ã©ã®ãããã®è·é¢ãŸã§èª¿æ»ããå¿
èŠãããããæ±ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>x<sub>1</sub></var> <var>r<sub>1</sub></var>
<var>x<sub>2</sub></var> <var>r<sub>2</sub></var>
:
<var>x<sub>N</sub></var> <var>r<sub>N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«æ¢æ»ã¬ãŒãã«ãã£ãŠæž¬å®ãããããŒã¿ã®æ° <var>N</var> (1 ≤ <var>N</var> ≤ 100000) ãäžãããããç¶ã <var>N</var> è¡ã«ã芳枬ããŒã¿ <var>i</var> ã®æµ·å²žç·äžã§ã®äœçœ®ãã¡ãŒãã«åäœã§è¡šãæŽæ° <var>x<sub>i</sub></var> (0 ≤ <var>x<sub>i</sub></var> ≤ 1,000,000) ãšããã®äœçœ®ããååŸäœã¡ãŒãã«ä»¥å
ã«éºè·¡ãååšããããè¡šãæŽæ° <var>r<sub>i</sub></var> (1 ≤ <var>r<sub>i</sub></var> ≤ 1,000,000) ãäžããããã芳枬ç¹ãåã芳枬ããŒã¿ãïŒã€ä»¥äžäžããããããšãããã
</p>
<p>
äžãããã芳枬ããŒã¿ãè€æ°ã®å Žåãããããã¹ãŠã®ååã«å«ãŸããç¹ãå¿
ãååšãããšèããŠããã
</p>
<h2>Output</h2>
<p>
海岞ç·ããæ倧ã§äœã¡ãŒãã«ãŸã§èª¿æ»ããå¿
èŠãããããå®æ°ã§åºåããããã ãã誀差ããã©ã¹ãã€ãã¹ 0.001 ã¡ãŒãã«ãè¶
ããŠã¯ãªããªãããã®æ¡ä»¶ãæºããã°å°æ°ç¹ä»¥äžã¯äœæ¡è¡šç€ºããŠãããã
</p>
<h2>Sample Input 1</h2>
<pre>
2
0 2
1 2
</pre>
<h2>Sample Output 1</h2>
<pre>
1.936
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
3
0 3
1 2
2 1
</pre>
<h2>Sample Output 2</h2>
<pre>
1.0
</pre>
<br/>
<h2>Sample Input 3</h2>
<pre>
2
0 1
3 2
</pre>
<h2>Sample Output 3</h2>
<pre>
0.0
</pre> | [
[
"2\n0 2\n1 2\n",
"2\n0 2\n1 2\n"
]
] |
p00319 | Downhill Race |
<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>
<ul>
<li> ãŽãŒã«å°ç¹ä»¥å€ã®æããã¯äžæ¬ä»¥äžã®ã©ã€ã³ã延ã³ãŠããã</li>
<li> ããæãšããæãçŽæ¥çµã¶ã©ã€ã³ã¯å€ããŠãäžã€ãããªãã</li>
<li> ã©ã€ã³ã¯æ±ºãŸã£ãæ¹åã«ããæ»éã§ããªãã</li>
<li> ã©ã®æã«ãå¿
ãã¹ã¿ãŒããããã©ãçãããšãã§ããã©ã®æããããŽãŒã«ã«ãã©ãçããã</li>
<li> ã©ã®ããã«ã©ã€ã³ããã©ã£ãŠãã£ãŠããåãæã«æ»ãããšã¯ãªãã</li>
</ul>
<p>
éžæã¯çŸåšããæãã延ã³ãŠããã©ã€ã³ãéžãã§æ¬¡ã«è¡ãæã決ããããšãã§ããŸããã©ã€ã³ã®éžã³æ¹ã¯èªç±ãªã®ã§ãéžæã¯æ»éããšã«ç°ãªãã©ã€ã³ãéã£ãŠãŽãŒã«ã«åããããšãã§ããŸãã
</p>
<p>
競æåå€ãã¹ããŒããã¯ã¿ãŒã®ãœã«ãåããããªããæ»ããšãã®ã²ã¬ã³ãã®ç¶æ
ãäºæ³ããŠãããŸãããããã«ãããšãïŒåç®ã®æ»éã§éã£ãã©ã€ã³ã¯ééã®åœ±é¿ã§éªè³ªãå€ãã£ãŠããŸããããïŒåç®ã®æ»éã§åãã©ã€ã³ãéããšããããæéãå€ããããšãããããã§ãããœã«ãåã¯ãããããã®ã©ã€ã³ãïŒåç®ã«éããšãã®æéãšãïŒåç®ã«éããšãã®æéãæããŠãããŸãããããªãã¯ãã®æ
å ±ããããã«ãïŒåã®æ»éã®åèšæéãæçã«ããæ»ãæ¹ãæãŸã§ã«èŠã€ããªããã°ãªããŸããã
</p>
<p>
ã²ã¬ã³ãã®ç¶æ
ãäžãããããšããïŒåã®æ»éã®åèšæéã§ãã£ãšãçãå€ãèšç®ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var> <var>P</var>
<var>s<sub>1</sub></var> <var>e<sub>1</sub></var> <var>t<sub>1,1</sub></var> <var>t<sub>1,2</sub></var>
<var>s<sub>2</sub></var> <var>e<sub>2</sub></var> <var>t<sub>2,1</sub></var> <var>t<sub>2,2</sub></var>
:
<var>s<sub>P</sub></var> <var>e<sub>P</sub></var> <var>t<sub>P,1</sub></var> <var>t<sub>P,2</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ãæã®æ° <var>N</var> (2 ≤ <var>N</var> ≤ 1000) ãšïŒã€ã®æãçµã¶ã©ã€ã³ã®æ° <var>P</var> (1 ≤ <var>P</var> ≤ 2000) ãäžãããããæã«ã¯ 1 ãã <var>N</var> ãŸã§ã®çªå·ãæ¯ãããŠããŠãã¹ã¿ãŒãå°ç¹ã®æã®çªå·ã1ããŽãŒã«å°ç¹ã®æã®çªå·ã <var>N</var> ã§ãããç¶ã <var>P</var> è¡ã«ãïŒã€ã®æãçµã¶ã©ã€ã³ã®æ
å ±ãäžãããããåè¡ã«ã¯ãã©ã€ã³ã®å§ç¹ã§ããæã®çªå· <var>s<sub>i</sub></var> (1 ≤ <var>s<sub>i</sub></var> < <var>N</var>)ãçµç¹ã§ããæã®çªå· <var>e<sub>i</sub></var> (1 < <var>e<sub>i</sub></var> ≤ <var>N</var>)ãïŒåç®ã«éããšãã®æèŠæé <var>t<sub>i,1</sub></var> (1 ≤ <var>t<sub>i,1</sub></var> ≤ 100000)ãåãã©ã€ã³ãïŒåç®ã«éã£ããšãã®æèŠæé(1 ≤ <var>t<sub>i,2</sub></var> ≤ 100000) ãäžããããã
</p>
<h2>Output</h2>
<p>
ïŒåã®æ»éã®åèšæéã§ãã£ãšãçãå€ãïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
3 3
1 2 1 2
2 3 1 2
1 3 1 3
</pre>
<h2>Sample Output 1</h2>
<pre>
3
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
3 3
1 2 1 2
2 3 1 2
1 3 1 1
</pre>
<h2>Sample Output 2</h2>
<pre>
2
</pre>
<br/>
<h2>Sample Input 3</h2>
<pre>
4 5
1 2 3 5
1 3 1 3
3 2 2 5
2 4 6 1
3 4 5 5
</pre>
<h2>Sample Output 3</h2>
<pre>
13
</pre> | [
[
"3 3\n1 2 1 2\n2 3 1 2\n1 3 1 3\n",
"3 3\n1 2 1 2\n2 3 1 2\n1 3 1 3\n"
]
] |
p00320 | Cuboid |
<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>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>h<sub>1</sub></var> <var>w<sub>1</sub></var>
<var>h<sub>2</sub></var> <var>w<sub>2</sub></var>
<var>h<sub>3</sub></var> <var>w<sub>3</sub></var>
<var>h<sub>4</sub></var> <var>w<sub>4</sub></var>
<var>h<sub>5</sub></var> <var>w<sub>5</sub></var>
<var>h<sub>6</sub></var> <var>w<sub>6</sub></var>
</pre>
<p>
å
¥åã¯ïŒè¡ãããªããããããã®è¡ã«åé·æ¹åœ¢ã®çžŠã®é·ããè¡šãæŽæ° <var>h<sub>i</sub></var> (1 ≤ <var>h<sub>i</sub></var> ≤ 1000) ãšæšªã®é·ããè¡šãæŽæ° <var>w<sub>i</sub></var> (1 ≤ <var>w<sub>i</sub></var> ≤ 1000) ãäžããããã
</p>
<h2>Output</h2>
<p>
çŽæ¹äœãäœæã§ããå Žåã«ã¯ãyesãããäœæã§ããªãå Žåã«ã¯ãnoããåºåããããã ããç«æ¹äœã¯çŽæ¹äœã®äžçš®ãªã®ã§ãç«æ¹äœã®å Žåã§ããyesããšåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
2 2
2 3
2 3
2 3
2 2
3 2
</pre>
<h2>Sample Output 1</h2>
<pre>
yes
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
2 2
2 3
2 3
2 3
2 2
2 2
</pre>
<h2>Sample Output 2</h2>
<pre>
no
</pre> | [
[
"2 2\n2 3\n2 3\n2 3\n2 2\n3 2\n",
"2 2\n2 3\n2 3\n2 3\n2 2\n3 2\n"
]
] |
p00321 | Related Products |
<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> | [
[
"5 2\n3 bread milk banana\n2 milk cornflakes\n3 potato bread milk\n4 cornflakes bread milk butter\n2 potato bread\n",
"5 2\n3 bread milk banana\n2 milk cornflakes\n3 potato bread milk\n4 cornflakes bread milk butter\n2 potato bread\n"
]
] |
p00322 | Alphametic |
<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>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2015_calculation1"><br/>
</center>
<br/>
<p>
ïŒããïŒã®æ°åãäžåºŠããçŸããªããšããæ¡ä»¶ã¯ãã®ãŸãŸã§ã以äžã®ããã«ãã£ãšããããã®æ°åãæ¬ ããŠããããæ£è§£ãšãªãæ°åã®åãæ¹ã¯äžéããããªãã®ã§ããããïŒ å®ã¯ãå¿
ãäžéãã«æ±ºãŸããšã¯éããŸããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2015_calculation2"><br/>
</center>
<br/>
<p>
äžã®å³ã®ãããªåœ¢ãããè«é£ãç®ã®ãããã®åãã¹ã®æ
å ±ãäžãããããšããæ£ããåãæ¹ãäœéãããããåºåããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>A</var> <var>B</var> <var>C</var> <var>D</var> <var>E</var> <var>F</var> <var>G</var> <var>H</var> <var>I</var>
</pre>
<p>
ïŒè¡ã«ãè«é£ãç®ã® <var></var> ãã <var></var> ã®ãã¹ã«å
¥ã£ãŠããæ°åã®æ
å ±ãäžããããããã ããäžããããå€ã -1 ã®ãšãã¯ããã®ãã¹ã®æ°åãæ¬ ããŠããããšãè¡šãã-1 以å€ã®å€ã¯ã1 ãã 9 ã®æŽæ°ã®ããããã§ããããã®éã«éè€ã¯ãªãã
</p>
<h2>Output</h2>
<p>
æ£ããåãæ¹ãäœéãããããïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
7 6 -1 1 -1 9 2 3 4
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
7 6 5 1 8 9 2 3 4
</pre>
<h2>Sample Output 2</h2>
<pre>
0
</pre>
<br/>
<h2>Sample Input 3</h2>
<pre>
-1 -1 -1 -1 -1 -1 8 4 6
</pre>
<h2>Sample Output 3</h2>
<pre>
12
</pre>
<br/>
<h2>Sample Input 4</h2>
<pre>
-1 -1 -1 -1 -1 -1 -1 -1 -1
</pre>
<h2>Sample Output 4</h2>
<pre>
168
</pre>
| [
[
"7 6 -1 1 -1 9 2 3 4\n",
"7 6 -1 1 -1 9 2 3 4\n"
]
] |
p00323 | Metal Recycling |
<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>
å¡ã®éãã«ã¯ãããã³ããšããåäœã䜿ããŸãã<var>x</var> ããã³ã®ã¢ã€ã
ããŠã ã®éã㯠2<sup><var>x</var></sup>ã°ã©ã ã§ããå®ç³ã§äŸãããšããã«ã©ãããã®ãããªãã®ã§ãããŸããå¡ã®åæ°ã«ã¯ããã«ã°ããšããåäœã䜿ããŸãã<var>y</var> ãã«ã°ã¯ 2<sup><var>y</var></sup> åã§ããïŒç®±ã«å
¥ã£ãŠããåç©ã®åæ°ã§ãããããŒã¹ãã®ãããªãã®ã§ãããã ãã<var>x</var> ãš <var>y</var> ã¯ ïŒ ä»¥äžã®æŽæ°ã§ãªããã°ãããŸããã
</p>
<p>
ååè» <var>i</var> ã¯ã <var>a<sub>i</sub></var> ããã³ã®éãã®ã¢ã€ã
ããŠã ã <var>b<sub>i</sub></var> ãã«ã°ãã€éããŸããããããŠéãŸã£ãã¢ã€ã
ããŠã ããçã®äžã«å
¥ããŠæº¶ãããããã€ãã®ã¢ã€ã
ããŠã ã®å¡ãåçããŸããããªãã¹ãã¢ã€ã
ããŠã ã®å¡ã®æ°ãå°ãªããªãããã«ããŸãããã®ãšããéããŠããã¢ã€ã
ããŠã ã®éãã®åèšãšãåçããŠã§ããã¢ã€ã
ããŠã ã®éãã®åèšã¯å€ãããŸããã
</p>
<p>
ååè»ãéããã¢ã€ã
ããŠã ã®å¡ã®ããã³åäœã®éããšãã«ã°åäœã®åæ°ãäžãããããšããåçåŸã®ã¢ã€ã
ããŠã ã®å¡ã®æ°ãæå°ã«ãªããããªçµæãæ±ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>a<sub>1</sub></var> <var>b<sub>1</sub></var>
<var>a<sub>2</sub></var> <var>b<sub>2</sub></var>
:
<var>a<sub>N</sub></var> <var>b<sub>N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ãååè»ã®æ° <var>N</var> (1 ≤ <var>N</var> ≤ 100000) ãäžãããããç¶ã <var>N</var> è¡ã«ãååè» <var>i</var> ãååããã¢ã€ã
ããŠã ã®å¡ã®ããããã³ãåäœã®éããè¡šãæŽæ° <var>a<sub>i</sub></var> (0 ≤ <var>a<sub>i</sub></var> ≤ 100000) ãšããã«ã°ãåäœã®åæ°ãè¡šãæŽæ° <var>b<sub>i</sub></var> (0 ≤ <var>b<sub>i</sub></var> ≤ 100000) ãäžããããã
</p>
<h2>Output</h2>
<p>
åçããåŸã«åŸãããã¢ã€ã
ããŠã ã®å¡ã®æ°ãæå°ã«ãªããããªãããã³åäœã®éããšãã«ã°åäœã®åæ°ããéãã®å°ããé ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
3
2 1
1 3
2 2
</pre>
<h2>Sample Output 1</h2>
<pre>
3 0
5 0
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
1
100000 2
</pre>
<h2>Sample Output 2</h2>
<pre>
100002 0
</pre> | [
[
"3\n2 1\n1 3\n2 2\n",
"3\n2 1\n1 3\n2 2\n"
]
] |
p00324 | Bilateral Trade |
<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>d<sub>1</sub></var>
<var>d<sub>2</sub></var>
:
<var>d<sub>N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ãè¡šã«æžãããå€ã®æ° <var>N</var> (1 ≤ <var>N</var> ≤ 200000) ãäžãããããç¶ã <var>N</var> è¡ã«ãè¡šã® <var>i</var> è¡ç®ã«æžãããå€ã瀺ãæŽæ° <var>d<sub>i</sub></var> (-10<sup>9</sup> ≤ <var>d<sub>i</sub></var> ≤ 10<sup>9</sup>) ãäžããããã
</p>
<h2>Output</h2>
<p>
è¡šããåŸããããç·åãïŒã«ãªãæé·ã®åºéã®é·ããïŒè¡ã«åºåããããã®ãããªåºéãååšããªãå Žåãã0ããïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
5
18
102
-155
53
32
</pre>
<h2>Sample Output 1</h2>
<pre>
3
</pre>
<p>
å
¥åäŸïŒã§ã¯ãïŒè¡ç®ããïŒè¡ç®ãŸã§ã®å€ã®ç·åãïŒã«ãªãã®ã§ãæé·ã®åºéã®é·ãã3ã«ãªãã
</p>
<br/>
<h2>Sample Input 2</h2>
<pre>
4
1
1
-1
-1
</pre>
<h2>Sample Output 2</h2>
<pre>
4
</pre>
<p>
å
¥åäŸïŒã§ã¯ãïŒè¡ç®ããïŒè¡ç®ã®ç·åãïŒã«ãªãããïŒè¡ç®ããïŒè¡ç®ãŸã§ã®å€ã®ç·åãïŒã«ãªãã®ã§ãæé·ã®åºéã®é·ãã4ã«ãªãã
</p> | [
[
"5\n18\n102\n-155\n53\n32\n",
"5\n18\n102\n-155\n53\n32\n"
]
] |
p00325 | Halting Problem |
<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>
TinyPowerãšããããã°ã©ãã³ã°èšèªãèããŸãããã®èšèªã®ããã°ã©ã ã¯è¡ã®äžŠã³ã§ããããã°ã©ã ã®åè¡ã«ã¯ãå
é ã«è¡çªå·ãæžãããã®åŸãã«æãäžã€æžããŸãããã®èšèªã§æžããæã®çš®é¡ã¯ä»¥äžã®éãã§ãã
</p>
<center>
<table width="680">
<tr>
<th style="text-align:left" width="200">æã®çš®é¡</th>
<th style="text-align:left">åäœ</th>
</tr>
<tr>
<td>ADD var<sub>1</sub> var<sub>2</sub> var<sub>3</sub></td>
<td>å€æ° var<sub>2</sub> ã®å€ãš var<sub>3</sub> ã®å€ãå ç®ããçµæãå€æ° var<sub>1</sub>ã«ä»£å
¥ãã</td>
</tr>
<tr>
<td>ADD var<sub>1</sub> var<sub>2</sub> con</td>
<td>å€æ° var<sub>2</sub> ã®å€ãšå®æ° con ãå ç®ããçµæãå€æ° var<sub>1</sub> ã«ä»£å
¥ãã</td>
</tr>
<tr>
<td>SUB var<sub>1</sub> var<sub>2</sub> var<sub>3</sub></td>
<td>å€æ° var<sub>2</sub> ã®å€ãã var<sub>3</sub> ã®å€ãæžç®ããçµæãå€æ° var<sub>1</sub> ã«ä»£å
¥ãã</td>
</tr>
<tr>
<td>SUB var<sub>1</sub> var<sub>2</sub> con</td>
<td>å€æ° var<sub>2</sub> ã®å€ããå®æ° con ãæžç®ããçµæãå€æ° var<sub>1</sub> ã«ä»£å
¥ãã</td>
</tr>
<tr>
<td>SET var<sub>1</sub> var<sub>2</sub></td>
<td>å€æ° var<sub>2</sub>ã®å€ãå€æ° var<sub>1</sub> ã«ä»£å
¥ãã</td>
</tr>
<tr>
<td>SET var<sub>1</sub> con</td>
<td>å®æ° con ãå€æ° var<sub>1</sub> ã«ä»£å
¥ãã</td>
</tr>
<tr>
<td>IF var<sub>1</sub> dest</td>
<td>å€æ° var<sub>1</sub> ã®å€ãïŒã§ãªããšãã ããè¡çªå· dest ã«ãžã£ã³ããã</td>
</tr>
<tr>
<td>HALT</td>
<td>ããã°ã©ã ãåæ¢ããã</td>
</tr>
</table>
</center>
<br/>
<p>
è¡çªå·ã¯æ£ã®æŽæ°ã§ãããã°ã©ã äžã«åãè¡çªå·ãïŒã€ä»¥äžçŸããããšã¯ãããŸãããå€æ°ã¯è±å°æåäžæåã§è¡šããå®æ°ãšå€æ°ã®å€ã¯æŽæ°ã§ããå€æ°ã®å®£èšã¯äžèŠã§ãå€æ°ã®åæå€ã¯ïŒã§ãã
</p>
<p>
ããã°ã©ã ã®å®è¡ã¯å
é ã®æããå§ãŸãã䞊ãã§ããé ã«æãå®è¡ãããŸãããã ããäžã®è¡šã«æžãããããã«ãIFæã®å€æ°ã®å€ãïŒã§ãªããšãã¯ãå€æ°ã®åŸãã«æžãããè¡çªå·ã§æå®ãããè¡ã«ãžã£ã³ããããã®è¡ã«æžãããæããå®è¡ãç¶ããŸããããã°ã©ã ã¯ä»¥äžã®ãšãã«åæ¢ããŸãã
</p>
<ul>
<li> HALTæãå®è¡ãããšãã</li>
<li> è² ã®æŽæ°ãŸãã¯ïŒïŒä»¥äžã®æŽæ°ãå€æ°ã«ä»£å
¥ããããšãããšãïŒå€æ°ã®å€ã¯æŽæ°ãããªãïŒã</li>
<li> ããã°ã©ã ã«çŸããªãè¡çªå·ã«ãžã£ã³ãããããšãããšãã</li>
<li> ããã°ã©ã ã®æåŸã®æãå®è¡ããåŸãããããã©ã®è¡ã«ããžã£ã³ãããªããšãã</li>
</ul>
<p>
TinyPowerã®ããã°ã©ã ãäžãããããšãããããåãŸããã©ãããå€å®ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>stmt<sub>1</sub></var>
<var>stmt<sub>2</sub></var>
:
<var>stmt<sub>N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ããã°ã©ã ã®è¡æ° <var>N</var> (1 ≤ <var>N</var> ≤ 50) ãäžãããããç¶ã <var>N</var> è¡ã«ãTinyPowerããã°ã©ã ã®æ <var>stmt<sub>i</sub></var> ãäžããããã<var>stmt<sub>i</sub></var> ã¯ã以äžã®ããããã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>line</var> ADD <var>var<sub>1</sub></var> <var>var<sub>2</sub></var> <var>var<sub>3</sub></var>
</pre>
<p>ãŸãã¯</p>
<pre>
<var>line</var> ADD <var>var<sub>1</sub></var> <var>var<sub>2</sub></var> <var>con</var>
</pre>
<p>ãŸãã¯</p>
<pre>
<var>line</var> SUB <var>var<sub>1</sub></var> <var>var<sub>2</sub></var> <var>var<sub>3</sub></var>
</pre>
<p>ãŸãã¯</p>
<pre>
<var>line</var> SUB <var>var<sub>1</sub></var> <var>var<sub>2</sub></var> <var>con</var>
</pre>
<p>ãŸãã¯</p>
<pre>
<var>line</var> SET <var>var<sub>1</sub></var> <var>var<sub>2</sub></var>
</pre>
<p>ãŸãã¯</p>
<pre>
<var>line</var> SET <var>var<sub>1</sub></var> <var>con</var>
</pre>
<p>ãŸãã¯</p>
<pre>
<var>line</var> IF <var>var<sub>1</sub></var> <var>dest</var>
</pre>
<p>ãŸãã¯</p>
<pre>
<var>line</var> HALT
</pre>
<p>
<var>line</var>, <var>dest</var> (1 ≤ <var>line</var>, <var>dest</var> ≤ 1000) ã¯è¡çªå·ã<var>var<sub>j</sub></var> (è±å°æåïŒæå)ã¯å€æ°ã<var>con</var> (0 ≤ <var>con</var> ≤ 15) ã¯å®æ°ãè¡šãã<var>stmt<sub>i</sub></var> äžã®åºåãã¯ç©ºçœïŒæåãšããããªããããã°ã©ã äžã«å€æ°ã¯å¿
ãïŒã€ä»¥äžçŸããç°ãªãå€æ°åã¯ïŒã€ãŸã§ããçŸããªããã®ãšããã
</p>
<h2>Output</h2>
<p>
ããã°ã©ã ãåæ¢ãããšãã¯ãããã°ã©ã ã«çŸããå€æ°ã®çµæããå€æ°åã®èŸæžé ã«æ¹è¡åºåãã§åºåããåæ¢ããªããšãã¯ãinfããåºåãããå€æ°ã®çµæã¯ãå€æ°åãšå€æ°ã®å€ãã=ãã§åºåã£ãŠåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
6
10 SET c 1
20 SET i 5
100 ADD s s i
110 SUB i i c
120 IF i 100
200 HALT
</pre>
<h2>Sample Output 1</h2>
<pre>
c=1
i=0
s=15
</pre>
<p>
å
¥åäŸïŒã¯ãïŒããïŒãŸã§ã®æŽæ°ã®åãèšç®ãããã®çµæãå€æ°sã«æ ŒçŽããããšãHALTæã®å®è¡ã§åæ¢ããã
</p>
<br/>
<h2>Sample Input 2</h2>
<pre>
3
10 SET c 1
120 IF c 10
20 HALT
</pre>
<h2>Sample Output 2</h2>
<pre>
inf
</pre>
<p>
å
¥åäŸïŒã¯ãè¡çªå·10ã§cã«1ã代å
¥ãã次ã®è¡çªå·120ã®IFæã§è¡çªå·10ã«æ»ãããšãç¹°ãè¿ãã®ã§ãåæ¢ããªãã
</p>
<br/>
<h2>Sample Input 3</h2>
<pre>
3
111 SET c 1
12 SUB c c 2
777 SET a 4
</pre>
<h2>Sample Output 3</h2>
<pre>
a=0
c=1
</pre>
<p>
å
¥åäŸïŒã¯ãè¡çªå·111ã§cã«1ã代å
¥ãã次ã®è¡çªå·12ã§cã«-1ã代å
¥ããããšããã®ã§ãåæ¢ããããã®ãšãcã®å€ã¯-1ã«æŽæ°ãããªããè¡çªå·777ã¯å®è¡ãããªãã®ã§ãaã®å€ã¯åæå€0ã®ãŸãŸã§ããã
</p> | [
[
"6\n10 SET c 1\n20 SET i 5\n100 ADD s s i\n110 SUB i i c\n120 IF i 100\n200 HALT\n",
"6\n10 SET c 1\n20 SET i 5\n100 ADD s s i\n110 SUB i i c\n120 IF i 100\n200 HALT\n"
]
] |
p00326 | Scheduler |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>ã¹ã±ãžã¥ãŒã©</H1>
<p>
ããªãã¯ãŠããŒã¯ãªãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ããŠã³ãºã°ãïŒïŒãã®éçºã«åãçµãã§ãããæ§èœã決å®ä»ããã¹ã±ãžã¥ãŒã©ã®èšèšã«é ãæ©ãŸããŠãããã¹ã±ãžã¥ãŒã©ãšã¯ãå®è¡ãã¹ãåŠçãã¿ã¹ã¯ãšããåäœã§è¡šçŸããããããã©ã®é åºã§å®è¡ãããã決å®ããããã°ã©ã ã§ãããã¹ã±ãžã¥ãŒã©ã¯ã¿ã¹ã¯ã«ïŒãã <var>N</var> ã®çªå·ãã€ããŠç®¡çãããå
šãŠã®ã¿ã¹ã¯ã¯ <var>K</var> åã®å±æ§ <var>f<sub>1</sub></var>, <var>f<sub>2</sub></var>,..., <var>f<sub>K</sub></var> ãæã¡ãåå±æ§ã«ã¯ããããåºæã®å€ãèšå®ãããŠããããã ããããïŒã€ã®ã¿ã¹ã¯ã«ã€ããŠã察å¿ããå±æ§ã®å€ãã¹ãŠãåãã«ãªãããšã¯ãªãã
</p>
<p>
ããã¿ã¹ã¯ã«ã¯ããã®ã¿ã¹ã¯ã®å®è¡ãå§ããåãŸã§ã«å®è¡ãå®äºããŠããªããã°ãªããªãã¿ã¹ã¯ãäžããããããšããããã¿ã¹ã¯ïŒ¡ãã¿ã¹ã¯ïŒ¢ã®åã«å®äºããŠããªããã°ãªããªãããšããã¿ã¹ã¯ïŒ¡ → ã¿ã¹ã¯ïŒ¢ããšè¡šããäŸãã°ãã¿ã¹ã¯ïŒ → ã¿ã¹ã¯ïŒãã¿ã¹ã¯ïŒ → ã¿ã¹ã¯ïŒãšããé¢ä¿ãããã°ãã¿ã¹ã¯ïŒãåŠçããåã«ã¿ã¹ã¯ïŒãšã¿ã¹ã¯ïŒã®äž¡æ¹ã®åŠçãçµãã£ãŠããªããã°ãªããªãããã®ãããªé¢ä¿ãã¿ã¹ã¯éã®äŸåé¢ä¿ãšããããã ããããã¿ã¹ã¯ããäŸåé¢ä¿ããã©ã£ãŠãã£ãŠããã®ã¿ã¹ã¯ã«ãã©ãçãããšã¯ãªãã
</p>
<p>
ã¹ã±ãžã¥ãŒã©ã¯äŸåé¢ä¿ã«åŸã£ãŠãå®è¡é åºã決å®ãããããããäŸåé¢ä¿ã ãã§ã¯é åºãäžéãã«å®ãŸããªãå Žåãããããã®ãããªå Žåã¯ãåã¿ã¹ã¯ãæã€å±æ§ã®å€ã«ãã£ãŠã次ã«åŠçããã¿ã¹ã¯ãéžæããã
</p>
<p>
ãŠã³ãºã°ãïŒïŒã®ã¿ã¹ã¯ã¯å±æ§ãè€æ°ãã€ããããã¹ãŠã®å±æ§ã®å€ãèæ
®ããŠå®è¡é åºã決å®ããå¿
èŠãããããã®ããã«ãå±æ§ãæ¯èŒããé çªãå®ããè©äŸ¡é åºãçšãããè©äŸ¡é åºãæãå
ã®å±æ§ãæ¯èŒãããã®å±æ§ã®å€ãæã倧ããã¿ã¹ã¯ãéžæããããã®ãããªã¿ã¹ã¯ãè€æ°ããå Žåã¯ãè©äŸ¡é åºããã®æ¬¡ã®å±æ§ã§æ¯èŒãã以äžåæ§ãªæé ãç¹°ãè¿ããäŸãã°ã以äžã®3 ã€ã®å±æ§ãæã€3 ã€ã®ã¿ã¹ã¯ã«ã€ããŠèããã
</p>
<center>
<table width="500">
<tr>
<td width="200">ã¿ã¹ã¯ïŒŒå±æ§</td>
<td width="100"><var>f<sub>1</sub></var></td>
<td width="100"><var>f<sub>2</sub></var></td>
<td width="100"><var>f<sub>3</sub></var></td>
</tr>
<tr>
<td>X</td> <td>3</td> <td>3</td> <td>2</td>
</tr>
<tr>
<td>Y</td> <td>3</td> <td>2</td> <td>2</td>
</tr>
<tr>
<td>Z</td> <td>3</td> <td>1</td> <td>3</td>
</tr>
</table>
</center>
<br/>
<p>
è©äŸ¡é åºã<var>f<sub>1</sub></var> <var>f<sub>2</sub></var> <var>f<sub>3</sub></var>ã<var>f<sub>2</sub></var> <var>f<sub>1</sub></var> <var>f<sub>3</sub></var>ããŸã㯠<var>f<sub>2</sub></var> <var>f<sub>3</sub></var> <var>f<sub>1</sub></var> ã«èšå®ãããŠããå Žåã¯ãã¿ã¹ã¯X ãéžã°ããããŸããè©äŸ¡é åºã <var>f<sub>1</sub></var> <var>f<sub>3</sub></var> <var>f<sub>2</sub></var>ã<var>f<sub>3</sub></var> <var>f<sub>1</sub></var> <var>f<sub>2</sub></var>ããŸã㯠<var>f<sub>3</sub></var> <var>f<sub>2</sub></var> <var>f<sub>1</sub></var> ã«èšå®ãããŠããå Žåã¯ã¿ã¹ã¯Z ãéžã°ããã
</p>
<p>
ãŠã³ãºã°ãïŒïŒã®ã¹ã±ãžã¥ãŒã©ã®ç¹åŸŽã¯ãå±æ§ã®è©äŸ¡é åºãéäžã§äœåºŠã§ãå€æŽã§ããããšã§ãããè©äŸ¡é åºã¯ãããåæ°ã®ã¿ã¹ã¯ã®å®è¡ãå®äºããæç¹ã§å€æŽã§ããããã ããã¹ã±ãžã¥ãŒã©ãæåã«äœ¿ãè©äŸ¡é åºã¯ããããã決ãŸã£ãŠããã
</p>
<p>
åã¿ã¹ã¯ã®å±æ§ã®å€ãã¿ã¹ã¯ã®äŸåé¢ä¿ãè©äŸ¡é åºã®å€æŽæ
å ±ãäžãããããšããã¿ã¹ã¯ãå®è¡ããé åºãå ±åããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var> <var>K</var>
<var>f<sub>1,1</sub></var> <var>f<sub>1,2</sub></var> ... <var>f<sub>1,K</sub></var>
<var>f<sub>2,1</sub></var> <var>f<sub>2,2</sub></var> ... <var>f<sub>2,K</sub></var>
:
<var>f<sub>N,1</sub></var> <var>f<sub>N,2</sub></var> ... <var>f<sub>N,K</sub></var>
<var>D</var>
<var>a<sub>1</sub></var> <var>b<sub>1</sub></var>
<var>a<sub>2</sub></var> <var>b<sub>2</sub></var>
:
<var>a<sub>D</sub></var> <var>b<sub>D</sub></var>
<var>e<sub>0,1</sub></var> <var>e<sub>0,2</sub></var> ... <var>e<sub>0,K</sub></var>
<var>R</var>
<var>m<sub>1</sub></var> <var>e<sub>1,1</sub></var> <var>e<sub>1,2</sub></var> ...⊠<var>e<sub>1,K</sub></var>
<var>m<sub>2</sub></var> <var>e<sub>2,1</sub></var> <var>e<sub>2,2</sub></var> ...⊠<var>e<sub>2,K</sub></var>
:
<var>m<sub>R</sub></var> <var>e<sub>R,1</sub></var> <var>e<sub>R,2</sub></var> ...⊠<var>e<sub>R,K</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ãã¿ã¹ã¯ã®æ° <var>N</var> (2 ≤ <var>N</var> ≤ 50000) ãšãåã¿ã¹ã¯ãæã€å±æ§ã®æ° <var>K</var> (1 ≤ <var>K</var> ≤ 4) ãäžãããããç¶ã <var>N</var> è¡ã«ãã¿ã¹ã¯ <var>i</var> ãæã€å±æ§ã®å€ <var>f<sub>i,j</sub></var> (1 ≤ <var>f<sub>i,j</sub></var> ≤ 100000) ãäžãããããç¶ãïŒè¡ã«ãäŸåé¢ä¿ã®åæ° <var>D</var> (0 ≤ <var>D</var> ≤ 200000) ãäžãããããç¶ã <var>D</var> è¡ã«äŸåé¢ä¿ <var>a<sub>i</sub></var> → <var>b<sub>i</sub></var> (1 ≤ <var>a<sub>i</sub></var>, <var>b<sub>i</sub></var> ≤ <var>N</var>) ãäžããããã
</p>
<p>
ç¶ãïŒè¡ã«ãæåã®è©äŸ¡é åº <var>e<sub>0,j</sub></var> (1 ≤ <var>e<sub>0,j</sub></var> ≤ <var>K</var>) ãäžãããããç¶ãïŒè¡ã«ãè©äŸ¡é åºã®å€æŽåæ° <var>R</var> (0 ≤ <var>R</var> < <var>N</var>) ãäžãããããç¶ã <var>R</var> è¡ã«ãè©äŸ¡é åºã®å€æŽæ
å ±ãäžããããã<var>i</var> åç®ã®å€æŽæ
å ±ã¯ãå®è¡ãå®äºããã¿ã¹ã¯ã®åæ° <var>m<sub>i</sub></var> (1 ≤ <var>m<sub>i</sub></var> < <var>N</var>) ãšè©äŸ¡é åº <var>e<sub>i,j</sub></var> (1 ≤ <var>e<sub>i,j</sub></var> ≤ <var>K</var>) ãããªããå
šéšã§ <var>m<sub>i</sub></var> åã®ã¿ã¹ã¯ã®å®è¡ãå®äºããæç¹ã§ãè©äŸ¡é åºã <var>e<sub>i,1</sub></var>, <var>e<sub>i,2</sub></var>,... , <var>e<sub>i,K</sub></var> ã«å€æŽããããšã瀺ãã
</p>
<p>
è©äŸ¡é åºã®å€æŽæ
å ±ã¯ä»¥äžã®æ¡ä»¶ãæºããã
</p>
<ul>
<li> <var>e<sub>i,1</sub></var>, <var>e<sub>i,2</sub></var>,..., <var>e<sub>i,K</sub></var> äžã«åãå€ã¯ïŒã€ä»¥äžçŸããªãã</li>
<li> <var>i</var> < <var>j</var> ã®ãšãã <var>m<sub>i</sub></var> < <var>m<sub>j</sub></var> ã§ããã</li>
</ul>
<h2>Output</h2>
<p>
ã¹ã±ãžã¥ãŒã©ãåŠçããé çªã«ãã¿ã¹ã¯ã®çªå·ãåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
5 3
1 5 2
3 8 5
1 2 3
5 5 5
4 8 2
0
1 2 3
2
2 2 3 1
4 3 1 2
</pre>
<h2>Sample Output 1</h2>
<pre>
4
5
2
1
3
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
5 2
1 1
2 1
3 1
4 4
5 2
3
1 4
2 4
2 5
1 2
1
3 2 1
</pre>
<h2>Sample Output 2</h2>
<pre>
3
2
5
1
4
</pre> | [
[
"5 3\n1 5 2\n3 8 5\n1 2 3\n5 5 5\n4 8 2\n0\n1 2 3\n2\n2 2 3 1\n4 3 1 2\n",
"5 3\n1 5 2\n3 8 5\n1 2 3\n5 5 5\n4 8 2\n0\n1 2 3\n2\n2 2 3 1\n4 3 1 2\n"
]
] |
p00327 | Disappearing Sequence |
<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>
<ul>
<li> æ°åãããåãæ°åãïŒã€ä»¥äžäžŠãã§ããéšåãé©åœã«éžã¶ããã®éšåãå«ã¿ãé£ç¶ããŠçŸããŠããåãæ°åããã¹ãŠæ¶ãã</li>
<li> æ¶ããéšåã®å³åŽã«æ°åãæ®ã£ãŠããå Žåã¯ããããå·Šã«è©°ããŠãæ°åãïŒã€ã«ãŸãšããã</li>
<li> äžã®ïŒã€ã®æäœãç¹°ãè¿ããçµæããã¹ãŠã®æ°åãæ¶ããã°ã²ãŒã ã¯ãªã¢ãšãªãã</li>
</ul>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2015_array"><br/>
</center>
<br/>
<p>
äŸãã°ãäžã®å³ã®ãã㪠1,2,3,3,2,2,1,2,2 ãšããæ°åã®å Žåã<br/>
å·Šããæ°ããŠãïŒçªç®ãïŒçªç®ã®ïŒãæ¶ããš 1,2,2,2,1,2,2 <br/>
å·Šããæ°ããŠãïŒçªç®ããïŒçªç®ã®ïŒãæ¶ããš 1,1,2,2<br/>
å·Šããæ°ããŠãïŒçªç®ãšïŒçªç®ã®ïŒãæ¶ããš 2,2<br/>
å·Šããæ°ããŠãïŒçªç®ãšïŒçªç®ã®ïŒãæ¶ããšãã²ãŒã ã¯ãªã¢ãšãªããŸãã
</p>
<p>
ãã ããã©ã®ããã«æ°åãæ¶ããŠãã¯ãªã¢ã§ããªãæ°åããããŸããããšãã°ã1,2,3,3,1,2 ã 1,2,3,1,2,3 ãªã©ã®æ°åã§ããçãæ°åã§ããã°ããã ãåã§ãã¯ãªã¢ã§ãããã©ãããããã«åãããã¯ãªã¢ã§ããªããšåããã°éãæ°åã«ãã£ã¬ã³ãžã§ããŸãããé·ãæ°åã«ãªããšããç°¡åã«ã¯ãããŸããã
</p>
<p>
äžããããæ°åãäžã®ã²ãŒã ãã¯ãªã¢ã§ãããã©ããå€å®ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>c<sub>1</sub></var> <var>c<sub>2</sub></var> ... <var>c<sub>N</sub></var>
</pre>
<p>
ïŒè¡ç®ã® <var>N</var> (1 ≤ <var>N</var> ≤ 100) ã¯ãæ°åã®é·ããè¡šãæŽæ°ã§ãããïŒè¡ç®ã«ã¯ïŒã€ã®ç©ºçœã§åºåããã <var>N</var> åã®æŽæ° <var>c<sub>i</sub></var> (1 ≤ <var>c<sub>i</sub></var> ≤ 9) ãäžããããã<var>c<sub>i</sub></var> ã¯æ°åã® <var>i</var> çªç®ã®æ°åã瀺ãã
</p>
<h2>Output</h2>
<p>
äžã«ç€ºãããã«ãŒã«ã§æ°åãæ¶ãããšãã§ããå Žåã¯ãyesããã§ããªãå Žåã¯ãnoããåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
8
1 2 3 3 2 1 2 2
</pre>
<h2>Sample Output 1</h2>
<pre>
yes
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
7
1 2 2 1 1 3 3
</pre>
<h2>Sample Output 2</h2>
<pre>
yes
</pre>
<br/>
<h2>Sample Input 3</h2>
<pre>
16
9 8 8 7 7 6 5 4 4 5 1 1 2 2 3 3
</pre>
<h2>Sample Output 3</h2>
<pre>
no
</pre>
<br/>
<h2>Sample Input 4</h2>
<pre>
5
1 1 2 2 1
</pre>
<h2>Sample Output 4</h2>
<pre>
yes
</pre>
| [
[
"8\n1 2 3 3 2 1 2 2\n",
"8\n1 2 3 3 2 1 2 2\n"
]
] |
p00328 | Line Segment Arrangement |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>ç·åé
眮</H1>
<p>
倧åŠã¯ä»å¹Žãããã°ã©ãã³ã°ã³ã³ãã¹ããéå¬ãããäœé¡ããŒã ã®äžå¡ã§ããããªãã¯ãèšç®å¹ŸäœåŠã®åé¡ã®å
¥åããŒã¿ã®äœæãæ
åœããããšã«ãªã£ããããªããäœãããå
¥åããŒã¿ã¯ã<var>x</var> 軞ãŸã㯠<var>y</var> 軞ã«å¹³è¡ã§ãäºãã«è§Šãåãããšã®ãªãç·åã®éåã§ãããããªãã¯ã次ã®ã¢ã«ãŽãªãºã ã«åºã¥ããããŒã¿çæããã°ã©ã ãéçºããŠãå
¥åããŒã¿ãçæããã
</p>
<ol>
<li> <var>xy</var> å¹³é¢äžã®ç·åã®éå <var>T</var> ã空ã«ããã</li>
<li> 次ã®åŠçã <var>N</var> åç¹°ãè¿ãã
<ul>
<li><var>x</var> 軞ãŸã㯠<var>y</var> 軞ã«å¹³è¡ãªé©åœãªç·å <var>s</var> ãäœãã</li>
<li><var>s</var> ã <var>T</var> å
ã®ã©ã®ç·åã«ã觊ããªãå Žå㯠<var>s</var> ã <var>T</var> ã«è¿œå ãã觊ããå Žå㯠<var>s</var> ãè¿œå ããªãã</li>
</ul>
</li>
</ol>
<p>
<var>x</var> 軞ãŸã㯠<var>y</var> 軞ã«å¹³è¡ãª <var>N</var> æ¬ã®ç·åãé çªã«å
¥åããåç·åãå¹³é¢äžã«è¿œå ããããã©ãããå€å®ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>px<sub>1</sub></var> <var>py<sub>1</sub></var> <var>qx<sub>1</sub></var> <var>qy<sub>1</sub></var>
<var>px<sub>2</sub></var> <var>py<sub>2</sub></var> <var>qx<sub>2</sub></var> <var>qy<sub>2</sub></var>
:
<var>px<sub>N</sub></var> <var>py<sub>N</sub></var> <var>qx<sub>N</sub></var> <var>qy<sub>N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ç·åã®æ° <var>N</var> (1 ≤ <var>N</var> ≤ 100000) ãäžãããããç¶ã <var>N</var> è¡ã«ã<var>i</var> çªç®ã«è¿œå ãããç·åã®æ
å ±ãäžãããããåè¡ã«äžããããïŒã€ã®æŽæ° <var>px<sub>i</sub></var>, <var>py<sub>i</sub></var>, <var>qx<sub>i</sub></var>, <var>qy<sub>i</sub></var> (0 ≤ <var>px<sub>i</sub></var>, <var>py<sub>i</sub></var>, <var>qx<sub>i</sub></var>, <var>qy<sub>i</sub></var> ≤ 10<sup>9</sup>) ã¯ããããã <var>i</var> çªç®ã®ç·åã®ç«¯ç¹ã® <var>x</var> 座æšã<var>y</var> 座æšãããäžã€ã®ç«¯ç¹ã® <var>x</var> 座æšã<var>y</var> 座æšãè¡šãããã ããç·åã®é·ãã¯ïŒä»¥äžã§ããã
</p>
<h2>Output</h2>
<p>
åç·åã«ã€ããŠãè¿œå ãããå Žåã1ãããè¿œå ãããªãå Žåã0ããïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
9
0 2 5 2
1 3 1 7
0 6 3 6
2 4 8 4
4 0 4 5
6 3 6 0
5 6 7 6
8 3 8 7
6 5 11 5
</pre>
<h2>Sample Output 1</h2>
<pre>
1
1
0
1
0
1
1
0
1
</pre> | [
[
"9\n0 2 5 2\n1 3 1 7\n0 6 3 6\n2 4 8 4\n4 0 4 5\n6 3 6 0\n5 6 7 6\n8 3 8 7\n6 5 11 5\n",
"9\n0 2 5 2\n1 3 1 7\n0 6 3 6\n2 4 8 4\n4 0 4 5\n6 3 6 0\n5 6 7 6\n8 3 8 7\n6 5 11 5\n"
]
] |
p00329 | Amidakuji |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>ãã¿ã ãã</H1>
<p>
PCK åã¯ã¿ããªã§ã²ãŒã 倧äŒãããŠããŸãããã®ã²ãŒã 倧äŒã§ã¯ã倧äŒã®æåŸã«ãã¿ã ããã§é äœãå
¥ãæ¿ããŸãã倧äŒã«ã¯ <var>N</var> 人ã®ãã¬ã€ã€ãŒãåå ããŠããããã¿ã ããã«ã¯ <var>N</var> æ¬ã®çžŠæ£ããããŸãã
</p>
<p>
ãã¿ã ããã¯ãå³ã®ããã« <var>N</var> - 1 段ã®éšåããã§ããŠããããããã 1 ãã <var>N</var>-1 ã®çªå·ãå²ãåœãŠãããŠããŸããåéšåã¯ããã¿ã ããã®äžéšã暪æ¹åã«åãåã£ãéšåã§ããåéšåã«ã¯ããã€ãã®æšªæ£ãåŒãããŠããŸãããéšåã®äžã®æšªæ£ã¯ãã¹ãŠåãé«ãã«ãããŸãã暪æ£å士ãã€ãªããããšã¯ãããŸããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2015_amida"><br/>
</center>
<br/>
<p>
倧äŒã®æåŸã«ãé äœã®é«ã人ããå³ããå·Šã®é ã«çžŠæ£ãå²ãåœãŠãããŸããPCK åã¯çŸæç¹ã§æäžäœãªã®ã§ã巊端ããã¹ã¿ãŒãã§ããäŸãã°ãäžå³ã®çµã¿ç«ãŠæ¹ã§ã¯ãïŒäœã ã£ãPCK åã¯ããã®ãã¿ã ããã«ãã£ãŠïŒäœïŒå³ããïŒçªç®ã®æ£ïŒã«æµ®äžããããšãã§ããŸãã
</p>
<p>
ãã®ã²ãŒã ã§ã¯ãæäžäœã®äººã«ãã¿ã ãããçµã¿ç«ãŠãæš©å©ãäžããããŸããPCK åã¯ããŸããã¿ã ããã®éšåã®é çªã決ããŠãé転åªåãçã£ãŠããŸãããã ããéšåãå転ããããšã¯ã§ããŸããã
</p>
<p>
ïŒâ»è£è¶³ïŒãã¿ã ããã®ãã©ãæ¹ã«ã€ããŠïŒ<br/>
ãã¿ã ããã®ãã瞊æ£ã®äžç«¯ããåºçºããŠäžããäžãžé²ãããã ãã暪æ£ãããå°ç¹ã§ã¯ãã®æšªæ£ã§ã€ãªãã£ãå¥ã®çžŠæ£ã«ç§»åããããããã瞊æ£ã®äžç«¯ã«ãã©ãçããŸã§ç¹°ãè¿ãã
</p>
<p>
ã²ãŒã ã®åå 人æ°ãšãã¿ã ããã®éšåã®æ
å ±ãå
¥åããPCK åãåªåã§ãããã©ããå€å®ããããã°ã©ã ãäœæãããåªåã§ããå Žåããã®ãã¿ã ããã®éšåã®äžŠã³ãïŒã€åºåããããã ãããã®ãããªäžŠã¹æ¹ãè€æ°ããå Žåã¯ãäžããããéšåã®çªå·ã§èŸæžé æå°ã®ãã®ãåºåããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>b<sub>1,1</sub></var> <var>b<sub>1,2</sub></var> ... <var>b<sub>1,N−1</sub></var>
<var>b<sub>2,1</sub></var> <var>b<sub>2,2</sub></var> ... <var>b<sub>2,N−1</sub></var>
:
<var>b<sub>N−1,1</sub></var> <var>b<sub>N−1,2</sub></var> ... <var>b<sub>N−1,N−1</sub></var>
</pre>
<p>
ïŒè¡ç®ã«å€§äŒã®åå è
æ° <var>N</var> (2 ≤ <var>N</var> ≤ 500) ãäžãããããç¶ã <var>N</var>-1 è¡ã« <var>i</var> çªç®ã®éšåã®æšªæ£ã®æ
å ±ãäžããããã<var>b<sub>i,j</sub></var> ã 1 ã§ãããšãã<var>i</var> çªç®ã®éšåã®ãå·Šãã <var>j</var> æ¬ç®ã®çžŠæ£ãã <var>j</var>+1 çªç®ã®çžŠæ£ãžæšªæ£ãåŒãããŠããããšãè¡šãã<var>b<sub>i,j</sub></var> ã 0 ã§ãããšãã<var>i</var> çªç®ã®éšåã®ãå·Šãã <var>j</var> æ¬ç®ã®çžŠæ£ãã <var>j</var>+1 çªç®ã®çžŠæ£ãžæšªæ£ã¯åŒãããŠããªãããšãè¡šãã<var>b<sub>i,j</sub></var> ã 1 ã§ãããšãã<var>b<sub>i,j+1</sub></var> ã 1 ãšãªããããªéšåã¯äžããããªãããŸãã暪æ£ã®ç·æ°ã¯ 10000 ãè¶ããªãã
</p>
<h2>Output</h2>
<p>
PCK åãåªåã§ããå ŽåïŒïŒè¡ç®ã«ãyesããšåºåãããç¶ã <var>N</var>-1 è¡ã«ããã¿ã ããã®äžããé ã«ãéšåã®çªå·ã®äžŠã³ãåºåããããã®ãããªäžŠã³ãè€æ°ããå ŽåãèŸæžé æå°ã§ãã䞊ã³ãåºåãããPCK åãåªåã§ããªãå ŽåãïŒè¡ã«ãnoããšåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
6
1 0 0 0 1
1 0 1 0 1
0 1 0 1 0
0 0 0 1 0
0 1 0 0 1
</pre>
<h2>Sample Output 1</h2>
<pre>
yes
1
3
2
4
5
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
5
0 1 0 1
0 1 0 1
1 0 1 0
1 0 0 1
</pre>
<h2>Sample Output 2</h2>
<pre>
yes
4
1
3
2
</pre>
<p>
4 1 3 2 ãš 4 2 3 1 ã®ïŒéãã®çµã¿ç«ãŠæ¹ãå¯èœã ããèŸæžé ã§å°ããæ¹ã® 4 1 3 2 ãåºåããã
</p>
<br/>
<h2>Sample Input 3</h2>
<pre>
5
1 0 0 1
0 1 0 1
1 0 0 0
0 1 0 1
</pre>
<h2>Sample Output 3</h2>
<pre>
no
</pre> | [
[
"6\n1 0 0 0 1\n1 0 1 0 1\n0 1 0 1 0\n0 0 0 1 0\n0 1 0 0 1\n",
"6\n1 0 0 0 1\n1 0 1 0 1\n0 1 0 1 0\n0 0 0 1 0\n0 1 0 0 1\n"
]
] |
p00330 | Word |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>ã¯ãŒã</H1>
<p>
ã³ã³ãã¥ãŒã¿ã§æ±ãããããŒã¿ã®æå°åäœãããã(bit)ãšåŒã³ãè€æ°ã®ãããããŸãšããŠè¡šããæ
å ±éãã¯ãŒã(word)ãšåŒã³ãŸããçŸåšãå€ãã®ã³ã³ãã¥ãŒã¿ã§ã¯ïŒã¯ãŒããïŒïŒããããšããŠåŠçããŠããŸãã
</p>
<p>
ïŒã¯ãŒããïŒïŒãããã§è¡šãã³ã³ãã¥ãŒã¿ã«ã€ããŠãã¯ãŒãåäœã§äžããããããŒã¿é <var>W</var> ããããåäœã§åºåããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>W</var>
</pre>
<p>
å
¥åã¯ïŒè¡ãããªããããŒã¿é <var>W</var> (0 ≤ <var>W</var> ≤ 100) ãäžããããã
</p>
<h2>Output</h2>
<p>
ãããåäœã®å€ãïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
4
</pre>
<h2>Sample Output 1</h2>
<pre>
128
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
3
</pre>
<h2>Sample Output 2</h2>
<pre>
96
</pre> | [
[
"4\n",
"4\n"
]
] |
p00331 | Sunrise and Sunset |
<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>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2016_sunset_1" width="640">
</center><br/>
<p>
ããæå»ã®å°å¹³ç·ãã倪éœã®äžå¿ãŸã§ã®é«ããšã倪éœã®ååŸãå
¥åãšãããã®æå»ããæŒéããããæ¥ã®åºãŸãã¯æ¥ã®å
¥ãããããå€éãããåºåããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>H</var> <var>R</var>
</pre>
<p>
å
¥åã¯ïŒè¡ãããªããããæå»ã®å°å¹³ç·ãã倪éœã®äžå¿ãŸã§ã®é«ããè¡šãæŽæ° <var>H</var> (-1000 ≤ <var>H</var> ≤ 1000) ãšååŸãè¡šãæŽæ° <var>R</var> (1 ≤ <var>R</var> ≤ 1000) ãäžããããããã ãã<var>H</var> ã¯å€ªéœã®äžå¿ãå°å¹³ç·äžã«ãããšãã 0 ãšããŠãããããäžã«ãããšãã¯æ£ãäžã«ãããšãã¯è² ãšããã
</p>
<h2>Output</h2>
<p>
æŒéã®ãšãã1ããæ¥ã®åºãŸãã¯æ¥ã®å
¥ãã®ãšãã0ããå€éã®ãšãã-1ããïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
-3 3
</pre>
<h2>Sample Output 1</h2>
<pre>
0
</pre>
<center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2016_sunset_2" width="240"></center>
<br/>
<h2>Sample Input 2</h2>
<pre>
3 3
</pre>
<h2>Sample Output 2</h2>
<pre>
1
</pre>
<center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2016_sunset_3" width="240"></center>
<br/>
<h2>Sample Input 3</h2>
<pre>
-4 3
</pre>
<h2>Sample Output 3</h2>
<pre>
-1
</pre>
<center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2016_sunset_4" width="240"></center>
| [
[
"-3 3\n",
"-3 3\n"
]
] |
p00332 | Japanese Calendar |
<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>
<center>
<table>
<tr>
<th width="260">西æŠ</th>
<th width="260">åæŠ</th>
</tr>
<tr>
<td>ïŒïŒïŒïŒå¹ŽããïŒïŒïŒïŒå¹Ž</td>
<td>ææ²»å
幎ããææ²»ïŒïŒå¹Ž</td>
</tr>
<tr>
<td>ïŒïŒïŒïŒå¹ŽããïŒïŒïŒïŒå¹Ž</td>
<td>倧æ£å
幎ãã倧æ£ïŒïŒå¹Ž</td>
</tr>
<tr>
<td>ïŒïŒïŒïŒå¹ŽããïŒïŒïŒïŒå¹Ž</td>
<td>æåå
幎ããæåïŒïŒå¹Ž</td>
</tr>
<tr>
<td>ïŒïŒïŒïŒå¹ŽããïŒïŒïŒïŒå¹Ž</td>
<td>å¹³æå
幎ããå¹³æïŒïŒå¹Ž</td>
</tr>
</table>
</center>
<br>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>E</var> <var>Y</var>
</pre>
<p>
å
¥åã¯ïŒè¡ãããªãã<var>E</var> (0 ≤ <var>E</var> ≤ 4) ã¯äžããããæŠã®çš®é¡ã<var>Y</var> ã¯ãã®æŠã§ã®å¹Žã§ããã<var>E</var> ã 0 ã®ãšãã¯è¥¿æŠ <var>Y</var> (1868 ≤ <var>Y</var> ≤ 2016)幎ã1 ã®ãšãã¯åæŠã®ææ²» <var>Y</var> (1 ≤ <var>Y</var> ≤ 44)幎ã2 ã®ãšãã¯åæŠã®å€§æ£ <var>Y</var> (1 ≤ <var>Y</var> ≤ 14)幎ã3 ã®ãšãã¯åæŠã®æå <var>Y</var> (1 ≤ <var>Y</var> ≤ 63)幎ã4 ã®ãšãã¯åæŠã®å¹³æ <var>Y</var> (1 ≤ <var>Y</var> ≤ 28)幎ãè¡šãã
</p>
<h2>Output</h2>
<p>
西æŠãªãã°åæŠã«ãåæŠãªãã°è¥¿æŠã«å€æããçµæããïŒè¡ã«åºåããããã ãã西æŠãåæŠã«å€æããçµæã¯ãææ²»ãªãæåãMãã倧æ£ãªãæåãTããæåãªãæåãSããå¹³æãªãæåãHããå
é ã«ä»ããŠåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
0 2015
</pre>
<h2>Sample Output 1</h2>
<pre>
H27
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
0 1912
</pre>
<h2>Sample Output 2</h2>
<pre>
T1
</pre>
<br/>
<h2>Sample Input 3</h2>
<pre>
2 1
</pre>
<h2>Sample Output 3</h2>
<pre>
1912
</pre>
<br/>
<h2>Sample Input 4</h2>
<pre>
4 28
</pre>
<h2>Sample Output 4</h2>
<pre>
2016
</pre> | [
[
"0 2015\n",
"0 2015\n"
]
] |
p00333 | New Town |
<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>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>W</var> <var>H</var> <var>C</var>
</pre>
<p>
å
¥åã¯ïŒè¡ã§ãããæ°ãã«éæããåå°ã®æ±è¥¿æ¹åã®é·ã <var>W</var> (1 ≤ <var>W</var> ≤ 1000)ãšååæ¹åã®é·ã <var>H</var> (1 ≤ <var>H</var> ≤ 1000)ãåºç»åœããã®æŽåè²»çš <var>C</var> (1 ≤ <var>C</var> ≤ 1000)ãæŽæ°ã§äžããããã
</p>
<h2>Output</h2>
<p>
åå°ãæŽåããããã«å¿
èŠãªæå°ã®è²»çšãïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
10 20 5
</pre>
<h2>Sample Output 1</h2>
<pre>
10
</pre>
<p>
ïŒåã®æ£æ¹åœ¢ã§åå°ãäœããšãããªãåºåãããšãã§ããïŒåºç»åœããã®æŽåè²»çšãïŒãªã®ã§ãïŒïŒãš
åºåããã
</p>
<br/>
<h2>Sample Input 2</h2>
<pre>
27 6 1
</pre>
<h2>Sample Output 2</h2>
<pre>
18
</pre>
<p>
ïŒïŒåã®æ£æ¹åœ¢ã§åå°ãäœããšãããªãåºåãããšãã§ããïŒåºç»åœããã®æŽåè²»çšãïŒãªã®ã§ãïŒïŒãšåºåããã
</p>
| [
[
"10 20 5\n",
"10 20 5\n"
]
] |
p00334 | Geometric Data |
<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>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2016_shape_data" width="280">
</center>
<br/>
<p>
é¢æ
å ±ãäžãããããšããéè€ããé¢ãç¡ããããã«æ¶ããªããã°ãªããªãé¢æ
å ±ã®åæ°ãæ±ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>p<sub>11</sub></var> <var>p<sub>12</sub></var> <var>p<sub>13</sub></var>
<var>p<sub>21</sub></var> <var>p<sub>22</sub></var> <var>p<sub>23</sub></var>
:
<var>p<sub>N1</sub></var> <var>p<sub>N2</sub></var> <var>p<sub>N3</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ãããªãŽã³ã¢ãã«ã®é¢æ
å ±ã®æ° <var>N</var> (1 ≤ <var>N</var> ≤ 1000) ãäžãããããç¶ã <var>N</var> è¡ã«ã<var>i</var> çªç®ã®é¢ãäœãããã«äœ¿ãé ç¹ã®çªå· <var>p<sub>ij</sub></var> (1 ≤ <var>p<sub>ij</sub></var> ≤ 1000) ãäžããããããã ããäžã€ã®é¢ã«ã€ããŠãåãé ç¹ãïŒåºŠä»¥äžäœ¿ãããšã¯ãªãïŒ<var>p<sub>i1</sub></var> ≠ <var>p<sub>i2</sub></var> ã〠<var>p<sub>i2</sub></var> ≠ <var>p<sub>i3</sub></var> ã〠<var>p<sub>i1</sub></var> ≠ <var>p<sub>i3</sub></var> ã§ããïŒã
</p>
<h2>Output</h2>
<p>
éè€ããé¢ãç¡ããããã«æ¶ããªããã°ãªããªãé¢æ
å ±ã®åæ°ãïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
4
1 3 2
1 2 4
1 4 3
2 3 4
</pre>
<h2>Sample Output 1</h2>
<pre>
0
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
6
1 3 2
1 2 4
1 4 3
2 3 4
3 2 1
2 3 1
</pre>
<h2>Sample Output 2</h2>
<pre>
2
</pre>
<p>
å
¥åºåäŸïŒã§ã¯ãïŒã€ç®ãšïŒã€ç®ãšïŒã€ç®ã®é¢ã¯é ç¹1, 3, 2ã䜿ã£ãŠäžè§åœ¢ãäœã£ãŠããŠãç¹ã®é çªãç°ãªãã ããªã®ã§éè€ããŠãããã€ãŸããéè€ããé¢ã®ãã¡ïŒã€ã®é¢ãæ¶ãã°éè€ããé¢ã¯ç¡ããªãã
</p> | [
[
"4\n1 3 2\n1 2 4\n1 4 3\n2 3 4\n",
"4\n1 3 2\n1 2 4\n1 4 3\n2 3 4\n"
]
] |
p00335 | Pancake |
<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>N</var>
<var>p<sub>1</sub></var> <var>p<sub>2</sub></var> ... <var>p<sub>N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ãã³ã±ãŒãã®ææ° <var>N</var> (3 ≤ <var>N</var> ≤ 5000)ãäžãããããïŒè¡ç®ã«åãã³ã±ãŒããå®æãããŸã§ã«å¿
èŠãªè£è¿ãåæ° <var>p<sub>i</sub></var> (0 ≤ <var>p<sub>i</sub></var> ≤ 3)ãäžããããã
</p>
<h2>Output</h2>
<p>
ãã¹ãŠå®æãããŸã§ã«åãã³ã±ãŒããè£è¿ãåæ°ã®ç·åã®æå°å€ãïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
3
1 2 1
</pre>
<h2>Sample Output 1</h2>
<pre>
4
</pre>
<p>
ãžããïŒåæäœããŠå·Šç«¯ãšçãäžã®ãã³ã±ãŒããè£è¿ããšãïŒåã®ãã³ã±ãŒããïŒåãã€è£è¿ãã®ã§ããã®æäœã§è£è¿ãåæ°ã¯ïŒåãããã«ããžããïŒåæäœããŠçãäžãšå³ç«¯ã®ãã³ã±ãŒããè£è¿ããšãïŒåã®ãã³ã±ãŒããïŒåãã€è£è¿ãã®ã§ããã®æäœã§è£è¿ãåæ°ã¯ïŒåã以äžã®ç·åïŒåãçãã«ãªãã
</p>
<br>
<h2>Sample Input 2</h2>
<pre>
3
0 3 0
</pre>
<h2>Sample Output 2</h2>
<pre>
6
</pre>
<p>
ãžããïŒåæäœããŠå·Šç«¯ãšçãäžã®ãã³ã±ãŒããè£è¿ããšããã®æäœã§è£è¿ãåæ°ã¯ïŒåããããïŒåç¹°ãè¿ãããšãã®ãç·åã®ïŒåãçãã«ãªãïŒçãäžã®ãã³ã±ãŒãã¯ãäž¡é£ã®ã©ã¡ããã®ãã³ã±ãŒããšäžç·ã«è£è¿ãããšããã§ããªãããšã«æ³šæïŒã
</p> | [
[
"3\n1 2 1\n",
"3\n1 2 1\n"
]
] |
p00336 | Repeated Spell |
<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>
ã€ã¯ã·ãã§ã¯åªæãæç« ã®äžã«ãäœåçŸããããéèŠãªæå³ãæã€ããã ããåªæã«å«ãŸãããã¹ãŠã®æåãé çªã«ãæç« ã®äžã«ãšã³ãšã³ã§çŸãããã®ãïŒåçŸããŠãããšèãããäŸãã°ãæç« ã"abab" ã§ãåªæã "ab" ã§ããã°ãé£ç¶ã§ãªããã®ãå«ã㊠"ab" 㯠"abab" ã®äžã«ïŒåçŸãããŠããïŒ <u>ab</u>ab, ab<u>ab</u>, <u>a</u>ba<u>b</u> ã®ïŒéãïŒã
</p>
<p>
æç« ãšåªæãäžãããããšããåªæãæç« ã®äžã«äœåçŸããããåºåããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>t</var>
<var>b</var>
</pre>
<p>
ïŒè¡ç®ã«ãç³çã«æžãããæç« ãè¡šãæååtãäžãããããïŒè¡ç®ã«ãç³çã«æžãããåªæãè¡šãæååbãäžãããããã©ã¡ãã®æååãè±å°æåã ãããæããé·ãã1以äž1000以äžã®æååã§ããã
</p>
<h2>Output</h2>
<p>
åªæãæç« ã®äžã«äœåçŸããããïŒè¡ã«åºåããããã ããåºåãã¹ãå€ã¯éåžžã«å€§ãããªãããã®ã§ã代ããã« 1,000,000,007 ã§å²ã£ãäœããåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
abab
ab
</pre>
<h2>Sample Output 1</h2>
<pre>
3
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
aaaabaaaabaaaabaaaab
aaaaa
</pre>
<h2>Sample Output 2</h2>
<pre>
4368
</pre>
<br>
<h2>Sample Input 3</h2>
<pre>
data
structure
</pre>
<h2>Sample Output 3</h2>
<pre>
0
</pre> | [
[
"abab\nab\n",
"abab\nab\n"
]
] |
p00337 | Road Planning |
<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> | [
[
"5 5\n0 0\n1 1\n3 0\n3 2\n0 2\n1 2\n2 3\n2 4\n3 4\n1 5\n",
"5 5\n0 0\n1 1\n3 0\n3 2\n0 2\n1 2\n2 3\n2 4\n3 4\n1 5\n"
]
] |
p00338 | Programming Contest II |
<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>ããã°ã©ãã³ã°ã³ã³ãã¹ã II</H1>
<p>
çœè倧åŠã§ã¯æ¯å¹Žããã°ã©ãã³ã°ã³ã³ãã¹ããéå¬ããŠããŸããã³ã³ãã¹ãã¯å
šãŠã®ããŒã ã®åŸç¹ã 0ã®ç¶æ
ããéå§ãã解çç¶æ³ã«å¿ããŠåŸç¹ãå ç®ãããŠãããŸãããã®ã³ã³ãã¹ãã§ã¯ãåŸç¹ã®é«ãé ã«é äœä»ããè¡ãããŸããããŒã ã®ç·æ°ã <var>N</var> ãšãããšããããŒã ã«ã¯ 1 ãã <var>N</var> ã®çªå·ãããããå²ãåœãŠãããŠããŸããåŸç¹ãåãå Žåã¯çªå·ãããå°ããæ¹ãäžäœã«ãªããŸãã
</p>
<p>
çœè倧åŠã§ã¯ãã³ã³ãã¹ããçãäžããããã«èŠ³æŠçšã®ã©ã³ãã³ã°ã·ã¹ãã ãéçºããŠããŸããéçºããŒã ã®äžå¡ã§ããããªãã¯ããã®ã·ã¹ãã ã®äžéšã§ããããã°ã©ã ã®äœæãä»»ãããŠããŸãã
</p>
<p>
äžããããåœä»€ã«åŸã£ãŠãåŸç¹ã®æŽæ°ãšãæå®ãããé äœã®ããŒã ã®çªå·ãšåŸç¹ãå ±åããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var> <var>C</var>
<var>command<sub>1</sub></var>
<var>command<sub>2</sub></var>
:
<var>command<sub>C</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ããŒã æ° <var>N</var> (2 ≤ <var>N</var> ≤ 100000) ãšåœä»€ã®æ° <var>C</var> (1 ≤ <var>C</var> ≤ 100000)ãäžãããããç¶ã <var>C</var> è¡ã«ãïŒè¡ãã€åœä»€ãäžãããããååœä»€ã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
0 <var>t</var> <var>p</var>
</pre>
<p>
ãŸãã¯
</p>
<pre>
1 <var>m</var>
</pre>
<p>
æåã®æ°åã0ã®ãšãæŽæ°åœä»€ã1ã®ãšãå ±ååœä»€ãè¡šããæŽæ°åœä»€ã§ã¯æå®ãããçªå· <var>t</var> (1 ≤ <var>t</var> ≤ <var>N</var>) ã®ããŒã ã«ãæŽæ°ã§äžããããåŸç¹ <var>p</var> (1 ≤ <var>p</var> ≤ 10<sup>9</sup>) ãå ç®ãããå ±ååœä»€ã§ã¯æå®ãããé äœ <var>m</var> (1 ≤ <var>m</var> ≤ <var>N</var>) ã®ããŒã ã®çªå·ãšåŸç¹ãå ±åããããã ããå ±ååœä»€ã¯å°ãªããšãïŒåçŸãããã®ãšããã
</p>
<h2>Output</h2>
<p>
åå ±ååœä»€ã«å¯ŸããŠãæå®ãããé äœã®ããŒã ã®çªå·ãšåŸç¹ã空çœåºåãã§ïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
3 11
0 2 5
0 1 5
0 3 4
1 1
1 2
1 3
0 3 2
1 1
0 2 1
1 2
1 3
</pre>
<h2>Sample Output 1</h2>
<pre>
1 5
2 5
3 4
3 6
3 6
1 5
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
5 2
1 1
1 2
</pre>
<h2>Sample Output 2</h2>
<pre>
1 0
2 0
</pre> | [
[
"3 11\n0 2 5\n0 1 5\n0 3 4\n1 1\n1 2\n1 3\n0 3 2\n1 1\n0 2 1\n1 2\n1 3\n",
"3 11\n0 2 5\n0 1 5\n0 3 4\n1 1\n1 2\n1 3\n0 3 2\n1 1\n0 2 1\n1 2\n1 3\n"
]
] |
p00339 | Game Strategy |
<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>
ãã®ã²ãŒã 㯠<var>M</var> åã®ã€ãã³ãããæããæå» <var>t<sub>i</sub></var> ã«ã€ãã³ã <var>i</var> ãæ»ç¥ããªããã°ãããŸããããã ãããã®ãšãã«ããªãã®åŒ·ã㯠<var>s<sub>i</sub></var> 以äžã§ããå¿
èŠãããã<var>s<sub>i</sub></var> 以äžã«ã§ããªãå Žåã¯ã²ãŒã ãªãŒããŒã«ãªããŸããã²ãŒã éå§æïŒæå»ïŒïŒã®ããªãã®åŒ·ãã¯ïŒã§ãããã¢ã€ãã ãè²·ãããšã§åŒ·ããå¢å ãããããšãã§ããŸããã²ãŒã éå§æã®ããªãã®ææéã¯ïŒã§ãããïŒåäœæéãããïŒå¢å ããŸãã
</p>
<p>
ããŒãã«ã¯ããããïŒãã <var>N</var> ã®çªå·ãä»ãããã <var>N</var> åã®ã¢ã€ãã ãé çªã«äžŠã¹ãããŠãããã¢ã€ãã <var>i</var> ã®å€æ®µã¯ <var>v<sub>i</sub></var> ã§ãããã賌å
¥ãããšããªãã®åŒ·ãã <var>h<sub>i</sub></var> å¢å ããŸããã¢ã€ãã ã¯ææéãååã§ããã°å¥œããªæå»ã«å¥œããªæ°ã ã賌å
¥ããããšãã§ããŸãããæ®ã£ãŠããã¢ã€ãã ã®äžã§çªå·ãå°ãããã®ããé ã«éžã°ãªããã°ãªããŸãããåã¢ã€ãã ã¯ïŒåºŠè³Œå
¥ãããšæ¶æ»
ããŸãã
</p>
<p>
ãŸããåãæå»ã«è€æ°ã®ã¢ã€ãã ãé£ç¶ã§è²·ãããšãã§ãããã®ãšãé£ãåãã¢ã€ãã ã® <var>h<sub>i</sub></var> ã®å·®åã®åãããŒãã¹ãšããŠåŸãããšãã§ããŸããäŸãã°ãããæå»ã«ã¢ã€ãã ïŒ,ïŒ,ïŒãåæã«è²·ã£ãå Žåã<var>h<sub>1</sub></var> + <var>h<sub>2</sub></var> + <var>h<sub>3</sub></var> ã«å ããŠ|<var>h<sub>1</sub></var> - <var>h<sub>2</sub></var>| + |<var>h<sub>2</sub></var> - <var>h<sub>3</sub></var>| ã ãããªãã®åŒ·ããå¢å ããŸãã
</p>
<p>
ããªãã¯ãå
šãŠã®ã€ãã³ããæ»ç¥ããåŸã®ææéãæ倧åããããšèããŠããŸãã
</p>
<p>
ã¢ã€ãã ã®æ
å ±ãšã€ãã³ãã®æ
å ±ãå
¥åãšãããã¹ãŠã®ã€ãã³ããæ»ç¥ããåŸã®ææéã®æ倧å€ãåºåããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var> <var>M</var>
<var>v<sub>1</sub></var> <var>h<sub>1</sub></var>
<var>v<sub>2</sub></var> <var>h<sub>2</sub></var>
:
<var>v<sub>N</sub></var> <var>h<sub>N</sub></var>
<var>t<sub>1</sub></var> <var>s<sub>1</sub></var>
<var>t<sub>2</sub></var> <var>s<sub>2</sub></var>
:
<var>t<sub>M</sub></var> <var>s<sub>M</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ã¢ã€ãã ã®æ° <var>N</var> (1 ≤ <var>N</var> ≤ 3000) ãšã€ãã³ãã®æ° <var>M</var> (1 ≤ <var>M</var> ≤ 1000) ãäžãããããç¶ã <var>N</var> è¡ã«ã¢ã€ãã <var>i</var> ã®å€æ®µ <va>v<sub>i</sub></var> ãšåŒ·ãã®å¢å é <var>h<sub>i</sub></var> (1 ≤ <var>v<sub>i</sub></var>, <var>h<sub>i</sub></var> ≤ 100000) ãäžãããããç¶ã <var>M</var> è¡ã«ã€ãã³ã <var>i</var> ã®æå» <var>t<sub>i</sub></var> ãšæ¡ä»¶ <var>s<sub>i</sub></var> (1 ≤ <var>t<sub>i</sub></var>, <var>s<sub>i</sub></var> ≤ 100000) ãäžããããããã ãã<var>i</var> < <var>j</var> ã®ãšãã<var>t<sub>i</sub></var> < <var>t<sub>j</sub></var> ãšãããå
¥åã¯ãã¹ãŠæŽæ°ã§äžããããã
</p>
<h2>Output</h2>
<p>
ææéã®æ倧å€ãïŒè¡ã«åºåããããã ããæ»ç¥ããããšãã§ããªãå Žåã«ã¯ã-1ããåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
5 4
3 3
2 1
1 5
4 2
2 6
4 1
8 2
10 4
12 17
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
5 4
3 3
2 1
1 5
4 2
2 6
4 1
8 2
10 4
12 30
</pre>
<h2>Sample Output 2</h2>
<pre>
-1
</pre> | [
[
"5 4\n3 3\n2 1\n1 5\n4 2\n2 6\n4 1\n8 2\n10 4\n12 17\n",
"5 4\n3 3\n2 1\n1 5\n4 2\n2 6\n4 1\n8 2\n10 4\n12 17\n"
]
] |
p00340 | Rectangle |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>é·æ¹åœ¢ </H1>
<p>
ã¢ã€ã
æŸéåäŒã®æè²çªçµ(æè²)ã§ã¯ãåã©ãåãã®å·¥äœçªçµããããã§ã€ããããæŸéããŠããŸããä»æ¥ã¯æ£ã§é·æ¹åœ¢ãäœãåã§ãããçšæããïŒæ¬ã®æ£ã䜿ã£ãŠé·æ¹åœ¢ãã§ãããã確ãããããšæããŸãããã ããæ£ã¯åã£ããæã£ããããŠã¯ãããŸããã
</p>
<br/>
<p>
ïŒæ¬ã®æ£ã®é·ããäžããããã®ã§ãããããã¹ãŠã蟺ãšããé·æ¹åœ¢ãäœãããã©ããå€å®ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>e<sub>1</suv></var> <var>e<sub>2</suv></var> <var>e<sub>3</suv></var> <var>e<sub>4</suv></var>
</pre>
<p>
å
¥åã¯ïŒè¡ãããªããåæ£ã®é·ããè¡šãæŽæ° <var>e<sub>i</sub></var> (1 ≤ <var>e<sub>i</sub></var> ≤ 100) ãäžããããã
</p>
<h2>Output</h2>
<p>
é·æ¹åœ¢ãäœæã§ããå Žåã«ã¯ãyesãããäœæã§ããªãå Žåã«ã¯ãnoããåºåããããã ããæ£æ¹åœ¢ã¯é·æ¹åœ¢ã®äžçš®ãªã®ã§ãæ£æ¹åœ¢ã®å Žåã§ããyesããšåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
1 1 3 4
</pre>
<h2>Sample Output 1</h2>
<pre>
no
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
1 1 2 2
</pre>
<h2>Sample Output 2</h2>
<pre>
yes
</pre>
<br/>
<h2>Sample Input 3</h2>
<pre>
2 1 1 2
</pre>
<h2>Sample Output 3</h2>
<pre>
yes
</pre>
<br/>
<h2>Sample Input 4</h2>
<pre>
4 4 4 10
</pre>
<h2>Sample Output 4</h2>
<pre>
no
</pre>
<br/> | [
[
"1 1 3 4\n",
"1 1 3 4\n"
]
] |
p00341 | Cuboid Made with Bars |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>æ£ã§äœãçŽæ¹äœ</H1>
<p>
ã¢ã€ã
æŸéåäŒã®æè²çªçµ(æè²)ã§ã¯ãåã©ãåãã®å·¥äœçªçµããããã§ã€ããããæŸéããŠããŸããä»åã¯æ£ã§ç®±ãäœãåã§ãããçšæããïŒïŒæ¬ã®æ£ã䜿ã£ãŠçŽæ¹äœãã§ãããã確ãããããšæããŸãããã ããæ£ã¯åã£ããæã£ããããŠã¯ãããŸããã
</p>
<br/>
<p>
ïŒïŒæ¬ã®æ£ã®é·ããäžããããã®ã§ãããããã¹ãŠã蟺ãšããçŽæ¹äœãäœãããã©ããå€å®ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>e<sub>1</sub></var> <var>e<sub>2</sub></var> ... <var>e<sub>12</sub></var>
</pre>
<p>
å
¥åã¯ïŒè¡ãããªããåæ£ã®é·ããè¡šãæŽæ° <var>e<sub>i</sub></var> (1 ≤ <var>e<sub>i</sub></var> ≤ 100) ãäžããããã
</p>
<h2>Output</h2>
<p>
çŽæ¹äœãäœæã§ããå Žåã«ã¯ãyesãããäœæã§ããªãå Žåã«ã¯ãnoããåºåããããã ããç«æ¹äœã¯çŽæ¹äœã®äžçš®ãªã®ã§ãç«æ¹äœã®å Žåã§ããyesããšåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
1 1 3 4 8 9 7 3 4 5 5 5
</pre>
<h2>Sample Output 1</h2>
<pre>
no
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
1 1 2 2 3 1 2 3 3 3 1 2
</pre>
<h2>Sample Output 2</h2>
<pre>
yes
</pre> | [
[
"1 1 3 4 8 9 7 3 4 5 5 5\n",
"1 1 3 4 8 9 7 3 4 5 5 5\n"
]
] |
p00342 | Maximization of Rational Expression |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>æçåŒæ倧å</H1>
<p>
<var>N</var> åã®ç°ãªãèªç¶æ°ãäžããããããã®äžããç°ãªãïŒã€ãéžãã§ããããã $A$, $B$, $C$, $D$ ãšãããšãã次ã®æ°åŒ </p>
<center>
$\frac{A + B}{C - D}$ <br/>
</center>
<br/>
<p>
ã®æ倧å€ãæ±ãããã
</p>
<br/>
<p>
<var>N</var> åã®ç°ãªãèªç¶æ°ãäžãããããšãããã®äžããç°ãªãïŒã€ãéžãã§ãäžã®æ°åŒã®æ倧å€ãæ±ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>a<sub>1</sub></var> <var>a<sub>2</sub></var> ... <var>a<sub>N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«èªç¶æ°ã®åæ° <var>N</var> (4 ≤ <var>N</var> ≤ 1000) ãäžãããããïŒè¡ç®ã«åèªç¶æ°ã®å€ <var>a<sub>i</sub></var> (1 ≤ <var>a<sub>i</sub></var> ≤ 10<sup>8</sup>) ãäžããããããã ããåãèªç¶æ°ãéè€ããŠçŸããããšã¯ãªãïŒ<var>i</var> ≠ <var>j</var> ã«ã€ã㊠<var>a<sub>i</sub></var> ≠ <var>a<sub>j</sub></var>)ã
</p>
<h2>Output</h2>
<p>
äžãããã <var>N</var> åã®èªç¶æ°ã«å¯ŸããŠãäžã®æ°åŒã®æ倧å€ãå®æ°ã§åºåããããã ãã誀差ããã©ã¹ãã€ãã¹ 10<sup>-5</sup> ãè¶
ããŠã¯ãªããªãã
</p>
<h2>Sample Input 1</h2>
<pre>
10
1 2 3 4 5 6 7 8 9 10
</pre>
<h2>Sample Output 1</h2>
<pre>
19.00000
</pre>
<p>
å
¥åäŸïŒã§ã¯ã$A=9$, $B=10$, $C=2$, $D=1$ ãªã©ã®çµã¿åããã§æ倧ã«ãªãã
</p>
<br/>
<h2>Sample Input 2</h2>
<pre>
5
22 100 42 3 86
</pre>
<h2>Sample Output 2</h2>
<pre>
9.78947
</pre>
<p>
å
¥åäŸïŒã§ã¯ã$A=100$, $B=86$, $C=22$, $D=3$ ãªã©ã®çµã¿åããã§æ倧ã«ãªãã
</p>
<br/>
<h2>Sample Input 3</h2>
<pre>
6
15 21 36 10 34 5
</pre>
<h2>Sample Output 3</h2>
<pre>
18.00000
</pre>
<p>
å
¥åäŸïŒã§ã¯ã$A=21$, $B=15$, $C=36$, $D=34$ ãªã©ã®çµã¿åããã§æ倧ã«ãªãã
</p>
<br/>
<h2>Sample Input 4</h2>
<pre>
4
100000 99999 8 1
</pre>
<h2>Sample Output 4</h2>
<pre>
28571.285714
</pre>
<br/> | [
[
"10\n1 2 3 4 5 6 7 8 9 10\n",
"10\n1 2 3 4 5 6 7 8 9 10\n"
]
] |
p00343 | Sevens |
<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>
<ol>
<li> ãå Žãã«ïŒã®ã«ãŒãã眮ããŸãã</li>
<li> ïŒè
ã«ã¯ãæ®ãã®ã«ãŒããã©ã³ãã ã«ïŒæãã€é
åžãããŸãã</li>
<li> å
æã®ææã¡ã®ã«ãŒãã®ãã¡ãå Žã«ããã«ãŒãã®çªå·ãšé£ç¶ããçªå·ã®ã«ãŒããããã°ããã®ãã¡ã®ïŒæãå Žã«çœ®ããŸãããã¬ã€ã€ãŒã¯ã«ãŒãã眮ããå Žåã«ã¯å¿
ã眮ããªããã°ãããŸãããç¡ããšãã«éããã«ãŒããåºããã«çžæã®çªã«ãªããŸãã</li>
<li> åŸæãåãèŠé ã§ãææã¡ã®ã«ãŒããå Žã«çœ®ããŸãã</li>
<li> æé ïŒãšïŒãç¹°ãè¿ããŠãäžæ¹ã®ææã¡ã®ã«ãŒãããªããªããŸã§ç¶ããŸããå
ã«ææã¡ã®ã«ãŒãããã¹ãŠå Žã«çœ®ããæ¹ãåè
ãšãªããŸãã</li>
</ol>
<br/>
<p>
å
æã®ã«ãŒãã®çªå·ãäžãããããšããåŸæãã©ã®ããã«ã«ãŒããåºããŠããŠããå
æãåã€æé ãå°ãªããšãäžã€ããããå€å®ããŠåºåããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>game<sub>1</sub></var>
<var>game<sub>2</sub></var>
:
<var>game<sub>N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ã¯ãã²ãŒã ãè¡ãåæ° <var>N</var> (1 ≤ <var>N</var> ≤ 100) ãäžãããããç¶ã <var>N</var> è¡ã«ã<var>i</var> åç®ã®ã²ãŒã ã®æ
å ± <var>game<sub>i</sub></var> ãäžãããããå <var>game<sub>i</sub></var> ã¯ã以äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>f<sub>1</sub></var> <var>f<sub>2</sub></var> <var>f<sub>3</sub></var> <var>f<sub>4</sub></var> <var>f<sub>5</sub></var> <var>f<sub>6</sub></var>
</pre>
<p>
<var>f<sub>j</sub></var> (1 ≤ <var>f<sub>j</sub></var> ≤ 13, <var>f<sub>j</sub></var> ≠ 7) ã¯å
æã«é
ãããã«ãŒãã®çªå·ã§ããããã ããåãè¡ã«çªå·ãéè€ããŠçŸããããšã¯ãªãïŒ<var>j</var> ≠ <var>k</var> ã«ã€ã㊠<var>f<sub>j</sub></var> ≠ <var>f<sub>k</sub></var>)ã
</p>
<h2>Output</h2>
<p>
åã²ãŒã ã«ã€ããŠãåŸæãã©ã®ããã«ã«ãŒããåºããŠããŠããå
æãåã€æé ãå°ãªããšãäžã€ããå Žåãyesããããã§ãªãå ŽåãnoããšïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
5
1 2 3 4 5 6
1 3 5 6 8 4
1 2 3 4 5 8
1 2 4 5 10 11
1 2 3 6 9 11
</pre>
<h2>Sample Output 1</h2>
<pre>
yes
yes
no
yes
no
</pre> | [
[
"5\n1 2 3 4 5 6\n1 3 5 6 8 4\n1 2 3 4 5 8\n1 2 4 5 10 11\n1 2 3 6 9 11\n",
"5\n1 2 3 4 5 6\n1 3 5 6 8 4\n1 2 3 4 5 8\n1 2 4 5 10 11\n1 2 3 6 9 11\n"
]
] |
p00344 | Cyclic Sugoroku |
<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>
<br/>
<p>
ããããã®æ
å ±ãå
¥åãšãããããããã«ãã©ãçãããã¹ã®åæ°ãå ±åããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>a<sub>1</sub></var> <var>a<sub>2</sub></var> ... <var>a<sub>N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ããããã«å«ãŸãããã¹ãŠã®ãã¹ã®åæ° <var>N</var> (1 ≤ <var>N</var> ≤ 100000) ãäžãããããïŒè¡ç®ã«ãããããã®ãã¹ã«æžãããæ° <var>a<sub>i</sub></var> (1 ≤ <var>a<sub>i</sub></var> ≤ 10<sup>9</sup>) ããæèšåãã«é çªã«äžããããã
</p>
<h2>Output</h2>
<p>
ãããããã«ãã©ãçãããã¹ã®åæ°ãïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
3
1 1 1
</pre>
<h2>Sample Output 1</h2>
<pre>
3
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
3
1 1 2
</pre>
<h2>Sample Output 2</h2>
<pre>
2
</pre>
<br/>
<h2>Sample Input 3</h2>
<pre>
8
2 3 7 3 3 3 4 4
</pre>
<h2>Sample Output 3</h2>
<pre>
6
</pre>
<br/> | [
[
"3\n1 1 1\n",
"3\n1 1 1\n"
]
] |
p00345 | Irreducible Fractionalization |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>å®æ°æ¢çŽåæ°å</H1>
<p>
å®æ°ã®ãã¡ãå°æ°éšã埪ç°ãããã®ãšæéæ¡ã®ãã®ã¯åæ°ãšããŠè¡šãããšãã§ããŸãã
</p>
<br/>
<p>
åæ°ã§è¡šãããšãã§ããå®æ°ãäžãããããšãããã®å®æ°ãšçããæ¢çŽåæ°ïŒãã以äžçŽåã§ããªãåæ°ïŒãåºåããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>str</var>
</pre>
<p>
ïŒè¡ã«ãå€æãããå®æ°ãè¡šãæåå <var>str</var> ãäžãããããå®æ°ã®å€ã¯ 0 ãã倧ãããæååã¯æ°åãã.ããã(ããã)ããå«ããé·ãã 3 ä»¥äž 8 以äžã®æååã§ãããã.ãã¯å°æ°ç¹ãã(ãã¯æ°åã®åŸªç°ã®å§ãŸããã)ãã¯æ°åã®åŸªç°ã®çµããã瀺ããæŽæ°éšã«ãå°æ°éšã«ããå¿
ãïŒæ¡ä»¥äžã®æ°åãäžãããããšããããã ãã埪ç°å°æ°ãäžããããå Žåãæååã¯ä»¥äžã®æ¡ä»¶ãæºããã
</p>
<ul>
<li> 埪ç°ã®å§ãŸããšçµããã®ãã¢ã¯ãå°æ°ç¹ã®å³åŽã«äžåºŠã ãçŸããã </li>
<li> 埪ç°ã®çµããã瀺ãã)ãã¯ãæååã®æ«å°Ÿã«çŸããã</li>
<li> 埪ç°ã®å§ãŸããšçµããã®éã«ã¯ãå¿
ãïŒæ¡ä»¥äžã®æ°åãäžããããã</li>
</ul>
<h2>Output</h2>
<p>
å®æ°ãæ¢çŽåæ°ã§è¡šãã圢åŒïŒååã®æŽæ°ã«ç¶ããŠã/ãåºåãã§åæ¯ã®æŽæ°ã䞊ã¹ããã®ïŒã§åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
0.(3)
</pre>
<h2>Sample Output 1</h2>
<pre>
1/3
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
1.0
</pre>
<h2>Sample Output 2</h2>
<pre>
1/1
</pre>
<br/>
<h2>Sample Input 3</h2>
<pre>
5.2(143)
</pre>
<h2>Sample Output 3</h2>
<pre>
52091/9990
</pre>
<br/>
<h2>Sample Input 4</h2>
<pre>
0.0739
</pre>
<h2>Sample Output 4</h2>
<pre>
739/10000
</pre>
<br/>
| [
[
"0.(3)\n",
"0.(3)\n"
]
] |
p00346 | Quiet Town |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>éããªçº</H1>
<p>
ã¢ã€ã
åœã§ã¯ãæ¯å¹Žãé§
äŒå€§äŒãéå¬ãããŠããŸããã¢ã€ã
åœã«ã¯ <var>N</var> åã®çºãç¹åšããŠããããããã 1 ãã <var>N</var> ãŸã§ã®çªå·ãä»ããŠããŸããããã€ãã®çºã®éã¯ãäºãã«çŽæ¥è¡ãæ¥ã§ããéã§ã€ãªãã£ãŠããŸãããŸããã©ã®çºã®éãããã€ãã®éã蟿ã£ãŠè¡ãæ¥ãã§ããŸãã倧äŒã®ã³ãŒã¹ã¯ã次ã®ããã«ããŠæ±ºããŸãã
</p>
<ul>
<li> ïŒã€ã®çºã®ãã¹ãŠã®çµã¿åããã«ã€ããŠãæççµè·¯ã®è·é¢ãæ±ããã</li>
<li> ãããã®äžã§ãæççµè·¯ã®è·é¢ãæ倧ã«ãªããããªïŒã€ã®çºããã¹ã¿ãŒãã®çºãšãŽãŒã«ã®çºãšãããçºã®çµã¿åãããè€æ°ããå Žåããã®ãã¡ã®ã©ããäžã€ãéžã¶ã</li>
<li> éžã°ããã¹ã¿ãŒãã®çºãšãŽãŒã«ã®çºã®éã®æççµè·¯ã倧äŒã®ã³ãŒã¹ãšãããæççµè·¯ãè€æ°ããå Žåããã®ãã¡ã®ã©ããäžã€ãéžã¶ã</li>
</ul>
<p>
ã€ããåœããæ¥ããåããã®ãã¯ã€ãã¯ãã¢ã€ã
åœã®ã§ããã ãéããªçºã«æ°ããã寺ãéããããšèããŠããŸãããã®ãããé§
äŒå€§äŒã®ã³ãŒã¹ã«äœ¿ãããå¯èœæ§ããªãçºãç¥ãããã£ãŠããŸãã
</p>
<br/>
<p>
ã¢ã€ã
åœã®çºãçµã¶éã®æ
å ±ãäžãããããšããé§
äŒå€§äŒã®ã³ãŒã¹ã«äœ¿ãããå¯èœæ§ããªãçºãæ±ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var> <var>R</var>
<var>s<sub>1</sub></var> <var>t<sub>1</sub></var> <var>d<sub>1</sub></var>
<var>s<sub>2</sub></var> <var>t<sub>2</sub></var> <var>d<sub>2</sub></var>
:
<var>s<sub>R</sub></var> <var>t<sub>R</sub></var> <var>d<sub>R</sub></var>
</pre>
<p>
ïŒè¡ç®ã«çºã®æ° <var>N</var> (2 ≤ <var>N</var> ≤ 1500) ãšãçºã®éãçŽæ¥ã€ãªãéã®æ° <var>R</var> (1 ≤ <var>R</var> ≤ 3000) ãäžãããããç¶ã <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>N</var>) 㯠<var>i</var> çªç®ã®éãã€ãªãïŒã€ã®çºã®çªå·ãè¡šãã<var>d<sub>i</sub></var> (1 ≤ <var>d<sub>i</sub></var> ≤ 1000) ã¯ãã®éã®é·ããè¡šãããã ããã©ã®ïŒã€ã®çºã«ã€ããŠããããããçŽæ¥ã€ãªãéã¯é«ã
ïŒæ¬ãšããã
</p>
<h2>Output</h2>
<p>
äžããããéã®æ
å ±ã«å¯ŸããŠãé§
äŒå€§äŒã®ã³ãŒã¹ã«ãªãããšããªãçºããã¹ãŠåºåãããïŒè¡ç®ã«é§
äŒå€§äŒã®ã³ãŒã¹ã«ãªãããšããªãçºã®æ° <var>M</var> ãåºåãããç¶ã <var>M</var> è¡ã«ããã®ãããªçºã®çªå·ãæé ã§åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
4 5
1 2 2
1 3 2
2 3 1
2 4 2
3 4 1
</pre>
<h2>Sample Output 1</h2>
<pre>
1
2
</pre>
<h2>Sample Input 2</h2>
<pre>
7 11
1 2 2
1 3 1
2 4 2
2 5 2
2 6 1
3 4 1
3 5 1
3 6 1
4 7 2
5 7 2
6 7 1
</pre>
<h2>Sample Output 2</h2>
<pre>
3
2
4
5
</pre> | [
[
"4 5\n1 2 2\n1 3 2\n2 3 1\n2 4 2\n3 4 1\n",
"4 5\n1 2 2\n1 3 2\n2 3 1\n2 4 2\n3 4 1\n"
]
] |
p00347 | Forecast of Forces |
<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>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2016_rectangleGame" width="680"><br/>
</center>
<br/>
<p>
ãã®ã²ãŒã ã§ã¯ïŒã€ã®é§ãåãããŠé å°ã®å¢çç·ã決ããŠãããŸããã²ãŒã éå§æãé§ã¯å³¶ã®å西端ã«ãããŸãïŒå³①ïŒããã®é§ã島ã®åæ±ç«¯ãŸã§åãããŠãã£ããšãã®é§ã®è»è·¡ãé å°ã®å¢çç·ãšãªããŸããäºäººã®ãã¬ãŒã€ãŒã¯äº€äºã«é§ãåãããŸããé§ã¯åé£ã®æ Œåç¹ãæ±é£ã®æ Œåç¹ã«ã®ã¿åããããšãã§ããŸãïŒå³②ïŒãé§ã島ã®ç«¯ã«å°éããå Žåã¯ãåãæ±ã®ãã¡åãããæ¹åã«åãããŸããé§ãåæ±ç«¯ã«å°éãããã²ãŒã çµäºã§ãã
</p>
<p>
ã²ãŒã çµäºåŸã®å¢çç·ããåæ±åŽã®é åãå
æ»ãã¬ãŒã€ãŒã®é åãå西åŽã®é åãåŸæ»ãã¬ãŒã€ãŒã®é
åã§ãïŒå³③ïŒãåãã¬ãŒã€ãŒã®é åå
ã«å«ãŸãããåºç»ããçããæåŸã®åèšããã®ãã¬ãŒã€ãŒã®ã¹
ã³ã¢ãšãªããŸããäºäººãšãã²ãŒã ã«ã¯ããªãæ
£ããŠãããæçµçã«èªåã®ã¹ã³ã¢ããçžæã®ã¹ã³ã¢ãã²
ããå€ãäžçªå€§ãããªãããã«æ£ç¢ºã«é§ãåãããŸãã
</p>
<br/>
<p>
島ã®å€§ãããšããããã®åºç»ããçããæåŸãäžãããããšããã²ãŒã çµäºæã®çµæãèšç®ããããã°ã©ã ãäœæãããçµæã¯ã信倫ãããšé倫ããã®ã¹ã³ã¢ã®å·®ã®çµ¶å¯Ÿå€ãšããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>W</var> <var>H</var>
<var>s<sub>1,1</sub></var> <var>s<sub>1,2</sub></var> ... <var>s<sub>1,W</sub></var>
<var>s<sub>2,1</sub></var> <var>s<sub>2,2</sub></var> ... <var>s<sub>2,W</sub></var>
:
<var>s<sub>H,1</sub></var> <var>s<sub>H,2</sub></var> ... <var>s<sub>H,W</sub></var>
</pre>
<p>
ïŒè¡ç®ã«å³¶ã«å«ãŸããæ±è¥¿æ¹åãšååæ¹åã®åºç»ã®æ° <var>W</var>, <var>H</var> (1 ≤ <var>W</var>, <var>H</var> ≤ 1000) ãäžãããããç¶ã <var>H</var> è¡ã« <var>i</var> è¡ <var>j</var> åç®ã®åºç»ããçããæåŸ <var>s<sub>i,j</sub></var> (-1000 ≤ <var>s<sub>i,j</sub></var> ≤ 1000) ãäžããããããã ãã<var>i</var> ã®å€ãå¢å ããæ¹åãåã<var>j</var> ã®å€ãå¢å ããæ¹åãæ±ãšããã
</p>
<h2>Output</h2>
<p>
信倫ãããšé倫ããã®ã¹ã³ã¢ã®å·®ã®çµ¶å¯Ÿå€ãïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
2 1
-2 1
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
2 2
2 -3
3 -1
</pre>
<h2>Sample Output 2</h2>
<pre>
3
</pre>
<br/>
<h2>Sample Input 3</h2>
<pre>
5 4
5 3 2 -5 2
2 -4 2 8 -4
2 3 -7 6 7
3 -4 10 -3 -3
</pre>
<h2>Sample Output 3</h2>
<pre>
5
</pre>
| [
[
"2 1\n-2 1\n",
"2 1\n-2 1\n"
]
] |
p00348 | Sort |
<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>
<ol>
<li> ã¯ããã«ãåã®å
é ã®èŠçŽ ãéžã¶ã</li>
<li> éžãã èŠçŽ ã®çŽåã«èŠçŽ ããããšããéžãã èŠçŽ ãšãã®çŽåã®èŠçŽ ãæ¯ã¹ããçŽåã®èŠçŽ ã®ã»ãã倧ãããªãããããåã®æ«å°Ÿã®çŽåŸã«ç§»åããã(å³ïŒããã®æäœããéžãã èŠçŽ ãåã®å
é ã«ãªãããéžãã èŠçŽ ãããã®çŽåã®èŠçŽ ã®æ¹ãå°ãããªããŸã§ç¶ããã</li>
<li> éžãã èŠçŽ ãåã®æ«å°Ÿãªãçµäºãããã§ãªããã°ãéžãã èŠçŽ ã®çŽåŸã®èŠçŽ ãæ°ãã«éžã³ã2 ãžæ»ãã</li>
</ol>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2016_sort" width="360"><br/>
</center>
<br/>
<p>
ã¿ã±åããã¯ãã®ã¢ã«ãŽãªãºã ãã©ã®ãããã®èšç®æéãå¿
èŠãšãããèŠç©ããããã«ãèŠçŽ ãåã®æ«å°Ÿã®çŽåŸã«ç§»åãããæäœã®åæ°ãæ°ããããšã«ããŸããã
</p>
<br/>
<p>
åã®æ
å ±ãå
¥åãšããèŠçŽ ãåã®æ«å°Ÿã®çŽåŸã«ç§»åãããæäœã®åæ°ãå ±åããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>a<sub>1</sub></var> <var>a<sub>2</sub></var> ... <var>a<sub>N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«åã«å«ãŸããèŠçŽ ã®åæ° <var>N</var> (1 ≤ <var>N</var> ≤ 200000) ãäžãããããïŒè¡ç®ã«åã®èŠçŽ <var>a<sub>i</sub></var> (1 ≤ <var>a<sub>i</sub></var> ≤ 10<sup>9</sup>) ãå
é ããé çªã«äžãããããèŠçŽ <var>a<sub>i</sub></var> ã«éè€ã¯ãªãã
</p>
<h2>Output</h2>
<p>
èŠçŽ ãåã®æ«å°Ÿã®çŽåŸã«ç§»åãããæäœã®åæ°ãïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
6
1 3 6 5 8 2
</pre>
<h2>Sample Output 1</h2>
<pre>
10
</pre>
<p>
å
¥åäŸïŒã§ã¯ãèŠçŽ ã®ç§»åãè¡ããããã³ã«ã以äžã®ããã«åãå€åããŠããã
</p>
<pre>
0åç®ïŒ 1 3 6 5 8 2
1åç®ïŒ 1 3 5 8 2 6
2åç®ïŒ 1 3 5 2 6 8
3åç®ïŒ 1 3 2 6 8 5
4åç®ïŒ 1 2 6 8 5 3
5åç®ïŒ 1 2 6 5 3 8
6åç®ïŒ 1 2 5 3 8 6
7åç®ïŒ 1 2 3 8 6 5
8åç®ïŒ 1 2 3 6 5 8
9åç®ïŒ 1 2 3 5 8 6
10åç®ïŒ 1 2 3 5 6 8
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
4
4 3 2 1
</pre>
<h2>Sample Output 2</h2>
<pre>
6
</pre> | [
[
"6\n1 3 6 5 8 2\n",
"6\n1 3 6 5 8 2\n"
]
] |
p00349 | Ant |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>è»</H1>
<p>
倧ããªãã§ã¹ç€äžã«ãããããïŒãã <var>N</var> ãŸã§ã®çªå·ãå²ãæ¯ããã <var>N</var> å¹ã®è»ãããŸããå³ã®ããã«ããã§ã¹ç€ã¯ HÃW ã®ãã¹ãããªãé·æ¹åœ¢ã§ãå西è§ãçœãšããŠãçœãã¹ãšé»ãã¹ã亀äºã«äžŠãã§ããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2016_ant" width="360"><br/>
</center>
<br/>
<p>
æåãã©ã®è»ããã§ã¹ç€ã®ãã¹ã®äžã«ããŠãæ±ãŸãã¯åãåããŠããŸããïŒã€ã®ãã¹ã®äžã«ïŒå¹ä»¥äžã®è»ãããããšã¯ãããŸããã
</p>
<p>
ä»ãè»ãã¡ãäžæã«åãåºããŸãããã¹ãŠã®è»ã¯ 1 åäœæéã«åããŠããæ¹åã®ãã¹ã«ïŒã€ç§»åããŸãããã ãã移åå
ããã§ã¹ç€ã®å€ã®å ŽåãèœäžããŠãã§ã¹ç€ãã姿ãæ¶ããŸãã
</p>
<p>
ãã§ã¹ç€äžã§ïŒå¹ã®è»ãåããã¹ã«å
¥ããšããããã®è»ã¯ä»¥äžã®ãããªè¡åããšããŸãïŒ
</p>
<ul>
<li> ãã®ãã¹ã®è²ãçœãªãã°ãæ±æ¹åã«é²ãã§ããè»ã¯åæ¹åãžãåæ¹åã«é²ãã§ããè»ã¯æ±æ¹åãžåããå€ããã</li>
<li> ãã®ãã¹ã®è²ãé»ãªãã°ãããããã®è»ã¯é²ãæ¹åãç¶æããã</li>
</ul>
<br/>
<p>
ãã§ã¹ç€ã®å€§ãããšè»ã®æ
å ±ãäžãããããšããèœäžããé çªã«è»ã®çªå·ãå ±åããããã°ã©ã ãäœæããããã ããåãæå»ã«è€æ°ã®è»ãèœäžããå Žåã¯ãçªå·ãããå°ããæ¹ãå
ã«å ±åããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>W</var> <var>H</var> <var>N</var>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>d<sub>1</sub></var>
<var>x<sub>2</sub></var> <var>y<sub>2</sub></var> <var>d<sub>2</sub></var>
:
<var>x<sub>N</sub></var> <var>y<sub>N</sub></var> <var>d<sub>N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ãã§ã¹ç€ã®æ±è¥¿æ¹åã®ãã¹ã®æ° <var>W</var> ãšååæ¹åã®ãã¹ã®æ° <var>H</var> (2 ≤ <var>W</var>, <var>H</var> ≤ 10<sup>9</sup>) ãšè»ã®æ° <var>N</var> (1 ≤ <var>N</var> ≤ 200000) ãäžãããããç¶ã <var>N</var> è¡ã« <var>i</var> çªç®ã®è»ã®æ±è¥¿æ¹åã®äœçœ® <var>x<sub>i</sub></var> (1 ≤ <var>x<sub>i</sub></var> ≤ <var>W</var>)ãååæ¹åã®äœçœ® <var>y<sub>i</sub></var> (1 ≤ <var>y<sub>i</sub></var> ≤ <var>H</var>)ãåããè¡šãæå <var>d<sub>i</sub></var>ïŒæ±åãã®å ŽåãEããååãã®å ŽåãSãïŒãäžãããããããã§ããã§ã¹ç€ã®å西è§ã®ãã¹ã (1,1)ã<var>x</var> ãå¢å ããæ¹åãæ±ã<var>y</var> ãå¢å ããæ¹åãåãšããã
</p>
<h2>Output</h2>
<p>
èœäžããé çªã«ãè»ã®çªå·ãïŒè¡ãã€åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
3 3 3
2 1 S
1 2 E
2 2 E
</pre>
<h2>Sample Output 1</h2>
<pre>
3
1
2
</pre>
<h2>Sample Input 2</h2>
<pre>
5 4 3
3 1 S
2 2 E
1 3 E
</pre>
<h2>Sample Output 2</h2>
<pre>
2
3
1
</pre> | [
[
"3 3 3\n2 1 S\n1 2 E\n2 2 E\n",
"3 3 3\n2 1 S\n1 2 E\n2 2 E\n"
]
] |
p00350 | String Game |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>æååã²ãŒã </H1>
<p>
ããªãã¯ãååã®ã¢ã€åãšã
ãŒåã«æååã䜿ã£ãã²ãŒã ã®ããã°ã©ã ããã¬ãŒã³ãããŸããããã®ã²ãŒã ã§ã¯ãã¢ã€åãšã
ãŒåãæååã®äžããéšåæååãããããéžã³ãããããæ¯èŒããŠå°ããæ¹ãéžãã 人ã«åŸç¹ãå ç®ãããŸããäºäººã¯ç«¶ãåããäœåºŠãã²ãŒã ãè¡ããŸããããšããããåãæååã«å¯ŸããŠäœåºŠãã²ãŒã ãããŠãããã¡ã«é£œããŠããŸããŸãããããã§ããªãã¯ãæååãå€åããããã«ããã°ã©ã ãä¿®æ£ããããšã«ããŸããã
</p>
<br/>
<p>
é·ã <var>N</var> ã®æåå <var>U</var> ãš <var>Q</var> åã®åœä»€æãäžãããããšãã以äžã®åœä»€ãåŠçããããã°ã©ã ãäœæããã
</p>
<ul>
<li> æåå <var>U</var> ã®æå®ãããç¯å²ã«ãããã¹ãŠã®æåããæå®ãããæåã«çœ®ãæããã</li>
<li> æåå <var>U</var> ã®æå®ãããïŒã€ã®éšåæåå <var>S</var>, <var>T</var> ãèŸæžé ã§æ¯èŒããŠããããã®å€§å°é¢ä¿ãåºåããã</li>
</ul>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>U</var>
<var>Q</var>
<var>query<sub>1</sub></var>
<var>query<sub>2</sub></var>
:
<var>query<sub>Q</sub></var>
</pre>
<p>
ïŒè¡ç®ã«æååã®é·ã <var>N</var> (1 ≤ <var>N</var> ≤ 200000)ãïŒè¡ç®ã«æåå <var>U</var> (è±å°æåã®ã¿ãå«ãæåå)ãäžãããããïŒè¡ç®ã«åœä»€ã®æ° <var>Q</var> (1 ≤ <var>Q</var> ≤ 100000) ãäžãããããç¶ã <var>Q</var> è¡ã« <var>i</var> çªç®ã®åœä»€ <var>query<sub>i</sub></var> ãäžãããããå <var>query<sub>i</sub></var> ã¯ã以äžã®ããããã®åœ¢åŒã§äžããããã
</p>
<pre>
set <var>x</var> <var>y</var> <var>z</var>
</pre>
<p>
ãŸãã¯
</p>
<pre>
comp <var>a</var> <var>b</var> <var>c</var> <var>d</var>
</pre>
<p>
set <var>x</var> <var>y</var> <var>z</var> ã¯æåå <var>U</var> ã® <var>x</var> æåç®ãã <var>y</var> æåç®ãŸã§ããæå®ãããæå <var>z</var> ã«çœ®ãæããããšãè¡šãããã ãã1 ≤ <var>x</var> ≤ <var>y</var> ≤ <var>N</var> ã§ããã<var>z</var> ã¯è±å°æåã§ããã
</p>
<p>
comp <var>a</var> <var>b</var> <var>c</var> <var>d</var> ã¯æåå <var>U</var> ã® <var>a</var> æåç®ãã <var>b</var> æåç®ãŸã§ã®éšåæååã <var>S</var>ãæåå <var>U</var> ã® <var>c</var> æåç®ãã <var>d</var> æåç®ãŸã§ã®éšåæååã <var>T</var> ãšãããšããæåå <var>S</var> ãšæåå <var>T</var> ãèŸæžé ã§æ¯èŒããããšãè¡šãããã ãã1 ≤ <var>a</var> ≤ <var>b</var> ≤ <var>N</var> ã〠1 ≤ <var>c</var> ≤ <var>d</var> ≤ <var>N</var> ã§ããã
</p>
<h2>Output</h2>
<p>
å comp åœä»€ã«ã€ããŠã<var>S</var> ã®æ¹ãå°ãããªãã°ãsãã<var>T</var> ã®æ¹ãå°ãããªãã°ãtããäž¡è
ãäžèŽããŠãããªãã°ãeããšïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
13
aizualgorithm
9
comp 1 1 4 5
comp 2 6 1 5
set 9 12 b
comp 9 9 10 10
comp 5 8 1 4
set 1 10 z
set 11 13 x
comp 8 10 1 5
comp 1 5 1 5
</pre>
<h2>Sample Output 1</h2>
<pre>
s
t
e
t
s
e
</pre> | [
[
"13\naizualgorithm\n9\ncomp 1 1 4 5\ncomp 2 6 1 5\nset 9 12 b\ncomp 9 9 10 10\ncomp 5 8 1 4\nset 1 10 z\nset 11 13 x\ncomp 8 10 1 5\ncomp 1 5 1 5\n",
"13\naizualgorithm\n9\ncomp 1 1 4 5\ncomp 2 6 1 5\nset 9 12 b\ncomp 9 9 10 10\ncomp 5 8 1 4\nset 1 10 z\nset 11 13 x\ncomp 8 10 1 5\ncomp 1 5 1 5\n"
]
] |
p00351 | Evening |
<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>
AIZU åœã®å€æ®ãæã¯ãã¹ããŒããã©ã³ã西ã®ç©ºãžæ§ããŠç«ã¡æ¢ãŸã芳å
客ã§è³ãããAIZU åœã¯ç¡æ°ã®ãã«ã建ã¡äžŠã¶å€§éœåžã§ããããã«ã®è°·éãé·ãé£ãªã西ã®ç©ºã«ã¯ããã«ã®ã·ã«ãšãããšãããããæŒãåºã倪éœã®å
ã«ãã絶æ¯ãåºããã
</p>
<p>
AIZU 芳å
åäŒã®è¥æŸæ°ã«ãããšã倪éœãè¡šãåãããã®é¢ç©ã®ã¡ããã©ååã ãé®ãããŠãããšããæ Œæ®µã®çµ¶æ¯ã«ãªããšããã
</p>
<p>
å³ã®ããã«ã西ã®ç©ºããå°å¹³ç·ã <var>x</var> 軞ã倪éœã®äžå¿ã®è»è·¡ã <var>y</var> 軞ãšãããã㪠<var>x</var>-<var>y</var> å¹³é¢ã§è¡šãã倪éœãååŸ <var>R</var> ã®åãããããã®ãã«ã®ã·ã«ãšãããé·æ¹åœ¢ãšããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2016_nightfall" width="400"><br/>
</center>
<br/>
<p>
åãã«ã®ã·ã«ãšããã®åºèŸºã¯ <var>x</var> 軞äžã«ããã倪éœã¯ååé«ãäœçœ®ããå°å¹³ç·ã«å¯ŸããŠåçŽã«æ²ãã§ããã倪éœã¯ãã«ã®ã·ã«ãšãããããã¯å°å¹³ç·ãäžç«¯ãšããå°é¢ã«é®ããããããŠå°å¹³ç·ã®äžãžæ¶ããŠããã
</p>
<br/>
<p>
倪éœã®ååŸãšåãã«ã®ã·ã«ãšããã®æ
å ±ãäžãããããšãã倪éœã®é¢ç©ã®ã¡ããã©ååãé®ããããããªãæãé«ã倪éœã®é«ãïŒäžå¿ã® <var>y</var>座æšïŒãæ±ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var> <var>R</var>
<var>x<sub>1</sub></var> <var>w<sub>1</sub></var> <var>h<sub>1</sub></var>
<var>x<sub>2</sub></var> <var>w<sub>2</sub></var> <var>h<sub>2</sub></var>
:
<var>x<sub>N</sub></var> <var>w<sub>N</sub></var> <var>h<sub>N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ãã«ã®æ° <var>N</var> (0 ≤ <var>N</var> ≤ 100) ãšå€ªéœãè¡šãåã®ååŸ <var>R</var> (1 ≤ <var>R</var> ≤ 100) ãäžãããããç¶ã <var>N</var> è¡ã« <var>i</var> çªç®ã®ãã«ã®ã·ã«ãšããã®å·Šäžè§ã® <var>x</var> åº§æš <var>x<sub>i</sub></var> (-100 ≤ <var>x<sub>i</sub></var> ≤ 100, <var>x<sub>i</sub></var> < <var>x<sub>i+1</sub></var>)ãå¹
<var>w<sub>i</sub></var> (1 ≤ <var>w<sub>i</sub></var> ≤ 100)ãé«ã <var>h<sub>i</sub></var> (1 ≤ <var>h<sub>i</sub></var> ≤ 100) ãäžãããããå
¥åã¯ãã¹ãŠæŽæ°ã§äžããããã
</p>
<p>
å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã
</p>
<ul>
<li> ãã«ã®ã·ã«ãšãããéãªãããšã¯ãªãïŒ<var>x<sub>i</sub></var> + <var>w<sub>i</sub></var> ≤ <var>x<sub>i+1</sub></var>ïŒã</li>
<li> ïŒã€ã®é£æ¥ãããã«ã®ã·ã«ãšããã®é«ãã®å·®ã¯ã<var>R</var> ãè¶
ããªãã</li>
<li> ãã«ã®å·ŠåŽïŒ<var>x</var> 軞ã®è² ã®æ¹åïŒãŸãã¯å³åŽïŒ<var>x</var> 軞ã®æ£ã®æ¹åïŒã«é£æ¥ãããã«ããªãå Žåããã®é«ã㯠<var>R</var> ãè¶
ããªãã</li>
</ul>
<h2>Output</h2>
<p>
倪éœã®é«ãïŒåã®äžå¿ã® <var>y</var> 座æšïŒãïŒè¡ã«åºåããããã ãã誀差ããã©ã¹ãã€ãã¹ 10<sup>-6</sup> ãè¶
ããŠã¯ãªããªãã
</p>
<h2>Sample Input 1</h2>
<pre>
0 2
</pre>
<h2>Sample Output 1</h2>
<pre>
0.00000000
</pre>
<h2>Sample Input 2</h2>
<pre>
3 2
-2 1 1
-1 1 2
0 2 1
</pre>
<h2>Sample Output 2</h2>
<pre>
1.25065774
</pre> | [
[
"0 2\n",
"0 2\n"
]
] |
p00352 | Handsel |
<H1>Handsel</H1>
<!-- New Yearâs gift money -->
<p>
Alice and Brown are brothers in a family and each receives pocket money in celebration of the coming year. They are very close and share the total amount of the money fifty-fifty. The pocket money each receives is a multiple of 1,000 yen.
</p>
<p>
Write a program to calculate each oneâs share given the amount of money Alice and Brown received.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>a</var> <var>b</var>
</pre>
<p>
A line of data is given that contains two values of money: <var>a</var> (1000 ≤ <var>a</var> ≤ 50000) for Alice and <bar>b</var> (1000 ≤ <var>b</var> ≤ 50000) for Brown.
</p>
<h2>Output</h2>
<p>
Output the amount of money each of Alice and Brown receive in a line.
</p>
<h2>Sample Input 1</h2>
<pre>
1000 3000
</pre>
<h2>Sample Output 1</h2>
<pre>
2000
</pre>
<h2>Sample Input 2</h2>
<pre>
5000 5000
</pre>
<h2>Sample Output 2</h2>
<pre>
5000
</pre>
<h2>Sample Input 3</h2>
<pre>
1000 2000
</pre>
<h2>Sample Output 3</h2>
<pre>
1500
</pre>
| [
[
"1000 3000\n",
"1000 3000\n"
]
] |
p00353 | Shopping | <H1>Shopping</H1>
<p>
You are now in a bookshop with your friend Alice to buy a book, "The Winning Strategy for the Programming Koshien Contest,â just released today. As you definitely want to buy it, you are planning to borrow some money from Alice in case the amount you have falls short of the price. If the amount you receive from Alice still fails to meet the price, you have to abandon buying the book this time.
</p>
<p>
Write a program to calculate the minimum amount of money you need to borrow from Alice given the following three items of data: the money you and Alice have now and the price of the book.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>m</var> <var>f</var> <var>b</var>
</pre>
<p>
A line containing the three amounts of money is given: the amount you have with you now <var>m</var> (0 ≤ <var>m</var> ≤ 10000), the money Alice has now <var>f</var> (0 ≤ <var>f</var> ≤ 10000) and the price of the book <var>b</var> (100 ≤ <var>b</var> ≤ 20000).
</p>
<h2>Output</h2>
<p>
Output a line suggesting the minimum amount of money you need to borrow from Alice. Output "NA" if all the money Alice has with him now is not a sufficient amount for you to buy the book.
</p>
<h2>Sample Input 1</h2>
<pre>
1000 3000 3000
</pre>
<h2>Sample Output 1</h2>
<pre>
2000
</pre>
<h2>Sample Input 2</h2>
<pre>
5000 3000 4500
</pre>
<h2>Sample Output 2</h2>
<pre>
0
</pre>
<h2>Sample Input 3</h2>
<pre>
500 1000 2000
</pre>
<h2>Sample Output 3</h2>
<pre>
NA
</pre>
| [
[
"1000 3000 3000\n",
"1000 3000 3000\n"
]
] |
p00354 | Day of Week |
<!--<H1>X-th day of September</H1>-->
<h1>Day of Week</h1>
<p>
The 9th day of September 2017 is Saturday. Then, what day of the week is the X-th of September 2017?
</p>
<p>
Given a day in September 2017, write a program to report what day of the week it is.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>X</var>
</pre>
<p>
The input line specifies a day <var>X</var> (1 ≤ <var>X</var> ≤ 30) in September 2017.
</p>
<h2>Output</h2>
<p>
Output what day of the week it is in a line. Use the following conventions in your output: "<span>mon</span>" for Monday, "<span>tue</span>" for Tuesday, "<span>wed</span>" for Wednesday, "<span>thu</span>" for Thursday, "<span>fri</span>" for Friday, "<span>sat</span>" for Saturday, and "<span>sun</span>" for Sunday.
</p>
<h2>Sample Input 1</h2>
<pre>
1
</pre>
<h2>Sample Output 1</h2>
<pre>
fri
</pre>
<h2>Sample Input 2</h2>
<pre>
9
</pre>
<h2>Sample Output 2</h2>
<pre>
sat
</pre>
<h2>Sample Input 3</h2>
<pre>
30
</pre>
<h2>Sample Output 3</h2>
<pre>
sat
</pre>
| [
[
"1\n",
"1\n"
]
] |
p00355 | Reservation System |
<H1>Reservation System</H1>
<p>
The supercomputer system L in the PCK Research Institute performs a variety of calculations upon request from external institutes, companies, universities and other entities. To use the L system, you have to reserve operation time by specifying the start and end time. No two reservation periods are allowed to overlap each other.
</p>
<p>
Write a program to report if a new reservation overlaps with any of the existing reservations. Note that the coincidence of start and end times is not considered to constitute an overlap. All the temporal data is given as the elapsed time from the moment at which the L system starts operation.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>a</var> <var>b</var>
<var>N</var>
<var>s_1</var> <var>f_1</var>
<var>s_2</var> <var>f_2</var>
:
<var>s_N</var> <var>f_N</var>
</pre>
<p>
The first line provides new reservation information, i.e., the start time <var>a</var> and end time <var>b</var> (0 ≤ <var>a</var> < <var>b</var> ≤ 1000) in integers. The second line specifies the number of existing reservations <var>N</var> (0 ≤ <var>N</var> ≤ 100). Subsequent <var>N</var> lines provide temporal information for the <var>i</var>-th reservation: start time <var>s_i</var> and end time <var>f_i</var> (0 ≤ <var>s_i</var> < <var>f_i</var> ≤ 1000) in integers. No two existing reservations overlap.
</p>
<h2>Output</h2>
<p>
Output "1" if the new reservation temporally overlaps with any of the existing ones, or "0" otherwise.
</p>
<h2>Sample Input 1</h2>
<pre>
5 7
3
1 4
4 5
7 10
</pre>
<h2>Sample Output 1</h2>
<pre>
0
</pre>
<h2>Sample Input 2</h2>
<pre>
3 7
3
7 10
1 4
4 5
</pre>
<h2>Sample Output 2</h2>
<pre>
1
</pre>
| [
[
"5 7\n3\n1 4\n4 5\n7 10\n",
"5 7\n3\n1 4\n4 5\n7 10\n"
]
] |
p00356 | Wire |
<H1>Wire</H1>
<p>
I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an <var>x</var> (horizontal) by <var>y</var> (vertical) array of the panels. The customer asked me to stretch a wire from the left top corner of the wall to the right bottom corner whereby the wire is tied up at the crossing points with the panel boundaries (edges and vertexes) as shown in the figure. There are nine tied-up points in the illustrative figure shown below.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2017_wire" width="300"><br/>
<span>
Fig: The wire is tied up at the edges and vertexes of the panels (X: 4 panels, Y: 6 panels)<br/>
</span>
</center>
<br/>
<p>
Write a program to provide the number of points where the wire intersects with the panel boundaries.
Assume that the wire and boundary lines have no thickness.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>x</var> <var>y</var>
</pre>
<p>
A line of data is given that contains the integer number of panels in the horizontal direction <var>x</var> (1 ≤ <var>x</var> ≤ 1000) and those in the vertical direction <var>y</var> (1 ≤ <var>y</var> ≤ 1000).
</p>
<h2>Output</h2>
<p>
Output the number of points where the wire intersects with the panel boundaries.
</p>
<h2>Sample Input 1</h2>
<pre>
4 4
</pre>
<h2>Sample Output 1</h2>
<pre>
5
</pre>
<h2>Sample Input 2</h2>
<pre>
4 6
</pre>
<h2>Sample Output 2</h2>
<pre>
9
</pre>
| [
[
"4 4\n",
"4 4\n"
]
] |
p00357 | Trampoline | <H1>Trampoline</H1>
<p>
A plurality of trampolines are arranged in a line at 10 m intervals. Each trampoline has its own maximum horizontal distance within which the jumper can jump safely. Starting from the left-most trampoline, the jumper jumps to another trampoline within the allowed jumping range. The jumper wants to repeat jumping until he/she reaches the right-most trampoline, and then tries to return to the left-most trampoline only through jumping. Can the jumper complete the roundtrip without a single stepping-down from a trampoline?
</p>
<p>
Write a program to report if the jumper can complete the journey using the list of maximum horizontal reaches of these trampolines. Assume that the trampolines are points without spatial extent.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>N</var>
<var>d_1</var>
<var>d_2</var>
:
<var>d_N</var>
</pre>
<p>
The first line provides the number of trampolines <var>N</var> (2 ≤ <var>N</var> ≤ 3 × 10<sup>5</sup>). Each of the subsequent <var>N</var> lines gives the maximum allowable jumping distance in integer meters for the <var>i</var>-th trampoline <var>d_i</var> (1 ≤ <var>d_i</var> ≤ 10<sup>6</sup>).
</p>
<h2>Output</h2>
<p>
Output "<span>yes</span>" if the jumper can complete the roundtrip, or "<span>no</span>" if he/she cannot.
</p>
<h2>Sample Input 1</h2>
<pre>
4
20
5
10
1
</pre>
<h2>Sample Output 1</h2>
<pre>
no
</pre>
<h2>Sample Input 2</h2>
<pre>
3
10
5
10
</pre>
<h2>Sample Output 2</h2>
<pre>
no
</pre>
<h2>Sample Input 3</h2>
<pre>
4
20
30
1
20
</pre>
<h2>Sample Output 3</h2>
<pre>
yes
</pre>
| [
[
"4\n20\n5\n10\n1\n",
"4\n20\n5\n10\n1\n"
]
] |
p00358 | Loading | <!--<H1>Cargo Layout</H1>-->
<H1>Loading</H1>
<p>
Aizu Ocean Transport Company (AOTC) accepted a new shipping order. The pieces of the cargo included in this order all have the same square footprint (2m x 2m). The cargo room has a rectangular storage space of 4m width with various longitudinal extents. Each pieces of cargo must be placed in alignment with partition boundaries which form a 1m x 1m square grid. A straddling arrangement with a neighboring partition (for example, protrusion by 50 cm) is not allowed. Neither an angled layout nor stacked placement are allowed. Note also that there may be some partitions on which any cargo loading is prohibited.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2017_cargo" width="680"><br/>
</center>
<br/>
<p>
AOTC wishes to use the currently available ship for this consignment and needs to know how many pieces of cargo it can accommodate.
</p>
<p>
Make a program to report the maximum cargo capacity of the cargo space given the following information: the depth (m) of the cargo space and the loading-inhibited partitions.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>H</var> <var>N</var>
<var>x_1</var> <var>y_1</var>
<var>x_2</var> <var>y_2</var>
:
<var>x_N</var> <var>y_N</var>
</pre>
<p>
The first line provides the longitudinal depth <var>H</var> (2 ≤ <var>H</var> ≤ 10<sup>4</sup>) of the cargo space in meters and the number of load-inhibited partitions <var>N</var> (0 ≤ <var>N</var> ≤ 4 × 10<sup>4</sup>). Each of the subsequent <var>N</var> lines defines the position of the <var>i</var>-th load-inhibited partition <var>x_i</var> (0 ≤ <var>x_i</var> ≤ 3) and <var>y_i</var> (0 ≤ <var>y_i</var> ≤ <var>H</var>-1) in integers, where <var>x</var> = 0 and <var>y</var> = 0 indicate the bottom-left corner partition. A load-inhibited partition appears only once in the list.
</p>
<h2>Output</h2>
<p>
Output the maximum number of cargo pieces loaded into the cargo space.
</p>
<h2>Sample Input 1</h2>
<pre>
5 3
0 1
1 2
3 3
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<p>
Input example 1 corresponds to the cargo layout shown in the left-most figure.
</p>
<h2>Sample Input 2</h2>
<pre>
6 4
0 2
1 3
3 4
0 5
</pre>
<h2>Sample Output 2</h2>
<pre>
4
</pre>
| [
[
"5 3\n0 1\n1 2\n3 3\n",
"5 3\n0 1\n1 2\n3 3\n"
]
] |
p00359 | Dungeon | <H1>Dungeon</H1>
<p>
Bob is playing a popular game called "Dungeon". The game is played on a rectangular board consisting of <var>W × H</var> squares. Each square is identified with its column and row number, thus the square located in the <var>x</var>-th column and the <var>y</var>-th row is represented as (<var>x</var>, <var>y</var>). The left-most square in the top row is (0, 0) and the right-most square in the bottom row is (<var>W</var>-1, <var>H</var>-1).
</p>
<p>
Bob moves a character "BomBom" to clear the game. BomBom is initially located at (0, 0). The game is won if Bob successfully destroys all the enemy characters on the board by manipulating BomBom cleverly. The enemy characters are fixed on specific squares, and Bob can manipulate BomBom using the following two operations any number of times.
</p>
<ul>
<li> One-square movement in the up, down, left, or right direction within the board</li>
<li> Using a bomb, eliminate all the enemy characters that are located in the same column and row as that of BomBom</li>
</ul>
<p>
BomBom consumes a Cost when it moves from one square to another. BomBom can use a bomb any number of times without consuming a Cost. Use of a bomb has no effect on BomBomâs behavior and it can move even to a square where an enemy character is located.
</p>
<p>
Given the board size and enemy information, make a program to evaluate the minimum Cost BomBom consumes before it destroys all enemy characters.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>W</var> <var>H</var> <var>N</var>
<var>x_1</var> <var>y_1</var>
<var>x_2</var> <var>y_2</var>
:
<var>x_N</var> <var>y_N</var>
</pre>
<p>
The first line provides the number of squares in the horizontal direction <var>W</var> (1 ≤ <var>W</var> ≤ 10<sup>5</sup>), in the vertical direction <var>H</var> (1 ≤ <var>H</var> ≤ 10<sup>5</sup>), and the number of enemy characters <var>N</var> (1 ≤ <var>N</var> ≤ 10<sup>5</sup>). Each of the subsequent <var>N</var> lines provides location information of the <var>i</var>-th enemy, column <var>x_i</var> (0 ≤ <var>x_i</var> ≤ <var>W</var>-1) and row <var>y_i</var> (0 ≤ <var>y_i</var> ≤ <var>H</var>-1). The number of enemy characters in a specific square can be either one or zero.
</p>
<h2>Output</h2>
<p>
Output the minimum Cost in a line.
</p>
<h2>Sample Input 1</h2>
<pre>
5 4 4
0 3
1 1
2 2
2 3
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<h2>Sample Input 2</h2>
<pre>
6 6 5
2 1
5 2
3 3
1 4
1 5
</pre>
<h2>Sample Output 2</h2>
<pre>
4
</pre>
<h2>Sample Input 3</h2>
<pre>
8 8 4
6 0
7 0
0 6
0 7
</pre>
<h2>Sample Output 3</h2>
<pre>
0
</pre>
| [
[
"5 4 4\n0 3\n1 1\n2 2\n2 3\n",
"5 4 4\n0 3\n1 1\n2 2\n2 3\n"
]
] |
p00360 | Swapping Characters | <H1>Swapping Characters</H1>
<p>
You are given a string and a number <var>k</var>. You are suggested to generate new strings by swapping any adjacent pair of characters in the string up to <var>k</var> times. Write a program to report the lexicographically smallest string among them.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>s</var>
<var>k</var>
</pre>
<p>
The first line provides a string <var>s</var>. The second line provides the maximum number of swapping operations <var>k</var> (0 ≤ <var>k</var> ≤ 10<sup>9</sup>). The string consists solely of lower-case alphabetical letters and has a length between 1 and 2 × 10<sup>5</sup>.
</p>
<h2>Output</h2>
<p>
Output the lexicographically smallest string.
</p>
<h2>Sample Input 1</h2>
<pre>
pckoshien
3
</pre>
<h2>Sample Output 1</h2>
<pre>
ckopshien
</pre>
<h2>Sample Input 2</h2>
<pre>
pckoshien
10
</pre>
<h2>Sample Output 2</h2>
<pre>
cekophsin
</pre>
| [
[
"pckoshien\n3\n",
"pckoshien\n3\n"
]
] |
p00361 | Road Improvement | <!--<H1>Modification of Road Network</H1>-->
<h1>Road Improvement</h1>
<p>
Aizu is a country famous for its rich tourism resources and has <var>N</var> cities, each of which is uniquely identified with a number (0 to <var>N</var>-1). It has a road network consisting of <var>M</var> one-way roads connecting a city to another.
</p>
<p>
All the roads connecting the cities in Aizu have a row of cherry trees along their routes. For enhancing the cherry-viewing experience, a proposal was made to modify the road network so that a tourist can travel around all the roads. To achieve this target, it was decided to construct several one-way roads, each connecting two cities and abiding by the following rules.
</p>
<ul>
<li>The newly constructed road is for one-way traffic</li>
<li>Starting from any city, a tourist is able to make a roundtrip and return to the city, whereby he/she drives all the roads exhaustively, including the newly constructed ones. Multiple passages of some of the roads are allowed.</li>
</ul>
<p>
You, as a tourism promotion officer, are assigned with the task of writing a program for the road construction project.
</p>
<p>
Write a program to determine the minimum number of roads to be constructed given the road network information in Aizu.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>N</var> <var>M</var>
<var>s_1</var> <var>t_1</var>
<var>s_2</var> <var>t_2</var>
:
<var>s_M</var> <var>t_M</var>
</pre>
<p>
The first line provides the number of cities <var>N</var> (1 ≤ <var>N</var> ≤ 10<sup>4</sup>) and roads <var>M</var> (0 ≤ <var>M</var> ≤ 10<sup>5</sup>). Each of the subsequent <var>M</var> lines provides the numbers assigned to start and destination cities for the <var>i</var>-th road: <var>s_i</var>, <var>t_i</var> (0 ≤ <var>s_i</var>, <var>t_i</var> ≤ <var>N</var>-1) , where <var>s_i ≠ t_i</var>. (no duplicate appearance of a road)
</p>
<h2>Output</h2>
<p>
Output the minimum number of roads to be newly constructed.
</p>
<h2>Sample Input 1</h2>
<pre>
6 7
0 2
2 1
1 0
2 3
4 3
4 5
5 4
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<h2>Sample Input 2</h2>
<pre>
6 9
0 2
2 1
1 0
2 3
4 3
4 5
5 4
5 2
3 4
</pre>
<h2>Sample Output 2</h2>
<pre>
0
</pre>
| [
[
"6 7\n0 2\n2 1\n1 0\n2 3\n4 3\n4 5\n5 4\n",
"6 7\n0 2\n2 1\n1 0\n2 3\n4 3\n4 5\n5 4\n"
]
] |
p00362 | Charging System for Network | <!--<H1>Network Charging System</H1>-->
<h1>Charging System for Network</h1>
<p>
There is a network consisting of <var>N</var> machines (sequentially numbered from 0 to <var>N</var>-1) interconnected through <var>N</var>-1 bidirectional communication cables. Any two machines can perform bidirectional communication through one or more cables. From time to time, machines in the network are renewed. When a new machine is introduced, the cables directly connected to it are also replaced with thicker ones to cope with the increased volume of communication traffic.
</p>
<p>
The communication fee arising from communication traffic between any two machines is calculated by summing the charges assigned to all the cables routing via the two. A unique charging scheme is employed in this system: if the size of a cable is a multiple of <var>K</var>, then the cable is not charged (free of charge). Other cables are charged according to their sizes.
</p>
<p>
Based on the given information on the network topology and <var>Q</var> instructions, write a program to execute each instruction.
</p>
<ul>
<li>Increase the sizes of all cables directly connected to the machine <var>x</var> by <var>d</var>.</li>
<li>Report the communication charge between the machines <var>s</var> and <var>t</var>.</li>
</ul>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>N</var> <var>K</var>
<var>a_1</var> <var>b_1</var> <var>c_1</var>
<var>a_2</var> <var>b_2</var> <var>c_2</var>
:
<var>a_{N−1}</var> <var>b_{N−1}</var> <var>c_{N−1}</var>
<var>Q</var>
<var>query_1</var>
<var>query_2</var>
:
<var>query_Q</var>
</pre>
<p>
The first line provides the number of machines <var>N</var> (2 ≤ <var>N</var> ≤ 10<sup>5</sup>) and the cable size <var>K</var> (1 ≤ <var>K</var> ≤ 10<sup>5</sup>) (the reference value for determining free of charge cables). Each of subsequent <var>N</var>-1 lines provides the <var>i</var>-th cable information that directly connects two machines <var>a_i</var> and <var>b_i</var> (0 ≤ <var>a_i</var> < <var>b_i</var> ≤ <var>N</var>-1), followed by the cableâs initial size <var>c_i</var> (1 ≤ <var>c_i</var> ≤ 10<sup>5</sup>). For any pair of machines, the number of cables directly connecting them is either one or zero. The next line following them provides the number of instructions <var>Q</var> (1 ≤ <var>Q</var> ≤ 10<sup>5</sup>). Each of the Q lines following it provides the <var>i</var>-th instruction <var>query_i</var>, which is either one of the following two:
</p>
<pre>
add <var>x</var> <var>d</var>
</pre>
<p>
or
</p>
<pre>
send <var>s</var> <var>t</var>
</pre>
<p>
The instruction <span>add</span> <var>x</var> <var>d</var> increase the size of all cables directly connected to machine <var>x</var> (0 ≤ <var>x</var> ≤ <var>N</var>-1) by <var>d</var> (1 ≤ <var>d</var> ≤ 10<sup>5</sup>).
</p>
<p>
The instruction <span>send</span> <var>s</var> <var>t</var> reports the charge imposed to the communication between the two machines <var>s</var> (0 ≤ <var>s</var> ≤ <var>N</var>-1) and <var>t</var> (0 ≤ <var>t</var> ≤ <var>N</var>-1), where <var>s ≠ t</var>.
</p>
<p>
At least one <span>send</span> instruction is included in the input information.
</p>
<h2>Output</h2>
<p>
For each <span>send</span> command, output the communication charge between <var>s</var> and <var>t</var>.
</p>
<h2>Sample Input 1</h2>
<pre>
6 3
0 1 1
0 2 1
0 3 1
2 4 1
2 5 1
3
send 1 4
add 2 2
send 1 4
</pre>
<h2>Sample Output 1</h2>
<pre>
3
1
</pre>
| [
[
"6 3\n0 1 1\n0 2 1\n0 3 1\n2 4 1\n2 5 1\n3\nsend 1 4\nadd 2 2\nsend 1 4\n",
"6 3\n0 1 1\n0 2 1\n0 3 1\n2 4 1\n2 5 1\n3\nsend 1 4\nadd 2 2\nsend 1 4\n"
]
] |
p00363 | Flag | <!--<H1>Letâs Make a Flag</H1>-->
<h1>Flag</h1>
<p>
AHK Education, the educational program section of Aizu Broadcasting Cooperation, broadcasts a childrenâs workshop program called "Let's Play and Make." Todayâs theme is "Make your own flag." A child writes his first initial in the center of their rectangular flag.
</p>
<p>
Given the flag size and the initial letter to be placed in the center of it, write a program to draw the flag as shown in the figure below.
</p>
<pre>
+-------+
|.......|
|...A...|
|.......|
+-------+
</pre>
<p>
The figure has "A" in the center of a flag with size 9 (horizontal) × 5 (vertical).
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>W</var> <var>H</var> <var>c</var>
</pre>
<p>
The input line provides the flag dimensions <var>W</var> (width) and <var>H</var> (height) (3 ≤ <var>W,H</var> ≤ 21), and the initial letter <var>c</var>. Both <var>W</var> and <var>H</var> are odd numbers, and <var>c</var> is a capital letter.
</p>
<h2>Output</h2>
<p>
Draw the flag of specified size with the initial in its center using the following characters: "<span>+</span>" for the four corners of the flag, "<span>-</span>" for horizontal lines, "<span>|</span>" for vertical lines, and "<span>.</span>" for the background (except for the initial in the center).
</p>
<h2>Sample Input 1</h2>
<pre>
3 3 B
</pre>
<h2>Sample Output 1</h2>
<pre>
+-+
|B|
+-+
</pre>
<h2>Sample Input 2</h2>
<pre>
11 7 Z
</pre>
<h2>Sample Output 2</h2>
<pre>
+---------+
|.........|
|.........|
|....Z....|
|.........|
|.........|
+---------+
</pre>
| [
[
"3 3 B\n",
"3 3 B\n"
]
] |
p00364 | Bange Hills Tower | <H1>Bange Hills Tower</H1>
<p>
A project is underway to build a new viewing tower in Bange town called âBange Hills Towerâ whose selling point will be the gorgeous view of the entire main keep of Wakamatsu Castle from top to bottom. Therefore, the view line from the top of the tower must reach the bottom of the keep without being hindered by any of the buildings in the town.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2017_wakamatsuCastle" width="600"></center><br/>
<p>
Write a program to calculate the minimum tower height required to view the keep in its entirety based on the following information: the planned location of the tower and the heights and locations of existing buildings. Assume all the buildings, including the keep, are vertical lines without horizontal stretch. âview of the entire keepâ means that the view line from the tower top can cover the keep from the bottom to the top without intersecting (contacts at the top are exempted) any of the other vertical lines (i.e., buildings).
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>N</var> <var>t</var>
<var>x_1</var> <var>h_1</var>
<var>x_2</var> <var>h_2</var>
:
<var>x_N</var> <var>h_N</var>
</pre>
<p>
The first line provides the number of existing buildings <var>N</var> (1≤<var>N</var>≤1000) and the planned location of the tower <var>t</var> (2≤<var>t</var>≤10<sup>5</sup>) in integers. Each of the subsequent <var>N</var> lines provides the information of the <var>i</var>-th building: location <var>x_i</var> (1 ≤ <var>x_i</var> < <var>t</var>) and height from the ground <var>h_i</var> (1 ≤ <var>h_i</var> ≤ 100). All position information is one-dimensional along the ground line whose origin coincides with the Keep location. No more than one building is located in the same location (i.e. if <var>i ≠ j</var>, then <var>x_i ≠ x_j</var>).
</p>
<h2>Output</h2>
<p>
Output the required height as a real number. No limits on the number of decimal places as long as the error does not exceed ± 10<sup>-3</sup>.
</p>
<h2>Sample Input 1</h2>
<pre>
3 10
6 4
4 2
3 2
</pre>
<h2>Sample Output 1</h2>
<pre>
6.666667
</pre>
| [
[
"3 10\n6 4\n4 2\n3 2\n",
"3 10\n6 4\n4 2\n3 2\n"
]
] |
p00365 | Age Difference | <H1>Age Difference</H1> <!-- Difference in ages-->
<p>
A trick of fate caused Hatsumi and Taku to come to know each other. To keep the encounter in memory, they decided to calculate the difference between their ages. But the difference in ages varies depending on the day it is calculated. While trying again and again, they came to notice that the difference of their ages will hit a maximum value even though the months move on forever.
</p>
<p>
Given the birthdays for the two, make a program to report the maximum difference between their ages. The age increases by one at the moment the birthday begins. If the birthday coincides with the 29<sup>th</sup> of February in a leap year, the age increases at the moment the 1<sup>st</sup> of March arrives in non-leap years.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>y_1</var> <var>m_1</var> <var>d_1</var>
<var>y_2</var> <var>m_2</var> <var>d_2</var>
</pre>
<p>
The first and second lines provide Hatsumiâs and Takuâs birthdays respectively in year <var>y_i</var> (1 ≤ <var>y_i</var> ≤ 3000), month <var>m_i</var> (1 ≤ <var>m_i</var> ≤ 12), and day <var>d_i</var> (1 ≤ <var>d_i</var> ≤ D<sub>max</sub>) format. Where <var>D<sub>max</sub></var> is given as follows:
</p>
<ul>
<li> 28 when February in a non-leap year</li>
<li> 29 when February in a leap-year</li>
<li> 30 in April, June, September, and November</li>
<li> 31 otherwise.</li>
</ul>
<p>
It is a leap year if the year represented as a four-digit number is divisible by 4. Note, however, that it is a non-leap year if divisible by 100, and a leap year if divisible by 400.
</p>
<h2>Output</h2>
<p>
Output the maximum difference between their ages.
</p>
<h2>Sample Input 1</h2>
<pre>
1999 9 9
2001 11 3
</pre>
<h2>Sample Output 1</h2>
<pre>
3
</pre>
<p>
In this example, the difference of ages between them in 2002 and subsequent years is 3 on the 1<sup>st</sup> of October, but 2 on the 1<sup>st</sup> of December.
</p>
<h2>Sample Input 2</h2>
<pre>
2008 2 29
2015 3 1
</pre>
<h2>Sample Output 2</h2>
<pre>
8
</pre>
<p>
In this example, the difference of ages will become 8 on the 29<sup>th</sup> of February in and later years than 2016.
</p>
| [
[
"1999 9 9\n2001 11 3\n",
"1999 9 9\n2001 11 3\n"
]
] |
p00366 | Electronic Metronome | <H1>Electric Metronome</H1>
<p>
A boy PCK is playing with <var>N</var> electric metronomes. The <var>i</var>-th metronome is set to tick every <var>t_i</var> seconds. He started all of them simultaneously.
</p>
<p>
He noticed that, even though each metronome has its own ticking interval, all of them tick simultaneously from time to time in certain intervals. To explore this interesting phenomenon more fully, he is now trying to shorten the interval of ticking in unison by adjusting some of the metronomesâ interval settings. Note, however, that the metronomes do not allow any shortening of the intervals.
</p>
<p>
Given the number of metronomes and their preset intervals <var>t_i</var> (sec), write a program to make the tick-in-unison interval shortest by adding a non-negative integer <var>d_i</var> to the current interval setting of the <var>i</var>-th metronome, and report the minimum value of the sum of all <var>d_i</var>.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>N</var>
<var>t_1</var>
<var>t_2</var>
:
<var>t_N</var>
</pre>
<p>
The first line provides the number of metronomes <var>N</var> (1 ≤ <var>N</var> ≤ 10<sup>5</sup>). Each of the subsequent <var>N</var> lines provides the preset ticking interval <var>t_i</var> (1 ≤ <var>t_i</var> ≤ 10<sup>4</sup>) of the <var>i</var>-th metronome.
</p>
<h2>Output</h2>
<p>
Output the minimum value.
</p>
<h2>Sample Input 1</h2>
<pre>
3
3
6
8
</pre>
<h2>Sample Output 1</h2>
<pre>
3
</pre>
<p>
If we have three metronomes each with a ticking interval of 3, 6, and 8 seconds, respectively, simultaneous activation of these will produce a tick in unison every 24 seconds. By extending the interval by 1 second for the first, and 2 seconds for the second metronome, the interval of ticking in unison will be reduced to 8 seconds, which is the shortest possible for the system.
</p>
<h2>Sample Input 2</h2>
<pre>
2
10
10
</pre>
<h2>Sample Output 2</h2>
<pre>
0
</pre>
<p>
If two metronomes are both set to 10 seconds, then simultaneous activation will produce a tick in unison every 10 seconds, which is the shortest possible for this system.
</p>
| [
[
"3\n3\n6\n8\n",
"3\n3\n6\n8\n"
]
] |
p00367 | Three Meals | <!--<H1>Breakfast, Lunch and Supper</H1>-->
<h1>Three Meals</h1>
<p>
You are running a restaurant that serves dishes only three times a day. Each of your customer has his/her own separate time zones for eating breakfast, lunch and supper. Thus, your customer enjoys your dish only when he/she visits your restaurant to meet your serving time settings. Your wish is to modify your serving time arrangement so that as many as possible of your customers can enjoy your meals three times a day.
</p>
<p>
Write a program to enable as many as possible of customers can enjoy your service three times a day, i.e. breakfast, lunch, and supper. A list of customers eating time zones is given, which you cannot change. Settings of your service time are your option. Coincidence between your service time and either edge of customerâs time zone (start or end time) does not hinder you to provide your service.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>N</var>
<var>ast_1</var> <var>aet_1</var> <var>hst_1</var> <var>het_1</var> <var>bst_1</var> <var>bet_1</var>
<var>ast_2</var> <var>aet_2</var> <var>hst_2</var> <var>het_2</var> <var>bst_2</var> <var>bet_2</var>
:
<var>ast_N</var> <var>aet_N</var> <var>hst_N</var> <var>het_N</var> <var>bst_N</var> <var>bet_N</var>
</pre>
<p>
The first line provides the number of customers <var>N</var>(1≤<var>N</var>≤50). Each of subsequent <var>N</var> lines provides time zone information of <var>i</var>-th customer: start and end time of breakfast zone (<var>ast_i</var>, <var>aet_i</var>), those of lunch zone (<var>hst_i</var>, <var>het_i</var>) and those of supper zone (<var>bst_i</var>, <var>bet_i</var>). The end time must be later in time as the start time. Time zones do not overlap, i.e. <var>hst_i</var> is later in time than <var>aet_i</var>, and so on. Each time settings must not cross 0:00 midnight.
</p>
<pre>
<var>h</var> <var>m</var>
</pre>
<p>
Each time information is given by hour <var>h</var> (0≤<var>h</var>≤23) and minute <var>m</var>(0≤<var>m</var>≤59).
</p>
<h2>Output</h2>
<p>
Output the maximum number of customers that can be served all three meals (breakfast, lunch, and supper).
</p>
<h2>Sample Input 1</h2>
<pre>
5
1 0 2 0 3 30 4 30 6 0 7 0
2 30 3 0 4 0 5 0 5 30 6 30
1 30 2 30 4 30 5 0 6 30 7 0
2 30 3 0 5 0 6 0 6 30 7 0
1 0 2 0 3 0 3 30 4 0 5 0
</pre>
<h2>Sample Output 1</h2>
<pre>
3
</pre>
| [
[
"5\n1 0 2 0 3 30 4 30 6 0 7 0\n2 30 3 0 4 0 5 0 5 30 6 30\n1 30 2 30 4 30 5 0 6 30 7 0\n2 30 3 0 5 0 6 0 6 30 7 0\n1 0 2 0 3 0 3 30 4 0 5 0\n",
"5\n1 0 2 0 3 30 4 30 6 0 7 0\n2 30 3 0 4 0 5 0 5 30 6 30\n1 30 2 30 4 30 5 0 6 30 7 0\n2 30 3 0 5 0 6 0 6 30 7 0\n1 0 2 0 3 0 3 30 4 0 5 0\n"
]
] |
p00368 | Checkered Pattern | <H1>Checkered Pattern</H1>
<p>
You have a cross-section paper with W x H squares, and each of them is painted either in white or black. You want to re-arrange the squares into a neat checkered pattern, in which black and white squares are arranged alternately both in horizontal and vertical directions (the figure shown below is a checkered patter with <var>W = 5</var> and <var>H = 5</var>). To achieve this goal, you can perform the following two operations as many times you like in an arbitrary sequence: swapping of two arbitrarily chosen columns, and swapping of two arbitrarily chosen rows.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2017_checkerBoard" width="280">
</center><br/>
<p>
Create a program to determine, starting from the given cross-section paper, if you can re-arrange them into a checkered pattern.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>W</var> <var>H</var>
<var>c<sub>1,1</sub></var> <var>c<sub>1,2</sub></var> ... <var>c<sub>1,W</sub></var>
<var>c<sub>2,1</sub></var> <var>c<sub>2,2</sub></var> ... <var>c<sub>2,W</sub></var>
:
<var>c<sub>H,1</sub></var> <var>c<sub>H,2</sub></var> ... <var>c<sub>H,W</sub></var>
</pre>
<p>
The first line provides the number of squares in horizontal direction <var>W</var> (2≤<var>W</var>≤1000) and those in vertical direction <var>H</var>(2≤<var>H</var>≤1000). Each of subsequent <var>H</var> lines provides an array of <var>W</var> integers <var>c<sub>i,j</sub></var> corresponding to a square of <var>i</var>-th row and <var>j</var>-th column. The color of the square is white if <var>c<sub>i,j</sub></var> is 0, and black if it is 1.
</p>
<h2>Output</h2>
<p>
Output "yes" if the goal is achievable and "no" otherwise.
</p>
<h2>Sample Input 1</h2>
<pre>
3 2
1 1 0
0 0 1
</pre>
<h2>Sample Output 1</h2>
<pre>
yes
</pre>
<h2>Sample Input 2</h2>
<pre>
2 2
0 0
1 1
</pre>
<h2>Sample Output 2</h2>
<pre>
no
</pre>
| [
[
"3 2\n1 1 0\n0 0 1\n",
"3 2\n1 1 0\n0 0 1\n"
]
] |
p00369 | Paper Fortune | <H1>Paper Fortune</H1>
<p>
If you visit Aizu Akabeko shrine, you will find a unique paper fortune on which a number with more than one digit is written.
</p>
<p>
Each digit ranges from 1 to 9 (zero is avoided because it is considered a bad omen in this shrine). Using this string of numeric values, you can predict how many years it will take before your dream comes true. Cut up the string into more than one segment and compare their values. The difference between the largest and smallest value will give you the number of years before your wish will be fulfilled. Therefore, the result varies depending on the way you cut up the string. For example, if you are given a string 11121314 and divide it into segments, say, as 1,11,21,3,14, then the difference between the largest and smallest is 21 - 1 = 20. Another division 11,12,13,14 produces 3 (i.e. 14 - 11) years. Any random division produces a game of luck. However, you can search the minimum number of years using a program.
</p>
<p>
Given a string of numerical characters, write a program to search the minimum years before your wish will be fulfilled.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>n</var>
</pre>
<p>
An integer <var>n</var> is given. Its number of digits is from 2 to 100,000, and each digit ranges from 1 to 9.
</p>
<h2>Output</h2>
<p>
Output the minimum number of years before your wish will be fulfilled.
</p>
<h2>Sample Input 1</h2>
<pre>
11121314
</pre>
<h2>Sample Output 1</h2>
<pre>
3
</pre>
<h2>Sample Input 2</h2>
<pre>
123125129
</pre>
<h2>Sample Output 2</h2>
<pre>
6
</pre>
<h2>Sample Input 3</h2>
<pre>
119138
</pre>
<h2>Sample Output 3</h2>
<pre>
5
</pre>
| [
[
"11121314\n",
"11121314\n"
]
] |
p00370 | Lake Survey | <H1>Lake Survery</H1>
<p>
The Onogawa Expedition is planning to conduct a survey of the Aizu nature reserve. The expedition planner wants to take the shortest possible route from the start to end point of the survey, while the expedition has to go around the coast of the Lake of Onogawa en route. The expedition walks along the coast of the lake, but can not wade across the lake.
</p>
<p>
Based on the base information including the start and end point of the survey and the area of Lake Onogawa as convex polygon data, make a program to find the shortest possible route for the expedition and calculate its distance. Note that the expedition can move along the polygonal lines passing through the nodes, but never enter within the area enclosed by the polygon.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>x_s</var> <var>y_s</var>
<var>x_g</var> <var>y_g</var>
<var>N</var>
<var>x_1</var> <var>y_1</var>
<var>x_2</var> <var>y_2</var>
:
<var>x_N</var> <var>y_N</var>
</pre>
<p>
The first line provides the start point of the survey <var>x_s,y_s</var> (0≤<var>x_s,y_s</var>≤10<sup>4</sup>), and the second line provides the end point <var>x_g,y_g</var> (0 ≤ <var>x_g,y_g</var> ≤ 10<sup>4</sup>) all in integers. The third line provides the number of apexes <var>N</var> (3 ≤ <var>N</var> ≤ 100) of the polygon that represents the lake, and each of the subsequent <var>N</var> lines provides the coordinate of the <var>i</var>-th apex <var>x_i,y_i</var> (0 ≤ <var>x_i,y_i</var> ≤ 10<sup>4</sup>) in counter-clockwise order. These data satisfy the following criteria:
</p>
<ul>
<li>Start and end points of the expedition are not within the area enclosed by the polygon nor on boundaries.</li>
<li>Start and end points of the expedition are not identical, i.e., <var>x_s ≠ x_g</var> or <var>y_s ≠ y_g</var>.</li>
<li>No duplicate coordinates are given, i.e., if <var>i ≠ j</var> then <var>x_i ≠ x_r</var> or <var>y_i ≠ y_j</var>.</li>
<li>The area enclosed by the polygon has a positive value.</li>
<li>Any three coordinates that define an area are not aligned on a line.</li>
</ul>
<h2>Output</h2>
<p>
Output the distance of the shortest possible expedition route. Any number of decimal places can be selected as long as the error does not exceed ± 10<sup>-3</sup>.
</p>
<h2>Sample Input 1</h2>
<pre>
0 0
4 0
4
1 1
2 1
3 3
1 2
</pre>
<h2>Sample Output 1</h2>
<pre>
4.472136
</pre>
<h2>Sample Input 2</h2>
<pre>
4 4
0 0
4
1 1
3 1
3 3
1 3
</pre>
<h2>Sample Output 2</h2>
<pre>
6.32455
</pre>
| [
[
"0 0\n4 0\n4\n1 1\n2 1\n3 3\n1 2\n",
"0 0\n4 0\n4\n1 1\n2 1\n3 3\n1 2\n"
]
] |
p00371 | Lottery Box | <H1>Lottery Box</H1>
<p>
A lottery is being held in a corner of the venue of the Aizu festival. Several types of balls are inside the lottery box and each type has its unique integer printed on the surfaces of the balls. An integer <var>T</var> is printed on the lottery box.
</p>
<p>
In the lottery, you first declare two integers <var>A</var> and <var>B</var>, and draw up to <var>M</var> balls from the box. Let the sum of the integers printed on the balls be <var>S</var>. You can get a wonderful gift if the following two criteria are met: <var>S</var> divided by <var>T</var> gives a remainder greater than or equal to <var>A</var>, and <var>S</var> divided by <var>T</var> gives a quotient (fractional portion dropped) greater than or equal to <var>B</var>.
</p>
<p>
Write a program to determine if you have any chance of getting the gift given the following information: the number of ball types, ball-type specific integers, the maximum number of balls to be drawn from the box, the integer printed on the lottery box, and two integers declared before drawing. Assume that each ball type has sufficient (≥M) population in the box. Note also that there may be a chance of getting the gift even without drawing any ball.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>N</var> <var>M</var> <var>T</var>
<var>a_1</var>
<var>a_2</var>
:
<var>a_N</var>
<var>Q</var>
<var>A_1</var> <var>B_1</var>
<var>A_2</var> <var>B_2</var>
:
<var>A_Q</var> <var>B_Q</var>
</pre>
<p>
The first line provides the number of ball types <var>N</var>(1≤<var>N</var>≤10<sup>5</sup>), the maximum number of balls you can draw from the box <var>M</var>(1≤<var>M</var>≤10<sup>5</sup>), and the integer printed on the box <var>T</var>(1≤<var>T</var>≤1000). Each of the subsequent <var>N</var> lines provides an integer <var>a_i</var> (1≤<var>a_i</var>≤10<sup>9</sup>) printed on the <var>i</var>-th ball type. The next line following these provides the number of declarations <var>Q</var> (1≤<var>Q</var>≤10<sup>5</sup>). Each of the <var>Q</var> lines following this provides a pair of integers <var>A_i</var> (0 ≤ <var>A_i</var> < <var>T</var>), <var>B_i</var> (0 ≤ <var>B_i</var> ≤ 10<sup>9</sup>) that constitute the <var>i</var>-th declaration.
</p>
<h2>Output</h2>
<p>
Output a line for each pair of declaration <var>A</var> and <var>B</var> that contains "<span>yes</span>" if there is a chance of getting the gift or "<span>no</span>" otherwise.
</p>
<h2>Sample Input 1</h2>
<pre>
3 2 7
8
3
6
5
2 2
3 2
4 1
6 1
6 0
</pre>
<h2>Sample Output 1</h2>
<pre>
yes
no
yes
no
yes
</pre>
| [
[
"3 2 7\n8\n3\n6\n5\n2 2\n3 2\n4 1\n6 1\n6 0\n",
"3 2 7\n8\n3\n6\n5\n2 2\n3 2\n4 1\n6 1\n6 0\n"
]
] |
p00372 | Party | <H1>Party</H1>
<p>
The students in a class in Akabe high-school define the relation âacquaintanceâ as:
</p>
<ul>
<li>If A and B are friends, then A is acquainted with B.</li>
<li>If A and B are friends and B is acquainted with C, then A is acquainted with C.</li>
</ul>
<p>
They define the relation âcompanionâ as:
</p>
<ul>
<!-- Suppose A is acquainted with B, and some classmate who has been friends with A and B distances himself from them. If A is still acquainted with B, then A and B are companions.-->
<li>
Suppose A is acquainted with B, and two classmates who have been friend distance. If A is still acquainted with B, then A and B are companions.
</li>
</ul>
<p>
A boy PCK joined the class recently and wishes to hold a party inviting his class fellows. He wishes to invite as many boys and girls as possible to the party and has written up an invitation list. In arranging the list, he placed the following conditions based on the acquaintanceship within the class before he joined.
</p>
<p>
When T is in the list:
</p>
<ul>
<li>U is listed if he/she is a companion of T.</li>
<li>If U is not a companion of T, U is not listed if he/she and T are friends, or he/she and some of Tâs companions are friends.</li>
</ul>
<p>
PCK made the invitation list so that the maximum number of his classmates is included.
</p>
<p>
Given the number of classmates <var>N</var> and the friendships among them, write a program to estimate the number of boys and girls in the list. All the classmates are identified by an index that ranges from 0 to <var>N</var>-1.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>N</var> <var>M</var>
<var>s_1</var> <var>t_1</var>
<var>s_2</var> <var>t_2</var>
:
<var>s_M</var> <var>t_M</var>
</pre>
<p>
The first line provides the number of classmates <var>N</var> (2 ≤ <var>N</var> ≤ 10<sup>5</sup>) and the number of friendships <var>M</var> (1 ≤ <var>M</var> ≤ 2×10<sup>5</sup>). Each of the <var>M</var> subsequent lines provides two of the classmates <var>s_i, t_i</var> (0 ≤ <var>s_i,t_i</var> ≤ <var>N</var>-1) indicating they are friends. No duplicate relationship appears among these lines.
</p>
<h2>Output</h2>
<p>
Output the maximum number of classmates PCK invited to the party.
</p>
<h2>Sample Input 1</h2>
<pre>
7 8
0 1
1 2
1 3
2 3
0 4
4 5
4 6
5 6
</pre>
<h2>Sample Output 1</h2>
<pre>
6
</pre>
<h2>Sample Input 2</h2>
<pre>
3 2
0 1
1 2
</pre>
<h2>Sample Output 2</h2>
<pre>
2
</pre>
| [
[
"7 8\n0 1\n1 2\n1 3\n2 3\n0 4\n4 5\n4 6\n5 6\n",
"7 8\n0 1\n1 2\n1 3\n2 3\n0 4\n4 5\n4 6\n5 6\n"
]
] |
p00373 | Aerial Photo | <H1>Aerial Photos</H1>
<p>
Hideyo has come by two aerial photos of the same scale and orientation. You can see various types of buildings, but some areas are hidden by clouds. Apparently, they are of the same area, and the area covered by the second photograph falls entirely within the first. However, because they were taken at different time points, different shapes and distribution of clouds obscure identification where the area in the second photograph is located in the first. There may even be more than one area within the first that the second fits equally well.
</p>
<p>
A set of pixel information is given for each of the photographs. Write a program to extract candidate sub-areas within the first photograph that compare with the second equally well and output the number of the candidates.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>AW</var> <var>AH</var> <var>BW</var> <var>BH</var>
<var>arow<sub>1</sub></var>
<var>arow<sub>2</sub></var>
:
<var>arow<sub>AH</sub></var>
<var>brow<sub>1</sub></var>
<var>brow<sub>2</sub></var>
:
<var>brow<sub>BH</sub></var>
</pre>
<p>
The first line provides the number of pixels in the horizontal and the vertical direction <var>AW</var> (1 ≤ <var>AW</var> ≤ 800) and <var>AH</var> (1 ≤ <var>AH</var> ≤ 800) for the first photograph, followed by those for the second <var>BW</var> (1 ≤ <var>BW</var> ≤ 100) and <var>BH</var> (1 ≤ <var>BH</var> ≤ 100) (<var>AW</var> ≥ <var>BW</var> and<var>AH</var> ≥ <var>BH</var>). Each of the subsequent <var>AH</var> lines provides pixel information (<var>arow<sub>i</sub></var>) of the <var>i</var>-th row from the top of the first photograph. Each of the <var>B</var>H lines that follows provides pixel information (<var>brow<sub>i</sub></var>) of the <var>i</var>-th row from the top of the second photograph.
</p>
<p>
Each of the pixel information <var>arow<sub>i</sub></var> and <var>brow<sub>i</sub></var> is a string of length <var>AW</var> and <var>BW</var>, respectively, consisting of upper/lower-case letters, numeric characters, or "<span>?</span>". Each one character represents a pixel, whereby upper/lower-case letters and numeric characters represent a type of building, and "<span>?</span>" indicates a cloud-covered area.
</p>
<h2>Output</h2>
<p>
Output the number of the candidates.
</p>
<h2>Sample Input 1</h2>
<pre>
5 5 3 3
AF??z
W?p88
???Hk
pU?m?
F???c
F??
p?8
?H?
</pre>
<h2>Sample Output 1</h2>
<pre>
4
</pre>
<h2>Sample Input 2</h2>
<pre>
6 5 4 2
aaaaaa
aaaaaa
aaaaaa
aaaaaa
aaaaaa
aaaa
aaaa
</pre>
<h2>Sample Output 2</h2>
<pre>
12
</pre>
| [
[
"5 5 3 3\nAF??z\nW?p88\n???Hk\npU?m?\nF???c\nF??\np?8\n?H?\n",
"5 5 3 3\nAF??z\nW?p88\n???Hk\npU?m?\nF???c\nF??\np?8\n?H?\n"
]
] |
p00374 | Iron Bars | <H1>Iron Bars</H1>
<p>
A boy PCK had <var>N</var> straight iron bars, which were serially indexed. Unfortunately, the first <var>M</var> bars (0 ≤ <var>M</var> ≤ <var>N</var>) among them were bent during transportation. They all suffered a perpendicular bend at one point.
</p>
<p>
He is planning to make a cube using a set of bars selected using the following rules: <var>X</var> bars from bent ones, <var>Y</var> bars from straight ones, where <var>2X + Y = 12</var>. Any two bars can be jointed only at the apexes of the cube. He wants to count how many types of rectangular parallelepipeds (hereafter RP) he can make using these bars.
</p>
<p>
Make a program to count out types (different shapes) of RPs that PCK can make using the following information: the number of bars and length of each one, position of the bend, and the number of bars to be used to construct an RP. Note that any two RPs similar in shape are considered identical: namely if the length of three defining sides of two RPs coincide if arranged in increasing/decreasing order (e.g., three sides of RP <var>i</var> and <var>j</var> are <var>A_i, B_i, C_i</var>, and <var>A_j, B_j</var> and <var>C_j</var> in increasing order, then the relations <var>A_i = A_j, B_i = B_j</var>, and <var>C_i = C_j</var> hold. Note also that the bars are sufficiently thin to allow you to consider them as idealized lines.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>N</var> <var>M</var> <var>X</var> <var>Y</var>
<var>a_1</var>
<var>a_2</var>
:
<var>a_N</var>
<var>b_1</var>
<var>b_2</var>
:
<var>b_M</var>
</pre>
<p>
The first line provides the total number of iron bars and bent bars, and those straight and bent bars used to construct an RP: <var>N</var> (6 ≤ <var>N</var> ≤ 6000), <var>M</var> (0 ≤ <var>M</var> ≤ <var>N</var>), <var>X</var> (0 ≤ <var>X</var> ≤ 6), and <var>Y</var> (0 ≤ <var>Y</var> ≤ 12). The following relations always hold for them: <var>2X+Y=12</var>, <var>X+Y</var> ≤ <var>N</var>, <var>X</var> ≤ <var>M</var>. Each of the subsequent <var>N</var> lines provides the length of the <var>i</var>-th bar <var>a_i</var> (1 ≤ <var>a_i</var> ≤ 6000) in integers. Furthermore, each of the subsequent <var>M</var> lines provides the location at which the <var>i</var>-th bent bar suffered a perpendicular bend <var>b_i</var> (1 ≤ <var>b_i</var> ≤ 3000) in centimeters from one end of the bar (note: 1 ≤ <var>a_i-b_i</var> ≤ 3000).
</p>
<h2>Output</h2>
<p>
Output the number of constructible rectangular parallelepipeds.
</p>
<h2>Sample Input 1</h2>
<pre>
18 8 3 6
4
3
3
3
3
2
2
2
1
1
1
1
1
2
2
3
3
3
1
1
1
1
1
1
1
1
</pre>
<h2>Sample Output 1</h2>
<pre>
3
</pre>
| [
[
"18 8 3 6\n4\n3\n3\n3\n3\n2\n2\n2\n1\n1\n1\n1\n1\n2\n2\n3\n3\n3\n1\n1\n1\n1\n1\n1\n1\n1\n",
"18 8 3 6\n4\n3\n3\n3\n3\n2\n2\n2\n1\n1\n1\n1\n1\n2\n2\n3\n3\n3\n1\n1\n1\n1\n1\n1\n1\n1\n"
]
] |
p00375 | Celsius and Fahrenheit | <h1>Celsius/Fahrenheit</h1>
ã
<p>
In Japan, temperature is usually expressed using the Celsius (℃) scale. In America, they used the Fahrenheit (℉) scale instead. $20$ degrees Celsius is roughly equal to $68$ degrees Fahrenheit. A phrase such as "Todayâs temperature is $68$ degrees" is commonly encountered while you are in America.
</p>
<p>
A value in Fahrenheit can be converted to Celsius by first subtracting $32$ and then multiplying by $\frac{5}{9}$. A simplified method may be used to produce a rough estimate: first subtract $30$ and then divide by $2$. Using the latter method, $68$ Fahrenheit is converted to $19$ Centigrade, i.e., $\frac{(68-30)}{2}$.
</p>
<p>
Make a program to convert Fahrenheit to Celsius using the simplified method: $C = \frac{F - 30}{2}$.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$F$
</pre>
<p>
The input line provides a temperature in Fahrenheit $F$ ($30 \leq F \leq 100$), which is an integer divisible by $2$.
</p>
<h2>Output</h2>
<p>
Output the converted Celsius temperature in a line.
</p>
<h2>Sample Input 1</h2>
<pre>
68
</pre>
<h2>Sample Output 1</h2>
<pre>
19
</pre>
<h2>Sample Input 2</h2>
<pre>
50
</pre>
<h2>Sample Output 2</h2>
<pre>
10
</pre>
| [
[
"68\n",
"68\n"
]
] |
p00376 | Red Dragonfly | <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>
| [
[
"20 30\n",
"20 30\n"
]
] |
p00377 | Cake Party | <h1>Cake Party</h1>
<p>ã
Iâm planning to have a party on my birthday. Many of my friends will come to the party. Some of them will come with one or more pieces of cakes, but it is not certain if the number of the cakes is a multiple of the number of people coming.
</p>
<p>
I wish to enjoy the cakes equally among the partiers. So, I decided to apply the following rules. First, all the party attendants are given the same number of cakes. If some remainder occurs, a piece goes on a priority basis to the party host (thatâs me!). How many pieces of cake can I enjoy?
</p>
<p>
Given the number of my friends and cake information, make a program to calculate how many pieces of cake I can enjoy. Note that I am not counted in the number of my friends.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$N$ $C$
$p_1$ $p_2$ ... $p_C$
</pre>
<p>
The first line provides the number of my friends $N$ ($1 \leq N \leq 100$) and the number of those among them who brought one or more pieces of cake with them $C$ ($1 \leq C \leq N$). The second line provides an array of integers $p_i$ ($1 \leq p_i \leq100$), each of which shows the number of cakes of the $i$-th friend of mine who was willing to come up with one or more pieces of cake.
</p>
<h2>Output</h2>
<p>
Output the number of cakes I can enjoy.
</p>
<h2>Sample Input 1</h2>
<pre>
5 4
5 5 6 5
</pre>
<h2>Sample Output 1</h2>
<pre>
4
</pre>
<h2>Sample Input 2</h2>
<pre>
7 5
8 8 8 8 8
</pre>
<h2>Sample Output 2</h2>
<pre>
5
</pre>
<h2>Sample Input 3</h2>
<pre>
100 3
3 3 3
</pre>
<h2>Sample Output 3</h2>
<pre>
1
</pre>
| [
[
"5 4\n5 5 6 5\n",
"5 4\n5 5 6 5\n"
]
] |
p00378 | Heat Strokes | <h1>Heat Stroke</h1>
<p>ã
We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than that if: no combination of these bottles meets the quantity, or, the total price becomes lower.
</p>
<p>
Given the prices for each bottle of water and the total quantity needed, make a program to seek the lowest price to buy greater than or equal to the quantity required.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$A$ $B$ $X$
</pre>
<p>
The first line provides the prices for a 1-liter bottle $A$ ($1\leq A \leq 1000$), 500-milliliter bottle $B$ ($1 \leq B \leq 1000$), and the total water quantity needed $X$ ($1 \leq X \leq 20000$). All these values are given as integers, and the quantity of water in milliliters.
</p>
<h2>Output</h2>
<p>
Output the total price.
</p>
<h2>Sample Input 1</h2>
<pre>
180 100 2400
</pre>
<h2>Sample Output 1</h2>
<pre>
460
</pre>
<h2>Sample Input 2</h2>
<pre>
200 90 2018
</pre>
<h2>Sample Output 2</h2>
<pre>
450
</pre>
| [
[
"180 100 2400\n",
"180 100 2400\n"
]
] |
p00379 | Dudeney Number | <h1>Dudeney Number</h1>
ã
<p>
A Dudeney number is a positive integer for which the sum of its decimal digits is equal to the cube root of the number. For example, $512$ is a Dudeney number because it is the cube of $8$, which is the sum of its decimal digits ($5 + 1 + 2$).
</p>
<p>
In this problem, we think of a type similar to Dudeney numbers and try to enumerate them.
</p>
<p>
Given a non-negative integer $a$, an integer $n$ greater than or equal to 2 and an upper limit $m$, make a program to enumerate all $x$âs such that the sum of its decimal digits $y$ satisfies the relation $x = (y + a)^n$, and $x \leq m$.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$a$ $n$ $m$
</pre>
<p>
The input line provides three integers: $a$ ($0 \leq a \leq 50$), $n$ ($2 \leq n \leq 10$) and the upper limit $m$ ($1000 \leq m \leq 10^8$).
</p>
<h2>Output</h2>
<p>
Output the number of integers that meet the above criteria.
</p>
<h2>Sample Input 1</h2>
<pre>
16 2 1000
</pre>
<h2>Sample Output 1<h2>
<pre>
2
</pre>
<p>
Two: $400 = (4 + 0 + 0 + 16)^2$ and $841 = (8 + 4 + 1 + 16)^2$
</p>
<h2>Sample Input 2</h2>
<pre>
0 3 5000
</pre>
<h2>Sample Output 2</h2>
<pre>
3
</pre>
<p>
Three: $1=1^3$, $512 = (5 + 1 + 2)^3$ and $4913 = (4 + 9 + 1 + 3)^3$.
</p>
<h2>Sample Input 3</h2>
<pre>
2 3 100000
</pre>
<h2>Sample Output 3</h2>
<pre>
0
</pre>
<p>
There is no such number $x$ in the range below $100,000$ such that its sum of decimal digits $y$ satisfies the relation $(y+2)^3 = x$.
</p>
| [
[
"16 2 1000\n",
"16 2 1000\n"
]
] |
p00380 | Bozo Sort | <h1>Bozosort</h1>
ã
<p>
Bozosort, as well as Bogosort, is a very inefficient sort algorithm. It is a random number-based algorithm that sorts sequence elements following the steps as below:
</p>
<ol>
<li> Randomly select two elements and swap them.</li>
<li> Verify if all the elements are sorted in increasing order.</li>
<li> Finish if sorted, else return to 1.</li>
</ol>
<p>
To analyze Bozosort, you have decided to simulate the process using several predetermined pairs of elements.
</p>
<p>
You are given several commands to swap two elements. Make a program to evaluate how many times you have to run the command before the sequence is aligned in increasing order.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$N$
$a_1$ $a_2$ ... $a_N$
$Q$
$x_1$ $y_1$
$x_2$ $y_2$
$...$
$x_Q$ $y_Q$
</pre>
<p>
The first line provides the number of sequence elements $N$ ($2 \leq N \leq 300,000$). The second line provides an array of integers $a_i$ ($1 \leq a_i \leq 10^9$) that constitutes the sequence. Each of the subsequent $Q$ lines provides a pair of integers $x_i,y_i$ ($1 \leq x_i,y_i \leq N$) that represent the $i$-th command, which swaps the two elements indicated by $x_i$ and $y_i$ ($x_i \ne y_i$).
</p>
<h2>Output</h2>
<p>
If neat alignment in increasing order is realized the first time after execution of multiple commands, output at what time it was. Output <span>0</span> if the initial sequence is aligned in increasing order, and <span>-1</span> if exhaustive execution still failed to attain the goal.
</p>
<h2>Sample Input 1</h2>
<pre>
6
9 7 5 6 3 1
3
1 6
2 5
3 4
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<h2>Sample Input 2</h2>
<pre>
4
4 3 2 1
2
1 2
3 4
</pre>
<h2>Sample Output 2</h2>
<pre>
-1
</pre>
<h2>Sample Input 3</h2>
<pre>
5
1 1 1 2 2
1
1 2
</pre>
<h2>Sample Input 3</h2>
<pre>
0
</pre>
| [
[
"6\n9 7 5 6 3 1\n3\n1 6\n2 5\n3 4\n",
"6\n9 7 5 6 3 1\n3\n1 6\n2 5\n3 4\n"
]
] |
p00381 | Transporter | <h1>Transporter</h1>
<p>
In the year 30XX, an expedition team reached a planet and found a warp machine suggesting the existence of a mysterious supercivilization. When you go through one of its entrance gates, you can instantaneously move to the exit irrespective of how far away it is. You can move even to the end of the universe at will with this technology!
</p>
<p>
The scientist team started examining the machine and successfully identified all the planets on which the entrances to the machine were located. Each of these N planets (identified by an index from $1$ to $N$) has an entrance to, and an exit from the warp machine. Each of the entrances and exits has a letter inscribed on it.
</p>
<p>
The mechanism of spatial mobility through the warp machine is as follows:
</p>
<ul>
<li>If you go into an entrance gate labeled with c, then you can exit from any gate with label c.</li>
<li>If you go into an entrance located on the $i$-th planet, then you can exit from any gate located on the $j$-th planet where $i < j$.</li>
</ul>
<p>
Once you have reached an exit of the warp machine on a planet, you can continue your journey by entering into the warp machine on the same planet. In this way, you can reach a faraway planet. Our human race has decided to dispatch an expedition to the star $N$, starting from Star $1$ and using the warp machine until it reaches Star $N$. To evaluate the possibility of successfully reaching the destination. it is highly desirable for us to know how many different routes are available for the expedition team to track.
</p>
<p>
Given information regarding the stars, make a program to enumerate the passages from Star $1$ to Star $N$.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$N$
$s$
$t$
</pre>
<p>
The first line provides the number of the stars on which the warp machine is located $N$ ($2 \leq N \leq 100,000$). The second line provides a string $s$ of length $N$, each component of which represents the letter inscribed on the entrance of the machine on the star. By the same token, the third line provides a string $t$ of length $N$ consisting of the letters inscribed on the exit of the machine. Two strings $s$ and $t$ consist all of lower-case alphabetical letters, and the $i$-th letter of these strings corresponds respectively to the entrance and exit of Star $i$ machine.
</p>
<h2>Output</h2>
<p>
Divide the number of possible routes from Star $1$ to Star $N$ obtained above by 1,000,000,007, and output the remainder.
</p>
<h2>Sample Input 1</h2>
<pre>
6
abbaba
baabab
</pre>
<h2>Sample Output 1</h2>
<pre>
5
</pre>
<h2>Sample Input 2</h2>
<pre>
25
neihsokcpuziafoytisrevinu
universityofaizupckoshien
</pre>
<h2>Sample Output 2</h2>
<pre>
4
</pre>
| [
[
"6\nabbaba\nbaabab\n",
"6\nabbaba\nbaabab\n"
]
] |
p00382 | Taxi | <h1>Taxi</h1>
ã
<p>
PCK Taxi in Aizu city, owned by PCK company, has adopted a unique billing system: the user can decide the taxi fare. Today as usual, many people are waiting in a queue at the taxi stand in front of the station.
</p>
<p>
In front of the station, there are $N$ parking spaces in row for PCK taxis, each with an index running from $1$ to $N$. Each of the parking areas is occupied by a taxi, and a queue of potential passengers is waiting for the ride. Each one in the queue has his/her own plan for how much to pay for the ride.
</p>
<p>
To increase the companyâs gain, the taxi driver is given the right to select the passenger who offers the highest taxi fare, rejecting others.
</p>
<p>
The driver in the $i$-th parking space can perform the following actions any number of times in any sequence before he finally selects a passenger and starts driving.
</p>
<ol>
<li>Offer a ride to the passenger who is at the head of the $i$-th parking spaceâs queue.</li>
<li>Reject to offer a ride to the passenger who is at the head of the $i$-th parking spaceâs queue. The passenger is removed from the queue.</li>
<li>Move to the $i + 1$-th parking area if it is empty. If he is in the $N$-th parking area, he leaves the taxi stand to cruise the open road.</li>
</ol>
<p>
A preliminary listening is made as to the fare the users offer. Your task is to maximize the sales volume of PCK Taxi in reference to the table of offered fares. A taxi cannot accommodate more than one passenger.
</p>
<p>
Given the number of taxi parking spaces and information regarding the persons waiting in the parking areas, calculate the maximum possible volume of sales.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$N$
$s_1$
$s_2$
$...$
$s_N$
</pre>
<p>
The first line provides the number of taxi parking areas $N$ ($1 \leq N \leq 300,000$). Each of the subsequent $N$ lines provides information on the customers queueing in the $i$-th taxi parking area in the following format:
</p>
<pre>
$M$ $c_1$ $c_2$ ... $c_M$
</pre>
<p>
The first integer $M$ ($1 \leq M \leq 300,000$) indicates the number of customers in the queue, and the subsequent array of integers $c_j$ ($1 \leq c_j \leq 10,000$) indicates the fare the $j$-th customer in the queue is willing to pay. The total number of customers in the taxi stand is equal to or less than $300,000$.
</p>
<h2>Output</h2>
<p>
Output the maximum volume of sales.
</p>
<h2>Sample Input</h2>
<pre>
3
3 8 10 1
4 7 1 2 15
3 11 8 19
</pre>
<h2>Sample Output</h2>
<pre>
45
</pre>
â
| [
[
"3\n3 8 10 1\n4 7 1 2 15\n3 11 8 19\n",
"3\n3 8 10 1\n4 7 1 2 15\n3 11 8 19\n"
]
] |
p00383 | Points on a Straight Line | <h1>Points on a Straight Line</h1>
ã
<p>
The university of A stages a programming contest this year as has been the case in the past. As a member of the team in charge of devising the problems, you have worked out a set of input data for a problem, which is an arrangement of points on a 2D plane in the coordinate system. The problem requires that any combination of these points greater than or equal to $K$ in number must not align on a line. You want to confirm that your data satisfies this requirement.
</p>
<p>
Given the number of points $K$ and their respective 2D coordinates, make a program to check if any combination of points greater or equal to $K$ align on a line.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$N$ $K$
$x_1$ $y_1$
$x_2$ $y_2$
$...$
$x_N$ $y_N$
</pre>
<p>
The first line provides the number of points $N$ ($3 \leq N \leq 3000$) on the 2D coordinate system and an integer $K$ ($3 \leq K \leq N$). Each of the subsequent lines provides the $i$-th coordinate $x_i,y_i$ ($0 \leq x_i,y_i \leq 10000$) as integers. None of these coordinates coincide, i.e., if $i \ne j$, then $x_i \ne x_j$ or $y_i \ne y_j$.
</p>
<h2>Output</h2>
<p>
Output <span>1</span> if any combination of points greater or equal to $K$ aligns on a line, or <span>0</span> otherwise.
</p>
<h2>Sample Input 1</h2>
<pre>
5 4
0 0
1 0
1 1
0 1
2 2
</pre>
<h2>Sample Output 1</h2>
<pre>
0
</pre>
<h2>Sample Input 2</h2>
<pre>
7 5
0 0
1 0
1 1
0 1
2 0
3 0
4 0
</pre>
<h2>Sample Output 2</h2>
<pre>
1
</pre>
| [
[
"5 4\n0 0\n1 0\n1 1\n0 1\n2 2\n",
"5 4\n0 0\n1 0\n1 1\n0 1\n2 2\n"
]
] |
p00384 | Dungeon 2 | <h1>Dungeon 2</h1>
ã
<p>
Bob is playing a game called "Dungeon 2" which is the sequel to the popular "Dungeon" released last year. The game is played on a map consisting of $N$ rooms and $N-1$ roads connecting them. The roads allow bidirectional traffic and the player can start his tour from any room and reach any other room by way of multiple of roads. A point is printed in each of the rooms.
</p>
<p>
Bob tries to accumulate the highest score by visiting the rooms by cleverly routing his character "Tora-Tora." He can add the point printed in a room to his score only when he reaches the room for the first time. He can also add the points on the starting and ending rooms of Tora-Toraâs journey. The score is reduced by one each time Tora-Tore passes a road. Tora-Tora can start from any room and end his journey in any room.
</p>
<p>
Given the map information, make a program to work out the maximum possible score Bob can gain.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$N$
$p_1$
$p_2$
$...$
$p_N$
$s_1$ $t_1$
$s_2$ $t_2$
$...$
$s_{N-1}$ $t_{N-1}$
</pre>
<p>
The first line provides the number of rooms $N$ ($1 \leq N \leq 100,000$). Each of the subsequent $N$ lines provides the point of the $i$-th room $p_i$ ($-100 \leq p_i \leq 100$) in integers. Each of the subsequent lines following these provides the information on the road directly connecting two rooms, where $s_i$ and $t_i$ ($1 \leq s_i < t_i \leq N$) represent the numbers of the two rooms connected by it. Not a single pair of rooms are connected by more than one road.
</p>
<h2>Output</h2>
<p>
Output the maximum possible score Bob can gain.
</p>
<h2>Sample Input 1</h2>
<pre>
7
6
1
-1
4
3
3
1
1 2
2 3
3 4
3 5
5 6
5 7
</pre>
<h2>Sample Output 1</h2>
<pre>
10
</pre>
<p>
For example, the score is maximized by routing the rooms in the following sequence: $6 \rightarrow 5 \rightarrow 3 \rightarrow 4 \rightarrow 3 \rightarrow 2 \rightarrow 1$.
</p>
<h2>Sample Input 2</h2>
<pre>
4
5
0
1
1
1 2
2 3
2 4
</pre>
<h2>Sample Output 2</h2>
<pre>
5
</pre>
<p>
The score is maximized if Tora-Tora stats his journey from room 1 and ends in the same room.
</p>
â
| [
[
"7\n6\n1\n-1\n4\n3\n3\n1\n1 2\n2 3\n3 4\n3 5\n5 6\n5 7\n",
"7\n6\n1\n-1\n4\n3\n3\n1\n1 2\n2 3\n3 4\n3 5\n5 6\n5 7\n"
]
] |
p00385 | Disk | <h1>Disc</h1>
ã<p>
A mysterious device was discovered in an ancient ruin. The device consists of a disc with integers inscribed on both sides, a bundle of cards with an integer written on each of them and a pedestal within which the cards are placed. The disc rotates when the bundle of cards is put into the pedestal. Only one side of the disc is exposed to view at any one time.
</p>
<p>
The disc is radially segmented in equal angles into $K$ sections, and an integer, from $1$ to $K$ in increasing order, is inscribed clockwise on each section on the front side. The sections on the back side share the same boundaries with the front side, and a negative counterpart of that in the section on the front side is inscribed, i.e., if $X$ is inscribed in the front side section, $-X$ is inscribed on the counterpart section on the back side. There is a needle on the periphery of the disc, and it always points to the middle point of the arc that belongs to a section. Hereafter, we say "the disc is set to $X$" if the front side section just below the needle contains an integer $X$.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/PCK2018_disk1" width="480"><br>
Fig.1 Disc with 5 sections (i.e., $K = 5$): When the disc is set to $1$ on the front side, it is set to $-1$ on the back side.
</center>
<p>
Investigation of the behavior of the device revealed the following:
</p>
<p>
When the bundle of cards is placed in the pedestal, the device sets the disc to 1.<br>
Then, the device reads the cards slice by slice from top downward and performs one of the following actions according to the integer $A$ on the card
</p>
<ul>
<li>If $A$ is a positive number, it rotates the disc clockwise by $|A|$ sections.</li>
<li>If $A$ is zero, it turns the disc back around the vertical line defined by the needle and the center of the disc.</li>
<li>If $A$ is a negative number, it rotates the disc counterclockwise by $|A|$ sections.</li>
</ul>
<p>
It is provided that $|A|$ is the absolute value of $A$. The final state of the device (i.e., to what section the needle is pointing) varies depending on the initial stacking sequence of the cards. To further investigate the behavior of the device, we swapped two arbitrary cards in the stack and placed the bundle in the pedestal to check what number the disc is set to. We performed this procedure over again and again.
</p>
<p>
Given the information on the device and several commands to swap two cards, make a program to determine the number to which the device is set at the completion of all actions. Note that the stacking sequence of the cards continues to change as a new trial is made.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$K$ $N$ $Q$
$A_1$ $A_2$ ... $A_N$
$L_1$ $R_1$
$L_2$ $R_2$
$...$
$L_Q$ $R_Q$
</pre>
<p>
The first line provides the number of sections $K$ ($2 \leq K \leq 10^9$), the slices of cards $N$ ($2 \leq N \leq 100,000$), and the number of commands $Q$ ($1 \leq Q \leq 100,000$). The second line provides an array of $N$ integers inscribed on the sections of the disc. $A_i$ ($-10^9 \leq A_i \leq 10^9$) represents the number written on the $i$-th card from the top. Each of the subsequent $Q$ lines defines the $i$-th command $L_i,R_i$ ($1 \leq L_ i < R_i \leq N$) indicating a swapping of $L_i$-th and $R_i$-th cards from the top followed by placing the card bundle in the device. </p>
<h2>Output</h2>
<p>
For each command, output a line containing the number to which the device is set at the completion of all actions.
â</p>
<h2>Sample Input 1</h2>
<pre>
5 3 1
1 -2 0
2 3
</pre>
<h2>Sample Output 1</h2>
<pre>
-3
</pre>
<p>
The device moves as follows while it is performing the first command.
</p>
<pre>
1 0 -2
</pre>
<p>
When the first command is performed, the stacking sequence of the card bundle, from top to bottom, changes to the sequence shown below.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/PCK2018_disk2" width="480"><br>
Fig.2 An illustrative example of how the device works
</center>
<p>
Therefore, the device is set to -3 after all actions have completed. Output this value.
</p>
<h2>Sample Input 2</h2>
<pre>
5 7 5
0 0 3 3 3 3 3
1 2
2 3
3 4
4 5
5 6
</pre>
<h2>Sample Output 2</h2>
<pre>
1
2
3
4
5
</pre>
| [
[
"5 3 1\n1 -2 0\n2 3\n",
"5 3 1\n1 -2 0\n2 3\n"
]
] |
p00386 | Gathering | <h1>Meeting in a City</h1>
ã<p>
You are a teacher at Iazu High School is the Zuia Kingdom. There are $N$ cities and $N-1$ roads connecting them that allow you to move from one city to another by way of more than one road. Each of the roads allows bidirectional traffic and has a known length.
</p>
<p>
As a part of class activities, you are planning the following action assignment for your students. First, you come up with several themes commonly applicable to three different cities. Second, you assign each of the themes to a group of three students. Then, each student of a group is assigned to one of the three cities and conducts a survey on it. Finally, all students of the group get together in one of the $N$ cities and compile their results.
</p>
<p>
After a theme group has completed its survey, the three members move from the city on which they studied to the city for getting together. The longest distance they have to travel for getting together is defined as the cost of the theme. You want to select the meeting city so that the cost for each theme becomes minimum.
</p>
<p>
Given the number of cities, road information and $Q$ sets of three cities for each theme, make a program to work out the minimum cost for each theme.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$N$ $Q$
$u_1$ $v_1$ $w_1$
$u_2$ $v_2$ $w_2$
$...$
$u_{N-1}$ $v_{N-1}$ $w_{N-1}$
$a_1$ $b_1$ $c_1$
$a_2$ $b_2$ $c_2$
$...$
$a_Q$ $b_Q$ $c_Q$
</pre>
<p>
The first line provides the number of cities in the Zuia Kingdom $N$ ($3 \leq N \leq 100,000$) and the number of themes $Q$ ($1 \leq Q \leq 100,000$). Each of the subsequent $N-1$ lines provides the information regarding the $i$-th road $u_i,v_i,w_i$ ($ 1 \leq u_i < v_i \leq N, 1 \leq w_i \leq 10,000$), indicating that the road connects cities $u_i$ and $v_i$, and the road distance between the two is $w_i$. Each of the $Q$ lines that follows the above provides the three cities assigned to the $i$-th theme: $a_i,b_i,c_i$ ($1 \leq a_i < b_i < c_i \leq N$).
</p>
<h2>Output</h2>
<p>
For each theme, output the cost in one line.
â</p>
<h2>Sample Input 1</h2>
<pre>
5 4
1 2 3
2 3 4
2 4 2
4 5 3
1 3 4
1 4 5
1 2 3
2 4 5
</pre>
<h2>Sample Output 1</h2>
<pre>
4
5
4
3
</pre>
<p>
In the first theme, traveling distance from City 3 (the student conducts survey) to City 2 (meeting venue) determines the cost 4. As no other meeting city can provide smaller cost, you should output 4. In the second theme, you can minimize the cost down to 5 by selecting City 2 or City 4 as the meeting venue.
</p>
<h2>Sample Input 2</h2>
<pre>
5 3
1 2 1
2 3 1
3 4 1
4 5 1
1 2 3
1 3 5
1 2 4
</pre>
<h2>Sample Output 2</h2>
<pre>
1
2
2
</pre>
<h2>Sample Input 3</h2>
<pre>
15 15
1 2 45
2 3 81
1 4 29
1 5 2
5 6 25
4 7 84
7 8 56
4 9 2
4 10 37
7 11 39
1 12 11
11 13 6
3 14 68
2 15 16
10 13 14
13 14 15
2 14 15
7 12 15
10 14 15
9 10 15
9 14 15
8 13 15
5 6 13
11 13 15
12 13 14
2 3 10
5 13 15
10 11 14
6 8 11
</pre>
<h2>Sample Output 3</h2>
<pre>
194
194
97
90
149
66
149
140
129
129
194
111
129
194
140
</pre>
| [
[
"5 4\n1 2 3\n2 3 4\n2 4 2\n4 5 3\n1 3 4\n1 4 5\n1 2 3\n2 4 5\n",
"5 4\n1 2 3\n2 3 4\n2 4 2\n4 5 3\n1 3 4\n1 4 5\n1 2 3\n2 4 5\n"
]
] |
p00387 | Party Dress | <h1>Party Dress</h1>
<p>
Yae joins a journey plan, in which parties will be held several times during the itinerary. She wants to participate in all of them and will carry several dresses with her. But the number of dresses she can carry with her may be smaller than that of the party opportunities. In that case, she has to wear some of her dresses more than once.
</p>
<p>
Fashion-conscious Yae wants to avoid that. At least, she wants to reduce the maximum number of times she has to wear the same dress as far as possible.
</p>
<p>
Given the number of dresses and frequency of parties, make a program to determine how she can reduce the maximum frequency of wearing the most reused dress.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$A$ $B$
</pre>
<p>
The input line provides the number of dresses $A$ ($1 \leq A \leq 10^5$) and frequency of parties $B$ ($1 \leq B \leq 10^5$).
</p>
<h2>Output</h2>
<p>
Output the frequency she has to wear the most reused dress.
</p>
<h2>Sample Input 1</h2>
<pre>
3 5
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<h2>Sample Input 2</h2>
<pre>
25 10
</pre>
<h2>Sample Output 2</h2>
<pre>
1
</pre>
| [
[
"3 5\n",
"3 5\n"
]
] |
p00388 | Design of a Mansion | <h1>Design of a Mansion</h1>
<p>
Our master carpenter is designing a condominium called Bange Hills Mansion. The condominium is constructed by stacking up floors of the same height. The height of each floor is designed so that the total height of the stacked floors coincides with the predetermined height of the condominium. The height of each floor can be adjusted freely with a certain range.
</p>
<p>
The final outcome of the building depends on clever height allotment for each floor. So, he plans to calculate possible combinations of per-floor heights to check how many options he has.
</p>
<p>
Given the height of the condominium and the adjustable range of each floorâs height, make a program to enumerate the number of choices for a floor.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$H$ $A$ $B$
</pre>
<p>
The input line provides the height of the condominium $H$ ($1 \leq H \leq 10^5$) and the upper and lower limits $A$ and $B$ of the height adjustable range for one floor ($1 \leq A \leq B \leq H$). All data are given as integers.
</p>
<h2>Output</h2>
<p>
Output the number of possible height selections for each floor in a line.
</p>
<h2>Sample Input 1</h2>
<pre>
100 2 4
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<h2>Sample Input 2</h2>
<pre>
101 3 5
</pre>
<h2>Sample Output 2</h2>
<pre>
0
</pre>
| [
[
"100 2 4\n",
"100 2 4\n"
]
] |
p00389 | Pilling Blocks | <h1>Pilling Blocks</h1>
<p>
We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
</p>
<p>
We have to build the tower abiding by the following conditions:
</p>
<ul>
<li>Every stage of the tower has one or more blocks on it.</li>
<li>Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.</li>
</ul>
<p>
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$N$ $K$
</pre>
<p>
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
</p>
<h2>Output</h2>
<p>
Output the maximum possible number of stages.
</p>
<h2>Sample Input 1</h2>
<pre>
4 2
</pre>
<h2>Sample Output 1</h2>
<pre>
3
</pre>
<h2>Sample Input 2</h2>
<pre>
5 2
</pre>
<h2>Sample Output 2</h2>
<pre>
4
</pre>
| [
[
"4 2\n",
"4 2\n"
]
] |
p00390 | A Round Table for Sages | <h1>Round Table of Sages</h1>
<p>
$N$ sages are sitting around a round table with $N$ seats. Each sage holds chopsticks with his dominant hand to eat his dinner. The following happens in this situation.
</p>
<ul>
<li>If sage $i$ is right-handed and a left-handed sage sits on his right, a level of frustration $w_i$ occurs to him. A right-handed sage on his right does not cause such frustration at all.</li>
<li>If sage $i$ is left-handed and a right-handed sage sits on his left, a level of frustration $w_i$ occurs to him. A left-handed sage on his left does not cause such frustration at all.</li>
</ul>
<p>
You wish you could minimize the total amount of frustration by clever sitting order arrangement.
</p>
<p>
Given the number of sages with his dominant hand information, make a program to evaluate the minimum frustration achievable.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$N$
$a_1$ $a_2$ $...$ $a_N$
$w_1$ $w_2$ $...$ $w_N$
</pre>
<p>
The first line provides the number of sages $N$ ($3 \leq N \leq 10$). The second line provides an array of integers $a_i$ (0 or 1) which indicate if the $i$-th sage is right-handed (0) or left-handed (1). The third line provides an array of integers $w_i$ ($1 \leq w_i \leq 1000$) which indicate the level of frustration the $i$-th sage bears.
</p>
<h2>Output</h2>
<p>
Output the minimum total frustration the sages bear.
</p>
<h2>Sample Input 1</h2>
<pre>
5
1 0 0 1 0
2 3 5 1 2
</pre>
<h2>Sample Output 1</h2>
<pre>
3
</pre>
<h2>Sample Input 2</h2>
<pre>
3
0 0 0
1 2 3
</pre>
<h2>Sample Output 2</h2>
<pre>
0
</pre>
| [
[
"5\n1 0 0 1 0\n2 3 5 1 2\n",
"5\n1 0 0 1 0\n2 3 5 1 2\n"
]
] |
p00391 | Treasure Map | <h1>Treasure Map</h1>
<p>
Mr. Kobou found a bundle of old paper when he was cleaning his family home. On each paper, two series of numbers are written. Strange as it appeared to him, Mr. Kobou further went through the storehouse and found out a note his ancestor left. According to it, the bundle of paper is a treasure map, in which the two sequences of numbers seem to give a clue to the whereabouts of the treasure the ancestor buried.
</p>
<p>
Mr. Kobouâs ancestor divided the area where he buried his treasure in a reticular pattern and used only some of the grid sections. The two series of numbers indicate the locations: the $i$-th member of the first series indicates the number of locations in the $i$-th column (form left) of the grid sections where a part of the treasure is buried, and the $j$-th member of the second indicates the same information regarding the $j$-th row from the top. No more than one piece of treasure is buried in one grid section. An example of a 5 × 4 case is shown below. If the pieces of treasure are buried in the grid sections noted as "<span>#</span>" the two series of numbers become "0,2,2,1,1" and "1,1,1,3".
</p>
<center>
<table border="1" style="border-collapse: collapse" cellpadding="8">
<tr>
<td> </td><td>0</td><td>2</td><td>2</td><td>1</td><td>1</td>
</tr>
<tr>
<td>1</td><td> </td><td> </td><td>#</td><td> </td><td> </td>
</tr>
<tr>
<td>1</td><td> </td><td>#</td><td> </td><td> </td><td> </td>
</tr>
<tr>
<td>1</td><td> </td><td> </td><td> </td><td> </td><td>#</td>
</tr>
<tr>
<td>3</td><td> </td><td>#</td><td>#</td><td>#</td><td> </td>
</tr>
</table>
</center>
<br/>
<p>
Mr. Kobouâs ancestor seems to be a very careful person. He slipped some pieces of paper with completely irrelevant information into the bundle. For example, a set of number series "3,2,3,0,0" and "4,2,0,0,2" does not match any combination of 5 × 5 matrixes. So, Mr. Kobou has first to exclude these pieces of garbage information.
</p>
<p>
Given the set of information written on the pieces of paper, make a program to judge if the information is relevant.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$W$ $H$
$a_1$ $a_2$ $...$ $a_W$
$b_1$ $b_2$ $...$ $b_H$
</pre>
<p>
The first line provides the number of horizontal partitions $W$ ($1 \leq W \leq 1000$) and vertical partitions $H$ ($1 \leq H \leq 1000$). The second line provides the $i$-th member of the first number series $a_i$ ($0 \leq a_i \leq H$) written on the paper, and the third line the $j$-th member of the second series $b_j$ ($0 \leq b_j \leq W$).
</p>
<h2>Output</h2>
<p>
Output "<span>1</span>" if the information written on the paper is relevant, or "<span>0</span>" otherwise.
</p>
<h2>Sample Input 1 </h2>
<pre>
5 4
0 2 2 1 1
1 1 1 3
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<h2>Sample Input 2</h2>
<pre>
5 5
3 2 3 0 0
4 2 0 0 2
</pre>
<h2>Sample Output 2</h2>
<pre>
0
</pre>
| [
[
"5 4\n0 2 2 1 1\n1 1 1 3\n",
"5 4\n0 2 2 1 1\n1 1 1 3\n"
]
] |
p00392 | Common-Prime Sort | <h1>Common-Prime Sort</h1>
<p>
You are now examining a unique method to sort a sequence of numbers in increasing order. The method only allows swapping of two numbers that have a common prime factor. For example, a sequence [6, 4, 2, 3, 7] can be sorted using the following steps.
<br/>
<span>Step 0: 6 4 2 3 7</span> (given sequence)<br/>
<span>Step 1: 2 4 6 3 7</span> (elements 6 and 2 swapped)<br/>
<span>Step 2: 2 6 4 3 7</span> (elements 4 and 6 swapped)<br/>
<span>Step 3: 2 3 4 6 7</span> (elements 6 and 3 swapped)<br/>
</p>
<p>
Depending on the nature of the sequence, however, this approach may fail to complete the sorting. You have given a name "Coprime sort" to this approach and are now examining if a given sequence is coprime-sortable.
</p>
<p>
Make a program to determine if a given sequence can be sorted in increasing order by iterating an arbitrary number of swapping operations of two elements that have a common prime number.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$N$
$a_1$ $a_2$ $...$ $a_N$
</pre>
<p>
The first line provides the number of elements included in the sequence $N$ ($2 \leq N \leq 10^5$). The second line provides an array of integers $a_i$ ($2 \leq a_i \leq 10^5$) that constitute the sequence.
</p>
<h2>Output</h2>
<p>
Output "<span>1</span>" if the sequence is coprime-sortable in increasing order, or "<span>0</span>" otherwise.
</p>
<h2>Sample Input 1</h2>
<pre>
5
6 4 2 3 7
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<h2>Sample Input 2</h2>
<pre>
7
2 9 6 5 6 7 3
</pre>
<h2>Sample Output 2</h2>
<pre>
0
</pre>
| [
[
"5\n6 4 2 3 7\n",
"5\n6 4 2 3 7\n"
]
] |
p00393 | Beautiful Sequence | <h1>Beautiful Sequence</h1>
<p>
Alice is spending his time on an independent study to apply to the Nationwide Mathematics Contest. This yearâs theme is "Beautiful Sequence." As Alice is interested in the working of computers, she wants to create a beautiful sequence using only 0 and 1. She defines a "Beautiful" sequence of length $N$ that consists only of 0 and 1 if it includes $M$ successive array of 1s as its sub-sequence.
</p>
<p>
Using his skills in programming, Alice decided to calculate how many "Beautiful sequences" she can generate and compile a report on it.
</p>
<p>
Make a program to evaluate the possible number of "Beautiful sequences" given the sequence length $N$ and sub-sequence length $M$ that consists solely of 1. As the answer can be extremely large, divide it by $1,000,000,007 (= 10^9 + 7)$ and output the remainder.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$N$ $M$
</pre>
<p>
The input line provides the length of sequence $N$ ($1 \leq N \leq 10^5$) and the length $M$ ($1 \leq M \leq N$) of the array that solely consists of 1s.
</p>
<h2>Output</h2>
<p>
Output the number of Beautiful sequences in a line.
</p>
<h2>Sample Input 1</h2>
<pre>
4 3
</pre>
<h2>Sample Output 1</h2>
<pre>
3
</pre>
<p>
The sequences with length 4 that include 1s in successive array of length 3 are: 0111, 1110 and 1111.
</p>
<h2>Sample Input 2</h2>
<pre>
4 2
</pre>
<h2>Sample Output 2</h2>
<pre>
8
</pre>
<p>
The sequences with length 4 that include 1s in successive array of length 2 are: 0011, 0110, 0111, 1011, 1100, 1101, 1110 and 1111.
</p>
| [
[
"4 3\n",
"4 3\n"
]
] |
p00394 | Payroll | <!--<h1> Salary Calculation</h1>-->
<h1>Payroll</h1>
<p>
PCK company has $N$ salaried staff and they have specific ID numbers that run from $0$ to $N-1$. The company provides $N$ types of work that are also identified by ID numbers from $0$ to $N-1$. The time required to complete work $j$ is $t_j$.
</p>
<p>
To get each of the working staff to learn as many types of work as possible, the company shifts work assignment in the following fashion.
</p>
<ul>
<li>
On the $d$-th day of a shift (the first day is counted as $0$th day), work $j$ is assigned to the staff $(j + d) \% N$, where the notation $p \% q$ indicates the remainder when $p$ is divided by $q$.
</li>
</ul>
<p>
Salaries in the PCK company are paid on a daily basis based on the hourly rate. When a staff whose hourly rate is $a$ carries out work $j$, his/her salary will amount to $a \times t_j$. The initial hourly rate for a staff $i$ is $s_i$ yen. To boost staffâs motivation, the company employs a unique scheme for raising hourly rates. The promotion scheme table of the company contains a list of factors $f_k$ ($0 \leq k \leq M-1$), and the hourly rate of a staff is raised based on the following rule.
</p>
<ul>
<li>
At the completion of the $d$-th dayâs work (the first day is counted as the $0$th day), the hourly rate of the staff with ID number $d \% N$ is raised by $f_{(d \% M)}$ yen. The salary raise takes effect after the dayâs pay has been made.
</li>
</ul>
<p>
As the person in charge of accounting in PCK company, you have to calculate the total amount of pay for $D$ days from the $0$-th day.
</p>
<p>
Make a program to work out the total amount of salary given the following information: initial hourly rate of each staff, hours required to complete a job, a table of promotion coefficients, and the number of days. Because the total may become excessively large, report the remainder when the total salary amount is divided by $1,000,000,007(= 10^9 + 7)$.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$N$ $M$ $D$
$s_0$ $s_1$ $...$ $s_{N-1}$
$t_0$ $t_1$ $...$ $t_{N-1}$
$f_0$ $f_1$ $...$ $f_{M-1}$
</pre>
<p>
The first line provides the number of working staff and types of work $N$ ($1 \leq N \leq 100$), the number of factors $M$ ($1 \leq M \leq 100$)and the number of days $D$ ($1 \leq D \leq 10^{15}$). Note that $M + N$ is equal to or less than 100. The second line provides the initial hourly rate for each staff $s_i$ ($1 \leq s_i \leq 10^8$) as integers. The third line provides the hours $t_j$ ($1 \leq t_j \leq 10^8$) required to complete each type of job as integers. The fourth line lists the factors $f_k$ ($1 \leq f_k \leq 10^8$) in the promotion scheme table.
</p>
<h2>Output</h2>
<p>
Output the total amount of the salary.
</p>
<h2>Sample Input 1</h2>
<pre>
3 2 2
3 2 1
1 2 3
1 2
</pre>
<h2>Sample Output 1</h2>
<pre>
26
</pre>
<h2>Sample Input 2</h2>
<pre>
3 2 5
3 2 1
1 2 3
1 2
</pre>
<h2>Sample Output 2</h2>
<pre>
91
</pre>
| [
[
"3 2 2\n3 2 1\n1 2 3\n1 2\n",
"3 2 2\n3 2 1\n1 2 3\n1 2\n"
]
] |
p00395 | Maze and Items | <h1> Maze & Items</h1>
<p>
Maze & Items is a puzzle game in which the player tries to reach the goal while collecting items. The maze consists of $W \times H$ grids, and some of them are inaccessible to the player depending on the items he/she has now. The score the player earns is defined according to the order of collecting items. The objective of the game is, after starting from a defined point, to collect all the items using the least number of moves before reaching the goal. There may be multiple routes that allow the least number of moves. In that case, the player seeks to maximize his/her score.
</p>
<p>
One of the following symbols is assigned to each of the grids. You can move to one of the neighboring grids (horizontally or vertically, but not diagonally) in one time, but you cannot move to the area outside the maze.
</p>
<table border="1" style="border-collapse: collapse" cellpadding="8">
<tr><th>Symbol</th><th>Description</th></tr>
<tr>
<td><span>.</span></td><td>Always accessible</td>
</tr>
<tr>
<td><span>#</span></td><td>Always inaccessible</td>
</tr>
<tr>
<td>Number <span>0</span>, <span>1</span>,.., <span>9</span></td><td>Always accessible and an item (with its specific number) is located in the grid.</td>
</tr>
<tr>
<td>Capital letter <span>A</span>, <span>B</span>, ..., <span>J</span></td><td>Accessible only when the player does NOT have the corresponding item. Each of <span>A</span>, <span>B</span>, ..., <span>J</span> takes a value from <span>0</span> to <span>9</span>.</td>
</tr>
<tr>
<td>Small letter <span>a</span>, <span>b</span>, ..., <span>j</span></td><td> Accessible only when the player DOES have the corresponding item. Each of <span>a</span>, <span>b</span>, ..., <span>j</span> takes one value from <span>0</span> to <span>9</span>.</td>
<tr>
<td><span>S</span></td><td>Starting grid. Always accessible.</td>
</tr>
<tr>
<td><span>T</span></td><td>Goal grid. Always accessible.</td>
</tr>
</table>
<br/>
<p>
The player fails to complete the game if he/she has not collected all the items before reaching the goal. When entering a grid in which an item is located, itâs the playerâs option to collect it or not. The player must keep the item once he/she collects it, and it disappears from the maze.
</p>
<p>
Given the state information of the maze and a table that defines the collecting order dependent scores, make a program that works out the minimum number of moves required to collect all the items before reaching the goal, and the maximum score gained through performing the moves.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$W$ $H$
$row_1$
$row_2$
...
$row_H$
$s_{00}$ $s_{01}$ ... $s_{09}$
$s_{10}$ $s_{11}$ ... $s_{19}$
...
$s_{90}$ $s_{91}$ ... $s_{99}$
</pre>
<p>
The first line provides the number of horizontal and vertical grids in the maze $W$ ($4 \leq W \leq 1000$) and $H$ ($4 \leq H \leq 1000$). Each of the subsequent $H$ lines provides the information on the grid $row_i$ in the $i$-th row from the top of the maze, where $row_i$ is a string of length $W$ defined in the table above. A letter represents a grid. Each of the subsequent 10 lines provides the table that defines collecting order dependent scores. An element in the table $s_{ij}$ ($0 \leq s_{ij} \leq 100$) is an integer that defines the score when item $j$ is collected after the item $i$ (without any item between them). Note that $s_{ii} = 0$.
</p>
<p>
The grid information satisfies the following conditions:
</p>
<ul>
<li>Each of <span>S</span>, <span>T</span>, <span>0</span>, <span>1</span>, ..., <span>9</span> appears in the maze once and only once.</li>
<li>Each of <span>A</span>, <span>B</span>, ..., <span>J</span>, <span>a</span>, <span>b</span>, ..., <span>j</span> appears in the maze no more than once.</li>
</ul>
<h2>Output</h2>
<p>
Output two items in a line separated by a space: the minimum number of moves and the maximum score associated with that sequence of moves. Output "<span>-1</span>" if unable to attain the gameâs objective.
</p>
<h2>Sample Input 1</h2>
<pre>
12 5
.....S......
.abcdefghij.
.0123456789.
.ABCDEFGHIJ.
.....T......
0 1 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
</pre>
<h2>Sample Output 1</h2>
<pre>
26 2
</pre>
<h2>Sample Input 2</h2>
<pre>
4 5
0jSB
###.
1234
5678
9..T
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
</pre>
<h2>Sample Output 2</h2>
<pre>
31 0
</pre>
<h2>Sample Input 3</h2>
<pre>
7 7
1.3#8.0
#.###.#
#.###.#
5..S..9
#.#T#.#
#.###.#
4.2#6.7
0 0 0 0 0 0 0 0 1 0
0 0 0 1 0 0 0 0 0 0
0 0 0 0 7 0 0 0 0 0
0 2 0 0 0 0 0 0 0 0
0 0 3 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 8 0 0 0
2 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
</pre>
<h2>Sample Output 3</h2>
<pre>
53 19
</pre>
<h2>Sample Input 4</h2>
<pre>
5 6
..S..
#####
01234
56789
#####
..T..
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
</pre>
<h2>Sample Output 4</h2>
<pre>
-1
</pre>
| [
[
"12 5\n.....S......\n.abcdefghij.\n.0123456789.\n.ABCDEFGHIJ.\n.....T......\n0 1 0 0 0 0 0 0 0 0\n2 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n",
"12 5\n.....S......\n.abcdefghij.\n.0123456789.\n.ABCDEFGHIJ.\n.....T......\n0 1 0 0 0 0 0 0 0 0\n2 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n"
]
] |
p00396 | Playing With Stones | <h2>Playing with Stones</h2>
<p>
Koshiro and Ukiko are playing a game with black and white stones. The rules of the game are as follows:
</p>
<ol>
<li>
Before starting the game, they define some small areas and place "one or more black stones and one or more white stones" in each of the areas.
</li>
<li>
Koshiro and Ukiko alternately select an area and perform one of the following operations.<br>
(a) Remove a white stone from the area<br>
(b) Remove one or more black stones from the area. Note, however, that the number of the black stones must be less than or equal to white ones in the area.<br>
(c) Pick up a white stone from the stone pod and replace it with a black stone. There are plenty of white stones in the pod so that there will be no shortage during the game.<br>
</li>
<li>If either Koshiro or Ukiko cannot perform 2 anymore, he/she loses.</li>
</ol>
<p>
They played the game several times, with Koshiroâs first move and Ukikoâs second move, and felt the winner was determined at the onset of the game. So, they tried to calculate the winner assuming both players take optimum actions.
</p>
<p>
Given the initial allocation of black and white stones in each area, make a program to determine which will win assuming both players take optimum actions.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$N$
$w_1$ $b_1$
$w_2$ $b_2$
:
$w_N$ $b_N$
</pre>
<p>
The first line provides the number of areas $N$ ($1 \leq N \leq 10000$). Each of the subsequent $N$ lines provides the number of white stones $w_i$ and black stones $b_i$ ($1 \leq w_i, b_i \leq 100$) in the $i$-th area.
</p>
<h2>Output</h2>
<p>
Output <span>0</span> if Koshiro wins and <span>1</span> if Ukiko wins.
</p>
<h2>Sample Input 1</h2>
<pre>
4
24 99
15 68
12 90
95 79
</pre>
<h2>Sample Output 1</h2>
<pre>
0
</pre>
<h2>Sample Input 1</h2>
<pre>
3
2 46
94 8
46 57
</pre>
<h2>Sample Output 2</h2>
<pre>
1
</pre>
| [
[
"4\n24 99\n15 68\n12 90\n95 79\n",
"4\n24 99\n15 68\n12 90\n95 79\n"
]
] |
p00397 | Kth XOR | <h1>K-th Exclusive OR</h1>
<p>
Exclusive OR (XOR) is an operation on two binary numbers $x$ and $y$ (0 or 1) that produces 0 if $x = y$ and $1$ if $x \ne y$. This operation is represented by the symbol $\oplus$. From the definition: $0 \oplus 0 = 0$, $0 \oplus 1 = 1$, $1 \oplus 0 = 1$, $1 \oplus 1 = 0$.
</p>
<p>
Exclusive OR on two non-negative integers comprises the following procedures: binary representation of the two integers are XORed on bit by bit bases, and the resultant bit array constitute a new integer. This operation is also represented by the same symbol $\oplus$. For example, XOR of decimal numbers $3$ and $5$ is equivalent to binary operation $011 \oplus 101$ which results in $110$, or $6$ in decimal format.
</p>
<p>
Bitwise XOR operation on a sequence $Z$ consisting of $M$ non-negative integers $z_1, z_2, . . . , z_M$ is defined as follows:
</p>
<ul>
<li> $v_0 = 0, v_i = v_{i - 1} \oplus z_i$ ($1 \leq i \leq M$)</li>
<li>Bitwise XOR on series $Z$ is defined as $v_M$.</li>
</ul>
<p>
You have a sequence $A$ consisting of $N$ non-negative integers, ample sheets of papers and an empty box. You performed each of the following operations once on every combinations of integers ($L, R$), where $1 \leq L \leq R \leq N$.
</p>
<ol>
<li>Perform the bitwise XOR operation on the sub-sequence (from $L$-th to $R$-th elements) and name the result as $B$.</li>
<li>Select a sheet of paper and write $B$ on it, then put it in the box.</li>
</ol>
<p>
Assume that ample sheets of paper are available to complete the trials. You select a positive integer $K$ and line up the sheets of paper inside the box in decreasing order of the number written on them. What you want to know is the number written on the $K$-th sheet of paper.
</p>
<p>
You are given a series and perform all the operations described above. Then, you line up the sheets of paper in decreasing order of the numbers written on them. Make a program to determine the $K$-th number in the series.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$N$ $K$
$a_1$ $a_2$ ... $a_N$
</pre>
<p>
The first line provides the number of elements in the series $N$ ($1 \leq N \leq 10^5$) and the selected number $K$ ($1 \leq K \leq N(N+1)/2$). The second line provides an array of elements $a_i$ ($0 \leq a_i \leq 10^6$).
</p>
<h2>Sample Input 1 </h2>
<pre>
3 3
1 2 3
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<p>
After all operations have been completed, the numbers written on the paper inside the box are as follows (sorted in decreasing order)
</p>
<ul>
<li>$3,3,2,1,1,0$</li>
</ul>
<p>
3çªç®ã®æ°ã¯2ã§ããããã2ãåºåããã
</p>
<h2>Sample Input 2</h2>
<pre>
7 1
1 0 1 0 1 0 1
</pre>
<h2>Sample Output 2</h2>
<pre>
1
</pre>
<h2>Sample Input 3 </h2>
<pre>
5 10
1 2 4 8 16
</pre>
<h2>Sample Output 3</h2>
<pre>
7
</pre>
| [
[
"3 3\n1 2 3\n",
"3 3\n1 2 3\n"
]
] |
p00398 | Road Construction | <h1>Road Construction</h1>
<p>
The Zuia Kingdom has finally emerged through annexation of $N$ cities, which are identified by index from $1$ to $N$. You are appointed the Minister of Transport of the newly born kingdom to construct the inter-city road network.
</p>
<p>
To simplify the conceptual design planning, you opted to consider each city as a point on the map, so that the $i$-th city can be represented by an coordinate ($x_i, y_i$).
</p>
<p>
The cost of road construction connecting $u$-th and $v$-th cities is equal to the distance $|x_u - x_v|$ or $|y_u - y_v|$, whichever the larger. The notation $|A|$ represents the absolute value of $A$. The object here is to explore the minimum cost required to construct the road network in such a way that people can move between different cities along one or more roads.
</p>
<p>
Make a program to calculate the minimum of total road construction cost from the number of cities and their coordinates.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$N$
$x_1$ $y_1$
$x_2$ $y_2$
...
$x_N$ $y_N$
</pre>
<p>
The first line provides the number of cities $N$ ($2 \leq N \leq 10^5$). Each of the subsequent $N$ lines provides the coordinate of the $i$-th city $x_i, y_i$ ($0 \leq x_i, y_i \leq 10^9$) as integers. Note that none of these coordinates coincides if: $i \ne j$, then $x_i \ne x_j$ or $y_i \ne y_j$.
</p>
<h2>Output</h2>
<p>
Output the minimum road construction cost.
</p>
<h2>Sample Input 1 </h2>
<pre>
3
1 2
3 4
10 1
</pre>
<h2>Sample Output 1</h2>
<pre>
9
</pre>
<p>
The road connecting city 1 and 2 can be constructed at the cost of 2, and that connecting city 2 and 3 at the cost of 7. Therefore, the total cost becomes 9, which is the minimum.
</p>
<h2>Sample Input 2</h2>
<pre>
3
1 2
3 4
3 2
</pre>
<h2>Sample Output 2</h2>
<pre>
4
</pre>
<h2>Sample Input 3</h2>
<pre>
5
7 41
10 0
99 27
71 87
14 25
</pre>
<h2>Sample Output 3</h2>
<pre>
163
</pre>
| [
[
"3\n1 2\n3 4\n10 1\n",
"3\n1 2\n3 4\n10 1\n"
]
] |
p00399 | Shiba Inu | <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>
| [
[
"4 2 1 1\n",
"4 2 1 1\n"
]
] |