message stringlengths 2 433k | message_type stringclasses 2
values | message_id int64 0 1 | conversation_id int64 113 108k | cluster float64 12 12 | __index_level_0__ int64 226 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the inpu... | instruction | 0 | 41,663 | 12 | 83,326 |
Tags: binary search, data structures, two pointers
Correct Solution:
```
n = int(input())
A = [int(x) for x in input().split()]
s = {A[0]}
left = 1
segments = []
for i in range(1, n):
if A[i] in s:
segments.append((left, i+1))
left = i+2
s.clear()
else:
s.add(A[i])
if len(segment... | output | 1 | 41,663 | 12 | 83,327 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the inpu... | instruction | 0 | 41,664 | 12 | 83,328 |
Tags: binary search, data structures, two pointers
Correct Solution:
```
n = int(input())
cnt = 0
gems = list(map(int, input().split()))
pearls = set()
for i in range(n):
if gems[i] not in pearls:
pearls.add(gems[i])
else:
cnt += 1
pearls = set()
if cnt:
print(cnt)
first = 0... | output | 1 | 41,664 | 12 | 83,329 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.... | instruction | 0 | 41,665 | 12 | 83,330 |
Yes | output | 1 | 41,665 | 12 | 83,331 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.... | instruction | 0 | 41,666 | 12 | 83,332 |
Yes | output | 1 | 41,666 | 12 | 83,333 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.... | instruction | 0 | 41,667 | 12 | 83,334 |
Yes | output | 1 | 41,667 | 12 | 83,335 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.... | instruction | 0 | 41,668 | 12 | 83,336 |
Yes | output | 1 | 41,668 | 12 | 83,337 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.... | instruction | 0 | 41,669 | 12 | 83,338 |
No | output | 1 | 41,669 | 12 | 83,339 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.... | instruction | 0 | 41,670 | 12 | 83,340 |
No | output | 1 | 41,670 | 12 | 83,341 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.... | instruction | 0 | 41,671 | 12 | 83,342 |
No | output | 1 | 41,671 | 12 | 83,343 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.... | instruction | 0 | 41,672 | 12 | 83,344 |
No | output | 1 | 41,672 | 12 | 83,345 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the... | instruction | 0 | 41,704 | 12 | 83,408 |
Tags: constructive algorithms, dfs and similar
Correct Solution:
```
#-*- coding:utf-8 -*-
#!/usr/bin/python3
def dfs(x):
if vis[p[x]] == False:
vis[p[x]] = True
dfs(p[x])
n = int(input())
p = list(map(int, input().split()))
b = list(map(int, input().split()))
vis = [False] * n
num = 0
for i in range(0, n):
p[... | output | 1 | 41,704 | 12 | 83,409 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the... | instruction | 0 | 41,705 | 12 | 83,410 |
Tags: constructive algorithms, dfs and similar
Correct Solution:
```
n=int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans =0
sums1 =0
for j in range(n):
if B[j] == 1:
sums1+=1
if sums1 % 2==0:
ans=1
visited = [0] * n
cou =0
for j in range(n):
if visited[j] == 0:
... | output | 1 | 41,705 | 12 | 83,411 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the... | instruction | 0 | 41,706 | 12 | 83,412 |
Tags: constructive algorithms, dfs and similar
Correct Solution:
```
n = int(input())
p = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ans = 0
visited = [False for i in range(n)]
for i in range(n):
if visited[i]:
continue
ans += 1
while not visited[i]:
visited[i] =... | output | 1 | 41,706 | 12 | 83,413 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the... | instruction | 0 | 41,707 | 12 | 83,414 |
Tags: constructive algorithms, dfs and similar
Correct Solution:
```
n = int(input())
p = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt_cyc = 0
vis = [0] * n
for i in range(n):
if vis[i] == 0:
vis[i] = 1
nxt = p[i]-1
while vis[nxt] == 0:
vis[nxt] = 1
... | output | 1 | 41,707 | 12 | 83,415 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the... | instruction | 0 | 41,708 | 12 | 83,416 |
Tags: constructive algorithms, dfs and similar
Correct Solution:
```
n = int(input())
p = [[0, 1] for i in range(n)]
b = [0 for i in range(n)]
ans = 0
s = input().split()
for i in range(n):
p[i][0] = int(s[i]) - 1
s = input().split()
for i in range(n):
b[i] = int(s[i])
temp = 0
cyc = 0
for i in range(n):
... | output | 1 | 41,708 | 12 | 83,417 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the... | instruction | 0 | 41,709 | 12 | 83,418 |
Tags: constructive algorithms, dfs and similar
Correct Solution:
```
from collections import deque
def read(type=int):
return type(input())
def read_arr(type=int):
return [type(token) for token in input().split()]
def num_cycles(P):
V = [False] * len(P)
i = 0
for u in P:
if not V[u]:
... | output | 1 | 41,709 | 12 | 83,419 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the... | instruction | 0 | 41,710 | 12 | 83,420 |
Tags: constructive algorithms, dfs and similar
Correct Solution:
```
import sys
input = sys.stdin.readline
n = int(input())
permutation = list(map(int, input().split()))
go = set(range(1,n+1))
reached = set()
ans = 0
while go:
x = go.pop()
while x not in reached:
reached.add(x)
x = permutation[x-1]
if... | output | 1 | 41,710 | 12 | 83,421 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the... | instruction | 0 | 41,711 | 12 | 83,422 |
Tags: constructive algorithms, dfs and similar
Correct Solution:
```
n = int(input())
p = list(map(lambda x: int(x)-1, input().split()))
b = list(map(int, input().split()))
cp = 0
z = [True]*n
old = -1
nn = n
while nn:
cp += 1
cur = next(i for i in range(old + 1, n) if z[i])
old = cur
while(z[cur]):
z[cur] ... | output | 1 | 41,711 | 12 | 83,423 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: i... | instruction | 0 | 41,712 | 12 | 83,424 |
Yes | output | 1 | 41,712 | 12 | 83,425 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: i... | instruction | 0 | 41,713 | 12 | 83,426 |
Yes | output | 1 | 41,713 | 12 | 83,427 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: i... | instruction | 0 | 41,714 | 12 | 83,428 |
Yes | output | 1 | 41,714 | 12 | 83,429 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: i... | instruction | 0 | 41,715 | 12 | 83,430 |
Yes | output | 1 | 41,715 | 12 | 83,431 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: i... | instruction | 0 | 41,716 | 12 | 83,432 |
No | output | 1 | 41,716 | 12 | 83,433 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: i... | instruction | 0 | 41,717 | 12 | 83,434 |
No | output | 1 | 41,717 | 12 | 83,435 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: i... | instruction | 0 | 41,718 | 12 | 83,436 |
No | output | 1 | 41,718 | 12 | 83,437 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: i... | instruction | 0 | 41,719 | 12 | 83,438 |
No | output | 1 | 41,719 | 12 | 83,439 |
Provide a correct Python 3 solution for this coding contest problem.
You are given N integers A_1, A_2, ..., A_N.
Consider the sums of all non-empty subsequences of A. There are 2^N - 1 such sums, an odd number.
Let the list of these sums in non-decreasing order be S_1, S_2, ..., S_{2^N - 1}.
Find the median of thi... | instruction | 0 | 41,909 | 12 | 83,818 |
"Correct Solution:
```
#!/usr/bin/env python3
import math
input()
A = list(map(int, input().split()))
dp = 1
for x in A:
dp |= dp << x
h = math.ceil(sum(A) / 2)
print(h + bin(dp >> h)[::-1].index('1'))
``` | output | 1 | 41,909 | 12 | 83,819 |
Provide a correct Python 3 solution for this coding contest problem.
You are given N integers A_1, A_2, ..., A_N.
Consider the sums of all non-empty subsequences of A. There are 2^N - 1 such sums, an odd number.
Let the list of these sums in non-decreasing order be S_1, S_2, ..., S_{2^N - 1}.
Find the median of thi... | instruction | 0 | 41,912 | 12 | 83,824 |
"Correct Solution:
```
"""
連続でない部分列問題…
中央値問題でよくあるのは、その数字以上の数がいくつ出てくるかで二分探索
部分問題:N個ある数列Aから1つ以上取って総和がK以上になる取り方はいくつあるか
→普通にdpするとできるがO(N^2*A)で無理(つーかほぼ答え)
中央値と平均値の関係は?
→今回はすべてのAが1/2の確率で選ばれるので、Aの総和/2 が全てのSの平均値となる
→だからなに・・・
=======解説をみた=======
Aのすべての合計をTとすると、前半はT/2以下で、後半はT/2以上(補集合の関係から)
求めるのは後半の一番小さい数字→T/2以上で登場する最小値
b... | output | 1 | 41,912 | 12 | 83,825 |
Provide a correct Python 3 solution for this coding contest problem.
You are given N integers A_1, A_2, ..., A_N.
Consider the sums of all non-empty subsequences of A. There are 2^N - 1 such sums, an odd number.
Let the list of these sums in non-decreasing order be S_1, S_2, ..., S_{2^N - 1}.
Find the median of thi... | instruction | 0 | 41,915 | 12 | 83,830 |
"Correct Solution:
```
def main():
_,a=open(0)
*a,=map(int,a.split())
d=1
for i in a:d|=d<<i
s=0--sum(a)//2
d>>=s
print((d&-d).bit_length()+s-1)
main()
``` | output | 1 | 41,915 | 12 | 83,831 |
Provide a correct Python 3 solution for this coding contest problem.
You are given N integers A_1, A_2, ..., A_N.
Consider the sums of all non-empty subsequences of A. There are 2^N - 1 such sums, an odd number.
Let the list of these sums in non-decreasing order be S_1, S_2, ..., S_{2^N - 1}.
Find the median of thi... | instruction | 0 | 41,916 | 12 | 83,832 |
"Correct Solution:
```
n, arr, dp = int(input()), list(map(int, input().split())), 1
for a in arr:
dp |= dp << a
ofs = (sum(arr) + 1) // 2
dp >>= ofs
print((dp & -dp).bit_length() + ofs - 1)
``` | output | 1 | 41,916 | 12 | 83,833 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given N integers A_1, A_2, ..., A_N.
Consider the sums of all non-empty subsequences of A. There are 2^N - 1 such sums, an odd number.
Let the list of these sums in non-decreasing orde... | instruction | 0 | 41,920 | 12 | 83,840 |
Yes | output | 1 | 41,920 | 12 | 83,841 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array which is initially empty. You need to perform n operations of the given format:
* "a l r k": append a to the end of the array. After that count the number of integer p... | instruction | 0 | 42,165 | 12 | 84,330 |
No | output | 1 | 42,165 | 12 | 84,331 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array which is initially empty. You need to perform n operations of the given format:
* "a l r k": append a to the end of the array. After that count the number of integer p... | instruction | 0 | 42,166 | 12 | 84,332 |
No | output | 1 | 42,166 | 12 | 84,333 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array which is initially empty. You need to perform n operations of the given format:
* "a l r k": append a to the end of the array. After that count the number of integer p... | instruction | 0 | 42,167 | 12 | 84,334 |
No | output | 1 | 42,167 | 12 | 84,335 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array which is initially empty. You need to perform n operations of the given format:
* "a l r k": append a to the end of the array. After that count the number of integer p... | instruction | 0 | 42,168 | 12 | 84,336 |
No | output | 1 | 42,168 | 12 | 84,337 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a consisting of 500000 integers (numbered from 1 to 500000). Initially all elements of a are zero.
You have to process two types of queries to this array:
* 1 x y — increase a_x by y;
* 2 x y — compute ∑_{i ∈ R(... | instruction | 0 | 42,173 | 12 | 84,346 |
Tags: brute force, data structures, implementation
Correct Solution:
```
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split())... | output | 1 | 42,173 | 12 | 84,347 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a consisting of 500000 integers (numbered from 1 to 500000). Initially all elements of a are zero.
You have to process two types of queries to this array:
* 1 x y — increase a_x by y;
* 2 x y — compute ∑_{i ∈ R(... | instruction | 0 | 42,174 | 12 | 84,348 |
Tags: brute force, data structures, implementation
Correct Solution:
```
import sys
from array import array # noqa: F401
import typing as Tp # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
def main():
q = int(input())
n = 500000
m = 600
a = array('i', [0]) * (n + 1... | output | 1 | 42,174 | 12 | 84,349 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a consisting of 500000 integers (numbered from 1 to 500000). Initially all elements of a are zero.
You have to process two types of queries to this array:
* 1 x y — increase a_x by y;
* 2 x y — compute ∑_{i ∈ R(... | instruction | 0 | 42,175 | 12 | 84,350 |
Tags: brute force, data structures, implementation
Correct Solution:
```
import sys
n = 500001
sqrt = int(0.75 * n**0.5)
data = [0]*(n)
ans = [[]]
out = []
for i in range(1, sqrt):
ans.append([0]*i)
j = int(sys.stdin.readline())
qus = sys.stdin.readlines()
for qu in qus:
q = [int(i) for i in qu.split()]
if... | output | 1 | 42,175 | 12 | 84,351 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a consisting of 500000 integers (numbered from 1 to 500000). Initially all elements of a are zero.
You have to process two types of queries to this array:
* 1 x y — increase a_x by y;
* 2 x y — compute ∑_{i ∈ R(... | instruction | 0 | 42,177 | 12 | 84,354 |
Tags: brute force, data structures, implementation
Correct Solution:
```
import sys
n = 500001
sqrt = int(0.75 * n**0.5)
data = [0]*(n)
ans = [[]]
out = []
for i in range(1, sqrt):
ans.append([0]*i)
j = int(sys.stdin.readline())
qus = sys.stdin.readlines()
for qu in qus:
q = [int(i) for i in qu.split()]
if... | output | 1 | 42,177 | 12 | 84,355 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a consisting of 500000 integers (numbered from 1 to 500000). Initially all elements of a are zero.
You have to process two types of queries to this array:
* 1 x y — increase a_x by y;
* 2 x y — compute ∑_{i ∈ R(... | instruction | 0 | 42,178 | 12 | 84,356 |
Tags: brute force, data structures, implementation
Correct Solution:
```
import sys
n = 500001
sqrt = int(0.75 * n**0.5)
data = [0]*(n)
ans = [[]]
# out = []
for i in range(1, sqrt):
ans.append([0]*i)
j = int(sys.stdin.readline())
qus = sys.stdin.readlines()
for qu in qus:
q = [int(i) for i in qu.split()]
... | output | 1 | 42,178 | 12 | 84,357 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a consisting of 500000 integers (numbered from 1 to 500000). Initially all elements of a are zero.
You have to process two types of queries to this array:
* 1 x y — increase a_x by y;
* 2 x y — compute ∑_{i ∈ R(... | instruction | 0 | 42,179 | 12 | 84,358 |
Tags: brute force, data structures, implementation
Correct Solution:
```
import sys
n = 500001
sqrt = int(0.75 * n**0.5)
data = [0]*(n)
ans = [[]]
# out = []
for i in range(1, sqrt):
ans.append([0]*i)
j = int(sys.stdin.readline())
qus = sys.stdin.readlines()
for qu in qus:
q = [int(i) for i in qu.split()]
... | output | 1 | 42,179 | 12 | 84,359 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a consisting of 500000 integers (numbered from 1 to 500000). Initially all elements of a are zero.
You have to process two types of queries to this array:
* 1 x y — increase a_x by y;
* 2 x y — compute ∑_{i ∈ R(... | instruction | 0 | 42,180 | 12 | 84,360 |
Tags: brute force, data structures, implementation
Correct Solution:
```
import sys
readline = sys.stdin.buffer.readline
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
def solve():
q = ni()
n = 5 * 10**5
a = [0]*(n + 1)
m = 710
rem = [[0]*m for _ in range(m)]
f... | output | 1 | 42,180 | 12 | 84,361 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n k-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers.
Input
The firs... | instruction | 0 | 42,189 | 12 | 84,378 |
Tags: brute force, combinatorics, implementation
Correct Solution:
```
from itertools import permutations
n, k = list(map(int, input().split(" ")))
permutacoes = []
for i in range(n):
x = list(input())
permuts = [''.join(x) for x in list(permutations(x))]
permuts = list(map(int, permuts))
permutacoes.appen... | output | 1 | 42,189 | 12 | 84,379 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n k-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers.
Input
The firs... | instruction | 0 | 42,190 | 12 | 84,380 |
Tags: brute force, combinatorics, implementation
Correct Solution:
```
from itertools import permutations
n, k = map(int, input().split())
min_diff = 10**9
tab = []
for _ in range(n):
tab += [list(input())]
for digit_map in permutations(list(range(k))):
perm_nums = []
for num in tab:
perm_nums +... | output | 1 | 42,190 | 12 | 84,381 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n k-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers.
Input
The firs... | instruction | 0 | 42,191 | 12 | 84,382 |
Tags: brute force, combinatorics, implementation
Correct Solution:
```
#! /usr/bin/python
from itertools import permutations
n, k = map(int, input().split())
N = []
for i in range(n):
N.append(permutations(input().strip()))
ans = 1000000000
try:
while True:
X = []
for i in range(n):
... | output | 1 | 42,191 | 12 | 84,383 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n k-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers.
Input
The firs... | instruction | 0 | 42,192 | 12 | 84,384 |
Tags: brute force, combinatorics, implementation
Correct Solution:
```
import itertools as it
n, k = [int(i) for i in input().split()]
a = [list(map(int, input())) for i in range(n)]
p = [10 ** j for j in range(k)][::-1]
m = 99999999999999
mmx, mmn = 0, 9999999999
for i in it.permutations(p):
mx, mn = 0, 999999999... | output | 1 | 42,192 | 12 | 84,385 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n k-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers.
Input
The firs... | instruction | 0 | 42,193 | 12 | 84,386 |
Tags: brute force, combinatorics, implementation
Correct Solution:
```
import math
import itertools
n, k = map(int, input().split())
numbers = []
for i in range(n):
numbers.append(input())
permutations = []
for number in numbers:
curr = [int(''.join(perm)) for perm in itertools.permutations(number)]
permu... | output | 1 | 42,193 | 12 | 84,387 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n k-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers.
Input
The firs... | instruction | 0 | 42,194 | 12 | 84,388 |
Tags: brute force, combinatorics, implementation
Correct Solution:
```
from itertools import permutations
n,k=map(int,input().split())
ar=[input() for i in range(n)]
ans=float('inf')
for p in permutations(range(k)):
mx=0
mn=float('inf')
for e in ar:
cur=0
for i in p:
cur=10*cur+(... | output | 1 | 42,194 | 12 | 84,389 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n k-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers.
Input
The firs... | instruction | 0 | 42,195 | 12 | 84,390 |
Tags: brute force, combinatorics, implementation
Correct Solution:
```
from itertools import *
n,k=map(int,input().split())
a=[]
for i in range(n):
a.append([i for i in input()])
l=[]
for i in range(k): l.append(i)
perm=permutations(l)
ans=10**9
for now in perm:
curr=list(now)
mx=0
mn=10**9
for i in a:
... | output | 1 | 42,195 | 12 | 84,391 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n k-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers.
Input
The firs... | instruction | 0 | 42,196 | 12 | 84,392 |
Tags: brute force, combinatorics, implementation
Correct Solution:
```
n,d = [int(x) for x in input().split()]
li = []
for i in range(n):
s = input()
li.append(s)
st = ""
for i in range(0,d):
st += str(i)
from itertools import permutations
max_diff = 10**9
for i in permutations(st):
ans = []
for j i... | output | 1 | 42,196 | 12 | 84,393 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.