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 number of the positive divisors of N!, modulo 10^9+7. * * *
s594512805
Runtime Error
p03828
The input is given from Standard Input in the following format: N
# -*- coding:utf-8 -*- import math import sys def mark(s, x): for i in range(x + x, len(s), x): s[i] = False def sieve(n): s = [True] * n for x in range(2, int(n**0.5) + 1): if s[x]: mark(s, x) return [i for i in range(0,n) if s[i] and i > 1] n = int(input()) p = sieve(n) arr = [0]*len(p) n = math.factorial(n) for i in range(len(p)): flag = 1 k = p[i] while flag: if n%k == 0: k = k*p[i] arr[i] += 1 else: flag = 0 x = 1 for i in range(len(arr)): if arr[i] != 0: x *= (arr[i]+1) if ( n = 6): print(4) else: print(x%(10**9+7))
Statement You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
[{"input": "3", "output": "4\n \n\nThere are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.\n\n* * *"}, {"input": "6", "output": "30\n \n\n* * *"}, {"input": "1000", "output": "972926972"}]
Print the number of the positive divisors of N!, modulo 10^9+7. * * *
s718055542
Accepted
p03828
The input is given from Standard Input in the following format: N
n = int(input()) x, answer = [2], 1 if n != 1: for i in range(2, n + 1): if all(i % j != 0 for j in x): x.append(i) for i in x: num, num2 = 1, 0 while i**num <= n: a = i**num num2 += (n - n % a) // a num += 1 answer = answer * (num2 + 1) % (10**9 + 7) print(answer)
Statement You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
[{"input": "3", "output": "4\n \n\nThere are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.\n\n* * *"}, {"input": "6", "output": "30\n \n\n* * *"}, {"input": "1000", "output": "972926972"}]
Print the number of the positive divisors of N!, modulo 10^9+7. * * *
s983924653
Runtime Error
p03828
The input is given from Standard Input in the following format: N
a = int(input()) c = list(map(int, input().split())) su = sum(c) diff = 1e9 cc = 0 for x in range(a - 1): cc += c[x] diff = min(diff, abs(su - 2 * cc)) print(diff)
Statement You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
[{"input": "3", "output": "4\n \n\nThere are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.\n\n* * *"}, {"input": "6", "output": "30\n \n\n* * *"}, {"input": "1000", "output": "972926972"}]
Print the number of the positive divisors of N!, modulo 10^9+7. * * *
s691143865
Wrong Answer
p03828
The input is given from Standard Input in the following format: N
n = int(input()) print(n % (10**9 + 7))
Statement You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
[{"input": "3", "output": "4\n \n\nThere are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.\n\n* * *"}, {"input": "6", "output": "30\n \n\n* * *"}, {"input": "1000", "output": "972926972"}]
Print the number of the positive divisors of N!, modulo 10^9+7. * * *
s418725725
Runtime Error
p03828
The input is given from Standard Input in the following format: N
import sympy
Statement You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
[{"input": "3", "output": "4\n \n\nThere are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.\n\n* * *"}, {"input": "6", "output": "30\n \n\n* * *"}, {"input": "1000", "output": "972926972"}]
Print the number of the positive divisors of N!, modulo 10^9+7. * * *
s666636892
Runtime Error
p03828
The input is given from Standard Input in the following format: N
n, k = map(int, input().split()) d = [] for _ in range(n): d.append(list(map(int, input().split()))) d.sort(key=lambda x: x[0]) count = 0 for x, y in d: count += y if count >= k: break print(x)
Statement You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
[{"input": "3", "output": "4\n \n\nThere are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.\n\n* * *"}, {"input": "6", "output": "30\n \n\n* * *"}, {"input": "1000", "output": "972926972"}]
For each dataset, write a line that contains an expected value. You may print any number of digits after the decimal point. Answers that have an error less than 1.0e-2 will be accepted.
s096358513
Runtime Error
p00642
Input consists of several datasets. Input for a single dataset is given as a single integer _n_. Input terminates with a dataset where _n_ = 0.
code = """ #include <bits/stdc++.h> using namespace std; #define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl #define repi(i,a,b) for(int i=int(a);i<int(b);i++) #define peri(i,a,b) for(int i=int(b);i-->int(a);) #define rep(i,n) repi(i,0,n) #define per(i,n) peri(i,0,n) #define all(c) begin(c),end(c) #define mp make_pair #define mt make_tuple typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<string> vs; template<typename T1,typename T2> ostream& operator<<(ostream& os,const pair<T1,T2>& p){ return os<<'('<<p.first<<','<<p.second<<')'; } template<typename Tuple> void print_tuple(ostream&,const Tuple&){} template<typename Car,typename... Cdr,typename Tuple> void print_tuple(ostream& os,const Tuple& t){ print_tuple<Cdr...>(os,t); os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t); } template<typename... Args> ostream& operator<<(ostream& os,const tuple<Args...>& t){ print_tuple<Args...>(os<<'(',t); return os<<')'; } template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))> basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){ os<<'['; for(auto i=begin(c);i!=end(c);++i) os<<(i==begin(c)?"":" ")<<*i; return os<<']'; } constexpr int INF=1e9; constexpr int MOD=1e9+7; constexpr double EPS=1e-9; int main() { for(int n;cin>>n && n;){ map<pii,double> dp; dp[mp(0,0)]=1; rep(_,n){ map<pii,double> dp2; for(auto p:dp){ if(p.second<1e-6) continue; int cnt,cur; tie(cnt,cur)=p.first; dp2[mp(cnt+1,cur+1)]+=p.second*1./(1<<cur); dp2[mp(cnt,0)]+=p.second*(1-1./(1<<cur)); } swap(dp,dp2); } double res=0; for(auto p:dp) res+=p.first.first*p.second; printf("%.8f",res); puts(""); } } """ import os, tempfile (_, filename) = tempfile.mkstemp(".cpp") f = open(filename, "w") f.write(code) f.close() os.system("g++ -std=c++11 {} -o ./a.out".format(filename)) os.system("./a.out")
F: Ben Toh As usual, those who called wolves get together on 8 p.m. at the supermarket. The thing they want is only one, a box lunch that is labeled half price. Scrambling for a few discounted box lunch, they fiercely fight every day. And those who are blessed by hunger and appetite the best can acquire the box lunch, while others have to have cup ramen or something with tear in their eyes. A senior high school student, Sato, is one of wolves. A dormitry he lives doesn't serve a dinner, and his parents don't send so much money. Therefore he absolutely acquire the half-priced box lunch and save his money. Otherwise he have to give up comic books and video games, or begin part-time job. Since Sato is an excellent wolf, he can acquire the discounted box lunch in 100% probability on the first day. But on the next day, many other wolves cooperate to block him and the probability to get a box lunch will be 50%. Even though he can get, the probability to get will be 25% on the next day of the day. Likewise, if he gets a box lunch on a certain day, the probability to get on the next day will be half. Once he failed to get a box lunch, probability to get would be back to 100%. He continue to go to supermaket and try to get the discounted box lunch for _n_ days. Please write a program to computes the expected value of the number of the discounted box lunches he can acquire.
[{"input": "2\n 3\n 0", "output": ".00000000\n 1.50000000\n 2.12500000"}]
For each dataset, write a line that contains an expected value. You may print any number of digits after the decimal point. Answers that have an error less than 1.0e-2 will be accepted.
s798144363
Wrong Answer
p00642
Input consists of several datasets. Input for a single dataset is given as a single integer _n_. Input terminates with a dataset where _n_ = 0.
# -*- coding: utf-8 -*- days = [] day = int(input()) while day != 0: days.append(day) day = int(input()) max_day = max(days) probs = [1.0] + [0.0 for _ in range(1, max_day)] for i in range(1, max_day): probs[i] = 1 - probs[i - 1] + probs[i - 1] * probs[i - 1] / 2 for day in days: print(str(sum(probs[:day])))
F: Ben Toh As usual, those who called wolves get together on 8 p.m. at the supermarket. The thing they want is only one, a box lunch that is labeled half price. Scrambling for a few discounted box lunch, they fiercely fight every day. And those who are blessed by hunger and appetite the best can acquire the box lunch, while others have to have cup ramen or something with tear in their eyes. A senior high school student, Sato, is one of wolves. A dormitry he lives doesn't serve a dinner, and his parents don't send so much money. Therefore he absolutely acquire the half-priced box lunch and save his money. Otherwise he have to give up comic books and video games, or begin part-time job. Since Sato is an excellent wolf, he can acquire the discounted box lunch in 100% probability on the first day. But on the next day, many other wolves cooperate to block him and the probability to get a box lunch will be 50%. Even though he can get, the probability to get will be 25% on the next day of the day. Likewise, if he gets a box lunch on a certain day, the probability to get on the next day will be half. Once he failed to get a box lunch, probability to get would be back to 100%. He continue to go to supermaket and try to get the discounted box lunch for _n_ days. Please write a program to computes the expected value of the number of the discounted box lunches he can acquire.
[{"input": "2\n 3\n 0", "output": ".00000000\n 1.50000000\n 2.12500000"}]
For each dataset, write a line that contains an expected value. You may print any number of digits after the decimal point. Answers that have an error less than 1.0e-2 will be accepted.
s774452979
Wrong Answer
p00642
Input consists of several datasets. Input for a single dataset is given as a single integer _n_. Input terminates with a dataset where _n_ = 0.
dp = [0.0] * 100001 dp[1] = 1.0 for i in range(2, 100001): a, b, j = 0.5, 1, 1 while j < i and b > 1e-5: dp[i] += b * (1 - a) * (j + dp[i - j - 1]) b *= a a /= 2 j += 1 dp[i] += i * b while 1: n = int(input()) if n == 0: break print(dp[n])
F: Ben Toh As usual, those who called wolves get together on 8 p.m. at the supermarket. The thing they want is only one, a box lunch that is labeled half price. Scrambling for a few discounted box lunch, they fiercely fight every day. And those who are blessed by hunger and appetite the best can acquire the box lunch, while others have to have cup ramen or something with tear in their eyes. A senior high school student, Sato, is one of wolves. A dormitry he lives doesn't serve a dinner, and his parents don't send so much money. Therefore he absolutely acquire the half-priced box lunch and save his money. Otherwise he have to give up comic books and video games, or begin part-time job. Since Sato is an excellent wolf, he can acquire the discounted box lunch in 100% probability on the first day. But on the next day, many other wolves cooperate to block him and the probability to get a box lunch will be 50%. Even though he can get, the probability to get will be 25% on the next day of the day. Likewise, if he gets a box lunch on a certain day, the probability to get on the next day will be half. Once he failed to get a box lunch, probability to get would be back to 100%. He continue to go to supermaket and try to get the discounted box lunch for _n_ days. Please write a program to computes the expected value of the number of the discounted box lunches he can acquire.
[{"input": "2\n 3\n 0", "output": ".00000000\n 1.50000000\n 2.12500000"}]
Print "Yes" if two dices are identical, otherwise "No" in a line.
s025450831
Accepted
p02385
In the first line, six integers assigned to faces of a dice are given in ascending order of their corresponding labels. In the second line, six integers assigned to faces of another dice are given in ascending order of their corresponding labels.
class Dice: def __init__(self): # 1:ue 2:syomen 3:migi 4:hidari 5:oku 6:shita self.position = [0, 0, 0, 0, 0, 0] self.search_result = [] def setNumber(self, num): for i, x in enumerate(num): self.position[i] = x # print(self.position) def roll(self, roll): for i in range(len(roll)): s = roll[i : i + 1] p = self.position if s == "E": self.setNumber([p[3], p[1], p[0], p[5], p[4], p[2]]) elif s == "W": self.setNumber([p[2], p[1], p[5], p[0], p[4], p[3]]) elif s == "S": self.setNumber([p[4], p[0], p[2], p[3], p[5], p[1]]) elif s == "N": self.setNumber([p[1], p[5], p[2], p[3], p[0], p[4]]) elif s == "R": self.setNumber([p[0], p[2], p[4], p[1], p[3], p[5]]) elif s == "L": self.setNumber([p[0], p[3], p[1], p[4], p[4], p[5]]) def printTop(self): print(self.position[0]) def searchRight(self, a, b): i1 = self.position.index(a) i2 = self.position.index(b) # print("i1:" + str(i1) + " i2:" + str(i2) ) # 0 if ( (i1 == 1 and i2 == 2) or (i1 == 2 and i2 == 4) or (i1 == 4 and i2 == 3) or (i1 == 3 and i2 == 1) ): self.search_result.append(self.position[0]) # 1 elif ( (i1 == 0 and i2 == 3) or (i1 == 3 and i2 == 5) or (i1 == 5 and i2 == 2) or (i1 == 2 and i2 == 0) ): self.search_result.append(self.position[1]) # 2 elif ( (i1 == 0 and i2 == 1) or (i1 == 1 and i2 == 5) or (i1 == 5 and i2 == 4) or (i1 == 4 and i2 == 0) ): self.search_result.append(self.position[2]) # 3 elif ( (i1 == 1 and i2 == 0) or (i1 == 0 and i2 == 4) or (i1 == 4 and i2 == 5) or (i1 == 5 and i2 == 1) ): self.search_result.append(self.position[3]) # 4 elif ( (i1 == 0 and i2 == 2) or (i1 == 2 and i2 == 5) or (i1 == 5 and i2 == 3) or (i1 == 3 and i2 == 0) ): self.search_result.append(self.position[4]) # 5 elif ( (i1 == 2 and i2 == 1) or (i1 == 1 and i2 == 3) or (i1 == 3 and i2 == 4) or (i1 == 4 and i2 == 2) ): self.search_result.append(self.position[5]) def printResult(self): for i in self.search_result: print(i) def isSame(self, d): for r in [ "", "R", "R", "R", "RE", "R", "R", "R", "RE", "R", "R", "R", "RE", "R", "R", "R", "RS", "R", "R", "R", "RNN", "R", "R", "R", ]: self.roll(r) # print(self.position) if self.position == d.position: print("Yes") return print("No") d1 = Dice() d2 = Dice() n = list(int(x) for x in input().split()) d1.setNumber(n) n = list(int(x) for x in input().split()) d2.setNumber(n) d1.isSame(d2)
Dice III Write a program which reads the two dices constructed in the same way as Dice I, and determines whether these two dices are identical. You can roll a dice in the same way as Dice I, and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical.
[{"input": "1 2 3 4 5 6\n 6 2 4 3 5 1", "output": "Yes"}, {"input": "1 2 3 4 5 6\n 6 5 4 3 2 1", "output": "No"}]
Print "Yes" if two dices are identical, otherwise "No" in a line.
s732331293
Accepted
p02385
In the first line, six integers assigned to faces of a dice are given in ascending order of their corresponding labels. In the second line, six integers assigned to faces of another dice are given in ascending order of their corresponding labels.
def create_dice(nums): a, b, c, d, e, f = nums vertical = [a, b, f, e] horizontal = [b, c, e, d] return Dice(vertical, horizontal) class Dice: def __init__(self, v, h): self.vertical = v self.horizontal = h def v2h(self): self.horizontal[0] = self.vertical[1] self.horizontal[2] = self.vertical[3] def h2v(self): self.vertical[1] = self.horizontal[0] self.vertical[3] = self.horizontal[2] def roll(self, direction): if direction == "N": tmp1 = self.vertical[0] tmp2 = self.vertical[1:] self.vertical = tmp2 + [tmp1] self.v2h() elif direction == "S": tmp1 = self.vertical[-1] tmp2 = self.vertical[:-1] self.vertical = [tmp1] + tmp2 self.v2h() elif direction == "E": tmp1 = self.horizontal[0] tmp2 = self.horizontal[1:] self.horizontal = tmp2 + [tmp1] self.h2v() elif direction == "W": tmp1 = self.horizontal[-1] tmp2 = self.horizontal[:-1] self.horizontal = [tmp1] + tmp2 self.h2v() s1 = map(int, input().split(" ")) d1 = create_dice(s1) s2 = map(int, input().split(" ")) d2 = create_dice(s2) def match(l1, l2): lenlist = len(l1) lenset = len(set(l1)) if lenlist == lenset: return l1[0] == l2[0] else: diff = 4 - (lenlist - lenset) + 1 for i in range(diff): if l1[i] != l2[i]: return False return True r = 0 while d1.vertical != d2.vertical and d1.horizontal != d2.horizontal and r < 4: # 強制的に一つ回す d2.roll("E") v = 0 while not match(d1.vertical, d2.vertical) and v < 4: d2.roll("N") v += 1 h = 0 while not match(d1.horizontal, d2.horizontal) and v < 4: d2.roll("E") h += 1 r += 1 if d1.vertical == d2.vertical and d1.horizontal == d2.horizontal: print("Yes") else: print("No")
Dice III Write a program which reads the two dices constructed in the same way as Dice I, and determines whether these two dices are identical. You can roll a dice in the same way as Dice I, and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical.
[{"input": "1 2 3 4 5 6\n 6 2 4 3 5 1", "output": "Yes"}, {"input": "1 2 3 4 5 6\n 6 5 4 3 2 1", "output": "No"}]
Print "Yes" if two dices are identical, otherwise "No" in a line.
s300904217
Accepted
p02385
In the first line, six integers assigned to faces of a dice are given in ascending order of their corresponding labels. In the second line, six integers assigned to faces of another dice are given in ascending order of their corresponding labels.
# 9_A # w = input().upper() # t = "" # while True: # tmp = input() # if tmp == "END_OF_TEXT": # break # t += tmp.upper() + " " # list = t.split() # print(list.count(w)) # 9_B # while True: # t = input() # if t == "-": # break # m = int(input()) # for i in range(m): # h = int(input()) # t = t[h:] + t[:h] # print(t) # 9_C # n = int(input()) # score_t, score_h = 0, 0 # for i in range(n): # t, h = input().split() # if t > h: # score_t += 3 # elif h > t: # score_h += 3 # else: # score_t += 1 # score_h += 1 # print(f"{score_t} {score_h}") # 9_D # t = str(input()) # o_list = [] # for i in range(int(input())): # o_list = input().split() # a, b = int(o_list[1]), int(o_list[2]) # if o_list[0] == "print": # print(t[a : b + 1]) # elif o_list[0] == "reverse": # t = t[:a] + t[a : b + 1][::-1] + t[b + 1 :] # elif o_list[0] == "replace": # t = t[:a] + o_list[3] + t[b + 1 :] # 10_A # import math # x1, y1, x2, y2 = map(float, input().split()) # line = (x2 - x1) ** 2 + (y2 - y1) ** 2 # line = math.sqrt(line) # print(line) # 10_B # import math # a, b, c = map(float, input().split()) # h = b * math.sin(math.radians(c)) # print(h) # 10_D # https://qiita.com/shiroux/items/16173c1588d22e81333c # import math # n = int(input()) # x = list(map(int, input().split())) # y = list(map(int, input().split())) # p_1, p_2, p_3, p_infinit = 0, 0, 0, 0 # dis_list = [] # for i in range(n): # dis_list.append(abs(x[i] - y[i])) # sum_d = abs(x[i] - y[i]) # p_1 += sum_d # p_2 += sum_d ** 2 # p_3 += sum_d ** 3 # p_2 = math.sqrt(p_2) # p_3 = p_3 ** (1 / 3) # print(p_1) # print(p_2) # print(p_3) # print(max(dis_list)) # 11_* class Dice: def __init__(self, label: list): self.top, self.front, self.right, self.left, self.back, self.bottom = label def roll(self, direction: str): if direction == "N": self.top, self.front, self.right, self.left, self.back, self.bottom = ( self.front, self.bottom, self.right, self.left, self.top, self.back, ) elif direction == "W": self.top, self.front, self.right, self.left, self.back, self.bottom = ( self.right, self.front, self.bottom, self.top, self.back, self.left, ) elif direction == "S": self.top, self.front, self.right, self.left, self.back, self.bottom = ( self.back, self.top, self.right, self.left, self.bottom, self.front, ) elif direction == "E": self.top, self.front, self.right, self.left, self.back, self.bottom = ( self.left, self.front, self.top, self.bottom, self.back, self.right, ) def output_top(self): print(self.top) def get_top_front(self): return f"{self.top} {self.front}" def print_right(self): print(self.right) def get_label(self): return [self.top, self.front, self.left, self.back, self.bottom] # 11_A # (*label,) = map(int, input().split()) # dice = Dice(label) # for i in input(): # dice.roll(i) # dice.output_top() # 11_B # (*label,) = map(int, input().split()) # dice = Dice(label) # q = int(input()) # for _ in range(q): # t, f = map(int, input().split()) # for i in "EEEN" * 2 + "EEES" * 2 + "EEEN" * 2: # if f"{t} {f}" == dice.get_top_front(): # dice.print_right() # break # dice.roll(i) # 11_C dice1 = list(map(int, input().split())) dice2 = list(map(int, input().split())) dice1 = Dice(dice1) dice2 = Dice(dice2) for i in "EEEN" * 2 + "EEES" * 2 + "EEEN" * 2: if dice1.get_label() == dice2.get_label(): print("Yes") break dice1.roll(i) else: print("No")
Dice III Write a program which reads the two dices constructed in the same way as Dice I, and determines whether these two dices are identical. You can roll a dice in the same way as Dice I, and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical.
[{"input": "1 2 3 4 5 6\n 6 2 4 3 5 1", "output": "Yes"}, {"input": "1 2 3 4 5 6\n 6 5 4 3 2 1", "output": "No"}]
Print "Yes" if two dices are identical, otherwise "No" in a line.
s951055267
Accepted
p02385
In the first line, six integers assigned to faces of a dice are given in ascending order of their corresponding labels. In the second line, six integers assigned to faces of another dice are given in ascending order of their corresponding labels.
class dice: top = 1 flont = 2 right = 3 def do_N(self): temp = self.flont self.flont = 7 - self.top self.top = temp def do_S(self): temp = 7 - self.flont self.flont = self.top self.top = temp def do_E(self): temp = self.top self.top = 7 - self.right self.right = temp def do_W(self): temp = 7 - self.top self.top = self.right self.right = temp num1 = list(map(int, input().split())) num2 = list(map(int, input().split())) dice1 = dice() dice2 = dice() flag1 = False flag2 = False if ( num1[dice1.flont - 1] == num2[dice2.flont - 1] and num1[dice1.top - 1] == num2[dice2.top - 1] ): flag1 = True if ( num1[dice1.right - 1] == num2[dice2.right - 1] and num1[7 - dice1.top - 1] == num2[7 - dice2.top - 1] and num1[7 - dice1.flont - 1] == num2[7 - dice2.flont - 1] and num1[7 - dice1.right - 1] == num2[7 - dice2.right - 1] ): flag2 = True for j in range(4): for k in range(4): dice1.do_E() if ( num1[dice1.flont - 1] == num2[dice2.flont - 1] and num1[dice1.top - 1] == num2[dice2.top - 1] ): flag1 = True if ( num1[dice1.right - 1] == num2[dice2.right - 1] and num1[7 - dice1.top - 1] == num2[7 - dice2.top - 1] and num1[7 - dice1.flont - 1] == num2[7 - dice2.flont - 1] and num1[7 - dice1.right - 1] == num2[7 - dice2.right - 1] ): flag2 = True dice1.do_N() if ( num1[dice1.flont - 1] == num2[dice2.flont - 1] and num1[dice1.top - 1] == num2[dice2.top - 1] ): flag1 = True if ( num1[dice1.right - 1] == num2[dice2.right - 1] and num1[7 - dice1.top - 1] == num2[7 - dice2.top - 1] and num1[7 - dice1.flont - 1] == num2[7 - dice2.flont - 1] and num1[7 - dice1.right - 1] == num2[7 - dice2.right - 1] ): flag2 = True dice1.do_S() dice1.do_E() if ( num1[dice1.flont - 1] == num2[dice2.flont - 1] and num1[dice1.top - 1] == num2[dice2.top - 1] ): flag1 = True if ( num1[dice1.right - 1] == num2[dice2.right - 1] and num1[7 - dice1.top - 1] == num2[7 - dice2.top - 1] and num1[7 - dice1.flont - 1] == num2[7 - dice2.flont - 1] and num1[7 - dice1.right - 1] == num2[7 - dice2.right - 1] ): flag2 = True for j in range(4): for k in range(4): dice1.do_E() if ( num1[dice1.flont - 1] == num2[dice2.flont - 1] and num1[dice1.top - 1] == num2[dice2.top - 1] ): flag1 = True if ( num1[dice1.right - 1] == num2[dice2.right - 1] and num1[7 - dice1.top - 1] == num2[7 - dice2.top - 1] and num1[7 - dice1.flont - 1] == num2[7 - dice2.flont - 1] and num1[7 - dice1.right - 1] == num2[7 - dice2.right - 1] ): flag2 = True dice1.do_N() if ( num1[dice1.flont - 1] == num2[dice2.flont - 1] and num1[dice1.top - 1] == num2[dice2.top - 1] ): flag1 = True if ( num1[dice1.right - 1] == num2[dice2.right - 1] and num1[7 - dice1.top - 1] == num2[7 - dice2.top - 1] and num1[7 - dice1.flont - 1] == num2[7 - dice2.flont - 1] and num1[7 - dice1.right - 1] == num2[7 - dice2.right - 1] ): flag2 = True if flag1 and flag2: print("Yes") else: print("No")
Dice III Write a program which reads the two dices constructed in the same way as Dice I, and determines whether these two dices are identical. You can roll a dice in the same way as Dice I, and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical.
[{"input": "1 2 3 4 5 6\n 6 2 4 3 5 1", "output": "Yes"}, {"input": "1 2 3 4 5 6\n 6 5 4 3 2 1", "output": "No"}]
Print "Yes" if two dices are identical, otherwise "No" in a line.
s291079758
Wrong Answer
p02385
In the first line, six integers assigned to faces of a dice are given in ascending order of their corresponding labels. In the second line, six integers assigned to faces of another dice are given in ascending order of their corresponding labels.
class dice: def __init__(self, li=[0] * 6): self.men = [0] + li def move0(self, a, b, c, d): self.men[a], self.men[b], self.men[c], self.men[d] = ( self.men[b], self.men[c], self.men[d], self.men[a], ) def move(self, h): if h == "N": self.move0(1, 2, 6, 5) elif h == "S": self.move0(1, 5, 6, 2) elif h == "W": self.move0(1, 3, 6, 4) elif h == "E": self.move0(1, 4, 6, 3) elif h == "O": self.men[1], self.men[6], self.men[2], self.men[5] = ( self.men[6], self.men[1], self.men[5], self.men[2], ) elif h == "L": self.move0(2, 3, 5, 4) elif h == "R": self.move0(2, 4, 5, 3) elif h == "B": self.men[3], self.men[4], self.men[2], self.men[5] = ( self.men[4], self.men[3], self.men[5], self.men[2], ) def move2(self, a, b): if self.men[1] != a: for i, s in [(2, "N"), (3, "W"), (4, "E"), (5, "S"), (6, "O")]: if self.men[i] == a: self.move(s) break if self.men[2] != b: if b == self.men[3]: self.move("L") elif b == self.men[4]: self.move("R") else: self.move("B") saikoro1 = dice(list(map(int, input().split()))) saikoro2 = dice(list(map(int, input().split()))) try: top = saikoro2.men[saikoro2.men.index(saikoro1.men[1])] front = saikoro2.men[saikoro2.men.index(saikoro1.men[2])] saikoro2.move2(top, front) print("Yes" if saikoro1.men == saikoro2.men else "No") except: print("No")
Dice III Write a program which reads the two dices constructed in the same way as Dice I, and determines whether these two dices are identical. You can roll a dice in the same way as Dice I, and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical.
[{"input": "1 2 3 4 5 6\n 6 2 4 3 5 1", "output": "Yes"}, {"input": "1 2 3 4 5 6\n 6 5 4 3 2 1", "output": "No"}]
Print "Yes" if two dices are identical, otherwise "No" in a line.
s752433299
Accepted
p02385
In the first line, six integers assigned to faces of a dice are given in ascending order of their corresponding labels. In the second line, six integers assigned to faces of another dice are given in ascending order of their corresponding labels.
class Dice: def __init__(self, nums): self.top = nums[0] self.front = nums[1] self.right = nums[2] self.left = nums[3] self.back = nums[4] self.bottom = nums[5] def toN(self): tmp = self.top self.top = self.front self.front = self.bottom self.bottom = self.back self.back = tmp def toS(self): tmp = self.top self.top = self.back self.back = self.bottom self.bottom = self.front self.front = tmp def toE(self): tmp = self.top self.top = self.left self.left = self.bottom self.bottom = self.right self.right = tmp def toW(self): tmp = self.top self.top = self.right self.right = self.bottom self.bottom = self.left self.left = tmp def moveTo(self, ds): for d in ds: if d == "N": self.toN() if d == "S": self.toS() if d == "E": self.toE() if d == "W": self.toW() def getTop(self): return self.top def getBottom(self): return self.bottom def getFront(self): return self.front def getBack(self): return self.back def getLeft(self): return self.left def getRight(self): return self.right def __eq__(self, other): if self.top != other.top: return False if self.bottom != other.bottom: return False if self.front != other.front: return False if self.back != other.back: return False if self.left != other.left: return False if self.right != other.right: return False return True def moveTo(dice, top, front): if dice.getFront() != front: if dice.getTop() == front: dice.moveTo("S") elif dice.getBottom() == front: dice.moveTo("N") elif dice.getBack() == front: dice.moveTo("NN") elif dice.getLeft() == front: dice.moveTo("ES") elif dice.getRight() == front: dice.moveTo("WS") if dice.getTop() != top: if dice.getBottom() == top: dice.moveTo("EE") elif dice.getLeft() == top: dice.moveTo("E") elif dice.getRight() == top: dice.moveTo("W") return dice def equalDice(dice1, dice2): dice2 = moveTo(dice2, dice1.getTop(), dice1.getFront()) return dice1 == dice2 def main(): dice1 = Dice(input().split()) dice2 = Dice(input().split()) if equalDice(dice1, dice2): print("Yes") else: print("No") if __name__ == "__main__": main()
Dice III Write a program which reads the two dices constructed in the same way as Dice I, and determines whether these two dices are identical. You can roll a dice in the same way as Dice I, and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical.
[{"input": "1 2 3 4 5 6\n 6 2 4 3 5 1", "output": "Yes"}, {"input": "1 2 3 4 5 6\n 6 5 4 3 2 1", "output": "No"}]
Print "Yes" if two dices are identical, otherwise "No" in a line.
s621291663
Accepted
p02385
In the first line, six integers assigned to faces of a dice are given in ascending order of their corresponding labels. In the second line, six integers assigned to faces of another dice are given in ascending order of their corresponding labels.
dice1 = input().rstrip().split(" ") dice2 = input().rstrip().split(" ") indication = "EEENEEENEEESEEESEEENEEENSWWSWWWNWWWNWWWSWWWSWWW" indic = list(indication) length = len(indic) count = 0 for i in range(length): newdice = [0] * 6 if str(indic[i]) == "N": newdice[0] = dice2[1] newdice[1] = dice2[5] newdice[2] = dice2[2] newdice[3] = dice2[3] newdice[4] = dice2[0] newdice[5] = dice2[4] dice2 = newdice if dice2 == dice1: count += 1 elif str(indic[i]) == "S": newdice[0] = dice2[4] newdice[1] = dice2[0] newdice[2] = dice2[2] newdice[3] = dice2[3] newdice[4] = dice2[5] newdice[5] = dice2[1] dice2 = newdice if dice2 == dice1: count += 1 elif str(indic[i]) == "E": newdice[0] = dice2[3] newdice[1] = dice2[1] newdice[2] = dice2[0] newdice[3] = dice2[5] newdice[4] = dice2[4] newdice[5] = dice2[2] dice2 = newdice if dice2 == dice1: count += 1 elif str(indic[i]) == "W": newdice[0] = dice2[2] newdice[1] = dice2[1] newdice[2] = dice2[5] newdice[3] = dice2[0] newdice[4] = dice2[4] newdice[5] = dice2[3] dice2 = newdice if dice2 == dice1: count += 1 if count == 0: print("No") else: print("Yes")
Dice III Write a program which reads the two dices constructed in the same way as Dice I, and determines whether these two dices are identical. You can roll a dice in the same way as Dice I, and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical.
[{"input": "1 2 3 4 5 6\n 6 2 4 3 5 1", "output": "Yes"}, {"input": "1 2 3 4 5 6\n 6 5 4 3 2 1", "output": "No"}]
Print "Yes" if two dices are identical, otherwise "No" in a line.
s844891314
Accepted
p02385
In the first line, six integers assigned to faces of a dice are given in ascending order of their corresponding labels. In the second line, six integers assigned to faces of another dice are given in ascending order of their corresponding labels.
d1 = input().split() d2 = input().split() def roll(Dice, Vector): if Vector == "N": c = Dice[0] Dice[0] = Dice[1] Dice[1] = Dice[5] Dice[5] = Dice[4] Dice[4] = c elif Vector == "W": c = Dice[0] Dice[0] = Dice[2] Dice[2] = Dice[5] Dice[5] = Dice[3] Dice[3] = c elif Vector == "E": c = Dice[0] Dice[0] = Dice[3] Dice[3] = Dice[5] Dice[5] = Dice[2] Dice[2] = c elif Vector == "S": c = Dice[0] Dice[0] = Dice[4] Dice[4] = Dice[5] Dice[5] = Dice[1] Dice[1] = c v = list("NNNNWNNNWNNNENNNENNNWNNN") f = 0 for item in v: roll(d2, item) if d1 == d2: print("Yes") f += 1 break if f == 0: print("No")
Dice III Write a program which reads the two dices constructed in the same way as Dice I, and determines whether these two dices are identical. You can roll a dice in the same way as Dice I, and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical.
[{"input": "1 2 3 4 5 6\n 6 2 4 3 5 1", "output": "Yes"}, {"input": "1 2 3 4 5 6\n 6 5 4 3 2 1", "output": "No"}]
Print "Yes" if two dices are identical, otherwise "No" in a line.
s977435283
Accepted
p02385
In the first line, six integers assigned to faces of a dice are given in ascending order of their corresponding labels. In the second line, six integers assigned to faces of another dice are given in ascending order of their corresponding labels.
houkou = { "N": (1, 5, 2, 3, 0, 4), "S": (4, 0, 2, 3, 5, 1), "E": (3, 1, 0, 5, 4, 2), "W": (2, 1, 5, 0, 4, 3), } S1 = list(map(int, input().split())) S2 = list(map(int, input().split())) for ( i ) in "SSSSEEEENEEEENEEEENEEEENWSSSSWSSSSWSSSSWNWSSSSEEEEWSSSSEEEEWSSSSEEEEWNWSSSSEEEEWSSSSEEEEWSSSSEEEEWNWSSSSEEEEWSSSSEEEEWSSSSEEEEW:": if S1 == S2: print("Yes") break if i == ":": print("No") break S1 = [S1[j] for j in houkou[i]] # print(S1)
Dice III Write a program which reads the two dices constructed in the same way as Dice I, and determines whether these two dices are identical. You can roll a dice in the same way as Dice I, and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical.
[{"input": "1 2 3 4 5 6\n 6 2 4 3 5 1", "output": "Yes"}, {"input": "1 2 3 4 5 6\n 6 5 4 3 2 1", "output": "No"}]
Print "Yes" if two dices are identical, otherwise "No" in a line.
s082304741
Wrong Answer
p02385
In the first line, six integers assigned to faces of a dice are given in ascending order of their corresponding labels. In the second line, six integers assigned to faces of another dice are given in ascending order of their corresponding labels.
class Dice: def __init__(self, num_tuple): self.faces = num_tuple def find_rf(self, top, front): tf = str(self.faces.index(top)) + str(self.faces.index(front)) if tf in "12431": return self.faces[0] elif tf in "03520": return self.faces[1] elif tf in "01540": return self.faces[2] elif tf in "04510": return self.faces[3] elif tf in "02530": return self.faces[4] else: return self.faces[5] def is_same(self, dice): for i in self.faces: if not i in dice.faces: return "No" top1 = self.faces[3] front1 = self.faces[1] top2 = self.faces[0] front2 = self.faces[3] top3 = self.faces[0] front3 = self.faces[1] top4 = self.faces[4] front4 = self.faces[5] top5 = self.faces[0] front5 = self.faces[2] top6 = self.faces[2] front6 = self.faces[1] if self.find_rf(top1, front1) == dice.find_rf(top1, front1): if self.find_rf(top2, front2) == dice.find_rf(top2, front2): if self.find_rf(top3, front3) == dice.find_rf(top3, front3): if self.find_rf(top4, front4) == dice.find_rf(top4, front4): if self.find_rf(top5, front5) == dice.find_rf(top5, front5): if self.find_rf(top6, front6) == dice.find_rf(top6, front6): return "Yes" return "No" num_tuple1 = tuple(map(int, input().split())) num_tuple2 = tuple(map(int, input().split())) dice1 = Dice(num_tuple1) dice2 = Dice(num_tuple2) ans = dice1.is_same(dice2) print(ans)
Dice III Write a program which reads the two dices constructed in the same way as Dice I, and determines whether these two dices are identical. You can roll a dice in the same way as Dice I, and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical.
[{"input": "1 2 3 4 5 6\n 6 2 4 3 5 1", "output": "Yes"}, {"input": "1 2 3 4 5 6\n 6 5 4 3 2 1", "output": "No"}]
Print "Yes" if two dices are identical, otherwise "No" in a line.
s504441413
Wrong Answer
p02385
In the first line, six integers assigned to faces of a dice are given in ascending order of their corresponding labels. In the second line, six integers assigned to faces of another dice are given in ascending order of their corresponding labels.
def move_dice(d, dir): if dir == "N": d[0], d[1], d[4], d[5] = d[1], d[5], d[0], d[4] if dir == "S": d[0], d[1], d[4], d[5] = d[4], d[0], d[5], d[1] if dir == "E": d[0], d[2], d[3], d[5] = d[3], d[0], d[5], d[2] if dir == "W": d[0], d[2], d[3], d[5] = d[2], d[5], d[0], d[3] def rotate_right_dice(d): d[1], d[2], d[3], d[4] = d[3], d[1], d[4], d[2] def to_up_dice(d, num): num_index = d.index(num) if num_index == 2 or num_index == 3: move_dice(d, "E") while d[0] != num: move_dice(d, "N") def to_front_dice(d, num): while d[1] != num: rotate_right_dice(d) def equal_dice(d1, d2): if d2[0] in d1: to_up_dice(d1, d2[0]) else: return "No" if d2[1] in d1[1:5]: while d1[1] != d2[1]: rotate_right_dice(d1) else: return "No" if d1 == d2: return "Yes" else: return "No" dice1 = list(map(int, input().split())) dice2 = list(map(int, input().split())) print(equal_dice(dice1, dice2))
Dice III Write a program which reads the two dices constructed in the same way as Dice I, and determines whether these two dices are identical. You can roll a dice in the same way as Dice I, and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical.
[{"input": "1 2 3 4 5 6\n 6 2 4 3 5 1", "output": "Yes"}, {"input": "1 2 3 4 5 6\n 6 5 4 3 2 1", "output": "No"}]
Print "Yes" if two dices are identical, otherwise "No" in a line.
s726077484
Accepted
p02385
In the first line, six integers assigned to faces of a dice are given in ascending order of their corresponding labels. In the second line, six integers assigned to faces of another dice are given in ascending order of their corresponding labels.
# coding: utf-8 import copy class Dice: def __init__(self, d): self.data = { "bottom": d[5], "north": d[4], "west": d[3], "east": d[2], "south": d[1], "top": d[0], } def moveOne(self, direction): if direction == "W": temp = self.data["bottom"] self.data["bottom"] = self.data["west"] self.data["west"] = self.data["top"] self.data["top"] = self.data["east"] self.data["east"] = temp elif direction == "E": temp = self.data["bottom"] self.data["bottom"] = self.data["east"] self.data["east"] = self.data["top"] self.data["top"] = self.data["west"] self.data["west"] = temp elif direction == "N": temp = self.data["bottom"] self.data["bottom"] = self.data["north"] self.data["north"] = self.data["top"] self.data["top"] = self.data["south"] self.data["south"] = temp elif direction == "S": temp = self.data["bottom"] self.data["bottom"] = self.data["south"] self.data["south"] = self.data["top"] self.data["top"] = self.data["north"] self.data["north"] = temp def movePart(self, directions): for direction in directions: self.moveOne(direction) def setDiceII(self, a, b): if self.data["east"] == a: self.moveOne("W") elif self.data["north"] == a: self.moveOne("S") elif self.data["west"] == a: self.moveOne("E") elif self.data["south"] == a: self.moveOne("N") elif self.data["bottom"] == a: self.movePart("WW") if self.data["north"] == b: self.rotateRight() self.rotateRight() elif self.data["east"] == b: self.rotateRight() elif self.data["west"] == b: self.rotateLeft() # self.printDice() def rotateRight(self): temp = self.data["east"] self.data["east"] = self.data["north"] self.data["north"] = self.data["west"] self.data["west"] = self.data["south"] self.data["south"] = temp def rotateLeft(self): temp = self.data["west"] self.data["west"] = self.data["north"] self.data["north"] = self.data["east"] self.data["east"] = self.data["south"] self.data["south"] = temp def getSurface(self): return self.data["top"] def getEast(self): return self.data["east"] def getData(self): return self.data def getPatterns(self): patterns = [] for i in range(4): tempi = copy.copy(self.getData()) for ip in range(i): self.moveOne("N") for j in range(4): tempj = copy.copy(self.getData()) for jp in range(j): self.moveOne("E") patterns.append(copy.copy(self.getData())) self.data = tempj self.data = tempi self.rotateRight() for i in range(4): tempi = copy.copy(self.getData()) for ip in range(i): self.moveOne("N") for j in range(4): tempj = copy.copy(self.getData()) for jp in range(j): self.moveOne("E") patterns.append(copy.copy(self.getData())) self.data = tempj self.data = tempi return patterns def printDice(self): print(self.data["north"]) print( str(self.data["west"]) + " " + str(self.data["bottom"]) + " " + str(self.data["east"]) ) print(self.data["south"]) print(self.data["top"]) num1 = list(map(int, input().rstrip().split())) num2 = list(map(int, input().rstrip().split())) dice1 = Dice(num1) dice2 = Dice(num2) flag = False for i in dice2.getPatterns(): if dice1.getData() == i: print("Yes") flag = True break if not flag: print("No")
Dice III Write a program which reads the two dices constructed in the same way as Dice I, and determines whether these two dices are identical. You can roll a dice in the same way as Dice I, and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical.
[{"input": "1 2 3 4 5 6\n 6 2 4 3 5 1", "output": "Yes"}, {"input": "1 2 3 4 5 6\n 6 5 4 3 2 1", "output": "No"}]
Print "Yes" if two dices are identical, otherwise "No" in a line.
s916562951
Accepted
p02385
In the first line, six integers assigned to faces of a dice are given in ascending order of their corresponding labels. In the second line, six integers assigned to faces of another dice are given in ascending order of their corresponding labels.
class Dice: def make_dice(self, value): self.face = value def move(self, direc): if direc == "N": self.face = [ self.face[1], self.face[5], self.face[2], self.face[3], self.face[0], self.face[4], ] return self.face elif direc == "E": self.face = [ self.face[3], self.face[1], self.face[0], self.face[5], self.face[4], self.face[2], ] return self.face elif direc == "S": self.face = [ self.face[4], self.face[0], self.face[2], self.face[3], self.face[5], self.face[1], ] return self.face elif direc == "W": self.face = [ self.face[2], self.face[1], self.face[5], self.face[0], self.face[4], self.face[3], ] return self.face def check_face(self, face1): for i in range(4): if face1 == self.face: return self.face else: self.face[1], self.face[2], self.face[4], self.face[3] = ( self.face[2], self.face[4], self.face[3], self.face[1], ) num1 = list(map(int, input().split())) num2 = list(map(int, input().split())) dice1 = Dice() dice2 = Dice() dice1.make_dice(num1) for i in range(6): dice2.make_dice(num2) if i == 0: dice2.check_face(dice1.face) if dice1.face == dice2.face: print("Yes") break elif i == 1: dice2.move("N") dice2.check_face(dice1.face) if dice1.face == dice2.face: print("Yes") break elif i == 2: dice2.move("E") dice2.check_face(dice1.face) if dice1.face == dice2.face: print("Yes") break elif i == 3: dice2.move("S") dice2.check_face(dice1.face) if dice1.face == dice2.face: print("Yes") break elif i == 4: dice2.move("W") dice2.check_face(dice1.face) if dice1.face == dice2.face: print("Yes") break elif i == 5: dice2.move("N") dice2.move("N") dice2.check_face(dice1.face) if dice1.face == dice2.face: print("Yes") break else: print("No") break
Dice III Write a program which reads the two dices constructed in the same way as Dice I, and determines whether these two dices are identical. You can roll a dice in the same way as Dice I, and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical.
[{"input": "1 2 3 4 5 6\n 6 2 4 3 5 1", "output": "Yes"}, {"input": "1 2 3 4 5 6\n 6 5 4 3 2 1", "output": "No"}]
Print "Yes" if two dices are identical, otherwise "No" in a line.
s397726350
Wrong Answer
p02385
In the first line, six integers assigned to faces of a dice are given in ascending order of their corresponding labels. In the second line, six integers assigned to faces of another dice are given in ascending order of their corresponding labels.
def roll(die, d): if d == "E": return [die[3], die[1], die[0], die[5], die[4], die[2]] if d == "N": return [die[1], die[5], die[2], die[3], die[0], die[4]] if d == "S": return [die[4], die[0], die[2], die[3], die[5], die[1]] if d == "W": return [die[2], die[1], die[5], die[0], die[4], die[3]] if d == "L": return [die[0], die[3], die[1], die[4], die[2], die[5]] if d == "R": return [die[0], die[2], die[4], die[1], die[3], die[5]] def checkdice(die1, die2): ans = "No" for d in "RRRNRRRNRRRSRRRSRRRNRRR": if die1 == die2: ans = "Yes" break die2 = roll(die2, d) return ans die1 = list(map(int, input().split())) die2 = list(map(int, input().split())) print(checkdice(die1, die2))
Dice III Write a program which reads the two dices constructed in the same way as Dice I, and determines whether these two dices are identical. You can roll a dice in the same way as Dice I, and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical.
[{"input": "1 2 3 4 5 6\n 6 2 4 3 5 1", "output": "Yes"}, {"input": "1 2 3 4 5 6\n 6 5 4 3 2 1", "output": "No"}]
Print a way to paint the squares satisfying the condition, in the following format. If the square (i,\ j) is painted in red, yellow, green or blue, c_{ij} should be `R`, `Y`, `G` or `B`, respectively. c_{11}c_{12}...c_{1W} : c_{H1}c_{H2}...c_{HW} * * *
s875491622
Runtime Error
p03594
Input is given from Standard Input in the following format: H W d
def makelist(n, m): return [["" for i in range(m)] for j in range(n)] H, W, d = map(int, input().split()) colors = ["R", "Y", "G", "B"] def isSound((x, y)): return x >= 1 and y >= 1 and x <= W and y <= H field = makelist(H + 1, W + 1) if d % 2 == 0: vol = d // 2 for y in range(): for x in range(): hoge = [(x - vol, y), (x, y - vol), (x + vol, y), (x, y + vol)] else: [][42] for y in range(1, H + 1): print("".join(field[y]))
Statement We have a grid with H rows and W columns of squares. We will represent the square at the i-th row from the top and j-th column from the left as (i,\ j). Also, we will define the distance between the squares (i_1,\ j_1) and (i_2,\ j_2) as |i_1 - i_2| + |j_1 - j_2|. Snuke is painting each square in red, yellow, green or blue. Here, for a given positive integer d, he wants to satisfy the following condition: * No two squares with distance exactly d have the same color. Find a way to paint the squares satisfying the condition. It can be shown that a solution always exists.
[{"input": "2 2 1", "output": "RY\n GR\n \n\nThere are four pairs of squares with distance exactly 1. As shown below, no\ntwo such squares have the same color.\n\n * (1,\\ 1), (1,\\ 2) : `R`, `Y`\n * (1,\\ 2), (2,\\ 2) : `Y`, `R`\n * (2,\\ 2), (2,\\ 1) : `R`, `G`\n * (2,\\ 1), (1,\\ 1) : `G`, `R`\n\n* * *"}, {"input": "2 3 2", "output": "RYB\n RGB\n \n\nThere are six pairs of squares with distance exactly 2. As shown below, no two\nsuch squares have the same color.\n\n * (1,\\ 1) , (1,\\ 3) : `R` , `B`\n * (1,\\ 3) , (2,\\ 2) : `B` , `G`\n * (2,\\ 2) , (1,\\ 1) : `G` , `R`\n * (2,\\ 1) , (2,\\ 3) : `R` , `B`\n * (2,\\ 3) , (1,\\ 2) : `B` , `Y`\n * (1,\\ 2) , (2,\\ 1) : `Y` , `R`"}]
Print a way to paint the squares satisfying the condition, in the following format. If the square (i,\ j) is painted in red, yellow, green or blue, c_{ij} should be `R`, `Y`, `G` or `B`, respectively. c_{11}c_{12}...c_{1W} : c_{H1}c_{H2}...c_{HW} * * *
s694975575
Accepted
p03594
Input is given from Standard Input in the following format: H W d
for a in ( lambda h, w, d: [ ["RYGB"[(i + j) // d % 2 * 2 + (i - j) // d % 2] for j in range(w)] for i in range(h) ] )(*map(int, input().split())): print("".join(a))
Statement We have a grid with H rows and W columns of squares. We will represent the square at the i-th row from the top and j-th column from the left as (i,\ j). Also, we will define the distance between the squares (i_1,\ j_1) and (i_2,\ j_2) as |i_1 - i_2| + |j_1 - j_2|. Snuke is painting each square in red, yellow, green or blue. Here, for a given positive integer d, he wants to satisfy the following condition: * No two squares with distance exactly d have the same color. Find a way to paint the squares satisfying the condition. It can be shown that a solution always exists.
[{"input": "2 2 1", "output": "RY\n GR\n \n\nThere are four pairs of squares with distance exactly 1. As shown below, no\ntwo such squares have the same color.\n\n * (1,\\ 1), (1,\\ 2) : `R`, `Y`\n * (1,\\ 2), (2,\\ 2) : `Y`, `R`\n * (2,\\ 2), (2,\\ 1) : `R`, `G`\n * (2,\\ 1), (1,\\ 1) : `G`, `R`\n\n* * *"}, {"input": "2 3 2", "output": "RYB\n RGB\n \n\nThere are six pairs of squares with distance exactly 2. As shown below, no two\nsuch squares have the same color.\n\n * (1,\\ 1) , (1,\\ 3) : `R` , `B`\n * (1,\\ 3) , (2,\\ 2) : `B` , `G`\n * (2,\\ 2) , (1,\\ 1) : `G` , `R`\n * (2,\\ 1) , (2,\\ 3) : `R` , `B`\n * (2,\\ 3) , (1,\\ 2) : `B` , `Y`\n * (1,\\ 2) , (2,\\ 1) : `Y` , `R`"}]
Print a way to paint the squares satisfying the condition, in the following format. If the square (i,\ j) is painted in red, yellow, green or blue, c_{ij} should be `R`, `Y`, `G` or `B`, respectively. c_{11}c_{12}...c_{1W} : c_{H1}c_{H2}...c_{HW} * * *
s724077606
Wrong Answer
p03594
Input is given from Standard Input in the following format: H W d
import sys H, W, d = map(int, input().split()) if d % 2 == 1: reg = list("R" * (W + 1)) for i in range(W + 1): if i % 4 == 1: reg[i] = "Y" if i % 4 == 2: reg[i] = "G" if i % 4 == 3: reg[i] = "B" for j in range(H): print("".join(map(str, reg))[j : j + W + 1] + "".join(map(str, reg))[0:j]) else: reg = list("R" * (W + 1)) for i in range(W + 1): if i % 8 == 2 or i % 8 == 3: reg[i] = "Y" if i % 8 == 4 or i % 8 == 5: reg[i] = "G" if i % 8 == 6 or i % 8 == 7: reg[i] = "B" for j in range(H): print( "".join(map(str, reg))[j * 3 : j * 3 + W + 1] + "".join(map(str, reg))[0 : j * 3] )
Statement We have a grid with H rows and W columns of squares. We will represent the square at the i-th row from the top and j-th column from the left as (i,\ j). Also, we will define the distance between the squares (i_1,\ j_1) and (i_2,\ j_2) as |i_1 - i_2| + |j_1 - j_2|. Snuke is painting each square in red, yellow, green or blue. Here, for a given positive integer d, he wants to satisfy the following condition: * No two squares with distance exactly d have the same color. Find a way to paint the squares satisfying the condition. It can be shown that a solution always exists.
[{"input": "2 2 1", "output": "RY\n GR\n \n\nThere are four pairs of squares with distance exactly 1. As shown below, no\ntwo such squares have the same color.\n\n * (1,\\ 1), (1,\\ 2) : `R`, `Y`\n * (1,\\ 2), (2,\\ 2) : `Y`, `R`\n * (2,\\ 2), (2,\\ 1) : `R`, `G`\n * (2,\\ 1), (1,\\ 1) : `G`, `R`\n\n* * *"}, {"input": "2 3 2", "output": "RYB\n RGB\n \n\nThere are six pairs of squares with distance exactly 2. As shown below, no two\nsuch squares have the same color.\n\n * (1,\\ 1) , (1,\\ 3) : `R` , `B`\n * (1,\\ 3) , (2,\\ 2) : `B` , `G`\n * (2,\\ 2) , (1,\\ 1) : `G` , `R`\n * (2,\\ 1) , (2,\\ 3) : `R` , `B`\n * (2,\\ 3) , (1,\\ 2) : `B` , `Y`\n * (1,\\ 2) , (2,\\ 1) : `Y` , `R`"}]
Print a way to paint the squares satisfying the condition, in the following format. If the square (i,\ j) is painted in red, yellow, green or blue, c_{ij} should be `R`, `Y`, `G` or `B`, respectively. c_{11}c_{12}...c_{1W} : c_{H1}c_{H2}...c_{HW} * * *
s981457119
Wrong Answer
p03594
Input is given from Standard Input in the following format: H W d
H, W, d = map(int, input().split()) C = ["R", "Y", "G", "B"] if d % 2 == 1: for i in range(H): out = "" for j in range(W): out += C[(i + j) % 4] print(out) elif d % 4 == 2: for i in range(H): out = "" for j in range(W): out += C[i % 2 * 2 + (i + j // 2) % 2] print(out) else: for i in range(H): out = "" for j in range(W): out += C[(i + j) // d % 2 * 2 + (i - j) // d % 2] print(out)
Statement We have a grid with H rows and W columns of squares. We will represent the square at the i-th row from the top and j-th column from the left as (i,\ j). Also, we will define the distance between the squares (i_1,\ j_1) and (i_2,\ j_2) as |i_1 - i_2| + |j_1 - j_2|. Snuke is painting each square in red, yellow, green or blue. Here, for a given positive integer d, he wants to satisfy the following condition: * No two squares with distance exactly d have the same color. Find a way to paint the squares satisfying the condition. It can be shown that a solution always exists.
[{"input": "2 2 1", "output": "RY\n GR\n \n\nThere are four pairs of squares with distance exactly 1. As shown below, no\ntwo such squares have the same color.\n\n * (1,\\ 1), (1,\\ 2) : `R`, `Y`\n * (1,\\ 2), (2,\\ 2) : `Y`, `R`\n * (2,\\ 2), (2,\\ 1) : `R`, `G`\n * (2,\\ 1), (1,\\ 1) : `G`, `R`\n\n* * *"}, {"input": "2 3 2", "output": "RYB\n RGB\n \n\nThere are six pairs of squares with distance exactly 2. As shown below, no two\nsuch squares have the same color.\n\n * (1,\\ 1) , (1,\\ 3) : `R` , `B`\n * (1,\\ 3) , (2,\\ 2) : `B` , `G`\n * (2,\\ 2) , (1,\\ 1) : `G` , `R`\n * (2,\\ 1) , (2,\\ 3) : `R` , `B`\n * (2,\\ 3) , (1,\\ 2) : `B` , `Y`\n * (1,\\ 2) , (2,\\ 1) : `Y` , `R`"}]
Print a way to paint the squares satisfying the condition, in the following format. If the square (i,\ j) is painted in red, yellow, green or blue, c_{ij} should be `R`, `Y`, `G` or `B`, respectively. c_{11}c_{12}...c_{1W} : c_{H1}c_{H2}...c_{HW} * * *
s093593226
Runtime Error
p03594
Input is given from Standard Input in the following format: H W d
#include <functional> #include <map> #include <cstdio> #include <iterator> #include <vector> #include <array> #include <utility> template<typename T> struct ScanfSpecifier{}; #define DEF(T,V) template<> struct ScanfSpecifier<T>{static constexpr const char* value = V;}; DEF(char*,"%s")DEF(int,"%d")DEF(double,"%lf")DEF(float,"%f")DEF(char,"%c")DEF(const char*,"%s")DEF(unsigned long,"%lu")DEF(unsigned int, "%u") #ifdef _MSC_VER DEF(long long int,"%I64d") #else DEF(long long int,"%lld") #endif #undef DEF template<typename T> int RD(T& arg){return std::scanf(ScanfSpecifier<T>::value, &arg);} template<int S> int RD(char (&arg)[S]){return std::scanf("%s", arg);} int RD(char* arg){return std::scanf("%s", arg);} template<> int RD<char>(char& arg){return std::scanf(" %c", &arg);} template<typename T, typename... Args> int RD(T& arg1, Args&... args) {return RD(arg1) + RD(args...);} template<typename T> T RD(){T ret; RD(ret); return ret;} template<typename It> void RDV(It begin, It end) { while(begin != end) RD(*begin++); } template<typename C> void RDV(C& c) {RDV(std::begin(c), std::end(c));} template<typename T> void WT(T arg) {std::printf(ScanfSpecifier<T>::value, arg); } template<typename T, typename U> void WT(std::pair<T, U> arg) {std::printf("("); WT(arg.first); std::printf(", "); WT(arg.second); std::printf(")");} template<typename... Args> void WT(Args... args) { int alc = 0; int dummy[] = {((alc++? std::printf(" "): 0), WT(args), 0)...}; } template<typename... Args> void WTL(Args... args) { WT(args...); std::printf("\n"); } template<typename It> void WTV(It begin, It end) { int alc = 0; while(begin != end) (alc++? std::printf(" "): 0), WT(*begin++); } template<typename C> void WTV(const C& c) {WTV(std::begin(c), std::end(c));} template<typename It> void WTVL(It begin, It end) { WTV(begin, end); std::printf("\n"); } template<typename C> void WTVL(const C& c) {WTVL(std::begin(c), std::end(c));} #define _M_VARGS_NUM_IMPL(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N #define _M_VARGS_NUM(...) _M_VARGS_NUM_IMPL(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1) #define _W1(_1) (#_1[0] == '"' || #_1[0] == '\''? WT("", _1, ""): WT('[', #_1, '=', _1, ']')) #define _W2(_1, _2) (_W1(_1), _W1(_2)) #define _W3(_1, _2, _3) (_W1(_1), _W2(_2, _3)) #define _W4(_1, _2, _3, _4) (_W1(_1), _W3(_2, _3, _4)) #define _W5(_1, _2, _3, _4, _5) (_W1(_1), _W4(_2, _3, _4, _5)) #define _W6(_1, _2, _3, _4, _5, _6) (_W1(_1), _W5(_2, _3, _4, _5, _6)) #define _W7(_1, _2, _3, _4, _5, _6, _7) (_W1(_1), _W6(_2, _3, _4, _5, _6, _7)) #define _W8(_1, _2, _3, _4, _5, _6, _7, _8) (_W1(_1), _W7(_2, _3, _4, _5, _6, _7, _8)) #define _WW_IMPL2(num, ...) _W ## num(__VA_ARGS__) #define _WW_IMPL(num, ...) _WW_IMPL2(num, __VA_ARGS__) #define WW(...) (std::printf("(%03d) ", __LINE__), _WW_IMPL(_M_VARGS_NUM(__VA_ARGS__), __VA_ARGS__), WTL("")) struct Range { struct It { int num, step; int operator*(){return num;} void operator++(){num += step;} bool operator!=(const It& other){return num != other.num;} }; Range(int ee):b(0),e(ee){} Range(int bb, int ee):b(bb), e(ee){} It begin(){return {b, (b < e? 1: -1)};} It end(){return {e, 0};} int b, e; }; template<typename T> inline T& UMAX(T& x, T y){if(x < y)x = y; return x;} template<typename T> inline T& UMIN(T& x, T y){if(y < x)x = y; return x;} template<typename T, typename... Args> struct ArithmiticPromotion { typedef decltype(T() + typename ArithmiticPromotion<Args...>::type()) type; }; template<typename T, typename U> struct ArithmiticPromotion<T, U> { typedef decltype(T() + U()) type; }; template<typename T> struct ArithmiticPromotion<T, T> { typedef T type; }; template<typename T> struct ArithmiticPromotion<T> { typedef T type; }; template<typename T, typename U> typename ArithmiticPromotion<T, U>::type MAX(T a, U b) { return a < b? b: a; } template<typename T, typename... Args> typename ArithmiticPromotion<T, Args...>::type MAX(T a, Args... args) { return MAX(a, MAX(args...)); } template<typename T, typename U> typename ArithmiticPromotion<T, U>::type MIN(T a, U b) { return a < b? a: b; } template<typename T, typename... Args> typename ArithmiticPromotion<T, Args...>::type MIN(T a, Args... args) { return MIN(a, MIN(args...)); } //alias using RG = Range; //RD[L],RDV[L],WT[L],WTV[L] for i/o //template #include <vector> #include <string> #include <cstring> #include <queue> #include <set> #include <map> #include <cstdlib> #include <algorithm> #include <functional> using namespace std; typedef long long int ll; char C[2][2] = {{'R', 'G'}, {'B', 'Y'}}; int main() { int H, W, D; RD(H, W, D); for(int i: RG(H)) { for(int j: RG(W)) WT(C[(i + j) / D % 2][(i + W - j) / D % 2]); WTL(); } }
Statement We have a grid with H rows and W columns of squares. We will represent the square at the i-th row from the top and j-th column from the left as (i,\ j). Also, we will define the distance between the squares (i_1,\ j_1) and (i_2,\ j_2) as |i_1 - i_2| + |j_1 - j_2|. Snuke is painting each square in red, yellow, green or blue. Here, for a given positive integer d, he wants to satisfy the following condition: * No two squares with distance exactly d have the same color. Find a way to paint the squares satisfying the condition. It can be shown that a solution always exists.
[{"input": "2 2 1", "output": "RY\n GR\n \n\nThere are four pairs of squares with distance exactly 1. As shown below, no\ntwo such squares have the same color.\n\n * (1,\\ 1), (1,\\ 2) : `R`, `Y`\n * (1,\\ 2), (2,\\ 2) : `Y`, `R`\n * (2,\\ 2), (2,\\ 1) : `R`, `G`\n * (2,\\ 1), (1,\\ 1) : `G`, `R`\n\n* * *"}, {"input": "2 3 2", "output": "RYB\n RGB\n \n\nThere are six pairs of squares with distance exactly 2. As shown below, no two\nsuch squares have the same color.\n\n * (1,\\ 1) , (1,\\ 3) : `R` , `B`\n * (1,\\ 3) , (2,\\ 2) : `B` , `G`\n * (2,\\ 2) , (1,\\ 1) : `G` , `R`\n * (2,\\ 1) , (2,\\ 3) : `R` , `B`\n * (2,\\ 3) , (1,\\ 2) : `B` , `Y`\n * (1,\\ 2) , (2,\\ 1) : `Y` , `R`"}]
Print a way to paint the squares satisfying the condition, in the following format. If the square (i,\ j) is painted in red, yellow, green or blue, c_{ij} should be `R`, `Y`, `G` or `B`, respectively. c_{11}c_{12}...c_{1W} : c_{H1}c_{H2}...c_{HW} * * *
s633152188
Accepted
p03594
Input is given from Standard Input in the following format: H W d
import os import sys import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 H, W, D = list(map(int, sys.stdin.readline().split())) X, Y = np.meshgrid(np.arange(H), np.arange(W)) # 45度回転 X, Y = X + Y, X - Y X = X.ravel() Y = Y.ravel() # いい感じに埋める colors = np.zeros(H * W, dtype=str) colors[(X % (D * 2) < D) & (Y % (D * 2) < D)] = "R" colors[(X % (D * 2) < D) & (Y % (D * 2) >= D)] = "Y" colors[(X % (D * 2) >= D) & (Y % (D * 2) < D)] = "G" colors[(X % (D * 2) >= D) & (Y % (D * 2) >= D)] = "B" # 復元 x, y = (X + Y) // 2, (X - Y) // 2 ans = np.zeros((H, W), dtype=str) ans[x, y] = colors print("\n".join(map(lambda r: "".join(r), ans)))
Statement We have a grid with H rows and W columns of squares. We will represent the square at the i-th row from the top and j-th column from the left as (i,\ j). Also, we will define the distance between the squares (i_1,\ j_1) and (i_2,\ j_2) as |i_1 - i_2| + |j_1 - j_2|. Snuke is painting each square in red, yellow, green or blue. Here, for a given positive integer d, he wants to satisfy the following condition: * No two squares with distance exactly d have the same color. Find a way to paint the squares satisfying the condition. It can be shown that a solution always exists.
[{"input": "2 2 1", "output": "RY\n GR\n \n\nThere are four pairs of squares with distance exactly 1. As shown below, no\ntwo such squares have the same color.\n\n * (1,\\ 1), (1,\\ 2) : `R`, `Y`\n * (1,\\ 2), (2,\\ 2) : `Y`, `R`\n * (2,\\ 2), (2,\\ 1) : `R`, `G`\n * (2,\\ 1), (1,\\ 1) : `G`, `R`\n\n* * *"}, {"input": "2 3 2", "output": "RYB\n RGB\n \n\nThere are six pairs of squares with distance exactly 2. As shown below, no two\nsuch squares have the same color.\n\n * (1,\\ 1) , (1,\\ 3) : `R` , `B`\n * (1,\\ 3) , (2,\\ 2) : `B` , `G`\n * (2,\\ 2) , (1,\\ 1) : `G` , `R`\n * (2,\\ 1) , (2,\\ 3) : `R` , `B`\n * (2,\\ 3) , (1,\\ 2) : `B` , `Y`\n * (1,\\ 2) , (2,\\ 1) : `Y` , `R`"}]
Print a way to paint the squares satisfying the condition, in the following format. If the square (i,\ j) is painted in red, yellow, green or blue, c_{ij} should be `R`, `Y`, `G` or `B`, respectively. c_{11}c_{12}...c_{1W} : c_{H1}c_{H2}...c_{HW} * * *
s545809594
Accepted
p03594
Input is given from Standard Input in the following format: H W d
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**15 mod = 10**9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def main(): h, w, d = LI() r = [["."] * w for _ in range(h)] cs = ["R", "Y", "G", "B"] for i in range(0, h + d, d): for j in range(0, w + d, d): c = cs[(i + j) % (d * 2) // d] for ii in range(-d, d): for jj in range(-d, d): if ( i + ii < 0 or i + ii >= h or j + jj < 0 or j + jj >= w or abs(ii) + abs(jj) >= d or abs(ii) + abs(d - jj - 1) >= d ): continue r[i + ii][j + jj] = c for i in range(1, h + d, d): for j in range(0, w + d, d): c = cs[(i + j) % (d * 2) // d + 2] for ii in range(d): for jj in range(d): if i + ii < 0 or i + ii >= h or j + jj < 0 or j + jj >= w: continue if abs(ii) + abs(jj) >= d or r[i + ii][j + jj] != "." or jj > ii: break r[i + ii][j + jj] = c for jj in range(-1, -d - 1, -1): if i + ii < 0 or i + ii >= h or j + jj < 0 or j + jj >= w: continue if abs(ii) + abs(jj) >= d or r[i + ii][j + jj] != ".": break r[i + ii][j + jj] = c return "\n".join(["".join(c) for c in r]) print(main())
Statement We have a grid with H rows and W columns of squares. We will represent the square at the i-th row from the top and j-th column from the left as (i,\ j). Also, we will define the distance between the squares (i_1,\ j_1) and (i_2,\ j_2) as |i_1 - i_2| + |j_1 - j_2|. Snuke is painting each square in red, yellow, green or blue. Here, for a given positive integer d, he wants to satisfy the following condition: * No two squares with distance exactly d have the same color. Find a way to paint the squares satisfying the condition. It can be shown that a solution always exists.
[{"input": "2 2 1", "output": "RY\n GR\n \n\nThere are four pairs of squares with distance exactly 1. As shown below, no\ntwo such squares have the same color.\n\n * (1,\\ 1), (1,\\ 2) : `R`, `Y`\n * (1,\\ 2), (2,\\ 2) : `Y`, `R`\n * (2,\\ 2), (2,\\ 1) : `R`, `G`\n * (2,\\ 1), (1,\\ 1) : `G`, `R`\n\n* * *"}, {"input": "2 3 2", "output": "RYB\n RGB\n \n\nThere are six pairs of squares with distance exactly 2. As shown below, no two\nsuch squares have the same color.\n\n * (1,\\ 1) , (1,\\ 3) : `R` , `B`\n * (1,\\ 3) , (2,\\ 2) : `B` , `G`\n * (2,\\ 2) , (1,\\ 1) : `G` , `R`\n * (2,\\ 1) , (2,\\ 3) : `R` , `B`\n * (2,\\ 3) , (1,\\ 2) : `B` , `Y`\n * (1,\\ 2) , (2,\\ 1) : `Y` , `R`"}]
Print a way to paint the squares satisfying the condition, in the following format. If the square (i,\ j) is painted in red, yellow, green or blue, c_{ij} should be `R`, `Y`, `G` or `B`, respectively. c_{11}c_{12}...c_{1W} : c_{H1}c_{H2}...c_{HW} * * *
s962134623
Runtime Error
p03594
Input is given from Standard Input in the following format: H W d
H, W, d = map(int, input().strip().split(" ")) m = [[None for _ in range(W)] for _ in range(H)] unopen = [(i, j) for i in range(H) for j in range(W)] cands = [[["R", "G", "B", "Y"] for _ in range(W)] for _ in range(H)] prio = {(i, j): 0 for i in range(H) for j in range(W)} def list_up(target): i, j = target global H global W global d out = [] for x in range(-d, d + 1): if not (0 <= i + x < H): continue g = d - abs(x) g = [g, -g] if g != 0 else [g] for y in g: if not (0 <= j + y < W): continue out.append((x + i, y + j)) return out default_color_dict = {"R": False, "G": False, "B": False, "Y": False} target = (0, 0) m[target[0]][target[1]] = "R" unopen.remove(target) cands[0][0] = ["R"] prio[target] = -1 lu = list_up(target) for n in list_up(target): i, j = n if n in unopen and "R" in cands[i][j]: cands[i][j].remove("R") prio[n] += 1 def print_m(): global m print("\n".join(["".join(["n" if l is None else l for l in n]) for n in m])) while len(unopen): next_target, p = max(prio.items(), key=lambda x: x[1]) cdict = dict(default_color_dict) c = cands[next_target[0]][next_target[1]][0] m[next_target[0]][next_target[1]] = c prio[next_target] = -1 unopen.remove(next_target) for t in list_up(next_target): if t in unopen and c in cands[t[0]][t[1]]: prio[t] += 1 cands[t[0]][t[1]].remove(c) print_m()
Statement We have a grid with H rows and W columns of squares. We will represent the square at the i-th row from the top and j-th column from the left as (i,\ j). Also, we will define the distance between the squares (i_1,\ j_1) and (i_2,\ j_2) as |i_1 - i_2| + |j_1 - j_2|. Snuke is painting each square in red, yellow, green or blue. Here, for a given positive integer d, he wants to satisfy the following condition: * No two squares with distance exactly d have the same color. Find a way to paint the squares satisfying the condition. It can be shown that a solution always exists.
[{"input": "2 2 1", "output": "RY\n GR\n \n\nThere are four pairs of squares with distance exactly 1. As shown below, no\ntwo such squares have the same color.\n\n * (1,\\ 1), (1,\\ 2) : `R`, `Y`\n * (1,\\ 2), (2,\\ 2) : `Y`, `R`\n * (2,\\ 2), (2,\\ 1) : `R`, `G`\n * (2,\\ 1), (1,\\ 1) : `G`, `R`\n\n* * *"}, {"input": "2 3 2", "output": "RYB\n RGB\n \n\nThere are six pairs of squares with distance exactly 2. As shown below, no two\nsuch squares have the same color.\n\n * (1,\\ 1) , (1,\\ 3) : `R` , `B`\n * (1,\\ 3) , (2,\\ 2) : `B` , `G`\n * (2,\\ 2) , (1,\\ 1) : `G` , `R`\n * (2,\\ 1) , (2,\\ 3) : `R` , `B`\n * (2,\\ 3) , (1,\\ 2) : `B` , `Y`\n * (1,\\ 2) , (2,\\ 1) : `Y` , `R`"}]
Print a way to paint the squares satisfying the condition, in the following format. If the square (i,\ j) is painted in red, yellow, green or blue, c_{ij} should be `R`, `Y`, `G` or `B`, respectively. c_{11}c_{12}...c_{1W} : c_{H1}c_{H2}...c_{HW} * * *
s882244873
Runtime Error
p03594
Input is given from Standard Input in the following format: H W d
import sys h, w, d = map(int, sys.stdin.readline().split()) def ironuri(x, b, c): a = [] if b - d >= 0: a.append(x[b - d][c]) if c - d >= 0: a.append(x[b][c - d]) nu = ["R", "Y", "G", "B"] for ia in nu: if ia not in a: return ia e = [[0] * w for i in range(h)] for i in range(w): for j in range(h): if e[j][i] != 0: continue e[j][i] = "R" for k in range(w // d): for l in range(h // d): e[j + k * d][i + l * d] = ironuri(e, j + k * d, i + l * d) for i in e: print("".join(i))
Statement We have a grid with H rows and W columns of squares. We will represent the square at the i-th row from the top and j-th column from the left as (i,\ j). Also, we will define the distance between the squares (i_1,\ j_1) and (i_2,\ j_2) as |i_1 - i_2| + |j_1 - j_2|. Snuke is painting each square in red, yellow, green or blue. Here, for a given positive integer d, he wants to satisfy the following condition: * No two squares with distance exactly d have the same color. Find a way to paint the squares satisfying the condition. It can be shown that a solution always exists.
[{"input": "2 2 1", "output": "RY\n GR\n \n\nThere are four pairs of squares with distance exactly 1. As shown below, no\ntwo such squares have the same color.\n\n * (1,\\ 1), (1,\\ 2) : `R`, `Y`\n * (1,\\ 2), (2,\\ 2) : `Y`, `R`\n * (2,\\ 2), (2,\\ 1) : `R`, `G`\n * (2,\\ 1), (1,\\ 1) : `G`, `R`\n\n* * *"}, {"input": "2 3 2", "output": "RYB\n RGB\n \n\nThere are six pairs of squares with distance exactly 2. As shown below, no two\nsuch squares have the same color.\n\n * (1,\\ 1) , (1,\\ 3) : `R` , `B`\n * (1,\\ 3) , (2,\\ 2) : `B` , `G`\n * (2,\\ 2) , (1,\\ 1) : `G` , `R`\n * (2,\\ 1) , (2,\\ 3) : `R` , `B`\n * (2,\\ 3) , (1,\\ 2) : `B` , `Y`\n * (1,\\ 2) , (2,\\ 1) : `Y` , `R`"}]
Print a way to paint the squares satisfying the condition, in the following format. If the square (i,\ j) is painted in red, yellow, green or blue, c_{ij} should be `R`, `Y`, `G` or `B`, respectively. c_{11}c_{12}...c_{1W} : c_{H1}c_{H2}...c_{HW} * * *
s804443206
Wrong Answer
p03594
Input is given from Standard Input in the following format: H W d
def ok(x, y): return (0 <= x < h) and (0 <= y < w) a = input().split() h = int(a[0]) w = int(a[1]) d = int(a[2]) state = [] ans = [] for i in range(h): temp1 = [] temp2 = [] for j in range(w): temp1.append(15) temp2.append("X") state.append(temp1) ans.append(temp2) # state[h][w] for i in range(h): for j in range(w): if (state[i][j] & 1) != 0: ans[i][j] = "R" for x in range(i - d, i + d + 1): y = j + (d - abs(i - x)) if ok(x, y): state[x][y] &= ~1 y = j - (d - abs(i - x)) if ok(x, y): state[x][y] &= ~1 elif (state[i][j] & 2) != 0: ans[i][j] = "Y" for x in range(i - d, i + d + 1): y = j + (d - abs(i - x)) if ok(x, y): state[x][y] &= ~2 y = j - (d - abs(i - x)) if ok(x, y): state[x][y] &= ~2 elif (state[i][j] & 4) != 0: ans[i][j] = "G" for x in range(i - d, i + d + 1): y = j + (d - abs(i - x)) if ok(x, y): state[x][y] &= ~4 y = j - (d - abs(i - x)) if ok(x, y): state[x][y] &= ~4 elif (state[i][j] & 8) != 0: ans[i][j] = "B" for x in range(i - d, i + d + 1): y = j + (d - abs(i - x)) if ok(x, y): state[x][y] &= ~8 y = j - (d - abs(i - x)) if ok(x, y): state[x][y] &= ~8 else: ans[i][j] = "Z" for i in range(h): for j in range(w): print(ans[i][j], end="") print()
Statement We have a grid with H rows and W columns of squares. We will represent the square at the i-th row from the top and j-th column from the left as (i,\ j). Also, we will define the distance between the squares (i_1,\ j_1) and (i_2,\ j_2) as |i_1 - i_2| + |j_1 - j_2|. Snuke is painting each square in red, yellow, green or blue. Here, for a given positive integer d, he wants to satisfy the following condition: * No two squares with distance exactly d have the same color. Find a way to paint the squares satisfying the condition. It can be shown that a solution always exists.
[{"input": "2 2 1", "output": "RY\n GR\n \n\nThere are four pairs of squares with distance exactly 1. As shown below, no\ntwo such squares have the same color.\n\n * (1,\\ 1), (1,\\ 2) : `R`, `Y`\n * (1,\\ 2), (2,\\ 2) : `Y`, `R`\n * (2,\\ 2), (2,\\ 1) : `R`, `G`\n * (2,\\ 1), (1,\\ 1) : `G`, `R`\n\n* * *"}, {"input": "2 3 2", "output": "RYB\n RGB\n \n\nThere are six pairs of squares with distance exactly 2. As shown below, no two\nsuch squares have the same color.\n\n * (1,\\ 1) , (1,\\ 3) : `R` , `B`\n * (1,\\ 3) , (2,\\ 2) : `B` , `G`\n * (2,\\ 2) , (1,\\ 1) : `G` , `R`\n * (2,\\ 1) , (2,\\ 3) : `R` , `B`\n * (2,\\ 3) , (1,\\ 2) : `B` , `Y`\n * (1,\\ 2) , (2,\\ 1) : `Y` , `R`"}]
Print the maximum value that can be displayed as your grade. * * *
s828201335
Accepted
p03701
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
def resolve(): import sys input = sys.stdin.readline # 整数 1 つ n = int(input()) # 整数複数個 # a, b = map(int, input().split()) # 整数 N 個 (改行区切り) S = [int(input()) for i in range(n)] # 整数 N 個 (スペース区切り) # N = list(map(int, input().split())) # 整数 (縦 H 横 W の行列) # A = [list(map(int, input().split())) for i in range(H)] Score = [[0] * 10001 for _ in range(n + 1)] for i in range(n): for j in range(10001): if j + S[i] <= 10000: Score[i + 1][j + S[i]] = max(Score[i + 1][j + S[i]], Score[i][j] + S[i]) Score[i + 1][j] = max(Score[i + 1][j], Score[i][j]) ansmax = 0 for i in range(n + 1): for j in range(10001): if Score[i][j] % 10 != 0: ansmax = max(ansmax, Score[i][j]) print(ansmax) resolve()
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s240466903
Accepted
p03701
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
a = [int(input()) for _ in "_" * int(input())] s = sum(a) print(max((s - x) * ((s - x) % 10 > 0) for x in [0] + a))
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s381122334
Runtime Error
p03701
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
n=int(input()) s=[None]*n minv=100 for in range(n): s[i]=int(input()) if minv>s[i]: if s[i]%10!=0: minv=s[i] if minv==100: print(0) elif sum(s)%10==0: print(sum(s)-minv) else: print(sum(s))
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s635736904
Wrong Answer
p03701
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
sum = 0 for i in range(int(input())): tmp = int(input()) sum += tmp if tmp % 10 != 0 else 0 print(sum)
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s319685873
Wrong Answer
p03701
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
n = int(input()) l = [] for i in range(n): l.append(int(input())) while l != [] and sum(l) % 10 == 0: l.pop(l.index(min(l))) print(sum(l))
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s645207405
Runtime Error
p03701
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
n = int(input()) s = [int(input()) for i in range(n)] if sum(s)%10: print(sum(s)) else: for i in sorted(s): if i%10: print(sum(s)-i) break else: print(0
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s320752777
Runtime Error
p03701
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
import sys n, *lst = map(int, sys.stdin.read().split()) res = sum(lst) if not res % 10: tmp = [i if not i % 10 for i in lst] if tmp: res -= min(tmp) else: res = 0 print(res)
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s716004981
Accepted
p03701
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
import sys class Solution(object): def __init__(self): self.N = int(sys.stdin.readline()) self.s = [] for _ in range(self.N): self.s.append(int(sys.stdin.readline())) # def solve(self): def naive_solve(self): sums = [0] for num in self.s: sums.extend([s + num for s in sums]) for r in sorted(sums, reverse=True): if r % 10: return r return 0 def answer_solve(self): S = sum(self.s) if S % 10: return S smallest = float("inf") for num in self.s: if num % 10: smallest = min(smallest, num) if smallest != float("inf"): return S - smallest return 0 print(Solution().answer_solve())
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s067099169
Accepted
p03701
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sun Feb 10 10:05:08 2019 @author: shinjisu """ # ARC 073 C def getInt(): return int(input()) def getIntLines(n): return [int(input()) for i in range(n)] def zeros(n): return [0] * n def genBits(n): # n個の0/1のリストを生成 [0]から変化 bits = zeros(n) for i in range(2**n): for k in range(n): bits[k] = i % 2 i //= 2 yield bits def dmp(x): global debug if debug: print(x) def probC_TLE(): N = getInt() S = getIntLines(N) dmp((N, S)) maxPoint = 0 for bit in genBits(N): point = 0 for i in range(N): point += S[i] * bit[i] if point % 10 == 0: point = 0 maxPoint = max(point, maxPoint) dmp((point, maxPoint)) return maxPoint def probC(): N = getInt() S = getIntLines(N) dmp((N, S)) tens = [] nonTens = [] for i in range(N): if S[i] % 10 == 0: tens.append(S[i]) else: nonTens.append(S[i]) total = sum(nonTens) dmp(total) if total > 0 and total % 10 == 0: total -= min(nonTens) dmp(total) if total > 0: total += sum(tens) dmp(total) return total debug = False print(probC())
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s981228818
Runtime Error
p03701
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
import math as mt store = [] def binarysearch(min, max): mid = int((max + min) / 2) if min == max: return mid elif count(mid) > mid: return binarysearch(mid + 1, max) else: return binarysearch(min, mid) def count(x): store = [mt.ceil((n - x * b) / a) for n in hp] store = [x for x in store if x > 0] return sum(store) st = 0 min = 10**18 max = 0 n, a, b = [int(x) for x in input().split(" ")] hp = [] for i in range(n): st = int(input()) if st < min: min = st if st > max: max = st hp.append(st) min, max = mt.ceil(min / a), mt.ceil(max / b) a = a - b print(binarysearch(min, max))
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s239227717
Runtime Error
p03701
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
import itertools N = int(input()) lst = [] # listにN個の数値を格納 for i in range(N): lst.append(int(input())) l_sum = sum(lst) p_list = [] if l_sum % 10 == 0: # enumerate()関数を使うと、forループの中でリスト(配列)インデックス番号(カウント、順番)を取得できる # i にインデックス番号が入る for i, _ in enumerate(lst, 1): # permutations()を使うと 第2引数分の全パターンを取得できる for j in itertools.permutations(lst, r=i): # rには1、2、3と渡される p_list.append(j) q_list = sorted(set(list(map(sum, p_list))),reverse=True) x = 0 for i, item in enumerate(q_list, 1): if item % 10 != 0 : print(item) x = 1 break if x = 0: print(0) else: print (l_sum)
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print |a - b|. * * *
s862813527
Accepted
p02813
Input is given from Standard Input in the following format: N P_1 P_2 ... P_N Q_1 Q_2 ... Q_N
from itertools import permutations def mapt(fn, *args): return tuple(map(fn, *args)) def main(): n = int(input()) data = permutations(range(1, n + 1), n) p = mapt(int, input().split(" ")) q = mapt(int, input().split(" ")) list1 = [] for index, i in enumerate(data): if p == i or i == q: list1.append(index) print(abs(list1[0] - list1[-1])) main()
Statement We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)). There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.
[{"input": "3\n 1 3 2\n 3 1 2", "output": "3\n \n\nThere are 6 permutations of size 3: (1,~2,~3), (1,~3,~2), (2,~1,~3),\n(2,~3,~1), (3,~1,~2), and (3,~2,~1). Among them, (1,~3,~2) and (3,~1,~2) come\n2-nd and 5-th in lexicographical order, so the answer is |2 - 5| = 3.\n\n* * *"}, {"input": "8\n 7 3 5 4 2 1 6 8\n 3 8 2 5 4 6 7 1", "output": "17517\n \n\n* * *"}, {"input": "3\n 1 2 3\n 1 2 3", "output": "0"}]
Print |a - b|. * * *
s893778444
Runtime Error
p02813
Input is given from Standard Input in the following format: N P_1 P_2 ... P_N Q_1 Q_2 ... Q_N
import fractions import math N, M = map(int, input().split()) a = list(map(int, input().split())) a_uniq = list(set(a)) len_a = len(a_uniq) # find lcm gcd_a = a_uniq[0] for i in range(1, len_a): gcd_a = fractions.gcd(gcd_a, a_uniq[i]) lcm = 1 for j in range(len_a): lcm *= a_uniq[j] lcm = lcm / gcd_a lcm /= 2 print(math.ceil((M / lcm) / 2), lcm, M)
Statement We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)). There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.
[{"input": "3\n 1 3 2\n 3 1 2", "output": "3\n \n\nThere are 6 permutations of size 3: (1,~2,~3), (1,~3,~2), (2,~1,~3),\n(2,~3,~1), (3,~1,~2), and (3,~2,~1). Among them, (1,~3,~2) and (3,~1,~2) come\n2-nd and 5-th in lexicographical order, so the answer is |2 - 5| = 3.\n\n* * *"}, {"input": "8\n 7 3 5 4 2 1 6 8\n 3 8 2 5 4 6 7 1", "output": "17517\n \n\n* * *"}, {"input": "3\n 1 2 3\n 1 2 3", "output": "0"}]
Print |a - b|. * * *
s108102635
Accepted
p02813
Input is given from Standard Input in the following format: N P_1 P_2 ... P_N Q_1 Q_2 ... Q_N
from itertools import permutations fact = [1] N = int(input()) seq = [i for i in range(1, N + 1)] seq = list(permutations(seq)) dic = {} for i in range(len(seq)): x = seq[i] dic[x] = i p = tuple([int(c) for c in input().split()]) q = tuple([int(c) for c in input().split()]) P = dic[p] Q = dic[q] print(abs(P - Q))
Statement We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)). There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.
[{"input": "3\n 1 3 2\n 3 1 2", "output": "3\n \n\nThere are 6 permutations of size 3: (1,~2,~3), (1,~3,~2), (2,~1,~3),\n(2,~3,~1), (3,~1,~2), and (3,~2,~1). Among them, (1,~3,~2) and (3,~1,~2) come\n2-nd and 5-th in lexicographical order, so the answer is |2 - 5| = 3.\n\n* * *"}, {"input": "8\n 7 3 5 4 2 1 6 8\n 3 8 2 5 4 6 7 1", "output": "17517\n \n\n* * *"}, {"input": "3\n 1 2 3\n 1 2 3", "output": "0"}]
Print |a - b|. * * *
s327059261
Accepted
p02813
Input is given from Standard Input in the following format: N P_1 P_2 ... P_N Q_1 Q_2 ... Q_N
from sys import stdin from itertools import permutations n = int(stdin.readline().strip()) rank = dict( [ (val, i) for i, val in enumerate( sorted( [ int("".join([str(v) for v in l])) for l in permutations(list(range(1, n + 1)), n) ] )[::-1] ) ] ) p_rank = rank[int("".join(stdin.readline().split()))] q_rank = rank[int("".join(stdin.readline().split()))] print(abs(p_rank - q_rank))
Statement We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)). There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.
[{"input": "3\n 1 3 2\n 3 1 2", "output": "3\n \n\nThere are 6 permutations of size 3: (1,~2,~3), (1,~3,~2), (2,~1,~3),\n(2,~3,~1), (3,~1,~2), and (3,~2,~1). Among them, (1,~3,~2) and (3,~1,~2) come\n2-nd and 5-th in lexicographical order, so the answer is |2 - 5| = 3.\n\n* * *"}, {"input": "8\n 7 3 5 4 2 1 6 8\n 3 8 2 5 4 6 7 1", "output": "17517\n \n\n* * *"}, {"input": "3\n 1 2 3\n 1 2 3", "output": "0"}]
Print |a - b|. * * *
s525326004
Accepted
p02813
Input is given from Standard Input in the following format: N P_1 P_2 ... P_N Q_1 Q_2 ... Q_N
n = int(input()) p = list(map(int, input().split())) q = list(map(int, input().split())) a = 1 b = 1 n1 = 1 for i in range(n): n1 = n1 * (i + 1) for i in range(n): t = 0 i1 = 1 for j in range(i + 1): i1 = i1 * (n - j) for j in range(n): if i < j and p[i] > p[j]: t += 1 a += t * n1 // i1 for i in range(n): t = 0 i1 = 1 for j in range(i + 1): i1 = i1 * (n - j) for j in range(n): if i < j and q[i] > q[j]: t += 1 b += t * n1 // i1 c = a - b if c > 0: print(c) else: print(-c)
Statement We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)). There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.
[{"input": "3\n 1 3 2\n 3 1 2", "output": "3\n \n\nThere are 6 permutations of size 3: (1,~2,~3), (1,~3,~2), (2,~1,~3),\n(2,~3,~1), (3,~1,~2), and (3,~2,~1). Among them, (1,~3,~2) and (3,~1,~2) come\n2-nd and 5-th in lexicographical order, so the answer is |2 - 5| = 3.\n\n* * *"}, {"input": "8\n 7 3 5 4 2 1 6 8\n 3 8 2 5 4 6 7 1", "output": "17517\n \n\n* * *"}, {"input": "3\n 1 2 3\n 1 2 3", "output": "0"}]
Print |a - b|. * * *
s236192443
Accepted
p02813
Input is given from Standard Input in the following format: N P_1 P_2 ... P_N Q_1 Q_2 ... Q_N
bit = [0] * 9 fa = [1] * 9 for n in range(1, 9): fa[n] = fa[n - 1] * n def up(id): while id < 9: bit[id] += 1 id += id & (-id) def qr(id): res = 0 while id: res += bit[id] id -= id & (-id) return res x = int(input()) s = list(map(int, input().split())) z = list(map(int, input().split())) v = "" for n in s: a = qr(n) vl = n - 1 - a v += str(vl) up(n) v = v[::-1] r1 = 0 for n in range(len(v)): r1 += int(v[n]) * fa[n] r2 = 0 v = "" bit = [0] * 9 for n in z: a = qr(n) vl = n - 1 - a v += str(vl) up(n) v = v[::-1] for n in range(len(v)): r2 += int(v[n]) * fa[n] print(abs(r1 - r2))
Statement We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)). There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.
[{"input": "3\n 1 3 2\n 3 1 2", "output": "3\n \n\nThere are 6 permutations of size 3: (1,~2,~3), (1,~3,~2), (2,~1,~3),\n(2,~3,~1), (3,~1,~2), and (3,~2,~1). Among them, (1,~3,~2) and (3,~1,~2) come\n2-nd and 5-th in lexicographical order, so the answer is |2 - 5| = 3.\n\n* * *"}, {"input": "8\n 7 3 5 4 2 1 6 8\n 3 8 2 5 4 6 7 1", "output": "17517\n \n\n* * *"}, {"input": "3\n 1 2 3\n 1 2 3", "output": "0"}]
Print |a - b|. * * *
s770384524
Accepted
p02813
Input is given from Standard Input in the following format: N P_1 P_2 ... P_N Q_1 Q_2 ... Q_N
n = int(input()) p = [int(i) - 1 for i in input().split()] q = [int(i) - 1 for i in input().split()] fact = [1] * 10 for i in range(2, 10): fact[i] = fact[i - 1] * i index1 = 1 l = [i for i in range(n)] while len(p) > 0: i = p.pop(0) l.remove(i) cnt = len([k for k in l if k < i]) index1 += cnt * fact[len(l)] index2 = 1 l = [i for i in range(n)] while len(q) > 0: i = q.pop(0) l.remove(i) cnt = len([k for k in l if k < i]) index2 += cnt * fact[len(l)] print(abs(index1 - index2))
Statement We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)). There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.
[{"input": "3\n 1 3 2\n 3 1 2", "output": "3\n \n\nThere are 6 permutations of size 3: (1,~2,~3), (1,~3,~2), (2,~1,~3),\n(2,~3,~1), (3,~1,~2), and (3,~2,~1). Among them, (1,~3,~2) and (3,~1,~2) come\n2-nd and 5-th in lexicographical order, so the answer is |2 - 5| = 3.\n\n* * *"}, {"input": "8\n 7 3 5 4 2 1 6 8\n 3 8 2 5 4 6 7 1", "output": "17517\n \n\n* * *"}, {"input": "3\n 1 2 3\n 1 2 3", "output": "0"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s901097873
Accepted
p03351
Input is given from Standard Input in the following format: a b c d
############################################################################### from sys import stdout from bisect import bisect_left as binl from copy import copy, deepcopy from collections import defaultdict mod = 1 def intin(): input_tuple = input().split() if len(input_tuple) <= 1: return int(input_tuple[0]) return tuple(map(int, input_tuple)) def intina(): return [int(i) for i in input().split()] def intinl(count): return [intin() for _ in range(count)] def modadd(x, y): global mod return (x + y) % mod def modmlt(x, y): global mod return (x * y) % mod def lcm(x, y): while y != 0: z = x % y x = y y = z return x def combination(x, y): assert x >= y if y > x // 2: y = x - y ret = 1 for i in range(0, y): j = x - i i = i + 1 ret = ret * j ret = ret // i return ret def get_divisors(x): retlist = [] for i in range(1, int(x**0.5) + 3): if x % i == 0: retlist.append(i) retlist.append(x // i) return retlist def get_factors(x): retlist = [] for i in range(2, int(x**0.5) + 3): while x % i == 0: retlist.append(i) x = x // i retlist.append(x) return retlist def make_linklist(xylist): linklist = {} for a, b in xylist: linklist.setdefault(a, []) linklist.setdefault(b, []) linklist[a].append(b) linklist[b].append(a) return linklist def calc_longest_distance(linklist, v=1): distance_list = {} distance_count = 0 distance = 0 vlist_previous = [] vlist = [v] nodecount = len(linklist) while distance_count < nodecount: vlist_next = [] for v in vlist: distance_list[v] = distance distance_count += 1 vlist_next.extend(linklist[v]) distance += 1 vlist_to_del = vlist_previous vlist_previous = vlist vlist = list(set(vlist_next) - set(vlist_to_del)) max_distance = -1 max_v = None for v, distance in distance_list.items(): if distance > max_distance: max_distance = distance max_v = v return (max_distance, max_v) def calc_tree_diameter(linklist, v=1): _, u = calc_longest_distance(linklist, v) distance, _ = calc_longest_distance(linklist, u) return distance ############################################################################### def main(): a, b, c, d = intin() if abs(a - c) <= d: print("Yes") return if abs(a - b) <= d and abs(c - b) <= d: print("Yes") return print("No") if __name__ == "__main__": main()
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s732476902
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a, b, c, d = map(int, input().split()) if abs (a - c) <= d: print('Yes') elif abs(a - b) <= d: print('Yes') elif abs(b - c) <= d: if d >= abs(a - c) or (d >= abs(a - b) and d >= abs(b - c)): print('Yes') else: print('No')
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s177067042
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
data = input() dataa,datab,datac,datad = data.split(' ') dataa = int(dataa) datab = int(datab) datac = int(datac) datad = int(datad) length1 = dataa - datab length2 = datab - datac length11 = abs(length1) + abs(length2) length3 = dataa - datac if abs(length1) <>= datad: print('Yes') elif abs(length2) <= datad: print('Yes') elif abs(length11) <= datad: print('Yes') else: print('No')
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s714070175
Wrong Answer
p03351
Input is given from Standard Input in the following format: a b c d
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random import itertools sys.setrecursionlimit(10**5) stdin = sys.stdin def LI(): return list(map(int, stdin.readline().split())) def LF(): return list(map(float, stdin.readline().split())) def LI_(): return list(map(lambda x: int(x) - 1, stdin.readline().split())) def II(): return int(stdin.readline()) def IF(): return float(stdin.readline()) def LS(): return list(map(list, stdin.readline().split())) def S(): return list(stdin.readline().rstrip()) def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = float("INF") # A def A(): a, b, c, d = LI() x = abs(a - b) + abs(b - c) y = abs(a - c) if x <= d or y <= d: print("Yes") else: print("No") return # B def B(): return # C def C(): s = stdin.readline().rstrip() K = II() - 1 ans = [] for i in range(len(s)): for k in range(K + 1): b = s[i : i + k + 1] ans.append(b) ans = list(set(ans)) ans.sort() print(ans[K]) return # D def D(): n, m = LI() p = LI_() xy = LIR_(m) size = [1 for _ in range(n)] height = [1 for _ in range(n)] par = [i for i in range(n)] def find(x): if par[x] == x: return x else: par[x] = find(par[x]) return par[x] def union(x, y): s1 = find(x) s2 = find(y) if s1 != s2: if height[s1] < height[s2]: par[s1] = s2 size[s2] += size[s1] size[s1] = 0 else: par[s2] = s1 size[s1] += size[s2] size[s2] = 0 if height[s1] == height[s2]: height[s1] += 1 for x, y in xy: union(x, y) ans = 0 for i in range(n): if find(p[i]) == find(i): ans += 1 print(ans) return # E def E(): return # F def F(): return # G def G(): return # H def H(): return # Solve if __name__ == "__main__": A()
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s752080296
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
cha = input() num = int(input()) list = [] for i in range(len(cha)): for j in range(num): if list.count(cha[i : i + j + 1]) == 0: list.append(cha[i : i + j + 1]) list.sort() print(list[num - 1])
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s142811689
Accepted
p03351
Input is given from Standard Input in the following format: a b c d
print("YNeos"[input()[-1] in "29" :: 2])
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s901925431
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a,b,c,d=map(int,input().split()) if (abs(a-b)=<d)or(abs(a-c)=<d)or(abs(b-c)=<d): print("Yes") else: print("No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s872005341
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a,b,c,d=map(int,input().split()) print(["No","Yes"][abs(a-c)<=d or (abs(a-b)<=d and abs(b-c)<=d])
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s327253066
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
if z =< d: print("Yse") elif x =< d and y =< d: print("Yes") else: print("No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s191441544
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a, b, c, d = map(int, input().split()) AB = abs(a - b) BC = abs(b - c) AC = abs(a - c) if AC <= d or ( AB <= d and BC <= d:): print("Yes") else: print("No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s736606725
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a, b, c, d=map(int,input().split) k1=abs(a,b) k2=abs(a,c) k3=abs(b,c) if (k2<=d): print("Yes") elif (k1<=d || k2<=d): print("Yes") else print("No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s673153542
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a = input() b = input() c = input() d = input() ab = a - b bc = b - c ac = a - c if ab <= d and bc <= d or ac <= d: print("Yes") else: print("No"
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s003629265
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a, b, c, d=map(int,input().split) k1=abs(a-b) k2=abs(a-c) k3=abs(b-c) if (k2<d): print("Yes") elif (k1<=d || k2<=d): print("Yes") else print("No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s171220561
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a, b, c, d=map(int,input().split()) k1=abs(a-b) k2=abs(a-c) k3=abs(b-c) if k2<=d: print("Yes") elif k1<=d || k2<=d: print("Yes") else print("No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s662509746
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a, b, c, d=map(int,input().split) k1=abs(a-b) k2=abs(a-c) k3=abs(b-c) if k2<=d: print("Yes") elif k1<=d || k2<=d: print("Yes") else print("No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s937793794
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a, b, c, d=map(int,input().split) k1=abs(a-b) k2=abs(a-c) k3=abs(b-c) if (k2<=d): print("Yes") elif (k1<=d || k2<=d): print("Yes") else print("No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s001766729
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a, b, c, d=map(int,input().split) k1=abs(a-b) k2=abs(a-c) k3=abs(b-c) if k2<=d: print("Yes") elif k1<=d or k2<=d: print("Yes") else print("No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s424708551
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a, b, c, d = map(int, input().split) k1 = int(abs(a - b)) k2 = int(abs(a - c)) k3 = int(abs(b - c)) print("Yes" if k2 <= d or k1 <= d and k3 <= d else "No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s234871132
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a,b,c,d = map(int,input().split()) if abs(a-c) <= d or(abs(a-b)<=d and abs(c-b)<=d: print('Yes') else: print('No')
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s059073183
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
N, M = map(int, input().split()) e = [int(x) - 1 for x in input().split()] p = [i for i in range(N)] r = [0] * N def find(x): if p[x] != x: p[x] = find(p[x]) return p[x] def unite(x, y): x = find(x) y = find(y) if x == y: return if r[x] < r[y]: p[x] = y else: p[y] = x if r[x] == r[y]: r[x] += 1 def same(x, y): return find(x) == find(y) for i in range(M): x, y = map(int, input().split()) unite(x - 1, y - 1) c = 0 for i in range(N): if same(i, e[i]): c += 1 print(c)
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s573827399
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
N = [int(i) for i in input().split()] if abs(N[2]-N[0]) <= N[3]: print(“Yes”) elif abs(N[1]-N[0])+abs(N[2]-N[1]) <= 2*N[3]: print(“Yes”) else: print(“No”)
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s144629605
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a,b,c = map(int, input().split()) d = int(input()) B-A = (b-a) C-B = (c-b) C-A = (c-a) if B-A <= d and C-B <= d: print("Yes") elif c-a =< d: print("Yes") else: ("No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s419478825
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a, b, c, d = map(int, input().split()) B - A = abs(b - a) B - C = abs(c - b) C - A = abs(a - c) if (B - A <= d and B - C <= d) or C - A <= d: print("Yes") else: print("No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s793146477
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a, b, c, d = map(int, input().split()) ans = 0 if abs(a-c) <= d: ans = 1 if abs(a-b) <= d && abs(b-c) <= d: ans = 1 if ans == 1: print("Yes") else print("No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s081295736
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
#include <algorithm> #include <iostream> #include <cstdlib> #include <limits.h> #include <math.h> #include <stdio.h> #include <string> #include <typeinfo> #include <random> #include <vector> //#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<bool> vb; typedef vector<char> vc; typedef vector<int> vi; typedef vector<long long> vll; typedef vector<string> vs; typedef vector<vector<bool>> vvb; typedef vector<vector<int>> vvi; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define all(a) (a).begin(), (a).end() int main() { int a, b, c, d; cin >> a >> b >> c >> d; if (abs(a - c) <= d || (abs(a - b) < d && abs(c - c) < d)) { cout << "Yes" << endl; }else{ cout << "No" << endl; } return 0; }
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s197938783
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a, b, c, d = map(int, inmput().split()) x = abs(a - b) y = abs(b - c) z = abs(c - a) if z <= d: print('Yes') elif if x<= d and y <= d: print('Yes') else: print('No')
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s270626504
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
import math, sys from bisect import bisect_left, bisect_right from collections import Counter, defaultdict, deque from copy import deepcopy from functools import lru_cache from heapq import heapify, heappop, heappush from itertools import accumulate, combinations, permutations input = sys.stdin.readline mod = 10**9 + 7 ns = lambda: input().strip() ni = lambda: int(input().strip()) nm = lambda: map(int, input().split()) nl = lambda: list(map(int, input().split())) def main(): a, b, c, d = nm() if abs(b-a) <= d or abs(c-b) <= d or abs(c-a) <=: print('Yes') else: print('No') if __name__ == '__main__': main()
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s765086488
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a,b,c,d=map(int,input().split()) print("Yes" if ((abs(a-b)<=d and (abs(c-b)<=d)) or (abs(c-a)<=d) else "No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s650138717
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
def judge(a,b,c,d): if(abs(a-b)<=d | abs(a-c)<=d & abs(b-c)<=d): print("Yes") else: print("No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s416485993
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
def judge(a,b,c,d): if(abs(a-b)<=d or abs(a-c)<=d and abs(b-c)<=d): print("Yes") else: print("No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s214090739
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a,b,c,d = map(int, input().split()) if abs(b-a) <= d and abs(c-b) <= d : print('Yes') elif: abs(a-c) <= d : print('Yes') else: print('No')
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s717110857
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a,b,c,d=map(int,input().split()) ans=False if abs(a-c)<=d: ans=True if abs(a-b)<=d&&abs(b-c)<=d: ans=True if ans: print("Yes") else: print("No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s695170617
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
X = int(input()) b = 0 MAX = 0 while b < X: p = 2 b += 1 while b**p <= X: if b**p > MAX: MAX = b**p p += 1 print(MAX)
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s289957226
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a,b,c,d = map(int, input().split()) if abs(b-a) < d and abs(a-b) < d : print('Yes') elif: abs(a-c) < d : print('Yes') else: print('No')
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s316146823
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
,b,c,d = map(int,input().split()) if abs(a-b)<=d: if abs(b-c)<=d: print("Yes") if abs(a-c)<=d: print('Yes') else: print("No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s101429250
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a,b,c,d = map(int,input().split()) if abs(a-c) <= d: print('Yes') elif (abs(a-b) <= d) && (abs(b-c) <= d): print('Yes') else: print('No')
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s070780404
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a, b, c, d = map(int, input().split()) if abs(c-a) =< d: print("Yes") elif abs(a-b) =< d and abs(b-c) =< d: print("Yes") else: print("No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s481374779
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a, b, c, d = [int(i) for i in input().split()] if abs(a-c) <= d: print('Yes') elif abs(a-b) <= d and abs()-c) <= d: print('Yes') else: print('No')
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s490443926
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a, b, c, d = map(int, input().split()) if abs(a - c) <= d: print("Yes") elif abs(a - b) <= d and abs(b + )c <= d: print("Yes") else: print("No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s847386281
Accepted
p03351
Input is given from Standard Input in the following format: a b c d
a, b, c, d = [int(c) for c in input().split()] X = sorted([a, b, c]) print("Yes" if (X[2] - X[1] <= d and X[1] - X[0] <= d) or abs(a - c) <= d else "No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s883036713
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a, b, c, d = map(int, input().split()) if abs(a-c) <= d || abs(a-b) <= d and abs(b-c) <= d: print("Yes") else: print("No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s210563603
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a b c d = map(int,input().split()) dis_ab = abs(a-b) dis_bc = abs(b-c) if dis_ab <= d and dis_bc <= d: print('Yes') else: print('No')
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s129356574
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a,b,c,d=map(int,input().split()) if abs(a-c)<=d: print('Yes') elif: abs(a-b)<=d and abs(b-d)<=d: print('Yes') else: print('No')
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s259162271
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a,b,c,d=map(int,input().split()) if(abs(a-c)<=d): print(“Yes”) elif(abs(a-b)<=d and abs(b-c)<=d): print(“Yes”) else: print(“No”)
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s323288923
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a, b, c, d = map(int, input().split()) if abs(a - c) <= d: print("Yes") elif abs(a - c) <= d * 2 and ((a <= b and b <= c) or (a >= b and b >= c): print("Yes") else: print("No")
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s679776158
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
a, b, c, d = [input(n) for n in input().split()] if abs(a - c) <= d: print('Yes') else: if abs(a - b) < d and abs(b - c) < d: print('Yes') else: print('No')
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s785346354
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
n, m = map(int, input().split()) p = list(map(int, input().split())) 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()) uf = UnionFind(n) for i in range(m): x, y = map(int, input().split()) uf.union(x - 1, y - 1) ans = 0 for i in range(n): if uf.find(i) == uf.find(p[i] - 1): ans += 1 print(ans)
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s017735211
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
s = input() K = int(input()) def sort_here(ll): # バブルソート for m in range(len(ll)): for n in range(len(ll) - 1 - m): A, B = compare(ll[n], ll[n + 1]) ll[n] = A ll[n + 1] = B return ll def compare_(A, B): # このゲームにおける比較 # 小、大の順で返す a = len(A) b = len(B) if a > b: if A[:b] == B: return B, A elif b > a: if B[:a] == A: return A, B for i in range(len(min(A, B))): if A[i] > B[i]: return B, A elif A[i] < B[i]: return A, B def compare(A, B): # このゲームにおける比較 # 小、大の順で返す for i in range(len(min(A, B))): if A[i] > B[i]: return B, A elif A[i] < B[i]: return A, B if len(A) < len(B): return A, B elif len(B) < len(A): return B, A else: raise Exception # まずは長さが5以下で存在しうるsubstringを準備 i_list = [] for i in range(1, K + 1): # i文字数のsutringをまずは作る for j in range(len(s) - i + 1): cand = s[j : j + i] if cand not in i_list: i_list.append(s[j : j + i]) # print(i_list) # 並び替え i_list = sort_here(i_list) # print(i_list) # 出力 print(i_list[K - 1])
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]
If A and C can communicate, print `Yes`; if they cannot, print `No`. * * *
s796110594
Runtime Error
p03351
Input is given from Standard Input in the following format: a b c d
n = int(input()) def gauss_2(n): g = 0 while g <= n ** (1 / 2): g += 1 return g - 1 def gauss_3(n): g = 0 while g <= n ** (1 / 3): g += 1 return g - 1 def gauss_4(n): g = 0 while g <= n ** (1 / 4): g += 1 return g - 1 def gauss_5(n): g = 0 while g <= n ** (1 / 5): g += 1 return g - 1 def gauss_6(n): g = 0 while g <= n ** (1 / 6): g += 1 return g - 1 def gauss_7(n): g = 0 while g <= n ** (1 / 7): g += 1 return g - 1 if n <= 3: print(1) elif n not in (125, 216, 343, 512, 729): print( max( gauss_2(n) ** 2, gauss_3(n) ** 3, gauss_4(n) ** 4, gauss_5(n) ** 5, gauss_6(n) ** 6, gauss_7(n) ** 7, ) ) else: print(n)
Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
[{"input": "4 7 9 3", "output": "Yes\n \n\nA and B can directly communicate, and also B and C can directly communicate,\nso we should print `Yes`.\n\n* * *"}, {"input": "100 10 1 2", "output": "No\n \n\nThey cannot communicate in this case.\n\n* * *"}, {"input": "10 10 10 1", "output": "Yes\n \n\nThere can be multiple people at the same position.\n\n* * *"}, {"input": "1 100 2 10", "output": "Yes"}]