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 all the integers that satisfies the condition above in ascending order. * * *
s382504513
Runtime Error
p03386
Input is given from Standard Input in the following format: A B K
2 10 3
Statement Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
[{"input": "3 8 2", "output": "3\n 4\n 7\n 8\n \n\n * 3 is the first smallest integer among the integers between 3 and 8.\n * 4 is the second smallest integer among the integers between 3 and 8.\n * 7 is the second largest integer among the integers between 3 and 8.\n * 8 is the first largest integer among the integers between 3 and 8.\n\n* * *"}, {"input": "4 8 3", "output": "4\n 5\n 6\n 7\n 8\n \n\n* * *"}, {"input": "2 9 100", "output": "2\n 3\n 4\n 5\n 6\n 7\n 8\n 9"}]
Print all the integers that satisfies the condition above in ascending order. * * *
s395230397
Accepted
p03386
Input is given from Standard Input in the following format: A B K
#!/usr/bin/env python3 import sys # import time # import math # import numpy as np # import scipy.sparse.csgraph as cs # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall # import random # random, uniform, randint, randrange, shuffle, sample # import string # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits # import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s) # from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]). # from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate() # from collections import defaultdict # subclass of dict. defaultdict(facroty) # from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter) # from datetime import date, datetime # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj # from datetime.datetime import strptime # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj # from datetime import timedelta # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available. # from copy import copy, deepcopy # use deepcopy to copy multi-dimentional matrix without reference # from functools import reduce # reduce(f, iter[, init]) # from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed) # from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn). # from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn). # from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n]) # from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])] # from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9] # from itertools import product, permutations # product(iter, repeat=n), permutations(iter[,r]) # from itertools import combinations, combinations_with_replacement # from itertools import accumulate # accumulate(iter[, f]) # from operator import itemgetter # itemgetter(1), itemgetter('key') # from fractions import gcd # for Python 3.4 (previous contest @AtCoder) def main(): mod = 1000000007 # 10^9+7 inf = float("inf") # sys.float_info.max = 1.79...e+308 # inf = 2 ** 64 - 1 # (for fast JIT compile in PyPy) 1.84...e+19 sys.setrecursionlimit(10**6) # 1000 -> 1000000 def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def mi(): return map(int, input().split()) def mi_0(): return map(lambda x: int(x) - 1, input().split()) def lmi(): return list(map(int, input().split())) def lmi_0(): return list(map(lambda x: int(x) - 1, input().split())) def li(): return list(input()) a, b, k = mi() for i in range(a, min(b, a + k)): print(i) for j in range(max(min(b, a + k), b - k + 1), b + 1): print(j) if __name__ == "__main__": main()
Statement Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
[{"input": "3 8 2", "output": "3\n 4\n 7\n 8\n \n\n * 3 is the first smallest integer among the integers between 3 and 8.\n * 4 is the second smallest integer among the integers between 3 and 8.\n * 7 is the second largest integer among the integers between 3 and 8.\n * 8 is the first largest integer among the integers between 3 and 8.\n\n* * *"}, {"input": "4 8 3", "output": "4\n 5\n 6\n 7\n 8\n \n\n* * *"}, {"input": "2 9 100", "output": "2\n 3\n 4\n 5\n 6\n 7\n 8\n 9"}]
Print all the integers that satisfies the condition above in ascending order. * * *
s873739016
Wrong Answer
p03386
Input is given from Standard Input in the following format: A B K
S = input().split(" ") A = int(S[0]) B = int(S[1]) A_B = range(A, B) K = int(S[2]) A_B_1 = A_B[: K - 1] A_B_2 = A_B[-(K - 1) :] print(K) print(A_B) print(A_B_1) print(A_B_2) list1 = list(A_B_1) list2 = list(A_B_2) SUM = list1 + list2 for i in range(0, len(SUM)): print(SUM[i])
Statement Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
[{"input": "3 8 2", "output": "3\n 4\n 7\n 8\n \n\n * 3 is the first smallest integer among the integers between 3 and 8.\n * 4 is the second smallest integer among the integers between 3 and 8.\n * 7 is the second largest integer among the integers between 3 and 8.\n * 8 is the first largest integer among the integers between 3 and 8.\n\n* * *"}, {"input": "4 8 3", "output": "4\n 5\n 6\n 7\n 8\n \n\n* * *"}, {"input": "2 9 100", "output": "2\n 3\n 4\n 5\n 6\n 7\n 8\n 9"}]
Print all the integers that satisfies the condition above in ascending order. * * *
s112999585
Runtime Error
p03386
Input is given from Standard Input in the following format: A B K
#bA A, B, K = map(int, input().split()) list = range(A, B+1) #上限下限を先に決めておく set1 = set(:K) set2 = set(-K:) print(sorted(set1|set2))
Statement Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
[{"input": "3 8 2", "output": "3\n 4\n 7\n 8\n \n\n * 3 is the first smallest integer among the integers between 3 and 8.\n * 4 is the second smallest integer among the integers between 3 and 8.\n * 7 is the second largest integer among the integers between 3 and 8.\n * 8 is the first largest integer among the integers between 3 and 8.\n\n* * *"}, {"input": "4 8 3", "output": "4\n 5\n 6\n 7\n 8\n \n\n* * *"}, {"input": "2 9 100", "output": "2\n 3\n 4\n 5\n 6\n 7\n 8\n 9"}]
Print all the integers that satisfies the condition above in ascending order. * * *
s482163910
Runtime Error
p03386
Input is given from Standard Input in the following format: A B K
a,b,c=map(int,input().split()) s=[] x=list(range(a,b+1)) for i in range(min(c,b-a+1): s.append(x[i]) s.append(x[-(i+1)]) s.sort().set() #print(s) for i in s: print(i)
Statement Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
[{"input": "3 8 2", "output": "3\n 4\n 7\n 8\n \n\n * 3 is the first smallest integer among the integers between 3 and 8.\n * 4 is the second smallest integer among the integers between 3 and 8.\n * 7 is the second largest integer among the integers between 3 and 8.\n * 8 is the first largest integer among the integers between 3 and 8.\n\n* * *"}, {"input": "4 8 3", "output": "4\n 5\n 6\n 7\n 8\n \n\n* * *"}, {"input": "2 9 100", "output": "2\n 3\n 4\n 5\n 6\n 7\n 8\n 9"}]
Print all the integers that satisfies the condition above in ascending order. * * *
s647953189
Runtime Error
p03386
Input is given from Standard Input in the following format: A B K
a,b,k = map(int,input().split()) mn = a mx = b def in_range(a,b,n): return a <= n and b >= n: for i in range(a,b+1): if in_range(mn,mn+k) or in_range()(mx-k,mx): print(i)
Statement Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
[{"input": "3 8 2", "output": "3\n 4\n 7\n 8\n \n\n * 3 is the first smallest integer among the integers between 3 and 8.\n * 4 is the second smallest integer among the integers between 3 and 8.\n * 7 is the second largest integer among the integers between 3 and 8.\n * 8 is the first largest integer among the integers between 3 and 8.\n\n* * *"}, {"input": "4 8 3", "output": "4\n 5\n 6\n 7\n 8\n \n\n* * *"}, {"input": "2 9 100", "output": "2\n 3\n 4\n 5\n 6\n 7\n 8\n 9"}]
Print all the integers that satisfies the condition above in ascending order. * * *
s328172457
Runtime Error
p03386
Input is given from Standard Input in the following format: A B K
A, B, K = [int(x) for x in input().split()] X = list(range(A, B+1))) o = set() for i in X[:K]: print(i) o.add(i) for i in X[-K:]: if i not in o: print(i)
Statement Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
[{"input": "3 8 2", "output": "3\n 4\n 7\n 8\n \n\n * 3 is the first smallest integer among the integers between 3 and 8.\n * 4 is the second smallest integer among the integers between 3 and 8.\n * 7 is the second largest integer among the integers between 3 and 8.\n * 8 is the first largest integer among the integers between 3 and 8.\n\n* * *"}, {"input": "4 8 3", "output": "4\n 5\n 6\n 7\n 8\n \n\n* * *"}, {"input": "2 9 100", "output": "2\n 3\n 4\n 5\n 6\n 7\n 8\n 9"}]
Print all the integers that satisfies the condition above in ascending order. * * *
s980045812
Runtime Error
p03386
Input is given from Standard Input in the following format: A B K
a,b,c=map(int,input().split()) d=c+1 e=b-a f=0 g=0 if d==e: while e>f: print(a) a+=1 f+=1 else: while c>f: print(a) a+=1 f+=1 while c>g: print(b-1) b+=1 g+=1
Statement Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
[{"input": "3 8 2", "output": "3\n 4\n 7\n 8\n \n\n * 3 is the first smallest integer among the integers between 3 and 8.\n * 4 is the second smallest integer among the integers between 3 and 8.\n * 7 is the second largest integer among the integers between 3 and 8.\n * 8 is the first largest integer among the integers between 3 and 8.\n\n* * *"}, {"input": "4 8 3", "output": "4\n 5\n 6\n 7\n 8\n \n\n* * *"}, {"input": "2 9 100", "output": "2\n 3\n 4\n 5\n 6\n 7\n 8\n 9"}]
Print all the integers that satisfies the condition above in ascending order. * * *
s584490445
Runtime Error
p03386
Input is given from Standard Input in the following format: A B K
#coding:utf-8 n=[int(i) for i in input().split()] if(n[1]-n[0]<=2*n[2]): for i in range(n[0],n[1]): print(i) else: for j in range(n[0],n[0]+n[2]): print(j) for k jn range(n[1]-n[2]+1,n[1]): print(k)
Statement Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
[{"input": "3 8 2", "output": "3\n 4\n 7\n 8\n \n\n * 3 is the first smallest integer among the integers between 3 and 8.\n * 4 is the second smallest integer among the integers between 3 and 8.\n * 7 is the second largest integer among the integers between 3 and 8.\n * 8 is the first largest integer among the integers between 3 and 8.\n\n* * *"}, {"input": "4 8 3", "output": "4\n 5\n 6\n 7\n 8\n \n\n* * *"}, {"input": "2 9 100", "output": "2\n 3\n 4\n 5\n 6\n 7\n 8\n 9"}]
Print all the integers that satisfies the condition above in ascending order. * * *
s054920996
Runtime Error
p03386
Input is given from Standard Input in the following format: A B K
a,b,k=map(int,input()split()) ans = [] for i in range(a,a+k+1): if i>b: break ans.append(i) for i in range(b,b-k-1,-1): if i<a: break ans.append(i) ans = sorted(list(set(ans))) for i in ans: print(ans)
Statement Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
[{"input": "3 8 2", "output": "3\n 4\n 7\n 8\n \n\n * 3 is the first smallest integer among the integers between 3 and 8.\n * 4 is the second smallest integer among the integers between 3 and 8.\n * 7 is the second largest integer among the integers between 3 and 8.\n * 8 is the first largest integer among the integers between 3 and 8.\n\n* * *"}, {"input": "4 8 3", "output": "4\n 5\n 6\n 7\n 8\n \n\n* * *"}, {"input": "2 9 100", "output": "2\n 3\n 4\n 5\n 6\n 7\n 8\n 9"}]
Print all the integers that satisfies the condition above in ascending order. * * *
s537294236
Runtime Error
p03386
Input is given from Standard Input in the following format: A B K
def solve(): a,b,k = map(int,input().split()) li = list(range(a,b+1)) if b - a + 1 >= 2 * k: for i in li[:k]: print(i) for i in li[-k:]: print(i) else: for i in li: print(i) if __name __ == "__main__": solve()
Statement Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
[{"input": "3 8 2", "output": "3\n 4\n 7\n 8\n \n\n * 3 is the first smallest integer among the integers between 3 and 8.\n * 4 is the second smallest integer among the integers between 3 and 8.\n * 7 is the second largest integer among the integers between 3 and 8.\n * 8 is the first largest integer among the integers between 3 and 8.\n\n* * *"}, {"input": "4 8 3", "output": "4\n 5\n 6\n 7\n 8\n \n\n* * *"}, {"input": "2 9 100", "output": "2\n 3\n 4\n 5\n 6\n 7\n 8\n 9"}]
Print all the integers that satisfies the condition above in ascending order. * * *
s971546538
Runtime Error
p03386
Input is given from Standard Input in the following format: A B K
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define PI 3.141592653589793 #define MOD 1000000007 typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); int a,b,k; cin >> a >> b >> k; for(int i = a; i < min(a+k, b+1); ++i) cout << i << endl; for(int i = max(b-k+1, a+k); i <= b; ++i) cout << i << endl; return 0; }
Statement Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
[{"input": "3 8 2", "output": "3\n 4\n 7\n 8\n \n\n * 3 is the first smallest integer among the integers between 3 and 8.\n * 4 is the second smallest integer among the integers between 3 and 8.\n * 7 is the second largest integer among the integers between 3 and 8.\n * 8 is the first largest integer among the integers between 3 and 8.\n\n* * *"}, {"input": "4 8 3", "output": "4\n 5\n 6\n 7\n 8\n \n\n* * *"}, {"input": "2 9 100", "output": "2\n 3\n 4\n 5\n 6\n 7\n 8\n 9"}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s871556720
Accepted
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math # from math import gcd import bisect from collections import defaultdict from collections import deque from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int, input().split())) def SL(): return list(map(str, input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg) return def Y(): print("Yes") return def N(): print("No") return def E(): exit() def PE(arg): print(arg) exit() def YE(): print("Yes") exit() def NE(): print("No") exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors #####MakePrimes###### def make_primes(N): max = int(math.sqrt(N)) seachList = [i for i in range(2, N + 1)] primeNum = [] while seachList[0] <= max: primeNum.append(seachList[0]) tmp = seachList[0] seachList = [i for i in seachList if i % tmp != 0] primeNum.extend(seachList) return primeNum #####GCD##### def gcd(a, b): while b: a, b = b, a % b return a #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X // n: return base_10_to_n(X // n, n) + [X % n] return [X % n] def base_n_to_10(X, n): return sum(int(str(X)[-i - 1]) * n**i for i in range(len(str(X)))) #####IntLog##### def int_log(n, a): count = 0 while n >= a: n //= a count += 1 return count ############# # Main Code # ############# N, A = IL() X = IL() X = [x - A for x in X] X.sort() pl = bisect.bisect_left(X, 0) pr = bisect.bisect_right(X, 0) MINUS = X[:pl] ZERO = X[pl:pr] PLUS = X[pr:] dpM = [[0 for j in range(3000)] for i in range(len(MINUS) + 1)] dpP = [[0 for j in range(3000)] for i in range(len(PLUS) + 1)] dpM[0][0] = 1 dpP[0][0] = 1 for i in range(len(MINUS)): x = abs(MINUS[i]) for j in range(3000): if j + x < 3000: dpM[i + 1][j + x] = dpM[i][j] dpM[i + 1][j] += dpM[i][j] for i in range(len(PLUS)): x = abs(PLUS[i]) for j in range(3000): if j + x < 3000: dpP[i + 1][j + x] = dpP[i][j] dpP[i + 1][j] += dpP[i][j] ans = 0 for i in range(1, 3000): ans += dpM[-1][i] * dpP[-1][i] print(ans * pow(2, len(ZERO)) + pow(2, len(ZERO)) - 1)
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s969695415
Accepted
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
( n, a, ) = map(int, input().split()) x = list(map(lambda y: int(y) - a, input().split())) w = 2 * n * (max(max(x), a)) dp = [[0] * (w + 1) for _ in range(n + 1)] dp[0][w // 2] = 1 for i in range(1, n + 1): for j in range(w + 1): dp[i][j] = dp[i - 1][j] + ( dp[i - 1][j - x[i - 1]] if 0 <= j - x[i - 1] <= w else 0 ) print(dp[n][w // 2] - 1)
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s427893576
Accepted
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
f = lambda: map(int, input().split()) n, a = f() l = [i - a for i in f()] dp = [[0] * 5000 for _ in range(51)] Z = 2500 dp[0][Z] = 1 for i in range(n): for s in range(5000 - max(l[i], 0)): dp[i + 1][s] += dp[i][s] dp[i + 1][s + l[i]] += dp[i][s] print(dp[n][Z] - 1)
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s202194852
Runtime Error
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
[n, a] = list(map(int, input().split())) xlist = list(map(int, input().split())) xlist.sort() for i in range(n): ave = a * i dp = [-1 for j in range(ave + 1)] dp[0] = 1 for k in xlist: for l in range(len(xlist)): if dp[l] != -1 and l + k <= ave: if dp[l + k] == -1: dp[l + k] = 0 dp[l + k] += dp[l] ans += dp[-1] print(ans)
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s440582717
Runtime Error
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
def main() N,A = map(int, input().split()) x = list(map(int, input().split())) for i in range(1,1 << len(x)): total = [] for j in range(len(x)): if ((i >> j) & 1): total.append(x[j]) if len(total): if (sum(total)/len(total)) == A: count += 1 print(count) main()
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s807473449
Runtime Error
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
n, a = map(int, input().split()) xs = list(map(int, input().split())) dp = [[0]*2501] * 51 for x in xs: dp[1][x] = 1 for i in range(2,n+1): for j in range(1,2501): for x in xs[i-1:] dp[i][j] = dp[i-1][j-x] ans = 0 for ys in dp: ans += ys[n*a] print(ans)
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s597159813
Accepted
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
n, a = map(int, input().split(" ")) list_x = [int(x) - a for x in input().split(" ")] counts = [{} for i in range(n + 1)] counts[0][0] = 1 for i, x in enumerate(list_x): for v in counts[i]: c = counts[i][v] if v not in counts[i + 1]: counts[i + 1][v] = 0 counts[i + 1][v] += c if v + x not in counts[i + 1]: counts[i + 1][v + x] = 0 counts[i + 1][v + x] += c print(counts[n][0] - 1)
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s536350045
Runtime Error
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
n, a = map(int,input().split()) x = list(map(int,input().split())) xx = [] for i in range(n): xx.append(x-a) X = max(xx) #dp def dp(j,t,l=xx): if j = 0 and t = n * X: return 1 elif j > 0 and t -l[j] < 0 or t- l[j] > 2* n * X: return dp(j-1,t,l=xx) elif j > 1 and 0 <= t-l[j] <= 2*n*X: return dp(j-1,t,l = xx) + dp(j-1,t-l[j],l = xx) else: return 0 print(dp(n,n*X,l=xx) - 1)
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s240672931
Runtime Error
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
def main(): n,a,*x=map(int,open(0).read().split()) x=[0]+x dp=[[[0]*(50*n+1)for j in range(n+1)]for i in range(n+1)] dp[0][0][0]=1 for i in range(1,n+1): dp[i][0]=dp[i-1][0] for j in range(1,n+1): for k in range(1,50*n+1): dp[i][j][k]=dp[i-1][j][k] if k-x[i]>=0: dp[i][j][k]+=dp[i-1][j-1][k-x[i]] ans=0 for i in range(1,n+1): j=i*a if j<50*n+2: ans+=dp[-1][i][j] print(ans) def __name__=='__main__': main()
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s038920162
Accepted
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
# 正負で分割 # dpの作り方はARCの方の人のロジックを参考にした。 # こんなんでええんや... def 解(): iN, iA = [int(x) for x in input().split()] aX = [int(x) - iA for x in input().split()] aPlus = [x for x in aX if 0 < x] aMinus = [-1 * x for x in aX if x < 0] iLenPlus = len(aPlus) iLenMinus = len(aMinus) iLen0 = iN - iLenPlus - iLenMinus iCZero = 2**iLen0 # sum(k=1..N){nCk} = 2^n -1 #1は組み合わせ0の場合 iRet = 0 iUlim = min(sum(aPlus), sum(aMinus)) if 0 < iUlim: dp1 = {0: 1} for iX in aPlus: for k, v in dp1.copy().items(): dp1[k + iX] = dp1.get(k + iX, 0) + v dp2 = {0: 1} for iX in aMinus: for k, v in dp2.copy().items(): dp2[k + iX] = dp2.get(k + iX, 0) + v for i in range(1, iUlim + 1): if i in dp1 and i in dp2: iRet += dp1[i] * dp2[i] print((iRet + 1) * iCZero - 1) # 組み合わせ0の場合を引く 解()
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s662166796
Runtime Error
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
def app(numlist, A): counter = 0 N = len(numlist) for i in range(1, N): counter += f(numlist, i, A * i) return counter def f(numlist, rest, sum): result = 0 numset = set(numlist) if rest == 1: return numlist.count(sum) elif rest == 2: for big in numset: if (sum - big in numset) and (big >= sum - big): result += counter(numlist, big, sum - big) return result else: for i in numset: i_place = numlist.index(i) result += f(numlist[i_place + 1 :], rest - 1, sum - i) return result def counter(numlist, big, small): hist = mkhist(numlist) if big == small: N = hist[big] return N * (N - 1) / 2 else: big_N = hist[big] small_N = hist[small] return big_N * small_N def mkhist(numlist): hist = dict() for char in numlist: if not char in hist.keys(): hist[char] = 1 else: hist[char] += 1 return hist N, A = input() inputs = input() inputnum = map(int, inputs.split(" ")) inputnum = sorted(list(inputnum)) print(app(inputnum, A))
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s557245995
Runtime Error
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
import itertools↲ ↲ n, a = map(int, input().split())↲ array = [int(x) for x in input().split()]↲ ↲ array2 = []↲ tmp = 0↲ for i in array:↲ tmp += i↲ array2.append(tmp)↲ ↲ ans = 0↲ for pickup in range(1, n+1):↲ tmp_gen = itertools.combinations(array, pickup)↲ for i in tmp_gen:↲ if sum(i) == a*pickup:↲ ans += 1↲ print(ans)↲
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s716220110
Runtime Error
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
#include <bits/stdc++.h> #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--) #define REP(i,n) for(int i=0;i<(n);i++) #define RREP(i,n) for(int i=n-1;i>=0;i--) #define PB push_back #define MP make_pair #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define CLR(a) memset(a,0,sizeof(a)) #define SET(a,c) memset(a,c,sizeof(a)) #define DEBUG(x) cout<< #x <<": "<<x<<endl using namespace std; typedef long long int ll; typedef vector<int> vi; typedef vector<ll> vl; const ll INF = INT_MAX/3; const ll MOD = 1000000007; const double EPS = 1e-14; const int dx[] = {1,0,-1,0} , dy[] = {0,1,0,-1}; ll dp[51][51][2601]; int main(){ int N,A,NX,x[51]; cin >> N >> A; REP(i,N) cin >> x[i]; NX = N * 50; dp[0][0][0] = 1; REP(i,N)REP(j,N)REP(k,NX){ dp[i+1][j+1][k+x[i]] += dp[i][j][k]; dp[i+1][j][k] += dp[i][j][k]; } ll ans = 0; FOR(i,1,N+1) ans += dp[N][i][A*i]; cout << ans << endl; return 0; }
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s867332192
Wrong Answer
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
import sys n, a = map(int, input().split()) x = [int(x) for x in input().split()] x_small = [] x_big = [] count = 0 for v in x: if v == a: count += 1 elif v > a: x_big.append(v - a) else: x_small.append(a - v) key = 0 k = 1 for v in range(count, 0, -1): k *= v k //= count - v + 1 key += k if not x_big or not x_small: print(key) sys.exit() x_big_size = len(x_big) * (max(x) - a + 1) x_small_size = len(x_small) * a + 1 x_big_sub = [0] * (x_big_size) x_small_sub = [0] * (x_small_size) for i in range(len(x_big)): for j in range(x_big_size - 1, -1, -1): if j == 0 or x_big_sub[j]: if j + x_big[i] <= x_big_size: x_big_sub[j + x_big[i]] += 1 for i in range(len(x_small)): for j in range(x_small_size - 1, -1, -1): if j == 0 or x_small_sub[j]: if j + x_small[i] <= x_small_size: x_small_sub[j + x_small[i]] += 1 sub = [] for i in range(min([len(x_small_sub), len(x_big_sub)])): v = x_small_sub[i] * x_big_sub[i] if v: sub.append(v) for i in range(len(sub)): k = 1 for j in range(i): k += sub[j] sub[i] *= k sub_sum = sum(sub) ans = (sub_sum + 1) * (key + 1) - 1 print(ans)
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s332872127
Runtime Error
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
import sys import heapq import re from itertools import permutations from bisect import bisect_left, bisect_right from collections import Counter, deque from fractions import gcd from math import factorial, sqrt from functools import lru_cache, reduce INF = 1 << 60 mod = 1000000007 sys.setrecursionlimit(10 ** 7) # UnionFind class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) # ダイクストラ def dijkstra_heap(s, edge, n): #始点sから各頂点への最短距離 d = [10**20] * n used = [True] * n #True:未確定 d[s] = 0 used[s] = False edgelist = [] for a,b in edge[s]: heapq.heappush(edgelist,a*(10**6)+b) while len(edgelist): minedge = heapq.heappop(edgelist) #まだ使われてない頂点の中から最小の距離のものを探す if not used[minedge%(10**6)]: continue v = minedge%(10**6) d[v] = minedge//(10**6) used[v] = False for e in edge[v]: if used[e[1]]: heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1]) return d # 素因数分解 def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr # 2数の最小公倍数 def lcm(x, y): return (x * y) // gcd(x, y) # リストの要素の最小公倍数 def lcm_list(numbers): return reduce(lcm, numbers, 1) # リストの要素の最大公約数 def gcd_list(numbers): return reduce(gcd, numbers) # ここから書き始める n, a = map(int, input().split()) x = list(map(int, input().split())) if n == 1: if x[0] == a: print(1) else: print(0) else: for i in range(n): x[i] -= a # x.sort() dp = [[0 for j in range(99)] for i in range(n)] # print(dp) for i in range(n): if i == 0: dp[i][49] = 1 dp[i][x[i] + 49] += 1 continue for j in range(99): dp[i][j] = dp[i - 1][j] if 0 <= j - x[i] <= 98: dp[i][j] += dp[i - 1][j - x[i]] ans = dp[-1][49] # for i in range(n): # print(dp[i]) print(ans - 1)
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s387980180
Runtime Error
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
num,ave = map(int,input().split()) numx = list(map(int,input().split())) L = len(numx) numy = [0] * L for i in range(L): numy[i] = numx[i] - ave if abs(min(numy)) < abs(max(numy)): maxX = max(numy) else: maxX = abs(min(numy)) dp = [[0]*(2*maxX*L+1) for _ in range(L+1)] dp[0][maxX*L] = 1 for i in range(L): for j in range(2*maxX*L+1): if (j-numy[i]) < 0 or (j - numy[i]) > 2*maxX*L: dp[i+1][j] = dp[i][j] else dp[i+1][j] = dp[i][j] + dp[i][j-numy[i]] print(dp[L][maxX*L]-1)
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s796312645
Runtime Error
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
N, A = map(int, input().split()) x = list(map(int, input().split())) tmp_max = max(x) tmp_max = max(tmp_max, A) dp = [[[0 for _ in range(tmp_max * N + 1)] for _ in range(N + 1)] for _ i range(N + 1)] dp[0][0][0] = 0 for j in range(n + 1): for k in range(j + 1): for s in range(tmp_max * K + 1): if j >= 1 and s < x[j - 1]: dp[j][k][s] = dp[j - 1][k][s] elif j >= 1 and k >= 1 and s >= x[j - 1]: dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j - 1]] ans = 0 for k in range(1, n + 1): ans += dp[N][k][k * A] print(ans)
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s093133722
Wrong Answer
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
n, a = map(int, input().split()) l = [] for i in map(int, input().split()): l.append(i - a) l.sort() pl = sorted([i for i in l if i > 0]) ml = sorted([-i for i in l if i < 0]) M = min(sum(pl), sum(ml)) dpp = [0] * (M + 1) dpm = [0] * (M + 1) s = 1 for i in pl: for j in range(s): if i + j <= M: dpp[i + j] += dpp[j] + 1 else: break s += i s = 1 for i in ml: for j in range(s): if i + j <= M: dpm[i + j] += dpm[j] + 1 else: break s += i ans = 0 for i in range(1, M + 1): ans += dpp[i] * dpm[i] z_cnt = l.count(0) print(ans * pow(2, z_cnt) + int(pow(2, z_cnt)) - 1)
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s816233047
Runtime Error
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
N, A = map(int, input().split()) x = list(map(int, input().split())) tmp_max = max(x) tmp_max = max(tmp_max, A) dp = [[[0 for _ in range(tmp_max * N + 1)] for _ in range(N + 1)] for _ i range(N + 1)] dp[0][0][0] = 0 for j in range(N + 1): for k in range(j + 1): for s in range(tmp_max * K + 1): if j >= 1 and s < x[j - 1]: dp[j][k][s] = dp[j - 1][k][s] elif j >= 1 and k >= 1 and s >= x[j - 1]: dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j - 1]] ans = 0 for k in range(1, N + 1): ans += dp[N][k][k * A] print(ans)
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s241452792
Wrong Answer
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
n, a = map(int, input().split()) x = list(map(int, input().split())) for i in range(n): x[i] = x[i] - a n2 = n // 8 n3 = n - n2 * 8 # n2=n//4 # n3=n-n2*4 y1 = [] y2 = [] y3 = [] y4 = [] y5 = [] y6 = [] y7 = [] y8 = [] for i in range(n2): y1.append(x[i]) y2.append(x[i + n2]) y3.append(x[i + n2 * 2]) y4.append(x[i + n2 * 3]) y5.append(x[i + n2 * 4]) y6.append(x[i + n2 * 5]) y7.append(x[i + n2 * 6]) y8.append(x[i + n2 * 7]) y9 = [] for i in range(n3): y9.append(x[i + n2 * 4]) # itertools 使用 bit全探索 import itertools def xdic(n2, xx): xsum = dict() for i in itertools.product([0, 1], repeat=n2): isum = 0 for ii in range(n2): if i[ii] == 0: isum = isum + xx[ii] if isum in xsum: xsum[isum] = xsum[isum] + 1 else: xsum[isum] = 1 return xsum xsum1 = xdic(n2, y1) xsum2 = xdic(n2, y2) xsum3 = xdic(n2, y3) xsum4 = xdic(n2, y4) xsum5 = xdic(n2, y5) xsum6 = xdic(n2, y6) xsum7 = xdic(n2, y7) xsum8 = xdic(n2, y8) xsum9 = xdic(n3, y9) # xsum[0]=xsum[0] # print(xsum) icnt = 0 for xs1 in xsum1.items(): for xs2 in xsum2.items(): for xs3 in xsum3.items(): for xs4 in xsum4.items(): for xs5 in xsum5.items(): for xs6 in xsum6.items(): for xs7 in xsum7.items(): for xs8 in xsum8.items(): for xs9 in xsum9.items(): if ( xs1[0] + xs2[0] + xs3[0] + xs4[0] + xs5[0] + xs6[0] + xs7[0] + xs8[0] + xs9[0] == 0 ): icnt = ( icnt + xs1[1] * xs2[1] * xs3[1] * xs4[1] * xs5[1] * xs6[1] * xs7[1] * xs8[1] * xs9[1] ) print(icnt - 1)
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s775021720
Accepted
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
def solve(): def recur(i, n, total): # print("i, n, total", i, n, total) if not TABLE[i][n][total] == -1: return TABLE[i][n][total] if not i < N: if n > 0 and total == A * n: TABLE[i][n][total] = 1 return TABLE[i][n][total] TABLE[i][n][total] = 0 return TABLE[i][n][total] ans1 = recur(i + 1, n, total) ans2 = recur(i + 1, n + 1, total + XS[i]) # print(ans1, ans2) TABLE[i][n][total] = ans1 + ans2 return TABLE[i][n][total] N, A = tuple(map(int, input().split())) XS = tuple(map(int, input().split())) TABLE = [] for _ in range(N + 1): lines = [[-1 for x in range(N * 50 + 1)] for y in range(N + 1)] TABLE.append(lines) return recur(0, 0, 0) if __name__ == "__main__": print(solve())
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s372821726
Accepted
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
from subprocess import * call( ( "pypy3", "-c", """ n,a,*x=map(int,open(0).read().split()) x=[0]+x dp=[[[0]*(50*n+1)for j in range(n+1)]for i in range(n+1)] dp[0][0][0]=1 for i in range(1,n+1): dp[i][0]=dp[i-1][0] for j in range(1,n+1): for k in range(1,50*n+1): dp[i][j][k]=dp[i-1][j][k] if k-x[i]>=0: dp[i][j][k]+=dp[i-1][j-1][k-x[i]] ans=0 for i in range(1,n+1): j=i*a if j<50*n+2: ans+=dp[-1][i][j] print(ans) """, ) )
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s583388281
Accepted
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
# python3.4.2用 import math import fractions import bisect import collections import itertools import heapq import string import sys import copy from decimal import * from collections import deque sys.setrecursionlimit(10**7) MOD = 10**9 + 7 INF = float("inf") # 無限大 def gcd(a, b): return fractions.gcd(a, b) # 最大公約数 def lcm(a, b): return (a * b) // fractions.gcd(a, b) # 最小公倍数 def iin(): return int(sys.stdin.readline()) # 整数読み込み def ifn(): return float(sys.stdin.readline()) # 浮動小数点読み込み def isn(): return sys.stdin.readline().split() # 文字列読み込み def imn(): return map(int, sys.stdin.readline().split()) # 整数map取得 def imnn(): return map(lambda x: int(x) - 1, sys.stdin.readline().split()) # 整数-1map取得 def fmn(): return map(float, sys.stdin.readline().split()) # 浮動小数点map取得 def iln(): return list(map(int, sys.stdin.readline().split())) # 整数リスト取得 def iln_s(): return sorted(iln()) # 昇順の整数リスト取得 def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得 def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得 def join(l, s=""): return s.join(l) # リストを文字列に変換 def perm(l, n): return itertools.permutations(l, n) # 順列取得 def perm_count(n, r): return math.factorial(n) // math.factorial(n - r) # 順列の総数 def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得 def comb_count(n, r): return math.factorial(n) // ( math.factorial(n - r) * math.factorial(r) ) # 組み合わせの総数 def two_distance(a, b, c, d): return ((c - a) ** 2 + (d - b) ** 2) ** 0.5 # 2点間の距離 def m_add(a, b): return (a + b) % MOD def lprint(l): print(*l, sep="\n") def sieves_of_e(n): is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return is_prime # ABC044-C # N枚のカードがあり、i番目(1<i<N)番目のカードには整数x(i)が書かれている # カードを一枚以上選び、選んだカードの平均をAとしたい # このような選び方は何通りあるか # 三次元配列を用いたdpを行う。計算量はO(N^3*X) N, A = imn() x = iln() # 数値の最大値 X = 50 # dp[i][j][k]とする # xの中からj枚を選んで、x(i)の合計をkにするような選び方の総数 dp = [[[0 for _ in range(N * X + 1)] for _ in range(N + 1)] for _ in range(N + 1)] dp[0][0][0] = 1 for j in range(N): for k in range(N): for s in range(N * X + 1): # 選択したカードの数値がS未満の場合 if s - x[j] < 0: # 選択できないので、前回値をそのまま移行 dp[j + 1][k][s] = dp[j][k][s] else: # 選択した場合の値は下記の2値を加算 # 1.dp[j][k+1][s]は今回選択してないが、既に合計がsのなる場合の数 # 2.dp[j][k][s-x[j]]は今回選択することにより、合計がsとなる場合の数 dp[j + 1][k + 1][s] = dp[j][k + 1][s] + dp[j][k][s - x[j]] ans = 0 for i in range(1, N + 1): # 合計が選んだカード数*平均値となっている場合の数を加算 ans += dp[N][i][i * A] print(ans)
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s512413085
Wrong Answer
p04013
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
N, A = map(int, input().split()) x = sorted(list(map(int, input().split()))) xn = [x[i] - A for i in range(len(x)) if x[i] < A] xn.reverse() x0 = [0 for i in range(len(xn), len(x)) if x[i] == A] xp = [x[i] - A for i in range(len(xn) + len(x0), len(x)) if x[i] > A] sxn = [0] sxn_n = [1] for x in xn: sxn_add = [] sxn_n_i = [] for j in range(len(sxn)): sxn_tmp = sxn[j] + x for k in range(len(sxn)): if sxn[k] <= sxn_tmp or k == len(sxn) - 1: if sxn[k] == sxn_tmp: sxn_n_i.append([k, sxn_n[j]]) elif sxn[k] < sxn_tmp: sxn_add.append([k, sxn_tmp, sxn_n[j]]) else: sxn_add.append([k + 1, sxn_tmp, sxn_n[j]]) break for k in range(len(sxn_add)): sxn.insert(k + sxn_add[k][0], sxn_add[k][1]) sxn_n.insert(k + sxn_add[k][0], 1) for l in sxn_n_i: sxn_n[l[0]] += l[1] sxp = [0] sxp_n = [1] for x in xp: sxp_add = [] sxp_n_i = [] for j in range(len(sxp)): sxp_tmp = sxp[j] + x for k in range(len(sxp)): if sxp[k] >= sxp_tmp or k == len(sxp) - 1: if sxp[k] == sxp_tmp: sxp_n_i.append([k, sxp_n[j]]) elif sxp[k] > sxp_tmp: sxp_add.append([k, sxp_tmp, sxp_n[j]]) else: sxp_add.append([k + 1, sxp_tmp, sxp_n[j]]) break for k in range(len(sxp_add)): sxp.insert(k + sxp_add[k][0], sxp_add[k][1]) sxp_n.insert(k + sxp_add[k][0], sxp_add[k][2]) for l in sxp_n_i: sxp_n[l[0]] += l[1] an = 0 for i in range(1, len(sxp)): for j in range(1, len(sxn)): if sxp[i] == -sxn[j]: an += sxp_n[i] * sxn_n[j] break print(2 ** len(x0) - 1 + an * 2 ** (len(x0)))
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print an integer representing the minimum number of operations needed. * * *
s046708245
Runtime Error
p02597
Input is given from Standard Input in the following format: N c_{1}c_{2}...c_{N}
N = int(input()) S = input() WPrefix = [0] RSuffix = [0] for elem in S: if elem == "R": RSuffix += 1 for elem in S: if elem == "R": RSuffix.append(RSuffix[-1] - 1) WPrefix.append(WPrefix[-1]) else: RSuffix.append(RSuffix[-1]) WPrefix.append(WPrefix[-1] + 1) minSwap = len(S) for index in range(len(RSuffix)): if max(RSuffix[index], WPrefix[index]) < minSwap: minSwap = max(RSuffix[index], WPrefix[index]) print(minSwap)
Statement An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white. You can do the following two kinds of operations any number of times in any order: * Choose two stones (not necessarily adjacent) and swap them. * Choose one stone and change its color (from red to white and vice versa). According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?
[{"input": "4\n WWRR", "output": "2\n \n\nFor example, the two operations below will achieve the objective.\n\n * Swap the 1-st and 3-rd stones from the left, resulting in `RWWR`.\n * Change the color of the 4-th stone from the left, resulting in `RWWW`.\n\n* * *"}, {"input": "2\n RR", "output": "0\n \n\nIt can be the case that no operation is needed.\n\n* * *"}, {"input": "8\n WRWWRWRR", "output": "3"}]
Print an integer representing the minimum number of operations needed. * * *
s246120321
Wrong Answer
p02597
Input is given from Standard Input in the following format: N c_{1}c_{2}...c_{N}
# alter altar length = int(input()) stone = input() red = [0] * (length + 1) white = [0] * (length + 1) [red_num, white_num] = [0, 0] for i in range(1, length + 1): if stone[i - 1] == "W": white_num += 1 if stone[length - i] == "R": red_num += 1 white[i] = white_num red[length - i] = red_num # print(white) # print(red) mini = 200000 for i in range(1, length + 1): trial = max(white[i], red[i]) mini = min(mini, trial) print(mini)
Statement An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white. You can do the following two kinds of operations any number of times in any order: * Choose two stones (not necessarily adjacent) and swap them. * Choose one stone and change its color (from red to white and vice versa). According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?
[{"input": "4\n WWRR", "output": "2\n \n\nFor example, the two operations below will achieve the objective.\n\n * Swap the 1-st and 3-rd stones from the left, resulting in `RWWR`.\n * Change the color of the 4-th stone from the left, resulting in `RWWW`.\n\n* * *"}, {"input": "2\n RR", "output": "0\n \n\nIt can be the case that no operation is needed.\n\n* * *"}, {"input": "8\n WRWWRWRR", "output": "3"}]
Print an integer representing the minimum number of operations needed. * * *
s019643329
Accepted
p02597
Input is given from Standard Input in the following format: N c_{1}c_{2}...c_{N}
N = int(input()) X = list(input()) es = [0, N, 0] def p(X): print(X) def list_change(X): for i in range(N): if X[i] == "W": es[0] = i for j in reversed(range(es[1])): if X[j] == "R": es[1] = j if i < j: X[i] = "R" X[j] = "W" es[2] += 1 break elif j == 0: es[1] = 1 list_change(X) p(es[2])
Statement An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white. You can do the following two kinds of operations any number of times in any order: * Choose two stones (not necessarily adjacent) and swap them. * Choose one stone and change its color (from red to white and vice versa). According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?
[{"input": "4\n WWRR", "output": "2\n \n\nFor example, the two operations below will achieve the objective.\n\n * Swap the 1-st and 3-rd stones from the left, resulting in `RWWR`.\n * Change the color of the 4-th stone from the left, resulting in `RWWW`.\n\n* * *"}, {"input": "2\n RR", "output": "0\n \n\nIt can be the case that no operation is needed.\n\n* * *"}, {"input": "8\n WRWWRWRR", "output": "3"}]
Print an integer representing the minimum number of operations needed. * * *
s510865794
Runtime Error
p02597
Input is given from Standard Input in the following format: N c_{1}c_{2}...c_{N}
def popcount(x): """xの立っているビット数をカウントする関数 (xは64bit整数)""" # 2bitごとの組に分け、立っているビット数を2bitで表現する x = x - ((x >> 1) & 0x5555555555555555) # 4bit整数に 上位2bit + 下位2bit を計算した値を入れる x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F # 8bitごと x = x + (x >> 8) # 16bitごと x = x + (x >> 16) # 32bitごと x = x + (x >> 32) # 64bitごと = 全部の合計 return x & 0x0000007F n = int(input()) data = input() c = 0 countR = 0 mask = 0 for i in range(len(data)): # print(i) # print(data[i]) if i != 0: c = c << 1 ci = data[i] if ci == "R": countR += 1 else: c += 1 for i in range(n - countR): mask += 1 mask = mask << 1 mask = mask << countR - 1 # print(bin(c)) # print(bin(mask)) # print(countR) print(popcount(c & mask))
Statement An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white. You can do the following two kinds of operations any number of times in any order: * Choose two stones (not necessarily adjacent) and swap them. * Choose one stone and change its color (from red to white and vice versa). According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?
[{"input": "4\n WWRR", "output": "2\n \n\nFor example, the two operations below will achieve the objective.\n\n * Swap the 1-st and 3-rd stones from the left, resulting in `RWWR`.\n * Change the color of the 4-th stone from the left, resulting in `RWWW`.\n\n* * *"}, {"input": "2\n RR", "output": "0\n \n\nIt can be the case that no operation is needed.\n\n* * *"}, {"input": "8\n WRWWRWRR", "output": "3"}]
Print an integer representing the minimum number of operations needed. * * *
s006289556
Runtime Error
p02597
Input is given from Standard Input in the following format: N c_{1}c_{2}...c_{N}
n, k = map(int, input().split()) a = list(map(int, input().split())) result = max(a) left = 1 right = result med = left + (right - left) // 2 while left <= right: counter = sum([(x - 1) // med for x in a]) if counter <= k: result = med right = med - 1 else: left = med + 1 med = left + (right - left) // 2 print(result)
Statement An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white. You can do the following two kinds of operations any number of times in any order: * Choose two stones (not necessarily adjacent) and swap them. * Choose one stone and change its color (from red to white and vice versa). According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?
[{"input": "4\n WWRR", "output": "2\n \n\nFor example, the two operations below will achieve the objective.\n\n * Swap the 1-st and 3-rd stones from the left, resulting in `RWWR`.\n * Change the color of the 4-th stone from the left, resulting in `RWWW`.\n\n* * *"}, {"input": "2\n RR", "output": "0\n \n\nIt can be the case that no operation is needed.\n\n* * *"}, {"input": "8\n WRWWRWRR", "output": "3"}]
Print an integer representing the minimum number of operations needed. * * *
s836377799
Accepted
p02597
Input is given from Standard Input in the following format: N c_{1}c_{2}...c_{N}
#!/usr/bin/env python3 #%% for atcoder uniittest use import sys input= lambda: sys.stdin.readline().rstrip() def pin(type=int):return map(type,input().split()) def tupin(t=int):return tuple(pin(t)) def lispin(t=int):return list(pin(t)) #%%code from collections import Counter def resolve(): N,=pin() C=input() X=Counter(C) a=(min(X["R"],X["W"]))#すべての色を変えにしてしまったらいい時 c=list(C) rightlimit_R=-1 for i in range(1,N): if c[-i]=="R": rightlimit_R=N-i break cnt=0 for i in range(N): if c[i]=="W": for j in range(rightlimit_R-1,0,-1): if c[j]=="R": rightlimit_R=j break cnt+=1 if rightlimit_R<=i: break print(min(a,cnt)) #%%submit! resolve()
Statement An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white. You can do the following two kinds of operations any number of times in any order: * Choose two stones (not necessarily adjacent) and swap them. * Choose one stone and change its color (from red to white and vice versa). According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?
[{"input": "4\n WWRR", "output": "2\n \n\nFor example, the two operations below will achieve the objective.\n\n * Swap the 1-st and 3-rd stones from the left, resulting in `RWWR`.\n * Change the color of the 4-th stone from the left, resulting in `RWWW`.\n\n* * *"}, {"input": "2\n RR", "output": "0\n \n\nIt can be the case that no operation is needed.\n\n* * *"}, {"input": "8\n WRWWRWRR", "output": "3"}]
Print an integer representing the minimum number of operations needed. * * *
s975068025
Accepted
p02597
Input is given from Standard Input in the following format: N c_{1}c_{2}...c_{N}
n=int(input()) c=list(input()) w=[i for i, x in enumerate(c) if x == 'W'] r=[i for i, x in enumerate(c) if x == 'R'] wc=len(w) rc=len(r) wt=list(range(rc,wc+rc)) tand = set(w) & set(wt) print(wc-len(tand))
Statement An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white. You can do the following two kinds of operations any number of times in any order: * Choose two stones (not necessarily adjacent) and swap them. * Choose one stone and change its color (from red to white and vice versa). According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?
[{"input": "4\n WWRR", "output": "2\n \n\nFor example, the two operations below will achieve the objective.\n\n * Swap the 1-st and 3-rd stones from the left, resulting in `RWWR`.\n * Change the color of the 4-th stone from the left, resulting in `RWWW`.\n\n* * *"}, {"input": "2\n RR", "output": "0\n \n\nIt can be the case that no operation is needed.\n\n* * *"}, {"input": "8\n WRWWRWRR", "output": "3"}]
Print an integer representing the minimum number of operations needed. * * *
s763853789
Accepted
p02597
Input is given from Standard Input in the following format: N c_{1}c_{2}...c_{N}
N=int(input()) ls=list(input()) left=0 right=N-1 count=0 while True: while left<N and ls[left]=='R': left+=1 while right>0 and ls[right]=='W': right-=1 if left>=right: break left+=1 right-=1 count+=1 print(count)
Statement An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white. You can do the following two kinds of operations any number of times in any order: * Choose two stones (not necessarily adjacent) and swap them. * Choose one stone and change its color (from red to white and vice versa). According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?
[{"input": "4\n WWRR", "output": "2\n \n\nFor example, the two operations below will achieve the objective.\n\n * Swap the 1-st and 3-rd stones from the left, resulting in `RWWR`.\n * Change the color of the 4-th stone from the left, resulting in `RWWW`.\n\n* * *"}, {"input": "2\n RR", "output": "0\n \n\nIt can be the case that no operation is needed.\n\n* * *"}, {"input": "8\n WRWWRWRR", "output": "3"}]
Print an integer representing the minimum number of operations needed. * * *
s562644417
Accepted
p02597
Input is given from Standard Input in the following format: N c_{1}c_{2}...c_{N}
_, C = input(), input() a = C.count("R") print(a - C[:a].count("R"))
Statement An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white. You can do the following two kinds of operations any number of times in any order: * Choose two stones (not necessarily adjacent) and swap them. * Choose one stone and change its color (from red to white and vice versa). According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?
[{"input": "4\n WWRR", "output": "2\n \n\nFor example, the two operations below will achieve the objective.\n\n * Swap the 1-st and 3-rd stones from the left, resulting in `RWWR`.\n * Change the color of the 4-th stone from the left, resulting in `RWWW`.\n\n* * *"}, {"input": "2\n RR", "output": "0\n \n\nIt can be the case that no operation is needed.\n\n* * *"}, {"input": "8\n WRWWRWRR", "output": "3"}]
Print an integer representing the minimum number of operations needed. * * *
s790591385
Accepted
p02597
Input is given from Standard Input in the following format: N c_{1}c_{2}...c_{N}
import sys from collections import Counter def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**19 MOD = 10**9 + 7 EPS = 10**-10 N = INT() A = list(input()) C = Counter(A) ans = 0 for i in range(C["R"]): if A[i] == "W": ans += 1 print(ans)
Statement An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white. You can do the following two kinds of operations any number of times in any order: * Choose two stones (not necessarily adjacent) and swap them. * Choose one stone and change its color (from red to white and vice versa). According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?
[{"input": "4\n WWRR", "output": "2\n \n\nFor example, the two operations below will achieve the objective.\n\n * Swap the 1-st and 3-rd stones from the left, resulting in `RWWR`.\n * Change the color of the 4-th stone from the left, resulting in `RWWW`.\n\n* * *"}, {"input": "2\n RR", "output": "0\n \n\nIt can be the case that no operation is needed.\n\n* * *"}, {"input": "8\n WRWWRWRR", "output": "3"}]
Print an integer representing the minimum number of operations needed. * * *
s133938101
Wrong Answer
p02597
Input is given from Standard Input in the following format: N c_{1}c_{2}...c_{N}
from collections import deque N = int(input()) state = input() newlist = sorted(state) goalstate = "".join(newlist) # print("goal is " + goalstate) # action1 is flippingg R(W) # action2 is changing position of two ones # and goal is no left W to all R # Distinguish if W is left of R uni = 0 for l in range(len(goalstate)): if goalstate[l] == "W": uni = l break def bfs(state, goalstate): cur_state = deque([state]) cou = 0 while cou < 4: cur = cur_state.popleft() if cur == goalstate: return cou break new = list(cur) temp = 0 for i in range(len(goalstate)): if new[i] == "W": temp = i break neow = 0 for j in range(uni - 1, len(goalstate)): if new[j] == "R": neow = j break tempstr = new.pop(temp) temp1str = new.pop(neow - 1) new.insert(neow, tempstr) new.insert(temp, temp1str) nowstr = "".join(new) cur_state.append(nowstr) cou += 1 goal = bfs(state, goalstate) print(goal)
Statement An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white. You can do the following two kinds of operations any number of times in any order: * Choose two stones (not necessarily adjacent) and swap them. * Choose one stone and change its color (from red to white and vice versa). According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?
[{"input": "4\n WWRR", "output": "2\n \n\nFor example, the two operations below will achieve the objective.\n\n * Swap the 1-st and 3-rd stones from the left, resulting in `RWWR`.\n * Change the color of the 4-th stone from the left, resulting in `RWWW`.\n\n* * *"}, {"input": "2\n RR", "output": "0\n \n\nIt can be the case that no operation is needed.\n\n* * *"}, {"input": "8\n WRWWRWRR", "output": "3"}]
Print an integer representing the minimum number of operations needed. * * *
s995514658
Accepted
p02597
Input is given from Standard Input in the following format: N c_{1}c_{2}...c_{N}
n=int(input()) s=input() red=s.count('R') print(red-s[:red].count('R'))
Statement An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white. You can do the following two kinds of operations any number of times in any order: * Choose two stones (not necessarily adjacent) and swap them. * Choose one stone and change its color (from red to white and vice versa). According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?
[{"input": "4\n WWRR", "output": "2\n \n\nFor example, the two operations below will achieve the objective.\n\n * Swap the 1-st and 3-rd stones from the left, resulting in `RWWR`.\n * Change the color of the 4-th stone from the left, resulting in `RWWW`.\n\n* * *"}, {"input": "2\n RR", "output": "0\n \n\nIt can be the case that no operation is needed.\n\n* * *"}, {"input": "8\n WRWWRWRR", "output": "3"}]
Print an integer representing the minimum number of operations needed. * * *
s475290201
Wrong Answer
p02597
Input is given from Standard Input in the following format: N c_{1}c_{2}...c_{N}
N = int(input()) mozi = input() mozi2 = list(mozi) a = len(mozi2) num_w = mozi2.count("W") num_r = mozi2.count("R") list_w2 = mozi2[(a - num_w) :] list_w1 = mozi2[: (a - num_w)] list_r2 = mozi2[(a - num_r) :] list_r1 = mozi2[: (a - num_r)] if num_w <= num_r: if "W" in list_w2: print(list_w1.count("W")) else: print(num_w) else: if "R" in list_r1: print(list_r2.count("R")) else: print(num_r)
Statement An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white. You can do the following two kinds of operations any number of times in any order: * Choose two stones (not necessarily adjacent) and swap them. * Choose one stone and change its color (from red to white and vice versa). According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?
[{"input": "4\n WWRR", "output": "2\n \n\nFor example, the two operations below will achieve the objective.\n\n * Swap the 1-st and 3-rd stones from the left, resulting in `RWWR`.\n * Change the color of the 4-th stone from the left, resulting in `RWWW`.\n\n* * *"}, {"input": "2\n RR", "output": "0\n \n\nIt can be the case that no operation is needed.\n\n* * *"}, {"input": "8\n WRWWRWRR", "output": "3"}]
Print an integer representing the minimum number of operations needed. * * *
s239472707
Accepted
p02597
Input is given from Standard Input in the following format: N c_{1}c_{2}...c_{N}
n = int(input()) rh_list = list(input()) # Rの個数 r_n = rh_list.count("R") # Rの個数までのlist R_list = [] for i in range(r_n): R_list.append(rh_list[i]) # listのr個数 R_r_n = R_list.count("R") print(r_n - R_r_n)
Statement An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white. You can do the following two kinds of operations any number of times in any order: * Choose two stones (not necessarily adjacent) and swap them. * Choose one stone and change its color (from red to white and vice versa). According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?
[{"input": "4\n WWRR", "output": "2\n \n\nFor example, the two operations below will achieve the objective.\n\n * Swap the 1-st and 3-rd stones from the left, resulting in `RWWR`.\n * Change the color of the 4-th stone from the left, resulting in `RWWW`.\n\n* * *"}, {"input": "2\n RR", "output": "0\n \n\nIt can be the case that no operation is needed.\n\n* * *"}, {"input": "8\n WRWWRWRR", "output": "3"}]
Print an integer representing the minimum number of operations needed. * * *
s591901860
Accepted
p02597
Input is given from Standard Input in the following format: N c_{1}c_{2}...c_{N}
import math # import bisect import sys # from collections import Counter input = sys.stdin.readline def inp(): return int(input()) def inlt(): return list(map(int, input().split())) def insr(): s = input() return s[: len(s) - 1] def invr(): return map(int, input().split()) def print_fract(p, q): g = math.gcd(p, q) p //= g q //= g print(str(p) + "/" + str(q)) # list1, list2 = zip(*sorted(zip(list1, list2))) # K = inp() # if K%2 == 0 or K%5 == 0: # print(-1) # else: # i = 7 # while True: # if len(str(i)) == 999982: # break # if i%K == 0: # print(len(str(i))) # break # i = (10*i) + 7 # 777777777777 N = inp() S = insr() print(S[: S.count("R")].count("W"))
Statement An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; `R` stands for red and `W` stands for white. You can do the following two kinds of operations any number of times in any order: * Choose two stones (not necessarily adjacent) and swap them. * Choose one stone and change its color (from red to white and vice versa). According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?
[{"input": "4\n WWRR", "output": "2\n \n\nFor example, the two operations below will achieve the objective.\n\n * Swap the 1-st and 3-rd stones from the left, resulting in `RWWR`.\n * Change the color of the 4-th stone from the left, resulting in `RWWW`.\n\n* * *"}, {"input": "2\n RR", "output": "0\n \n\nIt can be the case that no operation is needed.\n\n* * *"}, {"input": "8\n WRWWRWRR", "output": "3"}]
If \sqrt{a} + \sqrt{b} < \sqrt{c}, print `Yes`; otherwise, print `No`. * * *
s016354046
Wrong Answer
p02743
Input is given from Standard Input in the following format: a \ b \ c
a, b, c = map(int, (input().split())) s = (a**2) + (b**2) + (c**2) - (2 * a * b) - (2 * a * c) - (2 * b * c) print("Yes" if s > 0 else "No")
Statement Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
[{"input": "2 3 9", "output": "No\n \n\n\\sqrt{2} + \\sqrt{3} < \\sqrt{9} does not hold.\n\n* * *"}, {"input": "2 3 10", "output": "Yes\n \n\n\\sqrt{2} + \\sqrt{3} < \\sqrt{10} holds."}]
If \sqrt{a} + \sqrt{b} < \sqrt{c}, print `Yes`; otherwise, print `No`. * * *
s308203274
Wrong Answer
p02743
Input is given from Standard Input in the following format: a \ b \ c
print("No")
Statement Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
[{"input": "2 3 9", "output": "No\n \n\n\\sqrt{2} + \\sqrt{3} < \\sqrt{9} does not hold.\n\n* * *"}, {"input": "2 3 10", "output": "Yes\n \n\n\\sqrt{2} + \\sqrt{3} < \\sqrt{10} holds."}]
If \sqrt{a} + \sqrt{b} < \sqrt{c}, print `Yes`; otherwise, print `No`. * * *
s256469695
Wrong Answer
p02743
Input is given from Standard Input in the following format: a \ b \ c
# coding: utf-8 # Your code here! # coding: utf-8 import sys sys.setrecursionlimit(10000000) # const # my functions here! def pin(type=int): return map(type, input().rstrip().split()) def resolve(): a, b, c = pin() from math import sqrt cond = sqrt(a) + sqrt(b) < sqrt(c) print(["No", "Yes"][cond]) """ #printデバッグ消した? #前の問題の結果見てないのに次の問題に行くの? """ """ お前カッコ閉じるの忘れてるだろ """ import sys from io import StringIO import unittest class TestClass(unittest.TestCase): def assertIO(self, input, output): stdout, stdin = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(input) resolve() sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, stdin self.assertEqual(out, output) def test_入力例_1(self): input = """2 3 9""" output = """No""" self.assertIO(input, output) def test_入力例_2(self): input = """2 3 10""" output = """Yes""" self.assertIO(input, output) if __name__ == "__main__": resolve()
Statement Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
[{"input": "2 3 9", "output": "No\n \n\n\\sqrt{2} + \\sqrt{3} < \\sqrt{9} does not hold.\n\n* * *"}, {"input": "2 3 10", "output": "Yes\n \n\n\\sqrt{2} + \\sqrt{3} < \\sqrt{10} holds."}]
If \sqrt{a} + \sqrt{b} < \sqrt{c}, print `Yes`; otherwise, print `No`. * * *
s938380484
Accepted
p02743
Input is given from Standard Input in the following format: a \ b \ c
import math import fractions import bisect import collections import itertools import heapq import string import sys import copy from decimal import * from collections import deque sys.setrecursionlimit(10**7) MOD = 10**9 + 7 INF = float("inf") # 無限大 def gcd(a, b): return fractions.gcd(a, b) # 最大公約数 def lcm(a, b): return (a * b) // fractions.gcd(a, b) # 最小公倍数 def iin(): return int(sys.stdin.readline()) # 整数読み込み def ifn(): return float(sys.stdin.readline()) # 浮動小数点読み込み def isn(): return sys.stdin.readline().split() # 文字列読み込み def imn(): return map(int, sys.stdin.readline().split()) # 整数map取得 def imnn(): return map(lambda x: int(x) - 1, sys.stdin.readline().split()) # 整数-1map取得 def fmn(): return map(float, sys.stdin.readline().split()) # 浮動小数点map取得 def iln(): return list(map(int, sys.stdin.readline().split())) # 整数リスト取得 def iln_s(): return sorted(iln()) # 昇順の整数リスト取得 def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得 def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得 def join(l, s=""): return s.join(l) # リストを文字列に変換 def perm(l, n): return itertools.permutations(l, n) # 順列取得 def perm_count(n, r): return math.factorial(n) // math.factorial(n - r) # 順列の総数 def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得 def comb_count(n, r): return math.factorial(n) // ( math.factorial(n - r) * math.factorial(r) ) # 組み合わせの総数 def two_distance(a, b, c, d): return ((c - a) ** 2 + (d - b) ** 2) ** 0.5 # 2点間の距離 def m_add(a, b): return (a + b) % MOD def sieves_of_e(n): is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return is_prime a, b, c = imn() ma = Decimal(str(math.sqrt(a))) mb = Decimal(str(math.sqrt(b))) mc = Decimal(str(math.sqrt(c))) da = Decimal(str(a)) db = Decimal(str(b)) dc = Decimal(str(c)) if da.sqrt() + db.sqrt() < dc.sqrt(): print("Yes") else: print("No")
Statement Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
[{"input": "2 3 9", "output": "No\n \n\n\\sqrt{2} + \\sqrt{3} < \\sqrt{9} does not hold.\n\n* * *"}, {"input": "2 3 10", "output": "Yes\n \n\n\\sqrt{2} + \\sqrt{3} < \\sqrt{10} holds."}]
If \sqrt{a} + \sqrt{b} < \sqrt{c}, print `Yes`; otherwise, print `No`. * * *
s122120007
Wrong Answer
p02743
Input is given from Standard Input in the following format: a \ b \ c
a, b, c = list(map(float, input().split())) ar = a**0.5 br = b**0.5 cr = c**0.5 print("Yes") if 2 * ar * br < c - a - b else print("No")
Statement Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
[{"input": "2 3 9", "output": "No\n \n\n\\sqrt{2} + \\sqrt{3} < \\sqrt{9} does not hold.\n\n* * *"}, {"input": "2 3 10", "output": "Yes\n \n\n\\sqrt{2} + \\sqrt{3} < \\sqrt{10} holds."}]
If \sqrt{a} + \sqrt{b} < \sqrt{c}, print `Yes`; otherwise, print `No`. * * *
s373233344
Wrong Answer
p02743
Input is given from Standard Input in the following format: a \ b \ c
#!python3.4 # -*- coding: utf-8 -*- # panasonic2020/panasonic2020_c import sys from math import sqrt s2nn = lambda s: [int(c) for c in s.split(" ")] ss2nn = lambda ss: [int(s) for s in list(ss)] ss2nnn = lambda ss: [s2nn(s) for s in list(ss)] i2s = lambda: sys.stdin.readline().rstrip() i2n = lambda: int(i2s()) i2nn = lambda: s2nn(i2s()) ii2ss = lambda n: [i2s() for _ in range(n)] ii2nn = lambda n: ss2nn(ii2ss(n)) ii2nnn = lambda n: ss2nnn(ii2ss(n)) def main(): a, b, c = i2nn() print("Yes" if sqrt(a) + sqrt(b) < sqrt(c) else "No") return main()
Statement Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
[{"input": "2 3 9", "output": "No\n \n\n\\sqrt{2} + \\sqrt{3} < \\sqrt{9} does not hold.\n\n* * *"}, {"input": "2 3 10", "output": "Yes\n \n\n\\sqrt{2} + \\sqrt{3} < \\sqrt{10} holds."}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s178469335
Runtime Error
p03502
Input is given from Standard Input in the following format: N
import time n=int(input()) x=(n%15)*0.001*100 a=0.037 #time.sleep(x+a) ls=[for i in range((n%100)*10**6)] print('Yes')
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s782894459
Runtime Error
p03502
Input is given from Standard Input in the following format: N
N = int(input()) s = 0 while N//10 > 0 a = N % 10 s += a N = N // 10 if N % s == 0: print("Yes") else: print("No")
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s443368140
Accepted
p03502
Input is given from Standard Input in the following format: N
p = input() print("YNeos"[int(p) % sum(map(int, p)) > 0 :: 2])
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s853635903
Accepted
p03502
Input is given from Standard Input in the following format: N
A = input() nu = int(A) tmp = sum(map(int, list(A))) print("Yes") if nu % tmp == 0 else print("No")
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s099057954
Wrong Answer
p03502
Input is given from Standard Input in the following format: N
n = int(input()) dv = 0 for s in str(n): dv += int(s) print("YES" if n % dv == 0 else "NO")
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s964025520
Accepted
p03502
Input is given from Standard Input in the following format: N
#!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 def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n): l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n): l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n): l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n): l[i] = SR() return l mod = 1000000007 # A def A(): n, a, b = LI() print(min(n * a, b)) return # B def B(): n = list(map(int, S())) s = sum(n) a = 0 for i in n: a *= 10 a += i if a % s == 0: print("Yes") else: print("No") return # C def C(): n = I() f = LIR(n) po = [1] * 11 for i in range(n): k = 0 p = 1 for j in range(10): k += p * f[i][j] p *= 2 po[j + 1] = p f[i] = k p = LIR(n) ans = -float("inf") for i in range(1, 1024): k = 0 for j in range(n): c = i & f[j] s = 0 for l in po: if c & l: s += 1 k += p[j][s] ans = max(ans, k) print(ans) # D def D(): n, C = LI() T = [[0 for i in range(100002)] for j in range(C)] for i in range(n): s, t, c = LI() c -= 1 T[c][s] += 1 T[c][t + 1] -= 1 for c in range(C): for i in range(100000): T[c][i + 1] += T[c][i] ans = 0 for i in range(100000): k = 0 for c in range(C): if T[c][i]: k += 1 ans = max(ans, k) print(ans) # E def E(): return # F def F(): return # G def G(): return # H def H(): return # Solve if __name__ == "__main__": B()
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s907993042
Accepted
p03502
Input is given from Standard Input in the following format: N
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left, bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil, sqrt from operator import itemgetter def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def LI2(): return [int(input()) for i in range(n)] def MXI(): return [[LI()] for i in range(n)] def printns(x): print("\n".join(x)) def printni(x): print("\n".join(list(map(str, x)))) inf = 10**17 mod = 10**9 + 7 # s=input().rstrip() x = input().rstrip() fx = sum(map(int, list(str(x)))) # print(fx) if int(x) % fx == 0: print("Yes") else: print("No")
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s341407714
Accepted
p03502
Input is given from Standard Input in the following format: N
import sys, collections as cl, bisect as bs sys.setrecursionlimit(100000) input = sys.stdin.readline mod = 10**9 + 7 Max = sys.maxsize def l(): # intのlist return list(map(int, input().split())) def m(): # 複数文字 return map(int, input().split()) def onem(): # Nとかの取得 return int(input()) def s(x): # 圧縮 a = [] aa = x[0] su = 1 for i in range(len(x) - 1): if aa != x[i + 1]: a.append([aa, su]) aa = x[i + 1] su = 1 else: su += 1 a.append([aa, su]) return a def jo(x): # listをスペースごとに分ける return " ".join(map(str, x)) def max2(x): # 他のときもどうように作成可能 return max(map(max, x)) def In(x, a): # aがリスト(sorted) k = bs.bisect_left(a, x) if k != len(a) and a[k] == x: return True else: return False """ def nibu(x,n,r): ll = 0 rr = r while True: mid = (ll+rr)//2 if rr == mid: return ll if (ここに評価入れる): rr = mid else: ll = mid+1 """ n = onem() po = str(n) co = 0 for i in po: co += int(i) print("Yes" if n % co == 0 else "No")
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s099106137
Accepted
p03502
Input is given from Standard Input in the following format: N
# # abc080 b # import sys from io import StringIO import unittest class TestClass(unittest.TestCase): def assertIO(self, input, output): stdout, stdin = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(input) resolve() sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, stdin self.assertEqual(out, output) def test_入力例_1(self): input = """12""" output = """Yes""" self.assertIO(input, output) def test_入力例_2(self): input = """57""" output = """No""" self.assertIO(input, output) def test_入力例_3(self): input = """148""" output = """No""" self.assertIO(input, output) def resolve(): N = input() s = 0 for i in range(len(N)): s += int(N[i]) if int(N) % s == 0: print("Yes") else: print("No") if __name__ == "__main__": # unittest.main() resolve()
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s047722906
Wrong Answer
p03502
Input is given from Standard Input in the following format: N
###================================================== ### import # import bisect # from collections import Counter, deque, defaultdict # from copy import deepcopy # from functools import reduce, lru_cache # from heapq import heappush, heappop # import itertools # import math # import string import sys ### stdin def input(): return sys.stdin.readline().rstrip() def iIn(): return int(input()) def iInM(): return map(int, input().split()) def iInM1(): return map(int1, input().split()) def iInLH(): return list(map(int, input().split())) def iInLH1(): return list(map(int1, input().split())) def iInLV(n): return [iIn() for _ in range(n)] def iInLV1(n): return [iIn() - 1 for _ in range(n)] def iInLD(n): return [iInLH() for _ in range(n)] def iInLD1(n): return [iInLH1() for _ in range(n)] def sInLH(): return list(input().split()) def sInLV(n): return [input().rstrip("\n") for _ in range(n)] def sInLD(n): return [sInLH() for _ in range(n)] ### stdout def OutH(lst, deli=" "): print(deli.join(map(str, lst))) def OutV(lst): print("\n".join(map(str, lst))) ### setting sys.setrecursionlimit(10**6) ### utils int1 = lambda x: int(x) - 1 ### constants INF = int(1e9) MOD = 1000000007 dx = (-1, 0, 1, 0) dy = (0, -1, 0, 1) ###--------------------------------------------------- N = iIn() fN = sum(list(map(int, list(str(N))))) ans = "Yes" if N == fN else "No" print(ans)
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s580723896
Wrong Answer
p03502
Input is given from Standard Input in the following format: N
n = int(input()) ni = n x = [] for i in range(10): x.append(n // (10 ** (10 - i))) ni = n % (10 ** (10 - i)) x.append(ni % 10) print("Yes" if n % sum(x) == 0 else "No")
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s263567724
Runtime Error
p03502
Input is given from Standard Input in the following format: N
n=int(input()) st=str(n) sm = 0 for i in st: sm+=int(i) if n%sm==0: print("Yes") else print("No")
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s866707959
Accepted
p03502
Input is given from Standard Input in the following format: N
hoge = input() n = [int(i) for i in hoge] print("Yes" if int(hoge) % sum(n) == 0 else "No")
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s409472042
Accepted
p03502
Input is given from Standard Input in the following format: N
N = int(input()) def summ(X): a = X // 10000000 b = (X - a * 10000000) // 1000000 c = (X - a * 10000000 - b * 1000000) // 100000 d = (X - a * 10000000 - b * 1000000 - c * 100000) // 10000 e = (X - a * 10000000 - b * 1000000 - c * 100000 - d * 10000) // 1000 f = (X - a * 10000000 - b * 1000000 - c * 100000 - d * 10000 - e * 1000) // 100 g = ( X - a * 10000000 - b * 1000000 - c * 100000 - d * 10000 - e * 1000 - f * 100 ) // 10 h = ( X - a * 10000000 - b * 1000000 - c * 100000 - d * 10000 - e * 1000 - f * 100 - g * 10 ) return a + b + c + d + e + f + g + h if N % summ(N) == 0: print("Yes") else: print("No")
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s254872629
Wrong Answer
p03502
Input is given from Standard Input in the following format: N
n = int(input()) f8 = int(n / 10**8) fn = int(n % 10**8) f7 = int(n / 10**7) fn = int(n % 10**7) f6 = int(n / 10**6) fn = int(n % 10**6) f5 = int(n / 10**5) fn = int(n % 10**5) f4 = int(n / 10**4) fn = int(n % 10**4) f3 = int(n / 10**3) fn = int(n % 10**3) f2 = int(n / 10**2) fn = int(n % 10**2) f1 = int(n / 10**1) fn = int(n % 10**1) num = f8 + f7 + f6 + f5 + f4 + f3 + f2 + f1 + fn if n % num == 0: print("Yes") else: print("No")
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s470437583
Runtime Error
p03502
Input is given from Standard Input in the following format: N
)N = int(input()) fx = N total = 0 while fx > 0: total += fx % 10 fx // 10 if N % fx == 0: print('Yes') else: print('No')
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s050810987
Runtime Error
p03502
Input is given from Standard Input in the following format: N
X = input() sum = 0 for i in range(len(x)): sum += int(x[i]) if int(x) % sum == 0 print("Yes") else print("No")
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s605678841
Runtime Error
p03502
Input is given from Standard Input in the following format: N
N = input() f = sum(map(int, N)) print("Yes" int(N) % f == 0 else "No")
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s987125818
Runtime Error
p03502
Input is given from Standard Input in the following format: N
s=input() n=[int(c) for c in s] if int(s)%sum(n)==0: print('Yes') else: print('No')
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s161895580
Runtime Error
p03502
Input is given from Standard Input in the following format: N
A = input() for i in range(A) B = int(A) if A % B == 0 : print("Yes") else: print("No")
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s169073829
Runtime Error
p03502
Input is given from Standard Input in the following format: N
n = map(int, input()) print("Yes" if sum(n) % n == 0 else "No")
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s009416449
Runtime Error
p03502
Input is given from Standard Input in the following format: N
xs = input() xi = int(xs) xs = list(xs) fx = sum(xs) print("Yes" if xi % fx == 0 else "No")
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s008895718
Runtime Error
p03502
Input is given from Standard Input in the following format: N
from statistics import mean, median,variance,stdev import numpy as np import sys import math import fractions def j(q): if q==1: print("Yes") else:print("No") exit(0) def ct(x,y): if (x>y):print("") elif (x<y): print("") else: print("") def ip(): return int(input()) #n = ip() #入力整数1つ #a,b= (int(i) for i in input().split()) #入力整数横2つ #n,x,y= (int(i) for i in input().split()) #入力整数横3つ #n,m,x,y= (int(i) for i in input().split()) #入力整数横4つ #a = [int(i) for i in input().split()] #入力整数配列 a = #input() #入力文字列 #a = input().split() #入力文字配列 #n = ip() #入力セット(整数改行あり)(1/2) #a=[ip() for i in range(n)] #入力セット(整数改行あり)(2/2) #jの変数はしようできないので注意 #全足しにsum変数使用はsum関数使用できないので注意 s = 0 for i in range(len(a))): s+= int(a[0]) j(a%s ==0)
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s415211295
Runtime Error
p03502
Input is given from Standard Input in the following format: N
N = map(int,input().split()) f = sum(list(map(int,str(N)))) if N % f == 0: print("Yes") else: print("No")
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s601375968
Runtime Error
p03502
Input is given from Standard Input in the following format: N
N = int(input()) def if_test: if N % sum(int(input())) == 0: print('Yes') else: print('No')
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s638663379
Runtime Error
p03502
Input is given from Standard Input in the following format: N
N = list(input()) f_N = 0 [f_N += int(i) for i in N] print('Yes') if int(''.join(N))%f_N == 0 else print('No')
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s091608447
Runtime Error
p03502
Input is given from Standard Input in the following format: N
x = input() sum_of_digits = sum(map(int, x)) check = (int)x % sum_of_digits print('No' if check else 'Yes')
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s651575457
Runtime Error
p03502
Input is given from Standard Input in the following format: N
N = map(int,input().split()) fx = sum(list(map(int,str(N)))) if N % fx == 0: print("Yes") else: print("No")
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s366665720
Runtime Error
p03502
Input is given from Standard Input in the following format: N
N = int(input()) if N / sum(int(input())) == 0: print('Yes') else: print('No')
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s606455718
Runtime Error
p03502
Input is given from Standard Input in the following format: N
n=input() i=len(n) n=int(n) m=0 while x>10: m+=x%10 if n%m==0 print("Yes") else: print("No")
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s302628454
Accepted
p03502
Input is given from Standard Input in the following format: N
# Harshad Number print((lambda x: "Yes" if int(x) % sum(map(int, x)) == 0 else "No")(input()))
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s242575107
Runtime Error
p03502
Input is given from Standard Input in the following format: N
def sum_digits(n): s = 0 while n: s += n%10 n //= 10 retun s n = int(input()) ans = "Yes" if n % sum_digits(n) == 0 else "No" print(ans)
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s421382882
Runtime Error
p03502
Input is given from Standard Input in the following format: N
def calc_sum_digits(n): sumd = 0 while(n > 1): sumd += int(n%10) n /= 10 return sumd N = int(input()) sumd = 0 sumd = calc_sum_digits(N) if(N%sumd == 0): print('yes') else: print('No')
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print `Yes` if N is a Harshad number; print `No` otherwise. * * *
s837603218
Accepted
p03502
Input is given from Standard Input in the following format: N
N = input().rstrip() fxs = sum(list(map(int, list(N)))) print("Yes") if (int(N) % fxs == 0) else print("No")
Statement An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
[{"input": "12", "output": "Yes\n \n\nf(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.\n\n* * *"}, {"input": "57", "output": "No\n \n\nf(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.\n\n* * *"}, {"input": "148", "output": "No"}]
Print the number of ways to write the numbers under the conditions, modulo 10^9 + 7. * * *
s530825970
Accepted
p03152
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_{N} B_1 B_2 ... B_{M}
import sys readline = sys.stdin.readline MOD = 10**9 + 7 INF = float("INF") sys.setrecursionlimit(10**5) def main(): N, M = map(int, readline().split()) A = list(map(int, readline().split())) B = list(map(int, readline().split())) A_idx = dict() B_idx = dict() for i, x in enumerate(A, 1): A_idx[x] = i for i, x in enumerate(B, 1): B_idx[x] = i grid = [[0] * (M + 1) for _ in range(N + 1)] def calc(): ans = 1 cnt_r = 0 cnt_c = 0 for i in range(N * M, 0, -1): row = A_idx.get(i) col = B_idx.get(i) cnt = 0 if row and col: cnt_r += 1 cnt_c += 1 if grid[row][col]: return 0 else: grid[row][col] = i cnt = 1 elif row: cnt_r += 1 for j in range(M): if B[j] > i and not (grid[row][j]): cnt += 1 elif col: cnt_c += 1 for j in range(N): if A[j] > i and not (grid[j][col]): cnt += 1 else: cnt = cnt_r * cnt_c - (N * M - i) ans *= cnt ans %= MOD return ans ans = calc() print(ans) if __name__ == "__main__": main()
Statement Consider writing each of the integers from 1 to N \times M in a grid with N rows and M columns, without duplicates. Takahashi thinks it is not fun enough, and he will write the numbers under the following conditions: * The largest among the values in the i-th row (1 \leq i \leq N) is A_i. * The largest among the values in the j-th column (1 \leq j \leq M) is B_j. For him, find the number of ways to write the numbers under these conditions, modulo 10^9 + 7.
[{"input": "2 2\n 4 3\n 3 4", "output": "2\n \n\n(A_1, A_2) = (4, 3) and (B_1, B_2) = (3, 4). In this case, there are two ways\nto write the numbers, as follows:\n\n * 1 in (1, 1), 4 in (1, 2), 3 in (2, 1) and 2 in (2, 2).\n * 2 in (1, 1), 4 in (1, 2), 3 in (2, 1) and 1 in (2, 2).\n\nHere, (i, j) denotes the square at the i-th row and the j-th column.\n\n* * *"}, {"input": "3 3\n 5 9 7\n 3 6 9", "output": "0\n \n\nSince there is no way to write the numbers under the condition, 0 should be\nprinted.\n\n* * *"}, {"input": "2 2\n 4 4\n 4 4", "output": "0\n \n\n* * *"}, {"input": "14 13\n 158 167 181 147 178 151 179 182 176 169 180 129 175 168\n 181 150 178 179 167 180 176 169 182 177 175 159 173", "output": "343772227"}]
Print the number of ways to write the numbers under the conditions, modulo 10^9 + 7. * * *
s162499060
Wrong Answer
p03152
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_{N} B_1 B_2 ... B_{M}
from collections import deque import sys # sys.setrecursionlimit(200000) input = sys.stdin.readline # n = int(input()) n, d = map(int, input().split()) a = list(map(int, input().split())) ans = 0 kore = [] class UnionFind: def __init__(self, size): self.table = [-1 for _ in range(size)] def find(self, x): while self.table[x] >= 0: x = self.table[x] return x def union(self, x, y): s1 = self.find(x) s2 = self.find(y) if s1 != s2: if self.table[s1] != self.table[s2]: if self.table[s1] < self.table[s2]: self.table[s2] = s1 else: self.table[s1] = s2 else: self.table[s1] += -1 self.table[s2] = s1 return kimeta = UnionFind(n) for i in range(n): if i > 0: kore.append([a[i] + d + a[i - 1], i - 1, i]) if i < n - 1: kore.append([a[i] + d + a[i + 1], i + 1, i]) for j in range(i + 2, n): if a[i] + (j - i) * d < a[j - 1] + d: kore.append([a[i] + (j - i) * d + a[j], j, i]) else: break for j in range(i - 2, -1, -1): if a[i] + (i - j) * d < a[j + 1] + d: kore.append([a[i] + (i - j) * d + a[j], j, i]) else: break kore.sort() for i, j, k in kore: if kimeta.find(j) != kimeta.find(k): kimeta.union(j, k) ans += i print(ans)
Statement Consider writing each of the integers from 1 to N \times M in a grid with N rows and M columns, without duplicates. Takahashi thinks it is not fun enough, and he will write the numbers under the following conditions: * The largest among the values in the i-th row (1 \leq i \leq N) is A_i. * The largest among the values in the j-th column (1 \leq j \leq M) is B_j. For him, find the number of ways to write the numbers under these conditions, modulo 10^9 + 7.
[{"input": "2 2\n 4 3\n 3 4", "output": "2\n \n\n(A_1, A_2) = (4, 3) and (B_1, B_2) = (3, 4). In this case, there are two ways\nto write the numbers, as follows:\n\n * 1 in (1, 1), 4 in (1, 2), 3 in (2, 1) and 2 in (2, 2).\n * 2 in (1, 1), 4 in (1, 2), 3 in (2, 1) and 1 in (2, 2).\n\nHere, (i, j) denotes the square at the i-th row and the j-th column.\n\n* * *"}, {"input": "3 3\n 5 9 7\n 3 6 9", "output": "0\n \n\nSince there is no way to write the numbers under the condition, 0 should be\nprinted.\n\n* * *"}, {"input": "2 2\n 4 4\n 4 4", "output": "0\n \n\n* * *"}, {"input": "14 13\n 158 167 181 147 178 151 179 182 176 169 180 129 175 168\n 181 150 178 179 167 180 176 169 182 177 175 159 173", "output": "343772227"}]
Print the number of ways to write the numbers under the conditions, modulo 10^9 + 7. * * *
s878035240
Runtime Error
p03152
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_{N} B_1 B_2 ... B_{M}
#include<cstdio> #include<cstdlib> #include<algorithm> #include<iostream> #include<queue> #include<vector> #include <bitset> #include <cmath> #include <limits> #include <iostream> #include<set> #include<tuple> using namespace std; #define INF 11000000000 #define MAX 100000 #define MOD 1000000007 typedef long long ll; typedef pair<int,int> P; typedef pair<pair<int,int>,int> p; typedef pair< pair<int,int>, int> p; #define bit(n,k) ((n>>k)&1) /*nのk bit目*/ #define rad_to_deg(rad) (((rad)/2/M_PI)*360) //https://atcoder.jp/contests/keyence2019/submissions/4011139 //https://betrue12.hateblo.jp/entry/2019/01/14/023707 //最大の数字から入れていくと上手くいく int main(){ int N,M; cin>>N>>M; vector<int> A(N),B(M); for(int i=0;i<N;i++) cin>>A[i]; for(int i=0;i<M;i++) cin>>B[i]; sort(A.begin(),A.end(),greater<int>()); sort(B.begin(),B.end(),greater<int>()); A.push_back(-1); B.push_back(-1); int apt=0,bpt=0,num=N*M; ll ans=1; while(num>0){ if(A[apt]==num && B[bpt]==num){ apt++; bpt++; }else if(A[apt]==num){ apt++; ans*=bpt; }else if(B[bpt]==num){ bpt++; ans*=apt; }else{ ans=ans*(apt*bpt-(N*M-num)); } ans%=MOD; num--; } cout<<ans<<endl; }
Statement Consider writing each of the integers from 1 to N \times M in a grid with N rows and M columns, without duplicates. Takahashi thinks it is not fun enough, and he will write the numbers under the following conditions: * The largest among the values in the i-th row (1 \leq i \leq N) is A_i. * The largest among the values in the j-th column (1 \leq j \leq M) is B_j. For him, find the number of ways to write the numbers under these conditions, modulo 10^9 + 7.
[{"input": "2 2\n 4 3\n 3 4", "output": "2\n \n\n(A_1, A_2) = (4, 3) and (B_1, B_2) = (3, 4). In this case, there are two ways\nto write the numbers, as follows:\n\n * 1 in (1, 1), 4 in (1, 2), 3 in (2, 1) and 2 in (2, 2).\n * 2 in (1, 1), 4 in (1, 2), 3 in (2, 1) and 1 in (2, 2).\n\nHere, (i, j) denotes the square at the i-th row and the j-th column.\n\n* * *"}, {"input": "3 3\n 5 9 7\n 3 6 9", "output": "0\n \n\nSince there is no way to write the numbers under the condition, 0 should be\nprinted.\n\n* * *"}, {"input": "2 2\n 4 4\n 4 4", "output": "0\n \n\n* * *"}, {"input": "14 13\n 158 167 181 147 178 151 179 182 176 169 180 129 175 168\n 181 150 178 179 167 180 176 169 182 177 175 159 173", "output": "343772227"}]
Print the number of ways to write the numbers under the conditions, modulo 10^9 + 7. * * *
s040845385
Runtime Error
p03152
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_{N} B_1 B_2 ... B_{M}
N,M = map(int,input().split()) A = list(map(int,input()split())) B = list(map(int,input()split())) a = [0 for i in range(N*M+1)] b = [0 for i in range(N*M+1)] mod = 10**9+7 for i in range(N): a[A[i]] += 1 for i in range(M): b[B[i]] += 1 for i in range(1,N*M+1): a[-i-1] += a[-i] b[-i-1] += a[-i] ans = 1 for i in range(N*M): f = 0 g = 0 x = N*M - i y = i if x in A: f += 1 if x in B: g += 1 z = 1 if f == 0: z *= b[x] if g == 0: z *= a[x] z -= i if z <= 0: print(0) quit() else: ans *= z%mod print(ans%mod)
Statement Consider writing each of the integers from 1 to N \times M in a grid with N rows and M columns, without duplicates. Takahashi thinks it is not fun enough, and he will write the numbers under the following conditions: * The largest among the values in the i-th row (1 \leq i \leq N) is A_i. * The largest among the values in the j-th column (1 \leq j \leq M) is B_j. For him, find the number of ways to write the numbers under these conditions, modulo 10^9 + 7.
[{"input": "2 2\n 4 3\n 3 4", "output": "2\n \n\n(A_1, A_2) = (4, 3) and (B_1, B_2) = (3, 4). In this case, there are two ways\nto write the numbers, as follows:\n\n * 1 in (1, 1), 4 in (1, 2), 3 in (2, 1) and 2 in (2, 2).\n * 2 in (1, 1), 4 in (1, 2), 3 in (2, 1) and 1 in (2, 2).\n\nHere, (i, j) denotes the square at the i-th row and the j-th column.\n\n* * *"}, {"input": "3 3\n 5 9 7\n 3 6 9", "output": "0\n \n\nSince there is no way to write the numbers under the condition, 0 should be\nprinted.\n\n* * *"}, {"input": "2 2\n 4 4\n 4 4", "output": "0\n \n\n* * *"}, {"input": "14 13\n 158 167 181 147 178 151 179 182 176 169 180 129 175 168\n 181 150 178 179 167 180 176 169 182 177 175 159 173", "output": "343772227"}]
Print the number of ways to write the numbers under the conditions, modulo 10^9 + 7. * * *
s898616575
Runtime Error
p03152
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_{N} B_1 B_2 ... B_{M}
n,m=map(int,input().split()) a=set(map(int,input().split())) b=set(map(int,input().split())) c=1;N=0;M=0 for k in range(m*n,0,-1): N+=1;M+=1 if k in a and k in b else c*=M;N+=1 if k in a else c*=N;M+=1 if k in b else c*=M*N-m*n+k c%=10**9+7 print(c)
Statement Consider writing each of the integers from 1 to N \times M in a grid with N rows and M columns, without duplicates. Takahashi thinks it is not fun enough, and he will write the numbers under the following conditions: * The largest among the values in the i-th row (1 \leq i \leq N) is A_i. * The largest among the values in the j-th column (1 \leq j \leq M) is B_j. For him, find the number of ways to write the numbers under these conditions, modulo 10^9 + 7.
[{"input": "2 2\n 4 3\n 3 4", "output": "2\n \n\n(A_1, A_2) = (4, 3) and (B_1, B_2) = (3, 4). In this case, there are two ways\nto write the numbers, as follows:\n\n * 1 in (1, 1), 4 in (1, 2), 3 in (2, 1) and 2 in (2, 2).\n * 2 in (1, 1), 4 in (1, 2), 3 in (2, 1) and 1 in (2, 2).\n\nHere, (i, j) denotes the square at the i-th row and the j-th column.\n\n* * *"}, {"input": "3 3\n 5 9 7\n 3 6 9", "output": "0\n \n\nSince there is no way to write the numbers under the condition, 0 should be\nprinted.\n\n* * *"}, {"input": "2 2\n 4 4\n 4 4", "output": "0\n \n\n* * *"}, {"input": "14 13\n 158 167 181 147 178 151 179 182 176 169 180 129 175 168\n 181 150 178 179 167 180 176 169 182 177 175 159 173", "output": "343772227"}]
Print the number of ways to write the numbers under the conditions, modulo 10^9 + 7. * * *
s995084050
Wrong Answer
p03152
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_{N} B_1 B_2 ... B_{M}
print(0)
Statement Consider writing each of the integers from 1 to N \times M in a grid with N rows and M columns, without duplicates. Takahashi thinks it is not fun enough, and he will write the numbers under the following conditions: * The largest among the values in the i-th row (1 \leq i \leq N) is A_i. * The largest among the values in the j-th column (1 \leq j \leq M) is B_j. For him, find the number of ways to write the numbers under these conditions, modulo 10^9 + 7.
[{"input": "2 2\n 4 3\n 3 4", "output": "2\n \n\n(A_1, A_2) = (4, 3) and (B_1, B_2) = (3, 4). In this case, there are two ways\nto write the numbers, as follows:\n\n * 1 in (1, 1), 4 in (1, 2), 3 in (2, 1) and 2 in (2, 2).\n * 2 in (1, 1), 4 in (1, 2), 3 in (2, 1) and 1 in (2, 2).\n\nHere, (i, j) denotes the square at the i-th row and the j-th column.\n\n* * *"}, {"input": "3 3\n 5 9 7\n 3 6 9", "output": "0\n \n\nSince there is no way to write the numbers under the condition, 0 should be\nprinted.\n\n* * *"}, {"input": "2 2\n 4 4\n 4 4", "output": "0\n \n\n* * *"}, {"input": "14 13\n 158 167 181 147 178 151 179 182 176 169 180 129 175 168\n 181 150 178 179 167 180 176 169 182 177 175 159 173", "output": "343772227"}]
Print the number of ways to write the numbers under the conditions, modulo 10^9 + 7. * * *
s349659806
Accepted
p03152
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_{N} B_1 B_2 ... B_{M}
# -*- coding: utf-8 -*- """ 参考:https://img.atcoder.jp/keyence2019/editorial.pdf """ import sys, re from collections import deque, defaultdict, Counter from math import sqrt, hypot, factorial, pi, sin, cos, radians if sys.version_info.minor >= 5: from math import gcd else: from fractions import gcd from heapq import heappop, heappush, heapify, heappushpop from bisect import bisect_left, bisect_right from itertools import permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from functools import reduce, partial from fractions import Fraction from string import ascii_lowercase, ascii_uppercase, digits def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def round(x): return int((x * 2 + 1) // 2) def fermat(x, y, MOD): return x * pow(y, MOD - 2, MOD) % MOD def lcm(x, y): return (x * y) // gcd(x, y) def lcm_list(nums): return reduce(lcm, nums, 1) def gcd_list(nums): return reduce(gcd, nums, nums[0]) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") MOD = 10**9 + 7 N, M = MAP() # 二分探索用にソートしておく # (どの行に何が来るかの具体的な位置は今回必要ないのでソートしていい) A = sorted(LIST()) B = sorted(LIST()) MAX = N * M # 同じリストに同じ値がいたら論外 # (各値1回ずつしか使えないのに、違う行で最大値が同じとか不可能) if len(A) != len(set(A)) or len(B) != len(set(B)): print(0) exit() # 1: Aにある, 2: Bにある, 3: 両方にある, 0: どちらにもない flags = [0] * (MAX + 1) for i in range(N): flags[A[i]] += 1 for i in range(M): flags[B[i]] += 2 ans = 1 for i in range(MAX, 0, -1): tmp = 1 # どちらにもない if flags[i] == 0: # Aで自分以上の数 * Bで自分以上の数 - 自分以上の数 tmp = (N - bisect_left(A, i)) * (M - bisect_left(B, i)) - (N * M - i) if tmp <= 0: print(0) exit() # Aにある elif flags[i] == 1: # 自分の行が決まっているので、列を調べに行く tmp = M - bisect_left(B, i) # Bにある elif flags[i] == 2: tmp = N - bisect_left(A, i) ans = (ans * tmp) % MOD print(ans)
Statement Consider writing each of the integers from 1 to N \times M in a grid with N rows and M columns, without duplicates. Takahashi thinks it is not fun enough, and he will write the numbers under the following conditions: * The largest among the values in the i-th row (1 \leq i \leq N) is A_i. * The largest among the values in the j-th column (1 \leq j \leq M) is B_j. For him, find the number of ways to write the numbers under these conditions, modulo 10^9 + 7.
[{"input": "2 2\n 4 3\n 3 4", "output": "2\n \n\n(A_1, A_2) = (4, 3) and (B_1, B_2) = (3, 4). In this case, there are two ways\nto write the numbers, as follows:\n\n * 1 in (1, 1), 4 in (1, 2), 3 in (2, 1) and 2 in (2, 2).\n * 2 in (1, 1), 4 in (1, 2), 3 in (2, 1) and 1 in (2, 2).\n\nHere, (i, j) denotes the square at the i-th row and the j-th column.\n\n* * *"}, {"input": "3 3\n 5 9 7\n 3 6 9", "output": "0\n \n\nSince there is no way to write the numbers under the condition, 0 should be\nprinted.\n\n* * *"}, {"input": "2 2\n 4 4\n 4 4", "output": "0\n \n\n* * *"}, {"input": "14 13\n 158 167 181 147 178 151 179 182 176 169 180 129 175 168\n 181 150 178 179 167 180 176 169 182 177 175 159 173", "output": "343772227"}]
Print the number of ways to write the numbers under the conditions, modulo 10^9 + 7. * * *
s568534302
Accepted
p03152
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_{N} B_1 B_2 ... B_{M}
N, M = map(int, input().split()) A = map(int, input().split()) B = map(int, input().split()) Y = [0] * N * M X = [0] * N * M for a in A: if Y[a - 1]: print(0) exit() Y[a - 1] = 1 for b in B: if X[b - 1]: print(0) exit() X[b - 1] = 1 z = 1 h = w = 0 MD = 10**9 + 7 for i in range(N * M)[::-1]: z *= [h * w - (N * M - 1 - i), h, w, 1][Y[i] * 2 + X[i]] z %= MD h += Y[i] w += X[i] print(z)
Statement Consider writing each of the integers from 1 to N \times M in a grid with N rows and M columns, without duplicates. Takahashi thinks it is not fun enough, and he will write the numbers under the following conditions: * The largest among the values in the i-th row (1 \leq i \leq N) is A_i. * The largest among the values in the j-th column (1 \leq j \leq M) is B_j. For him, find the number of ways to write the numbers under these conditions, modulo 10^9 + 7.
[{"input": "2 2\n 4 3\n 3 4", "output": "2\n \n\n(A_1, A_2) = (4, 3) and (B_1, B_2) = (3, 4). In this case, there are two ways\nto write the numbers, as follows:\n\n * 1 in (1, 1), 4 in (1, 2), 3 in (2, 1) and 2 in (2, 2).\n * 2 in (1, 1), 4 in (1, 2), 3 in (2, 1) and 1 in (2, 2).\n\nHere, (i, j) denotes the square at the i-th row and the j-th column.\n\n* * *"}, {"input": "3 3\n 5 9 7\n 3 6 9", "output": "0\n \n\nSince there is no way to write the numbers under the condition, 0 should be\nprinted.\n\n* * *"}, {"input": "2 2\n 4 4\n 4 4", "output": "0\n \n\n* * *"}, {"input": "14 13\n 158 167 181 147 178 151 179 182 176 169 180 129 175 168\n 181 150 178 179 167 180 176 169 182 177 175 159 173", "output": "343772227"}]
Print the number of ways to write the numbers under the conditions, modulo 10^9 + 7. * * *
s861199892
Accepted
p03152
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_{N} B_1 B_2 ... B_{M}
from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b # aとbの最大公約数 def gcd(a, b): if b == 0: return a return gcd(b, a % b) # aとbの最小公倍数 def lcm(a, b): g = gcd(a, b) return a / g * b class BisectWrapper: from bisect import bisect, bisect_left, bisect_right def __init__(self): pass # aにxが存在するか @staticmethod def exist(a, x): i = bisect_left(a, x) if i != len(a) and a[i] == x: return True return False # xのindex(なければ-1) @staticmethod def index(a, x): i = bisect_left(a, x) if i != len(a) and a[i] == x: return i return -1 # y < xのようなyの中でもっとも右のindex @staticmethod def index_lt(a, x): i = bisect_left(a, x) if i: return i - 1 return -1 # y < xのようなyの個数 @staticmethod def num_lt(a, x): return bisect_left(a, x) # y <= xのようなyの中でもっとも右のindex @staticmethod def index_lte(a, x): i = bisect_right(a, x) if i: return i - 1 return -1 # y < xのようなyの個数 @staticmethod def num_lte(a, x): return bisect_right(a, x) # y > xのようなyの中でもっとも左のindex @staticmethod def index_gt(a, x): i = bisect_right(a, x) if i != len(a): return i return -1 # y > xのようなyの個数 @staticmethod def num_gt(a, x): return len(a) - bisect_right(a, x) # y >= xのようなyの中でもっとも左のindex @staticmethod def index_gte(a, x): i = bisect_left(a, x) if i != len(a): return i return -1 # y >= xのようなyの個数 @staticmethod def num_gte(a, x): return len(a) - bisect_left(a, x) def main(): N, M = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) if len(set(A)) != N or len(set(B)) != M: print(0) return MOD = 10**9 + 7 sorted_A = list(sorted(A[:])) sorted_B = list(sorted(B[:])) sorted_total = list(sorted(set(A[:] + B[:]))) ans = 1 free = 0 for d in range(N * M, 0, -1): in_a = BisectWrapper.exist(sorted_A, d) in_b = BisectWrapper.exist(sorted_B, d) if in_a and in_b: pass elif in_a: num_b = BisectWrapper.num_gt(sorted_B, d) ans *= num_b ans %= MOD elif in_b: num_a = BisectWrapper.num_gt(sorted_A, d) ans *= num_a ans %= MOD else: num_a = BisectWrapper.num_gt(sorted_A, d) num_b = BisectWrapper.num_gt(sorted_B, d) num_t = BisectWrapper.num_gt(sorted_total, d) num = num_a * num_b - num_t ans *= num - free ans %= MOD free += 1 print(ans % MOD) if __name__ == "__main__": main()
Statement Consider writing each of the integers from 1 to N \times M in a grid with N rows and M columns, without duplicates. Takahashi thinks it is not fun enough, and he will write the numbers under the following conditions: * The largest among the values in the i-th row (1 \leq i \leq N) is A_i. * The largest among the values in the j-th column (1 \leq j \leq M) is B_j. For him, find the number of ways to write the numbers under these conditions, modulo 10^9 + 7.
[{"input": "2 2\n 4 3\n 3 4", "output": "2\n \n\n(A_1, A_2) = (4, 3) and (B_1, B_2) = (3, 4). In this case, there are two ways\nto write the numbers, as follows:\n\n * 1 in (1, 1), 4 in (1, 2), 3 in (2, 1) and 2 in (2, 2).\n * 2 in (1, 1), 4 in (1, 2), 3 in (2, 1) and 1 in (2, 2).\n\nHere, (i, j) denotes the square at the i-th row and the j-th column.\n\n* * *"}, {"input": "3 3\n 5 9 7\n 3 6 9", "output": "0\n \n\nSince there is no way to write the numbers under the condition, 0 should be\nprinted.\n\n* * *"}, {"input": "2 2\n 4 4\n 4 4", "output": "0\n \n\n* * *"}, {"input": "14 13\n 158 167 181 147 178 151 179 182 176 169 180 129 175 168\n 181 150 178 179 167 180 176 169 182 177 175 159 173", "output": "343772227"}]