Dataset Viewer
Auto-converted to Parquet Duplicate
submission_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
status
stringclasses
1 value
code_size
int64
26
8.99k
cpu_time
float64
0
100
memory
float64
2.57k
99k
code
stringlengths
26
8.99k
input
stringlengths
2
906
output
stringlengths
2
686
problem_description
stringlengths
415
9.48k
s715901262
p02576
Python
Accepted
62
25
9,084
N,X,T = map(int,input().split()) cnt = -(-N//X) print(cnt * T)
20 12 6
12
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi loves takoyaki - a ball-shaped snack.</p> <p>With a takoyaki machine, he can make at most <var>X</var> pieces of takoyaki at a time, taking <var>T</var> minutes regardless of the number of pieces to make.</p> <p>How long does it take to make <var>N</var> takoyaki?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N,X,T \leq 1000</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> <var>T</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print an integer representing the minimum number of minutes needed to make <var>N</var> pieces of takoyaki.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>20 12 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>He can make <var>12</var> pieces of takoyaki in the first <var>6</var> minutes and <var>8</var> more in the next <var>6</var> minutes, so he can make <var>20</var> in a total of <var>12</var> minutes.</p> <p>Note that being able to make <var>12</var> in <var>6</var> minutes does not mean he can make <var>2</var> in <var>1</var> minute.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1000 1 1000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1000000 </pre> <p>It seems to take a long time to make this kind of takoyaki.</p></section> </div> </span>
s227404596
p03694
Python
Accepted
523
19
9,148
# クリスマスもあと半年となり、トナカイのAtCoDeer君はプレゼントを配る計画を立てることにしました。 # TopCoDeer通りにはN個の家が並んでいます。i個目の家は座標aiにあります。彼はこのすべての家にプレゼントを配ることにしました。 # 好きな場所から開始し好きな場所で終了することができる時、最小の移動距離を求めなさい。 N = int(input()) a = list(map(int,input().split())) print(max(a) - min(a))
4 2 3 7 9
7
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>It is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts.<br/> There are <var>N</var> houses along <em>TopCoDeer street</em>. The <var>i</var>-th house is located at coordinate <var>a_i</var>. He has decided to deliver gifts to all these houses.<br/> Find the minimum distance to be traveled when AtCoDeer can start and end his travel at any positions. </p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≤ N ≤ 100</var></li> <li><var>0 ≤ a_i ≤ 1000</var></li> <li><var>a_i</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum distance to be traveled. </p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 3 7 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>The travel distance of <var>7</var> can be achieved by starting at coordinate <var>9</var> and traveling straight to coordinate <var>2</var>.<br/> It is not possible to do with a travel distance of less than <var>7</var>, and thus <var>7</var> is the minimum distance to be traveled. </p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>8 3 1 4 1 5 9 2 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>8 </pre> <p>There may be more than one house at a position. </p></section> </div> </span>
s559547612
p02567
Python
Accepted
1,753
81
14,848
import sys if sys.argv[-1] == 'ONLINE_JUDGE': import os, zlib, base64 open('solve.pyx', 'wb').write(zlib.decompress(base64.b85decode("c$}SA&2Hm15WWY<I}lj3krE|{7kgL)ac-Mq_tINx2(m=mglS4k%ig571ikgvK0t5np+H~Cmp;bMkQ7CcRDM=4V3EW5`{v__d`HTMc2$cjGOu@{+LkL?uBW#J-_qlwg{(J5ez9ltD=FEgsbxzFDT@aq=WJeHY}*R{t$b5(UY8kJND5|-kIMF;p%q;aUW+A3PCundN<_V6Jd}M-6MW0mI9$a<3yW^`A}fXkC@gug-I6U`w&3{c_=vz$c3Qc}$d>&|(el!fp`lY!IWwOKbw-~_-Jl1Yz;T|JOt3c36XOUR@<nRg;qy~1D0xQ?kAJG)KZmE^4o|-y9{)Q${qg_5e;=M6508I!CY6tU%_@Rc2R1VmH-wELWEhs~#Rh+OH6wd6)m2Fnk)=A(dZ9te$O%75Jw>$4K<Tod|H|5x2GsGQ1S`fVtiC3~li;(zV>2*BlQfhuayBKCejc;BQ0SqvTt~dmRC+XxL*gzSqGOYH5ehP}=?aLFQ<3arSO6zHG*r?Pa(%62VeU9P%+4A^^ub!E9H|*OZD7H*e!VdpCV5XzweIPlfUl{YEm3E~i?$i5l3$@wyMFr3or?5~D7#34=MAgU=U4;bO&YZD&y(n)3=mZF70fo?9GdX;YXrG&hS@21=Wb|Sk~a{rm!*z6-!)ayQrPk=fbU#o>9&W8s%k#dAh0hcI+F<Lw=~uU8qIfdA2Pf_s4bK}R(A~+=zfGl5g4wg7X25{XvobC2_ZRiAn6&ujHeZ*BWb&n!bT4iv$@SevyH5)h+VG#<VZhIs@n}GCRf-O&@?yF8TT4|1YbEauYu&SX`}}r1JC5gfMp8XKA5^mV3c(T@L8m@a&LPX>vF`pG&~KxO4qA)C}#=_&nt&w2R5WX=@!rCp=|kugH4hL#e0bjlOY4J#GB$imu$I;u?w8vl88}Nhv~FyN*-XY%Urz71D8=z0%=10EO&la?wA5a!*DJmm5ag-@r$}8i=@ZdrAr#I)05I>5Lu-?PSsb0$Hn0LEq=SFhbB-PSBkM5A5$R?eLPZ+H@O?xNLZ6|#S#BBgwI^kVjbrw62@mJ6FH}g7(wMYL1l~)#*_1f9&1A1Ps&)Y(2HTW15pc6J=14i#a6e^Ji}J`3bsnaR=^>~6yyIbzPo2gp@G`C(paN4g;P<!mbK5gG_C$zk;MPX;1g%)Wq8_fKIb7l*C8`aRO?w7DVAY9vs+CKG2fZ${_btEDI~Oi%I%G@k%d@N?@GyPD~H2Fxhi0{G!o)k*c%@P3D>b?7^fA@Gg9^kT63g#l9_|hn0B`YpgRZZefW6g<A~Nu$ZK*5iOr#qA3kcK0l2i0sjY|KCh7%eR-R8TyC>8EO!YU?9Qx)%6A)hkTX7zKCJQ}7;r<>9=L6XE<-#wqS-OVw_k-nla#u)a<V*j`GSX&bm*L{Ug|v9Zg>+F%I4v?^st*fwDAP%LMGAdkQGSf=o}WuaJ~cuqyau;QfKDT+|7pbE7ssE@zU@8Ya5o(8heN1Bi`#E9*d5CYJiqVoh5@LgT|K(R@7;5|;&O8G1FwD&Cz(=KCnBqzM$2jSdbR!#WOU)10y_`%zX3Jegro"))) os.system('cythonize -i -3 -b solve.pyx') import solve
5 5 1 2 3 2 1 2 1 5 3 2 3 1 3 1 2 2 4 3 1 3
3 3 2 6
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an array <var>a_0, a_1, ..., a_{N-1}</var> of length <var>N</var>. Process <var>Q</var> queries of the following types.</p> <p>The type of <var>i</var>-th query is represented by <var>T_i</var>.</p> <ul> <li><var>T_i=1</var>: You are given two integers <var>X_i,V_i</var>. Replace the value of <var>A_{X_i}</var> with <var>V_i</var>.</li> <li><var>T_i=2</var>: You are given two integers <var>L_i,R_i</var>. Calculate the maximum value among <var>A_{L_i},A_{L_i+1},\cdots,A_{R_i}</var>.</li> <li><var>T_i=3</var>: You are given two integers <var>X_i,V_i</var>. Calculate the minimum <var>j</var> such that <var>X_i \leq j \leq N, V_i \leq A_j</var>. If there is no such <var>j</var>, answer <var>j=N+1</var> instead.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 2 \times 10^5</var></li> <li><var>0 \leq A_i \leq 10^9</var></li> <li><var>1 \leq Q \leq 2 \times 10^5</var></li> <li><var>1 \leq T_i \leq 3</var></li> <li><var>1 \leq X_i \leq N</var>, <var>0 \leq V_i \leq 10^9</var> (<var>T_i=1,3</var>)</li> <li><var>1 \leq L_i \leq R_i \leq N</var> (<var>T_i=2</var>)</li> <li>All values in Input are integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>Q</var> <var>A_1</var> <var>A_2</var> <var>\cdots</var> <var>A_N</var> First query Second query <var>\vdots</var> <var>Q</var>-th query </pre> <p>Each query is given in the following format:</p> <p>If <var>T_i=1,3</var>,</p> <pre><var>T_i</var> <var>X_i</var> <var>V_i</var> </pre> <p>If <var>T_i=2</var>,</p> <pre><var>T_i</var> <var>L_i</var> <var>R_i</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>For each query with <var>T_i=2, 3</var>, print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 5 1 2 3 2 1 2 1 5 3 2 3 1 3 1 2 2 4 3 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 3 2 6 </pre> <ul> <li>First query: Print <var>3</var>, which is the maximum of <var>(A_1,A_2,A_3,A_4,A_5)=(1,2,3,2,1)</var>.</li> <li>Second query: Since <var>3&gt;A_2</var>, <var>j=2</var> does not satisfy the condition.Since <var>3 \leq A_3</var>, print <var>j=3</var>.</li> <li>Third query: Replace the value of <var>A_3</var> with <var>1</var>. It becomes <var>A=(1,2,1,2,1)</var>.</li> <li>Fourth query: Print <var>2</var>, which is the maximum of <var>(A_2,A_3,A_4)=(2,1,2)</var>.</li> <li>Fifth query: Since there is no <var>j</var> that satisfies the condition, print <var>j=N+1=6</var>.</li> </ul></section> </div> </span>
s556371913
p03533
Python
Accepted
223
60
61,592
A=["KIHBR","KIHABR","AKIHBR","KIHBAR","KIHBRA","AKIHABR","AKIHBAR","AKIHBRA","KIHABAR","KIHABRA","KIHBARA","AKIHABAR","AKIHABRA","AKIHBARA","KIHABARA","AKIHABARA"] s=input() if s in A: print("YES") else: print("NO")
KIHBR
YES
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a string <var>S</var>.</p> <p>Takahashi can insert the character <code>A</code> at any position in this string any number of times.</p> <p>Can he change <var>S</var> into <code>AKIHABARA</code>?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |S| \leq 50</var></li> <li><var>S</var> consists of uppercase English letters.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If it is possible to change <var>S</var> into <code>AKIHABARA</code>, print <code>YES</code>; otherwise, print <code>NO</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>KIHBR </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>YES </pre> <p>Insert one <code>A</code> at each of the four positions: the beginning, immediately after <code>H</code>, immediately after <code>B</code> and the end.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>AKIBAHARA </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>NO </pre> <p>The correct spell is <code>AKIHABARA</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>AAKIAHBAARA </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>NO </pre></section> </div> </span>
s196419657
p00607
Python
Accepted
4,936
20
5,632
class Editer: def __init__(self, text): # カーソルの位置 self.row = 0 #行 self.col = 0 #列 # 編集中のテキスト self.text = [list(t) + ['\n'] for t in text] # バッファー self.buffer = [] def row_head(self): return 0 def row_tail(self): return len(self.text) - 1 def col_head(self): return 0 def col_tail(self): return len(self.text[self.row]) - 1 def __repr__(self): return ''.join(''.join(t) for t in self.text) def command_a(self): # カーソルを現在の行の先頭文字に移動 self.col = self.col_head() def command_e(self): # カーソルを現在の行の行末に移動 self.col = self.col_tail() def command_p(self): # 上に行があれば、カーソルを上の行に if self.row != self.row_head() : self.row -= 1 # カーソルを先頭に self.col = self.col_head() def command_n(self): # 下に行があれば if self.row != self.row_tail(): # カーソルを下の行に移動 self.row += 1 # カーソルを先頭文字に移動 self.col = self.col_head() def command_b(self): # カーソルが行末にない場合 if self.col != self.col_head(): # カーソルを1つ左に移動 self.col -= 1 # カーソルが行末にあり、上に行がある場合 elif self.row != self.row_head(): # カーソルを前の行の先頭に self.row -= 1 self.col = self.col_tail() def command_f(self): # カーソルが行末にない場合 if self.col != self.col_tail(): # カーソルを1つ右に移動 self.col += 1 # カーソルが行末にあり、下に行がある場合 elif self.row != self.row_tail(): # カーソルを次の行の先頭に self.row += 1 self.col = self.col_head() def command_d(self): # カーソルが行末にない場合 if self.col != self.col_tail(): # カーソルの文字を削除 self.text[self.row].pop(self.col) # カーソルが行末を指し、下に行がある場合 elif self.row != self.row_tail(): # 下の行をそのままカーソルの位置に繋げ、以下の行は上にシフト self.text[self.row].pop(self.col_tail()) self.text[self.row] += self.text.pop(self.row+1) def command_k(self): # カーソルが行末にない場合 if self.col != self.col_tail(): # カーソルが指す文字を含めた右側すべての文字を切り取りそれをバッファに記録する。 self.buffer = self.text[self.row][self.col:-1] self.text[self.row] = self.text[self.row][:self.col] + ['\n'] # カーソルは元の行の行末を指すようになる self.col = self.col_tail() # カーソルが行末にあり、下に行がある場合 elif self.row != self.row_tail(): # バッファに改行を記録する。 self.buffer = ['\n'] # 下の行をそのままカーソルの位置に繋げる。以下の行は上にシフトされる。 self.text[self.row].pop(self.col_tail()) self.text[self.row] += self.text.pop(self.row+1) def command_y(self): ''' カーソルが指す文字の直前にバッファを挿入 カーソルの位置はもともと指していた文字へ移動 バッファの内容が改行なら ''' if self.buffer != ['\n']: self.text[self.row][self.col:self.col] = self.buffer self.col += len(self.buffer) else: self.text.insert(self.row+1, self.text[self.row][self.col:]) self.text[self.row] = self.text[self.row][:self.col] + ['\n'] self.row += 1 self.col = self.col_head() def main(): # input text text = [] while True: str = input() if str == 'END_OF_TEXT': break text.append(str) editer = Editer(text) # input command while True: command = input() if command == 'a' : editer.command_a() elif command == 'e' : editer.command_e() elif command == 'p' : editer.command_p() elif command == 'n' : editer.command_n() elif command == 'f' : editer.command_f() elif command == 'b' : editer.command_b() elif command == 'd' : editer.command_d() elif command == 'y' : editer.command_y() elif command == 'k' : editer.command_k() elif command == '-' : break print(editer, end='') if __name__ == '__main__': main()
hyo ni END_OF_TEXT f d f f k p p e y a k y y n y -
honihoni honi
<H1><font color="#000000">Problem C:</font> Emacs-like Editor</H1> <p> Emacs is a text editor which is widely used by many programmers. </p> <p> The advantage of Emacs is that we can move a cursor without arrow keys and the mice. For example, the cursor can be moved right, left, down, and up by pushing <span>f</span>, <span>b</span>, <span>n</span>, <span>p</span> with the Control Key respectively. In addition, cut-and-paste can be performed without the mouse. </p> <p> Your task is to write a program which simulates key operations in the Emacs-like editor. The program should read a text and print the corresponding edited text. </p> <p> The text consists of several lines and each line consists of zero or more alphabets and space characters. A line, which does not have any character, is a blank line. </p> <p> The editor has a cursor which can point out a character or the end-of-line in the corresponding line. The cursor can also point out the end-of-line in a blank line. </p> <p> In addition, the editor has a buffer which can hold either a string (a sequence of characters) or a linefeed. </p> <p> The editor accepts the following set of commands (If the corresponding line is a blank line, the word "the first character" should be "the end-of-line"): </p> <ul> <li> <span>a</span><br> Move the cursor to the first character of the current line. </li> <li> <span>e</span><br> Move the cursor to the end-of-line of the current line. </li> <li> <span>p</span><br> Move the cursor to the first character of the next upper line, if it exists.<br> If there is no line above the current line, move the cursor to the first character of the current line. </li> <li> <span>n</span><br> Move the cursor to the first character of the next lower line, if it exists.<br> If there is no line below the current line, move the cursor to the first character of the current line. </li> <li> <span>f</span><br> Move the cursor by one character to the right, unless the cursor points out the end-of-line.<br> If the cursor points out the end-of-line and there is a line below the current line, move the cursor to the first character of the next lower line. Otherwise, do nothing. </li> <li> <span>b</span><br> Move the cursor by one character to the left, unless the cursor points out the first character.<br> If the cursor points out the first character and there is a line above the current line, move the cursor to the end-of-line of the next upper line. Otherwise, do nothing. </li> <li> <span>d</span><br> If the cursor points out a character, delete the character (Characters and end-of-line next to the deleted character are shifted to the left).<br> If the cursor points out the end-of-line and there is a line below, the next lower line is appended to the end-of-line of the current line (Lines below the current line are shifted to the upper). <br>Otherwise, do nothing. </li> <li> <span>k</span><br> If the cursor points out the end-of-line and there is a line below the current line, perform the command <span>d</span> mentioned above, and record a linefeed on the buffer.<br> If the cursor does not point out the end-of-line, cut characters between the cursor (inclusive) and the end-of-line, and record them on the buffer. <!--Move the cursor to the end-of-line of the original line.--> After this operation, the cursor indicates the end-of-line of the current line. </li> <li> <span>y</span><br> If the buffer is empty, do nothing.<br> If the buffer is holding a linefeed, insert the linefeed at the cursor. The cursor moves to the first character of the new line.<br> If the buffer is holding characters, insert the characters at the cursor. The cursor moves to the character or end-of-line which is originally pointed by the cursor. </li> </ul> <p> The cursor position just after reading the text is the beginning of the first line, and the initial buffer is empty. </p> <H2>Input</H2> <p> The input consists of only one data-set which includes two parts. The first part gives a text consisting of several lines. The end of the text is indicated by a line (without quotes): <pre> "END_OF_TEXT" </pre> <p> This line should not be included in the text. </p> <p> Next part gives a series of commands. Each command is given in a line. The end of the commands is indicated by a character '<span>-</span>'. </p> <H2>Output</H2> <p> For the input text, print the text edited by the commands. </p> <H2>Constraints</H2> <ul> <li>The number of lines in the text given as input &le; 10</li> <li>The number of characters in a line given as input &le; 20 </li> <li>The number of commands &le; 300 </li> <li>The maximum possible number of lines in the text during operations &le; 100 </li> <li>The maximum possible number of characters in a line during operations &le; 1000 </li> </ul> <H2>Sample Input</H2> <pre> hyo ni END_OF_TEXT f d f f k p p e y a k y y n y - </pre> <H2>Output for the Sample Input</H2> <pre> honihoni honi </pre>
s668216812
p03398
Python
Accepted
465
39
28,396
print[0,1,2,12,84,770,8340,106400,1546888,25343766,461133960,232367169,627905865,632459808,928262728,919805769,382796331,887217496,639768068,869694124,205875097,205589953,487772376,239955313,998339621,31622834,902930073,146839084,449786840,982224660,865803735,21834818,721531716,26008837,471774471,69010090,700009308,776938882,645550477,526939604,142728157,654489641,128201240,185493259,789721045,977049419,589149550,700648836,25087729,874433491,352791804][input()]
3
12
<span class="lang-en"> <p>Score : <var>1600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Let <var>X = 10^{100}</var>. Inaba has <var>N</var> checker pieces on the number line, where the <var>i</var>-th checker piece is at coordinate <var>X^{i}</var> for all <var>1 \leq i \leq N</var>.</p> <p>Every second, Inaba chooses two checker pieces, <var>A</var> and <var>B</var>, and move <var>A</var> to the symmetric point of its current position with respect to <var>B</var>. After that, <var>B</var> is removed. (It is possible that <var>A</var> and <var>B</var> occupy the same position, and it is also possible for <var>A</var> to occupy the same position as another checker piece after the move).</p> <p>After <var>N - 1</var> seconds, only one checker piece will remain. Find the number of distinct possible positions of that checker piece, modulo <var>10^{9} + 7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 50</var></li> <li><var>N</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of distinct possible positions of the final checker piece, modulo <var>10^{9} + 7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>There are <var>3</var> checker pieces, positioned at <var>10^{100}, 10^{200}, 10^{300}</var> respectively. Call them <var>A, B, C</var> respectively.</p> <p>Here are two (of the <var>12</var>) possible sequence of moves :</p> <ul> <li> <p>Let <var>A</var> jump over <var>B</var> in the first second, and let <var>A</var> jump over <var>C</var> in the second second. The final position of <var>A</var> is <var>2 \times 10^{300} - 2 \times 10^{200} + 10^{100}</var>.</p> </li> <li> <p>Let <var>C</var> jump over <var>A</var> in the first second, and let <var>B</var> jump over <var>C</var> in the second second. The final position of <var>B</var> is <var>-2 \times 10^{300} - 10^{200} + 4 \times 10^{100}</var>.</p> </li> </ul> <p>There are a total of <var>3 \times 2 \times 2 = 12</var> possible sequence of moves, and the final piece are in different positions in all of them.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>84 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>22 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>487772376 </pre> <p>Remember to output your answer modulo <var>10^{9} + 7</var>.</p></section> </div> </span>
s009469424
p00020
Python
Accepted
29
10
4,604
print raw_input().swapcase()
this is a pen.
THIS IS A PEN.
<H1>Capitalize</H1> <p> Write a program which replace all the lower-case letters of a given text with the corresponding captital letters. </p> <H2>Input</H2> <p> A text including lower-case letters, periods, and space is given in a line. The number of characters in the text is less than or equal to 200. </p> <H2>Output</H2> <p> Print the converted text. </p> <H2>Sample Input</H2> <pre> this is a pen. </pre> <H2>Output for the Sample Input</H2> <pre> THIS IS A PEN. </pre>
s125064404
p02312
Python
Accepted
2,432
60
7,348
from math import acos, hypot, isclose, sqrt from typing import List, Tuple def intersection(circle: Tuple[int, int, int], polygon: List[Tuple[float, float]]) -> float: x, y, r = circle area = 0.0 for p1, p2 in zip(polygon, polygon[1:] + [polygon[0]]): ps = seg_intersection(circle, (p1, p2)) for pp1, pp2 in zip([p1] + ps, ps + [p2]): c = cross(pp1, pp2) if c == 0: continue d1 = hypot(*pp1) d2 = hypot(*pp2) if le(d1, r) and le(d2, r): area += c / 2 else: t = acos(dot(pp1, pp2) / (d1 * d2)) sign = c // abs(c) area += sign * r * r * t / 2 return area def cross(v1: Tuple[float, float], v2: Tuple[float, float]) -> float: x1, y1 = v1 x2, y2 = v2 return x1 * y2 - x2 * y1 def dot(v1: Tuple[float, float], v2: Tuple[float, float]) -> float: x1, y1 = v1 x2, y2 = v2 return x1 * x2 + y1 * y2 def seg_intersection(circle: Tuple[int, int, int], seg: Tuple[Tuple[float, float], Tuple[float, float]]) -> List[Tuple[float, float]]: x0, y0, r = circle p1, p2 = seg x1, y1 = p1 x2, y2 = p2 p1p2 = (x2 - x1) ** 2 + (y2 - y1) ** 2 op1 = (x1 - x0) ** 2 + (y1 - y0) ** 2 rr = r * r dp = dot((x1 - x0, y1 - y0), (x2 - x1, y2 - y1)) d = dp * dp - p1p2 * (op1 - rr) ps = [] if isclose(d, 0.0, abs_tol=1e-9): t = - dp / p1p2 if ge(t, 0.0) and le(t, 1.0): ps.append((x1 + t * (x2 - x1), y1 + t * (y2 - y1))) elif d > 0.0: t1 = (- dp - sqrt(d)) / p1p2 if ge(t1, 0.0) and le(t1, 1.0): ps.append((x1 + t1 * (x2 - x1), y1 + t1 * (y2 - y1))) t2 = (- dp + sqrt(d)) / p1p2 if ge(t2, 0.0) and le(t2, 1.0): ps.append((x1 + t2 * (x2 - x1), y1 + t2 * (y2 - y1))) return ps def le(f1: float, f2: float) -> bool: return f1 < f2 or isclose(f1, f2, abs_tol=1e-9) def ge(f1: float, f2: float) -> bool: return f1 > f2 or isclose(f1, f2, abs_tol=1e-9) if __name__ == "__main__": n, r = [int(i) for i in input().split()] ps: List[Tuple[float, float]] = [] for _ in range(n): x, y = map(lambda x: float(x), input().split()) ps.append((x, y)) print("{:.6f}".format(intersection((0, 0, r), ps)))
3 5 1 1 4 1 5 5
4.639858417607
<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>Intersection of a Circle and a Polygon</H1> <p> Find the area of intersection between a circle $c$ and a polygon $g$. The center coordinate of the circle is ($0, 0$). </p> <p> The polygon $g$ is represented by a sequence of points $p_1$, $p_2$,..., $p_n$ where line segments connecting $p_i$ and $p_{i+1}$ ($1 \leq i \leq n−1$) are sides of the polygon. The line segment connecting $p_n$ and $p_1$ is also a side of the polygon. </p> <p> Note that the polygon is not necessarily convex. </p> <h2>Input</h2> <p>The input is given in the following format.<br/> <br/> $n$ $r$<br/> $x_1$ $y_1$<br/> $x_2$ $y_2$<br/> :<br/> $x_n$ $y_n$<br/> </p> <p> In the first line, an integer <var>n</var> representing the number of points in the polygon is given. The coordinate of a point $p_i$ is given by two integers $x_i$ and $y_i$. The coordinates of the points are given in the order of counter-clockwise visit of them. All input values are given in integers. </p> <h2>Constraints</h2> <ul> <li>$3 \leq n \leq 100$</li> <li>$1 \leq r \leq 100$</li> <li>$-100 \leq x_i, y_i \leq 100$</li> </ul> <h2>Output</h2> <p> Print the area of intersection in a line. The output values should be in a decimal fraction with an error less than 0.00001. </p> <h2>Sample Input 1</h2> <pre> 3 5 1 1 4 1 5 5 </pre> <h2>Sample Output 1</h2> <pre> 4.639858417607 </pre> <h2>Sample Input 2</h2> <pre> 4 5 0 0 -3 -6 1 -3 5 -4 </pre> <h2>Sample Output 2</h2> <pre> 11.787686807576 </pre>
s948499044
p00354
Python
Accepted
79
20
5,588
ans=["thu","fri","sat","sun","mon","tue","wed"] i=int(input()) print(ans[i%7])
1
fri
<!--<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 &le; <var>X</var> &le; 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>
s949780828
p01858
Python
Accepted
1,281
10
6,464
K = int(raw_input()) nakaji = isono = 0 for I, N in zip([raw_input() for i in xrange(K)], [raw_input() for i in xrange(K)]): lose1 = lose2 = False if I == "kougekida" and isono == 0: lose1 = True if N == "kougekida" and nakaji == 0: lose2 = True if lose1 and lose2: continue elif lose1: print "Nakajima-kun" break elif lose2: print "Isono-kun" break if I == "tameru": isono = min(5, isono + 1) if N == "tameru": nakaji = min(5, nakaji + 1) if I == "kougekida": if N == "mamoru": if isono == 5: print "Isono-kun" break isono = 0 if N == "tameru": print "Isono-kun" break if N == "kougekida": if nakaji < isono: print "Isono-kun" break elif nakaji == isono: nakaji = isono = 0 elif nakaji > isono: print "Nakajima-kun" break if N == "kougekida": if I == "mamoru": if nakaji == 5: print "Nakajima-kun" break nakaji = 0 if I == "tameru": print "Nakajima-kun" break else: print "Hikiwake-kun"
3 tameru tameru tameru tameru kougekida tameru
Nakajima-kun
<!--<script language="JavaScript" type="text/javascript" src="js/varmath.js" charset="UTF-8"></script>--> <h2>A: 磯野、あれやろうぜ! - Sendame -</h2> <h3>物語</h3> <p>中島「磯野〜,あれやろうぜ!」</p> <p>磯野「あれって何だよ,中島」</p> <p>中島「ほら,あれだよ,あれ.なぜか文字で表さなきゃならないから,説明しづらいな〜」</p> <p>磯野「いや,図や写真も入れられるみたいだぞ?」</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2015HokudaiPC_sazae" type="image/jpeg" width="300"></img> <p>中島「本当だ!」</p> <p>磯野「で,何をやるんだ?」</p> <p>中島「ほら,リズムに乗って,手を2回叩いた後に,防御,溜め,攻撃のポーズを取るやつ」</p> <p>磯野「う〜ん,イマイチわからないな…」</p> <p>中島「2回手を叩いた後に,例えば防御だったら」</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2015HokudaiPC_bougyo" type="image/jpeg" width="300"></img> <p>中島「で,溜めだったら」</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2015HokudaiPC_tame" type="image/jpeg" width="300"></img> <p>中島「攻撃だったら」</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2015HokudaiPC_kougeki" type="image/jpeg" width="300"></img> <p>中島「ってやるやつ,知ってるだろ?」</p> <p>磯野「ああ!写真が入ると劇的に分かりやすくなるな!」</p> <p>中島「これぞ文明の進歩だな!」</p> <p>(それから悠久の時が経った)</p> <p>花沢「い゛そ゛の゛く゛〜゛ん゛な゛か゛じ゛ま゛く゛〜゛ん゛」</p> <p>二人「(パチパチ…パチパチ…パチパチ…)」</p> <p>花沢「アンタたち,まさか寝ながらあれやってるの…!?」</p> <p>花沢「今勝負ついたじゃない…磯野くん,今あなた勝ったわよ?」</p> <p>磯野「……花沢さん来てたんだ…中島もう一度やるぞ…zzz」</p> <p>中島「(こくり)」</p> <p>二人「(パチパチ…パチパチ…)」</p> <p>花沢「もう…ここに,あれの勝敗判定ロボット置いておくから…」</p> <p>そうして花沢さんは去って行った.</p> <p>ということがあるかもしれないので,あれの勝敗判定プログラムを書いてください.</p> <h3>問題</h3> <p>「あれ」は2人で行うゲームである.リズムに合わせて2人が同時に,防御,溜め,攻撃のいずれかのポーズを取ることを繰り返す.ここで,2人がポーズを取るタイミングのことを「回」と表記する.このゲームでは,ある回で勝敗がつき,かつ,それまでの回で勝敗がついていないとき,その勝敗がゲームの勝敗となる.</p> <p>2人はそれぞれ「攻撃力」というパラメータを持ち,ゲーム開始時,攻撃力は <var>0</var> である.</p> <p>攻撃のポーズを取った場合,その時点での攻撃力に応じて,次のようになる.</p> <ul> <li>攻撃力が <var>0</var> のときに攻撃のポーズを取ると,反則負けとなる.ただし,相手も攻撃力が <var>0</var> で攻撃のポーズをした場合,その回では勝敗がつかない.</li> <li>自分の攻撃力が <var>1</var> 以上のときに攻撃のポーズをとると,相手に攻撃を加える.また,その回で相手も攻撃のポーズを取った場合,攻撃力のより高いプレイヤーが勝利する.ただし,両プレイヤーが同じ攻撃力で攻撃のポーズを取った場合には,その回では勝敗がつかない.</li> </ul> <p>また,攻撃のポーズを取った回の終了時に,自分の攻撃力が <var>0</var> になる.</p> <p>溜めのポーズを取ると,そのプレイヤーの攻撃力が <var>1</var> だけ上昇する.ただし,攻撃力が <var>5</var> である場合,そのプレイヤーが溜めのポーズを取っても,攻撃力は <var>5</var> のままである.溜めのポーズを取った回で,相手が攻撃を加えた場合,相手が勝利する.なお,溜めのポーズを取った回で,相手が攻撃以外のポーズをとった場合,勝敗がつかない.</p> <p>防御のポーズを取った回に,相手が攻撃力 <var>5</var> の攻撃を加えた場合,相手が勝利する.一方,防御のポーズを取った回に,相手が攻撃力 <var>4</var> 以下の攻撃を加えた場合や,溜めまたは防御のポーズを取った場合,その回では勝敗がつかない.なお,防御のポーズを取っても,そのプレイヤーの攻撃力に変化はない.</p> <p>両プレイヤーのポーズが順に与えられるので,勝敗を出力せよ.なお,両プレイヤーは勝敗が決定した後もポーズをとり続けることがあるが,勝敗が決定した後のポーズは無視するものとする.</p> <h3>入力形式</h3> <p>入力は以下の形式で与えられる.</p> <pre> <var>K</var> <var>I_1</var> ... <var>I_K</var> <var>N_1</var> ... <var>N_K</var> </pre> <p> 入力の1行目には,1個の整数 <var>K</var> (<var> 1 &le; K &le; 100</var>) が与えられる. 2行目からの <var>K</var> 行には,磯野が取ったポーズ <var>I_i</var> (<var>1 &le; i &le; K</var>) が順に与えられる. その直後の <var>K</var> 行には,中島が取ったポーズ <var>N_i</var> (<var>1 &le; i &le; K</var>) が順に与えられる. <var>I_i</var> および <var>N_i</var> は “mamoru”, “tameru”, “kougekida” のいずれかである.これらの文字列は順に,防御,溜め,攻撃のポーズを表す. </p> <h3>出力形式</h3> <p>磯野が勝利した場合には “Isono-kun” ,中島が勝利した場合には “Nakajima-kun” , <var>K</var> 回で勝敗がつかない場合には, “Hikiwake-kun” と1行で出力せよ.</p> <h3>入力例1</h3> <pre> 3 tameru tameru tameru tameru kougekida tameru </pre> <h3>出力例1</h3> <pre>Nakajima-kun</pre> <p><var>2</var> 回目で,磯野が溜めのポーズをしているのに対し,中島は攻撃力 <var>1</var> の攻撃をしているので,中島の勝利です.</p> <h3>入力例2</h3> <pre> 3 mamoru mamoru mamoru tameru tameru tameru </pre> <h3>出力例2</h3> <pre>Hikiwake-kun</pre> <p>どちらも攻撃をしなかったので,勝敗がつきませんでした.</p> <h3>入力例3</h3> <pre> 5 tameru tameru mamoru mamoru kougekida tameru tameru kougekida tameru kougekida </pre> <h3>出力例3</h3> <pre>Isono-kun</pre> <p><var>1</var> 回目から <var>4</var> 回目まででは勝敗がつきません. <var>5</var> 回目で,両プレイヤーが攻撃のポーズをしていますが,磯野の攻撃力が <var>2</var> なのに対し,中島の攻撃力が <var>1</var> なので,磯野の勝利です.</p> <h3>入力例4</h3> <pre> 3 kougekida kougekida tameru kougekida mamoru kougekida </pre> <h3>出力例4</h3> <pre>Nakajima-kun</pre> <p><var>1</var> 回目では,両プレイヤーが攻撃力 <var>0</var> で攻撃のポーズを取っているので,勝敗がつきません. <var>2</var> 回目では,磯野のみが攻撃力 <var>0</var> で攻撃のポーズをとっているので,中島の勝利です.</p> <h3>入力例5</h3> <pre> 8 tameru mamoru tameru tameru tameru tameru tameru kougekida tameru kougekida mamoru mamoru mamoru mamoru mamoru mamoru </pre> <h3>出力例5</h3> <pre>Isono-kun</pre> <p><var>2</var> 回目では,中島が攻撃力 <var>1</var> で攻撃のポーズを取っていますが,磯野が防御のポーズを取っているので,勝敗がつきません. <var>7</var> 回目では,磯野が攻撃力 <var>5</var> で溜めのポーズを取っているので,磯野の攻撃力は <var>5</var> のままです. <var>8</var> 回目では,磯野が攻撃力 <var>5</var> で攻撃のポーズをとり,中島が防御のポーズを取っているので,磯野が勝利します.</p>
s971614031
p00435
Python
Accepted
348
20
5,716
x = input() str_list = list(x) dict_ = { "D":"A", "E":"B", "F":"C", "G":"D", "H":"E", "I":"F", "J":"G", "K":"H", "L":"I", "M":"J", "N":"K", "O":"L", "P":"M", "Q":"N", "R":"O", "S":"P", "T":"Q", "U":"R", "V":"S", "W":"T", "X":"U", "Y":"V", "Z":"W", "A":"X", "B":"Y", "C":"Z" } for a in str_list: print(dict_.get(a) , end = "") print()
MRL
JOI
<H1>シーザー暗号</H1> <h2>問題</h2> <p> ガイウス・ユリウス・カエサル(Gaius Julius Caesar),英語読みでジュリアス・シーザー(Julius Caesar)は,古代ローマの軍人であり政治家である.カエサルは,秘密の手紙を書くときに, 'A' を 'D' に, 'B' を 'E' に, 'C' を 'F' に,というように3つずらして表記したという記録が残っている. </p> <p> 大文字のアルファベット26文字だけからなる文字列を,カエサルがしたように3文字ずつずらす変換を施し得られた文字列がある.このような文字列を元の文字列に戻すプログラムを作成せよ. </p> <p> 各文字の変換前と変換後の対応は次のようになる. </p> <table style="margin-left:28px; margin-bottom:28px"> <tr> <td width="80">変換前</td> <td width="30">A</td> <td width="30">B</td> <td width="30">C</td> <td width="30">D</td> <td width="30">E</td> <td width="30">F</td> <td width="30">G</td> <td width="30">H</td> <td width="30">I</td> <td width="30">J</td> <td width="30">K</td> <td width="30">L</td> <td width="30">M</td> <td width="30">N</td> <td width="30">O</td> <td width="30">P</td> <td width="30">Q</td> <td width="30">R</td> <td width="30">S</td> <td width="30">T</td> <td width="30">U</td> <td width="30">V</td> <td width="30">W</td> <td width="30">X</td> <td width="30">Y</td> <td width="30">Z</td> </tr> <tr> <td>変換後</td> <td>D</td> <td>E</td> <td>F</td> <td>G</td> <td>H</td> <td>I</td> <td>J</td> <td>K</td> <td>L</td> <td>M</td> <td>N</td> <td>O</td> <td>P</td> <td>Q</td> <td>R</td> <td>S</td> <td>T</td> <td>U</td> <td>V</td> <td>W</td> <td>X</td> <td>Y</td> <td>Z</td> <td>A</td> <td>B</td> <td>C </td> </tr> </table> <p> 例えば,この方法で文字列 JOI を変換すると MRL が得られ,この方法で変換された文字列 FURDWLD の元の文字列は CROATIA である. </p> <H2>入力</H2> <p> 入力は1行だけからなり,その1行は大文字のアルファベットのみで構成される文字列を1つ含む. </p> <p> 入力される文字列の長さは 1000 以下である. </p> <H2>出力</H2> <p> <!--提出する出力ファイルは、入力された文字列を元に戻した文字列だけを含む1行を出力する。--> 入力された文字列を元に戻した文字列だけを含む1行を出力する。 </p> <h2>入出力例</h2> <h3>入力例 1</h3> <pre>MRL</pre> <h3>出力例 1</h3> <pre> JOI </pre> <br> <h3>入力例 2</h3> <pre>FURDWLD</pre> <h3>出力例 2</h3> <pre>CROATIA</pre> <div class="source"> <p class="source"> 上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。 </p> </div>
s938943334
p00433
Python
Accepted
162
20
4,192
a_score = sum(map(int, raw_input().split())) b_score = sum(map(int, raw_input().split())) if a_score > b_score: print a_score else: print b_score
100 80 70 60 80 70 80 90
320
<H1>得点</H1> <h2>問題</h2> <p> JOI高校の2人の生徒 A さんと B さんは,情報,数学,理科,英語の4教科の試験を受けた. A さんと B さんのこれら4教科の得点が与えられると, Aさんの合計点 S と Bさんの合計点 T のうち大きな方を出力するプログラムを作成せよ.ただし,同点の場合は S (= T) を出力せよ. </p> <H2>入力</H2> <p> <!--入力ファイルは2行からなる.--> 入力は2行からなる. </p> <p> 1行目は4つの整数が1つの空白を区切りとして書かれており,それぞれ順に, A さんの情報の得点,数学の得点,理科の得点,英語の得点を表している. </p> <p> 2行目は4つの整数が1つの空白を区切りとして書かれており,それぞれ順に, B さんの情報の得点,数学の得点,理科の得点,英語の得点を表している. </p> <p> どの教科の得点も100点満点で,負の得点が与えられることはない. </p> <H2>出力</H2> <p> <!--提出するファイルは, 求める1つの整数からなる.--> 出力は, 求める1つの整数からなる. </p> <h2>入出力例</h2> <h3>入力例1</h3> <pre> 100 80 70 60 80 70 80 90 </pre> <h3>出力例1</h3> <pre> 320 </pre> <br> <h3>入力例2</h3> <pre> 100 80 70 60 80 70 60 100 </pre> <h3>出力例2</h3> <pre> 310 </pre> <div class="source"> <p class="source"> 上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。 </p> </div>
s169448030
p01905
Python
Accepted
97
20
5,580
# AOJ 2805: Tournament # Python3 2018.7.11 bal4u N, M = map(int, input().split()) print(N-1-M)
2 0
1
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]} }); </script> <script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <h1>A: トーナメント</h1> <h2>問題</h2> <p> AOR イカちゃんとあなたは、トーナメント形式の卓球大会シングルスの部に偵察に来た。 全ての試合を録画したい AOR イカちゃんのために、あなたはこの大会で行われる試合数を求めてあげることにした。 </p> <p> この大会には $N$ 人の選手が参加しており、それぞれ $0, \dots , N - 1$ の背番号を持っている。 そのうち、 $M$ 人の選手が棄権し、試合には出場しなかった。 </p> <p> この大会の試合数は、以下のルールに基いて決定される。 </p> <ul> <li>シード選手は存在せず、任意の出場者が優勝するために必要な勝利回数は一定である。</li> <li>対戦相手が不在の場合は試合を行わず、出場した選手が勝利する。試合数にはカウントされない。</li> <li>優勝者が決まった段階で大会は終了する。</li> <li>一度試合に負けた人が再び試合をすることはない。つまり敗者復活戦や 3 位決定戦などは行わない。</li> <li>なお、卓球台が 1 台しか無いため異なる試合が同時に行われることはなく、また各試合では必ず勝者が決まる (引き分けとなることはない)。</li> </ul> <p> なお、トーナメントの定義は次のとおりである。 トーナメントは高さ $L = \log_2 N$ の完全二分木で表され、葉にあたる各頂点には参加者の背番号が書き込まれている。 根の深さを 0 とすると、 $i$ 回戦 ($1 \le i \le L$) では、 深さ $L - i$ の各頂点の子に書かれた番号の選手同士が試合を行い、その勝者の背番号をその頂点に書き込む。 </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp17Day1_RUPC2017_Tournament"> <h2>制約</h2> <ul> <li>$2 \le N \le 2^8$</li> <li>$0 \le M \le N - 1$</li> <li>$0 \le a_i \le N - 1 \ (0 \le i \le M - 1)$</li> <li> $N$ は 2 の累乗である。</li> <li> $a_i \ (0 \le i \le M - 1)$ は相異なる</li> </ul> <h2>入力形式</h2> <p> 入力は以下の形式で与えられる。 </p> <p> $N \ M$<br> $a_1$<br> $\vdots$<br> $a_M$<br> </p> <ul> <li>1 行目には、参加者を表す整数 $N$ 、参加者のうち棄権した者の人数を表す整数 $M$ が与えられる。</li> <li>続く $M$ 行には、棄権して出場しなかった選手の番号を表す整数 $a_i$ が与えられる。</li> </ul> <h2>出力</h2> <p> この大会が終了するまでに行われる試合数を 1 行で出力せよ。また、末尾に改行も出力せよ。 </p> <h2>サンプル</h2> <h3>サンプル入力 1</h3> <pre> 2 0 </pre> <h3>サンプル出力 1</h3> <pre> 1 </pre> <p> 最初の試合で優勝者が決まる。 </p> <h3>サンプル入力 2</h3> <pre> 4 2 2 3 </pre> <h3>サンプル出力 2</h3> <pre> 1 </pre>
s089387393
p03167
Python
Accepted
2,418
99
80,800
''' =============================== -- @uthor : Kaleab Asfaw -- Handle : kaleabasfaw2010 -- Bio : High-School Student ===============================''' # Fast IO import sys import os from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno(); self.buffer = BytesIO(); self.writable = "x" in file.mode or "r" not in file.mode; self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell(); self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0; return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)); self.newlines = b.count(b"\n") + (not b); ptr = self.buffer.tell(); self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1; return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()); self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file); self.flush = self.buffer.flush; self.writable = self.buffer.writable; self.write = lambda s: self.buffer.write(s.encode("ascii")); self.read = lambda: self.buffer.read().decode("ascii"); self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout); input = lambda: sys.stdin.readline().rstrip("\r\n") # Others # from math import floor, ceil, gcd # from decimal import Decimal as d mod = 10**9+7 def lcm(x, y): return (x * y) / (gcd(x, y)) def fact(x, mod=mod): ans = 1 for i in range(1, x+1): ans = (ans * i) % mod return ans def arr2D(n, m, default=0): lst = [] for i in range(n): temp = [default] * m; lst.append(temp) return lst def sortDictV(x): return {k: v for k, v in sorted(x.items(), key = lambda item : item[1])} def solve(n, m, grid): dp = arr2D(n, m) dp[0][0] = 1 for i in range(n): for j in range(m): if grid[i][j] == "." and ((i > 0 and grid[i-1][j] == ".") or (j > 0 and grid[i][j-1] == ".")): dp[i][j] = (dp[i][j-1] + dp[i-1][j]) % mod return dp[n-1][m-1] n, m = list(map(int, input().split())) grid = [] for i in range(n): grid.append(input()) print(solve(n, m, grid))
3 4 ...# .#.. ....
3
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a grid with <var>H</var> horizontal rows and <var>W</var> vertical columns. Let <var>(i, j)</var> denote the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left.</p> <p>For each <var>i</var> and <var>j</var> (<var>1 \leq i \leq H</var>, <var>1 \leq j \leq W</var>), Square <var>(i, j)</var> is described by a character <var>a_{i, j}</var>. If <var>a_{i, j}</var> is <code>.</code>, Square <var>(i, j)</var> is an empty square; if <var>a_{i, j}</var> is <code>#</code>, Square <var>(i, j)</var> is a wall square. It is guaranteed that Squares <var>(1, 1)</var> and <var>(H, W)</var> are empty squares.</p> <p>Taro will start from Square <var>(1, 1)</var> and reach <var>(H, W)</var> by repeatedly moving right or down to an adjacent empty square.</p> <p>Find the number of Taro's paths from Square <var>(1, 1)</var> to <var>(H, W)</var>. As the answer can be extremely large, find the count modulo <var>10^9 + 7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>H</var> and <var>W</var> are integers.</li> <li><var>2 \leq H, W \leq 1000</var></li> <li><var>a_{i, j}</var> is <code>.</code> or <code>#</code>.</li> <li>Squares <var>(1, 1)</var> and <var>(H, W)</var> are empty squares.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>H</var> <var>W</var> <var>a_{1, 1}</var><var>\ldots</var><var>a_{1, W}</var> <var>:</var> <var>a_{H, 1}</var><var>\ldots</var><var>a_{H, W}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of Taro's paths from Square <var>(1, 1)</var> to <var>(H, W)</var>, modulo <var>10^9 + 7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 4 ...# .#.. .... </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>There are three paths as follows:</p> <p><img alt="" src="https://img.atcoder.jp/dp/grid_0_0_muffet.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 2 .. #. .. .# .. </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>There may be no paths.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 5 ..#.. ..... #...# ..... ..#.. </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>24 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>20 20 .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>345263555 </pre> <p>Be sure to print the count modulo <var>10^9 + 7</var>.</p></section> </div> </span>
s664158188
p02255
Python
Accepted
1,048
20
5,600
length=int(input()) firstArray=input() listForArray=list(map(int,firstArray.split())) listForPrint=[firstArray] def insertionSort(list,length): index=1 while index<length: if listForArray[index]<=listForArray[index-1]: for index2 in range(0,index): if listForArray[index2-1]<=listForArray[index] and listForArray[index]<=listForArray[index2] or index2==0 and listForArray[index]<=listForArray[index2]: newCommer=listForArray[index] n=index while n>index2: listForArray[n]=listForArray[n-1] n-=1 listForArray[index2]=newCommer break nowArray=str(listForArray[0]) for index3 in range(1,length): nowArray+=" "+str(listForArray[index3]) listForPrint.append(nowArray) index+=1 #---------------------main------------------------- insertionSort(listForArray,length) for array in listForPrint: print(array)
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key </pre> <p> Note that, indices for array elements are based on 0-origin. </p> <p> To illustrate the algorithms, your program should trace intermediate result for each step. </p> <H2>Input</H2> <p> The first line of the input includes an integer N, the number of elements in the sequence. </p> <p> In the second line, <i>N</i> elements of the sequence are given separated by a single space. </p> <H2>Output</H2> <p> The output consists of <i>N</i> lines. Please output the intermediate sequence in a line for each step. Elements of the sequence should be separated by single space. </p> <H2>Constraints</H2> <p> 1 &le; <i>N</i> &le; 100 </p> <H2>Sample Input 1</H2> <pre> 6 5 2 4 6 1 3 </pre> <H2>Sample Output 1</H2> <pre> 5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6 </pre> <H2>Sample Input 2</H2> <pre> 3 1 2 3 </pre> <H2>Sample Output 2</H2> <pre> 1 2 3 1 2 3 1 2 3 </pre> <H2>Hint</H2> <a href="template/ALDS1_1_A_template.c">Template in C</a>
s444434531
p03891
Python
Accepted
137
73
61,900
a=int(input()) b=int(input()) c=int(input()) d=c*3-a-b g=c*2-d h=c*2-b i=c*2-a e=c*3-a-g f=c*3-d-i print(a,b,d) print(e,c,f) print(g,h,i)
8 3 5
8 3 4 1 5 9 6 7 2
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>A <var>3×3</var> grid with a integer written in each square, is called a magic square if and only if the integers in each row, the integers in each column, and the integers in each diagonal (from the top left corner to the bottom right corner, and from the top right corner to the bottom left corner), all add up to the same sum.</p> <p>You are given the integers written in the following three squares in a magic square:</p> <ul> <li>The integer <var>A</var> at the upper row and left column</li> <li>The integer <var>B</var> at the upper row and middle column</li> <li>The integer <var>C</var> at the middle row and middle column</li> </ul> <p>Determine the integers written in the remaining squares in the magic square.</p> <p>It can be shown that there exists a unique magic square consistent with the given information.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0 \leq A, B, C \leq 100</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> <var>C</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Output the integers written in the magic square, in the following format:</p> <pre><var>X_{1,1}</var> <var>X_{1,2}</var> <var>X_{1,3}</var> <var>X_{2,1}</var> <var>X_{2,2}</var> <var>X_{2,3}</var> <var>X_{3,1}</var> <var>X_{3,2}</var> <var>X_{3,3}</var> </pre> <p>where <var>X_{i,j}</var> is the integer written in the square at the <var>i</var>-th row and <var>j</var>-th column.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>8 3 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>8 3 4 1 5 9 6 7 2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 1 1 1 1 1 1 1 1 </pre></section> </div> </span>
s073784356
p03388
Python
Accepted
1,554
29
9,444
q=int(input()) ab=[list(map(int,input().split())) for _ in range(q)] from math import floor for a,b in ab: # a*bをぎりぎりまで攻めたい # (1,1)とかはもったいない。(1,a*b-1)は良い。片方は√a*b未満で、片方は√a*bより大きい組み合わせ。 # a==bならa未満の整数yについて適切な数字xを選べばy*x<a*bとできる。xは他のxと被らないように選択できる。 if a==b: print(2*a-2) else: # t,t+1 組み合わせの積がa*bで抑えられているかどうか。(t+1)*(t+1)は必ずa*bを超える。 # t未満の自然数については適切な整数を選べばa*b以下にできる。 t=floor((a*b)**0.5) # (1,2*t-1),(2,2*t-2),(3,(a*b-1)//3),...,(t-1,(a*b-1)//(t-1)) if t*t>=a*b: # (t,t),(t,t+1)はだめ。この条件を満たすのはt*t=a*b、a!=bのときのみ。t未満の数字と適切な数字を選べばよいが、t未満の数字の内一つはaなので、その分を引く。 print(2*t-3) elif t*(t+1)>=a*b: # (t,t)はOK。(t,t+1)はだめ。(t,t)をまず選ぶ。t未満の数字と適切な数字を選べばよいが、t未満の数字の内一つはaなので、その分を引く。 print(2*t-2) else: # t*tもt*(t+1)もOK。(t,t+1),(t+1,t)をまず選ぶ。あとはt未満の数字と適切な数字を選べばよいが、t未満の数字の内一つはaなので、その分を引く。 print(2*t-1)
8 1 4 10 5 3 3 4 11 8 9 22 40 8 36 314159265 358979323
1 12 4 11 14 57 31 671644785
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p><var>10^{10^{10}}</var> participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through <var>10^{10^{10}}</var>-th.</p> <p>The <em>score</em> of a participant is the product of his/her ranks in the two contests.</p> <p>Process the following <var>Q</var> queries:</p> <ul> <li>In the <var>i</var>-th query, you are given two positive integers <var>A_i</var> and <var>B_i</var>. Assuming that Takahashi was ranked <var>A_i</var>-th in the first contest and <var>B_i</var>-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq Q \leq 100</var></li> <li><var>1\leq A_i,B_i\leq 10^9(1\leq i\leq Q)</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>Q</var> <var>A_1</var> <var>B_1</var> <var>:</var> <var>A_Q</var> <var>B_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>For each query, print the maximum possible number of participants whose scores are smaller than Takahashi's.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>8 1 4 10 5 3 3 4 11 8 9 22 40 8 36 314159265 358979323 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 12 4 11 14 57 31 671644785 </pre> <p>Let us denote a participant who was ranked <var>x</var>-th in the first contest and <var>y</var>-th in the second contest as <var>(x,y)</var>.</p> <p>In the first query, <var>(2,1)</var> is a possible candidate of a participant whose score is smaller than Takahashi's. There are never two or more participants whose scores are smaller than Takahashi's, so we should print <var>1</var>.</p></section> </div> </span>
s934603618
p02696
Python
Accepted
123
64
61,860
a,b,n=map(int,input().split()) x=min(b-1,n) #上記よりxとしてmin(B-1,N)を選ぶのが最善 print((a*x)//b-a*(x//b))
5 7 4
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are integers <var>A</var>, <var>B</var>, and <var>N</var>.</p> <p>Find the maximum possible value of <var>floor(Ax/B) - A × floor(x/B)</var> for a non-negative integer <var>x</var> not greater than <var>N</var>.</p> <p>Here <var>floor(t)</var> denotes the greatest integer not greater than the real number <var>t</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≤ A ≤ 10^{6}</var></li> <li><var>1 ≤ B ≤ 10^{12}</var></li> <li><var>1 ≤ N ≤ 10^{12}</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> <var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible value of <var>floor(Ax/B) - A × floor(x/B)</var> for a non-negative integer <var>x</var> not greater than <var>N</var>, as an integer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 7 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>When <var>x=3</var>, <var>floor(Ax/B)-A×floor(x/B) = floor(15/7) - 5×floor(3/7) = 2</var>. This is the maximum value possible.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>11 10 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>9 </pre></section> </div> </span>
s107222901
p02801
Python
Accepted
37
62
61,668
print(chr(ord(input().strip()) + 1))
a
b
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is a lowercase English letter <var>C</var> that is not <code>z</code>. Print the letter that follows <var>C</var> in alphabetical order.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>C</var> is a lowercase English letter that is not <code>z</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>C</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the letter that follows <var>C</var> in alphabetical order.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>a </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>b </pre> <p><code>a</code> is followed by <code>b</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>y </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>z </pre> <p><code>y</code> is followed by <code>z</code>.</p></section> </div> </span>
s970409947
p02715
Python
Accepted
934
96
69,056
n, k = map(int, input().split()) mod = 10**9 + 7 # For each X, in 1<= X <= K, let us find the number of sequences {A1, A2, .., An} with GCD = X. # The necessary and sufficient condition of the greatest common divisor being a multiple of X # is that all the A1, ..., AN are multiples of X. The number of such sequences is (floor(K/X))^N. # The necessary and sufficient condition of it being **exactly** X is that it is a multiple of X, but # not 2X, 3X.... If they are calculated in the decreasing order of X, it can be found by subtracting # the number of those of 2X, 3X # Let dp[i] store the number of sequences whose GCD is i. dp = [0]*(k+1) for i in range(k, 0, -1): # no. of sequences whose gcd is a multiple of i. dp[i] = pow(k//i, n, mod) # no. of sequences whose gcd is exactly i. for j in range(2*i, k+1, i): dp[i] -= dp[j] ans = 0 for i in range(1, k+1): ans += (i*dp[i])%mod print(ans%mod)
3 2
9
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Consider sequences <var>\{A_1,...,A_N\}</var> of length <var>N</var> consisting of integers between <var>1</var> and <var>K</var> (inclusive).</p> <p>There are <var>K^N</var> such sequences. Find the sum of <var>\gcd(A_1, ..., A_N)</var> over all of them.</p> <p>Since this sum can be enormous, print the value modulo <var>(10^9+7)</var>.</p> <p>Here <var>\gcd(A_1, ..., A_N)</var> denotes the greatest common divisor of <var>A_1, ..., A_N</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 10^5</var></li> <li><var>1 \leq K \leq 10^5</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the sum of <var>\gcd(A_1, ..., A_N)</var> over all <var>K^N</var> sequences, modulo <var>(10^9+7)</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>9 </pre> <p><var>\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)</var> <var>+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)</var> <var>=1+1+1+1+1+1+1+2=9</var></p> <p>Thus, the answer is <var>9</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 200 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>10813692 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>100000 100000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>742202979 </pre> <p>Be sure to print the sum modulo <var>(10^9+7)</var>.</p></section> </div> </span>
s893956280
p02909
Python
Accepted
113
21
8,832
S = input() if S == 'Sunny': print('Cloudy') elif S == 'Cloudy': print('Rainy') else: print('Sunny')
Sunny
Cloudy
<span class="lang-en"> <p>Score: <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>The weather in Takahashi's town changes day by day, in the following cycle: Sunny, Cloudy, Rainy, Sunny, Cloudy, Rainy, ...</p> <p>Given is a string <var>S</var> representing the weather in the town today. Predict the weather tomorrow.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>S</var> is <code>Sunny</code>, <code>Cloudy</code>, or <code>Rainy</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print a string representing the expected weather tomorrow, in the same format in which input is given.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>Sunny </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Cloudy </pre> <p>In Takahashi's town, a sunny day is followed by a cloudy day.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>Rainy </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Sunny </pre></section> </div> </span>
s113807170
p02735
Python
Accepted
623
91
74,104
H, W = map(int,input().split()) grid = [input() for _ in range(H)] dp = [[float('inf')]*(W) for _ in range(H)] dp[0][0] = 0 if grid[0][0] == '.' else 1 for i in range(H): for k in range(W): if i+1 < H: if grid[i][k] == '.' and grid[i+1][k] == '#': dp[i+1][k] = min(dp[i][k]+1,dp[i+1][k]) else: dp[i+1][k] = min(dp[i][k],dp[i+1][k]) if k+1 < W: if grid[i][k] == '.' and grid[i][k+1] == '#': dp[i][k+1] = min(dp[i][k]+1,dp[i][k+1]) else: dp[i][k+1] = min(dp[i][k],dp[i][k+1]) print(dp[-1][-1])
3 3 .## .#. ##.
1
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Consider a grid with <var>H</var> rows and <var>W</var> columns of squares. Let <var>(r, c)</var> denote the square at the <var>r</var>-th row from the top and the <var>c</var>-th column from the left. Each square is painted black or white.</p> <p>The grid is said to be <em>good</em> if and only if the following condition is satisfied:</p> <ul> <li>From <var>(1, 1)</var>, we can reach <var>(H, W)</var> by moving one square <strong>right or down</strong> repeatedly, while always being on a white square.</li> </ul> <p>Note that <var>(1, 1)</var> and <var>(H, W)</var> must be white if the grid is good.</p> <p>Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations.</p> <ul> <li>Choose four integers <var>r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W)</var>. For each pair <var>r, c</var> (<var>r_0 \leq r \leq r_1, c_0 \leq c \leq c_1</var>), invert the color of <var>(r, c)</var> - that is, from white to black and vice versa.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq H, W \leq 100</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>H</var> <var>W</var> <var>s_{11} s_{12} \cdots s_{1W}</var> <var>s_{21} s_{22} \cdots s_{2W}</var> <var>\vdots</var> <var>s_{H1} s_{H2} \cdots s_{HW}</var> </pre> <p>Here <var>s_{rc}</var> represents the color of <var>(r, c)</var> - <code>#</code> stands for black, and <code>.</code> stands for white.</p> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of operations needed.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 .## .#. ##. </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>Do the operation with <var>(r_0, c_0, r_1, c_1) = (2, 2, 2, 2)</var> to change just the color of <var>(2, 2)</var>, and we are done.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 2 #. .# </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 4 ..## #... ###. ###. </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p>No operation may be needed.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>5 5 .#.#. #.#.# .#.#. #.#.# .#.#. </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>4 </pre></section> </div> </span>
s498456168
p00007
Python
Accepted
138
10
4,708
import math price = 100000.0 n = int(raw_input()) for i in range(n): price = math.ceil((price * 1.05) / 1000) * 1000 print int(price)
5
130000
<H1>Debt Hell</H1> <p> Your friend who lives in undisclosed country is involved in debt. He is borrowing 100,000-yen from a loan shark. The loan shark adds 5% interest of the debt and rounds it to the nearest 1,000 above week by week. </p> <p> Write a program which computes the amount of the debt in <var>n</var> weeks. </p> <H2>Input</H2> <p> An integer <var>n</var> (0 &le; <var>n</var> &le; 100) is given in a line. </p> <H2>Output</H2> <p> Print the amout of the debt in a line. </p> <H2>Sample Input</H2> <pre> 5 </pre> <H2>Output for the Sample Input</H2> <pre> 130000 </pre>
s889897473
p02847
Python
Accepted
122
28
8,972
def resolve(): week = ['SUN','MON','TUE','WED','THU','FRI','SAT'] s = input() print(7-week.index(s)) resolve()
SAT
1
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is a string <var>S</var> representing the day of the week today.</p> <p><var>S</var> is <code>SUN</code>, <code>MON</code>, <code>TUE</code>, <code>WED</code>, <code>THU</code>, <code>FRI</code>, or <code>SAT</code>, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.</p> <p>After how many days is the next Sunday (tomorrow or later)?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>S</var> is <code>SUN</code>, <code>MON</code>, <code>TUE</code>, <code>WED</code>, <code>THU</code>, <code>FRI</code>, or <code>SAT</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of days before the next Sunday.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>SAT </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>It is Saturday today, and tomorrow will be Sunday.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>SUN </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>7 </pre> <p>It is Sunday today, and seven days later, it will be Sunday again.</p></section> </div> </span>
s045969688
p00606
Python
Accepted
1,068
20
6,400
time = -1 place = ["a","b","c","d","e","f","g","h","i"] empty_count={} for i in place: empty_count[i] = 0 count_d = empty_count.copy() def reset(): global d global count_d d={"a":["a","a","b","d"],"b":["a","e","c","b"],"c":["b","f","c","c"],"d":["a","e","g","d"],"e":["b","d","f","h"],"f":["c","e","i","f"],"g":["d","h","g","g"],"h":["g","e","i","h"],"i":["f","h","i","i"]} count_d = empty_count.copy() def pre_set(start_place,fix_place): global d global count_d for i in place: d[i] = list(("").join(d[i]).replace(fix_place,i)) count_d[start_place] = 1 def repeat(time): global count_d for i in range (time): new_count_d = empty_count.copy() old_count_d = count_d.copy() for j in place: for k in d[j]: new_count_d[k] += old_count_d[j] count_d = new_count_d.copy() while time != 0: time = int(raw_input()) if time == 0: break else: info_pre = raw_input().split() info = [] for i in info_pre: info.append(i.lower()) reset() pre_set(info[0],info[2]) repeat(time) print (count_d[info[1]])/float((4**time))
1 E A C 1 E B C 2 E A B 0
0.00000000 0.25000000 0.06250000
<H1><font color="#000000">Problem B:</font> Cleaning Robot</H1> <p> Dr. Asimov, a robotics researcher, loves to research, but hates houseworks and his house were really dirty. So, he has developed a cleaning robot. </p> <p> As shown in the following figure, his house has 9 rooms, where each room is identified by an alphabet: </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cleaningRobot"> </center> <br> <p> The robot he developed operates as follows: </p> <ul> <li> If the battery runs down, the robot stops. </li> <li> If not so, the robot chooses a direction from four cardinal points with the equal probability, and moves to the room in that direction. Then, the robot clean the room and consumes 1 point of the battery. </li> <li> However, if there is no room in that direction, the robot does not move and remains the same room. In addition, there is a junk room in the house where the robot can not enter, and the robot also remains when it tries to enter the junk room. The robot also consumes 1 point of the battery when it remains the same place. </li> </ul> <p> A battery charger for the robot is in a room. It would be convenient for Dr. Asimov if the robot stops at the battery room when its battery run down. </p> <p> Your task is to write a program which computes the probability of the robot stopping at the battery room. </p> <H2>Input</H2> <p> The input consists of several datasets. Each dataset consists of: </p> <pre> <i>n</i> <i>s t b</i> </pre> <p> <i>n</i> is an integer that indicates the initial battery point. <i>s</i>, <i>t</i>, <i>b</i> are alphabets respectively represent the room where the robot is initially, the battery room, and the junk room. </p> <p> The input ends with a dataset which consists of single 0 for <i>n</i>. Your program should not output for this dataset. </p> <H2>Output</H2> <p> For each dataset, print the probability as a floating point number in a line. The answer may not have an error greater than 0.000001. </p> <H2>Constraints</H2> <ul> <li>Judge data includes at most 100 data sets.</li> <li><i>n</i> &le; 15</li> <li><i>s</i>, <i>t</i>, <i>b</i> are distinct.</li> </ul> <H2>Sample Input</H2> <pre> 1 E A C 1 E B C 2 E A B 0 </pre> <H2>Output for the Sample Input</H2> <pre> 0.00000000 0.25000000 0.06250000 </pre>
s981851807
p03742
Python
Accepted
61
67
61,644
print(["Alice","Brown"][-1<=eval(input().replace(*" -"))<=1])
2 1
Brown
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Alice and Brown loves games. Today, they will play the following game.</p> <p>In this game, there are two piles initially consisting of <var>X</var> and <var>Y</var> stones, respectively. Alice and Bob alternately perform the following operation, starting from Alice:</p> <ul> <li>Take <var>2i</var> stones from one of the piles. Then, throw away <var>i</var> of them, and put the remaining <var>i</var> in the other pile. Here, the integer <var>i</var> <var>(1≤i)</var> can be freely chosen as long as there is a sufficient number of stones in the pile.</li> </ul> <p>The player who becomes unable to perform the operation, loses the game.</p> <p>Given <var>X</var> and <var>Y</var>, determine the winner of the game, assuming that both players play optimally.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0 ≤ X, Y ≤ 10^{18}</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>X</var> <var>Y</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the winner: either <code>Alice</code> or <code>Brown</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Brown </pre> <p>Alice can do nothing but taking two stones from the pile containing two stones. As a result, the piles consist of zero and two stones, respectively. Then, Brown will take the two stones, and the piles will consist of one and zero stones, respectively. Alice will be unable to perform the operation anymore, which means Brown's victory.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Alice </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>0 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Brown </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>4 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>Alice </pre></section> </div> </span>
s322831715
p02415
Python
Accepted
81
20
5,548
def main(): print(input().swapcase()) if __name__ == '__main__': main()
fAIR, LATER, OCCASIONALLY CLOUDY.
Fair, later, occasionally cloudy.
<H1>Toggling Cases</H1><br> <p> Write a program which converts uppercase/lowercase letters to lowercase/uppercase for a given string. </p> <H2>Input</H2> <p> A string is given in a line. </p> <H2>Output</H2> <p> Print the converted string in a line. Note that you do not need to convert any characters other than alphabetical letters. </p> <h2>Constraints</h2> <ul> <li>The length of the input string &lt; 1200</li> </ul> <H2>Sample Input</H2> <pre> fAIR, LATER, OCCASIONALLY CLOUDY. </pre> <H2>Sample Output</H2> <pre> Fair, later, occasionally cloudy. </pre>
s885658910
p02939
Python
Accepted
126
67
9,304
s = input() ans = 0 a = b = "" for i in s: b += i if a != b: a = b b = "" ans += 1 print(ans)
aabbaa
4
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is a string <var>S</var> consisting of lowercase English letters. Find the maximum positive integer <var>K</var> that satisfies the following condition:</p> <ul> <li>There exists a partition of <var>S</var> into <var>K</var> non-empty strings <var>S=S_1S_2...S_K</var> such that <var>S_i \neq S_{i+1}</var> (<var>1 \leq i \leq K-1</var>).</li> </ul> <p>Here <var>S_1S_2...S_K</var> represents the concatenation of <var>S_1,S_2,...,S_K</var> in this order.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |S| \leq 2 \times 10^5</var></li> <li><var>S</var> consists of lowercase English letters.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum positive integer <var>K</var> that satisfies the condition.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>aabbaa </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>We can, for example, divide <var>S</var> into four strings <code>aa</code>, <code>b</code>, <code>ba</code>, and <code>a</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>aaaccacabaababc </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>12 </pre></section> </div> </span>
s594356635
p00148
Python
Accepted
66
10
4,188
while 1: try: print '3C%02d' %((input()-1)%39+1) except: break
50 5576 5577 5578
3C11 3C38 3C39 3C01
<H1>キャンディーとクラス旗</H1> <p> 3年C組では、平成19年11月10日の体育祭で使用する「クラス旗」を、将来のクラス会の時にも使うことにしました。そこで「クラス旗」を保管する生徒を決めるために、先生が先日差し入れてくれた大量のキャンディーを使って次のようなゲームを行うことにしました。 </p> <ul> <li>各生徒は生徒番号の順に1個ずつキャンディーを取ります。</li> <li>一巡してもキャンディーが残っていたら、最初の生徒番号の人から順々にキャンディーを取り続けます。</li> <li>最後のキャンディーを取った人が「クラス旗」を保管する生徒になります。</li> </ul> <p> 3年C組のクラスの人数は 39 人です。彼らの生徒番号は 3C01 から 3C39 です。例えば、キャンディーの数が 50 個の場合、クラス全員が1個目のキャンディーを取り終えると、キャンディーの残りは 11 個となります。それを再び生徒番号順に取ると、最後の 1 個は、3C11 の生徒が取ることとなります。すなわち 3C11 の生徒が「クラス旗」を保管する生徒となります。 </p> <p> キャンディーの個数を入力とし、「クラス旗」を保管する生徒の生徒番号を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 複数のテストケースが与えられます。各テストケースは以下の形式で与えられます。各テストケースとして、キャンディーの個数を表す整数 <var>a</var> (1 &le; <var>a</var> &le; 10000) が1行に与えられます。入力の最後(EOF)まで処理してください。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> 各テストケースごとに、「クラス旗」を保管する生徒の生徒番号(半角英数字)を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> 50 5576 5577 5578 </pre> <H2>Output for the Sample Input</H2> <pre> 3C11 3C38 3C39 3C01 </pre>
s908556789
p02553
Python
Accepted
71
29
8,984
a, b, c, d = map(int, input().split()) print(max([a*c, b*c, a*d, b*d]))
1 2 1 1
2
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are integers <var>a,b,c</var> and <var>d</var>. If <var>x</var> and <var>y</var> are integers and <var>a \leq x \leq b</var> and <var>c\leq y \leq d</var> hold, what is the maximum possible value of <var>x \times y</var>?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>-10^9 \leq a \leq b \leq 10^9</var></li> <li><var>-10^9 \leq c \leq d \leq 10^9</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>a</var> <var>b</var> <var>c</var> <var>d</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 2 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>If <var>x = 1</var> and <var>y = 1</var> then <var>x \times y = 1</var>. If <var>x = 2</var> and <var>y = 1</var> then <var>x \times y = 2</var>. Therefore, the answer is <var>2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 5 -4 -2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-6 </pre> <p>The answer can be negative.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>-1000000000 0 -1000000000 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1000000000000000000 </pre></section> </div> </span>
s511681237
p02945
Python
Accepted
173
23
9,172
A,B=map(int,input().split()) if (A+B)>=(A-B) and (A+B)>=(A*B): print(A+B) elif (A-B)>=(A+B) and (A-B)>=(A*B): print(A-B) elif (A*B)>=(A+B) and (A*B)>=(A-B): print(A*B)
-13 3
-10
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have two integers: <var>A</var> and <var>B</var>.</p> <p>Print the largest number among <var>A + B</var>, <var>A - B</var>, and <var>A \times B</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>-100 \leq A,\ B \leq 100</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the largest number among <var>A + B</var>, <var>A - B</var>, and <var>A \times B</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>-13 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>-10 </pre> <p>The largest number among <var>A + B = -10</var>, <var>A - B = -16</var>, and <var>A \times B = -39</var> is <var>-10</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 -33 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>34 </pre> <p>The largest number among <var>A + B = -32</var>, <var>A - B = 34</var>, and <var>A \times B = -33</var> is <var>34</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>13 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>39 </pre> <p>The largest number among <var>A + B = 16</var>, <var>A - B = 10</var>, and <var>A \times B = 39</var> is <var>39</var>.</p></section> </div> </span>
s250337778
p02419
Python
Accepted
495
20
5,564
def main(): Counter = 0 Text_W = input() while True: Text_T = input() if "END_OF_TEXT" in Text_T: temp = Text_T.lower().split() for i in range(len(temp)): Counter += 1 if Text_W == temp[i] else 0 break else: temp = Text_T.lower().split() for i in range(len(temp)): Counter += 1 if Text_W == temp[i] else 0 print (Counter) if __name__ == '__main__': main()
computer Nurtures computer scientists and highly-skilled computer engineers who will create and exploit "knowledge" for the new era. Provides an outstanding computer environment. END_OF_TEXT
3
<H1>Finding a Word</H1><br> <p> Write a program which reads a word <var>W</var> and a text <var>T</var>, and prints the number of word <var>W</var> which appears in text <var>T</var> </p> <p> <var>T</var> consists of string <var>T<sub>i</sub></var> separated by space characters and newlines. Count the number of <var>T<sub>i</sub></var> which equals to <var>W</var>. The word and text are case insensitive. </p> <H2>Constraints</H2> <ul> <li>The length of <var>W</var> &le; 10</li> <li><var>W</var> consists of lower case letters</li> <li>The length of <var>T</var> in a line &le; 1000</li> </ul> <H2>Input</H2> <p> In the first line, the word <var>W</var> is given. In the following lines, the text <var>T</var> is given separated by space characters and newlines. </p> <p> "<span>END_OF_TEXT</span>" indicates the end of the text. </p> <H2>Output</H2> <p> Print the number of <var>W</var> in the text. </p> <H2>Sample Input</H2> <pre> computer Nurtures computer scientists and highly-skilled computer engineers who will create and exploit "knowledge" for the new era. Provides an outstanding computer environment. END_OF_TEXT </pre> <H2>Sample Output</H2> <pre> 3 </pre>
s697218269
p03136
Python
Accepted
273
26
8,896
# listを並び替えてif-elseで条件分岐 N = int(input()) L = list(map(int, input().split())) descending_L = sorted(L, reverse=True) # print(descending_L) other_side = sum(descending_L[1:]) if descending_L[0] < other_side: print('Yes') else: print('No')
4 3 8 5 1
Yes
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Determine if an <var>N</var>-sided polygon (not necessarily convex) with sides of length <var>L_1, L_2, ..., L_N</var> can be drawn in a two-dimensional plane.</p> <p>You can use the following theorem:</p> <p><strong>Theorem</strong>: an <var>N</var>-sided polygon satisfying the condition can be drawn if and only if the longest side is strictly shorter than the sum of the lengths of the other <var>N-1</var> sides.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>3 \leq N \leq 10</var></li> <li><var>1 \leq L_i \leq 100</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>L_1</var> <var>L_2</var> <var>...</var> <var>L_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If an <var>N</var>-sided polygon satisfying the condition can be drawn, print <code>Yes</code>; otherwise, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 3 8 5 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>Since <var>8 &lt; 9 = 3 + 5 + 1</var>, it follows from the theorem that such a polygon can be drawn on a plane.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 3 8 4 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <p>Since <var>8 \geq 8 = 3 + 4 + 1</var>, it follows from the theorem that such a polygon cannot be drawn on a plane.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 1 8 10 5 8 12 34 100 11 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>No </pre></section> </div> </span>
s678635123
p02321
Python
Accepted
1,174
20
5,628
import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) def branchAndBound(N, items, lim_w): items.sort(key=lambda x: x[0] / x[1], reverse=True) Value = [] Weight = [] Ratio = [] for v, w in items: Value.append(v) Weight.append(w) Ratio.append(v / w) def upperbound(cur, cur_w, cur_v): rest_w = lim_w - cur_w max_v = ub_v = cur_v for j in range(cur + 1, N): if Weight[j] <= rest_w: rest_w -= Weight[j] max_v += Value[j] ub_v = max_v else: ub_v += Ratio[j] * rest_w break return max_v, ub_v answer_v, ub_v = upperbound(-1, 0, 0) def dfs(cur, ub_v, cur_w, cur_v): nonlocal answer_v if answer_v > ub_v or cur == N: return if cur_w + Weight[cur] <= lim_w: dfs(cur + 1, ub_v, cur_w + Weight[cur], cur_v + Value[cur]) max_v, ub_v = upperbound(cur, cur_w, cur_v) if max_v > answer_v: answer_v = max_v if ub_v > answer_v: dfs(cur + 1, ub_v, cur_w, cur_v) dfs(0, ub_v, 0, 0) return answer_v def main(): N, lim_w = map(int, input().split()) items = [list(map(int, input().split())) for _ in range(N)] print(branchAndBound(N, items, lim_w)) if __name__ == "__main__": main()
4 5 4 2 5 2 2 1 8 3
13
<H1>Huge Knapsack Problem</H1> <br/> <p> You have <var>N</var> items that you want to put them into a knapsack. Item <var>i</var> has value <var>v<sub>i</sub></var> and weight <var>w<sub>i</sub></var>. </p> <p> You want to find a subset of items to put such that: </p> <ul> <li>The total value of the items is as large as possible.</li> <li>The items have combined weight at most <var>W</var>, that is capacity of the knapsack.</li> </ul> <p> Find the maximum total value of items in the knapsack. </p> <H2>Input</H2> <pre> <var>N</var> <var>W</var> <var>v<sub>1</sub></var> <var>w<sub>1</sub></var> <var>v<sub>2</sub></var> <var>w<sub>2</sub></var> : <var>v<sub>N</sub></var> <var>w<sub>N</sub></var> </pre> <p> The first line consists of the integers <var>N</var> and <var>W</var>. In the following <var>N</var> lines, the value and weight of the <var>i</var>-th item are given. </p> <H2>Output</H2> <p> Print the maximum total values of the items in a line. </p> <h2>Constraints</h2> <ul> <li> 1 &le; <var>N</var> &le; 40</li> <li> 1 &le; <var>v<sub>i</sub></var> &le; 10<sup>15</sup></li> <li> 1 &le; <var>w<sub>i</sub></var> &le; 10<sup>15</sup></li> <li> 1 &le; <var>W</var> &le; 10<sup>15</sup></li> </ul> <H2>Sample Input 1</H2> <pre> 4 5 4 2 5 2 2 1 8 3 </pre> <H2>Sample Output 1</H2> <pre> 13 </pre> <br/> <H2>Sample Input 2</H2> <pre> 2 20 5 9 4 10 </pre> <H2>Sample Output 2</H2> <pre> 9 </pre>
s827019671
p02859
Python
Accepted
28
28
8,836
r = int(input()) print(r*r)
2
4
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is an integer <var>r</var>.</p> <p>How many times is the area of a circle of radius <var>r</var> larger than the area of a circle of radius <var>1</var>?</p> <p>It can be proved that the answer is always an integer under the constraints given.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq r \leq 100</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>r</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the area of a circle of radius <var>r</var>, divided by the area of a circle of radius <var>1</var>, as an integer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>The area of a circle of radius <var>2</var> is <var>4</var> times larger than the area of a circle of radius <var>1</var>.</p> <p>Note that output must be an integer - for example, <code>4.0</code> will not be accepted.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>10000 </pre></section> </div> </span>
s171758791
p03369
Python
Accepted
39
20
8,704
s=input() print((s.count('o'))*100+700)
oxo
900
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs <var>700</var> yen (the currency of Japan), plus <var>100</var> yen for each kind of topping (boiled egg, sliced pork, green onions).</p> <p>A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string <var>S</var>. <var>S</var> is three characters long, and if the first character in <var>S</var> is <code>o</code>, it means the ramen should be topped with boiled egg; if that character is <code>x</code>, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in <var>S</var> mean the presence or absence of sliced pork and green onions on top of the ramen.</p> <p>Write a program that, when <var>S</var> is given, prints the price of the corresponding bowl of ramen.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>S</var> is a string of length <var>3</var>.</li> <li>Each character in <var>S</var> is <code>o</code> or <code>x</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the price of the bowl of ramen corresponding to <var>S</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>oxo </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>900 </pre> <p>The price of a ramen topped with two kinds of toppings, boiled egg and green onions, is <var>700 + 100 \times 2 = 900</var> yen.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>ooo </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1000 </pre> <p>The price of a ramen topped with all three kinds of toppings is <var>700 + 100 \times 3 = 1000</var> yen.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>xxx </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>700 </pre> <p>The price of a ramen without any toppings is <var>700</var> yen.</p></section> </div> </span>
s006555876
p02399
Python
Accepted
208
20
5,624
#coding:utf-8 ''' a ÷ b : d (整数) a ÷ b の余り : r (整数) a ÷ b : f (浮動小数点数) ''' a, b = map(int, input().split()) d = a // b r = a % b f = a / b print('%d %d %.8f' % (d, r, f))
3 2
1 1 1.50000
<H1>A/B Problem</H1> <p> Write a program which reads two integers <var>a</var> and <var>b</var>, and calculates the following values: </p> <ul> <li><var>a</var> &divide; <var>b</var>: <var>d</var> (in integer)</li> <li>remainder of <var>a</var> &divide; <var>b</var>: <var>r</var> (in integer)</li> <li><var>a</var> &divide; <var>b</var>: <var>f</var> (in real number)</li> </ul> <H2>Input</H2> <p> Two integers <var>a</var> and <var>b</var> are given in a line. </p> <H2>Output</H2> <p> Print <var>d</var>, <var>r</var> and <var>f</var> separated by a space in a line. For <var>f</var>, the output should not contain an absolute error greater than 10<sup>-5</sup>. </p> <h2>Constraints</h2> <ul> <li> 1 &le; <var>a</var>, <var>b</var> &le; 10<sup>9</sup></li> </ul> <H2>Sample Input 1</H2> <pre> 3 2 </pre> <H2>Sample Output 1</H2> <pre> 1 1 1.50000 </pre>
s996136946
p01859
Python
Accepted
1,204
20
5,608
li, ri = map(int, input().split()) ln, rn = map(int, input().split()) ISONO = True NAKAJIMA = False def search(li, ri, ln, rn, turn): if li == None and ri == None: return False if ln == None and rn == None: return True if turn == ISONO: ret = False if li and ln: ret = ret or search(li, ri, ln + li if ln + li < 5 else None, rn, not turn) if li and rn: ret = ret or search(li, ri, ln, rn + li if rn + li < 5 else None, not turn) if ri and ln: ret = ret or search(li, ri, ln + ri if ln + ri < 5 else None, rn, not turn) if ri and rn: ret = ret or search(li, ri, ln, rn + ri if rn + ri < 5 else None, not turn) if turn == NAKAJIMA: ret = True if li and ln: ret = ret and search(li + ln if li + ln < 5 else None, ri, ln, rn, not turn) if li and rn: ret = ret and search(li + rn if li + rn < 5 else None, ri, ln, rn, not turn) if ri and ln: ret = ret and search(li, ri + ln if ri + ln < 5 else None, ln, rn, not turn) if ri and rn: ret = ret and search(li, ri + rn if ri + rn < 5 else None, ln, rn, not turn) return ret if search(li, ri, ln, rn, ISONO): print("ISONO") else: print("NAKAJIMA")
3 2 2 2
NAKAJIMA
<!--<script language="JavaScript" type="text/javascript" src="js/varmath.js" charset="UTF-8"></script>--> <h2>B: 中島、あれやろうぜ! - Match Peas War -</h2> <h3>問題</h3> <p>中島「うぅっ・・・」</p> <p>磯野「中島,大丈夫か?」</p> <p>中島「・・・なんだか嫌な夢を見ていた気がするよ」</p> <p>磯野「どんな夢だい?」</p> <p>中島「無限に遊ぶ夢」</p> <p>磯野「意味わからん.まぁいいや,中島,あれやろうぜ!」</p> <p>中島「あれってまさか,あれじゃないよな・・・」</p> <p>磯野「あれだよ,あれ」</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2015HokudaiPC_are" type="image/jpeg" width="300"></img> <p>中島「おっ,いいじゃないか!やろうやろう」</p> <p>磯野「それじゃあ,まずはじゃんけんだな!」</p> <p>なにやら,公園で2人の子供が遊んでいるようです.懐かしさを感じますね.ところで,あなたは『マッチ・グリーンピース・戦争』などと呼ばれる手遊びを知っていますか?その名称にピンとこなかったとしても,きっと,子供時代に幾度となく遊んだことがあるでしょう.</p> <p>ここでは,『マッチ・グリーンピース・戦争』のルールを簡略化した手遊びを考え,『あれ』と名付けます.『あれ』は次のような2人プレイの遊びです.</p> <pre> (1).各プレイヤーが両手の指を1本ずつ立てた状態から遊びを開始する. (2).先手のプレイヤーから順番に以下の(3)〜(5)を行う. (3).プレイヤーは,自身のどちらか一方の手で相手のどちらか一方の手に触れる. (4).触れられた手は,触れた手に立っている指の本数だけ追加で指を立てる. ここで,5本以上の指が立つべき状況になった手は退場する. (退場した手は,今後触れたり触れられるときに選ばれることはない.) (5).両手とも退場したプレイヤーがいるかどうか確認する.いるならば,両プレイヤーは(6)に従う. (6).遊びを終了する.このとき,少なくとも一方の手が残っているプレイヤーが勝者である. </pre> <p>磯野「よーし,僕からだね!」</p> <p>おや?どうやら,磯野君が先手になったようですね.2人の遊びの行く末を見守ってみましょう.</p> <p>磯野「じゃあ僕は,右手に2本,左手に1本ではじめるよ!」</p> <p>中島「それなら僕は,右手に2本,左手に2本でいくよ!」</p> <p>ちょっと待て,なんだそのルールは&minus;</p> <p>どうやら,磯野君たちの間では,遊び開始時に各手に立っている指の本数を1 〜 4本のうち自由に決められるようです.ローカルルールってやつですね.</p> <p>『あれ』のような類の遊びは,先手後手でどちらが必勝なのかを簡単に調べることができます.しかし,『あれ』に磯野君たちのローカルルールを取り入れると,先手後手の勝敗が変わってきそうです.とても気になりますね.皆さんも興味がおありなのでは?もしそうならば,実際に調査してみましょう.</p> <p>磯野君と中島君がローカルルールを取り入れた『あれ』で遊ぶとします.磯野君が先手と仮定して,磯野君の左手には<var>L_i</var>本,右手には<var>R_i</var>本の指が,中島君の左手には<var>L_n</var>本,右手には<var>R_n</var>本の指が立っているとします.2人とも最適な行動を選択する場合,どちらが勝つかを判定してください.</p> <h3>入力形式</h3> <p>入力は以下の形式で与えられる.</p> <pre> <var>L_i</var> <var>R_i</var> <var>L_n</var> <var>R_n</var> </pre> <p>1行目には磯野君の手の初期状態を表す<var>L_i</var>,<var>R_i</var>が空白区切りで与えられる.<var>L_i</var>は左手で立っている指の本数,<var>R_i</var>は右手で立っている指の本数である.</p> <p>2行目には中島君の手の初期状態を表す<var>L_n</var>,<var>R_n</var>が空白区切りで与えられる.<var>L_n</var>は左手で立っている指の本数,<var>R_n</var>は右手で立っている指の本数である.</p> <p>また,入力は以下の制約を満たす.</p> <pre><var>1 &le; L_i, R_i, L_n, R_n &le; 4</var></pre> <h3>出力形式</h3> <p>磯野君が勝つ場合は“ISONO”を,中島君が勝つ場合は“NAKAJIMA”を1行に出力せよ.</p> <h3>入力例1</h3> <pre> 3 2 2 2 </pre> <h3>出力例1</h3> <pre>NAKAJIMA</pre> <h3>入力例2</h3> <pre> 3 2 2 3 </pre> <h3>出力例2</h3> <pre>ISONO</pre> <h3>入力例3</h3> <pre> 1 1 1 1 </pre> <h3>出力例3</h3> <pre>NAKAJIMA</pre> <p>『あれ』は後手で常勝</p>
s209541683
p00081
Python
Accepted
299
10
4,232
import sys for s in sys.stdin: x1,y1,x2,y2,xq,yq = map(float,s.split(",")) dx,dy = x2-x1,y2-y1 det = dx*dx+dy*dy y0 = dx*(y1*dx-x1*dy) + dy*(yq*dy+xq*dx) x0 = -dy*(y1*dx-x1*dy) + dx*(yq*dy+xq*dx) x0 /= det y0 /= det xp = x0+(x0-xq) yp = y0+(y0-yq) print xp,yp
1.0,0.0,-1.0,0.0,1.0,1.0 1.0,0.0,0.0,-1.0,3.0,0.0 0.0,1.0,0.0,-1.0,1.0,1.0
1.000000 -1.000000 1.000000 2.000000 -1.000000 1.000000
<H1>線対称</H1> <p> 平面上の異なる 3 点 <var>P1(x1,y1)</var>, <var>P2(x2,y2)</var>, <var>Q(xq,yq)</var> の座標の組を読み込んで、点 <var>P1</var> 点<var>P2</var> を通る直線を対称軸として点 <var>Q</var> と線対称の位置にある点 <var>R(x,y)</var> を出力するプログラムを作成してください。なお、点 <var>Q</var> は、その対称軸上にないものとします。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_09_1"> </center> <H2>入力</H2> <p> 入力は複数のデータセットからなります。各データセットは以下の形式で与えられます。 </p> <pre> <var>x1</var>,<var>y1</var>,<var>x2</var>,<var>y2</var>,<var>xq</var>,<var>yq</var> </pre> <p> <var>x1</var>, <var>y1</var>, <var>x2</var>, <var>y2</var>, <var>xq</var>, <var>yq</var> (-100 以上 100 以下の実数) がカンマ区切りで1行に与えられます。 </p> <p> データセットの数は 50 を超えない。 </p> <H2>出力</H2> <p> データセットごとに、<var>x</var>, <var>y</var> を空白区切りで 1 行に出力する。出力は実数で 0.0001 以下の誤差を含んでもよい。 </p> <H2>Sample Input</H2> <pre> 1.0,0.0,-1.0,0.0,1.0,1.0 1.0,0.0,0.0,-1.0,3.0,0.0 0.0,1.0,0.0,-1.0,1.0,1.0 </pre> <H2>Output for the Sample Input</H2> <pre> 1.000000 -1.000000 1.000000 2.000000 -1.000000 1.000000 </pre>
s848963629
p02016
Python
Accepted
74
20
5,540
s = input() if s == "ani": print("square1001") else: print("e869120")
ani
square1001
<h2>B: 双子 (Twins)</h2> <p>とある双子は、自分たちのどちらが兄でどちらが弟かがあまり知られていないことに腹を立てた。</p> <p>"ani" と入力されたら "square1001"、"otouto" と入力されたら "e869120" と出力するプログラムを作りなさい。</p> <h3>入力</h3> <p>入力として "ani" または "otouto" という文字列のどちらかが与えられます。</p> <h3>出力</h3> <p>"e869120" または "square1001" を、問題文の通りに出力してください。最後の改行を忘れないようにしましょう。</p> <h3>入力例1</h3> <pre> ani </pre> <h3>出力例1</h3> <pre> square1001 </pre> <h3>入力例2</h3> <pre> otouto </pre> <h3>出力例2</h3> <pre> e869120 </pre>
s731849660
p02022
Python
Accepted
116
100
18,516
n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) print(sum(a)*sum(b))
3 2 3 1 5 2 4
54
<h2>H: 慈悲 (Mercy)</h2> <p>サンタクロースは、クリスマスなのにプログラミングをやっている集団を見つけた。</p> <p>サンタクロースは彼らを可哀想に思ったので、ケーキをプレゼントすることにした。</p> <p>クリームが $N$ 種類あって、美味しさは $A_1, A_2, A_3, \dots, A_N$ である。</p> <p>スポンジが $M$ 種類あって、美味しさは $B_1, B_2, B_3, \dots, B_M$ である。</p> <p>クリーム 1 種類とスポンジ 1 種類を組み合わせてケーキを作り、その美味しさは (クリームの美味しさ) × (スポンジの美味しさ) になる。</p> <p>サンタクロースは慈悲深いので、$N \times M$ 通りの組み合わせのケーキをすべて一つずつ作った。</p> <p>ケーキの美味しさは合計いくつか。</p> <h3>入力</h3> <p>1 行目には、整数 $N, M$ が空白区切りで与えられる。</p> <p>2 行目には、整数 $A_1, A_2, A_3, \dots, A_N$ が空白区切りで与えられる。</p> <p>3 行目には、整数 $B_1, B_2, B_3, \dots, B_M$ が空白区切りで与えられる。</p> <h3>出力</h3> <p>サンタクロースの作ったケーキの美味しさの合計を出力せよ。最後には改行を入れること。</p> <h3>制約</h3> <ul> <li>$N, M$ は $1$ 以上 $100 \ 000$ 以下の整数</li> <li>$A_1, A_2, A_3, \dots, A_N$ は $1$ 以上 $1 \ 000$ 以下の整数</li> <li>$B_1, B_2, B_3, \dots, B_M$ は $1$ 以上 $1 \ 000$ 以下の整数</li> </ul> <h3>注意</h3> <p>答えが 32 bit 整数型 (int 型など) の範囲に収まらない可能性があるので、64 bit 整数型 (long long 型など) を使いましょう。</p> <h3>入力例1</h3> <pre> 3 2 3 1 5 2 4 </pre> <h3>出力例1</h3> <pre> 54 </pre> <p>サンタクロースは、次の 6 種類のケーキを作ります。</p> <ul> <li>クリーム 1 とスポンジ 1 を組み合わせたケーキの美味しさ:$3 \times 2 = 6$</li> <li>クリーム 1 とスポンジ 2 を組み合わせたケーキの美味しさ:$3 \times 4 = 12$</li> <li>クリーム 2 とスポンジ 1 を組み合わせたケーキの美味しさ:$1 \times 2 = 2$</li> <li>クリーム 2 とスポンジ 2 を組み合わせたケーキの美味しさ:$1 \times 4 = 4$</li> <li>クリーム 3 とスポンジ 1 を組み合わせたケーキの美味しさ:$5 \times 2 = 10$</li> <li>クリーム 3 とスポンジ 2 を組み合わせたケーキの美味しさ:$5 \times 4 = 20$</li> </ul> <p>合計の美味しさは $54$ となります。</p> <h3>入力例2</h3> <pre> 10 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 </pre> <h3>出力例2</h3> <pre> 3025 </pre>
s386184267
p00595
Python
Accepted
208
20
4,200
def gcd(m,n): while m%n>0: m,n=n,m%n else: return n while True: try: m,n = map(int,raw_input().split()) print gcd(m,n) except EOFError: break
57 38 60 84
19 12
<H1><font color="#000000">Problem A:</font> Greatest Common Divisor</H1> <p> Please find the greatest common divisor of two natural numbers. A clue is: The Euclid's algorithm is a way to resolve this task. </p> <H2>Input</H2> <p> The input file consists of several lines with pairs of two natural numbers in each line. The numbers do not exceed 100000. </p> <p> The number of pairs (datasets) is less than 50. </p> <H2>Output</H2> <p> Your program has to print the greatest common divisor for each pair of input numbers. Print each result on a new line. </p> <H2>Sample Input</H2> <pre> 57 38 60 84 </pre> <H2>Output for the Sample Input</H2> <pre> 19 12 </pre>
s607631239
p03332
Python
Accepted
429
94
85,200
n,a,b,k=map(int,input().split()) mod1,mod2=10**9+7,998244353 mod=mod2 fact=[1]*(n+1) inv=[1]*(n+1) for i in range(2,n+1): fact[i]=i*fact[i-1]%mod inv[-1]=pow(fact[-1],mod-2,mod) for i in range(n,1,-1): inv[i-1]=inv[i]*i%mod def comb(x,y):return fact[x]*inv[y]%mod*inv[x-y]%mod if x>=y>=0 else 0 ans=0 for i in range(n+1): if (k-(a*i))%b:continue o=(k-(a*i))//b ans=(ans+comb(n,i)*comb(n,o)%mod)%mod print(ans)
4 1 2 5
40
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi has a tower which is divided into <var>N</var> layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the <em>beauty of the tower</em> as follows:</p> <ul> <li>The beauty of the tower is the sum of the scores of the <var>N</var> layers, where the score of a layer is <var>A</var> if the layer is painted red, <var>A+B</var> if the layer is painted green, <var>B</var> if the layer is painted blue, and <var>0</var> if the layer is uncolored.</li> </ul> <p>Here, <var>A</var> and <var>B</var> are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors.</p> <p>Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly <var>K</var>. How many such ways are there to paint the tower? Find the count modulo <var>998244353</var>. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≤ N ≤ 3×10^5</var></li> <li><var>1 ≤ A,B ≤ 3×10^5</var></li> <li><var>0 ≤ K ≤ 18×10^{10}</var></li> <li>All values in the input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A</var> <var>B</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the ways to paint tiles, modulo <var>998244353</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 1 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>40 </pre> <p>In this case, a red layer worth <var>1</var> points, a green layer worth <var>3</var> points and the blue layer worth <var>2</var> points. The beauty of the tower is <var>5</var> when we have one of the following sets of painted layers:</p> <ul> <li><var>1</var> green, <var>1</var> blue</li> <li><var>1</var> red, <var>2</var> blues</li> <li><var>2</var> reds, <var>1</var> green</li> <li><var>3</var> reds, <var>1</var> blue</li> </ul> <p>The total number of the ways to produce them is <var>40</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 5 6 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> <p>The beauty of the tower is <var>0</var> only when all the layers are uncolored. Thus, the answer is <var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>90081 33447 90629 6391049189 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>577742975 </pre></section> </div> </span>
s858597585
p03834
Python
Accepted
49
21
9,028
haike = input().split(',') print(' '.join(haike))
happy,newyear,enjoy
happy newyear enjoy
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>As a New Year's gift, Dolphin received a string <var>s</var> of length <var>19</var>.<br/> The string <var>s</var> has the following format: <code>[five lowercase English letters],[seven lowercase English letters],[five lowercase English letters]</code>.<br/> Dolphin wants to convert the comma-separated string <var>s</var> into a space-separated string.<br/> Write a program to perform the conversion for him. </p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>The length of <var>s</var> is <var>19</var>.</li> <li>The sixth and fourteenth characters in <var>s</var> are <code>,</code>.</li> <li>The other characters in <var>s</var> are lowercase English letters.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>s</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the string after the conversion.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>happy,newyear,enjoy </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>happy newyear enjoy </pre> <p>Replace all the commas in <code>happy,newyear,enjoy</code> with spaces to obtain <code>happy newyear enjoy</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>haiku,atcoder,tasks </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>haiku atcoder tasks </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>abcde,fghihgf,edcba </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>abcde fghihgf edcba </pre></section> </div> </span>
s963330449
p02675
Python
Accepted
216
29
9,036
n = input() if n[-1] == "2" or n[-1] == "4" or n[-1] == "5" or n[-1] =="7" or n[-1] == "9": print("hon") elif n[-1] == "0" or n[-1] == "1" or n[-1] == "6" or n[-1] == "8": print("pon") else: print("bon")
16
pon
<span class="lang-en"> <p>Score: <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>The cat Snuke wants to play a popular Japanese game called ÅtCoder, so Iroha has decided to teach him Japanese.</p> <p>When counting pencils in Japanese, the counter word "本" follows the number. The pronunciation of this word varies depending on the number. Specifically, the pronunciation of "本" in the phrase "<var>N</var> 本" for a positive integer <var>N</var> not exceeding <var>999</var> is as follows:</p> <ul> <li><code>hon</code> when the digit in the one's place of <var>N</var> is <var>2</var>, <var>4</var>, <var>5</var>, <var>7</var>, or <var>9</var>;</li> <li><code>pon</code> when the digit in the one's place of <var>N</var> is <var>0</var>, <var>1</var>, <var>6</var> or <var>8</var>;</li> <li><code>bon</code> when the digit in the one's place of <var>N</var> is <var>3</var>.</li> </ul> <p>Given <var>N</var>, print the pronunciation of "本" in the phrase "<var>N</var> 本".</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>N</var> is a positive integer not exceeding <var>999</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>16 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>pon </pre> <p>The digit in the one's place of <var>16</var> is <var>6</var>, so the "本" in "<var>16</var> 本" is pronounced <code>pon</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>hon </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>183 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>bon </pre></section> </div> </span>
s050443659
p00111
Python
Accepted
620
30
4,284
import sys def f1(s): return "".join([d0[c] for c in s]) d0={"M":"10010","N":"10011"} a="ABCD"; for i in range(4): d0[a[i]]=format(i,"02b") a="EFGHIJKL" for i in range(8): d0[a[i]]=format(i,"03b") L0="ABCDEFGHIJKLMNOPQRSTUVWXYZ" L1=" ',-.?"+L0 L2=L0+" .,-'?" dc={} a="J,EE,EH,MF,GF,EF,IJ,NG,BB,AB,K,BF,NH,GE,BD,NE,BC,"\ "AI,NF,NK,AJ,L,NL,CA,AK,AL,NI,NJ,EG,MG,MH,ME".split(",") for i,e in enumerate(a): dc[f1(e)]=L1[i] ec={} for i in range(32): ec[L2[i]]=format(i,"05b") for s0 in sys.stdin: s1="".join([ec[c] for c in s0.strip("\n")]) s="" x="" for c in s1: s+=c if s in dc: x+=dc[s]; s="" print x
?D-C'KOPUA
PETER POTTER
<H1>博士の暗号</H1> <p> 博 士 : ?D-C'KOPUA </p> <p> ピーター : どうしたんですか、デビッド博士? わけのわからないことを叫ぶのにはもう慣れましたが、 今日は文章にすらなっていませんよ。 </p> <p> 博 士 : ほれ。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_memorableCodes1"> </center> <br/> <p> ピーター : なんですか? この表は......ああ、予選の問題にこんなのがありました。表を使って文字を置き換え ると文字数が減るんですよね。まさか予選と本選で同じ問題を出して手を抜こうって気じゃないでし ょうね。 </p> <p> 博 士 : 逆じゃよ。 </p> <p> ピーター : 逆? なるほど、今度は短くした文字列を元に戻そうって問題ですか。ということは「?D-C'KOPUA」の 文字を、この表を使って「文字」から「符号」に置きかえるんですね......できましたよ。 </p> <pre> 11111 00011 11101 00010 11110 01010 01110 01111 10100 00000 </pre> <p> 博 士 : うむ。次はこれじゃ。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_memorableCodes2"> </center> <br/> <p> ピーター : そうそう、こんな表もありましたね。これを逆に使うんだから「符号」から「文字」に置き換えればいい んですね。でも、最初は「11111」ですが表にありませんよ? </p> <p> 博 士 : そういうときは、もっと短くするか、後ろとつなげるかしてみるのだよ。 </p> <p> ピ ー タ ー : じゃあ短くして......あ、 「111」ならあります。じゃあ最初は「P」ですね。そうすると残りは「11」ですが、 これはぴったり合うのがないから次の「00011」から 1 文字借りて「110」にすればいいんですね。 </p> <p> 博 士 : そうそう。つまり「E」だね。 </p> <p> ピ ー タ ー : それで残るのが「0011」なので、これも次から借りて「00111」にして「T」と......。全部できました。最 後の「0000」は捨てちゃえばいいんですよね? </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_memorableCodes3"> </center> <br/> <p> 博 士 : そうじゃ、よろしい。次はこれじゃ。 </p> <pre> ?D-C'?-C'-LMGZN?FNJKN- WEYN?P'QMRWLPZLKKTPOVRGDI </pre> <p> 博 士 : さらにこれじゃ。 </p> <pre> ?P'QNPY?IXX?IXXK.BI -G?R'RPP'RPOVWDMW?SWUVG'-LCMGQ </pre> <p> 博 士 : 仕上げにこうじゃ。 </p> <pre> ?P'QMDUEQ GADKOQ ?SWUVG'-LCMG?X?IGX,PUL.?UL.VNQQI </pre> <p> ピ ー タ ー : しっかし面倒だなあ。博士、今度は自分でプログラムを作って下さいよ。 </p> <p> ということで、博士のかわりに、上の文章を置き換えるプログラムを作成してください。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットとして、1つの文字列(表に含まれる文字からなる 200 文字以下の文字列)が1行に与えられます。入力の終わりまで処理してください。データセットの数は 200 を超えません。 </p> <H2>Output</H2> <p> 各データセットごとに、変換後の文字列を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ?D-C'KOPUA </pre> <H2>Output for the Sample Input</H2> <pre> PETER POTTER </pre> <!-- <p> Judge error has been fixed on 2009/10/12. We are very sorry for the inconvenience. </p> -->
s642203400
p00064
Python
Accepted
71
30
6,548
import sys,re print(sum(map(int,re.findall(r"\d+",sys.stdin.read()))))
Thereare100yenonthetable.Iam17yearsold. Ishouldgohomeat6pm.
123
<H1>暗証番号</H1> <p> 新しい暗証番号は覚えにくいものです。メモするのはダメといわれましたが、覚えられそうにありません。そこで文章の中に数値を埋め込んで暗証番号をメモすることにしました。ここでは全ての数値の和が暗証番号になります。 </p> <p> メモされた文章を読み込んで、暗証番号を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 正の整数が埋め込まれた文章が複数行にわたり与えられます。各行は半角英数字、記号、空白を含む文字列または空行です。 ただし、入力は 1 行あたり 80 文字以内で、暗証番号は 10,000 以下であることが保障されています。 </p> <H2>Output</H2> <p> 暗証番号(文章中の正の整数の合計)を1行に出力します。 </p> <H2>Sample Input</H2> <pre> Thereare100yenonthetable.Iam17yearsold. Ishouldgohomeat6pm. </pre> <H2>Output for the Sample Input</H2> <pre> 123 </pre>
s049922902
p02663
Python
Accepted
89
71
61,448
H1, M1, H2, M2, K = map(int, input().split()) T = (H2 - H1) * 60 + (M2 - M1) print(T - K)
10 0 15 0 30
270
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In this problem, we use the <var>24</var>-hour clock.</p> <p>Takahashi gets up exactly at the time <var>H_1</var> : <var>M_1</var> and goes to bed exactly at the time <var>H_2</var> : <var>M_2</var>. (See Sample Inputs below for clarity.) He has decided to study for <var>K</var> consecutive minutes while he is up. What is the length of the period in which he can start studying?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0 \le H_1, H_2 \le 23</var></li> <li><var>0 \le M_1, M_2 \le 59</var></li> <li>The time <var>H_1</var> : <var>M_1</var> comes before the time <var>H_2</var> : <var>M_2</var>.</li> <li><var>K \ge 1</var></li> <li>Takahashi is up for at least <var>K</var> minutes.</li> <li>All values in input are integers (without leading zeros).</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>H_1</var> <var>M_1</var> <var>H_2</var> <var>M_2</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the length of the period in which he can start studying, as an integer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>10 0 15 0 30 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>270 </pre> <p>Takahashi gets up at exactly ten in the morning and goes to bed at exactly three in the afternoon. It takes <var>30</var> minutes to do the study, so he can start it in the period between ten o'clock and half-past two. The length of this period is <var>270</var> minutes, so we should print <var>270</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 0 12 0 120 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>Takahashi gets up at exactly ten in the morning and goes to bed at exactly noon. It takes <var>120</var> minutes to do the study, so he has to start it at exactly ten o'clock. Thus, we should print <var>0</var>.</p></section> </div> </span>
s095304763
p02542
Python
Accepted
8,952
51
13,828
code = r''' # distutils: language=c++ # distutils: include_dirs=[/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include,/opt/atcoder-stl] # cython: boundscheck=False # cython: wraparound=False from libcpp cimport bool from libcpp.string cimport string from libcpp.vector cimport vector from libcpp.pair cimport pair cdef extern from *: ctypedef int MOD '998244353' ctypedef long long ll 'long long' # cdef extern from '<atcoder/fenwicktree>' namespace 'atcoder': cdef cppclass fenwick_tree[T]: fenwick_tree(int n) void add(int p, T x) T sum(int l, int r) cdef class fenwick_tree_: cdef fenwick_tree[int] *ptr def __cinit__(self, int n): self.ptr = new fenwick_tree[int](n) def __dealloc__(self): del self.ptr cpdef void add(self, int p, ll x): self.ptr.add(p, x) cpdef ll sum(self, int l, int r): return self.ptr.sum(l, r) # cdef extern from '<atcoder/string>' namespace 'atcoder': vector[int] suffix_array(vector[int] s, int upper) vector[int] suffix_array(vector[ll] s) vector[int] suffix_array(string s) vector[int] lcp_array(vector[ll] s, vector[int] sa) vector[int] lcp_array(string s, vector[int] sa) vector[int] z_algorithm(vector[ll] s) vector[int] z_algorithm(string s) cpdef vector[int] suffix_array_u(vector[int] s, int upper): return suffix_array(s, upper) cpdef vector[int] suffix_array_l(vector[ll] s): return suffix_array(s) cpdef vector[int] suffix_array_s(string s): return suffix_array(s) cpdef vector[int] lcp_array_l(vector[ll] s, vector[int] sa): return lcp_array(s, sa) cpdef vector[int] lcp_array_s(string s, vector[int] sa): return lcp_array(s, sa) cpdef vector[int] z_algorithm_l(vector[ll] s): return z_algorithm(s) cpdef vector[int] z_algorithm_s(string s): return z_algorithm(s) # cdef extern from '<atcoder/math>' namespace 'atcoder': ll pow_mod(ll x, ll n, ll m) ll inv_mod(ll x, ll m) pair[ll, ll] crt(vector[ll] r, vector[ll] m) ll floor_sum(ll n, ll m, ll a, ll b) cpdef ll pow_mod_(ll x, ll n, ll m): return pow_mod(x, n, m) cpdef ll inv_mod_(ll x, ll m): return inv_mod(x, m) cpdef pair[ll, ll] crt_(vector[ll] r, vector[ll] m): return crt(r, m) cpdef ll floor_sum_(ll n, ll m, ll a, ll b): return floor_sum(n, m, a, b) # cdef extern from '<atcoder/convolution>' namespace 'atcoder': vector[ll] convolution[m](vector[ll] a, vector[ll] b) vector[ll] convolution_ll(vector[ll] a, vector[ll] b) cpdef vector[ll] convolution_(vector[ll] a, vector[ll] b): return convolution[MOD](a, b) cpdef vector[ll] convolution_ll_(vector[ll] a, vector[ll] b): return convolution_ll(a, b) # cdef extern from '<atcoder/dsu>' namespace 'atcoder': cpdef cppclass dsu: dsu(int n) int merge(int a, int b) bool same(int a, int b) int leader(int a) int size(int a) vector[vector[int]] groups() cdef class dsu_: cdef dsu *ptr def __cinit__(self, int n): self.ptr = new dsu(n) def __dealloc__(self): del self.ptr cpdef int merge(self,a,b): return self.ptr.merge(a,b) cpdef bool same(self,a,b): return self.ptr.same(a,b) cpdef int leader(self,a): return self.ptr.leader(a) cpdef int size(self,a): return self.ptr.size(a) cpdef vector[vector[int]] groups(self): return self.ptr.groups() # cdef extern from '<atcoder/maxflow>' namespace 'atcoder': cdef cppclass mf_graph[Cap]: mf_graph(int n) int add_edge(int frm, int to, Cap cap) Cap flow(int s, int t) Cap flow(int s, int t, Cap flow_limit) vector[bool] min_cut(int s) cppclass edge: int frm 'from', to Cap cap, flow edge(edge &e) edge get_edge(int i) vector[edge] edges() void change_edge(int i, Cap new_cap, Cap new_flow) cdef class mf_graph_: cdef mf_graph[ll] *ptr def __cinit__(self, int n): self.ptr = new mf_graph[ll](n) def __dealloc__(self): del self.ptr cpdef int add_edge(self, int frm, int to, ll cap): return self.ptr.add_edge(frm, to, cap) cpdef ll flow(self, int s, int t): return self.ptr.flow(s, t) cpdef ll flow_limit(self, int s, int t, ll flow_limit): return self.ptr.flow(s, t, flow_limit) cpdef vector[bool] min_cut(self, int s): return self.ptr.min_cut(s) cpdef vector[ll] get_edge(self, int i): cdef mf_graph[ll].edge *e = new mf_graph[ll].edge(self.ptr.get_edge(i)) cdef vector[ll] *ret_e = new vector[ll]() ret_e.push_back(e.frm) ret_e.push_back(e.to) ret_e.push_back(e.cap) ret_e.push_back(e.flow) return ret_e[0] cpdef vector[vector[ll]] edges(self): cdef vector[mf_graph[ll].edge] es = self.ptr.edges() cdef vector[vector[ll]] *ret_es = new vector[vector[ll]](es.size()) for i in range(es.size()): ret_es.at(i).push_back(es.at(i).frm) ret_es.at(i).push_back(es.at(i).to) ret_es.at(i).push_back(es.at(i).cap) ret_es.at(i).push_back(es.at(i).flow) return ret_es[0] cpdef void change_edge(self, int i, ll new_cap, ll new_flow): self.ptr.change_edge(i, new_cap, new_flow) # cdef extern from '<atcoder/mincostflow>' namespace 'atcoder': cdef cppclass mcf_graph[Cap, Cost]: mcf_graph(int n) int add_edge(int frm, int to, Cap cap, Cost cost) pair[Cap, Cost] flow(int s, int t) pair[Cap, Cost] flow(int s, int t, Cap flow_limit) vector[pair[Cap, Cost]] slope(int s, int t) vector[pair[Cap, Cost]] slope(int s, int t, Cap flow_limit) cppclass edge: int frm 'from', to Cap cap, flow Cost cost edge(edge &e) edge get_edge(int i) vector[edge] edges() cdef class mcf_graph_: cdef mcf_graph[ll, ll] *ptr def __cinit__(self, int n): self.ptr = new mcf_graph[ll, ll](n) def __dealloc__(self): del self.ptr cpdef int add_edge(self, int frm, int to, ll cap, ll cost): return self.ptr.add_edge(frm, to, cap, cost) cpdef pair[ll, ll] flow(self, int s, int t): return self.ptr.flow(s, t) cpdef pair[ll, ll] flow_limit(self, int s, int t, ll flow_limit): return self.ptr.flow(s, t, flow_limit) cpdef vector[pair[ll, ll]] slope(self, int s, int t): return self.ptr.slope(s, t) cpdef vector[pair[ll, ll]] slope_limit(self, int s, int t, ll flow_limit): return self.ptr.slope(s, t, flow_limit) cpdef vector[ll] get_edge(self, int i): cdef mcf_graph[ll, ll].edge *e = new mcf_graph[ll, ll].edge(self.ptr.get_edge(i)) cdef vector[ll] *ret_e = new vector[ll]() ret_e.push_back(e.frm) ret_e.push_back(e.to) ret_e.push_back(e.cap) ret_e.push_back(e.flow) ret_e.push_back(e.cost) return ret_e[0] cpdef vector[vector[ll]] edges(self): cdef vector[mcf_graph[ll, ll].edge] es = self.ptr.edges() cdef vector[vector[ll]] *ret_es = new vector[vector[ll]](es.size()) for i in range(es.size()): ret_es.at(i).push_back(es.at(i).frm) ret_es.at(i).push_back(es.at(i).to) ret_es.at(i).push_back(es.at(i).cap) ret_es.at(i).push_back(es.at(i).flow) ret_es.at(i).push_back(es.at(i).cost) return ret_es[0] # cdef extern from '<atcoder/scc>' namespace 'atcoder': cdef cppclass scc_graph: scc_graph(int n) void add_edge(int fr, int to) vector[vector[int]] scc() cdef class scc_graph_: cdef scc_graph *ptr def __cinit__(self, int n): self.ptr = new scc_graph(n) def __dealloc__(self): del self.ptr cpdef void add_edge(self, int fr, int to): self.ptr.add_edge(fr, to) cpdef vector[vector[int]] scc(self): return self.ptr.scc() # cdef extern from '<atcoder/twosat>' namespace 'atcoder': cdef cppclass two_sat: two_sat(int n) void add_clause(int i, bool f, int j, bool g) bool satisfiable() vector[bool] answer() cdef class two_sat_: cdef two_sat *ptr def __cinit__(self, int n): self.ptr = new two_sat(n) def __dealloc__(self): del self.ptr cpdef void add_clause(self, int i, bool f, int j, bool g): self.ptr.add_clause(i, f, j, g) cpdef bool satisfiable(self): return self.ptr.satisfiable() cpdef vector[bool] answer(self): return self.ptr.answer() ''' import os try: from atcoder import * except: open('atcoder.pyx', 'w').write(code) os.system('cythonize -i -3 -b atcoder.pyx') N,M=map(int,input().split()) S=[input() for i in range(N)] g=mcf_graph_(N*M+2) s,t=N*M,N*M+1 X=10**9 for i in range(N): for j in range(M): if S[i][j]=='o': g.add_edge(s,i*M+j,1,0) if j<M-1 and S[i][j]!='#'!=S[i][j+1]: g.add_edge(i*M+j,i*M+j+1,X,0) if i<N-1 and S[i][j]!='#'!=S[i+1][j]: g.add_edge(i*M+j,(i+1)*M+j,X,0) g.add_edge(i*M+j,t,1,X-i-j) g.flow(s,t) print(sum([e[3] for e in g.edges() if e[0]!=s and e[1]!=t]))
3 3 o.. ... o.#
4
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a board with <var>N</var> rows and <var>M</var> columns. The information of this board is represented by <var>N</var> strings <var>S_1,S_2,\ldots,S_N</var>. Specifically, the state of the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left is represented as follows:</p> <ul> <li><var>S_{i,j}=</var><code>.</code> : the square is empty.</li> <li><var>S_{i,j}=</var><code>#</code> : an obstacle is placed on the square.</li> <li><var>S_{i,j}=</var><code>o</code> : a piece is placed on the square.</li> </ul> <p>Yosupo repeats the following operation:</p> <ul> <li>Choose a piece and move it to its right adjecent square or its down adjacent square. Moving a piece to squares with another piece or an obstacle is prohibited. Moving a piece out of the board is also prohibited.</li> </ul> <p>Yosupo wants to perform the operation as many times as possible. Find the maximum possible number of operations.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 50</var></li> <li><var>1 \leq M \leq 50</var></li> <li><var>S_i</var> is a string of length <var>M</var> consisting of <code>.</code>, <code>#</code> and <code>o</code>.</li> <li><var>1 \leq (</var> the number of pieces <var>)\leq 100</var>. In other words, the number of pairs <var>(i, j)</var> that satisfy <var>S_{i,j}=</var><code>o</code> is between <var>1</var> and <var>100</var>, both inclusive.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>S_1</var> <var>S_2</var> <var>\vdots</var> <var>S_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible number of operations in a line.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 o.. ... o.# </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>Yosupo can perform operations <var>4</var> times as follows:</p> <pre>o.. .o. ..o ... ... ... -&gt; ... -&gt; ... -&gt; ..o -&gt; ..o o.# o.# o.# o.# .o# </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>9 10 .#....o#.. .#..#..##o .....#o.## .###.#o..o #.#...##.# ..#..#.### #o.....#.. ....###..o o.......o# </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>24 </pre></section> </div> </span>
s096910698
p02052
Python
Accepted
401
20
5,608
H,W=map(int,input().split()) MAP=[list(input()) for i in range(H)] BLIST=[] for i in range(H): for j in range(W): if MAP[i][j]=="B": BLIST.append([i,j]) BLIST.sort(key=lambda x:x[0]+x[1]) ANS=abs(BLIST[0][0]-BLIST[-1][0])+abs(BLIST[0][1]-BLIST[-1][1]) BLIST.sort(key=lambda x:x[0]-x[1]) ANS=max(ANS,abs(BLIST[0][0]-BLIST[-1][0])+abs(BLIST[0][1]-BLIST[-1][1])) print(ANS)
3 3 B.B ..B .BB
4
<h2>A: Hokkaido University Easy</h2> <h3>注意</h3> <p> 問題設定は B 問題と同一のものですが、制約のみが異なりますのでご注意ください。</p> <h3>物語</h3> <p> 北海道大学に合格し、新たな生活の始まりに心を躍らせるほむらちゃん。しかし彼女の前には、とてつもなく広いキャンパスが待ち受けていた...。</p> <p> 「え...次の授業に間に合わないんだけど...」</p> <h3>問題</h3> <p> 北海道大学札幌キャンパスは異常に広いことで有名です。札幌キャンパスは縦に <var>H</var> マス、横に <var>W</var> マス並んだ長方形のマス目で表現されます。北から <var>i</var> マス、西から <var>j</var> マス進んだマスを <var>(i,j)</var> で表すことにします。キャンパス内にはいくつか建物があり、マス <var>(i,j)</var> で表される位置に建物がある場合は 'B' 、ない場合は '.' が <var>c_{i,j}</var> に書かれています。</p> <p> 北海道大学の新入生のほむらちゃんは、キャンパスのあまりの広さに驚愕し、建物間の移動が心配になってきました。そこで、建物のある <var>2</var> つのマスのうち、最も遠い組はどれくらい離れているのかが気になりました。ここで、<var>2</var> つのマスの組 <var>(i,j) , (i',j')</var> の間の距離を <var>|i-i'|+|j-j'|</var> と定義します。</p> <p> ほむらちゃんは、自分にはこの問題は難しいと思い、同級生のあなたに助けを求めてきました。ほむらちゃんの代わりに答えを求めてください。</p> <h3>入力形式</h3> <pre> <var>H</var> <var>W</var> <var>c_{11}</var><var>c_{12}</var> <var>...</var> <var>c_{1W}</var> <var>:</var> <var>c_{H1}</var><var>c_{H2}</var> <var>...</var> <var>c_{HW}</var> </pre> <h3>制約</h3> <ul> <li> <var>2\leq H,W \leq 30</var></li> <li> <var>H,W</var> は整数</li> <li> <var>c_{i,j}</var> は 'B' か '.' のいずれかである。</li> <li> <var>c_{i,j}</var> のうち少なくとも <var>2</var> つは 'B' である。</li> </ul> <h3>出力形式</h3> <p>答えを表す整数を <var>1</var> 行に出力せよ。</p> <h3>入力例 1</h3> <pre> 3 3 B.B ..B .BB </pre> <h3>出力例 1</h3> <pre>4</pre> <ul> <li><var>(1,1)</var> と <var>(3,3)</var> の <var>2</var> 点間が最長です。</li> </ul> <h3>入力例 2</h3> <pre> 4 3 B.. B.. ... ... </pre> <h3>出力例 2</h3> <pre>1</pre> <ul> <li>隣り合う位置が最長になる場合もあります。</li> </ul> <h3>入力例 3</h3> <pre> 6 6 ...B.. B.B.B. .B.B.B ...B.B .B..B. ..B... </pre> <h3>出力例 3</h3> <pre>7</pre>
s673025921
p00333
Python
Accepted
98
20
5,660
import math W,H,C=map(int,input().split()) sikaku=math.gcd(W,H) print(C*(W*H)//(sikaku*sikaku))
10 20 5
10
<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> 新たに開拓した土地の東西方向と南北方向の長さと、1区画当たりの整備費用が与えられたとき、すべての区画を整備したときにかかる、最小の整備費用を求めるプログラムを作成せよ。 </p> <h2>Input</h2> <p> 入力は以下の形式で与えられる。 </p> <pre> <var>W</var> <var>H</var> <var>C</var> </pre> <p> 入力は1行であり、新たに開拓した土地の東西方向の長さ <var>W</var> (1 &le; <var>W</var> &le; 1000)と南北方向の長さ <var>H</var> (1 &le; <var>H</var> &le; 1000)、区画当たりの整備費用 <var>C</var> (1 &le; <var>C</var> &le; 1000)が整数で与えられる。 </p> <h2>Output</h2> <p> 土地を整備するために必要な最小の費用を1行に出力する。 </p> <h2>Sample Input 1</h2> <pre> 10 20 5 </pre> <h2>Sample Output 1</h2> <pre> 10 </pre> <p> 2個の正方形で土地を余すところなく区切ることができ、1区画当たりの整備費用が5なので、10と 出力する。 </p> <br/> <h2>Sample Input 2</h2> <pre> 27 6 1 </pre> <h2>Sample Output 2</h2> <pre> 18 </pre> <p> 18個の正方形で土地を余すところなく区切ることができ、1区画当たりの整備費用が1なので、18と出力する。 </p>
s541529419
p00466
Python
Accepted
169
30
6,720
while(1): N=int(input()) if(N==0): exit() l=[] for i in range(9): tmp=int(input()) l.append(tmp) ans=0 for i in range(9): ans+=l[i] a=N-ans print(a)
9850 1050 800 420 380 600 820 2400 1800 980 0
600
<H1>レシート </H1> <h2>問題</h2> <p> 太郎君は10冊の本を購入した. 後日, レシートをもとに価格を調べようとしたが, レシートには汚れがあり, ある本の価格が読み取れなかった. その本の価格を, 10冊の総額と他の9冊の価格から計算することにした. </p> <p> 価格が読み取れなかった本の価格を出力するプログラムを書け. なお,本の価格はすべて正の整数である. また,消費税を考慮する必要はない. </p> <h2> 入力</h2> <p> 入力は複数のデータセットからなる.各データセットは以下の形式で与えられる. </p> <p> 各データセットは10行からなり,1行に1つずつ正の整数が書かれている. 1行目の整数は10冊の総額を, 2行目から10行目の整数は読み取れた価格を表している. なお,10冊の総額は10000以下である. </p> <p> 総額 が 0 のとき入力の終了を示す.データセットの数は 5 を超えない. </p> <h2> 出力</h2> <p> データセットごとに,価格が読み取れなかった本の価格を1 行に出力する. </p> <h2> 入出力例</h2> <h3>入力例</h3> <pre> 9850 1050 800 420 380 600 820 2400 1800 980 0 </pre> <h3>出力例</h3> <pre> 600 </pre> <div class="source"> <p class="source"> 上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。 </p> </div>
s237164062
p03252
Python
Accepted
250
49
9,708
import collections A = input() B = input() A_c = collections.Counter(A) B_c = collections.Counter(B) A_c = A_c.values() B_c = B_c.values() A_c = list(A_c) B_c = list(B_c) A_c.sort() B_c.sort() if A_c == B_c: print("Yes") else: print("No")
azzel apple
Yes
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given strings <var>S</var> and <var>T</var> consisting of lowercase English letters.</p> <p>You can perform the following operation on <var>S</var> any number of times:</p> <p>Operation: Choose two distinct lowercase English letters <var>c_1</var> and <var>c_2</var>, then replace every occurrence of <var>c_1</var> with <var>c_2</var>, and every occurrence of <var>c_2</var> with <var>c_1</var>.</p> <p>Determine if <var>S</var> and <var>T</var> can be made equal by performing the operation zero or more times.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |S| \leq 2 \times 10^5</var></li> <li><var>|S| = |T|</var></li> <li><var>S</var> and <var>T</var> consists of lowercase English letters.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> <var>T</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If <var>S</var> and <var>T</var> can be made equal, print <code>Yes</code>; otherwise, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>azzel apple </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p><code>azzel</code> can be changed to <code>apple</code>, as follows:</p> <ul> <li>Choose <code>e</code> as <var>c_1</var> and <code>l</code> as <var>c_2</var>. <code>azzel</code> becomes <code>azzle</code>.</li> <li>Choose <code>z</code> as <var>c_1</var> and <code>p</code> as <var>c_2</var>. <code>azzle</code> becomes <code>apple</code>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>chokudai redcoder </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <p>No sequences of operation can change <code>chokudai</code> to <code>redcoder</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>abcdefghijklmnopqrstuvwxyz ibyhqfrekavclxjstdwgpzmonu </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Yes </pre></section> </div> </span>
s150531799
p03085
Python
Accepted
100
30
8,836
moji = str(input()) correct = ["A","C","G","T"] ind = correct.index(moji) + 1 print(correct[ind*-1])
A
T
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>On the Planet AtCoder, there are four types of bases: <code>A</code>, <code>C</code>, <code>G</code> and <code>T</code>. <code>A</code> bonds with <code>T</code>, and <code>C</code> bonds with <code>G</code>.</p> <p>You are given a letter <var>b</var> as input, which is <code>A</code>, <code>C</code>, <code>G</code> or <code>T</code>. Write a program that prints the letter representing the base that bonds with the base <var>b</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>b</var> is one of the letters <code>A</code>, <code>C</code>, <code>G</code> and <code>T</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>b</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the letter representing the base that bonds with the base <var>b</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>A </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>T </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>G </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>C </pre></section> </div> </span>
s110833628
p03575
Python
Accepted
801
28
9,196
# Union Find # xの根を求める def find(x): if par[x] < 0: return x else: par[x] = find(par[x]) return par[x] # xとyの属する集合の併合 def unite(x, y): x = find(x) y = find(y) if x == y: return False else: # x < y にする if par[x] > par[y]: x, y = y, x par[x] += par[y] par[y] = x return True # 根の個数を返す def group_count(): return sum(x < 0 for x in par) n, m = map(int, input().split()) l = [] for _ in range(m): l.append(tuple(map(int, input().split()))) ans = 0 for j in range(m): par = [-1] * n for i, ab in enumerate(l): if i != j: unite(ab[0] - 1, ab[1] - 1) if group_count() == 2: ans += 1 print(ans)
7 7 1 3 2 7 3 4 4 5 4 6 5 6 6 7
4
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an undirected connected graph with <var>N</var> vertices and <var>M</var> edges that does not contain self-loops and double edges.<br/> The <var>i</var>-th edge <var>(1 \leq i \leq M)</var> connects Vertex <var>a_i</var> and Vertex <var>b_i</var>. </p> <p>An edge whose removal disconnects the graph is called a <em>bridge</em>.<br/> Find the number of the edges that are bridges among the <var>M</var> edges. </p> </section> </div> <div class="part"> <section> <h3>Notes</h3><ul> <li>A <em>self-loop</em> is an edge <var>i</var> such that <var>a_i=b_i</var> <var>(1 \leq i \leq M)</var>.</li> <li><em>Double edges</em> are a pair of edges <var>i,j</var> such that <var>a_i=a_j</var> and <var>b_i=b_j</var> <var>(1 \leq i&lt;j \leq M)</var>.</li> <li>An undirected graph is said to be <em>connected</em> when there exists a path between every pair of vertices.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 50</var></li> <li><var>N-1 \leq M \leq min(N(N−1)⁄2,50)</var></li> <li><var>1 \leq a_i&lt;b_i \leq N</var></li> <li>The given graph does not contain self-loops and double edges.</li> <li>The given graph is connected.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format: </p> <pre><var>N</var> <var>M</var> <var>a_1</var> <var>b_1</var> <var>a_2</var> <var>b_2</var> <var>:</var> <var>a_M</var> <var>b_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the edges that are bridges among the <var>M</var> edges.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>7 7 1 3 2 7 3 4 4 5 4 6 5 6 6 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>The figure below shows the given graph:</p> <div style="text-align: center;"> <img alt="570677a9809fd7a5b63bff11e5d9bf79.png" src="https://img.atcoder.jp/abc075/570677a9809fd7a5b63bff11e5d9bf79.png"> </img></div> <p>The edges shown in red are bridges. There are four of them.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 1 2 1 3 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>It is possible that there is no bridge.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 5 1 2 2 3 3 4 4 5 5 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>5 </pre> <p>It is possible that every edge is a bridge.</p></section> </div> </span>
s361106056
p02700
Python
Accepted
1,594
27
9,208
''' 問題: 高橋君と青木君がモンスターを闘わせます。 高橋君のモンスターは体力が A で攻撃力が B です。 青木君のモンスターは体力が C で攻撃力が D です。 高橋君→青木君→高橋君→青木君→... の順に攻撃を行います。 攻撃とは、相手のモンスターの体力の値を自分のモンスターの攻撃力のぶんだけ減らすことをいいます。 このことをどちらかのモンスターの体力が 0 以下になるまで続けたとき、 先に自分のモンスターの体力が 0 以下になった方の負け、そうでない方の勝ちです。 高橋君が勝つなら Yes、負けるなら No を出力してください。 ''' ''' 制約: 1 ≦ A, B, C, D ≦ 100 入力は全て整数である ''' class Monster: def __init__(self, hp, power): self.hp = hp self.power = power def fight(self, power) -> int: self.hp -= power return self.hp def is_loser(self) -> bool: return self.hp <= 0 # 標準入力から A, B, C, D を取得する a, b, c, d = map(int, input().split()) takahashi_monster = Monster(a, b) # 高橋モンスター aoki_monster = Monster(c, d) # 青木モンスター result = "ret" while True: aoki_monster.fight(b) # 高橋の攻撃 if aoki_monster.is_loser(): result = "Yes" break takahashi_monster.fight(d) # 青木の攻撃 if takahashi_monster.is_loser(): result = "No" break print(result)
10 9 10 10
No
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi and Aoki will have a battle using their monsters.</p> <p>The health and strength of Takahashi's monster are <var>A</var> and <var>B</var>, respectively, and those of Aoki's monster are <var>C</var> and <var>D</var>, respectively.</p> <p>The two monsters will take turns attacking, in the order Takahashi's, Aoki's, Takahashi's, Aoki's, ... Here, an attack decreases the opponent's health by the value equal to the attacker's strength. The monsters keep attacking until the health of one monster becomes <var>0</var> or below. The person with the monster whose health becomes <var>0</var> or below loses, and the other person wins.</p> <p>If Takahashi will win, print <code>Yes</code>; if he will lose, print <code>No</code>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq A,B,C,D \leq 100</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> <var>C</var> <var>D</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If Takahashi will win, print <code>Yes</code>; if he will lose, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>10 9 10 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>No </pre> <p>First, Takahashi's monster attacks Aoki's monster, whose health is now <var>10-9=1</var>.</p> <p>Next, Aoki's monster attacks Takahashi's monster, whose health is now <var>10-10=0</var>.</p> <p>Takahashi's monster is the first to have <var>0</var> or less health, so Takahashi loses.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>46 4 40 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Yes </pre></section> </div> </span>
s676588810
p02383
Python
Accepted
1,197
20
5,608
class Dice: def __init__(self): # 初期値がない場合 self.t = 1 self.s = 2 self.e = 4 self.w = 8 self.n = 16 self.b = 32 def __init__(self, t, s, e, w, n, b): # 初期値が指定される場合 self.t = t self.s = s self.e = e self.w = w self.n = n self.b = b def rot(self, way): if way == "S": self.t, self.s, self.e, self.w, self.n, self.b = self.n, self.t, self.e, self.w, self.b, self.s elif way == "N": self.t, self.s, self.e, self.w, self.n, self.b = self.s, self.b, self.e, self.w, self.t, self.n elif way == "E": self.t, self.s, self.e, self.w, self.n, self.b = self.w, self.s, self.t, self.b, self.n, self.e elif way == "W": self.t, self.s, self.e, self.w, self.n, self.b = self.e, self.s, self.b, self.t, self.n, self.w def main(): t,s,e,w,n,b = map(int, input().split()) cmd = input().upper() dice1 = Dice(t,s,e,w,n,b) for i in range(len(cmd)): dice1.rot(cmd[i]) print(dice1.t) if __name__ == '__main__': main()
1 2 4 8 16 32 SE
8
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <h1>Dice I</h1><br> <p> Write a program to simulate rolling a dice, which can be constructed by the following net. </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_1"><br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_A_2"><br> </center> <br><br> <p> As shown in the figures, each face is identified by a different label from 1 to 6. </p> <p> Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures. </p> <h2>Input</h2> <p> In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. </p> <p> In the second line, a string which represents a sequence of commands, is given. The command is one of '<span>E</span>', '<span>N</span>', '<span>S</span>' and '<span>W</span>' representing four directions shown in the above figures. </p> <h2>Output</h2> <p> Print the integer which appears on the top face after the simulation. </p> <h2>Constraints</h2> <ul> <li>$0 \leq $ the integer assigned to a face $ \leq 100$</li> <li>$0 \leq $ the length of the command $\leq 100$</li> </ul> <h2>Sample Input 1</h2> <pre> 1 2 4 8 16 32 SE </pre> <h2>Sample Output 1</h2> <pre> 8 </pre> <p> You are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face labeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction <span>S</span> and then to the direction <span>E</span>, you can see 8 on the top face. </p> <br><br> <h2>Sample Input 2</h2> <pre> 1 2 4 8 16 32 EESWN </pre> <h2>Sample Output 2</h2> <pre> 32 </pre>
s106297760
p02924
Python
Accepted
766
68
65,624
import math from math import gcd,pi,sqrt INF = float("inf") MOD = 10**9 + 7 import sys sys.setrecursionlimit(10**6) import itertools import bisect from collections import Counter,deque def i_input(): return int(input()) def i_map(): return map(int, input().split()) def i_list(): return list(i_map()) def i_row(N): return [i_input() for _ in range(N)] def i_row_list(N): return [i_list() for _ in range(N)] def s_input(): return input() def s_map(): return input().split() def s_list(): return list(s_map()) def s_row(N): return [s_input for _ in range(N)] def s_row_str(N): return [s_list() for _ in range(N)] def s_row_list(N): return [list(s_input()) for _ in range(N)] def main(): n = i_input() print(n*(n-1)//2) if __name__=="__main__": main()
2
1
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>For an integer <var>N</var>, we will choose a permutation <var>\{P_1, P_2, ..., P_N\}</var> of <var>\{1, 2, ..., N\}</var>.</p> <p>Then, for each <var>i=1,2,...,N</var>, let <var>M_i</var> be the remainder when <var>i</var> is divided by <var>P_i</var>.</p> <p>Find the maximum possible value of <var>M_1 + M_2 + \cdots + M_N</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>N</var> is an integer satisfying <var>1 \leq N \leq 10^9</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible value of <var>M_1 + M_2 + \cdots + M_N</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>When the permutation <var>\{P_1, P_2\} = \{2, 1\}</var> is chosen, <var>M_1 + M_2 = 1 + 0 = 1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>13 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>78 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
s003961310
p03039
Python
Accepted
1,389
77
81,804
# N, M から相異なる二点を取った時のマンハッタン距離の、二点の取り方についての総和を、 # _{N + M - 2} C _{K - 2} 倍したものが答え。 N, M, K = map(int, input().split()) # コンビネーション前計算。 MOD = 10 ** 9 + 7 table_len = 2 * 10 ** 5 + 10 fac = [1, 1] for i in range(2, table_len): fac.append(fac[-1] * i % MOD) finv = [0] * table_len finv[-1] = pow(fac[-1], MOD - 2, MOD) for i in range(table_len-1, 0, -1): finv[i-1] = finv[i] * i % MOD # マンハッタン距離の総和は、各距離の部分がカウントされるかを考えればよいので、 # (ex. 左半分と右半分にひとつずつなら、必ず二等分する線を横断する部分がある、みたいな) # l + r = N に対し lM * rM = M^2 * lr の総和と、 # l + r = M に対し lN * rN = N^2 * lr の総和の和でよい。 # シグマ公式をつかえばO(1)にも出来そうだが、面倒なので省略。 # M^2は最後にまとめる distsum1 = 0 for l in range(1, N): distsum1 += l * (N - l) distsum1 %= MOD distsum1 *= pow(M, 2, MOD) distsum1 %= MOD # N^2は最後にまとめる distsum2 = 0 for l in range(1, M): distsum2 += l * (M - l) distsum2 %= MOD distsum2 *= pow(N, 2, MOD) distsum2 %= MOD print((distsum1 + distsum2) % MOD * fac[N * M - 2] % MOD * finv[K - 2] % MOD * finv[N * M - K] % MOD)
2 2 2
8
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a grid of squares with <var>N</var> rows and <var>M</var> columns. Let <var>(i, j)</var> denote the square at the <var>i</var>-th row from the top and <var>j</var>-th column from the left. We will choose <var>K</var> of the squares and put a piece on each of them.</p> <p>If we place the <var>K</var> pieces on squares <var>(x_1, y_1)</var>, <var>(x_2, y_2)</var>, ..., and <var>(x_K, y_K)</var>, the <em>cost</em> of this arrangement is computed as:</p> <p><var>\sum_{i=1}^{K-1} \sum_{j=i+1}^K (|x_i - x_j| + |y_i - y_j|)</var></p> <p>Find the sum of the costs of all possible arrangements of the pieces. Since this value can be tremendous, print it modulo <var>10^9+7</var>.</p> <p>We consider two arrangements of the pieces different if and only if there is a square that contains a piece in one of the arrangements but not in the other.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \times M \leq 2 \times 10^5</var></li> <li><var>2 \leq K \leq N \times M</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the sum of the costs of all possible arrangements of the pieces, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>8 </pre> <p>There are six possible arrangements of the pieces, as follows:</p> <ul> <li><var>((1,1),(1,2))</var>, with the cost <var>|1-1|+|1-2| = 1</var></li> <li><var>((1,1),(2,1))</var>, with the cost <var>|1-2|+|1-1| = 1</var></li> <li><var>((1,1),(2,2))</var>, with the cost <var>|1-2|+|1-2| = 2</var></li> <li><var>((1,2),(2,1))</var>, with the cost <var>|1-2|+|2-1| = 2</var></li> <li><var>((1,2),(2,2))</var>, with the cost <var>|1-2|+|2-2| = 1</var></li> <li><var>((2,1),(2,2))</var>, with the cost <var>|2-2|+|1-2| = 1</var></li> </ul> <p>The sum of these costs is <var>8</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 5 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>87210 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>100 100 5000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>817260251 </pre> <p>Be sure to print the sum modulo <var>10^9+7</var>.</p></section> </div> </span>
s868966337
p02786
Python
Accepted
209
24
9,032
H = int(input()) attackcnt = 0 monstercnt = 1 def monster(h, m, a): if h == 1: return 0,0,a+m else: return monster(int((h/2)),2*m,a+m) a, b, c = monster(H,monstercnt,attackcnt) print(c)
2
3
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Caracal is fighting with a monster.</p> <p>The <em>health</em> of the monster is <var>H</var>.</p> <p>Caracal can attack by choosing one monster. When a monster is attacked, depending on that monster's health, the following happens:</p> <ul> <li>If the monster's health is <var>1</var>, it drops to <var>0</var>.</li> <li>If the monster's health, <var>X</var>, is greater than <var>1</var>, that monster disappears. Then, two new monsters appear, each with the health of <var>\lfloor X/2 \rfloor</var>.</li> </ul> <p>(<var>\lfloor r \rfloor</var> denotes the greatest integer not exceeding <var>r</var>.)</p> <p>Caracal wins when the healths of all existing monsters become <var>0</var> or below.</p> <p>Find the minimum number of attacks Caracal needs to make before winning.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq H \leq 10^{12}</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>H</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Find the minimum number of attacks Caracal needs to make before winning.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>When Caracal attacks the initial monster, it disappears, and two monsters appear, each with the health of <var>1</var>.</p> <p>Then, Caracal can attack each of these new monsters once and win with a total of three attacks.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>7 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1000000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1099511627775 </pre></section> </div> </span>
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
3