output_description stringlengths 15 956 | submission_id stringlengths 10 10 | status stringclasses 3 values | problem_id stringlengths 6 6 | input_description stringlengths 9 2.55k | attempt stringlengths 1 13.7k | problem_description stringlengths 7 5.24k | samples stringlengths 2 2.72k |
|---|---|---|---|---|---|---|---|
Print the lexicographically smallest string after performing exactly K
operations on s.
* * * | s149283408 | Runtime Error | p03994 | The input is given from Standard Input in the following format:
s
K | a=[ord(i) for i in input()]
s = int(input())
for i in range(len(a)):
if 26+97-a[i]<=s && a[i]!=97:
aa=a[i]
a[i]=97
s-=26+97-aa
if s>0:
a[-1]+=s
if a[-1]>97+25:
a[-1]=(a[-1]-97)%26+97
b=""
for i in a:
b+=chr(i)
print(b) | Statement
Mr. Takahashi has a string s consisting of lowercase English letters. He
repeats the following operation on s exactly K times.
* Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`.
For example, if you perform an operation for the second letter on `aaz`, `aaz`
becomes `abz`. If you then perform an operation for the third letter on `abz`,
`abz` becomes `aba`.
Mr. Takahashi wants to have the lexicographically smallest string after
performing exactly K operations on s. Find the such string. | [{"input": "xyz\n 4", "output": "aya\n \n\nFor example, you can perform the following operations: `xyz`, `yyz`, `zyz`,\n`ayz`, `aya`.\n\n* * *"}, {"input": "a\n 25", "output": "z\n \n\nYou have to perform exactly K operations.\n\n* * *"}, {"input": "codefestival\n 100", "output": "aaaafeaaivap"}] |
Print the lexicographically smallest string after performing exactly K
operations on s.
* * * | s157005519 | Accepted | p03994 | The input is given from Standard Input in the following format:
s
K | import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians
sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9 + 7
def lcm(x, y):
return x * y // gcd(x, y)
def lgcd(l):
return reduce(gcd, l)
def llcm(l):
return reduce(lcm, l)
def powmod(n, i, mod=MOD):
return pow(n, mod - 1 + i, mod) if i < 0 else pow(n, i, mod)
def div2(x):
return x.bit_length()
def div10(x):
return len(str(x)) - (x == 0)
def intput():
return int(input())
def mint():
return map(int, input().split())
def lint():
return list(map(int, input().split()))
def ilint():
return int(input()), list(map(int, input().split()))
def judge(x, l=["Yes", "No"]):
print(l[0] if x else l[1])
def lprint(l, sep="\n"):
for x in l:
print(x, end=sep)
def ston(c, c0="a"):
return ord(c) - ord(c0)
def ntos(x, c0="a"):
return chr(x + ord(c0))
class counter(dict):
def __init__(self, *args):
super().__init__(args)
def add(self, x, d=1):
self.setdefault(x, 0)
self[x] += d
def list(self):
l = []
for k in self:
l.extend([k] * self[k])
return l
class comb:
def __init__(self, n, mod=None):
self.l = [1]
self.n = n
self.mod = mod
def get(self, k):
l, n, mod = self.l, self.n, self.mod
k = n - k if k > n // 2 else k
while len(l) <= k:
i = len(l)
l.append(
l[i - 1] * (n + 1 - i) // i
if mod == None
else (l[i - 1] * (n + 1 - i) * powmod(i, -1, mod)) % mod
)
return l[k]
def pf(x, mode="counter"):
C = counter()
p = 2
while x > 1:
k = 0
while x % p == 0:
x //= p
k += 1
if k > 0:
C.add(p, k)
p = p + 2 - (p == 2) if p * p < x else x
if mode == "counter":
return C
S = set([1])
for k in C:
T = deepcopy(S)
for x in T:
for i in range(1, C[k] + 1):
S.add(x * (k**i))
if mode == "set":
return S
if mode == "list":
return sorted(list(S))
s = input()
N = len(s)
K = intput()
ans = []
for i in range(N - 1):
if (26 - ston(s[i])) % 26 <= K:
ans.append("a")
K -= (26 - ston(s[i])) % 26
else:
ans.append(s[i])
ans.append(ntos((ston(s[N - 1]) + K) % 26))
lprint(ans, "")
| Statement
Mr. Takahashi has a string s consisting of lowercase English letters. He
repeats the following operation on s exactly K times.
* Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`.
For example, if you perform an operation for the second letter on `aaz`, `aaz`
becomes `abz`. If you then perform an operation for the third letter on `abz`,
`abz` becomes `aba`.
Mr. Takahashi wants to have the lexicographically smallest string after
performing exactly K operations on s. Find the such string. | [{"input": "xyz\n 4", "output": "aya\n \n\nFor example, you can perform the following operations: `xyz`, `yyz`, `zyz`,\n`ayz`, `aya`.\n\n* * *"}, {"input": "a\n 25", "output": "z\n \n\nYou have to perform exactly K operations.\n\n* * *"}, {"input": "codefestival\n 100", "output": "aaaafeaaivap"}] |
Print the lexicographically smallest string after performing exactly K
operations on s.
* * * | s068068536 | Accepted | p03994 | The input is given from Standard Input in the following format:
s
K | import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, ceil, gcd
from functools import lru_cache, reduce
from decimal import Decimal
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10**7)
# UnionFind
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())
# ダイクストラ
def dijkstra_heap(s, edge, n):
# 始点sから各頂点への最短距離
d = [10**20] * n
used = [True] * n # True:未確定
d[s] = 0
used[s] = False
edgelist = []
for a, b in edge[s]:
heapq.heappush(edgelist, a * (10**6) + b)
while len(edgelist):
minedge = heapq.heappop(edgelist)
# まだ使われてない頂点の中から最小の距離のものを探す
if not used[minedge % (10**6)]:
continue
v = minedge % (10**6)
d[v] = minedge // (10**6)
used[v] = False
for e in edge[v]:
if used[e[1]]:
heapq.heappush(edgelist, (e[0] + d[v]) * (10**6) + e[1])
return d
# 素因数分解
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
# 2数の最小公倍数
def lcm(x, y):
return (x * y) // gcd(x, y)
# リストの要素の最小公倍数
def lcm_list(numbers):
return reduce(lcm, numbers, 1)
# リストの要素の最大公約数
def gcd_list(numbers):
return reduce(gcd, numbers)
# 素数判定
def is_prime(n):
if n <= 1:
return False
p = 2
while True:
if p**2 > n:
break
if n % p == 0:
return False
p += 1
return True
# limit以下の素数を列挙
def eratosthenes(limit):
A = [i for i in range(2, limit + 1)]
P = []
while True:
prime = min(A)
if prime > sqrt(limit):
break
P.append(prime)
i = 0
while i < len(A):
if A[i] % prime == 0:
A.pop(i)
continue
i += 1
for a in A:
P.append(a)
return P
# 同じものを含む順列
def permutation_with_duplicates(L):
if L == []:
return [[]]
else:
ret = []
# set(集合)型で重複を削除、ソート
S = sorted(set(L))
for i in S:
data = L[:]
data.remove(i)
for j in permutation_with_duplicates(data):
ret.append([i] + j)
return ret
def make_divisors(n):
lower_divisors, upper_divisors = [], []
i = 1
while i * i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n // i)
i += 1
return lower_divisors + upper_divisors[::-1]
# ここから書き始める
s = input()
k = int(input())
cnt = 0
n = len(s)
ans = [i for i in s]
for i in range(n):
# print("cnt =", cnt)
if cnt == k:
break
cost = ord("z") + 1 - ord(ans[i])
if i == n - 1:
cost2 = cost - 1
# print(k - cnt <= cost2)
if k - cnt <= cost2:
ans[i] = chr(ord(ans[i]) + k - cnt)
else:
k2 = k - cnt - cost2
if k2 % 26 == 0:
ans[i] = "z"
else:
ans[i] = chr(ord("a") + k2 % 26 - 1)
break
if ans[i] == "a":
continue
if k - cnt >= cost:
cnt += cost
ans[i] = "a"
print("".join(ans))
| Statement
Mr. Takahashi has a string s consisting of lowercase English letters. He
repeats the following operation on s exactly K times.
* Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`.
For example, if you perform an operation for the second letter on `aaz`, `aaz`
becomes `abz`. If you then perform an operation for the third letter on `abz`,
`abz` becomes `aba`.
Mr. Takahashi wants to have the lexicographically smallest string after
performing exactly K operations on s. Find the such string. | [{"input": "xyz\n 4", "output": "aya\n \n\nFor example, you can perform the following operations: `xyz`, `yyz`, `zyz`,\n`ayz`, `aya`.\n\n* * *"}, {"input": "a\n 25", "output": "z\n \n\nYou have to perform exactly K operations.\n\n* * *"}, {"input": "codefestival\n 100", "output": "aaaafeaaivap"}] |
Print the lexicographically smallest string after performing exactly K
operations on s.
* * * | s406979394 | Runtime Error | p03994 | The input is given from Standard Input in the following format:
s
K | s=str(input())
k=int(input())
lista=[]
for i in range(26):
lista.append(chr(ord('a') + i))
#print(lista)
s_list=list(s)
len_s=len(list(s))
temp1=k
temp2=0
for i in range(len_s):
if (123-ord(s_list[i])<=temp1):
temp1=temp1-(123-ord(s_list[i]))
s_list[i]="a"
if temp1!=0:
# print(temp1)
temp2=temp1%26+ord(s_list[-1])
if temp2>122:
temp2=temp2-122+96
s_list[-1]=chr(temp2)
#print(temp2)
#print(str(s_list))
for i in range(len(s_list)):
print(s_list[i],end="")
print(\n)
| Statement
Mr. Takahashi has a string s consisting of lowercase English letters. He
repeats the following operation on s exactly K times.
* Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`.
For example, if you perform an operation for the second letter on `aaz`, `aaz`
becomes `abz`. If you then perform an operation for the third letter on `abz`,
`abz` becomes `aba`.
Mr. Takahashi wants to have the lexicographically smallest string after
performing exactly K operations on s. Find the such string. | [{"input": "xyz\n 4", "output": "aya\n \n\nFor example, you can perform the following operations: `xyz`, `yyz`, `zyz`,\n`ayz`, `aya`.\n\n* * *"}, {"input": "a\n 25", "output": "z\n \n\nYou have to perform exactly K operations.\n\n* * *"}, {"input": "codefestival\n 100", "output": "aaaafeaaivap"}] |
Print the lexicographically smallest string after performing exactly K
operations on s.
* * * | s722495282 | Runtime Error | p03994 | The input is given from Standard Input in the following format:
s
K | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main()
{
#ifdef DEBUG
cout << "DEBUG MODE" << endl;
ifstream in("input.txt"); //for debug
cin.rdbuf(in.rdbuf()); //for debug
#endif
string s;
cin >> s;
int k, a;
cin >> k;
rep(i, s.length()-1){
a = 'z' - s[i];
if (k > a){
k -= a + 1;
s[i] = 'a';
}
}
k %= 26;
s[s.length()-1] += k;
if (s[s.length()-1] > 'z')
s[s.length()-1] -= 26;
cout << s << endl;
return 0;
}
| Statement
Mr. Takahashi has a string s consisting of lowercase English letters. He
repeats the following operation on s exactly K times.
* Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`.
For example, if you perform an operation for the second letter on `aaz`, `aaz`
becomes `abz`. If you then perform an operation for the third letter on `abz`,
`abz` becomes `aba`.
Mr. Takahashi wants to have the lexicographically smallest string after
performing exactly K operations on s. Find the such string. | [{"input": "xyz\n 4", "output": "aya\n \n\nFor example, you can perform the following operations: `xyz`, `yyz`, `zyz`,\n`ayz`, `aya`.\n\n* * *"}, {"input": "a\n 25", "output": "z\n \n\nYou have to perform exactly K operations.\n\n* * *"}, {"input": "codefestival\n 100", "output": "aaaafeaaivap"}] |
Print the lexicographically smallest string after performing exactly K
operations on s.
* * * | s414932737 | Runtime Error | p03994 | The input is given from Standard Input in the following format:
s
K | jkl
| Statement
Mr. Takahashi has a string s consisting of lowercase English letters. He
repeats the following operation on s exactly K times.
* Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`.
For example, if you perform an operation for the second letter on `aaz`, `aaz`
becomes `abz`. If you then perform an operation for the third letter on `abz`,
`abz` becomes `aba`.
Mr. Takahashi wants to have the lexicographically smallest string after
performing exactly K operations on s. Find the such string. | [{"input": "xyz\n 4", "output": "aya\n \n\nFor example, you can perform the following operations: `xyz`, `yyz`, `zyz`,\n`ayz`, `aya`.\n\n* * *"}, {"input": "a\n 25", "output": "z\n \n\nYou have to perform exactly K operations.\n\n* * *"}, {"input": "codefestival\n 100", "output": "aaaafeaaivap"}] |
Print the lexicographically smallest string after performing exactly K
operations on s.
* * * | s215589209 | Accepted | p03994 | The input is given from Standard Input in the following format:
s
K | # -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *
class Scanner:
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [input() for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [int(input()) for i in range(n)]
class Math:
@staticmethod
def gcd(a, b):
if b == 0:
return a
return Math.gcd(b, a % b)
@staticmethod
def lcm(a, b):
return (a * b) // Math.gcd(a, b)
@staticmethod
def divisor(n):
res = []
i = 1
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
res.append(i)
if i != n // i:
res.append(n // i)
return res
@staticmethod
def round_up(a, b):
return -(-a // b)
@staticmethod
def is_prime(n):
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
d = int(n**0.5) + 1
for i in range(3, d + 1, 2):
if n % i == 0:
return False
return True
def pop_count(x):
x = x - ((x >> 1) & 0x5555555555555555)
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F
x = x + (x >> 8)
x = x + (x >> 16)
x = x + (x >> 32)
return x & 0x0000007F
MOD = int(1e09) + 7
INF = int(1e15)
def solve():
S = list(Scanner.string())
K = Scanner.int()
i = 0
while i < len(S):
c = S[i]
n = ord(c) - ord("a")
if n > 0 and 26 - n <= K:
c = "a"
K -= 26 - n
S[i] = c
i += 1
if K > 0:
c = S[-1]
for _ in range(K % 26):
c = chr(ord(c) + 1)
if c == chr(ord("z") + 1):
c = "a"
S[-1] = c
print("".join(S))
def main():
# sys.stdin = open("sample.txt")
solve()
if __name__ == "__main__":
main()
| Statement
Mr. Takahashi has a string s consisting of lowercase English letters. He
repeats the following operation on s exactly K times.
* Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`.
For example, if you perform an operation for the second letter on `aaz`, `aaz`
becomes `abz`. If you then perform an operation for the third letter on `abz`,
`abz` becomes `aba`.
Mr. Takahashi wants to have the lexicographically smallest string after
performing exactly K operations on s. Find the such string. | [{"input": "xyz\n 4", "output": "aya\n \n\nFor example, you can perform the following operations: `xyz`, `yyz`, `zyz`,\n`ayz`, `aya`.\n\n* * *"}, {"input": "a\n 25", "output": "z\n \n\nYou have to perform exactly K operations.\n\n* * *"}, {"input": "codefestival\n 100", "output": "aaaafeaaivap"}] |
Print the lexicographically smallest string after performing exactly K
operations on s.
* * * | s494336528 | Accepted | p03994 | The input is given from Standard Input in the following format:
s
K | w = input()
nw = len(w)
lw = list(w)
n = int(input())
alpha = "qwertyuiopasdfghjklzxcvbnm"
l = sorted(list(alpha))
d = {}
for i in range(26):
d[l[i]] = i
num = n
count = 0
while num > 0 and count < nw:
if lw[count] == "a":
count += 1
else:
letter = lw[count]
if 27 - d[letter] - 1 <= num:
num -= 27 - d[letter] - 1
lw[count] = "a"
count += 1
else:
count += 1
if num > 0:
a = lw[-1]
num1 = d[a]
lw[-1] = l[(num1 + num) % 26]
print("".join(lw))
| Statement
Mr. Takahashi has a string s consisting of lowercase English letters. He
repeats the following operation on s exactly K times.
* Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`.
For example, if you perform an operation for the second letter on `aaz`, `aaz`
becomes `abz`. If you then perform an operation for the third letter on `abz`,
`abz` becomes `aba`.
Mr. Takahashi wants to have the lexicographically smallest string after
performing exactly K operations on s. Find the such string. | [{"input": "xyz\n 4", "output": "aya\n \n\nFor example, you can perform the following operations: `xyz`, `yyz`, `zyz`,\n`ayz`, `aya`.\n\n* * *"}, {"input": "a\n 25", "output": "z\n \n\nYou have to perform exactly K operations.\n\n* * *"}, {"input": "codefestival\n 100", "output": "aaaafeaaivap"}] |
Print the lexicographically smallest string after performing exactly K
operations on s.
* * * | s879178950 | Runtime Error | p03994 | The input is given from Standard Input in the following format:
s
K | #n,x=map(int,input().split())
#a=[int(i) for i in input().split()]
import string
alp=string.ascii_lowercase
di={}
for i in range(26):
di[alp[i]]=i
s=input()
a=[]
for i in s:
a.append(i)
l=a.pop()
if a:
a=a[::-1]
k=int(input())
ans=''
i=0
while a:
t=a.pop()
d=(26-di[t])%26
if d<=k:
k-=d
#ans+='a'
else:
#ans+=t
i+=1
kk=k%26
#ans+=alp[(alp.index(l)+kk)%26]
print(ans)
| Statement
Mr. Takahashi has a string s consisting of lowercase English letters. He
repeats the following operation on s exactly K times.
* Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`.
For example, if you perform an operation for the second letter on `aaz`, `aaz`
becomes `abz`. If you then perform an operation for the third letter on `abz`,
`abz` becomes `aba`.
Mr. Takahashi wants to have the lexicographically smallest string after
performing exactly K operations on s. Find the such string. | [{"input": "xyz\n 4", "output": "aya\n \n\nFor example, you can perform the following operations: `xyz`, `yyz`, `zyz`,\n`ayz`, `aya`.\n\n* * *"}, {"input": "a\n 25", "output": "z\n \n\nYou have to perform exactly K operations.\n\n* * *"}, {"input": "codefestival\n 100", "output": "aaaafeaaivap"}] |
If a bracket sequence can be formed by concatenating all the N strings in some
order, print `Yes`; otherwise, print `No`.
* * * | s565558685 | Wrong Answer | p02686 | Input is given from Standard Input in the following format:
N
S_1
:
S_N | N = int(input())
Lflg = 0
Rflg = 0
ryohoCnt = 0
LOver = 0
for i in range(N):
S = input()
lnum = S.count("(") - S.count(")")
konkaiflg = 0
if Lflg < 2 or ryohoCnt < 2:
if S[0] == "(" and lnum >= 0:
f = 0
for j in range(len(S)):
if S[0:j].count("(") - S[0:j].count(")") < 0:
f = 1
break
if f == 0:
Lflg = Lflg + 1
konkaiflg = 1
if Rflg < 2 or ryohoCnt < 2:
if S[-1] == ")" and lnum <= 0:
f = 0
for j in range(len(S)):
if S[j * (-1)].count("(") - S[j * (-1)].count(")") > 0:
f = 1
break
if f == 0:
Rflg = Rflg + 1
if konkaiflg == 1:
ryohoCnt = ryohoCnt + 1
LOver = LOver + lnum
if (
Lflg >= 1
and Rflg >= 1
and LOver == 0
and not (ryohoCnt == 1 and Lflg == 1 and Rflg == 1)
):
print("Yes")
else:
print("No")
| Statement
A **bracket sequence** is a string that is one of the following:
1. An empty string;
2. The concatenation of `(`, A, and `)` in this order, for some bracket sequence A ;
3. The concatenation of A and B in this order, for some non-empty bracket sequences A and B /
Given are N strings S_i. Can a bracket sequence be formed by concatenating all
the N strings in some order? | [{"input": "2\n )\n (()", "output": "Yes\n \n\nConcatenating `(()` and `)` in this order forms a bracket sequence.\n\n* * *"}, {"input": "2\n )(\n ()", "output": "No\n \n\n* * *"}, {"input": "4\n ((()))\n ((((((\n ))))))\n ()()()", "output": "Yes\n \n\n* * *"}, {"input": "3\n (((\n )\n )", "output": "No"}] |
If a bracket sequence can be formed by concatenating all the N strings in some
order, print `Yes`; otherwise, print `No`.
* * * | s362688916 | Wrong Answer | p02686 | Input is given from Standard Input in the following format:
N
S_1
:
S_N | print("Yes")
| Statement
A **bracket sequence** is a string that is one of the following:
1. An empty string;
2. The concatenation of `(`, A, and `)` in this order, for some bracket sequence A ;
3. The concatenation of A and B in this order, for some non-empty bracket sequences A and B /
Given are N strings S_i. Can a bracket sequence be formed by concatenating all
the N strings in some order? | [{"input": "2\n )\n (()", "output": "Yes\n \n\nConcatenating `(()` and `)` in this order forms a bracket sequence.\n\n* * *"}, {"input": "2\n )(\n ()", "output": "No\n \n\n* * *"}, {"input": "4\n ((()))\n ((((((\n ))))))\n ()()()", "output": "Yes\n \n\n* * *"}, {"input": "3\n (((\n )\n )", "output": "No"}] |
If a bracket sequence can be formed by concatenating all the N strings in some
order, print `Yes`; otherwise, print `No`.
* * * | s197013195 | Wrong Answer | p02686 | Input is given from Standard Input in the following format:
N
S_1
:
S_N | #!/usr/bin/env python3
import sys
YES = "Yes" # type: str
NO = "No" # type: str
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
def solve(N: int):
tokens = iterate_tokens()
left_all = 0
right_all = 0
for _ in range(N):
# print("all", left_all, right_all)
s = next(tokens)
left = 0
right = 0
for ss in s:
# print(ss)
# print(left, right)
if ss == ")":
if right > 0:
right -= 1
else:
left += 1
else:
right += 1
# print(left, right)
new_left_all_right = max(0, left_all - right) + left
new_right_all_right = max(0, right - left_all) + right_all
# print(new_left_all_right, new_right_all_right)
new_left_all_left = max(0, right_all - left) + right
new_right_all_left = max(0, left - right_all) + left_all
# print(new_left_all_left, new_right_all_left)
if (
new_left_all_right + new_right_all_right
> new_left_all_left + new_right_all_left
):
left_all = new_left_all_left
right_all = new_right_all_left
else:
left_all = new_left_all_right
right_all = new_right_all_right
if left_all == 0 and right_all == 0:
print(YES)
else:
print(NO)
return
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
solve(N)
if __name__ == "__main__":
main()
| Statement
A **bracket sequence** is a string that is one of the following:
1. An empty string;
2. The concatenation of `(`, A, and `)` in this order, for some bracket sequence A ;
3. The concatenation of A and B in this order, for some non-empty bracket sequences A and B /
Given are N strings S_i. Can a bracket sequence be formed by concatenating all
the N strings in some order? | [{"input": "2\n )\n (()", "output": "Yes\n \n\nConcatenating `(()` and `)` in this order forms a bracket sequence.\n\n* * *"}, {"input": "2\n )(\n ()", "output": "No\n \n\n* * *"}, {"input": "4\n ((()))\n ((((((\n ))))))\n ()()()", "output": "Yes\n \n\n* * *"}, {"input": "3\n (((\n )\n )", "output": "No"}] |
If a bracket sequence can be formed by concatenating all the N strings in some
order, print `Yes`; otherwise, print `No`.
* * * | s438911296 | Wrong Answer | p02686 | Input is given from Standard Input in the following format:
N
S_1
:
S_N | import bisect
import sys
from collections import defaultdict
input = sys.stdin.readline
class Node:
def __init__(self, value, index):
self.value = value
self.index = index
def __str__(self):
return "val : " + str(self.value) + " index : " + str(self.index)
# 0-indexed SegmentTree
class SegmentTree:
def __init__(self, N, default_list, default_value=-(10**10)):
self.N0 = pow(2, (N - 1).bit_length())
self.nodes = [
Node(default_value, i + 1 - self.N0) for i in range(2 * self.N0 - 1)
]
for i in reversed(range(2 * self.N0 - 1)):
ind = i + 1 - self.N0
if ind >= N:
self.nodes[i].value = default_value
elif N > ind >= 0:
self.nodes[i].value = default_list[ind]
else:
self.nodes[i] = self.process(
self.nodes[i * 2 + 1], self.nodes[i * 2 + 2]
)
def __str__(self):
return (
"["
+ ", ".join(
map(str, [self.nodes[i + self.N0 - 1].value for i in range(self.N0)])
)
+ "]"
)
def query(self, L, R): # [L,R)の値
retnode = Node(-(10**10), -(10**10))
L += self.N0
R += self.N0
while L < R:
if R & 1:
R -= 1
retnode = self.process(retnode, self.nodes[R - 1])
if L & 1:
retnode = self.process(retnode, self.nodes[L - 1])
L += 1
L >>= 1
R >>= 1
return retnode
def process(self, node_x, node_y): # x,yが子の時,親に返る値
if node_x.value > node_y.value:
return node_x
else:
return node_y
def update(self, i, x):
i += self.N0 - 1
self.nodes[i] = Node(x, i + 1 - self.N0)
while i:
i = (i - 1) // 2
self.nodes[i] = self.process(self.nodes[i * 2 + 1], self.nodes[i * 2 + 2])
N = int(input())
ss = [input().replace("\n", "") for _ in range(N)]
def calc(S):
tmp = 0
MIN = 0
for s in S:
if s == "(":
tmp += 1
else:
tmp -= 1
MIN = min(tmp, MIN)
return -MIN, tmp
cnts = []
for s in ss:
down, up = calc(s)
cnts.append((down, up, s))
cnts.sort()
# print(cnts)
ups = []
downs = []
rights = defaultdict(int)
for i, (d, u, s) in enumerate(cnts):
downs.append(d)
ups.append(u)
ST = SegmentTree(N, ups)
tmp = 0
for _ in range(N):
R = bisect.bisect_right(downs, tmp)
# print(tmp, R)
node = ST.query(0, R)
ST.update(node.index, -(10**10))
tmp += node.value
if tmp < 0:
print("No")
sys.exit()
if tmp == 0:
print("Yes")
else:
print("No")
| Statement
A **bracket sequence** is a string that is one of the following:
1. An empty string;
2. The concatenation of `(`, A, and `)` in this order, for some bracket sequence A ;
3. The concatenation of A and B in this order, for some non-empty bracket sequences A and B /
Given are N strings S_i. Can a bracket sequence be formed by concatenating all
the N strings in some order? | [{"input": "2\n )\n (()", "output": "Yes\n \n\nConcatenating `(()` and `)` in this order forms a bracket sequence.\n\n* * *"}, {"input": "2\n )(\n ()", "output": "No\n \n\n* * *"}, {"input": "4\n ((()))\n ((((((\n ))))))\n ()()()", "output": "Yes\n \n\n* * *"}, {"input": "3\n (((\n )\n )", "output": "No"}] |
If a bracket sequence can be formed by concatenating all the N strings in some
order, print `Yes`; otherwise, print `No`.
* * * | s602722918 | Runtime Error | p02686 | Input is given from Standard Input in the following format:
N
S_1
:
S_N | from functools import reduce
from itertools import permutations
def f(s):
while True:
t = s.replace("()", "")
if t == s:
return s
s = t
N = int(input())
S = [input() for _ in range(N)]
l = 0
r = 0
for s in S:
t = s.count("(")
l += t
r += len(s) - t
if l != r:
print("No")
exit()
S = [s for s in map(f, S) if s != ""]
if len(S) == 0:
print("Yes")
exit()
lS = [s for s in S if s[0] == "("]
rS = [s for s in S if s[0] == ")"]
ld = {}
for s in lS:
ld.setdefault(s, 0)
ld[s] += 1
rd = {}
for s in rS:
rd.setdefault(s, 0)
rd[s] += 1
for k1 in ld:
for k2 in rd.keys():
if f(k1 + k2) != "":
continue
t = max(ld[k1], rd[k2])
ld[k1] -= t
rd[k2] -= t
if len(ld) == 0 and len(rd) == 0:
print("Yes")
exit()
SS = []
for k in ld:
for i in range(ld[k]):
SS.append(k)
for k in rd:
for i in range(rd[k]):
SS.append(k)
for ss in permutations(SS, len(SS)):
t = reduce(lambda x, y: x + y, ss)
if f(t) == "":
print("Yes")
exit()
print("No")
| Statement
A **bracket sequence** is a string that is one of the following:
1. An empty string;
2. The concatenation of `(`, A, and `)` in this order, for some bracket sequence A ;
3. The concatenation of A and B in this order, for some non-empty bracket sequences A and B /
Given are N strings S_i. Can a bracket sequence be formed by concatenating all
the N strings in some order? | [{"input": "2\n )\n (()", "output": "Yes\n \n\nConcatenating `(()` and `)` in this order forms a bracket sequence.\n\n* * *"}, {"input": "2\n )(\n ()", "output": "No\n \n\n* * *"}, {"input": "4\n ((()))\n ((((((\n ))))))\n ()()()", "output": "Yes\n \n\n* * *"}, {"input": "3\n (((\n )\n )", "output": "No"}] |
If there is no permutation that satisfies the conditions, print `NO`.
If there is such a permutation, print `YES` in the first line. Then, print
(P_0,\ P_1,\ ...\ P_{2^N-1}) in the second line, with spaces in between. If
there are multiple solutions, any of them is accepted.
* * * | s019953816 | Runtime Error | p03097 | Input is given from Standard Input in the following format:
N A B | mod = 1000000007
N = int(input())
C = []
for i in range(N):
c = int(input())
if i == 0 or C[-1] != c:
C.append(c)
cases = [1] * (len(C) + 1)
indexes = dict()
for i in range(1, 1 + len(C)):
c = C[i - 1]
if c not in indexes:
cases[i] = cases[i - 1]
else:
cases[i] = (cases[i - 1] + cases[indexes[c]]) % mod
indexes[c] = i
print(cases[len(C)])
| Statement
You are given integers N,\ A and B. Determine if there exists a permutation
(P_0,\ P_1,\ ...\ P_{2^N-1}) of (0,\ 1,\ ...\ 2^N-1) that satisfies all of the
following conditions, and create one such permutation if it exists.
* P_0=A
* P_{2^N-1}=B
* For all 0 \leq i < 2^N-1, the binary representations of P_i and P_{i+1} differ by exactly one bit. | [{"input": "2 1 3", "output": "YES\n 1 0 2 3\n \n\nThe binary representation of P=(1,0,2,3) is (01,00,10,11), where any two\nadjacent elements differ by exactly one bit.\n\n* * *"}, {"input": "3 2 1", "output": "NO"}] |
If there is no permutation that satisfies the conditions, print `NO`.
If there is such a permutation, print `YES` in the first line. Then, print
(P_0,\ P_1,\ ...\ P_{2^N-1}) in the second line, with spaces in between. If
there are multiple solutions, any of them is accepted.
* * * | s040779455 | Wrong Answer | p03097 | Input is given from Standard Input in the following format:
N A B | n, a, b = map(int, input().split())
if bin(a).count("1") % 2 == bin(b).count("1") % 2:
print("NO")
exit()
# グレイコードのリスト生成
gray = [0] * (1 << n)
for i in range(1 << n):
gray[i] = i ^ (i >> 1)
# グレイコードリストでのa, bの位置探索
ind_a, ind_b = -1, -1
for i in range(1 << n):
if gray[i] == a:
ind_a = i
if gray[i] == b:
ind_b = i
if ind_a > ind_b:
ind_a, ind_b = ind_b, ind_a
# a->b までの距離と b->a までの距離でより長い方をベースに使う
res1 = [gray[i] for i in range(ind_a, ind_b + 1)]
res2 = [gray[i] for i in range(ind_b, len(gray))] + [
gray[i] for i in range(0, ind_a + 1)
]
if len(res1) > len(res2):
res = res1[0:]
nokori = res2[1:-1]
else:
res = res2[0:]
nokori = res1[1:-1]
# 余ったほうをベースに加えるための整理(cnt1で分類)
nokori_memo = {}
for i in range(0, len(nokori), 2):
tmp = nokori[i : i + 2]
cnt0 = bin(tmp[0]).count("1")
cnt1 = bin(tmp[1]).count("1")
if (cnt0, cnt1) not in nokori_memo:
nokori_memo[cnt0, cnt1] = []
nokori_memo[cnt0, cnt1].append(tmp)
# ベースとあまりをマージ
ans = []
while res:
num = res.pop()
ans.append(num)
num = bin(num).count("1")
while (num + 1, num) in nokori_memo and nokori_memo[(num + 1, num)]:
tmp = nokori_memo[(num + 1, num)].pop()
ans.append(tmp[0])
ans.append(tmp[1])
while (num - 1, num) in nokori_memo and nokori_memo[(num - 1, num)]:
tmp = nokori_memo[(num - 1, num)].pop()
ans.append(tmp[0])
ans.append(tmp[1])
while (num, num + 1) in nokori_memo and nokori_memo[(num, num + 1)]:
tmp = nokori_memo[(num, num + 1)].pop()
ans.append(tmp[1])
ans.append(tmp[0])
while (num, num - 1) in nokori_memo and nokori_memo[(num, num - 1)]:
tmp = nokori_memo[(num, num - 1)].pop()
ans.append(tmp[1])
ans.append(tmp[0])
print("YES")
if ans[0] == a:
print(*ans)
else:
print(*ans[::-1])
| Statement
You are given integers N,\ A and B. Determine if there exists a permutation
(P_0,\ P_1,\ ...\ P_{2^N-1}) of (0,\ 1,\ ...\ 2^N-1) that satisfies all of the
following conditions, and create one such permutation if it exists.
* P_0=A
* P_{2^N-1}=B
* For all 0 \leq i < 2^N-1, the binary representations of P_i and P_{i+1} differ by exactly one bit. | [{"input": "2 1 3", "output": "YES\n 1 0 2 3\n \n\nThe binary representation of P=(1,0,2,3) is (01,00,10,11), where any two\nadjacent elements differ by exactly one bit.\n\n* * *"}, {"input": "3 2 1", "output": "NO"}] |
If there is no permutation that satisfies the conditions, print `NO`.
If there is such a permutation, print `YES` in the first line. Then, print
(P_0,\ P_1,\ ...\ P_{2^N-1}) in the second line, with spaces in between. If
there are multiple solutions, any of them is accepted.
* * * | s437159557 | Wrong Answer | p03097 | Input is given from Standard Input in the following format:
N A B | N, A, B = [int(i) for i in input().split()]
def checkio(n, m):
return format(n ^ m, "b").count("1")
if 1 == checkio(A, B):
print("Yes")
else:
print("No")
| Statement
You are given integers N,\ A and B. Determine if there exists a permutation
(P_0,\ P_1,\ ...\ P_{2^N-1}) of (0,\ 1,\ ...\ 2^N-1) that satisfies all of the
following conditions, and create one such permutation if it exists.
* P_0=A
* P_{2^N-1}=B
* For all 0 \leq i < 2^N-1, the binary representations of P_i and P_{i+1} differ by exactly one bit. | [{"input": "2 1 3", "output": "YES\n 1 0 2 3\n \n\nThe binary representation of P=(1,0,2,3) is (01,00,10,11), where any two\nadjacent elements differ by exactly one bit.\n\n* * *"}, {"input": "3 2 1", "output": "NO"}] |
If there is no permutation that satisfies the conditions, print `NO`.
If there is such a permutation, print `YES` in the first line. Then, print
(P_0,\ P_1,\ ...\ P_{2^N-1}) in the second line, with spaces in between. If
there are multiple solutions, any of them is accepted.
* * * | s018223701 | Wrong Answer | p03097 | Input is given from Standard Input in the following format:
N A B | print("YES")
print(1, 0, 2, 3)
| Statement
You are given integers N,\ A and B. Determine if there exists a permutation
(P_0,\ P_1,\ ...\ P_{2^N-1}) of (0,\ 1,\ ...\ 2^N-1) that satisfies all of the
following conditions, and create one such permutation if it exists.
* P_0=A
* P_{2^N-1}=B
* For all 0 \leq i < 2^N-1, the binary representations of P_i and P_{i+1} differ by exactly one bit. | [{"input": "2 1 3", "output": "YES\n 1 0 2 3\n \n\nThe binary representation of P=(1,0,2,3) is (01,00,10,11), where any two\nadjacent elements differ by exactly one bit.\n\n* * *"}, {"input": "3 2 1", "output": "NO"}] |
If there is no permutation that satisfies the conditions, print `NO`.
If there is such a permutation, print `YES` in the first line. Then, print
(P_0,\ P_1,\ ...\ P_{2^N-1}) in the second line, with spaces in between. If
there are multiple solutions, any of them is accepted.
* * * | s963942134 | Wrong Answer | p03097 | Input is given from Standard Input in the following format:
N A B | n, a, b = map(int, input().split())
if (a - b) % 2 == 0:
print("NO")
print("YES")
| Statement
You are given integers N,\ A and B. Determine if there exists a permutation
(P_0,\ P_1,\ ...\ P_{2^N-1}) of (0,\ 1,\ ...\ 2^N-1) that satisfies all of the
following conditions, and create one such permutation if it exists.
* P_0=A
* P_{2^N-1}=B
* For all 0 \leq i < 2^N-1, the binary representations of P_i and P_{i+1} differ by exactly one bit. | [{"input": "2 1 3", "output": "YES\n 1 0 2 3\n \n\nThe binary representation of P=(1,0,2,3) is (01,00,10,11), where any two\nadjacent elements differ by exactly one bit.\n\n* * *"}, {"input": "3 2 1", "output": "NO"}] |
If there is no permutation that satisfies the conditions, print `NO`.
If there is such a permutation, print `YES` in the first line. Then, print
(P_0,\ P_1,\ ...\ P_{2^N-1}) in the second line, with spaces in between. If
there are multiple solutions, any of them is accepted.
* * * | s263640351 | Wrong Answer | p03097 | Input is given from Standard Input in the following format:
N A B | N, A, B = [int(_) for _ in input().split()]
print("NO")
| Statement
You are given integers N,\ A and B. Determine if there exists a permutation
(P_0,\ P_1,\ ...\ P_{2^N-1}) of (0,\ 1,\ ...\ 2^N-1) that satisfies all of the
following conditions, and create one such permutation if it exists.
* P_0=A
* P_{2^N-1}=B
* For all 0 \leq i < 2^N-1, the binary representations of P_i and P_{i+1} differ by exactly one bit. | [{"input": "2 1 3", "output": "YES\n 1 0 2 3\n \n\nThe binary representation of P=(1,0,2,3) is (01,00,10,11), where any two\nadjacent elements differ by exactly one bit.\n\n* * *"}, {"input": "3 2 1", "output": "NO"}] |
If there is no permutation that satisfies the conditions, print `NO`.
If there is such a permutation, print `YES` in the first line. Then, print
(P_0,\ P_1,\ ...\ P_{2^N-1}) in the second line, with spaces in between. If
there are multiple solutions, any of them is accepted.
* * * | s265647468 | Runtime Error | p03097 | Input is given from Standard Input in the following format:
N A B | _ = input()
_ = input()
print("YES")
print("1 0 2 3")
| Statement
You are given integers N,\ A and B. Determine if there exists a permutation
(P_0,\ P_1,\ ...\ P_{2^N-1}) of (0,\ 1,\ ...\ 2^N-1) that satisfies all of the
following conditions, and create one such permutation if it exists.
* P_0=A
* P_{2^N-1}=B
* For all 0 \leq i < 2^N-1, the binary representations of P_i and P_{i+1} differ by exactly one bit. | [{"input": "2 1 3", "output": "YES\n 1 0 2 3\n \n\nThe binary representation of P=(1,0,2,3) is (01,00,10,11), where any two\nadjacent elements differ by exactly one bit.\n\n* * *"}, {"input": "3 2 1", "output": "NO"}] |
If there is no permutation that satisfies the conditions, print `NO`.
If there is such a permutation, print `YES` in the first line. Then, print
(P_0,\ P_1,\ ...\ P_{2^N-1}) in the second line, with spaces in between. If
there are multiple solutions, any of them is accepted.
* * * | s516514500 | Accepted | p03097 | Input is given from Standard Input in the following format:
N A B | #!/usr/bin/env python
# -*- coding: utf-8 -*-
def trace(bits, idx, history):
if idx == len(bits):
history.append(bits[:])
elif idx == len(bits) - 1:
history.append(bits[:])
bits[idx] = 1 - bits[idx]
history.append(bits[:])
else:
trace(bits, idx + 1, history)
bits[idx] = 1 - bits[idx]
trace(bits, idx + 1, history)
def down(bits, idx, count, history):
if idx == len(bits):
history.append(bits[:])
elif idx == len(bits) - 1:
history.append(bits[:])
bits[idx] = 1 - bits[idx]
history.append(bits[:])
elif count > 0:
trace(bits, idx + 2, history)
bits[idx] = 1 - bits[idx]
trace(bits, idx + 2, history)
bits[idx + 1] = 1 - bits[idx + 1]
trace(bits, idx + 2, history)
bits[idx] = 1 - bits[idx]
down(bits, idx + 2, count - 2, history)
else:
trace(bits, idx + 2, history)
bits[idx + 1] = 1 - bits[idx + 1]
trace(bits, idx + 2, history)
bits[idx] = 1 - bits[idx]
trace(bits, idx + 2, history)
bits[idx + 1] = 1 - bits[idx + 1]
down(bits, idx + 2, count - 2, history)
def main():
n, a, b = map(int, input().split())
x = a ^ b
count = 0
remain = 0
mapper = [-1] * n
for i in range(n):
if (x >> i) & 0x1 != 0:
mapper[count] = i
count += 1
else:
remain += 1
mapper[-remain] = i
if count % 2 == 0:
print("NO", flush=True)
return
bits = [0] * n
history = []
trace(bits, 1, history)
bits[0] = 1
down(bits, 1, count - 1, history)
for i in range(len(history)):
v = history[i][:]
for j, m in enumerate(mapper):
history[i][n - m - 1] = v[j]
history = [str(a ^ int("".join(str(v) for v in h), 2)) for h in history]
print("YES", flush=True)
print(" ".join(history), flush=True)
if __name__ == "__main__":
main()
| Statement
You are given integers N,\ A and B. Determine if there exists a permutation
(P_0,\ P_1,\ ...\ P_{2^N-1}) of (0,\ 1,\ ...\ 2^N-1) that satisfies all of the
following conditions, and create one such permutation if it exists.
* P_0=A
* P_{2^N-1}=B
* For all 0 \leq i < 2^N-1, the binary representations of P_i and P_{i+1} differ by exactly one bit. | [{"input": "2 1 3", "output": "YES\n 1 0 2 3\n \n\nThe binary representation of P=(1,0,2,3) is (01,00,10,11), where any two\nadjacent elements differ by exactly one bit.\n\n* * *"}, {"input": "3 2 1", "output": "NO"}] |
If there is no permutation that satisfies the conditions, print `NO`.
If there is such a permutation, print `YES` in the first line. Then, print
(P_0,\ P_1,\ ...\ P_{2^N-1}) in the second line, with spaces in between. If
there are multiple solutions, any of them is accepted.
* * * | s299493645 | Runtime Error | p03097 | Input is given from Standard Input in the following format:
N A B | import sys
import time
import random
sys.setrecursionlimit(100000000)
N, A, B = map(int, input().split())
sTime = time.time()
P = [-1] * N
Q = [0] * (2**N)
X = [0] * (2**N)
X[0] = 1
X[1] = 1
Y = [1 << i for i in range(N)]
Z = [0]
def calc(k, l, M):
aa = 0
bb = 0
done = [0] * N
for i in range(M):
# print("M, i, k,aa,Y=", M, i, k, aa, Y)
while k & Y[aa] == 0:
aa += 1
while l & Y[bb] == 0:
bb += 1
P[aa] = bb
done[bb] = 1
aa += 1
bb += 1
j = 0
# print(P)
# print(done)
for i in range(N):
if P[i] >= 0:
continue
while done[j] == 1:
j += 1
P[i] = j
j += 1
def change(n):
ret = 0
for i in range(N):
if n & (1 << i):
ret += 1 << P[i]
return ret
def dc(n):
return sum(map(int, list(bin(n)[2:])))
def dfs(n, c):
if time.time() - sTime > 1.75:
return -1
for i in range(N):
m = n ^ Y[i]
# print(n, i, m, c)
if c == 2**N - 2 and m == 1:
X[m] = 1
Z.append(m)
return 1
if X[m] == 0 and m != 1:
X[m] = 1
Z.append(m)
# print(Z)
r = dfs(m, c + 1)
if r:
return r
if r < 0:
return -1
X[m] = 0
Z.pop()
return 0
if (dc(A) + dc(B)) % 2 == 0:
print("NO")
else:
r = dfs(0, 0)
for i in range(N):
if Z[i] == A:
Z = Z[i:] + Z[:i]
# print(X, Y, Z)
if r < 0:
print("NO")
else:
# print("A", Z[:10], Z[-10:])
mi = 99999
while mi > 0:
# for i in range(3, 2**N-1, 2):
i = random.randrange(max(2**N - 1001, 1), 2**N - 1, 2)
if Z[i - 1] ^ Z[-1] in Y:
Z = Z[:i] + Z[i:][::-1]
mi = abs(dc(Z[-1]) - dc(B))
# print("A", Z[:10], Z[-10:])
# print("(Z[-1], B, dc(B))", Z[-1], B, dc(B))
calc(Z[-1], B, dc(B))
# print("P=", P)
for i in range(N):
s = 1 << P[i]
t = 1 << i
for j in range(2**N):
if j & t:
Q[j] += s
Z = [Q[z] for z in Z]
# print(Z[:10], Z[-10:])
print("YES")
print(*Z)
| Statement
You are given integers N,\ A and B. Determine if there exists a permutation
(P_0,\ P_1,\ ...\ P_{2^N-1}) of (0,\ 1,\ ...\ 2^N-1) that satisfies all of the
following conditions, and create one such permutation if it exists.
* P_0=A
* P_{2^N-1}=B
* For all 0 \leq i < 2^N-1, the binary representations of P_i and P_{i+1} differ by exactly one bit. | [{"input": "2 1 3", "output": "YES\n 1 0 2 3\n \n\nThe binary representation of P=(1,0,2,3) is (01,00,10,11), where any two\nadjacent elements differ by exactly one bit.\n\n* * *"}, {"input": "3 2 1", "output": "NO"}] |
Print the answer.
* * * | s873039871 | Wrong Answer | p03582 | Input is given from Standard Input in the following format:
X Y Z | from itertools import permutations, count, chain
from collections import deque
def helper(s):
for i in range(len(s)):
yield s[i:] + s[:i]
def naive(a, b, c):
return max(min(helper(s)) for s in permutations("a" * a + "b" * b + "c" * c))
def solve(a, b, c):
def helper(a, b, c):
cnt = (a, b, c).count(0)
if cnt == 3:
return []
elif cnt == 2:
n, i = max((x, i) for i, x in enumerate((a, b, c)))
return [i] * n
elif cnt == 1:
(l, nl), (u, nu) = ((i, x) for i, x in enumerate((a, b, c)) if x != 0)
n = nl // nu
return tuple(reversed(([u] + [l] * n) * nu + [l] * (nl - n * nu)))
n0 = c % a
n1 = a - n0
m0 = b % n1
m1 = n1 - m0
R = helper(m1, m0, n0)
nc = c // a
nb = b // n1
s = (
[0] + [2] * nc + [1] * nb,
[0] + [2] * nc + [1] * (nb + 1),
[0] + [2] * (nc + 1),
)
return tuple(chain.from_iterable(s[r] for r in R))
s = ("a", "b", "c")
return "".join(s[i] for i in helper(a, b, c))
print(solve(*map(int, input().split())))
| Statement
For a string S, let f(S) be the lexicographically smallest cyclic shift of S.
For example, if S = `babca`, f(S) = `ababc` because this is the smallest among
all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T
that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there
are multiple such strings, you want to choose one that maximizes f(T)
lexicographically.
Compute the lexicographically largest possible value of f(T). | [{"input": "2 2 0", "output": "abab\n \n\nT must consist of two `a`s and two `b`s.\n\n * If T = `aabb`, f(T) = `aabb`.\n * If T = `abab`, f(T) = `abab`.\n * If T = `abba`, f(T) = `aabb`.\n * If T = `baab`, f(T) = `aabb`.\n * If T = `baba`, f(T) = `abab`.\n * If T = `bbaa`, f(T) = `aabb`.\n\nThus, the largest possible f(T) is `abab`.\n\n* * *"}, {"input": "1 1 1", "output": "acb"}] |
Print K lines. The i-th line should contain the i-th value stated in the
problem statement.
* * * | s761776384 | Accepted | p03078 | Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z | X, Y, Z, K = map(int, input().split())
x_list = list(map(int, input().split()))
y_list = list(map(int, input().split()))
z_list = list(map(int, input().split()))
x_list = sorted(x_list, reverse=True)
y_list = sorted(y_list, reverse=True)
z_list = sorted(z_list, reverse=True)
# 次にとるindexの管理
next_dict = {}
def sumxyz(tup):
return x_list[tup[0]] + y_list[tup[1]] + z_list[tup[2]]
def argmax(l):
mxi = -1
mx = -1
for i, v in enumerate(l):
if v >= mx:
mx = v
mxi = i
return mxi
def add_next(tup):
def add_not_exist(ntup):
sm = sumxyz(ntup)
if ntup not in next_dict:
next_dict[ntup] = sm
if tup[0] < len(x_list) - 1:
ntup = (tup[0] + 1, tup[1], tup[2])
add_not_exist(ntup)
if tup[1] < len(y_list) - 1:
ntup = (tup[0], tup[1] + 1, tup[2])
add_not_exist(ntup)
if tup[2] < len(z_list) - 1:
ntup = (tup[0], tup[1], tup[2] + 1)
add_not_exist(ntup)
for i in range(K):
if i == 0:
print(sumxyz((0, 0, 0)))
add_next((0, 0, 0))
else:
v = next_dict.values()
k = list(next_dict.keys())
max_idx = argmax(v)
print(next_dict[k[max_idx]])
next_dict[k[max_idx]] = -1
add_next(k[max_idx])
| Statement
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y
and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles,
respectively. Each cake has an integer value called _deliciousness_ , as
follows:
* The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
* The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
* The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the
candles, to celebrate ABC 123.
There are X \times Y \times Z such ways to choose three cakes.
We will arrange these X \times Y \times Z ways in descending order of the sum
of the deliciousness of the cakes.
Print the sums of the deliciousness of the cakes for the first, second, ...,
K-th ways in this list. | [{"input": "2 2 2 8\n 4 6\n 1 5\n 3 8", "output": "19\n 17\n 15\n 14\n 13\n 12\n 10\n 8\n \n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below\nin descending order of the sum of the deliciousness of the cakes:\n\n * (A_2, B_2, C_2): 6 + 5 + 8 = 19\n * (A_1, B_2, C_2): 4 + 5 + 8 = 17\n * (A_2, B_1, C_2): 6 + 1 + 8 = 15\n * (A_2, B_2, C_1): 6 + 5 + 3 = 14\n * (A_1, B_1, C_2): 4 + 1 + 8 = 13\n * (A_1, B_2, C_1): 4 + 5 + 3 = 12\n * (A_2, B_1, C_1): 6 + 1 + 3 = 10\n * (A_1, B_1, C_1): 4 + 1 + 3 = 8\n\n* * *"}, {"input": "3 3 3 5\n 1 10 100\n 2 20 200\n 1 10 100", "output": "400\n 310\n 310\n 301\n 301\n \n\nThere may be multiple combinations of cakes with the same sum of the\ndeliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and\nthe sum of A_3, B_3, C_1 are both 301. However, they are different ways of\nchoosing cakes, so 301 occurs twice in the output.\n\n* * *"}, {"input": "10 10 10 20\n 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736", "output": "23379871545\n 22444657051\n 22302177772\n 22095691512\n 21667941469\n 21366963278\n 21287912315\n 21279176669\n 21160477018\n 21085311041\n 21059876163\n 21017997739\n 20703329561\n 20702387965\n 20590247696\n 20383761436\n 20343962175\n 20254073196\n 20210218542\n 20150096547\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print K lines. The i-th line should contain the i-th value stated in the
problem statement.
* * * | s839051782 | Wrong Answer | p03078 | Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z | x, y, z, k = map(int, input().split())
a = sorted(map(int, input().split()), reverse=True)
b = sorted(map(int, input().split()), reverse=True)
c = sorted(map(int, input().split()), reverse=True)
p = q = r = 0
listlist = [[p, q, r]]
numlist = [a[p] + b[q] + c[r]]
listlistdone = []
for yy in range(k):
maxtemp = max(numlist)
print(maxtemp)
p, q, r = (
listlist[numlist.index(maxtemp)][0],
listlist[numlist.index(maxtemp)][1],
listlist[numlist.index(maxtemp)][2],
)
listlistdone.append(listlist[numlist.index(maxtemp)])
del listlist[numlist.index(maxtemp)]
numlist.remove(maxtemp)
temp = [p + 1, q, r]
if p <= x - 2 and (temp not in listlistdone):
appendflag = True
for xx in listlist:
if (
(temp[0] == xx[0] and temp[1] == xx[1])
or (temp[0] == xx[0] and temp[2] == xx[2])
or (temp[1] == xx[1] and temp[2] == xx[2])
):
appendflag = False
if appendflag == True:
listlist.append(temp)
numlist.append(a[p + 1] + b[q] + c[r])
temp = [p, q + 1, r]
if q <= y - 2 and (temp not in listlistdone):
appendflag = True
for xx in listlist:
if (
(temp[0] == xx[0] and temp[1] == xx[1])
or (temp[0] == xx[0] and temp[2] == xx[2])
or (temp[1] == xx[1] and temp[2] == xx[2])
):
appendflag = False
if appendflag == True:
listlist.append(temp)
numlist.append(a[p] + b[q + 1] + c[r])
temp = [p, q, r + 1]
if r <= z - 2 and (temp not in listlistdone):
appendflag = True
for xx in listlist:
if (
(temp[0] == xx[0] and temp[1] == xx[1])
or (temp[0] == xx[0] and temp[2] == xx[2])
or (temp[1] == xx[1] and temp[2] == xx[2])
):
appendflag = False
if appendflag == True:
listlist.append(temp)
numlist.append(a[p] + b[q] + c[r + 1])
| Statement
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y
and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles,
respectively. Each cake has an integer value called _deliciousness_ , as
follows:
* The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
* The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
* The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the
candles, to celebrate ABC 123.
There are X \times Y \times Z such ways to choose three cakes.
We will arrange these X \times Y \times Z ways in descending order of the sum
of the deliciousness of the cakes.
Print the sums of the deliciousness of the cakes for the first, second, ...,
K-th ways in this list. | [{"input": "2 2 2 8\n 4 6\n 1 5\n 3 8", "output": "19\n 17\n 15\n 14\n 13\n 12\n 10\n 8\n \n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below\nin descending order of the sum of the deliciousness of the cakes:\n\n * (A_2, B_2, C_2): 6 + 5 + 8 = 19\n * (A_1, B_2, C_2): 4 + 5 + 8 = 17\n * (A_2, B_1, C_2): 6 + 1 + 8 = 15\n * (A_2, B_2, C_1): 6 + 5 + 3 = 14\n * (A_1, B_1, C_2): 4 + 1 + 8 = 13\n * (A_1, B_2, C_1): 4 + 5 + 3 = 12\n * (A_2, B_1, C_1): 6 + 1 + 3 = 10\n * (A_1, B_1, C_1): 4 + 1 + 3 = 8\n\n* * *"}, {"input": "3 3 3 5\n 1 10 100\n 2 20 200\n 1 10 100", "output": "400\n 310\n 310\n 301\n 301\n \n\nThere may be multiple combinations of cakes with the same sum of the\ndeliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and\nthe sum of A_3, B_3, C_1 are both 301. However, they are different ways of\nchoosing cakes, so 301 occurs twice in the output.\n\n* * *"}, {"input": "10 10 10 20\n 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736", "output": "23379871545\n 22444657051\n 22302177772\n 22095691512\n 21667941469\n 21366963278\n 21287912315\n 21279176669\n 21160477018\n 21085311041\n 21059876163\n 21017997739\n 20703329561\n 20702387965\n 20590247696\n 20383761436\n 20343962175\n 20254073196\n 20210218542\n 20150096547\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print K lines. The i-th line should contain the i-th value stated in the
problem statement.
* * * | s911130487 | Wrong Answer | p03078 | Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z | class pqueue:
def __init__(self):
self.queue = {1: [], 2: []}
def push(self, x):
if self.queue[1] == []:
self.queue[1].append(x)
else:
if x[0] > self.queue[1][0][0]:
self.queue[2].append(self.queue[1].pop(0))
self.queue[1].append(x)
else:
self.queue[2].append(x)
def pop(self):
if self.queue[1] == []:
return None
else:
if self.queue[2] != []:
m = max(self.queue[2], key=lambda x: x[0])
self.queue[1].append(m)
self.queue[2].remove(m)
return self.queue[1].pop(0)
else:
return self.queue[1].pop(0)
P = pqueue()
x, y, z, k = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)
P.push([a[0] + b[0] + c[0], 0, 0, 0])
for cnt in range(k):
p = P.pop()
if p[1] + 1 < x:
A = [a[p[1] + 1] + b[p[2]] + c[p[3]], p[1] + 1, p[2], p[3]]
if not A in P.queue[1] and not A in P.queue[2]:
P.push(A)
if p[2] + 1 < y:
B = [a[p[1]] + b[p[2] + 1] + c[p[3]], p[1], p[2] + 1, p[3]]
if not B in P.queue[1] and not B in P.queue[2]:
P.push(B)
if p[3] + 1 < z:
C = [a[p[1]] + b[p[2]] + c[p[3] + 1], p[1], p[2], p[3] + 1]
if not C in P.queue[1] and not C in P.queue[2]:
P.push(C)
print(p[0])
| Statement
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y
and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles,
respectively. Each cake has an integer value called _deliciousness_ , as
follows:
* The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
* The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
* The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the
candles, to celebrate ABC 123.
There are X \times Y \times Z such ways to choose three cakes.
We will arrange these X \times Y \times Z ways in descending order of the sum
of the deliciousness of the cakes.
Print the sums of the deliciousness of the cakes for the first, second, ...,
K-th ways in this list. | [{"input": "2 2 2 8\n 4 6\n 1 5\n 3 8", "output": "19\n 17\n 15\n 14\n 13\n 12\n 10\n 8\n \n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below\nin descending order of the sum of the deliciousness of the cakes:\n\n * (A_2, B_2, C_2): 6 + 5 + 8 = 19\n * (A_1, B_2, C_2): 4 + 5 + 8 = 17\n * (A_2, B_1, C_2): 6 + 1 + 8 = 15\n * (A_2, B_2, C_1): 6 + 5 + 3 = 14\n * (A_1, B_1, C_2): 4 + 1 + 8 = 13\n * (A_1, B_2, C_1): 4 + 5 + 3 = 12\n * (A_2, B_1, C_1): 6 + 1 + 3 = 10\n * (A_1, B_1, C_1): 4 + 1 + 3 = 8\n\n* * *"}, {"input": "3 3 3 5\n 1 10 100\n 2 20 200\n 1 10 100", "output": "400\n 310\n 310\n 301\n 301\n \n\nThere may be multiple combinations of cakes with the same sum of the\ndeliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and\nthe sum of A_3, B_3, C_1 are both 301. However, they are different ways of\nchoosing cakes, so 301 occurs twice in the output.\n\n* * *"}, {"input": "10 10 10 20\n 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736", "output": "23379871545\n 22444657051\n 22302177772\n 22095691512\n 21667941469\n 21366963278\n 21287912315\n 21279176669\n 21160477018\n 21085311041\n 21059876163\n 21017997739\n 20703329561\n 20702387965\n 20590247696\n 20383761436\n 20343962175\n 20254073196\n 20210218542\n 20150096547\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print K lines. The i-th line should contain the i-th value stated in the
problem statement.
* * * | s095292988 | Accepted | p03078 | Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z | from heapq import heappush, heappop
N = [int(x) for x in input().split()]
a = [sorted([int(x) for x in input().split()], reverse=True) for _ in range(3)]
Q = [(-(a[0][0] + a[1][0] + a[2][0]), [0, 0, 0])]
L = [[0, 0, 0]]
def f(v):
global a, L, Q
if not v in L:
t = 0
for i in range(3):
t -= a[i][v[i]]
heappush(Q, (t, v))
L.append(v)
for _ in range(N[3]):
p, v = heappop(Q)
print(-p)
for i in range(3):
if v[i] + 1 < N[i]:
f([x if j != i else x + 1 for j, x in enumerate(v)])
| Statement
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y
and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles,
respectively. Each cake has an integer value called _deliciousness_ , as
follows:
* The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
* The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
* The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the
candles, to celebrate ABC 123.
There are X \times Y \times Z such ways to choose three cakes.
We will arrange these X \times Y \times Z ways in descending order of the sum
of the deliciousness of the cakes.
Print the sums of the deliciousness of the cakes for the first, second, ...,
K-th ways in this list. | [{"input": "2 2 2 8\n 4 6\n 1 5\n 3 8", "output": "19\n 17\n 15\n 14\n 13\n 12\n 10\n 8\n \n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below\nin descending order of the sum of the deliciousness of the cakes:\n\n * (A_2, B_2, C_2): 6 + 5 + 8 = 19\n * (A_1, B_2, C_2): 4 + 5 + 8 = 17\n * (A_2, B_1, C_2): 6 + 1 + 8 = 15\n * (A_2, B_2, C_1): 6 + 5 + 3 = 14\n * (A_1, B_1, C_2): 4 + 1 + 8 = 13\n * (A_1, B_2, C_1): 4 + 5 + 3 = 12\n * (A_2, B_1, C_1): 6 + 1 + 3 = 10\n * (A_1, B_1, C_1): 4 + 1 + 3 = 8\n\n* * *"}, {"input": "3 3 3 5\n 1 10 100\n 2 20 200\n 1 10 100", "output": "400\n 310\n 310\n 301\n 301\n \n\nThere may be multiple combinations of cakes with the same sum of the\ndeliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and\nthe sum of A_3, B_3, C_1 are both 301. However, they are different ways of\nchoosing cakes, so 301 occurs twice in the output.\n\n* * *"}, {"input": "10 10 10 20\n 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736", "output": "23379871545\n 22444657051\n 22302177772\n 22095691512\n 21667941469\n 21366963278\n 21287912315\n 21279176669\n 21160477018\n 21085311041\n 21059876163\n 21017997739\n 20703329561\n 20702387965\n 20590247696\n 20383761436\n 20343962175\n 20254073196\n 20210218542\n 20150096547\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print K lines. The i-th line should contain the i-th value stated in the
problem statement.
* * * | s353284203 | Wrong Answer | p03078 | Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z | x, y, z, k = map(int, input().split())
ax = [int(_) for _ in input().split()]
ay = [int(_) for _ in input().split()]
az = [int(_) for _ in input().split()]
ax.sort(reverse=True)
ay.sort(reverse=True)
az.sort(reverse=True)
INF = -(10**9)
ax.extend([INF] * k)
ay.extend([INF] * k)
az.extend([INF] * k)
l = [(ax[0] + ay[0] + az[0], 0, 0, 0)]
for i in range(k):
t = l.pop(0)
print(t[0])
if (ax[t[1] + 1] + ay[t[2]] + az[t[3]], t[1] + 1, t[2], t[3]) not in l:
l.append((ax[t[1] + 1] + ay[t[2]] + az[t[3]], t[1] + 1, t[2], t[3]))
if (ax[t[1]] + ay[t[2] + 1] + az[t[3]], t[1], t[2] + 1, t[3]) not in l:
l.append((ax[t[1]] + ay[t[2] + 1] + az[t[3]], t[1], t[2] + 1, t[3]))
if (ax[t[1]] + ay[t[2]] + az[t[3] + 1], t[1], t[2], t[3] + 1) not in l:
l.append((ax[t[1]] + ay[t[2]] + az[t[3] + 1], t[1], t[2], t[3] + 1))
l.sort(reverse=True)
| Statement
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y
and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles,
respectively. Each cake has an integer value called _deliciousness_ , as
follows:
* The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
* The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
* The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the
candles, to celebrate ABC 123.
There are X \times Y \times Z such ways to choose three cakes.
We will arrange these X \times Y \times Z ways in descending order of the sum
of the deliciousness of the cakes.
Print the sums of the deliciousness of the cakes for the first, second, ...,
K-th ways in this list. | [{"input": "2 2 2 8\n 4 6\n 1 5\n 3 8", "output": "19\n 17\n 15\n 14\n 13\n 12\n 10\n 8\n \n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below\nin descending order of the sum of the deliciousness of the cakes:\n\n * (A_2, B_2, C_2): 6 + 5 + 8 = 19\n * (A_1, B_2, C_2): 4 + 5 + 8 = 17\n * (A_2, B_1, C_2): 6 + 1 + 8 = 15\n * (A_2, B_2, C_1): 6 + 5 + 3 = 14\n * (A_1, B_1, C_2): 4 + 1 + 8 = 13\n * (A_1, B_2, C_1): 4 + 5 + 3 = 12\n * (A_2, B_1, C_1): 6 + 1 + 3 = 10\n * (A_1, B_1, C_1): 4 + 1 + 3 = 8\n\n* * *"}, {"input": "3 3 3 5\n 1 10 100\n 2 20 200\n 1 10 100", "output": "400\n 310\n 310\n 301\n 301\n \n\nThere may be multiple combinations of cakes with the same sum of the\ndeliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and\nthe sum of A_3, B_3, C_1 are both 301. However, they are different ways of\nchoosing cakes, so 301 occurs twice in the output.\n\n* * *"}, {"input": "10 10 10 20\n 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736", "output": "23379871545\n 22444657051\n 22302177772\n 22095691512\n 21667941469\n 21366963278\n 21287912315\n 21279176669\n 21160477018\n 21085311041\n 21059876163\n 21017997739\n 20703329561\n 20702387965\n 20590247696\n 20383761436\n 20343962175\n 20254073196\n 20210218542\n 20150096547\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print K lines. The i-th line should contain the i-th value stated in the
problem statement.
* * * | s806850123 | Wrong Answer | p03078 | Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z | x, y, z, k = map(int, input().split())
list_a = list(map(int, input().split()))
list_b = list(map(int, input().split()))
list_c = list(map(int, input().split()))
list_a.sort(reverse=True)
list_b.sort(reverse=True)
list_c.sort(reverse=True)
dict_p = {}
dict_p[(0, 0, 0)] = list_a[0] + list_b[0] + list_c[0]
now = 0
for i in range(0, k):
Max = max(dict_p.values())
print(Max)
for j in dict_p:
if dict_p[j] == Max:
now = j
dict_p.pop(now)
break
if now[0] + 1 < x:
dict_p[(now[0] + 1, now[1], now[2])] = (
list_a[now[0] + 1] + list_b[now[1]] + list_c[now[2]]
)
if now[1] + 1 < y:
dict_p[(now[0], now[1] + 1, now[2])] = (
list_a[now[0]] + list_b[now[1] + 1] + list_c[now[2]]
)
if now[2] + 1 < z:
dict_p[(now[0], now[1], now[2] + 1)] = (
list_a[now[0]] + list_b[now[1]] + list_c[now[2] + 1]
)
| Statement
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y
and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles,
respectively. Each cake has an integer value called _deliciousness_ , as
follows:
* The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
* The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
* The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the
candles, to celebrate ABC 123.
There are X \times Y \times Z such ways to choose three cakes.
We will arrange these X \times Y \times Z ways in descending order of the sum
of the deliciousness of the cakes.
Print the sums of the deliciousness of the cakes for the first, second, ...,
K-th ways in this list. | [{"input": "2 2 2 8\n 4 6\n 1 5\n 3 8", "output": "19\n 17\n 15\n 14\n 13\n 12\n 10\n 8\n \n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below\nin descending order of the sum of the deliciousness of the cakes:\n\n * (A_2, B_2, C_2): 6 + 5 + 8 = 19\n * (A_1, B_2, C_2): 4 + 5 + 8 = 17\n * (A_2, B_1, C_2): 6 + 1 + 8 = 15\n * (A_2, B_2, C_1): 6 + 5 + 3 = 14\n * (A_1, B_1, C_2): 4 + 1 + 8 = 13\n * (A_1, B_2, C_1): 4 + 5 + 3 = 12\n * (A_2, B_1, C_1): 6 + 1 + 3 = 10\n * (A_1, B_1, C_1): 4 + 1 + 3 = 8\n\n* * *"}, {"input": "3 3 3 5\n 1 10 100\n 2 20 200\n 1 10 100", "output": "400\n 310\n 310\n 301\n 301\n \n\nThere may be multiple combinations of cakes with the same sum of the\ndeliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and\nthe sum of A_3, B_3, C_1 are both 301. However, they are different ways of\nchoosing cakes, so 301 occurs twice in the output.\n\n* * *"}, {"input": "10 10 10 20\n 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736", "output": "23379871545\n 22444657051\n 22302177772\n 22095691512\n 21667941469\n 21366963278\n 21287912315\n 21279176669\n 21160477018\n 21085311041\n 21059876163\n 21017997739\n 20703329561\n 20702387965\n 20590247696\n 20383761436\n 20343962175\n 20254073196\n 20210218542\n 20150096547\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print K lines. The i-th line should contain the i-th value stated in the
problem statement.
* * * | s106591239 | Accepted | p03078 | Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z | import heapq
class PriorityQueue:
def __init__(self):
self.__heap = []
self.__count = 0
def empty(self) -> bool:
return self.__count == 0
def dequeue(self):
if self.empty():
raise Exception("empty")
self.__count -= 1
return heapq.heappop(self.__heap)
def enqueue(self, v):
self.__count += 1
heapq.heappush(self.__heap, v)
def __len__(self):
return self.__count
def cake123(X: int, Y: int, Z: int, K: int, A: list, B: list, C: list) -> list:
ret = [0] * K
sA = sorted(-a for a in A)
sB = sorted(-b for b in B)
sC = sorted(-c for c in C)
q = PriorityQueue()
q.enqueue((sA[0] + sB[0] + sC[0], 0, 0, 0))
used = {}
k = 0
while k < K:
delicious, ai, bi, ci = q.dequeue()
if -delicious in used and (ai, bi, ci) in used[-delicious]:
continue
used.setdefault(-delicious, set())
used[-delicious].add((ai, bi, ci))
ret[k] = -delicious
k += 1
if ai + 1 < X:
q.enqueue((sA[ai + 1] + sB[bi] + sC[ci], ai + 1, bi, ci))
if bi + 1 < Y:
q.enqueue((sA[ai] + sB[bi + 1] + sC[ci], ai, bi + 1, ci))
if ci + 1 < Z:
q.enqueue((sA[ai] + sB[bi] + sC[ci + 1], ai, bi, ci + 1))
return ret
if __name__ == "__main__":
X, Y, Z, K = map(int, input().split())
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]
ans = cake123(X, Y, Z, K, A, B, C)
for a in ans:
print(a)
| Statement
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y
and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles,
respectively. Each cake has an integer value called _deliciousness_ , as
follows:
* The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
* The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
* The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the
candles, to celebrate ABC 123.
There are X \times Y \times Z such ways to choose three cakes.
We will arrange these X \times Y \times Z ways in descending order of the sum
of the deliciousness of the cakes.
Print the sums of the deliciousness of the cakes for the first, second, ...,
K-th ways in this list. | [{"input": "2 2 2 8\n 4 6\n 1 5\n 3 8", "output": "19\n 17\n 15\n 14\n 13\n 12\n 10\n 8\n \n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below\nin descending order of the sum of the deliciousness of the cakes:\n\n * (A_2, B_2, C_2): 6 + 5 + 8 = 19\n * (A_1, B_2, C_2): 4 + 5 + 8 = 17\n * (A_2, B_1, C_2): 6 + 1 + 8 = 15\n * (A_2, B_2, C_1): 6 + 5 + 3 = 14\n * (A_1, B_1, C_2): 4 + 1 + 8 = 13\n * (A_1, B_2, C_1): 4 + 5 + 3 = 12\n * (A_2, B_1, C_1): 6 + 1 + 3 = 10\n * (A_1, B_1, C_1): 4 + 1 + 3 = 8\n\n* * *"}, {"input": "3 3 3 5\n 1 10 100\n 2 20 200\n 1 10 100", "output": "400\n 310\n 310\n 301\n 301\n \n\nThere may be multiple combinations of cakes with the same sum of the\ndeliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and\nthe sum of A_3, B_3, C_1 are both 301. However, they are different ways of\nchoosing cakes, so 301 occurs twice in the output.\n\n* * *"}, {"input": "10 10 10 20\n 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736", "output": "23379871545\n 22444657051\n 22302177772\n 22095691512\n 21667941469\n 21366963278\n 21287912315\n 21279176669\n 21160477018\n 21085311041\n 21059876163\n 21017997739\n 20703329561\n 20702387965\n 20590247696\n 20383761436\n 20343962175\n 20254073196\n 20210218542\n 20150096547\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print K lines. The i-th line should contain the i-th value stated in the
problem statement.
* * * | s971268682 | Runtime Error | p03078 | Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z | a = map(int, input().split())
a = list(a)
b = map(int, input().split())
b = list(b)
c = map(int, input().split())
c = list(c)
d = map(int, input().split())
d = list(d)
e = [0] * a[0] * a[1]
f = [0] * a[0] * a[1] * a[2]
print(a, b, c, d)
g1, g2 = 0, 0
for i in range(a[0]):
for j in range(a[1]):
e[g1] = b[i] + c[j]
g1 += 1
print(e)
for k in range(a[2]):
for l in range(len(e)):
f[g2] = c[k] + e[l]
g2 += 1
f.reverse()
print(f)
for m in range(a[3]):
print(f[m])
| Statement
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y
and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles,
respectively. Each cake has an integer value called _deliciousness_ , as
follows:
* The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
* The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
* The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the
candles, to celebrate ABC 123.
There are X \times Y \times Z such ways to choose three cakes.
We will arrange these X \times Y \times Z ways in descending order of the sum
of the deliciousness of the cakes.
Print the sums of the deliciousness of the cakes for the first, second, ...,
K-th ways in this list. | [{"input": "2 2 2 8\n 4 6\n 1 5\n 3 8", "output": "19\n 17\n 15\n 14\n 13\n 12\n 10\n 8\n \n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below\nin descending order of the sum of the deliciousness of the cakes:\n\n * (A_2, B_2, C_2): 6 + 5 + 8 = 19\n * (A_1, B_2, C_2): 4 + 5 + 8 = 17\n * (A_2, B_1, C_2): 6 + 1 + 8 = 15\n * (A_2, B_2, C_1): 6 + 5 + 3 = 14\n * (A_1, B_1, C_2): 4 + 1 + 8 = 13\n * (A_1, B_2, C_1): 4 + 5 + 3 = 12\n * (A_2, B_1, C_1): 6 + 1 + 3 = 10\n * (A_1, B_1, C_1): 4 + 1 + 3 = 8\n\n* * *"}, {"input": "3 3 3 5\n 1 10 100\n 2 20 200\n 1 10 100", "output": "400\n 310\n 310\n 301\n 301\n \n\nThere may be multiple combinations of cakes with the same sum of the\ndeliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and\nthe sum of A_3, B_3, C_1 are both 301. However, they are different ways of\nchoosing cakes, so 301 occurs twice in the output.\n\n* * *"}, {"input": "10 10 10 20\n 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736", "output": "23379871545\n 22444657051\n 22302177772\n 22095691512\n 21667941469\n 21366963278\n 21287912315\n 21279176669\n 21160477018\n 21085311041\n 21059876163\n 21017997739\n 20703329561\n 20702387965\n 20590247696\n 20383761436\n 20343962175\n 20254073196\n 20210218542\n 20150096547\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print K lines. The i-th line should contain the i-th value stated in the
problem statement.
* * * | s332630661 | Accepted | p03078 | Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z | def 解法3優先度付きキュー():
import heapq
X, Y, Z, K = [int(_) for _ in input().split()]
aA = sorted((int(_) for _ in input().split()), reverse=True)
aB = sorted((int(_) for _ in input().split()), reverse=True)
aC = sorted((int(_) for _ in input().split()), reverse=True)
dS = set()
aAns = [0] * K
aQ = []
def fPush(aQ, i, j, k):
if X <= i:
i = X - 1
if Y <= j:
j = Y - 1
if Z <= k:
k = Z - 1
if (i, j, k) not in dS:
heapq.heappush(aQ, (-1 * (aA[i] + aB[j] + aC[k]), i, j, k))
dS.add((i, j, k))
def fPop(aQ):
iD, i, j, k = heapq.heappop(aQ)
return (-1 * iD, i, j, k)
fPush(aQ, 0, 0, 0)
for iU in range(K):
aAns[iU], i, j, k = fPop(aQ)
fPush(aQ, i + 1, j, k)
fPush(aQ, i, j + 1, k)
fPush(aQ, i, j, k + 1)
print(*aAns, sep="\n")
解法3優先度付きキュー()
| Statement
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y
and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles,
respectively. Each cake has an integer value called _deliciousness_ , as
follows:
* The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
* The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
* The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the
candles, to celebrate ABC 123.
There are X \times Y \times Z such ways to choose three cakes.
We will arrange these X \times Y \times Z ways in descending order of the sum
of the deliciousness of the cakes.
Print the sums of the deliciousness of the cakes for the first, second, ...,
K-th ways in this list. | [{"input": "2 2 2 8\n 4 6\n 1 5\n 3 8", "output": "19\n 17\n 15\n 14\n 13\n 12\n 10\n 8\n \n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below\nin descending order of the sum of the deliciousness of the cakes:\n\n * (A_2, B_2, C_2): 6 + 5 + 8 = 19\n * (A_1, B_2, C_2): 4 + 5 + 8 = 17\n * (A_2, B_1, C_2): 6 + 1 + 8 = 15\n * (A_2, B_2, C_1): 6 + 5 + 3 = 14\n * (A_1, B_1, C_2): 4 + 1 + 8 = 13\n * (A_1, B_2, C_1): 4 + 5 + 3 = 12\n * (A_2, B_1, C_1): 6 + 1 + 3 = 10\n * (A_1, B_1, C_1): 4 + 1 + 3 = 8\n\n* * *"}, {"input": "3 3 3 5\n 1 10 100\n 2 20 200\n 1 10 100", "output": "400\n 310\n 310\n 301\n 301\n \n\nThere may be multiple combinations of cakes with the same sum of the\ndeliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and\nthe sum of A_3, B_3, C_1 are both 301. However, they are different ways of\nchoosing cakes, so 301 occurs twice in the output.\n\n* * *"}, {"input": "10 10 10 20\n 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736", "output": "23379871545\n 22444657051\n 22302177772\n 22095691512\n 21667941469\n 21366963278\n 21287912315\n 21279176669\n 21160477018\n 21085311041\n 21059876163\n 21017997739\n 20703329561\n 20702387965\n 20590247696\n 20383761436\n 20343962175\n 20254073196\n 20210218542\n 20150096547\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print K lines. The i-th line should contain the i-th value stated in the
problem statement.
* * * | s655962522 | Accepted | p03078 | Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z | import sys
import heapq
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readline_s = sys.stdin.readline
readlines = sys.stdin.buffer.readlines
INF = 10**10 + 7
def main():
X, Y, Z, K = map(int, readline().split())
A = sorted(list(map(int, readline().split())), reverse=True)
B = sorted(list(map(int, readline().split())), reverse=True)
C = sorted(list(map(int, readline().split())), reverse=True)
ans = solve3(X, Y, Z, K, A, B, C)
print("\n".join(map(str, ans)))
def solve3(X, Y, Z, K, A, B, C):
init_v = -(A[0] + B[0] + C[0])
q = [(init_v, 0, 0, 0)]
heapq.heapify(q)
search = set()
ans = []
for k in range(K):
v, a, b, c = heapq.heappop(q)
ans.append(-v)
if a + 1 < X and not ((a + 1, b, c) in search):
nv = A[a + 1] + B[b] + C[c]
heapq.heappush(q, (-nv, a + 1, b, c))
search |= {(a + 1, b, c)}
if b + 1 < Y and not ((a, b + 1, c) in search):
nv = A[a] + B[b + 1] + C[c]
heapq.heappush(q, (-nv, a, b + 1, c))
search |= {(a, b + 1, c)}
if c + 1 < Z and not ((a, b, c + 1) in search):
nv = A[a] + B[b] + C[c + 1]
heapq.heappush(q, (-nv, a, b, c + 1))
search |= {(a, b, c + 1)}
return ans
def solve2(X, Y, Z, K, A, B, C):
ABC = []
for i in range(X):
if (i + 1) > K:
break
for j in range(Y):
if (i + 1) * (j + 1) > K:
break
for k in range(Z):
if (i + 1) * (j + 1) * (k + 1) > K:
break
else:
ABC.append(A[i] + B[j] + C[k])
return sorted(ABC, reverse=True)[:K]
def solve1(X, Y, Z, K, A, B, C):
AB = []
for i in range(X):
for j in range(Y):
AB.append(A[i] + B[j])
AB.sort(reverse=True)
AB = AB[: min(X * Y, K)]
ABC = []
for i in range(len(AB)):
for j in range(Z):
ABC.append(AB[i] + C[j])
ABC.sort(reverse=True)
return ABC[:K]
if __name__ == "__main__":
main()
| Statement
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y
and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles,
respectively. Each cake has an integer value called _deliciousness_ , as
follows:
* The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
* The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
* The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the
candles, to celebrate ABC 123.
There are X \times Y \times Z such ways to choose three cakes.
We will arrange these X \times Y \times Z ways in descending order of the sum
of the deliciousness of the cakes.
Print the sums of the deliciousness of the cakes for the first, second, ...,
K-th ways in this list. | [{"input": "2 2 2 8\n 4 6\n 1 5\n 3 8", "output": "19\n 17\n 15\n 14\n 13\n 12\n 10\n 8\n \n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below\nin descending order of the sum of the deliciousness of the cakes:\n\n * (A_2, B_2, C_2): 6 + 5 + 8 = 19\n * (A_1, B_2, C_2): 4 + 5 + 8 = 17\n * (A_2, B_1, C_2): 6 + 1 + 8 = 15\n * (A_2, B_2, C_1): 6 + 5 + 3 = 14\n * (A_1, B_1, C_2): 4 + 1 + 8 = 13\n * (A_1, B_2, C_1): 4 + 5 + 3 = 12\n * (A_2, B_1, C_1): 6 + 1 + 3 = 10\n * (A_1, B_1, C_1): 4 + 1 + 3 = 8\n\n* * *"}, {"input": "3 3 3 5\n 1 10 100\n 2 20 200\n 1 10 100", "output": "400\n 310\n 310\n 301\n 301\n \n\nThere may be multiple combinations of cakes with the same sum of the\ndeliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and\nthe sum of A_3, B_3, C_1 are both 301. However, they are different ways of\nchoosing cakes, so 301 occurs twice in the output.\n\n* * *"}, {"input": "10 10 10 20\n 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736", "output": "23379871545\n 22444657051\n 22302177772\n 22095691512\n 21667941469\n 21366963278\n 21287912315\n 21279176669\n 21160477018\n 21085311041\n 21059876163\n 21017997739\n 20703329561\n 20702387965\n 20590247696\n 20383761436\n 20343962175\n 20254073196\n 20210218542\n 20150096547\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print K lines. The i-th line should contain the i-th value stated in the
problem statement.
* * * | s216957636 | Runtime Error | p03078 | Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z | x, y, z, k = map(int, input().split())
alis = sorted(list(map(int, input().split())))[::-1]
blis = sorted(list(map(int, input().split())))[::-1]
clis = sorted(list(map(int, input().split())))[::-1]
alis.append(-max(alis))
blis.append(-max(blis))
clis.append(-max(clis))
def search_next(a, b, c):
cans = [(alis[a] - alis[a + 1]), (blis[b] - blis[b + 1]), (clis[c] - clis[c + 1])]
nexts = [a, b, c]
nexts[cans.index(min(cans))] += 1
return nexts
a, b, c = 0, 0, 0
for i in range(k):
print(alis[a] + blis[b] + clis[c])
a, b, c = search_next(a, b, c)
| Statement
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y
and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles,
respectively. Each cake has an integer value called _deliciousness_ , as
follows:
* The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
* The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
* The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the
candles, to celebrate ABC 123.
There are X \times Y \times Z such ways to choose three cakes.
We will arrange these X \times Y \times Z ways in descending order of the sum
of the deliciousness of the cakes.
Print the sums of the deliciousness of the cakes for the first, second, ...,
K-th ways in this list. | [{"input": "2 2 2 8\n 4 6\n 1 5\n 3 8", "output": "19\n 17\n 15\n 14\n 13\n 12\n 10\n 8\n \n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below\nin descending order of the sum of the deliciousness of the cakes:\n\n * (A_2, B_2, C_2): 6 + 5 + 8 = 19\n * (A_1, B_2, C_2): 4 + 5 + 8 = 17\n * (A_2, B_1, C_2): 6 + 1 + 8 = 15\n * (A_2, B_2, C_1): 6 + 5 + 3 = 14\n * (A_1, B_1, C_2): 4 + 1 + 8 = 13\n * (A_1, B_2, C_1): 4 + 5 + 3 = 12\n * (A_2, B_1, C_1): 6 + 1 + 3 = 10\n * (A_1, B_1, C_1): 4 + 1 + 3 = 8\n\n* * *"}, {"input": "3 3 3 5\n 1 10 100\n 2 20 200\n 1 10 100", "output": "400\n 310\n 310\n 301\n 301\n \n\nThere may be multiple combinations of cakes with the same sum of the\ndeliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and\nthe sum of A_3, B_3, C_1 are both 301. However, they are different ways of\nchoosing cakes, so 301 occurs twice in the output.\n\n* * *"}, {"input": "10 10 10 20\n 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736", "output": "23379871545\n 22444657051\n 22302177772\n 22095691512\n 21667941469\n 21366963278\n 21287912315\n 21279176669\n 21160477018\n 21085311041\n 21059876163\n 21017997739\n 20703329561\n 20702387965\n 20590247696\n 20383761436\n 20343962175\n 20254073196\n 20210218542\n 20150096547\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print K lines. The i-th line should contain the i-th value stated in the
problem statement.
* * * | s000988458 | Wrong Answer | p03078 | Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z | 23379871545
22444657051
22302177772
22095691512
21667941469
21366963278
21287912315
21279176669
21160477018
21085311041
21059876163
21017997739
20703329561
20702387965
20590247696
20383761436
20343962175
20254073196
20210218542
20150096547
| Statement
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y
and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles,
respectively. Each cake has an integer value called _deliciousness_ , as
follows:
* The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
* The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
* The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the
candles, to celebrate ABC 123.
There are X \times Y \times Z such ways to choose three cakes.
We will arrange these X \times Y \times Z ways in descending order of the sum
of the deliciousness of the cakes.
Print the sums of the deliciousness of the cakes for the first, second, ...,
K-th ways in this list. | [{"input": "2 2 2 8\n 4 6\n 1 5\n 3 8", "output": "19\n 17\n 15\n 14\n 13\n 12\n 10\n 8\n \n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below\nin descending order of the sum of the deliciousness of the cakes:\n\n * (A_2, B_2, C_2): 6 + 5 + 8 = 19\n * (A_1, B_2, C_2): 4 + 5 + 8 = 17\n * (A_2, B_1, C_2): 6 + 1 + 8 = 15\n * (A_2, B_2, C_1): 6 + 5 + 3 = 14\n * (A_1, B_1, C_2): 4 + 1 + 8 = 13\n * (A_1, B_2, C_1): 4 + 5 + 3 = 12\n * (A_2, B_1, C_1): 6 + 1 + 3 = 10\n * (A_1, B_1, C_1): 4 + 1 + 3 = 8\n\n* * *"}, {"input": "3 3 3 5\n 1 10 100\n 2 20 200\n 1 10 100", "output": "400\n 310\n 310\n 301\n 301\n \n\nThere may be multiple combinations of cakes with the same sum of the\ndeliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and\nthe sum of A_3, B_3, C_1 are both 301. However, they are different ways of\nchoosing cakes, so 301 occurs twice in the output.\n\n* * *"}, {"input": "10 10 10 20\n 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736", "output": "23379871545\n 22444657051\n 22302177772\n 22095691512\n 21667941469\n 21366963278\n 21287912315\n 21279176669\n 21160477018\n 21085311041\n 21059876163\n 21017997739\n 20703329561\n 20702387965\n 20590247696\n 20383761436\n 20343962175\n 20254073196\n 20210218542\n 20150096547\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print K lines. The i-th line should contain the i-th value stated in the
problem statement.
* * * | s194575913 | Runtime Error | p03078 | Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z | X, Y, Z, K = map(int(input()))
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
| Statement
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y
and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles,
respectively. Each cake has an integer value called _deliciousness_ , as
follows:
* The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
* The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
* The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the
candles, to celebrate ABC 123.
There are X \times Y \times Z such ways to choose three cakes.
We will arrange these X \times Y \times Z ways in descending order of the sum
of the deliciousness of the cakes.
Print the sums of the deliciousness of the cakes for the first, second, ...,
K-th ways in this list. | [{"input": "2 2 2 8\n 4 6\n 1 5\n 3 8", "output": "19\n 17\n 15\n 14\n 13\n 12\n 10\n 8\n \n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below\nin descending order of the sum of the deliciousness of the cakes:\n\n * (A_2, B_2, C_2): 6 + 5 + 8 = 19\n * (A_1, B_2, C_2): 4 + 5 + 8 = 17\n * (A_2, B_1, C_2): 6 + 1 + 8 = 15\n * (A_2, B_2, C_1): 6 + 5 + 3 = 14\n * (A_1, B_1, C_2): 4 + 1 + 8 = 13\n * (A_1, B_2, C_1): 4 + 5 + 3 = 12\n * (A_2, B_1, C_1): 6 + 1 + 3 = 10\n * (A_1, B_1, C_1): 4 + 1 + 3 = 8\n\n* * *"}, {"input": "3 3 3 5\n 1 10 100\n 2 20 200\n 1 10 100", "output": "400\n 310\n 310\n 301\n 301\n \n\nThere may be multiple combinations of cakes with the same sum of the\ndeliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and\nthe sum of A_3, B_3, C_1 are both 301. However, they are different ways of\nchoosing cakes, so 301 occurs twice in the output.\n\n* * *"}, {"input": "10 10 10 20\n 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736", "output": "23379871545\n 22444657051\n 22302177772\n 22095691512\n 21667941469\n 21366963278\n 21287912315\n 21279176669\n 21160477018\n 21085311041\n 21059876163\n 21017997739\n 20703329561\n 20702387965\n 20590247696\n 20383761436\n 20343962175\n 20254073196\n 20210218542\n 20150096547\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print K lines. The i-th line should contain the i-th value stated in the
problem statement.
* * * | s661439067 | Accepted | p03078 | Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z | import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines
# rstrip().decode('utf-8')
# import math
import numpy as np
# import operator
# import bisect
# from heapq import heapify,heappop,heappush
# from math import gcd
# from fractions import gcd
# from collections import deque
# from collections import defaultdict
# from collections import Counter
# from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# sys.setrecursionlimit(10**7)
# map(int,input().split())
def main():
x, y, z, k = map(int, input().split())
ABC = np.array(read().split(), np.int64)
A = ABC[:x]
B = ABC[x:-z]
C = ABC[-z:]
AB = np.add.outer(A, B)
AB = AB.ravel()
AB.sort()
AB = AB[-k:]
ans = np.add.outer(AB, C)
ans = ans.ravel()
ans.sort()
for i in range(k):
print(ans[-i - 1])
if __name__ == "__main__":
main()
| Statement
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y
and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles,
respectively. Each cake has an integer value called _deliciousness_ , as
follows:
* The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
* The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
* The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the
candles, to celebrate ABC 123.
There are X \times Y \times Z such ways to choose three cakes.
We will arrange these X \times Y \times Z ways in descending order of the sum
of the deliciousness of the cakes.
Print the sums of the deliciousness of the cakes for the first, second, ...,
K-th ways in this list. | [{"input": "2 2 2 8\n 4 6\n 1 5\n 3 8", "output": "19\n 17\n 15\n 14\n 13\n 12\n 10\n 8\n \n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below\nin descending order of the sum of the deliciousness of the cakes:\n\n * (A_2, B_2, C_2): 6 + 5 + 8 = 19\n * (A_1, B_2, C_2): 4 + 5 + 8 = 17\n * (A_2, B_1, C_2): 6 + 1 + 8 = 15\n * (A_2, B_2, C_1): 6 + 5 + 3 = 14\n * (A_1, B_1, C_2): 4 + 1 + 8 = 13\n * (A_1, B_2, C_1): 4 + 5 + 3 = 12\n * (A_2, B_1, C_1): 6 + 1 + 3 = 10\n * (A_1, B_1, C_1): 4 + 1 + 3 = 8\n\n* * *"}, {"input": "3 3 3 5\n 1 10 100\n 2 20 200\n 1 10 100", "output": "400\n 310\n 310\n 301\n 301\n \n\nThere may be multiple combinations of cakes with the same sum of the\ndeliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and\nthe sum of A_3, B_3, C_1 are both 301. However, they are different ways of\nchoosing cakes, so 301 occurs twice in the output.\n\n* * *"}, {"input": "10 10 10 20\n 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736", "output": "23379871545\n 22444657051\n 22302177772\n 22095691512\n 21667941469\n 21366963278\n 21287912315\n 21279176669\n 21160477018\n 21085311041\n 21059876163\n 21017997739\n 20703329561\n 20702387965\n 20590247696\n 20383761436\n 20343962175\n 20254073196\n 20210218542\n 20150096547\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print K lines. The i-th line should contain the i-th value stated in the
problem statement.
* * * | s841389488 | Runtime Error | p03078 | Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z | # To avoid the use of reverse, define inverse order intentionally
def merge(a, b):
i, j = 0, 0
merged = []
while i < len(a) or j < len(b):
if j >= len(b) or a[i] > b[j]: # take from a if a[i] is larger than b[j]
merged.append(a[i])
i += 1
else:
merged.append(b[j])
j += 1
return merged
# merge sort with inverse order
def merge_sort(l):
if len(l) == 1:
return l
l1 = l[0 : (len(l) // 2)]
l2 = l[(len(l) // 2) :]
ll1 = merge_sort(l1)
ll2 = merge_sort(l2)
return merge(ll1, ll2)
XYZK = list(map(int, input().split()))
tastes = []
for n in range(3):
tastes.append(list(map(int, input().split())))
ab_tastes = []
for i in range(XYZK[0]):
for j in range(XYZK[1]):
ab_tastes.append(tastes[0][i] + tastes[1][j])
ab_tastes = merge_sort(ab_tastes)
final = []
for i in range(min(XYZK[0] * XYZK[1], XYZK[3])):
for j in range(XYZK[2]):
final.append(ab_tastes[i] + tastes[2][j])
final = merge_sort(final)
for i in range(XYZK[3]):
print(final[i])
| Statement
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y
and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles,
respectively. Each cake has an integer value called _deliciousness_ , as
follows:
* The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
* The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
* The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the
candles, to celebrate ABC 123.
There are X \times Y \times Z such ways to choose three cakes.
We will arrange these X \times Y \times Z ways in descending order of the sum
of the deliciousness of the cakes.
Print the sums of the deliciousness of the cakes for the first, second, ...,
K-th ways in this list. | [{"input": "2 2 2 8\n 4 6\n 1 5\n 3 8", "output": "19\n 17\n 15\n 14\n 13\n 12\n 10\n 8\n \n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below\nin descending order of the sum of the deliciousness of the cakes:\n\n * (A_2, B_2, C_2): 6 + 5 + 8 = 19\n * (A_1, B_2, C_2): 4 + 5 + 8 = 17\n * (A_2, B_1, C_2): 6 + 1 + 8 = 15\n * (A_2, B_2, C_1): 6 + 5 + 3 = 14\n * (A_1, B_1, C_2): 4 + 1 + 8 = 13\n * (A_1, B_2, C_1): 4 + 5 + 3 = 12\n * (A_2, B_1, C_1): 6 + 1 + 3 = 10\n * (A_1, B_1, C_1): 4 + 1 + 3 = 8\n\n* * *"}, {"input": "3 3 3 5\n 1 10 100\n 2 20 200\n 1 10 100", "output": "400\n 310\n 310\n 301\n 301\n \n\nThere may be multiple combinations of cakes with the same sum of the\ndeliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and\nthe sum of A_3, B_3, C_1 are both 301. However, they are different ways of\nchoosing cakes, so 301 occurs twice in the output.\n\n* * *"}, {"input": "10 10 10 20\n 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736", "output": "23379871545\n 22444657051\n 22302177772\n 22095691512\n 21667941469\n 21366963278\n 21287912315\n 21279176669\n 21160477018\n 21085311041\n 21059876163\n 21017997739\n 20703329561\n 20702387965\n 20590247696\n 20383761436\n 20343962175\n 20254073196\n 20210218542\n 20150096547\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print K lines. The i-th line should contain the i-th value stated in the
problem statement.
* * * | s792830076 | Accepted | p03078 | Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z | X, Y, Z, K = [int(_) for _ in input().split()]
As = [int(_) for _ in input().split()]
Bs = [int(_) for _ in input().split()]
Cs = [int(_) for _ in input().split()]
As.sort()
Bs.sort()
Cs.sort()
choice_stack = [(As[-1] + Bs[-1] + Cs[-1], len(As) - 1, len(Bs) - 1, len(Cs) - 1)]
choice_log = set()
j = 0
while True:
choice_stack.sort()
chosen_sum, Ai, Bi, Ci = choice_stack.pop()
print(chosen_sum)
step_A = (As[max(0, Ai - 1)] + Bs[Bi] + Cs[Ci], max(0, Ai - 1), Bi, Ci)
step_B = (As[Ai] + Bs[max(0, Bi - 1)] + Cs[Ci], Ai, max(0, Bi - 1), Ci)
step_C = (As[Ai] + Bs[Bi] + Cs[max(0, Ci - 1)], Ai, Bi, max(0, Ci - 1))
if not (step_A in choice_log):
choice_stack.append(step_A)
choice_log.add(step_A)
if not (step_B in choice_log):
choice_stack.append(step_B)
choice_log.add(step_B)
if not (step_C in choice_log):
choice_stack.append(step_C)
choice_log.add(step_C)
j += 1
if j >= K:
break
| Statement
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y
and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles,
respectively. Each cake has an integer value called _deliciousness_ , as
follows:
* The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
* The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
* The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the
candles, to celebrate ABC 123.
There are X \times Y \times Z such ways to choose three cakes.
We will arrange these X \times Y \times Z ways in descending order of the sum
of the deliciousness of the cakes.
Print the sums of the deliciousness of the cakes for the first, second, ...,
K-th ways in this list. | [{"input": "2 2 2 8\n 4 6\n 1 5\n 3 8", "output": "19\n 17\n 15\n 14\n 13\n 12\n 10\n 8\n \n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below\nin descending order of the sum of the deliciousness of the cakes:\n\n * (A_2, B_2, C_2): 6 + 5 + 8 = 19\n * (A_1, B_2, C_2): 4 + 5 + 8 = 17\n * (A_2, B_1, C_2): 6 + 1 + 8 = 15\n * (A_2, B_2, C_1): 6 + 5 + 3 = 14\n * (A_1, B_1, C_2): 4 + 1 + 8 = 13\n * (A_1, B_2, C_1): 4 + 5 + 3 = 12\n * (A_2, B_1, C_1): 6 + 1 + 3 = 10\n * (A_1, B_1, C_1): 4 + 1 + 3 = 8\n\n* * *"}, {"input": "3 3 3 5\n 1 10 100\n 2 20 200\n 1 10 100", "output": "400\n 310\n 310\n 301\n 301\n \n\nThere may be multiple combinations of cakes with the same sum of the\ndeliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and\nthe sum of A_3, B_3, C_1 are both 301. However, they are different ways of\nchoosing cakes, so 301 occurs twice in the output.\n\n* * *"}, {"input": "10 10 10 20\n 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736", "output": "23379871545\n 22444657051\n 22302177772\n 22095691512\n 21667941469\n 21366963278\n 21287912315\n 21279176669\n 21160477018\n 21085311041\n 21059876163\n 21017997739\n 20703329561\n 20702387965\n 20590247696\n 20383761436\n 20343962175\n 20254073196\n 20210218542\n 20150096547\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print K lines. The i-th line should contain the i-th value stated in the
problem statement.
* * * | s300879235 | Accepted | p03078 | Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z | import heapq
class Delicious(object):
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
def total(self):
return A[self.x] + B[self.y] + C[self.z]
def __lt__(self, other):
return self.total() > other.total()
X, Y, Z, K = map(int, input().split(" "))
A = sorted(map(int, input().split(" ")), reverse=True)
B = sorted(map(int, input().split(" ")), reverse=True)
C = sorted(map(int, input().split(" ")), reverse=True)
ds = []
heapq.heappush(ds, Delicious(0, 0, 0))
check = {}
for _ in range(K):
d = heapq.heappop(ds)
while (d.x, d.y, d.z) in check:
d = heapq.heappop(ds)
print(d.total())
check[d.x, d.y, d.z] = True
if d.x < X - 1:
heapq.heappush(ds, Delicious(d.x + 1, d.y, d.z))
if d.y < Y - 1:
heapq.heappush(ds, Delicious(d.x, d.y + 1, d.z))
if d.z < Z - 1:
heapq.heappush(ds, Delicious(d.x, d.y, d.z + 1))
| Statement
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y
and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles,
respectively. Each cake has an integer value called _deliciousness_ , as
follows:
* The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
* The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
* The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the
candles, to celebrate ABC 123.
There are X \times Y \times Z such ways to choose three cakes.
We will arrange these X \times Y \times Z ways in descending order of the sum
of the deliciousness of the cakes.
Print the sums of the deliciousness of the cakes for the first, second, ...,
K-th ways in this list. | [{"input": "2 2 2 8\n 4 6\n 1 5\n 3 8", "output": "19\n 17\n 15\n 14\n 13\n 12\n 10\n 8\n \n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below\nin descending order of the sum of the deliciousness of the cakes:\n\n * (A_2, B_2, C_2): 6 + 5 + 8 = 19\n * (A_1, B_2, C_2): 4 + 5 + 8 = 17\n * (A_2, B_1, C_2): 6 + 1 + 8 = 15\n * (A_2, B_2, C_1): 6 + 5 + 3 = 14\n * (A_1, B_1, C_2): 4 + 1 + 8 = 13\n * (A_1, B_2, C_1): 4 + 5 + 3 = 12\n * (A_2, B_1, C_1): 6 + 1 + 3 = 10\n * (A_1, B_1, C_1): 4 + 1 + 3 = 8\n\n* * *"}, {"input": "3 3 3 5\n 1 10 100\n 2 20 200\n 1 10 100", "output": "400\n 310\n 310\n 301\n 301\n \n\nThere may be multiple combinations of cakes with the same sum of the\ndeliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and\nthe sum of A_3, B_3, C_1 are both 301. However, they are different ways of\nchoosing cakes, so 301 occurs twice in the output.\n\n* * *"}, {"input": "10 10 10 20\n 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736", "output": "23379871545\n 22444657051\n 22302177772\n 22095691512\n 21667941469\n 21366963278\n 21287912315\n 21279176669\n 21160477018\n 21085311041\n 21059876163\n 21017997739\n 20703329561\n 20702387965\n 20590247696\n 20383761436\n 20343962175\n 20254073196\n 20210218542\n 20150096547\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print K lines. The i-th line should contain the i-th value stated in the
problem statement.
* * * | s159579926 | Accepted | p03078 | Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z | read = input
def read_numbers():
a = read().split(" ")
a = list(map(int, a))
return a
[x, y, z, K] = read_numbers()
memo = [[set() for i in range(y)] for i in range(x)]
X = read_numbers()
Y = read_numbers()
Z = read_numbers()
X.sort()
X.reverse()
Y.sort()
Y.reverse()
Z.sort()
Z.reverse()
import queue
def cal(px, py, pz):
return X[px] + Y[py] + Z[pz]
memo[0][0].add(0)
cnt = 0
pq = queue.PriorityQueue()
# print(X,Y,Z)
pq.put((-cal(0, 0, 0), 0, 0, 0))
while cnt < K:
# print(cnt)
cost, px, py, pz = pq.get(timeout=1)
# print(cost, px, py,pz)
for i in range(px - 1, px + 2):
for j in range(py - 1, py + 2):
for k in range(pz - 1, pz + 2):
if (
i >= 0
and i < x
and j >= 0
and j < y
and k >= 0
and k < z
and k not in memo[i][j]
):
memo[i][j].add(k)
pq.put((-cal(i, j, k), i, j, k))
print(-cost)
cnt = cnt + 1
| Statement
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y
and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles,
respectively. Each cake has an integer value called _deliciousness_ , as
follows:
* The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
* The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
* The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the
candles, to celebrate ABC 123.
There are X \times Y \times Z such ways to choose three cakes.
We will arrange these X \times Y \times Z ways in descending order of the sum
of the deliciousness of the cakes.
Print the sums of the deliciousness of the cakes for the first, second, ...,
K-th ways in this list. | [{"input": "2 2 2 8\n 4 6\n 1 5\n 3 8", "output": "19\n 17\n 15\n 14\n 13\n 12\n 10\n 8\n \n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below\nin descending order of the sum of the deliciousness of the cakes:\n\n * (A_2, B_2, C_2): 6 + 5 + 8 = 19\n * (A_1, B_2, C_2): 4 + 5 + 8 = 17\n * (A_2, B_1, C_2): 6 + 1 + 8 = 15\n * (A_2, B_2, C_1): 6 + 5 + 3 = 14\n * (A_1, B_1, C_2): 4 + 1 + 8 = 13\n * (A_1, B_2, C_1): 4 + 5 + 3 = 12\n * (A_2, B_1, C_1): 6 + 1 + 3 = 10\n * (A_1, B_1, C_1): 4 + 1 + 3 = 8\n\n* * *"}, {"input": "3 3 3 5\n 1 10 100\n 2 20 200\n 1 10 100", "output": "400\n 310\n 310\n 301\n 301\n \n\nThere may be multiple combinations of cakes with the same sum of the\ndeliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and\nthe sum of A_3, B_3, C_1 are both 301. However, they are different ways of\nchoosing cakes, so 301 occurs twice in the output.\n\n* * *"}, {"input": "10 10 10 20\n 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736", "output": "23379871545\n 22444657051\n 22302177772\n 22095691512\n 21667941469\n 21366963278\n 21287912315\n 21279176669\n 21160477018\n 21085311041\n 21059876163\n 21017997739\n 20703329561\n 20702387965\n 20590247696\n 20383761436\n 20343962175\n 20254073196\n 20210218542\n 20150096547\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print K lines. The i-th line should contain the i-th value stated in the
problem statement.
* * * | s245407807 | Runtime Error | p03078 | Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z | x, y, z, w = map(int, input().split())
lx = list(map(int, input().split()))
ly = list(map(int, input().split()))
lz = list(map(int, input().split()))
lxy = []
for i in range(x):
for j in range(y):
lxy.append(lx[i] + ly[j])
lxy = sorted(lxy)
lxy = lxy[::-1]
l = []
for i in range(w):
l.append(lxy[i])
lxyz = []
for i in range(z):
for j in range(w):
lxyz.append(lz[i] + l[j])
lxyz = sorted(lxyz)
lxyz = lxyz[::-1]
for i in range(w):
print(lxyz[i])
| Statement
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y
and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles,
respectively. Each cake has an integer value called _deliciousness_ , as
follows:
* The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
* The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
* The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the
candles, to celebrate ABC 123.
There are X \times Y \times Z such ways to choose three cakes.
We will arrange these X \times Y \times Z ways in descending order of the sum
of the deliciousness of the cakes.
Print the sums of the deliciousness of the cakes for the first, second, ...,
K-th ways in this list. | [{"input": "2 2 2 8\n 4 6\n 1 5\n 3 8", "output": "19\n 17\n 15\n 14\n 13\n 12\n 10\n 8\n \n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below\nin descending order of the sum of the deliciousness of the cakes:\n\n * (A_2, B_2, C_2): 6 + 5 + 8 = 19\n * (A_1, B_2, C_2): 4 + 5 + 8 = 17\n * (A_2, B_1, C_2): 6 + 1 + 8 = 15\n * (A_2, B_2, C_1): 6 + 5 + 3 = 14\n * (A_1, B_1, C_2): 4 + 1 + 8 = 13\n * (A_1, B_2, C_1): 4 + 5 + 3 = 12\n * (A_2, B_1, C_1): 6 + 1 + 3 = 10\n * (A_1, B_1, C_1): 4 + 1 + 3 = 8\n\n* * *"}, {"input": "3 3 3 5\n 1 10 100\n 2 20 200\n 1 10 100", "output": "400\n 310\n 310\n 301\n 301\n \n\nThere may be multiple combinations of cakes with the same sum of the\ndeliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and\nthe sum of A_3, B_3, C_1 are both 301. However, they are different ways of\nchoosing cakes, so 301 occurs twice in the output.\n\n* * *"}, {"input": "10 10 10 20\n 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736", "output": "23379871545\n 22444657051\n 22302177772\n 22095691512\n 21667941469\n 21366963278\n 21287912315\n 21279176669\n 21160477018\n 21085311041\n 21059876163\n 21017997739\n 20703329561\n 20702387965\n 20590247696\n 20383761436\n 20343962175\n 20254073196\n 20210218542\n 20150096547\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print K lines. The i-th line should contain the i-th value stated in the
problem statement.
* * * | s546293382 | Wrong Answer | p03078 | Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z | N = list(map(int, (input().split(" "))))
teast = []
K = N[3]
total = []
all = []
c = 0
for i in range(3):
teast.append(list(map(int, input().split(" "))))
for i in teast[0]:
for j in teast[1]:
total.append(i + j)
total_s = sorted(total, reverse=True)
del total_s[K:]
for i in total_s:
for k in teast[2]:
all.append(i + k)
all_s = sorted(all, reverse=True)
for i in all_s:
print(i)
| Statement
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y
and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles,
respectively. Each cake has an integer value called _deliciousness_ , as
follows:
* The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
* The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
* The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the
candles, to celebrate ABC 123.
There are X \times Y \times Z such ways to choose three cakes.
We will arrange these X \times Y \times Z ways in descending order of the sum
of the deliciousness of the cakes.
Print the sums of the deliciousness of the cakes for the first, second, ...,
K-th ways in this list. | [{"input": "2 2 2 8\n 4 6\n 1 5\n 3 8", "output": "19\n 17\n 15\n 14\n 13\n 12\n 10\n 8\n \n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below\nin descending order of the sum of the deliciousness of the cakes:\n\n * (A_2, B_2, C_2): 6 + 5 + 8 = 19\n * (A_1, B_2, C_2): 4 + 5 + 8 = 17\n * (A_2, B_1, C_2): 6 + 1 + 8 = 15\n * (A_2, B_2, C_1): 6 + 5 + 3 = 14\n * (A_1, B_1, C_2): 4 + 1 + 8 = 13\n * (A_1, B_2, C_1): 4 + 5 + 3 = 12\n * (A_2, B_1, C_1): 6 + 1 + 3 = 10\n * (A_1, B_1, C_1): 4 + 1 + 3 = 8\n\n* * *"}, {"input": "3 3 3 5\n 1 10 100\n 2 20 200\n 1 10 100", "output": "400\n 310\n 310\n 301\n 301\n \n\nThere may be multiple combinations of cakes with the same sum of the\ndeliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and\nthe sum of A_3, B_3, C_1 are both 301. However, they are different ways of\nchoosing cakes, so 301 occurs twice in the output.\n\n* * *"}, {"input": "10 10 10 20\n 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736", "output": "23379871545\n 22444657051\n 22302177772\n 22095691512\n 21667941469\n 21366963278\n 21287912315\n 21279176669\n 21160477018\n 21085311041\n 21059876163\n 21017997739\n 20703329561\n 20702387965\n 20590247696\n 20383761436\n 20343962175\n 20254073196\n 20210218542\n 20150096547\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print K lines. The i-th line should contain the i-th value stated in the
problem statement.
* * * | s287703741 | Accepted | p03078 | Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z | X, Y, Z, K = map(int, input().split())
A_array = list(map(int, input().split()))
B_array = list(map(int, input().split()))
C_array = list(map(int, input().split()))
A_array.sort()
B_array.sort()
C_array.sort()
use_array = []
sum_array = []
candidate_array = []
max_sum = A_array[-1] + B_array[-1] + C_array[-1]
candidate_array = [[X - 1, Y - 1, Z - 1, max_sum]]
use_array.append((X - 1, Y - 1, Z - 1))
for i in range(K):
candidate_array = sorted(candidate_array, key=lambda x: -x[3])
x, y, z, s = candidate_array.pop(0)
sum_array.append(s)
if x != 0 and (x - 1, y, z) not in use_array:
use_array.append((x - 1, y, z))
diff = A_array[x] - A_array[x - 1]
candidate_array.append([x - 1, y, z, s - diff])
if y != 0 and (x, y - 1, z) not in use_array:
use_array.append((x, y - 1, z))
diff = B_array[y] - B_array[y - 1]
candidate_array.append([x, y - 1, z, s - diff])
if z != 0 and (x, y, z - 1) not in use_array:
use_array.append((x, y, z - 1))
diff = C_array[z] - C_array[z - 1]
candidate_array.append([x, y, z - 1, s - diff])
for ans in sum_array:
print(ans)
| Statement
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y
and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles,
respectively. Each cake has an integer value called _deliciousness_ , as
follows:
* The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
* The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
* The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the
candles, to celebrate ABC 123.
There are X \times Y \times Z such ways to choose three cakes.
We will arrange these X \times Y \times Z ways in descending order of the sum
of the deliciousness of the cakes.
Print the sums of the deliciousness of the cakes for the first, second, ...,
K-th ways in this list. | [{"input": "2 2 2 8\n 4 6\n 1 5\n 3 8", "output": "19\n 17\n 15\n 14\n 13\n 12\n 10\n 8\n \n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below\nin descending order of the sum of the deliciousness of the cakes:\n\n * (A_2, B_2, C_2): 6 + 5 + 8 = 19\n * (A_1, B_2, C_2): 4 + 5 + 8 = 17\n * (A_2, B_1, C_2): 6 + 1 + 8 = 15\n * (A_2, B_2, C_1): 6 + 5 + 3 = 14\n * (A_1, B_1, C_2): 4 + 1 + 8 = 13\n * (A_1, B_2, C_1): 4 + 5 + 3 = 12\n * (A_2, B_1, C_1): 6 + 1 + 3 = 10\n * (A_1, B_1, C_1): 4 + 1 + 3 = 8\n\n* * *"}, {"input": "3 3 3 5\n 1 10 100\n 2 20 200\n 1 10 100", "output": "400\n 310\n 310\n 301\n 301\n \n\nThere may be multiple combinations of cakes with the same sum of the\ndeliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and\nthe sum of A_3, B_3, C_1 are both 301. However, they are different ways of\nchoosing cakes, so 301 occurs twice in the output.\n\n* * *"}, {"input": "10 10 10 20\n 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736", "output": "23379871545\n 22444657051\n 22302177772\n 22095691512\n 21667941469\n 21366963278\n 21287912315\n 21279176669\n 21160477018\n 21085311041\n 21059876163\n 21017997739\n 20703329561\n 20702387965\n 20590247696\n 20383761436\n 20343962175\n 20254073196\n 20210218542\n 20150096547\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print K lines. The i-th line should contain the i-th value stated in the
problem statement.
* * * | s590062947 | Wrong Answer | p03078 | Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z | # ヒープに要素を追加、一番でかいのを取り出すという操作を最大3000回やるやり方
# これもなかなか早い
# ヒープは追加も要素の取り出しもO(log n)で住むので、
# 計算オーダーはO(K log n)で済む(nはヒープの要素数)らしいが
# not in があるのでO(n K log n)では?
# pythonのヒープは使い方に癖があるのでこの機会に習得しよう
import sys
read = sys.stdin.readline
def read_ints():
return list(map(int, read().split()))
X, Y, Z, K = read_ints()
A = read_ints()
B = read_ints()
C = read_ints()
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
from heapq import heapify, heappop, heappush, heappushpop
class PriorityQueue:
def __init__(self, heap):
"""
heap ... list
"""
self.heap = heap
heapify(self.heap)
def push(self, item):
print(self.heap, item)
heappush(self.heap, item)
def pop(self):
return heappop(self.heap)
def pushpop(self, item):
return heappushpop(self.heap, item)
def __call__(self):
return self.heap
heap = [] # ヒープといっても順序を工夫したただのリスト
q = PriorityQueue(heap)
q.push((-(A[0] + B[0] + C[0]), 0, 0, 0))
ans = []
for k_th in range(1, K + 1):
heap_max, i, j, k = q.pop()
# print(heap_max)
ans.append(-heap_max)
for di, dj, dk in zip([1, 0, 0], [0, 1, 0], [0, 0, 1]):
i_new, j_new, k_new = i + di, j + dj, k + dk
if i_new >= X or j_new >= Y or k_new >= Z:
continue
tmp = (-(A[i_new] + B[j_new] + C[k_new]), i_new, j_new, k_new)
if tmp in q(): # ここが計算量がおおい
continue
q.push(tmp)
print(*ans, sep="\n")
| Statement
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y
and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles,
respectively. Each cake has an integer value called _deliciousness_ , as
follows:
* The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
* The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
* The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the
candles, to celebrate ABC 123.
There are X \times Y \times Z such ways to choose three cakes.
We will arrange these X \times Y \times Z ways in descending order of the sum
of the deliciousness of the cakes.
Print the sums of the deliciousness of the cakes for the first, second, ...,
K-th ways in this list. | [{"input": "2 2 2 8\n 4 6\n 1 5\n 3 8", "output": "19\n 17\n 15\n 14\n 13\n 12\n 10\n 8\n \n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below\nin descending order of the sum of the deliciousness of the cakes:\n\n * (A_2, B_2, C_2): 6 + 5 + 8 = 19\n * (A_1, B_2, C_2): 4 + 5 + 8 = 17\n * (A_2, B_1, C_2): 6 + 1 + 8 = 15\n * (A_2, B_2, C_1): 6 + 5 + 3 = 14\n * (A_1, B_1, C_2): 4 + 1 + 8 = 13\n * (A_1, B_2, C_1): 4 + 5 + 3 = 12\n * (A_2, B_1, C_1): 6 + 1 + 3 = 10\n * (A_1, B_1, C_1): 4 + 1 + 3 = 8\n\n* * *"}, {"input": "3 3 3 5\n 1 10 100\n 2 20 200\n 1 10 100", "output": "400\n 310\n 310\n 301\n 301\n \n\nThere may be multiple combinations of cakes with the same sum of the\ndeliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and\nthe sum of A_3, B_3, C_1 are both 301. However, they are different ways of\nchoosing cakes, so 301 occurs twice in the output.\n\n* * *"}, {"input": "10 10 10 20\n 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736", "output": "23379871545\n 22444657051\n 22302177772\n 22095691512\n 21667941469\n 21366963278\n 21287912315\n 21279176669\n 21160477018\n 21085311041\n 21059876163\n 21017997739\n 20703329561\n 20702387965\n 20590247696\n 20383761436\n 20343962175\n 20254073196\n 20210218542\n 20150096547\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print K lines. The i-th line should contain the i-th value stated in the
problem statement.
* * * | s928848207 | Accepted | p03078 | Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z | X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
asort, bsort, csort = (
sorted(A, reverse=True),
sorted(B, reverse=True),
sorted(C, reverse=True),
)
print(asort[0] + bsort[0] + csort[0])
already = [[0, 0, 0]]
x, y, z = 0, 0, 0
place_sum = []
check = []
for k in range(K - 1):
if [x + 1, y, z] not in already and x + 1 < X:
already.append([x + 1, y, z])
place_sum.append([x + 1, y, z])
check.append(asort[x + 1] + bsort[y] + csort[z])
if [x, y + 1, z] not in already and y + 1 < Y:
already.append([x, y + 1, z])
place_sum.append([x, y + 1, z])
check.append(asort[x] + bsort[y + 1] + csort[z])
if [x, y, z + 1] not in already and z + 1 < Z:
already.append([x, y, z + 1])
place_sum.append([x, y, z + 1])
check.append(asort[x] + bsort[y] + csort[z + 1])
print(max(check))
x, y, z = (
place_sum[check.index(max(check))][0],
place_sum[check.index(max(check))][1],
place_sum[check.index(max(check))][2],
)
place_sum.pop(check.index(max(check)))
check.remove(max(check))
| Statement
The Patisserie AtCoder sells cakes with number-shaped candles. There are X, Y
and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles,
respectively. Each cake has an integer value called _deliciousness_ , as
follows:
* The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
* The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
* The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the
candles, to celebrate ABC 123.
There are X \times Y \times Z such ways to choose three cakes.
We will arrange these X \times Y \times Z ways in descending order of the sum
of the deliciousness of the cakes.
Print the sums of the deliciousness of the cakes for the first, second, ...,
K-th ways in this list. | [{"input": "2 2 2 8\n 4 6\n 1 5\n 3 8", "output": "19\n 17\n 15\n 14\n 13\n 12\n 10\n 8\n \n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below\nin descending order of the sum of the deliciousness of the cakes:\n\n * (A_2, B_2, C_2): 6 + 5 + 8 = 19\n * (A_1, B_2, C_2): 4 + 5 + 8 = 17\n * (A_2, B_1, C_2): 6 + 1 + 8 = 15\n * (A_2, B_2, C_1): 6 + 5 + 3 = 14\n * (A_1, B_1, C_2): 4 + 1 + 8 = 13\n * (A_1, B_2, C_1): 4 + 5 + 3 = 12\n * (A_2, B_1, C_1): 6 + 1 + 3 = 10\n * (A_1, B_1, C_1): 4 + 1 + 3 = 8\n\n* * *"}, {"input": "3 3 3 5\n 1 10 100\n 2 20 200\n 1 10 100", "output": "400\n 310\n 310\n 301\n 301\n \n\nThere may be multiple combinations of cakes with the same sum of the\ndeliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and\nthe sum of A_3, B_3, C_1 are both 301. However, they are different ways of\nchoosing cakes, so 301 occurs twice in the output.\n\n* * *"}, {"input": "10 10 10 20\n 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736", "output": "23379871545\n 22444657051\n 22302177772\n 22095691512\n 21667941469\n 21366963278\n 21287912315\n 21279176669\n 21160477018\n 21085311041\n 21059876163\n 21017997739\n 20703329561\n 20702387965\n 20590247696\n 20383761436\n 20343962175\n 20254073196\n 20210218542\n 20150096547\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print N real numbers. The i-th real number must represent the probability that
Snuke falls into the i-th hole.
The output will be judged correct when, for all output values, the absolute or
relative error is at most 10^{-5}.
* * * | s924274494 | Accepted | p03428 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | import math
from copy import deepcopy
import sys
input = sys.stdin.readline
class Vec:
def __init__(self, x, y):
self.x = x
self.y = y
def __str__(self):
return "({}, {})".format(self.x, self.y)
def __add__(self, other):
return Vec(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return Vec(self.x - other.x, self.y - other.y)
def __mul__(self, k):
return Vec(self.x * k, self.y * k)
def __truediv__(self, k):
return Vec(self.x / k, self.y / k)
def __neg__(self):
return Vec(-self.x, -self.y)
def __eq__(self, other):
return self.x == other.x and self.y == other.y
def __ne__(self, other):
return not (self == other)
def abs(self):
return (self.x**2 + self.y**2) ** 0.5
def dot(self, other):
return self.x * other.x + self.y * other.y
def cross(self, other):
return self.x * other.y - self.y * other.x
def rot(self, ang):
c = math.cos(ang)
s = math.sin(ang)
return Vec(c * self.x - s * self.y, s * self.x + c * self.y)
def arg(self):
return math.atan2(self.y, self.x)
def convex_hull(points, eps=1e-12):
n = len(points)
points.sort(key=lambda p: (p.x, p.y))
k = 0 # # of vertices in the convex hull
ch = [None] * (2 * n)
# bottom
for i in range(n):
while k > 1 and (ch[k - 1] - ch[k - 2]).cross(points[i] - ch[k - 1]) < eps:
k -= 1
ch[k] = points[i]
k += 1
t = k
# top
for i in range(0, n - 1)[::-1]:
while k > t and (ch[k - 1] - ch[k - 2]).cross(points[i] - ch[k - 1]) < eps:
k -= 1
ch[k] = points[i]
k += 1
return ch[: k - 1]
N = int(input())
points = [Vec(*map(int, input().split())) for _ in range(N)]
tmp = deepcopy(points)
ch = convex_hull(tmp)
ch.sort(key=lambda v: v.arg())
ans = [0] * N
for i in range(len(ch)):
p0 = ch[(i - 1) % len(ch)]
p1 = ch[i]
p2 = ch[(i + 1) % len(ch)]
a = (p2 - p1).arg() - (p1 - p0).arg()
if a < 0:
a += 2 * math.pi
for j in range(N):
if p1 == points[j]:
ans[j] = a / (2 * math.pi)
print(*ans, sep="\n")
| Statement
There are N holes in a two-dimensional plane. The coordinates of the i-th hole
are (x_i,y_i).
Let R=10^{10^{10^{10}}}. Ringo performs the following operation:
* Randomly choose a point from the interior of a circle of radius R centered at the origin, and put Snuke there. Snuke will move to the hole with the smallest Euclidean distance from the point, and fall into that hole. If there are multiple such holes, the hole with the smallest index will be chosen.
For every i (1 \leq i \leq N), find the probability that Snuke falls into the
i-th hole.
Here, the operation of randomly choosing a point from the interior of a circle
of radius R is defined as follows:
* Pick two real numbers x and y independently according to uniform distribution on [-R,R].
* If x^2+y^2\leq R^2, the point (x,y) is chosen. Otherwise, repeat picking the real numbers x,y until the condition is met. | [{"input": "2\n 0 0\n 1 1", "output": "0.5\n 0.5\n \n\nIf Ringo put Snuke in the region x+y\\leq 1, Snuke will fall into the first\nhole. The probability of this happening is very close to 0.5. Otherwise, Snuke\nwill fall into the second hole, the probability of which happening is also\nvery close to 0.5.\n\n* * *"}, {"input": "5\n 0 0\n 2 8\n 4 5\n 2 6\n 3 10", "output": "0.43160120892732328768\n 0.03480224363653196956\n 0.13880483535586193855\n 0.00000000000000000000\n 0.39479171208028279727"}] |
Print N real numbers. The i-th real number must represent the probability that
Snuke falls into the i-th hole.
The output will be judged correct when, for all output values, the absolute or
relative error is at most 10^{-5}.
* * * | s175536044 | Accepted | p03428 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | #! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
"""
AGC021 B
"""
import math
from collections import defaultdict
n = int(input())
ps = [tuple(map(int, input().split())) for i in range(n)]
def dist(rad, p):
radtmp = 2 * math.pi * rad / maxcut
return -p[0] * math.cos(radtmp) - p[1] * math.sin(radtmp)
def closest(rad):
tmp = dist(rad, ps[0])
itmp = 0
for i, pp in enumerate(ps):
tmp2 = dist(rad, pp)
if tmp2 < tmp:
itmp = i
tmp = tmp2
return itmp
maxcut = 2**20
binary = defaultdict(int)
binary[0] = closest(0)
binary[maxcut] = binary[0]
binary[maxcut // 2] = closest(maxcut // 2)
binary[maxcut // 4] = closest(maxcut // 4)
binary[3 * maxcut // 4] = closest(3 * maxcut // 4)
def fillbinary(ll, rr):
if binary[ll] != binary[rr] and rr - ll != 1:
mm = (ll + rr) // 2
binary[mm] = closest(mm)
fillbinary(ll, mm)
fillbinary(mm, rr)
fillbinary(0, maxcut // 4)
fillbinary(maxcut // 4, maxcut // 2)
fillbinary(maxcut // 2, 3 * maxcut // 4)
fillbinary(3 * maxcut // 4, maxcut)
binkeys = sorted(binary.keys())
ansli = [0] * n
beforekey = 0
for i in binkeys:
ansli[binary[i]] += i - beforekey
beforekey = i
for i in range(n):
print(ansli[i] / maxcut)
| Statement
There are N holes in a two-dimensional plane. The coordinates of the i-th hole
are (x_i,y_i).
Let R=10^{10^{10^{10}}}. Ringo performs the following operation:
* Randomly choose a point from the interior of a circle of radius R centered at the origin, and put Snuke there. Snuke will move to the hole with the smallest Euclidean distance from the point, and fall into that hole. If there are multiple such holes, the hole with the smallest index will be chosen.
For every i (1 \leq i \leq N), find the probability that Snuke falls into the
i-th hole.
Here, the operation of randomly choosing a point from the interior of a circle
of radius R is defined as follows:
* Pick two real numbers x and y independently according to uniform distribution on [-R,R].
* If x^2+y^2\leq R^2, the point (x,y) is chosen. Otherwise, repeat picking the real numbers x,y until the condition is met. | [{"input": "2\n 0 0\n 1 1", "output": "0.5\n 0.5\n \n\nIf Ringo put Snuke in the region x+y\\leq 1, Snuke will fall into the first\nhole. The probability of this happening is very close to 0.5. Otherwise, Snuke\nwill fall into the second hole, the probability of which happening is also\nvery close to 0.5.\n\n* * *"}, {"input": "5\n 0 0\n 2 8\n 4 5\n 2 6\n 3 10", "output": "0.43160120892732328768\n 0.03480224363653196956\n 0.13880483535586193855\n 0.00000000000000000000\n 0.39479171208028279727"}] |
Print N real numbers. The i-th real number must represent the probability that
Snuke falls into the i-th hole.
The output will be judged correct when, for all output values, the absolute or
relative error is at most 10^{-5}.
* * * | s449627150 | Wrong Answer | p03428 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | import sys
input = sys.stdin.readline
import numpy as np
from numpy import pi
N = int(input())
X, Y = np.array([input().split() for _ in range(N)], dtype=np.float64).T
# ひとつずつ計算する。垂直二等分線のどっちか側。
# 半平面の共通部分
def solve(i):
Xother = np.delete(X, i)
Yother = np.delete(Y, i)
angle = np.arctan2(Y[i] - Yother, X[i] - Xother) # 半平面の中心線
# 下半平面との共通部分、主値で持つ
case1 = angle <= -pi / 2
case2 = (-pi / 2 <= angle) & (angle <= pi / 2)
case3 = pi / 2 <= angle
lower_left = np.zeros_like(angle)
lower_left[case1] = -pi
lower_left[case2] = angle[case2] - pi / 2
lower_left[case3] = -pi / 2
lower_right = np.zeros_like(angle)
lower_right[case1] = angle[case1] + pi / 2
lower_right[case2] = 0
lower_right[case3] = angle[case3] + pi / 2 - 2 * pi
upper_left = np.zeros_like(angle)
upper_left[case1] = angle[case1] + 3 * pi / 2
upper_left[case2] = 0
upper_left[case3] = angle[case3] - pi / 2
upper_right = np.zeros_like(angle)
upper_right[case1] = pi
upper_right[case2] = angle[case2] + pi / 2
upper_right[case3] = pi
p_upper = max(0, upper_right.min() - upper_left.max()) / (2 * pi)
p_lower = max(0, lower_right.min() - lower_left.max()) / (2 * pi)
return p_upper + p_lower
answer = [solve(i) for i in range(N)]
print(*answer, sep="\n")
| Statement
There are N holes in a two-dimensional plane. The coordinates of the i-th hole
are (x_i,y_i).
Let R=10^{10^{10^{10}}}. Ringo performs the following operation:
* Randomly choose a point from the interior of a circle of radius R centered at the origin, and put Snuke there. Snuke will move to the hole with the smallest Euclidean distance from the point, and fall into that hole. If there are multiple such holes, the hole with the smallest index will be chosen.
For every i (1 \leq i \leq N), find the probability that Snuke falls into the
i-th hole.
Here, the operation of randomly choosing a point from the interior of a circle
of radius R is defined as follows:
* Pick two real numbers x and y independently according to uniform distribution on [-R,R].
* If x^2+y^2\leq R^2, the point (x,y) is chosen. Otherwise, repeat picking the real numbers x,y until the condition is met. | [{"input": "2\n 0 0\n 1 1", "output": "0.5\n 0.5\n \n\nIf Ringo put Snuke in the region x+y\\leq 1, Snuke will fall into the first\nhole. The probability of this happening is very close to 0.5. Otherwise, Snuke\nwill fall into the second hole, the probability of which happening is also\nvery close to 0.5.\n\n* * *"}, {"input": "5\n 0 0\n 2 8\n 4 5\n 2 6\n 3 10", "output": "0.43160120892732328768\n 0.03480224363653196956\n 0.13880483535586193855\n 0.00000000000000000000\n 0.39479171208028279727"}] |
Print N real numbers. The i-th real number must represent the probability that
Snuke falls into the i-th hole.
The output will be judged correct when, for all output values, the absolute or
relative error is at most 10^{-5}.
* * * | s213576929 | Accepted | p03428 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | import math
from collections import defaultdict
n = int(input())
ipt = [list(map(int, input().split())) for i in range(n)]
xy = sorted(ipt)
convh1 = [xy[0], xy[1]]
def slope(xy1, xy2, const=1):
x1, y1 = xy1
x2, y2 = xy2
dx, dy = x2 - x1, y2 - y1
if dx == 0:
return 10**18 * (y2 - y1) * const // abs(y2 - y1)
else:
return dy / dx
def convex(xy1, xy2, xy3, const=1):
x1, y1 = xy1
x2, y2 = xy2
x3, y3 = xy3
if slope([x1, y1], [x2, y2], const) < slope([x2, y2], [x3, y3], const):
return True
return False
for i in range(2, n):
x, y = xy[i]
while len(convh1) >= 2 and not convex(convh1[-2], convh1[-1], [x, y]):
convh1.pop()
convh1.append(xy[i])
convh2 = [xy[-1], xy[-2]]
for i in range(n - 2)[::-1]:
x, y = xy[i]
while len(convh2) >= 2 and not convex(convh2[-2], convh2[-1], [x, y], -1):
convh2.pop()
convh2.append(xy[i])
convh = convh1 + convh2[1:-1]
prob = [0 for i in convh]
dc = defaultdict(int)
for i, xy in enumerate(convh):
x, y = xy
px, py = convh[i - 1]
nx, ny = convh[(i + 1) % len(convh)]
px -= x
py -= y
nx -= x
ny -= y
rad = math.atan2(ny, nx) - math.atan2(py, px)
dc[(x, y)] = (math.pi - min(abs(rad), 2 * math.pi - abs(rad))) / (2 * math.pi)
for x, y in ipt:
print(dc[(x, y)])
| Statement
There are N holes in a two-dimensional plane. The coordinates of the i-th hole
are (x_i,y_i).
Let R=10^{10^{10^{10}}}. Ringo performs the following operation:
* Randomly choose a point from the interior of a circle of radius R centered at the origin, and put Snuke there. Snuke will move to the hole with the smallest Euclidean distance from the point, and fall into that hole. If there are multiple such holes, the hole with the smallest index will be chosen.
For every i (1 \leq i \leq N), find the probability that Snuke falls into the
i-th hole.
Here, the operation of randomly choosing a point from the interior of a circle
of radius R is defined as follows:
* Pick two real numbers x and y independently according to uniform distribution on [-R,R].
* If x^2+y^2\leq R^2, the point (x,y) is chosen. Otherwise, repeat picking the real numbers x,y until the condition is met. | [{"input": "2\n 0 0\n 1 1", "output": "0.5\n 0.5\n \n\nIf Ringo put Snuke in the region x+y\\leq 1, Snuke will fall into the first\nhole. The probability of this happening is very close to 0.5. Otherwise, Snuke\nwill fall into the second hole, the probability of which happening is also\nvery close to 0.5.\n\n* * *"}, {"input": "5\n 0 0\n 2 8\n 4 5\n 2 6\n 3 10", "output": "0.43160120892732328768\n 0.03480224363653196956\n 0.13880483535586193855\n 0.00000000000000000000\n 0.39479171208028279727"}] |
Print N real numbers. The i-th real number must represent the probability that
Snuke falls into the i-th hole.
The output will be judged correct when, for all output values, the absolute or
relative error is at most 10^{-5}.
* * * | s590585541 | Wrong Answer | p03428 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | N = input()
print(int(N[0]) - 1 + 9 * (len(N) - 1))
| Statement
There are N holes in a two-dimensional plane. The coordinates of the i-th hole
are (x_i,y_i).
Let R=10^{10^{10^{10}}}. Ringo performs the following operation:
* Randomly choose a point from the interior of a circle of radius R centered at the origin, and put Snuke there. Snuke will move to the hole with the smallest Euclidean distance from the point, and fall into that hole. If there are multiple such holes, the hole with the smallest index will be chosen.
For every i (1 \leq i \leq N), find the probability that Snuke falls into the
i-th hole.
Here, the operation of randomly choosing a point from the interior of a circle
of radius R is defined as follows:
* Pick two real numbers x and y independently according to uniform distribution on [-R,R].
* If x^2+y^2\leq R^2, the point (x,y) is chosen. Otherwise, repeat picking the real numbers x,y until the condition is met. | [{"input": "2\n 0 0\n 1 1", "output": "0.5\n 0.5\n \n\nIf Ringo put Snuke in the region x+y\\leq 1, Snuke will fall into the first\nhole. The probability of this happening is very close to 0.5. Otherwise, Snuke\nwill fall into the second hole, the probability of which happening is also\nvery close to 0.5.\n\n* * *"}, {"input": "5\n 0 0\n 2 8\n 4 5\n 2 6\n 3 10", "output": "0.43160120892732328768\n 0.03480224363653196956\n 0.13880483535586193855\n 0.00000000000000000000\n 0.39479171208028279727"}] |
Print N real numbers. The i-th real number must represent the probability that
Snuke falls into the i-th hole.
The output will be judged correct when, for all output values, the absolute or
relative error is at most 10^{-5}.
* * * | s317885073 | Wrong Answer | p03428 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | n = int(input())
for i in range(n):
print("nan")
| Statement
There are N holes in a two-dimensional plane. The coordinates of the i-th hole
are (x_i,y_i).
Let R=10^{10^{10^{10}}}. Ringo performs the following operation:
* Randomly choose a point from the interior of a circle of radius R centered at the origin, and put Snuke there. Snuke will move to the hole with the smallest Euclidean distance from the point, and fall into that hole. If there are multiple such holes, the hole with the smallest index will be chosen.
For every i (1 \leq i \leq N), find the probability that Snuke falls into the
i-th hole.
Here, the operation of randomly choosing a point from the interior of a circle
of radius R is defined as follows:
* Pick two real numbers x and y independently according to uniform distribution on [-R,R].
* If x^2+y^2\leq R^2, the point (x,y) is chosen. Otherwise, repeat picking the real numbers x,y until the condition is met. | [{"input": "2\n 0 0\n 1 1", "output": "0.5\n 0.5\n \n\nIf Ringo put Snuke in the region x+y\\leq 1, Snuke will fall into the first\nhole. The probability of this happening is very close to 0.5. Otherwise, Snuke\nwill fall into the second hole, the probability of which happening is also\nvery close to 0.5.\n\n* * *"}, {"input": "5\n 0 0\n 2 8\n 4 5\n 2 6\n 3 10", "output": "0.43160120892732328768\n 0.03480224363653196956\n 0.13880483535586193855\n 0.00000000000000000000\n 0.39479171208028279727"}] |
Print N real numbers. The i-th real number must represent the probability that
Snuke falls into the i-th hole.
The output will be judged correct when, for all output values, the absolute or
relative error is at most 10^{-5}.
* * * | s862423164 | Runtime Error | p03428 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | package main
import (
"bufio"
"os"
"strconv"
"strings"
"fmt"
"math"
)
var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
buffer := make([]byte, 0)
for true {
line, isPrefix, err := reader.ReadLine()
if err != nil { panic(err) }
buffer = append(buffer, line...)
if !isPrefix { break }
}
return string(buffer)
}
func NextInt() int {
n, _ := strconv.Atoi(NextLine())
return n
}
func NextFloatVec() []float64 {
L := strings.Split(NextLine(), " ")
N := make([]float64, len(L))
for i := range N {
N[i], _ = strconv.ParseFloat(L[i], 64)
}
return N
}
func Write(s interface{}) {
fmt.Fprintln(writer, s)
}
func Output() {
_ = writer.Flush()
}
func Dist(mode int, A ...*[]float64) float64 {
if len(A) < 1 { return 0.0 }
if len(A) < 2 { A = append(A, &[]float64{0.0, 0.0}) }
D := 0.0
for i := range (*A[0]) {
x := (*A[0])[i] - (*A[1])[i]
D += x * x
}
if mode == 1 { D = math.Sqrt(D) }
return D
}
func InnerProduct(A, B *[]float64) float64 {
IP := 0.0
for i, a := range (*A) {
IP += a * (*B)[i]
}
return IP
}
func Angle(A ...*[]float64) float64 {
if len(A) < 2 { return 0.0 }
if len(A) < 3 {
a := make([]float64, len((*A[0])))
A = append(A, &a)
}
_A := make([]float64, len((*A[0])))
_B := make([]float64, len((*A[0])))
for i := range (*A[0]) {
_A[i] = (*A[0])[i] - (*A[2])[i]
_B[i] = (*A[1])[i] - (*A[2])[i]
}
acos := math.Acos(InnerProduct(&_A, &_B) / Dist(1, &_A) / Dist(1, &_B))
theta := acos / math.Pi * 180.0
_A_ := []float64{-_A[1], _A[0]}
if InnerProduct(&_A_, &_B) < 0 { theta = 360 - theta }
return theta
}
func TriangleArea(mode int, A ...*[]float64) float64 {
if len(A) < 2 { return 0.0 }
if len(A) < 3 {
_A := make([]*[]float64, 0)
a := make([]float64, len((*A[0])))
_A = append(_A, &a)
A = append(_A, A...)
}
AB := []float64{(*A[1])[0] - (*A[0])[0], (*A[1])[1] - (*A[0])[1]}
AC := []float64{(*A[2])[0] - (*A[0])[0], (*A[2])[1] - (*A[0])[1]}
S := math.Abs(AB[0] * AC[1] - AB[1] * AC[0])
if mode == 1 { S /= 2.0 }
return S
}
func OuterCircle(A, B, C *[]float64) (X, Y, R float64) {
AB := []float64{(*B)[0] - (*A)[0], (*B)[1] - (*A)[1]}
AC := []float64{(*C)[0] - (*A)[0], (*C)[1] - (*A)[1]}
AB2 := Dist(2, &AB)
AC2 := Dist(2, &AC)
IP := InnerProduct(&AB, &AC)
b := AC2 * (IP - AB2) / (2 * (IP * IP - AB2 * AC2))
c := AB2 * (IP - AC2) / (2 * (IP * IP - AB2 * AC2))
X = (*A)[0] + AB[0] * b + AC[0] * c
Y = (*A)[1] + AB[1] * b + AC[1] * c
S := TriangleArea(1, A, B, C)
ab := math.Sqrt(AB2)
bc := Dist(1, B, C)
ca := math.Sqrt(AC2)
R = ab * bc * ca / (4 * S)
return
}
func Less(A *[][]float64, i, j int) bool {
if (*A)[i][0] == (*A)[j][0] { return (*A)[i][1] < (*A)[j][1] }
return (*A)[i][0] < (*A)[j][0]
}
func Convex(A *[][]float64) []int {
C := make([]int, 0)
h := 0
for i := range (*A) {
if Less(A, h, i) { h = i }
}
next := h
for len(C) == 0 || next != h {
C = append(C, next)
p := (*A)[next]
for i, a := range (*A) {
if i == next { continue }
_A := []float64{a[0] - p[0], a[1] - p[1]}
D1 := Dist(2, &a, &p)
convex := true
for j, b := range (*A) {
if j == next || j == i { continue }
_B := []float64{b[0] - p[0], b[1] - p[1]}
D2 := Dist(2, &b, &p)
OP := _A[0] * _B[1] - _A[1] * _B[0]
if math.Abs(OP) < 1e-5 {
if D2 < D1 { continue }
} else if OP < 0.0 {
continue
}
convex = false
break
}
if !convex { continue }
next = i
break
}
}
return C
}
func Solve() {
N := NextInt()
A := make([][]float64, N)
for i := range A {
A[i] = NextFloatVec()
}
C := Convex(&A)
C = append(C, C...)
R := make([]float64, N)
for i := 0; i < len(C) / 2; i++ {
if C[i] == C[i + 2] {
R[C[i + 1]] = 180.0
continue
}
x, y, _ := OuterCircle(&A[C[i]], &A[C[i + 1]], &A[C[i + 2]])
_A := []float64{A[C[i + 2]][0] - x, A[C[i + 2]][1] - y}
_B := []float64{A[C[i]][0] - x, A[C[i]][1] - y}
theta := Angle(&_A, &_B)
R[C[i + 1]] = theta / 2.0
}
for _, r := range R {
Write(r / 360.0)
}
return
}
func main() {
Solve()
Output()
} | Statement
There are N holes in a two-dimensional plane. The coordinates of the i-th hole
are (x_i,y_i).
Let R=10^{10^{10^{10}}}. Ringo performs the following operation:
* Randomly choose a point from the interior of a circle of radius R centered at the origin, and put Snuke there. Snuke will move to the hole with the smallest Euclidean distance from the point, and fall into that hole. If there are multiple such holes, the hole with the smallest index will be chosen.
For every i (1 \leq i \leq N), find the probability that Snuke falls into the
i-th hole.
Here, the operation of randomly choosing a point from the interior of a circle
of radius R is defined as follows:
* Pick two real numbers x and y independently according to uniform distribution on [-R,R].
* If x^2+y^2\leq R^2, the point (x,y) is chosen. Otherwise, repeat picking the real numbers x,y until the condition is met. | [{"input": "2\n 0 0\n 1 1", "output": "0.5\n 0.5\n \n\nIf Ringo put Snuke in the region x+y\\leq 1, Snuke will fall into the first\nhole. The probability of this happening is very close to 0.5. Otherwise, Snuke\nwill fall into the second hole, the probability of which happening is also\nvery close to 0.5.\n\n* * *"}, {"input": "5\n 0 0\n 2 8\n 4 5\n 2 6\n 3 10", "output": "0.43160120892732328768\n 0.03480224363653196956\n 0.13880483535586193855\n 0.00000000000000000000\n 0.39479171208028279727"}] |
Print N real numbers. The i-th real number must represent the probability that
Snuke falls into the i-th hole.
The output will be judged correct when, for all output values, the absolute or
relative error is at most 10^{-5}.
* * * | s919318781 | Accepted | p03428 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | import math
N = int(input())
ps = []
for i in range(N):
x, y = map(int, input().split())
ps.append((x, y, i))
ps.sort()
# i -> j のベクトル
def vec(pi, pj):
return (pj[0] - pi[0], pj[1] - pi[1])
# i -> j 向きの外積
def det(vi, vj):
return vi[0] * vj[1] - vi[1] * vj[0]
# 凸包を求める
cvx = []
for i in list(range(N)) + list(range(N - 1))[::-1]:
while (
len(cvx) >= 2
and det(vec(ps[cvx[-2]], ps[cvx[-1]]), vec(ps[cvx[-1]], ps[i])) < 0
):
cvx.pop()
cvx.append(i)
# 凸包の各頂点について、頂点から出る2辺のなす角を計算
ans = {}
pi = None
for i in cvx:
x, y, j = ps[i]
if pi is not None:
px, py, pj = ps[pi]
slope = math.atan2(y - py, x - px)
if j not in ans:
ans[j] = [0, 0]
if pj not in ans:
ans[pj] = [0, 0]
ans[j][0] = slope
ans[pj][1] = slope
pi = i
for i in range(N):
if i not in ans:
print(0)
continue
v1, v2 = ans[i]
if v2 < v1:
v2 += 2 * math.pi
print(round((v2 - v1) / (2 * math.pi), 8))
| Statement
There are N holes in a two-dimensional plane. The coordinates of the i-th hole
are (x_i,y_i).
Let R=10^{10^{10^{10}}}. Ringo performs the following operation:
* Randomly choose a point from the interior of a circle of radius R centered at the origin, and put Snuke there. Snuke will move to the hole with the smallest Euclidean distance from the point, and fall into that hole. If there are multiple such holes, the hole with the smallest index will be chosen.
For every i (1 \leq i \leq N), find the probability that Snuke falls into the
i-th hole.
Here, the operation of randomly choosing a point from the interior of a circle
of radius R is defined as follows:
* Pick two real numbers x and y independently according to uniform distribution on [-R,R].
* If x^2+y^2\leq R^2, the point (x,y) is chosen. Otherwise, repeat picking the real numbers x,y until the condition is met. | [{"input": "2\n 0 0\n 1 1", "output": "0.5\n 0.5\n \n\nIf Ringo put Snuke in the region x+y\\leq 1, Snuke will fall into the first\nhole. The probability of this happening is very close to 0.5. Otherwise, Snuke\nwill fall into the second hole, the probability of which happening is also\nvery close to 0.5.\n\n* * *"}, {"input": "5\n 0 0\n 2 8\n 4 5\n 2 6\n 3 10", "output": "0.43160120892732328768\n 0.03480224363653196956\n 0.13880483535586193855\n 0.00000000000000000000\n 0.39479171208028279727"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s354019440 | Accepted | p02393 | Three integers separated by a single space are given in a line. | x = []
x = input().split()
x[0], x[1], x[2] = int(x[0]), int(x[1]), int(x[2])
if x[0] > x[1]:
a = x[0]
x[0] = x[1]
x[1] = a
if x[1] > x[2]:
a = x[2]
x[2] = x[1]
x[1] = a
if x[0] > x[1]:
a = x[0]
x[0] = x[1]
x[1] = a
print(str(x[0]), str(x[1]), str(x[2]))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s725400394 | Accepted | p02393 | Three integers separated by a single space are given in a line. | x = list(map(int, input().split()))
if x[0] > x[1]:
x[0], x[1] = x[1], x[0]
if x[1] > x[2]:
x[1], x[2] = x[2], x[1]
if x[0] > x[1]:
x[0], x[1] = x[1], x[0]
print(*x)
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s360111724 | Accepted | p02393 | Three integers separated by a single space are given in a line. | inputDataList = input().split()
outputDataList = []
for i in inputDataList:
outputDataList.append(int(i))
outputDataList.sort()
print("{} {} {}".format(outputDataList[0], outputDataList[1], outputDataList[2]))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s732977381 | Wrong Answer | p02393 | Three integers separated by a single space are given in a line. | table = list(map(int, input().split()))
i = 2
k = 0
while k < i:
if table[k] > table[k + 1]:
table[k], table[k + 1] = table[k + 1], table[k]
k += 1
print(table[0], table[1], table[2])
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s755877217 | Accepted | p02393 | Three integers separated by a single space are given in a line. | data1 = list(int(i) for i in input().split())
data1.sort()
data2 = map(str, data1)
data3 = " ".join(data2)
print(data3)
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s104161620 | Accepted | p02393 | Three integers separated by a single space are given in a line. | line = (int(x) for x in input().split())
# 3つの数の整列
hoge = sorted(line)
print(hoge[0], hoge[1], hoge[2], end="\n")
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s403035206 | Accepted | p02393 | Three integers separated by a single space are given in a line. | [a, b, c] = (int(x) for x in input().split())
y = sorted([a, b, c])
print(*y)
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s048516526 | Accepted | p02393 | Three integers separated by a single space are given in a line. | a = sorted([int(x) for x in input().split(" ")])
a = [str(x) for x in a]
print(" ".join(a))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s861900058 | Accepted | p02393 | Three integers separated by a single space are given in a line. | s = [int(i) for i in input().split()]
s = sorted(s)
s = [str(i) for i in s]
print(" ".join(s))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s350181937 | Accepted | p02393 | Three integers separated by a single space are given in a line. | l = input().split()
li = list(map(int, l))
num = len(li)
for i in range(num - 1):
if li[i] > li[i + 1]:
t = li[i]
li[i] = li[i + 1]
li[i + 1] = t
if li[0] > li[1]:
t = li[0]
li[0] = li[1]
li[1] = t
a, b, c = li
print(a, b, c)
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s994040096 | Accepted | p02393 | Three integers separated by a single space are given in a line. | base = input("")
term = base.split(" ")
sort_list = [int(term[0]), int(term[1]), int(term[2])]
sort_list.sort()
print("{} {} {}".format(sort_list[0], sort_list[1], sort_list[2]))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s827003270 | Wrong Answer | p02393 | Three integers separated by a single space are given in a line. | nums = [int(e) for e in input().split()]
for i in range(len(nums)):
for j in range(i):
if nums[i] < nums[j]:
a = nums[i]
nums[i] = nums[j]
nums[j] = a
print(nums)
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s449591354 | Accepted | p02393 | Three integers separated by a single space are given in a line. | l = sorted(list(map(int, input().split())))
for i in range(len(l) - 1):
print(l[i], end=" ")
print(l[-1])
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s773365081 | Wrong Answer | p02393 | Three integers separated by a single space are given in a line. | lis = [int(x) for x in input().split()]
lis.sort(reverse=True)
for i in range(2):
print(lis[i], end=" ")
print(lis[-1])
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s460378939 | Accepted | p02393 | Three integers separated by a single space are given in a line. | In = list(map(int, input().split()))
In.sort()
print(In[0], In[1], In[2])
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s123533484 | Accepted | p02393 | Three integers separated by a single space are given in a line. | print(*sorted([int(a) for a in input().split()]))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s112763827 | Accepted | p02393 | Three integers separated by a single space are given in a line. | print(*sorted([int(n) for n in input().split()]))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s978846727 | Accepted | p02393 | Three integers separated by a single space are given in a line. | print(*sorted(int(x) for x in input().split()))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s136179065 | Accepted | p02393 | Three integers separated by a single space are given in a line. | print(*sorted([int(_) for _ in input().split()]))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s039020618 | Wrong Answer | p02393 | Three integers separated by a single space are given in a line. | print(sorted([int(i) for i in input().split()]))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s737738289 | Accepted | p02393 | Three integers separated by a single space are given in a line. | a = input().split(" ")
temp = a[0]
if a[0] > a[1]:
temp = a[1]
a[1] = a[0]
a[0] = temp
if a[1] > a[2]:
temp = a[2]
a[2] = a[1]
a[1] = temp
if a[0] > a[1]:
temp = a[1]
a[1] = a[0]
a[0] = temp
print(str(a[0]) + " " + str(a[1]) + " " + str(a[2]))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s394862399 | Runtime Error | p02393 | Three integers separated by a single space are given in a line. | num = [int(i) for i in input().split()]
for i in range(len(num)):
for j in range(i + 1, len(num) + 1):
if num[i] > num[j]:
bigger = num[i]
num[i] = num[j]
num[j] = bigger
for i in range(len(num)):
print(num[i], end="")
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s909971964 | Accepted | p02393 | Three integers separated by a single space are given in a line. | target = list(map(int, input().split()))
target.sort()
target = list(map(str, target))
print(" ".join(target))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s846260451 | Accepted | p02393 | Three integers separated by a single space are given in a line. | num_list = list(input().split())
sorted_list = sorted(num_list)
answer = " ".join(sorted_list)
print(answer)
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s570872110 | Accepted | p02393 | Three integers separated by a single space are given in a line. | num_sorted = list(map(int, input().split()))
num_sorted.sort()
print("{} {} {}".format(num_sorted[0], num_sorted[1], num_sorted[2]))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s781159924 | Runtime Error | p02393 | Three integers separated by a single space are given in a line. | InData = input().split
Indata = map(int, InData)
sorted = sorted(InData)
print(" ".join(map(str, sorted)))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s128522998 | Runtime Error | p02393 | Three integers separated by a single space are given in a line. | d = input()
a, b, c = map(int, d.split())
e = [a, b, c]
e.sort()
print(e[0] + " " + e[1] + " " + e[2])
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s656428129 | Accepted | p02393 | Three integers separated by a single space are given in a line. | x, y, z = map(str, input().split())
p = [x, y, z]
p.sort()
print(" ".join(map(str, p)))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s164327355 | Accepted | p02393 | Three integers separated by a single space are given in a line. | num_list = sorted(list(map(int, input().split())))
print(*num_list, sep=" ")
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s537559794 | Accepted | p02393 | Three integers separated by a single space are given in a line. | li = map(int, input().split(" "))
sorted_list = sorted(li)
print(" ".join(map(str, sorted_list)))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s047814278 | Runtime Error | p02393 | Three integers separated by a single space are given in a line. | n = input().split()
m = int(n[0])
c = int(n[1])
d = int(n[2])
n.sort()
print(m[0], c[1], d[2])
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s141569153 | Runtime Error | p02393 | Three integers separated by a single space are given in a line. | inputlines = list(map(int, input().split()))
li = inputlines.sort()
print(" ".join(map(str, li)))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s120707339 | Runtime Error | p02393 | Three integers separated by a single space are given in a line. | sorted([int(x) for x in input().split()])
print(sorted[0] + " " + sorted[1] + " " + sorted[2])
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s603135306 | Accepted | p02393 | Three integers separated by a single space are given in a line. | X = sorted(list(map(int, input().split())))
print(X[0], X[1], X[2])
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s489590379 | Accepted | p02393 | Three integers separated by a single space are given in a line. | L = list(map(int, input().split()))
L.sort()
print(*L)
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s942420413 | Runtime Error | p02393 | Three integers separated by a single space are given in a line. | x = map(int, input().split())
print(" ".join(x.sort()))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s291723194 | Runtime Error | p02393 | Three integers separated by a single space are given in a line. | input()
print(*sorted(input().split()))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s999484835 | Accepted | p02393 | Three integers separated by a single space are given in a line. | inps = input().split()
lst = [int(i) for i in inps]
for idx in range(len(lst) - 1):
for idx_next in range(idx + 1, len(lst)):
if lst[idx] > lst[idx_next]:
tmp = lst[idx_next]
lst[idx_next] = lst[idx]
lst[idx] = tmp
print("{} {} {}".format(lst[0], lst[1], lst[2]))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s976981241 | Accepted | p02393 | Three integers separated by a single space are given in a line. | i = j = k = 0
n = ""
m = ""
l = ""
line = input()
while line[i] != " ":
n = n + line[i]
i += 1
i += 1
while line[i] != " ":
l = l + line[i]
i += 1
while i < len(line):
m = m + line[i]
i += 1
n = int(n)
l = int(l)
m = int(m)
min = n
if min > l:
min = l
if min > m:
min = m
max = n
if max < l:
max = l
if max < m:
max = m
if min < n < max:
cen = n
elif min < l < max:
cen = l
else:
cen = m
print(min, end=" ")
print(cen, end=" ")
print(max)
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s887552060 | Wrong Answer | p02393 | Three integers separated by a single space are given in a line. | a, b, c = input().split(" ")
if int(a) > int(b) > int(c):
print(int(c), int(b), int(a))
elif int(b) > int(c) > int(a):
print(int(a), int(c), int(b))
elif int(c) > int(a) > int(b):
print(int(b), int(a), int(c))
elif int(c) > int(b) > int(a):
print(int(a), int(b), int(c))
elif int(b) > int(a) > int(c):
print(int(c), int(a), int(b))
else:
print(int(b), int(c), int(a))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s628717383 | Accepted | p02393 | Three integers separated by a single space are given in a line. | # encoding:utf-8
input = list(map(int, input().split(" ")))
input.sort()
print(str(input[0]) + " " + str(input[1]) + " " + str(input[2]))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s383377079 | Accepted | p02393 | Three integers separated by a single space are given in a line. | al = list(map(int, input().split()))
al = sorted(al)
print(al[0], al[1], al[2])
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s571529191 | Accepted | p02393 | Three integers separated by a single space are given in a line. | t = list(map(int, input().split()))
t.sort()
print(" ".join(list(map(str, t))))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s396401959 | Accepted | p02393 | Three integers separated by a single space are given in a line. | print(" ".join([str(i) for i in sorted([int(w) for w in input().split()])]))
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Print the given integers in ascending order in a line. Put a single space
between two integers. | s684931212 | Accepted | p02393 | Three integers separated by a single space are given in a line. | memo = input().split()
[int(i) for i in memo]
memo.sort()
print(memo[0] + " " + memo[1] + " " + memo[2])
| Sorting Three Numbers
Write a program which reads three integers, and prints them in ascending
order. | [{"input": "3 8 1", "output": "1 3 8"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.