s_id
stringlengths
10
10
p_id
stringlengths
6
6
u_id
stringlengths
10
10
date
stringlengths
10
10
language
stringclasses
1 value
original_language
stringclasses
11 values
filename_ext
stringclasses
1 value
status
stringclasses
1 value
cpu_time
int64
0
100
memory
stringlengths
4
6
code_size
int64
15
14.7k
code
stringlengths
15
14.7k
problem_id
stringlengths
6
6
problem_description
stringlengths
358
9.83k
input
stringlengths
2
4.87k
output
stringclasses
807 values
__index_level_0__
int64
1.1k
1.22M
s325456948
p04048
u399560160
1468741169
Python
Python (3.4.3)
py
Accepted
41
3064
317
def sub(a, b): if (a%b == 0): return a//b-1 return a//b def mod(a, b): if a%b==0: return b return a%b n, x = map(int, input().split(' ')) ans = n c = [x, n-x] while (c[0] != c[1]): c = [min(c), max(c)] ans += 2*sub(c[1], c[0])*c[0] c[1] = mod(c[1], c[0]) print(ans+c[0])
p04048
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p> <p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle. Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p> <p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p> <p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed.</p> <p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p> <div style="text-align: center;"> <img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png"> </img></div> <p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>. Find the total length of the ray's trajectory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦10^{12}</var></li> <li><var>1≦X≦N-1</var></li> <li><var>N</var> and <var>X</var> are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Points</h3><ul> <li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li> <li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total length of the ray's trajectory.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>Refer to the image in the Problem Statement section. The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section> </div> </span>
5 2
12
1,217,717
s976467494
p04048
u477320129
1468729155
Python
Python (3.4.3)
py
Accepted
39
3064
243
import sys sys.setrecursionlimit(1500) def f(x, y): if x == 0: return 0 if y % x == 0: return 2 * (y // x) * x - x return 2 * (y // x) * x + f(y % x, x) N, X = list(map(int, input().split())) print(f(X, N-X) + N)
p04048
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p> <p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle. Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p> <p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p> <p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed.</p> <p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p> <div style="text-align: center;"> <img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png"> </img></div> <p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>. Find the total length of the ray's trajectory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦10^{12}</var></li> <li><var>1≦X≦N-1</var></li> <li><var>N</var> and <var>X</var> are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Points</h3><ul> <li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li> <li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total length of the ray's trajectory.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>Refer to the image in the Problem Statement section. The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section> </div> </span>
5 2
12
1,217,718
s472021971
p04048
u250209149
1468728968
Python
Python (2.7.6)
py
Accepted
34
3072
313
tmp = [int(x) for x in raw_input().split(' ')] N = tmp[0] X = tmp[1] if(X > 0.5 * N): X = N-X totaldist = N step = X dist = N-X while(1): totaldist += (dist/step) * 2 * step distnew = step stepnew = dist % step if(stepnew == 0): totaldist -= step break dist = distnew step = stepnew print totaldist
p04048
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p> <p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle. Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p> <p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p> <p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed.</p> <p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p> <div style="text-align: center;"> <img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png"> </img></div> <p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>. Find the total length of the ray's trajectory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦10^{12}</var></li> <li><var>1≦X≦N-1</var></li> <li><var>N</var> and <var>X</var> are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Points</h3><ul> <li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li> <li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total length of the ray's trajectory.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>Refer to the image in the Problem Statement section. The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section> </div> </span>
5 2
12
1,217,719
s655089067
p04048
u534783449
1468723523
Python
Python (2.7.6)
py
Accepted
26
2568
332
args = [ int(x) for x in raw_input().split() ] l0 = args[0] x0 = args[1] def get_length(l, x): if l % x == 0: part = l * 2 - x # print l, x, part return part part = int(l / x) * 2 * x # print l, x, part return part + get_length(x, l % x) length = l0 + get_length(l0 - x0, x0) print length
p04048
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p> <p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle. Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p> <p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p> <p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed.</p> <p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p> <div style="text-align: center;"> <img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png"> </img></div> <p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>. Find the total length of the ray's trajectory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦10^{12}</var></li> <li><var>1≦X≦N-1</var></li> <li><var>N</var> and <var>X</var> are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Points</h3><ul> <li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li> <li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total length of the ray's trajectory.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>Refer to the image in the Problem Statement section. The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section> </div> </span>
5 2
12
1,217,720
s936583900
p04048
u966695411
1468722792
Python
Python (3.4.3)
py
Accepted
44
3064
196
#! /usr/bin/env python3 def f(a, b): if a < b : b, a = a, b c = a // b r = b * 3 * c if a % b > 0 : r += f(b, a-c*b) return r N, X = map(int, input().split()) print(f(X, N-X))
p04048
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p> <p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle. Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p> <p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p> <p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed.</p> <p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p> <div style="text-align: center;"> <img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png"> </img></div> <p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>. Find the total length of the ray's trajectory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦10^{12}</var></li> <li><var>1≦X≦N-1</var></li> <li><var>N</var> and <var>X</var> are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Points</h3><ul> <li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li> <li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total length of the ray's trajectory.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>Refer to the image in the Problem Statement section. The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section> </div> </span>
5 2
12
1,217,721
s235812495
p04048
u725662235
1468722732
Python
Python (2.7.6)
py
Accepted
26
2568
333
n = map(int, raw_input().split()) x = n[1] n = n[0] tpl = x # print '55',tps, tpl if x < float(n)/2: tps = abs(n - 2*x) l = x + n - tps else: l = 0 tps = n - x while tps != 0: # print l # print "t", tps, tpl l += tpl/tps * 3*tps # tpl/tps * 3*tps ntps = tpl % tps tpl = tps tps = ntps print l
p04048
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p> <p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle. Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p> <p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p> <p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed.</p> <p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p> <div style="text-align: center;"> <img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png"> </img></div> <p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>. Find the total length of the ray's trajectory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦10^{12}</var></li> <li><var>1≦X≦N-1</var></li> <li><var>N</var> and <var>X</var> are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Points</h3><ul> <li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li> <li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total length of the ray's trajectory.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>Refer to the image in the Problem Statement section. The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section> </div> </span>
5 2
12
1,217,722
s825221067
p04048
u707500405
1468722384
Python
Python (2.7.6)
py
Accepted
27
2568
118
N,X = map(int,raw_input().split()) X = min(X,N-X) ans = 0 N -= X while X > 0: ans += N/X * X *3 N,X= X,N%X print ans
p04048
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p> <p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle. Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p> <p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p> <p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed.</p> <p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p> <div style="text-align: center;"> <img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png"> </img></div> <p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>. Find the total length of the ray's trajectory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦10^{12}</var></li> <li><var>1≦X≦N-1</var></li> <li><var>N</var> and <var>X</var> are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Points</h3><ul> <li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li> <li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total length of the ray's trajectory.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>Refer to the image in the Problem Statement section. The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section> </div> </span>
5 2
12
1,217,723
s767993794
p04048
u248145581
1468722067
Python
Python (3.4.3)
py
Accepted
37
3064
437
#!/usr/bin/env python3 # -*- coding: utf-8 -*- N, X = list(map(int, input().split())) sum_ = X prev = X next = N - X i = 0 while True: num = prev // next if i == 0: sum_ += 2 * num * next elif i % 2 == 1: sum_ += 2 * num * next - next else: sum_ += 2 * num * next - next mod_ = prev % next if mod_ == 0: break sum_ += next prev = next next = mod_ i += 1 print(sum_)
p04048
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p> <p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle. Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p> <p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p> <p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed.</p> <p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p> <div style="text-align: center;"> <img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png"> </img></div> <p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>. Find the total length of the ray's trajectory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦10^{12}</var></li> <li><var>1≦X≦N-1</var></li> <li><var>N</var> and <var>X</var> are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Points</h3><ul> <li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li> <li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total length of the ray's trajectory.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>Refer to the image in the Problem Statement section. The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section> </div> </span>
5 2
12
1,217,724
s380250602
p04048
u601018334
1468721581
Python
Python (3.4.3)
py
Accepted
38
3064
211
def calc(N,X): if N%X ==0: return 3*N else: return 3*X*(int(N/X)) + calc(X,N-X*(int(N/X))) N,X = list(map(int, input().split())) X = min(X,N-X) ans = calc(N-X,X) print('%s' % str(ans))
p04048
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p> <p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle. Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p> <p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p> <p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed.</p> <p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p> <div style="text-align: center;"> <img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png"> </img></div> <p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>. Find the total length of the ray's trajectory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦10^{12}</var></li> <li><var>1≦X≦N-1</var></li> <li><var>N</var> and <var>X</var> are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Points</h3><ul> <li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li> <li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total length of the ray's trajectory.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>Refer to the image in the Problem Statement section. The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section> </div> </span>
5 2
12
1,217,725
s414580965
p04048
u786082266
1468721183
Python
Python (2.7.6)
py
Accepted
26
2568
144
n, x = map(int, raw_input().split()) s = 0 t = n - x while t % x != 0: m = t % x s += x * (t / x) t = x x = m s += x * (t / x) print s * 3
p04048
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p> <p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle. Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p> <p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p> <p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed.</p> <p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p> <div style="text-align: center;"> <img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png"> </img></div> <p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>. Find the total length of the ray's trajectory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦10^{12}</var></li> <li><var>1≦X≦N-1</var></li> <li><var>N</var> and <var>X</var> are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Points</h3><ul> <li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li> <li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total length of the ray's trajectory.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>Refer to the image in the Problem Statement section. The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section> </div> </span>
5 2
12
1,217,726
s051327110
p04048
u357487020
1468721025
Python
Python (2.7.6)
py
Accepted
27
2568
403
n,x=map(int,raw_input().split()) y=n-x ans=x+y if y>=x: while 1: if y%x==0: ans+=x+((y-x)/x)*x*2 print(ans) break else: ans+=((y)/x)*x*2 y,x=x,y%x else: while 1: if x%y==0: ans+=y+((x-y)/y)*y*2 print(ans) break else: ans+=((x)/y)*y*2 x,y=y,x%y
p04048
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p> <p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle. Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p> <p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p> <p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed.</p> <p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p> <div style="text-align: center;"> <img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png"> </img></div> <p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>. Find the total length of the ray's trajectory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦10^{12}</var></li> <li><var>1≦X≦N-1</var></li> <li><var>N</var> and <var>X</var> are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Points</h3><ul> <li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li> <li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total length of the ray's trajectory.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>Refer to the image in the Problem Statement section. The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section> </div> </span>
5 2
12
1,217,727
s757958726
p04048
u124139453
1468720989
Python
Python (2.7.6)
py
Accepted
25
2568
208
n, x = map(int,raw_input().split()) x = min(n-x,x) ans = 0 def cal(ans,l,s): ans += l/s*s*3 if l%s == 0: return ans else: return cal(ans,max(s,l%s),min(s,l%s)) print cal(ans,n-x,x)
p04048
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p> <p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle. Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p> <p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p> <p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed.</p> <p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p> <div style="text-align: center;"> <img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png"> </img></div> <p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>. Find the total length of the ray's trajectory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦10^{12}</var></li> <li><var>1≦X≦N-1</var></li> <li><var>N</var> and <var>X</var> are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Points</h3><ul> <li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li> <li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total length of the ray's trajectory.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>Refer to the image in the Problem Statement section. The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section> </div> </span>
5 2
12
1,217,728
s908649186
p04048
u024612773
1468720861
Python
Python (3.4.3)
py
Accepted
40
3064
202
n,x=map(int,input().split()) if x>n/2: x = n-x ans = n c = x d = n-x while c > 0: if d%c==0: ans += int(d/c)*(2*c) - c else: ans += int(d/c)*(2*c) c,d = d%c,c print(ans)
p04048
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p> <p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle. Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p> <p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p> <p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed.</p> <p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p> <div style="text-align: center;"> <img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png"> </img></div> <p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>. Find the total length of the ray's trajectory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦10^{12}</var></li> <li><var>1≦X≦N-1</var></li> <li><var>N</var> and <var>X</var> are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Points</h3><ul> <li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li> <li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total length of the ray's trajectory.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>Refer to the image in the Problem Statement section. The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section> </div> </span>
5 2
12
1,217,729
s240991215
p04048
u810735437
1468719592
Python
Python (3.4.3)
py
Accepted
65
4212
666
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import functools def gcd(a, b): while b: a, b = b, a % b return a # @functools.lru_cache(maxsize = None) # def func(N, X): # g = gcd(N, X) # if g == 1: # if X > N // 2: # return func(N, N - X) # if N == 2: # return 3 # if N == 3: # return 6 # return X * 3 + func(N-X, X) # else: # return g * func(N//g, X//g) def func_fast(N, X): g = gcd(N, X) if g == 1: return 3 * N - 3 else: return g * func_fast(N // g, X // g) N,X = map(int,input().split()) print(func_fast(N,X))
p04048
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p> <p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle. Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p> <p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p> <p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed.</p> <p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p> <div style="text-align: center;"> <img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png"> </img></div> <p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>. Find the total length of the ray's trajectory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦10^{12}</var></li> <li><var>1≦X≦N-1</var></li> <li><var>N</var> and <var>X</var> are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Points</h3><ul> <li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li> <li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total length of the ray's trajectory.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>Refer to the image in the Problem Statement section. The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section> </div> </span>
5 2
12
1,217,730
s406843225
p04048
u202619899
1468719357
Python
Python (3.4.3)
py
Accepted
37
3064
266
def rec(a, b): mx = max(a, b) mn = min(a, b) #print(mn, mx//mn) if mx % mn == 0: return (2 * (mx // mn) - 1) * mn return (2 * mn * (mx // mn)) + rec(mn, mx % mn) N, X = list(map(int, input().split())) #print(N, X) print(rec(N-X, X) + N)
p04048
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p> <p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle. Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p> <p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p> <p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed.</p> <p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p> <div style="text-align: center;"> <img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png"> </img></div> <p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>. Find the total length of the ray's trajectory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦10^{12}</var></li> <li><var>1≦X≦N-1</var></li> <li><var>N</var> and <var>X</var> are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Points</h3><ul> <li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li> <li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total length of the ray's trajectory.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>Refer to the image in the Problem Statement section. The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section> </div> </span>
5 2
12
1,217,731
s047819608
p04048
u765237551
1468719065
Python
Python (3.4.3)
py
Accepted
39
3064
198
N, X = map(int, input().split()) def solve(a, b): d = a // b m = a % b if m==0: return (d * 2 - 1) * b else: return d * 2 * b + solve(b, m) print(N + solve(X, N-X))
p04048
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p> <p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle. Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p> <p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p> <p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed.</p> <p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p> <div style="text-align: center;"> <img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png"> </img></div> <p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>. Find the total length of the ray's trajectory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦10^{12}</var></li> <li><var>1≦X≦N-1</var></li> <li><var>N</var> and <var>X</var> are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Points</h3><ul> <li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li> <li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total length of the ray's trajectory.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>Refer to the image in the Problem Statement section. The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section> </div> </span>
5 2
12
1,217,732
s888053853
p04048
u207056619
1468718916
Python
Python (3.4.3)
py
Accepted
37
3064
212
#!/usr/bin/env python3 def f(n, x): if n % x == 0: return (n // x * 2 - 1) * x else: return (n // x * 2) * x + f(x, n % x) n, x = map(int,input().split()) ans = n + f(n - x, x) print(ans)
p04048
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p> <p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle. Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p> <p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p> <p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed.</p> <p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p> <div style="text-align: center;"> <img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png"> </img></div> <p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>. Find the total length of the ray's trajectory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦10^{12}</var></li> <li><var>1≦X≦N-1</var></li> <li><var>N</var> and <var>X</var> are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Points</h3><ul> <li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li> <li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total length of the ray's trajectory.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>Refer to the image in the Problem Statement section. The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section> </div> </span>
5 2
12
1,217,733
s609499278
p04048
u945080461
1468718829
Python
Python (2.7.6)
py
Accepted
60
4392
113
from fractions import gcd n, x = map(int, raw_input().split()) g = gcd(n, x) n /= g x /= g print 3 * (n - 1) * g
p04048
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p> <p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle. Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p> <p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p> <p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed.</p> <p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p> <div style="text-align: center;"> <img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png"> </img></div> <p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>. Find the total length of the ray's trajectory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦10^{12}</var></li> <li><var>1≦X≦N-1</var></li> <li><var>N</var> and <var>X</var> are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Points</h3><ul> <li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li> <li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total length of the ray's trajectory.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>Refer to the image in the Problem Statement section. The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section> </div> </span>
5 2
12
1,217,734
s998319904
p04048
u299869545
1468718133
Python
Python (2.7.6)
py
Accepted
27
2692
214
n, x = map(int, raw_input().split()) def solve(a, b): if a > b:return solve(b, a) if b % a == 0: return (2 * (b / a) - 1) * a return 2 * a * (b / a) + solve(a, b % a) print solve(x, n-x) + n
p04048
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p> <p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle. Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p> <p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p> <p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed.</p> <p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p> <div style="text-align: center;"> <img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png"> </img></div> <p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>. Find the total length of the ray's trajectory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦10^{12}</var></li> <li><var>1≦X≦N-1</var></li> <li><var>N</var> and <var>X</var> are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Points</h3><ul> <li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li> <li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total length of the ray's trajectory.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>Refer to the image in the Problem Statement section. The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section> </div> </span>
5 2
12
1,217,735
s292125822
p04050
u218843509
1592028903
Python
Python (3.4.3)
py
Accepted
18
3064
636
from sys import exit n, m = map(int, input().split()) a = list(map(int, input().split())) odd = [] even = [] for x in a: if x%2 == 0: even.append(x) else: odd.append(x) if n%2 == 0: if len(odd) > 2: print("Impossible") exit() if len(odd) == 2: a = [odd[0]] + even + [odd[1]] b = [odd[0]+1] + even + [odd[1]-1] if b[-1] == 0: b.pop() else: a = even b = [1] + even b[-1] -= 1 if b[-1] == 0: b.pop() else: if len(odd) > 1: print("Impossible") exit() if m == 1: b = [1, n-1] else: a = odd + even b = [odd[0]+1] + even b[-1] -= 1 if b[-1] == 0: b.pop() print(*a) print(len(b)) print(*b)
p04050
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke got a present from his mother on his birthday. The present was a pair of two sequences <var>a</var> and <var>b</var>, consisting of positive integers. They satisfied all of the following properties:</p> <ul> <li>The sum of all elements of <var>a</var> is <var>N</var>.</li> <li>The sum of all elements of <var>b</var> is <var>N</var>.</li> <li>Any string of length <var>N</var> that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).</li> <ul style="list-style:none;"> <li><b>(1)</b> Any of the following forms a palindrome: the first <var>a_1</var> letters, the following <var>a_2</var> letters, the following <var>a_3</var> letters and so on.</li> <li><b>(2)</b> Any of the following forms a palindrome: the first <var>b_1</var> letters, the following <var>b_2</var> letters, the following <var>b_3</var> letters and so on.</li> <li><b>(3)</b> All <var>N</var> letters are the same.</li> </ul> </ul> <p>He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence <var>a</var> was a permutation of another sequence <var>A</var> of length <var>M</var>.</p> <p>To bring him happiness again, his mother has decided to give him another pair of sequences <var>a</var> and <var>b</var> that satisfies his favorite properties and is consistent with his memory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≦N≦10^5</var></li> <li><var>1≦M≦100</var></li> <li><var>1≦A_i≦10^5</var></li> <li>The sum of all <var>A_i</var> equals <var>N</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there exists a pair of sequences <var>a</var> and <var>b</var> that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence <var>a</var>, the second line must contain the length of the sequence <var>b</var>, and the third line must contain the sequence <var>b</var>.</p> <p>If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word <code>Impossible</code> (case-sensitive).</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 2 1 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 1 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 3 1 2 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>55 10 1 2 3 4 5 6 7 8 9 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Impossible </pre></section> </div> </span>
3 2 2 1
1 2 1 3
1,217,736
s965943795
p04050
u340781749
1588795367
Python
Python (3.4.3)
py
Accepted
35
4980
928
import sys def solve(n, m, arr): odds = [] evens = [] for a in arr: if a % 2 == 0: evens.append(a) else: odds.append(a) if len(odds) > 2: print('Impossible') return if len(odds) == 2: o1, o2 = odds aaa = [o1] + evens + [o2] bbb = [2] * (o1 // 2 + 1) bbb += evens bbb += [2] * (o2 // 2) elif len(odds) == 1: if odds[0] == 1: aaa = odds + evens bbb = evens + odds elif evens: aaa = odds + evens bbb = [odds[0] - 1] + evens[:-1] + [evens[-1] + 1] else: aaa = odds bbb = [odds[0] // 2, odds[0] // 2 + 1] else: aaa = evens bbb = [1] + evens[:-1] + [evens[-1] - 1] print(*aaa) print(len(bbb)) print(*bbb) n, m, *aaa = map(int, sys.stdin.buffer.read().split()) solve(n, m, aaa)
p04050
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke got a present from his mother on his birthday. The present was a pair of two sequences <var>a</var> and <var>b</var>, consisting of positive integers. They satisfied all of the following properties:</p> <ul> <li>The sum of all elements of <var>a</var> is <var>N</var>.</li> <li>The sum of all elements of <var>b</var> is <var>N</var>.</li> <li>Any string of length <var>N</var> that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).</li> <ul style="list-style:none;"> <li><b>(1)</b> Any of the following forms a palindrome: the first <var>a_1</var> letters, the following <var>a_2</var> letters, the following <var>a_3</var> letters and so on.</li> <li><b>(2)</b> Any of the following forms a palindrome: the first <var>b_1</var> letters, the following <var>b_2</var> letters, the following <var>b_3</var> letters and so on.</li> <li><b>(3)</b> All <var>N</var> letters are the same.</li> </ul> </ul> <p>He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence <var>a</var> was a permutation of another sequence <var>A</var> of length <var>M</var>.</p> <p>To bring him happiness again, his mother has decided to give him another pair of sequences <var>a</var> and <var>b</var> that satisfies his favorite properties and is consistent with his memory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≦N≦10^5</var></li> <li><var>1≦M≦100</var></li> <li><var>1≦A_i≦10^5</var></li> <li>The sum of all <var>A_i</var> equals <var>N</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there exists a pair of sequences <var>a</var> and <var>b</var> that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence <var>a</var>, the second line must contain the length of the sequence <var>b</var>, and the third line must contain the sequence <var>b</var>.</p> <p>If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word <code>Impossible</code> (case-sensitive).</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 2 1 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 1 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 3 1 2 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>55 10 1 2 3 4 5 6 7 8 9 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Impossible </pre></section> </div> </span>
3 2 2 1
1 2 1 3
1,217,737
s571339864
p04050
u227082700
1577511744
Python
Python (3.4.3)
py
Accepted
18
3064
464
n,m=map(int,input().split()) a=list(map(int,input().split())) b=[] o=[] for i in a: if i%2:o.append(i) else:b.append(i) if len(o)>2:print("Impossible");exit() if len(o)==1:b=o+b elif len(o)==2:b=[o[0]]+b+[o[1]] ans=[] for i in range(len(b)): if i==0:ans.append(b[i]-1) elif i==len(b)-1:ans.append(b[i]+1) else:ans.append(b[i]) anss=[] for i in ans: if i!=0:anss.append(i) if sum(anss)!=n:anss.append(n-sum(anss)) print(*b) print(len(anss)) print(*anss)
p04050
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke got a present from his mother on his birthday. The present was a pair of two sequences <var>a</var> and <var>b</var>, consisting of positive integers. They satisfied all of the following properties:</p> <ul> <li>The sum of all elements of <var>a</var> is <var>N</var>.</li> <li>The sum of all elements of <var>b</var> is <var>N</var>.</li> <li>Any string of length <var>N</var> that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).</li> <ul style="list-style:none;"> <li><b>(1)</b> Any of the following forms a palindrome: the first <var>a_1</var> letters, the following <var>a_2</var> letters, the following <var>a_3</var> letters and so on.</li> <li><b>(2)</b> Any of the following forms a palindrome: the first <var>b_1</var> letters, the following <var>b_2</var> letters, the following <var>b_3</var> letters and so on.</li> <li><b>(3)</b> All <var>N</var> letters are the same.</li> </ul> </ul> <p>He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence <var>a</var> was a permutation of another sequence <var>A</var> of length <var>M</var>.</p> <p>To bring him happiness again, his mother has decided to give him another pair of sequences <var>a</var> and <var>b</var> that satisfies his favorite properties and is consistent with his memory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≦N≦10^5</var></li> <li><var>1≦M≦100</var></li> <li><var>1≦A_i≦10^5</var></li> <li>The sum of all <var>A_i</var> equals <var>N</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there exists a pair of sequences <var>a</var> and <var>b</var> that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence <var>a</var>, the second line must contain the length of the sequence <var>b</var>, and the third line must contain the sequence <var>b</var>.</p> <p>If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word <code>Impossible</code> (case-sensitive).</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 2 1 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 1 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 3 1 2 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>55 10 1 2 3 4 5 6 7 8 9 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Impossible </pre></section> </div> </span>
3 2 2 1
1 2 1 3
1,217,738
s943528127
p04050
u211706121
1576375590
Python
Python (3.4.3)
py
Accepted
20
3188
867
n,m = [int(i) for i in input().split()] a = [int(i) for i in input().split()] breakFlag = False for i in range(1,m-1): if a[i]%2==1: if a[0]%2==1: if a[len(a)-1]%2==1: print("Impossible") breakFlag = True break else: a[i],a[len(a)-1] = a[len(a)-1],a[i] else: a[i],a[0] = a[0],a[i] if breakFlag==False: ans = ''.join([str(s)+" " for s in a]) print(ans[:-1]) if m==1: if a[0]>1: a[0]-=1 a.append(1) print(m+1) else: print(m) else: if a[len(a)-1]==1: print(m-1) a.pop() a[0]+=1 else: print(m) a[0]+=1 a[len(a)-1] -= 1 ans = ''.join([str(s)+" " for s in a]) print(ans[:-1])
p04050
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke got a present from his mother on his birthday. The present was a pair of two sequences <var>a</var> and <var>b</var>, consisting of positive integers. They satisfied all of the following properties:</p> <ul> <li>The sum of all elements of <var>a</var> is <var>N</var>.</li> <li>The sum of all elements of <var>b</var> is <var>N</var>.</li> <li>Any string of length <var>N</var> that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).</li> <ul style="list-style:none;"> <li><b>(1)</b> Any of the following forms a palindrome: the first <var>a_1</var> letters, the following <var>a_2</var> letters, the following <var>a_3</var> letters and so on.</li> <li><b>(2)</b> Any of the following forms a palindrome: the first <var>b_1</var> letters, the following <var>b_2</var> letters, the following <var>b_3</var> letters and so on.</li> <li><b>(3)</b> All <var>N</var> letters are the same.</li> </ul> </ul> <p>He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence <var>a</var> was a permutation of another sequence <var>A</var> of length <var>M</var>.</p> <p>To bring him happiness again, his mother has decided to give him another pair of sequences <var>a</var> and <var>b</var> that satisfies his favorite properties and is consistent with his memory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≦N≦10^5</var></li> <li><var>1≦M≦100</var></li> <li><var>1≦A_i≦10^5</var></li> <li>The sum of all <var>A_i</var> equals <var>N</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there exists a pair of sequences <var>a</var> and <var>b</var> that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence <var>a</var>, the second line must contain the length of the sequence <var>b</var>, and the third line must contain the sequence <var>b</var>.</p> <p>If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word <code>Impossible</code> (case-sensitive).</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 2 1 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 1 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 3 1 2 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>55 10 1 2 3 4 5 6 7 8 9 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Impossible </pre></section> </div> </span>
3 2 2 1
1 2 1 3
1,217,739
s065079131
p04050
u102461423
1569523863
Python
Python (3.4.3)
py
Accepted
17
3064
662
import sys readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 7) N,M = map(int,readline().split()) A = [int(x) for x in readline().split()] OD = [x for x in A if x&1] EV = [x for x in A if not x&1] if len(OD) >= 3: print('Impossible') exit() if len(A) == 1: if N == 1: B = [1] else: B = [1,N-1] elif len(OD) == 0: B = A.copy() B[0] -= 1 B[-1] += 1 elif len(OD) == 1: A = OD + EV B = A.copy() B[0] += 1 B[-1] -= 1 else: A = [OD[0]] + EV + [OD[-1]] B = A.copy() B[0] += 1 B[-1] -= 1 B = [x for x in B if x > 0] print(*A) print(len(B)) print(*B)
p04050
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke got a present from his mother on his birthday. The present was a pair of two sequences <var>a</var> and <var>b</var>, consisting of positive integers. They satisfied all of the following properties:</p> <ul> <li>The sum of all elements of <var>a</var> is <var>N</var>.</li> <li>The sum of all elements of <var>b</var> is <var>N</var>.</li> <li>Any string of length <var>N</var> that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).</li> <ul style="list-style:none;"> <li><b>(1)</b> Any of the following forms a palindrome: the first <var>a_1</var> letters, the following <var>a_2</var> letters, the following <var>a_3</var> letters and so on.</li> <li><b>(2)</b> Any of the following forms a palindrome: the first <var>b_1</var> letters, the following <var>b_2</var> letters, the following <var>b_3</var> letters and so on.</li> <li><b>(3)</b> All <var>N</var> letters are the same.</li> </ul> </ul> <p>He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence <var>a</var> was a permutation of another sequence <var>A</var> of length <var>M</var>.</p> <p>To bring him happiness again, his mother has decided to give him another pair of sequences <var>a</var> and <var>b</var> that satisfies his favorite properties and is consistent with his memory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≦N≦10^5</var></li> <li><var>1≦M≦100</var></li> <li><var>1≦A_i≦10^5</var></li> <li>The sum of all <var>A_i</var> equals <var>N</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there exists a pair of sequences <var>a</var> and <var>b</var> that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence <var>a</var>, the second line must contain the length of the sequence <var>b</var>, and the third line must contain the sequence <var>b</var>.</p> <p>If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word <code>Impossible</code> (case-sensitive).</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 2 1 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 1 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 3 1 2 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>55 10 1 2 3 4 5 6 7 8 9 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Impossible </pre></section> </div> </span>
3 2 2 1
1 2 1 3
1,217,740
s952339729
p04050
u816116805
1542178048
Python
Python (3.4.3)
py
Accepted
18
3064
826
#! /usr/bin/env python # -*- coding: utf-8 -*- # vim:fenc=utf-8 # """ agc001 D """ n, m = map(int, input().split()) ali = list(map(int, input().split())) if m == 1 and ali[0] == 1: print(1) print(1) print(1) exit() if m == 1: print(ali[0]) print(2) print(ali[0]-1, 1) exit() flag = 0 c = [] for a in ali: if a % 2 == 1: if flag == 0: lm = a flag += 1 elif flag == 1: rm = a flag += 1 elif flag == 2: print('Impossible') exit() else: c.append(a) if flag == 0: lm = c[0] del c[0] rm = c.pop() if flag == 1: rm = c.pop() b = [lm+1] + c d = [lm] + c + [rm] if rm > 1: b.append(rm-1) print(" ".join(map(str, d))) print(len(b)) print(" ".join(map(str, b)))
p04050
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke got a present from his mother on his birthday. The present was a pair of two sequences <var>a</var> and <var>b</var>, consisting of positive integers. They satisfied all of the following properties:</p> <ul> <li>The sum of all elements of <var>a</var> is <var>N</var>.</li> <li>The sum of all elements of <var>b</var> is <var>N</var>.</li> <li>Any string of length <var>N</var> that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).</li> <ul style="list-style:none;"> <li><b>(1)</b> Any of the following forms a palindrome: the first <var>a_1</var> letters, the following <var>a_2</var> letters, the following <var>a_3</var> letters and so on.</li> <li><b>(2)</b> Any of the following forms a palindrome: the first <var>b_1</var> letters, the following <var>b_2</var> letters, the following <var>b_3</var> letters and so on.</li> <li><b>(3)</b> All <var>N</var> letters are the same.</li> </ul> </ul> <p>He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence <var>a</var> was a permutation of another sequence <var>A</var> of length <var>M</var>.</p> <p>To bring him happiness again, his mother has decided to give him another pair of sequences <var>a</var> and <var>b</var> that satisfies his favorite properties and is consistent with his memory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≦N≦10^5</var></li> <li><var>1≦M≦100</var></li> <li><var>1≦A_i≦10^5</var></li> <li>The sum of all <var>A_i</var> equals <var>N</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there exists a pair of sequences <var>a</var> and <var>b</var> that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence <var>a</var>, the second line must contain the length of the sequence <var>b</var>, and the third line must contain the sequence <var>b</var>.</p> <p>If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word <code>Impossible</code> (case-sensitive).</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 2 1 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 1 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 3 1 2 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>55 10 1 2 3 4 5 6 7 8 9 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Impossible </pre></section> </div> </span>
3 2 2 1
1 2 1 3
1,217,741
s213815438
p04050
u207056619
1504708476
Python
Python (3.4.3)
py
Accepted
17
3064
778
#!/usr/bin/env python3 def solve(n, m, a): odd = [] even = [] for a_i in a: if a_i % 2 == 0: even += [ a_i ] else: odd += [ a_i ] if len(odd) >= 3: return None a, b = [], [] if odd: x = odd.pop() a += [ x ] b += [ x - 1 ] else: x = even.pop() a += [ x ] b += [ x - 1 ] a += even b += even if odd: x = odd.pop() a += [ x ] b += [ x + 1 ] else: b += [ 1 ] return a, b n, m = map(int, input().split()) a = list(map(int, input().split())) it = solve(n, m, a) if it is None: print('Impossible') else: a, b = it b = list(filter(lambda b_i: b_i, b)) print(*a) print(len(b)) print(*b)
p04050
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke got a present from his mother on his birthday. The present was a pair of two sequences <var>a</var> and <var>b</var>, consisting of positive integers. They satisfied all of the following properties:</p> <ul> <li>The sum of all elements of <var>a</var> is <var>N</var>.</li> <li>The sum of all elements of <var>b</var> is <var>N</var>.</li> <li>Any string of length <var>N</var> that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).</li> <ul style="list-style:none;"> <li><b>(1)</b> Any of the following forms a palindrome: the first <var>a_1</var> letters, the following <var>a_2</var> letters, the following <var>a_3</var> letters and so on.</li> <li><b>(2)</b> Any of the following forms a palindrome: the first <var>b_1</var> letters, the following <var>b_2</var> letters, the following <var>b_3</var> letters and so on.</li> <li><b>(3)</b> All <var>N</var> letters are the same.</li> </ul> </ul> <p>He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence <var>a</var> was a permutation of another sequence <var>A</var> of length <var>M</var>.</p> <p>To bring him happiness again, his mother has decided to give him another pair of sequences <var>a</var> and <var>b</var> that satisfies his favorite properties and is consistent with his memory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≦N≦10^5</var></li> <li><var>1≦M≦100</var></li> <li><var>1≦A_i≦10^5</var></li> <li>The sum of all <var>A_i</var> equals <var>N</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there exists a pair of sequences <var>a</var> and <var>b</var> that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence <var>a</var>, the second line must contain the length of the sequence <var>b</var>, and the third line must contain the sequence <var>b</var>.</p> <p>If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word <code>Impossible</code> (case-sensitive).</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 2 1 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 1 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 3 1 2 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>55 10 1 2 3 4 5 6 7 8 9 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Impossible </pre></section> </div> </span>
3 2 2 1
1 2 1 3
1,217,742
s637050993
p04050
u804080968
1468806315
Python
Python (3.4.3)
py
Accepted
39
3064
388
S, N = map(int, input().split()) A = list(map(int, input().split())) O = [a for a in A if a % 2 == 1] E = [a for a in A if a % 2 == 0] if len(O) > 2: print("Impossible") else: A = O[:min(len(O), 1)] + E + O[1:] B = A[:] + ([0] if N == 1 else []) B[0] -= 1 B[-1] += 1 if B[0] == 0: B = B[1:] print(*A, sep=" ") print(len(B)) print(*B, sep=" ")
p04050
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke got a present from his mother on his birthday. The present was a pair of two sequences <var>a</var> and <var>b</var>, consisting of positive integers. They satisfied all of the following properties:</p> <ul> <li>The sum of all elements of <var>a</var> is <var>N</var>.</li> <li>The sum of all elements of <var>b</var> is <var>N</var>.</li> <li>Any string of length <var>N</var> that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).</li> <ul style="list-style:none;"> <li><b>(1)</b> Any of the following forms a palindrome: the first <var>a_1</var> letters, the following <var>a_2</var> letters, the following <var>a_3</var> letters and so on.</li> <li><b>(2)</b> Any of the following forms a palindrome: the first <var>b_1</var> letters, the following <var>b_2</var> letters, the following <var>b_3</var> letters and so on.</li> <li><b>(3)</b> All <var>N</var> letters are the same.</li> </ul> </ul> <p>He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence <var>a</var> was a permutation of another sequence <var>A</var> of length <var>M</var>.</p> <p>To bring him happiness again, his mother has decided to give him another pair of sequences <var>a</var> and <var>b</var> that satisfies his favorite properties and is consistent with his memory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≦N≦10^5</var></li> <li><var>1≦M≦100</var></li> <li><var>1≦A_i≦10^5</var></li> <li>The sum of all <var>A_i</var> equals <var>N</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there exists a pair of sequences <var>a</var> and <var>b</var> that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence <var>a</var>, the second line must contain the length of the sequence <var>b</var>, and the third line must contain the sequence <var>b</var>.</p> <p>If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word <code>Impossible</code> (case-sensitive).</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 2 1 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 1 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 3 1 2 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>55 10 1 2 3 4 5 6 7 8 9 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Impossible </pre></section> </div> </span>
3 2 2 1
1 2 1 3
1,217,743
s709919279
p04050
u804080968
1468805506
Python
Python (3.4.3)
py
Accepted
42
3064
438
S, N = map(int, input().split()) A = list(map(int, input().split())) O = [a for a in A if a % 2 == 1] E = [a for a in A if a % 2 == 0] if len(O) > 2: print("Impossible") else: A = O[:min(len(O), 1)] + E + O[min(1, len(O)):] B = A[:] + ([0] if len(A) == 1 else []) B[0] -= 1 B[-1] += 1 if B[0] == 0: B = B[1:] print(" ".join(str(a) for a in A)) print(len(B)) print(" ".join(str(b) for b in B))
p04050
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke got a present from his mother on his birthday. The present was a pair of two sequences <var>a</var> and <var>b</var>, consisting of positive integers. They satisfied all of the following properties:</p> <ul> <li>The sum of all elements of <var>a</var> is <var>N</var>.</li> <li>The sum of all elements of <var>b</var> is <var>N</var>.</li> <li>Any string of length <var>N</var> that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).</li> <ul style="list-style:none;"> <li><b>(1)</b> Any of the following forms a palindrome: the first <var>a_1</var> letters, the following <var>a_2</var> letters, the following <var>a_3</var> letters and so on.</li> <li><b>(2)</b> Any of the following forms a palindrome: the first <var>b_1</var> letters, the following <var>b_2</var> letters, the following <var>b_3</var> letters and so on.</li> <li><b>(3)</b> All <var>N</var> letters are the same.</li> </ul> </ul> <p>He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence <var>a</var> was a permutation of another sequence <var>A</var> of length <var>M</var>.</p> <p>To bring him happiness again, his mother has decided to give him another pair of sequences <var>a</var> and <var>b</var> that satisfies his favorite properties and is consistent with his memory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≦N≦10^5</var></li> <li><var>1≦M≦100</var></li> <li><var>1≦A_i≦10^5</var></li> <li>The sum of all <var>A_i</var> equals <var>N</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there exists a pair of sequences <var>a</var> and <var>b</var> that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence <var>a</var>, the second line must contain the length of the sequence <var>b</var>, and the third line must contain the sequence <var>b</var>.</p> <p>If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word <code>Impossible</code> (case-sensitive).</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 2 1 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 1 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 3 1 2 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>55 10 1 2 3 4 5 6 7 8 9 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Impossible </pre></section> </div> </span>
3 2 2 1
1 2 1 3
1,217,744
s678667268
p04050
u945080461
1468721660
Python
Python (2.7.6)
py
Accepted
27
2696
659
from sys import stdout def main(): n, m = map(int, raw_input().split()) a = map(int, raw_input().split()) if m == 1: print a[0] if n == 1: print 1 print 1 else: print 2 print 1, n - 1 return if sum(x % 2 for x in a) > 2: print "Impossible" return a.sort(key=lambda x: x%2) a = a[-1:] + a[:-1] t = a[:] t[0] += 1 t[-1] -= 1 if not t[-1]: t.pop() stdout.write(' '.join(map(str, a))) stdout.write('\n') stdout.write(str(len(t)) + '\n') stdout.write(' '.join(map(str, t))) stdout.write('\n') main()
p04050
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke got a present from his mother on his birthday. The present was a pair of two sequences <var>a</var> and <var>b</var>, consisting of positive integers. They satisfied all of the following properties:</p> <ul> <li>The sum of all elements of <var>a</var> is <var>N</var>.</li> <li>The sum of all elements of <var>b</var> is <var>N</var>.</li> <li>Any string of length <var>N</var> that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).</li> <ul style="list-style:none;"> <li><b>(1)</b> Any of the following forms a palindrome: the first <var>a_1</var> letters, the following <var>a_2</var> letters, the following <var>a_3</var> letters and so on.</li> <li><b>(2)</b> Any of the following forms a palindrome: the first <var>b_1</var> letters, the following <var>b_2</var> letters, the following <var>b_3</var> letters and so on.</li> <li><b>(3)</b> All <var>N</var> letters are the same.</li> </ul> </ul> <p>He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence <var>a</var> was a permutation of another sequence <var>A</var> of length <var>M</var>.</p> <p>To bring him happiness again, his mother has decided to give him another pair of sequences <var>a</var> and <var>b</var> that satisfies his favorite properties and is consistent with his memory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≦N≦10^5</var></li> <li><var>1≦M≦100</var></li> <li><var>1≦A_i≦10^5</var></li> <li>The sum of all <var>A_i</var> equals <var>N</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there exists a pair of sequences <var>a</var> and <var>b</var> that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence <var>a</var>, the second line must contain the length of the sequence <var>b</var>, and the third line must contain the sequence <var>b</var>.</p> <p>If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word <code>Impossible</code> (case-sensitive).</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 2 1 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 1 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 3 1 2 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>55 10 1 2 3 4 5 6 7 8 9 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Impossible </pre></section> </div> </span>
3 2 2 1
1 2 1 3
1,217,745