output_description stringlengths 15 956 | submission_id stringlengths 10 10 | status stringclasses 3 values | problem_id stringlengths 6 6 | input_description stringlengths 9 2.55k | attempt stringlengths 1 13.7k | problem_description stringlengths 7 5.24k | samples stringlengths 2 2.72k |
|---|---|---|---|---|---|---|---|
Print the minimum possible difference between X and 753.
* * * | s656185038 | Runtime Error | p03211 | Input is given from Standard Input in the following format:
S | S=input()
ans=1000
for i in range(len(S)-3):
ans=min(ans,abs(753-int(S[i:i+3]))
print(ans)
| Statement
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the
Dachshund, will take out three consecutive digits from S, treat them as a
single integer X and bring it to her master. (She cannot rearrange the
digits.)
The master's favorite number is 753. The closer to this number, the better.
What is the minimum possible (absolute) difference between X and 753? | [{"input": "1234567876", "output": "34\n \n\nTaking out the seventh to ninth characters results in X = 787, and the\ndifference between this and 753 is 787 - 753 = 34. The difference cannot be\nmade smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out `567` and\nrearranging it to `765` is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For\nexample, taking out the seventh digit `7`, the ninth digit `7` and the tenth\ndigit `6` to obtain `776` is not allowed.\n\n* * *"}, {"input": "35753", "output": "0\n \n\nIf `753` itself can be taken out, the answer is 0.\n\n* * *"}, {"input": "1111111111", "output": "642\n \n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642."}] |
Print the minimum possible difference between X and 753.
* * * | s849618181 | Runtime Error | p03211 | Input is given from Standard Input in the following format:
S | n=input()
a=0
b=753
ans=100000000
for i in renge(len(n)-2):
a=int(n[i])*100+int(n[i+1])*10+int(n[i+2])
ans=min(abs(a-b),ans)
print(ans) | Statement
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the
Dachshund, will take out three consecutive digits from S, treat them as a
single integer X and bring it to her master. (She cannot rearrange the
digits.)
The master's favorite number is 753. The closer to this number, the better.
What is the minimum possible (absolute) difference between X and 753? | [{"input": "1234567876", "output": "34\n \n\nTaking out the seventh to ninth characters results in X = 787, and the\ndifference between this and 753 is 787 - 753 = 34. The difference cannot be\nmade smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out `567` and\nrearranging it to `765` is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For\nexample, taking out the seventh digit `7`, the ninth digit `7` and the tenth\ndigit `6` to obtain `776` is not allowed.\n\n* * *"}, {"input": "35753", "output": "0\n \n\nIf `753` itself can be taken out, the answer is 0.\n\n* * *"}, {"input": "1111111111", "output": "642\n \n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642."}] |
Print the minimum possible difference between X and 753.
* * * | s938173345 | Runtime Error | p03211 | Input is given from Standard Input in the following format:
S | s = input()
imin = 753
for i in range(len(s)-2):
if(abs(int(s[i] + s[i+1] + s[i+2]) - 753) < imin:
imin = abs(int(s[i] + s[i+1] + s[i+2])-753)
print(imin) | Statement
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the
Dachshund, will take out three consecutive digits from S, treat them as a
single integer X and bring it to her master. (She cannot rearrange the
digits.)
The master's favorite number is 753. The closer to this number, the better.
What is the minimum possible (absolute) difference between X and 753? | [{"input": "1234567876", "output": "34\n \n\nTaking out the seventh to ninth characters results in X = 787, and the\ndifference between this and 753 is 787 - 753 = 34. The difference cannot be\nmade smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out `567` and\nrearranging it to `765` is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For\nexample, taking out the seventh digit `7`, the ninth digit `7` and the tenth\ndigit `6` to obtain `776` is not allowed.\n\n* * *"}, {"input": "35753", "output": "0\n \n\nIf `753` itself can be taken out, the answer is 0.\n\n* * *"}, {"input": "1111111111", "output": "642\n \n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642."}] |
Print the minimum possible difference between X and 753.
* * * | s357779859 | Runtime Error | p03211 | Input is given from Standard Input in the following format:
S | s = [*input()]
ans = 1000
for i in range(len(s)-2):
x = int(s[i]+s[i+1]+s[i+2])
if ans > abs(753-x):
ans = abs(753-x)
print(ans)
| Statement
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the
Dachshund, will take out three consecutive digits from S, treat them as a
single integer X and bring it to her master. (She cannot rearrange the
digits.)
The master's favorite number is 753. The closer to this number, the better.
What is the minimum possible (absolute) difference between X and 753? | [{"input": "1234567876", "output": "34\n \n\nTaking out the seventh to ninth characters results in X = 787, and the\ndifference between this and 753 is 787 - 753 = 34. The difference cannot be\nmade smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out `567` and\nrearranging it to `765` is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For\nexample, taking out the seventh digit `7`, the ninth digit `7` and the tenth\ndigit `6` to obtain `776` is not allowed.\n\n* * *"}, {"input": "35753", "output": "0\n \n\nIf `753` itself can be taken out, the answer is 0.\n\n* * *"}, {"input": "1111111111", "output": "642\n \n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642."}] |
Print the minimum possible difference between X and 753.
* * * | s900758865 | Runtime Error | p03211 | Input is given from Standard Input in the following format:
S | nums = list(map(int, input().split()))
sums = [sum(nums[i : i + 3]) for i in range(len(nums) - 1)]
poyo = [abs(x - 753) for x in sums]
print(min(poyo))
| Statement
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the
Dachshund, will take out three consecutive digits from S, treat them as a
single integer X and bring it to her master. (She cannot rearrange the
digits.)
The master's favorite number is 753. The closer to this number, the better.
What is the minimum possible (absolute) difference between X and 753? | [{"input": "1234567876", "output": "34\n \n\nTaking out the seventh to ninth characters results in X = 787, and the\ndifference between this and 753 is 787 - 753 = 34. The difference cannot be\nmade smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out `567` and\nrearranging it to `765` is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For\nexample, taking out the seventh digit `7`, the ninth digit `7` and the tenth\ndigit `6` to obtain `776` is not allowed.\n\n* * *"}, {"input": "35753", "output": "0\n \n\nIf `753` itself can be taken out, the answer is 0.\n\n* * *"}, {"input": "1111111111", "output": "642\n \n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642."}] |
Print the minimum possible difference between X and 753.
* * * | s003915311 | Accepted | p03211 | Input is given from Standard Input in the following format:
S | n = list(map(int, input()))
three = [0] * (len(n) - 2)
sa = 1000
for i in range(len(three)):
three[i] = n[i] * 100 + n[i + 1] * 10 + n[i + 2]
if abs(three[i] - 753) <= sa:
sa = abs(three[i] - 753)
print(sa)
| Statement
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the
Dachshund, will take out three consecutive digits from S, treat them as a
single integer X and bring it to her master. (She cannot rearrange the
digits.)
The master's favorite number is 753. The closer to this number, the better.
What is the minimum possible (absolute) difference between X and 753? | [{"input": "1234567876", "output": "34\n \n\nTaking out the seventh to ninth characters results in X = 787, and the\ndifference between this and 753 is 787 - 753 = 34. The difference cannot be\nmade smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out `567` and\nrearranging it to `765` is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For\nexample, taking out the seventh digit `7`, the ninth digit `7` and the tenth\ndigit `6` to obtain `776` is not allowed.\n\n* * *"}, {"input": "35753", "output": "0\n \n\nIf `753` itself can be taken out, the answer is 0.\n\n* * *"}, {"input": "1111111111", "output": "642\n \n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642."}] |
Print the minimum possible difference between X and 753.
* * * | s741738927 | Accepted | p03211 | Input is given from Standard Input in the following format:
S | s = input()
most = abs(753 - int(s[0:3]))
start = 1
while start + 3 <= len(s):
cand = abs(753 - int(s[start : start + 3]))
if cand < most:
most = cand
start += 1
print(most)
| Statement
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the
Dachshund, will take out three consecutive digits from S, treat them as a
single integer X and bring it to her master. (She cannot rearrange the
digits.)
The master's favorite number is 753. The closer to this number, the better.
What is the minimum possible (absolute) difference between X and 753? | [{"input": "1234567876", "output": "34\n \n\nTaking out the seventh to ninth characters results in X = 787, and the\ndifference between this and 753 is 787 - 753 = 34. The difference cannot be\nmade smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out `567` and\nrearranging it to `765` is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For\nexample, taking out the seventh digit `7`, the ninth digit `7` and the tenth\ndigit `6` to obtain `776` is not allowed.\n\n* * *"}, {"input": "35753", "output": "0\n \n\nIf `753` itself can be taken out, the answer is 0.\n\n* * *"}, {"input": "1111111111", "output": "642\n \n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642."}] |
Print the minimum possible difference between X and 753.
* * * | s991507546 | Accepted | p03211 | Input is given from Standard Input in the following format:
S | N = int(input())
hoge = []
for i in range(10):
if N != 0:
hoge.append(N % 10)
N = int(N / 10)
hoge = hoge[::-1]
huga = []
for i in range(len(hoge) - 2):
huga.append(abs(hoge[i] * 100 + hoge[i + 1] * 10 + hoge[i + 2] - 753))
print(min(huga))
| Statement
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the
Dachshund, will take out three consecutive digits from S, treat them as a
single integer X and bring it to her master. (She cannot rearrange the
digits.)
The master's favorite number is 753. The closer to this number, the better.
What is the minimum possible (absolute) difference between X and 753? | [{"input": "1234567876", "output": "34\n \n\nTaking out the seventh to ninth characters results in X = 787, and the\ndifference between this and 753 is 787 - 753 = 34. The difference cannot be\nmade smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out `567` and\nrearranging it to `765` is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For\nexample, taking out the seventh digit `7`, the ninth digit `7` and the tenth\ndigit `6` to obtain `776` is not allowed.\n\n* * *"}, {"input": "35753", "output": "0\n \n\nIf `753` itself can be taken out, the answer is 0.\n\n* * *"}, {"input": "1111111111", "output": "642\n \n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642."}] |
Print the minimum possible difference between X and 753.
* * * | s483049559 | Runtime Error | p03211 | Input is given from Standard Input in the following format:
S |
in = input()
result = 999
for i in range(len(in)-2):
if i == len(in) - 3:
num = in[I:]
else:
num = in[i:i+3]
sa = abs(753 - int(num))
if sa < result:
result = sa
print(result)
| Statement
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the
Dachshund, will take out three consecutive digits from S, treat them as a
single integer X and bring it to her master. (She cannot rearrange the
digits.)
The master's favorite number is 753. The closer to this number, the better.
What is the minimum possible (absolute) difference between X and 753? | [{"input": "1234567876", "output": "34\n \n\nTaking out the seventh to ninth characters results in X = 787, and the\ndifference between this and 753 is 787 - 753 = 34. The difference cannot be\nmade smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out `567` and\nrearranging it to `765` is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For\nexample, taking out the seventh digit `7`, the ninth digit `7` and the tenth\ndigit `6` to obtain `776` is not allowed.\n\n* * *"}, {"input": "35753", "output": "0\n \n\nIf `753` itself can be taken out, the answer is 0.\n\n* * *"}, {"input": "1111111111", "output": "642\n \n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642."}] |
Print the minimum possible difference between X and 753.
* * * | s827442644 | Runtime Error | p03211 | Input is given from Standard Input in the following format:
S | A, B, K = map(int, open(0).read().split())
intList = [i for i in range(A, B + 1)]
ansList = set(intList[:K] + intList[::-1][:K])
# print(intList)
# print(ansList)
for j in sorted(ansList):
print(j)
| Statement
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the
Dachshund, will take out three consecutive digits from S, treat them as a
single integer X and bring it to her master. (She cannot rearrange the
digits.)
The master's favorite number is 753. The closer to this number, the better.
What is the minimum possible (absolute) difference between X and 753? | [{"input": "1234567876", "output": "34\n \n\nTaking out the seventh to ninth characters results in X = 787, and the\ndifference between this and 753 is 787 - 753 = 34. The difference cannot be\nmade smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out `567` and\nrearranging it to `765` is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For\nexample, taking out the seventh digit `7`, the ninth digit `7` and the tenth\ndigit `6` to obtain `776` is not allowed.\n\n* * *"}, {"input": "35753", "output": "0\n \n\nIf `753` itself can be taken out, the answer is 0.\n\n* * *"}, {"input": "1111111111", "output": "642\n \n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642."}] |
Print the minimum possible difference between X and 753.
* * * | s390448619 | Wrong Answer | p03211 | Input is given from Standard Input in the following format:
S | S = input()
SS = int(S)
for i in range(0, len(S)):
for j in range(0, i):
for k in range(0, j):
X = int(S[k] + S[j] + S[i])
if abs(753 - X) < SS:
SS = abs(753 - X)
print(SS)
| Statement
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the
Dachshund, will take out three consecutive digits from S, treat them as a
single integer X and bring it to her master. (She cannot rearrange the
digits.)
The master's favorite number is 753. The closer to this number, the better.
What is the minimum possible (absolute) difference between X and 753? | [{"input": "1234567876", "output": "34\n \n\nTaking out the seventh to ninth characters results in X = 787, and the\ndifference between this and 753 is 787 - 753 = 34. The difference cannot be\nmade smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out `567` and\nrearranging it to `765` is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For\nexample, taking out the seventh digit `7`, the ninth digit `7` and the tenth\ndigit `6` to obtain `776` is not allowed.\n\n* * *"}, {"input": "35753", "output": "0\n \n\nIf `753` itself can be taken out, the answer is 0.\n\n* * *"}, {"input": "1111111111", "output": "642\n \n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642."}] |
Print the minimum possible difference between X and 753.
* * * | s623001013 | Wrong Answer | p03211 | Input is given from Standard Input in the following format:
S | S = list(str(input()))
S = [int(s) for s in S]
num_100 = 0
rm_index = 0
for index, s in enumerate(S):
if abs(7 - s) < abs(7 - num_100):
num_100 = s
rm_index = index
S.pop(rm_index)
num_10 = 0
rm_index = 0
for index, s in enumerate(S):
if abs(5 - s) < abs(5 - num_10):
num_10 = s
rm_index = index
S.pop(rm_index)
num_1 = 0
rm_index = 0
for index, s in enumerate(S):
if abs(3 - s) < abs(3 - num_1):
num_1 = s
rm_index = index
S.pop(rm_index)
print(abs(753 - 100 * num_100 + 10 * num_10 + num_1))
| Statement
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the
Dachshund, will take out three consecutive digits from S, treat them as a
single integer X and bring it to her master. (She cannot rearrange the
digits.)
The master's favorite number is 753. The closer to this number, the better.
What is the minimum possible (absolute) difference between X and 753? | [{"input": "1234567876", "output": "34\n \n\nTaking out the seventh to ninth characters results in X = 787, and the\ndifference between this and 753 is 787 - 753 = 34. The difference cannot be\nmade smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out `567` and\nrearranging it to `765` is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For\nexample, taking out the seventh digit `7`, the ninth digit `7` and the tenth\ndigit `6` to obtain `776` is not allowed.\n\n* * *"}, {"input": "35753", "output": "0\n \n\nIf `753` itself can be taken out, the answer is 0.\n\n* * *"}, {"input": "1111111111", "output": "642\n \n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642."}] |
Print the minimum possible difference between X and 753.
* * * | s041770525 | Runtime Error | p03211 | Input is given from Standard Input in the following format:
S | #! /usr/bin/env python3
# -*- coding: utf-8 -*-
S = list(input())
sublist = []
for i in range(len(S)-2):
num = int("".join(S[i:i+3]))
sublist.append(abs(num-754)
print(min(sublist)) | Statement
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the
Dachshund, will take out three consecutive digits from S, treat them as a
single integer X and bring it to her master. (She cannot rearrange the
digits.)
The master's favorite number is 753. The closer to this number, the better.
What is the minimum possible (absolute) difference between X and 753? | [{"input": "1234567876", "output": "34\n \n\nTaking out the seventh to ninth characters results in X = 787, and the\ndifference between this and 753 is 787 - 753 = 34. The difference cannot be\nmade smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out `567` and\nrearranging it to `765` is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For\nexample, taking out the seventh digit `7`, the ninth digit `7` and the tenth\ndigit `6` to obtain `776` is not allowed.\n\n* * *"}, {"input": "35753", "output": "0\n \n\nIf `753` itself can be taken out, the answer is 0.\n\n* * *"}, {"input": "1111111111", "output": "642\n \n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642."}] |
Print the minimum possible difference between X and 753.
* * * | s254541110 | Runtime Error | p03211 | Input is given from Standard Input in the following format:
S | a=input()
x=abs(int(a[0])*100+int(a[1])*10+int(a[2])-753)
for i in range(i-2)
if abs(int(a[i])*100+int(a[i+1])*10+int(a[i+2])-753)<=x:
x=abs(int(a[i])*100+int(a[i+1])*10+int(a[i+2])-753) | Statement
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the
Dachshund, will take out three consecutive digits from S, treat them as a
single integer X and bring it to her master. (She cannot rearrange the
digits.)
The master's favorite number is 753. The closer to this number, the better.
What is the minimum possible (absolute) difference between X and 753? | [{"input": "1234567876", "output": "34\n \n\nTaking out the seventh to ninth characters results in X = 787, and the\ndifference between this and 753 is 787 - 753 = 34. The difference cannot be\nmade smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out `567` and\nrearranging it to `765` is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For\nexample, taking out the seventh digit `7`, the ninth digit `7` and the tenth\ndigit `6` to obtain `776` is not allowed.\n\n* * *"}, {"input": "35753", "output": "0\n \n\nIf `753` itself can be taken out, the answer is 0.\n\n* * *"}, {"input": "1111111111", "output": "642\n \n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642."}] |
Print the minimum possible difference between X and 753.
* * * | s580328269 | Runtime Error | p03211 | Input is given from Standard Input in the following format:
S | s = input()
l = len(s)
r = 10000
for i in range(l-3):
p = s[i] + s[i+1] + s[i+2]
x = int(p)
r = min(r, abs(x-753))
print(r) | Statement
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the
Dachshund, will take out three consecutive digits from S, treat them as a
single integer X and bring it to her master. (She cannot rearrange the
digits.)
The master's favorite number is 753. The closer to this number, the better.
What is the minimum possible (absolute) difference between X and 753? | [{"input": "1234567876", "output": "34\n \n\nTaking out the seventh to ninth characters results in X = 787, and the\ndifference between this and 753 is 787 - 753 = 34. The difference cannot be\nmade smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out `567` and\nrearranging it to `765` is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For\nexample, taking out the seventh digit `7`, the ninth digit `7` and the tenth\ndigit `6` to obtain `776` is not allowed.\n\n* * *"}, {"input": "35753", "output": "0\n \n\nIf `753` itself can be taken out, the answer is 0.\n\n* * *"}, {"input": "1111111111", "output": "642\n \n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642."}] |
Print the minimum possible difference between X and 753.
* * * | s962602122 | Runtime Error | p03211 | Input is given from Standard Input in the following format:
S | x = 753
s = input()
ans=100
for i in range(len(s)-2):
if(abs(x-int(s[i:i+3]))<ans):
ans=abs(x-int(s[i:i+3))
print(ans) | Statement
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the
Dachshund, will take out three consecutive digits from S, treat them as a
single integer X and bring it to her master. (She cannot rearrange the
digits.)
The master's favorite number is 753. The closer to this number, the better.
What is the minimum possible (absolute) difference between X and 753? | [{"input": "1234567876", "output": "34\n \n\nTaking out the seventh to ninth characters results in X = 787, and the\ndifference between this and 753 is 787 - 753 = 34. The difference cannot be\nmade smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out `567` and\nrearranging it to `765` is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For\nexample, taking out the seventh digit `7`, the ninth digit `7` and the tenth\ndigit `6` to obtain `776` is not allowed.\n\n* * *"}, {"input": "35753", "output": "0\n \n\nIf `753` itself can be taken out, the answer is 0.\n\n* * *"}, {"input": "1111111111", "output": "642\n \n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642."}] |
Print the minimum possible difference between X and 753.
* * * | s579617290 | Runtime Error | p03211 | Input is given from Standard Input in the following format:
S | S = str(input())
ans = 10**3
for i in range(0, len(S)-2):
ans = min(ans, abs(753 - int(S[i:i+2])))
print(ans) | Statement
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the
Dachshund, will take out three consecutive digits from S, treat them as a
single integer X and bring it to her master. (She cannot rearrange the
digits.)
The master's favorite number is 753. The closer to this number, the better.
What is the minimum possible (absolute) difference between X and 753? | [{"input": "1234567876", "output": "34\n \n\nTaking out the seventh to ninth characters results in X = 787, and the\ndifference between this and 753 is 787 - 753 = 34. The difference cannot be\nmade smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out `567` and\nrearranging it to `765` is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For\nexample, taking out the seventh digit `7`, the ninth digit `7` and the tenth\ndigit `6` to obtain `776` is not allowed.\n\n* * *"}, {"input": "35753", "output": "0\n \n\nIf `753` itself can be taken out, the answer is 0.\n\n* * *"}, {"input": "1111111111", "output": "642\n \n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642."}] |
Print the minimum possible difference between X and 753.
* * * | s158611344 | Runtime Error | p03211 | Input is given from Standard Input in the following format:
S | S = input().strip()
print(min(int([S[i:i+3]) for i in range(0,len(S)-2,3))) | Statement
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the
Dachshund, will take out three consecutive digits from S, treat them as a
single integer X and bring it to her master. (She cannot rearrange the
digits.)
The master's favorite number is 753. The closer to this number, the better.
What is the minimum possible (absolute) difference between X and 753? | [{"input": "1234567876", "output": "34\n \n\nTaking out the seventh to ninth characters results in X = 787, and the\ndifference between this and 753 is 787 - 753 = 34. The difference cannot be\nmade smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out `567` and\nrearranging it to `765` is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For\nexample, taking out the seventh digit `7`, the ninth digit `7` and the tenth\ndigit `6` to obtain `776` is not allowed.\n\n* * *"}, {"input": "35753", "output": "0\n \n\nIf `753` itself can be taken out, the answer is 0.\n\n* * *"}, {"input": "1111111111", "output": "642\n \n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642."}] |
Print the minimum possible difference between X and 753.
* * * | s916841672 | Accepted | p03211 | Input is given from Standard Input in the following format:
S | # 値取得
S = str(input())
res = 754
for i in range(len(S)):
s = abs(int(S[i : i + 3]) - 753)
if s < res:
res = s
print(res)
| Statement
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the
Dachshund, will take out three consecutive digits from S, treat them as a
single integer X and bring it to her master. (She cannot rearrange the
digits.)
The master's favorite number is 753. The closer to this number, the better.
What is the minimum possible (absolute) difference between X and 753? | [{"input": "1234567876", "output": "34\n \n\nTaking out the seventh to ninth characters results in X = 787, and the\ndifference between this and 753 is 787 - 753 = 34. The difference cannot be\nmade smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out `567` and\nrearranging it to `765` is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For\nexample, taking out the seventh digit `7`, the ninth digit `7` and the tenth\ndigit `6` to obtain `776` is not allowed.\n\n* * *"}, {"input": "35753", "output": "0\n \n\nIf `753` itself can be taken out, the answer is 0.\n\n* * *"}, {"input": "1111111111", "output": "642\n \n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642."}] |
Print the minimum possible difference between X and 753.
* * * | s432974468 | Runtime Error | p03211 | Input is given from Standard Input in the following format:
S | s = [int(x) for in list(input())]
cand = []
for c1, c2, c3 in zip(s, s[1:], s[2:]):
res = abs(c1 * 100 + c2 * 10 + c3 - 753)
cand.append(res)
print(min(cand))
| Statement
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the
Dachshund, will take out three consecutive digits from S, treat them as a
single integer X and bring it to her master. (She cannot rearrange the
digits.)
The master's favorite number is 753. The closer to this number, the better.
What is the minimum possible (absolute) difference between X and 753? | [{"input": "1234567876", "output": "34\n \n\nTaking out the seventh to ninth characters results in X = 787, and the\ndifference between this and 753 is 787 - 753 = 34. The difference cannot be\nmade smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out `567` and\nrearranging it to `765` is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For\nexample, taking out the seventh digit `7`, the ninth digit `7` and the tenth\ndigit `6` to obtain `776` is not allowed.\n\n* * *"}, {"input": "35753", "output": "0\n \n\nIf `753` itself can be taken out, the answer is 0.\n\n* * *"}, {"input": "1111111111", "output": "642\n \n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642."}] |
Print all pairs (k, x) such that a' and b will be equal, using one line for
each pair, in ascending order of k (ascending order of x for pairs with the
same k).
If there are no such pairs, the output should be empty.
* * * | s813932832 | Accepted | p02816 | Input is given from Standard Input in the following format:
N
a_0 a_1 ... a_{N-1}
b_0 b_1 ... b_{N-1} | class RollingHash(object):
"""
construct: O(N)
query:
hash: O(1)
lcp: O(logN)
search: O(N)
"""
__base1 = 1007
__mod1 = 10**9
__base2 = 1009
__mod2 = 10**7
def __init__(self, s):
n = len(s)
self.__s = s
self.__n = n
b1 = self.__base1
m1 = self.__mod1
b2 = self.__base2
m2 = self.__mod2
H1, H2 = [0] * (n + 1), [0] * (n + 1)
P1, P2 = [1] * (n + 1), [1] * (n + 1)
for i in range(n):
H1[i + 1] = (H1[i] * b1 + (s[i])) % m1
H2[i + 1] = (H2[i] * b2 + (s[i])) % m2
P1[i + 1] = P1[i] * b1 % m1
P2[i + 1] = P2[i] * b2 % m2
self.__H1 = H1
self.__H2 = H2
self.__P1 = P1
self.__P2 = P2
@property
def str(self):
return self.__s
@property
def len(self):
return self.__n
def hash(self, l, r=None):
"""
l,r: int (0<=l<=r<=n)
return (hash1,hash2) of S[l:r]
"""
m1 = self.__mod1
m2 = self.__mod2
if r is None:
r = self.__n
assert 0 <= l <= r <= self.__n
hash1 = (self.__H1[r] - self.__P1[r - l] * self.__H1[l] % m1) % m1
hash2 = (self.__H2[r] - self.__P2[r - l] * self.__H2[l] % m2) % m2
return hash1, hash2
@classmethod
def lcp(cls, rh1, rh2, l1, l2, r1=None, r2=None):
"""
rh1,rh2: RollingHash object
l1,l2,r1,r2: int 0<=l1<=r1<=r1.len, 0<=l2<=r2<=rh2.len
return lcp length between rh1[l1:r1] and rh2[l2:r2]
"""
if r1 is None:
r1 = rh1.__n
if r2 is None:
r2 = rh2.__n
assert 0 <= l1 <= r1 <= rh1.__n and 0 <= l2 <= r2 <= rh2.__n
L = 0
R = min(r1 - l1, r2 - l2)
if rh1.hash(l1, l1 + R) == rh2.hash(l2, l2 + R):
return R
while R - L > 1:
H = (L + R) // 2
if rh1.hash(l1, l1 + H) == rh2.hash(l2, l2 + H):
L = H
else:
R = H
return L
@classmethod
def search(cls, pattern, text):
"""
pattern,text: RollingHash object
return list of index i's satisfying text[i:] starts with pattern
"""
n = text.__n
m = pattern.__n
res = []
for i in range(n - m + 1):
if text.hash(i, i + m) == pattern.hash(0, m):
res.append(i)
return res
def resolve():
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
dA = [A[i] ^ A[(i + 1) % N] for i in range(N)]
dB = [B[i] ^ B[(i + 1) % N] for i in range(N)]
dA += dA
# 今回は数字を扱うのでRollingHash: init() ord削除し対応
RHa = RollingHash(dA)
RHb = RollingHash(dB)
query = RHb.hash(0, N - 1)
ans = []
for i in range(N):
val = RHa.hash(i, i + N - 1)
if val == query:
ans.append((i, A[i] ^ B[0]))
ans.sort()
for k, x in ans:
print(k, x)
if __name__ == "__main__":
resolve()
| Statement
Given are two sequences a=\\{a_0,\ldots,a_{N-1}\\} and
b=\\{b_0,\ldots,b_{N-1}\\} of N non-negative integers each.
Snuke will choose an integer k such that 0 \leq k < N and an integer x not
less than 0, to make a new sequence of length N,
a'=\\{a_0',\ldots,a_{N-1}'\\}, as follows:
* a_i'= a_{i+k \mod N}\ XOR \ x
Find all pairs (k,x) such that a' will be equal to b.
What is \mbox{ XOR }?
The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:
* When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.
For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.) | [{"input": "3\n 0 2 1\n 1 2 3", "output": "1 3\n \n\nIf (k,x)=(1,3),\n\n * a_0'=(a_1\\ XOR \\ 3)=1\n\n * a_1'=(a_2\\ XOR \\ 3)=2\n\n * a_2'=(a_0\\ XOR \\ 3)=3\n\nand we have a' = b.\n\n* * *"}, {"input": "5\n 0 0 0 0 0\n 2 2 2 2 2", "output": "0 2\n 1 2\n 2 2\n 3 2\n 4 2\n \n\n* * *"}, {"input": "6\n 0 1 3 7 6 4\n 1 5 4 6 2 3", "output": "2 2\n 5 5\n \n\n* * *"}, {"input": "2\n 1 2\n 0 0", "output": "No pairs may satisfy the condition."}] |
Print all pairs (k, x) such that a' and b will be equal, using one line for
each pair, in ascending order of k (ascending order of x for pairs with the
same k).
If there are no such pairs, the output should be empty.
* * * | s031489027 | Runtime Error | p02816 | Input is given from Standard Input in the following format:
N
a_0 a_1 ... a_{N-1}
b_0 b_1 ... b_{N-1} | import fractions # version 3.4
from functools import reduce
def gcd(*numbers):
return reduce(fractions.gcd, numbers)
def lcm(*numbers):
return reduce(lambda x, y: (x * y) // fractions.gcd(x, y), numbers, 1)
def s_in():
return input()
def n_in():
return int(input())
def l_in():
return list(map(int, input().split()))
class Interval:
def __init__(self, li):
self.li = li
self.n = len(li)
self.sum_li = [li[0]]
for i in range(1, self.n):
self.sum_li.append(self.sum_li[i - 1] + li[i])
def sum(self, a, b=None):
if b is None:
return self.sum(0, a)
res = self.sum_li[min(self.n - 1, b - 1)]
if a > 0:
res -= self.sum_li[a - 1]
return res
N, M = l_in()
A = l_in()
B = [a // 2 for a in A]
L = lcm(*B)
if any([(L // b) % 2 == 0 for b in B]):
print(0)
else:
print((M // L + 1) // 2)
| Statement
Given are two sequences a=\\{a_0,\ldots,a_{N-1}\\} and
b=\\{b_0,\ldots,b_{N-1}\\} of N non-negative integers each.
Snuke will choose an integer k such that 0 \leq k < N and an integer x not
less than 0, to make a new sequence of length N,
a'=\\{a_0',\ldots,a_{N-1}'\\}, as follows:
* a_i'= a_{i+k \mod N}\ XOR \ x
Find all pairs (k,x) such that a' will be equal to b.
What is \mbox{ XOR }?
The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:
* When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.
For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.) | [{"input": "3\n 0 2 1\n 1 2 3", "output": "1 3\n \n\nIf (k,x)=(1,3),\n\n * a_0'=(a_1\\ XOR \\ 3)=1\n\n * a_1'=(a_2\\ XOR \\ 3)=2\n\n * a_2'=(a_0\\ XOR \\ 3)=3\n\nand we have a' = b.\n\n* * *"}, {"input": "5\n 0 0 0 0 0\n 2 2 2 2 2", "output": "0 2\n 1 2\n 2 2\n 3 2\n 4 2\n \n\n* * *"}, {"input": "6\n 0 1 3 7 6 4\n 1 5 4 6 2 3", "output": "2 2\n 5 5\n \n\n* * *"}, {"input": "2\n 1 2\n 0 0", "output": "No pairs may satisfy the condition."}] |
Print all pairs (k, x) such that a' and b will be equal, using one line for
each pair, in ascending order of k (ascending order of x for pairs with the
same k).
If there are no such pairs, the output should be empty.
* * * | s246433070 | Runtime Error | p02816 | Input is given from Standard Input in the following format:
N
a_0 a_1 ... a_{N-1}
b_0 b_1 ... b_{N-1} | # coding: utf-8
def main():
N = 0
a = []
b = []
with open("C:/Users/admin/Downloads/random_05") as f:
N = int(f.readline())
a = [int(x) for x in f.readline().split()]
b = [int(x) for x in f.readline().split()]
# N = int(input())
# a = [int(x) for x in input().split()]
# b = [int(x) for x in input().split()]
xor_a = [a[i] ^ a[(i + 1) % N] for i in range(len(a))]
xor_b = [b[i] ^ b[(i + 1) % N] for i in range(len(b))]
kmp = KmpSearch(xor_a + xor_a, xor_b)
# start = 0
# ans = []
# x = []
# while True:
# k = kmp.search(start)
# if k == -1 or k == len(a):
# break
# # ans.append(k)
# start = k + 1
# # x.append(a[0 + k] ^ b[0])
# print(str(k) + " " + str(a[0 + k] ^ b[0]))
ans = kmp.full_search()
for k in ans:
print(str(k) + " " + str(a[0 + k] ^ b[0]))
# for i in range(len(ans)):
# print(str(ans[i]) + " " + str(x[i]))
class KmpSearch:
def __init__(self, target, pattern):
self.target = target
self.pattern = pattern
self.__table = self.__create_kmp_table()
def search(self, start=0):
if len(self.pattern) > len(self.target):
return -1
i = start
p = 0
while i < len(self.target):
if self.pattern[p] == self.target[i]:
i += 1
p += 1
if p == len(self.pattern):
return i - p
elif p == 0:
i += 1
else:
p = self.__table[p]
return -1
def full_search(self):
if len(self.pattern) > len(self.target):
return -1
res = []
i = 0
p = 0
while i < len(self.target):
if self.pattern[p] == self.target[i]:
i += 1
p += 1
if p == len(self.pattern):
res.append(i - p)
i -= 1
p = self.__table[p - 1]
elif p == 0:
i += 1
else:
p = self.__table[p]
return res
def __create_kmp_table(self):
table = [0 for x in range(len(self.pattern))]
j = 0
for i in range(1, len(self.pattern)):
table[i] = j
if self.pattern[j] == self.pattern[i]:
j += 1
else:
j = 0
return table
if __name__ == "__main__":
main()
| Statement
Given are two sequences a=\\{a_0,\ldots,a_{N-1}\\} and
b=\\{b_0,\ldots,b_{N-1}\\} of N non-negative integers each.
Snuke will choose an integer k such that 0 \leq k < N and an integer x not
less than 0, to make a new sequence of length N,
a'=\\{a_0',\ldots,a_{N-1}'\\}, as follows:
* a_i'= a_{i+k \mod N}\ XOR \ x
Find all pairs (k,x) such that a' will be equal to b.
What is \mbox{ XOR }?
The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:
* When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.
For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.) | [{"input": "3\n 0 2 1\n 1 2 3", "output": "1 3\n \n\nIf (k,x)=(1,3),\n\n * a_0'=(a_1\\ XOR \\ 3)=1\n\n * a_1'=(a_2\\ XOR \\ 3)=2\n\n * a_2'=(a_0\\ XOR \\ 3)=3\n\nand we have a' = b.\n\n* * *"}, {"input": "5\n 0 0 0 0 0\n 2 2 2 2 2", "output": "0 2\n 1 2\n 2 2\n 3 2\n 4 2\n \n\n* * *"}, {"input": "6\n 0 1 3 7 6 4\n 1 5 4 6 2 3", "output": "2 2\n 5 5\n \n\n* * *"}, {"input": "2\n 1 2\n 0 0", "output": "No pairs may satisfy the condition."}] |
Print all pairs (k, x) such that a' and b will be equal, using one line for
each pair, in ascending order of k (ascending order of x for pairs with the
same k).
If there are no such pairs, the output should be empty.
* * * | s115987911 | Accepted | p02816 | Input is given from Standard Input in the following format:
N
a_0 a_1 ... a_{N-1}
b_0 b_1 ... b_{N-1} | def check(ccc, ddd, e, ans):
m = 2147483647
g = 1000000007
for l in range(e):
cl = ccc[l]
if any(c != cl for c in ccc[l::e]):
return
dl = ddd[l]
if any(d != dl for d in ddd[l::e]):
return
s = 0
for c in ccc[:e]:
s = (s * g + c) % m
t = 0
for d in ddd[:e]:
t = (t * g + d) % m
u = pow(g, e, m)
for h in range(e):
if s == t:
bh = bbb[h]
ans.update(((i - h) % n, aaa[i] ^ bh) for i in range(0, n, e))
return
t = (t * g + ddd[(e + h) % n] - ddd[h] * u) % m
def solve(n, aaa, bbb):
ccc = [a1 ^ a2 for a1, a2 in zip(aaa, aaa[1:])] + [aaa[-1] ^ aaa[0]]
ddd = [b1 ^ b2 for b1, b2 in zip(bbb, bbb[1:])] + [bbb[-1] ^ bbb[0]]
ans = set()
e = 1
while e * e <= n:
if n % e != 0:
e += 1
continue
check(ccc, ddd, e, ans)
check(ccc, ddd, n // e, ans)
e += 1
return ans
n = int(input())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
ans = solve(n, aaa, bbb)
print("".join("{} {}\n".format(*answer) for answer in sorted(ans)))
| Statement
Given are two sequences a=\\{a_0,\ldots,a_{N-1}\\} and
b=\\{b_0,\ldots,b_{N-1}\\} of N non-negative integers each.
Snuke will choose an integer k such that 0 \leq k < N and an integer x not
less than 0, to make a new sequence of length N,
a'=\\{a_0',\ldots,a_{N-1}'\\}, as follows:
* a_i'= a_{i+k \mod N}\ XOR \ x
Find all pairs (k,x) such that a' will be equal to b.
What is \mbox{ XOR }?
The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:
* When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.
For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.) | [{"input": "3\n 0 2 1\n 1 2 3", "output": "1 3\n \n\nIf (k,x)=(1,3),\n\n * a_0'=(a_1\\ XOR \\ 3)=1\n\n * a_1'=(a_2\\ XOR \\ 3)=2\n\n * a_2'=(a_0\\ XOR \\ 3)=3\n\nand we have a' = b.\n\n* * *"}, {"input": "5\n 0 0 0 0 0\n 2 2 2 2 2", "output": "0 2\n 1 2\n 2 2\n 3 2\n 4 2\n \n\n* * *"}, {"input": "6\n 0 1 3 7 6 4\n 1 5 4 6 2 3", "output": "2 2\n 5 5\n \n\n* * *"}, {"input": "2\n 1 2\n 0 0", "output": "No pairs may satisfy the condition."}] |
Print all pairs (k, x) such that a' and b will be equal, using one line for
each pair, in ascending order of k (ascending order of x for pairs with the
same k).
If there are no such pairs, the output should be empty.
* * * | s177094805 | Wrong Answer | p02816 | Input is given from Standard Input in the following format:
N
a_0 a_1 ... a_{N-1}
b_0 b_1 ... b_{N-1} | import sys
input = sys.stdin.readline
N = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
class RollingHash:
def __init__(self, S, base=26, mod=2**61 - 1):
hash = [0]
pow = [1]
for s in S:
hash.append((hash[-1] * base + s) % mod)
pow.append(pow[-1] * base % mod)
self.hash = hash
self.pow = pow
self.mod = mod
def get(self, l, r):
return (self.hash[r + 1] - self.hash[l] * self.pow[r + 1 - l]) % self.mod
da = [a[i] ^ a[(i + 1) % N] for i in range(N)] * 2
db = [b[i] ^ b[(i + 1) % N] for i in range(N)] * 2
RHa = RollingHash(da, base=1 << 30)
RHb = RollingHash(db, base=1 << 30)
hashb = RHb.get(0, N - 1)
for i in range(N):
if RHa.get(i, N - 1 + i) == hashb:
print(i, a[i] ^ b[0])
| Statement
Given are two sequences a=\\{a_0,\ldots,a_{N-1}\\} and
b=\\{b_0,\ldots,b_{N-1}\\} of N non-negative integers each.
Snuke will choose an integer k such that 0 \leq k < N and an integer x not
less than 0, to make a new sequence of length N,
a'=\\{a_0',\ldots,a_{N-1}'\\}, as follows:
* a_i'= a_{i+k \mod N}\ XOR \ x
Find all pairs (k,x) such that a' will be equal to b.
What is \mbox{ XOR }?
The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:
* When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.
For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.) | [{"input": "3\n 0 2 1\n 1 2 3", "output": "1 3\n \n\nIf (k,x)=(1,3),\n\n * a_0'=(a_1\\ XOR \\ 3)=1\n\n * a_1'=(a_2\\ XOR \\ 3)=2\n\n * a_2'=(a_0\\ XOR \\ 3)=3\n\nand we have a' = b.\n\n* * *"}, {"input": "5\n 0 0 0 0 0\n 2 2 2 2 2", "output": "0 2\n 1 2\n 2 2\n 3 2\n 4 2\n \n\n* * *"}, {"input": "6\n 0 1 3 7 6 4\n 1 5 4 6 2 3", "output": "2 2\n 5 5\n \n\n* * *"}, {"input": "2\n 1 2\n 0 0", "output": "No pairs may satisfy the condition."}] |
Print all pairs (k, x) such that a' and b will be equal, using one line for
each pair, in ascending order of k (ascending order of x for pairs with the
same k).
If there are no such pairs, the output should be empty.
* * * | s577445518 | Accepted | p02816 | Input is given from Standard Input in the following format:
N
a_0 a_1 ... a_{N-1}
b_0 b_1 ... b_{N-1} | N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.append(A[0])
B.append(B[0])
AX = []
BX = []
for i in range(N):
AX.append(A[i] ^ A[i + 1])
BX.append(B[i] ^ B[i + 1])
AX += AX[:-1]
# MP法
LEN = len(BX)
MP = [-1] * (LEN + 1) # 「接頭辞と接尾辞が最大何文字一致しているか」を記録する配列
NOW = -1 # 何文字一致しているか.
for i in range(LEN):
while (
NOW >= 0 and BX[i] != BX[NOW]
): # 一致していなかったら0から数え直すのではなく, MP[NOW]から数える.
NOW = MP[NOW]
NOW += 1
MP[i + 1] = NOW
LEN2 = len(AX)
MP_SEARCH = [0] * (
LEN2
) # その文字までで何個一致しているかを調べる. LEN文字一致したらSが検出できたということ.
NOW = 0
for i in range(LEN2):
while NOW >= 0 and AX[i] != BX[NOW]:
NOW = MP[NOW]
NOW += 1
MP_SEARCH[i] = NOW
if NOW == LEN: # LEN文字一致したら, MP[LEN]から数える.
NOW = MP[NOW]
for i in range(LEN2):
if MP_SEARCH[i] == LEN:
print(i - LEN + 1, A[i - LEN + 1] ^ B[0])
| Statement
Given are two sequences a=\\{a_0,\ldots,a_{N-1}\\} and
b=\\{b_0,\ldots,b_{N-1}\\} of N non-negative integers each.
Snuke will choose an integer k such that 0 \leq k < N and an integer x not
less than 0, to make a new sequence of length N,
a'=\\{a_0',\ldots,a_{N-1}'\\}, as follows:
* a_i'= a_{i+k \mod N}\ XOR \ x
Find all pairs (k,x) such that a' will be equal to b.
What is \mbox{ XOR }?
The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:
* When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.
For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.) | [{"input": "3\n 0 2 1\n 1 2 3", "output": "1 3\n \n\nIf (k,x)=(1,3),\n\n * a_0'=(a_1\\ XOR \\ 3)=1\n\n * a_1'=(a_2\\ XOR \\ 3)=2\n\n * a_2'=(a_0\\ XOR \\ 3)=3\n\nand we have a' = b.\n\n* * *"}, {"input": "5\n 0 0 0 0 0\n 2 2 2 2 2", "output": "0 2\n 1 2\n 2 2\n 3 2\n 4 2\n \n\n* * *"}, {"input": "6\n 0 1 3 7 6 4\n 1 5 4 6 2 3", "output": "2 2\n 5 5\n \n\n* * *"}, {"input": "2\n 1 2\n 0 0", "output": "No pairs may satisfy the condition."}] |
Print all pairs (k, x) such that a' and b will be equal, using one line for
each pair, in ascending order of k (ascending order of x for pairs with the
same k).
If there are no such pairs, the output should be empty.
* * * | s915684635 | Wrong Answer | p02816 | Input is given from Standard Input in the following format:
N
a_0 a_1 ... a_{N-1}
b_0 b_1 ... b_{N-1} | def main():
mod = 2**61 - 1
pow3 = [1] * 400001
pow3i = [1] * 200001
p = 1
i3 = pow(3, mod - 2, mod)
for i in range(1, 400001):
p = p * 3 % mod
pow3[i] = p
p = 1
for i in range(1, 200001):
p = p * i3 % mod
pow3i[i] = p
class rolling_hash:
def __init__(self, seq):
seq_size = len(seq) # 文字列の長さ
self.H0s = [0] * (seq_size + 1) # 先頭からi-1文字目までのハッシュ値
H0s, p = self.H0s, 0
for i, j in enumerate(seq):
p = (p + (j + 1) * pow3[i]) % mod
H0s[i + 1] = p
def calc_hash(self, l, r): # l文字目からr-1文字目までのハッシュ値
H0s = self.H0s
return ((H0s[r] - H0s[l]) * pow3i[l]) % mod
def rolling_hash2(seq):
p = 0
for i, j in enumerate(seq):
p += (j + 1) * pow3[i] % mod
return p % mod
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m = max(a + b)
a += a
a1 = [0] * (2 * n)
a2 = [0] * (2 * n)
b1 = [0] * n
memo = [0] * n
cnt = n
for k in range(len(bin(m)) - 2):
k2 = 2**k
for i, j in enumerate(a):
p = j & k2
a1[i] = p
a2[i] = p ^ k2
for i, j in enumerate(b):
b1[i] = j & k2
b_hash = rolling_hash2(b1)
A1 = rolling_hash(a1)
A2 = rolling_hash(a2)
for i, j in enumerate(memo):
if j is None:
continue
elif A1.calc_hash(i, i + n) == b_hash:
pass
elif A2.calc_hash(i, i + n) == b_hash:
memo[i] += k2
else:
memo[i] = None
cnt -= 1
if cnt == 0:
print(-1)
return
for i, j in enumerate(memo):
if j is not None:
print(i, j)
main()
| Statement
Given are two sequences a=\\{a_0,\ldots,a_{N-1}\\} and
b=\\{b_0,\ldots,b_{N-1}\\} of N non-negative integers each.
Snuke will choose an integer k such that 0 \leq k < N and an integer x not
less than 0, to make a new sequence of length N,
a'=\\{a_0',\ldots,a_{N-1}'\\}, as follows:
* a_i'= a_{i+k \mod N}\ XOR \ x
Find all pairs (k,x) such that a' will be equal to b.
What is \mbox{ XOR }?
The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:
* When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.
For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.) | [{"input": "3\n 0 2 1\n 1 2 3", "output": "1 3\n \n\nIf (k,x)=(1,3),\n\n * a_0'=(a_1\\ XOR \\ 3)=1\n\n * a_1'=(a_2\\ XOR \\ 3)=2\n\n * a_2'=(a_0\\ XOR \\ 3)=3\n\nand we have a' = b.\n\n* * *"}, {"input": "5\n 0 0 0 0 0\n 2 2 2 2 2", "output": "0 2\n 1 2\n 2 2\n 3 2\n 4 2\n \n\n* * *"}, {"input": "6\n 0 1 3 7 6 4\n 1 5 4 6 2 3", "output": "2 2\n 5 5\n \n\n* * *"}, {"input": "2\n 1 2\n 0 0", "output": "No pairs may satisfy the condition."}] |
Print all pairs (k, x) such that a' and b will be equal, using one line for
each pair, in ascending order of k (ascending order of x for pairs with the
same k).
If there are no such pairs, the output should be empty.
* * * | s308662442 | Wrong Answer | p02816 | Input is given from Standard Input in the following format:
N
a_0 a_1 ... a_{N-1}
b_0 b_1 ... b_{N-1} | import numpy as np
N = int(input())
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))
NA = np.array(range(N))
buf = []
for k in range(N):
g = a[list(np.array(range(k, N + k)) % N)]
if sum(g - g[0]) == 0:
buf.append((k, g[0]))
for d in buf:
print(*d)
| Statement
Given are two sequences a=\\{a_0,\ldots,a_{N-1}\\} and
b=\\{b_0,\ldots,b_{N-1}\\} of N non-negative integers each.
Snuke will choose an integer k such that 0 \leq k < N and an integer x not
less than 0, to make a new sequence of length N,
a'=\\{a_0',\ldots,a_{N-1}'\\}, as follows:
* a_i'= a_{i+k \mod N}\ XOR \ x
Find all pairs (k,x) such that a' will be equal to b.
What is \mbox{ XOR }?
The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:
* When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.
For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.) | [{"input": "3\n 0 2 1\n 1 2 3", "output": "1 3\n \n\nIf (k,x)=(1,3),\n\n * a_0'=(a_1\\ XOR \\ 3)=1\n\n * a_1'=(a_2\\ XOR \\ 3)=2\n\n * a_2'=(a_0\\ XOR \\ 3)=3\n\nand we have a' = b.\n\n* * *"}, {"input": "5\n 0 0 0 0 0\n 2 2 2 2 2", "output": "0 2\n 1 2\n 2 2\n 3 2\n 4 2\n \n\n* * *"}, {"input": "6\n 0 1 3 7 6 4\n 1 5 4 6 2 3", "output": "2 2\n 5 5\n \n\n* * *"}, {"input": "2\n 1 2\n 0 0", "output": "No pairs may satisfy the condition."}] |
Print all pairs (k, x) such that a' and b will be equal, using one line for
each pair, in ascending order of k (ascending order of x for pairs with the
same k).
If there are no such pairs, the output should be empty.
* * * | s441810673 | Wrong Answer | p02816 | Input is given from Standard Input in the following format:
N
a_0 a_1 ... a_{N-1}
b_0 b_1 ... b_{N-1} | N = int(input())
def input_data():
data = list(map(int, input().split()))
xor_data = [data[i] ^ data[(i + 1) % N] for i in range(N)]
table = {}
for i, x in enumerate(xor_data):
if x in table:
table[x].append(i)
else:
table[x] = [i]
count_data = [(len(offsets), value) for value, offsets in table.items()]
count_data.sort()
return data, xor_data, table, count_data
a_data, a_xor, a_table, a_counts = input_data()
b_data, b_xor, b_table, b_counts = input_data()
# print(a_counts)
# print(b_counts)
if a_counts == b_counts:
a = a_counts[0][1]
b = b_counts[0][1]
a_offsets = a_table[a]
b_offsets = b_table[b]
a_offset = a_offsets[0]
k_cands = set(((N + a_offset - b_offset) % N for b_offset in b_offsets))
# print(k_cands)
for i in range(1, len(b_counts)):
a = a_counts[i][1]
b = b_counts[i][1]
a_offsets = a_table[a]
b_offsets = b_table[b]
new_k_cands = set()
for k in k_cands:
a_offsets_tmp = [(N + a_offset - k) % N for a_offset in a_offsets]
a_offsets_tmp.sort()
# print(a_offsets_tmp, b_offsets)
if a_offsets_tmp == b_offsets:
new_k_cands.add(k)
k_cands = new_k_cands
for k in k_cands:
print(k, a_data[k] ^ b_data[0])
| Statement
Given are two sequences a=\\{a_0,\ldots,a_{N-1}\\} and
b=\\{b_0,\ldots,b_{N-1}\\} of N non-negative integers each.
Snuke will choose an integer k such that 0 \leq k < N and an integer x not
less than 0, to make a new sequence of length N,
a'=\\{a_0',\ldots,a_{N-1}'\\}, as follows:
* a_i'= a_{i+k \mod N}\ XOR \ x
Find all pairs (k,x) such that a' will be equal to b.
What is \mbox{ XOR }?
The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:
* When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.
For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.) | [{"input": "3\n 0 2 1\n 1 2 3", "output": "1 3\n \n\nIf (k,x)=(1,3),\n\n * a_0'=(a_1\\ XOR \\ 3)=1\n\n * a_1'=(a_2\\ XOR \\ 3)=2\n\n * a_2'=(a_0\\ XOR \\ 3)=3\n\nand we have a' = b.\n\n* * *"}, {"input": "5\n 0 0 0 0 0\n 2 2 2 2 2", "output": "0 2\n 1 2\n 2 2\n 3 2\n 4 2\n \n\n* * *"}, {"input": "6\n 0 1 3 7 6 4\n 1 5 4 6 2 3", "output": "2 2\n 5 5\n \n\n* * *"}, {"input": "2\n 1 2\n 0 0", "output": "No pairs may satisfy the condition."}] |
Print all pairs (k, x) such that a' and b will be equal, using one line for
each pair, in ascending order of k (ascending order of x for pairs with the
same k).
If there are no such pairs, the output should be empty.
* * * | s649176371 | Wrong Answer | p02816 | Input is given from Standard Input in the following format:
N
a_0 a_1 ... a_{N-1}
b_0 b_1 ... b_{N-1} | n = int(input())
yaku = [0]
for i in range(1, n):
if n % i == 0:
yaku.append(i)
yaku.append(n - i)
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
def c(i):
ret = []
for k in yaku:
ok1 = True
ok2 = True
for j in range(n):
# print(i, j, k, (a[(j + k) % n] & i), (b[j] & i))
if (a[(j + k) % n] & i == 0) == (b[j] & i == 0):
ok2 &= False
else:
ok1 &= False
ret.append([k, ok1 or ok2, ok2])
return ret
ans = {i: [True, 0] for i in yaku}
i = 1
for _ in range(32):
# print(c(i),ans)
for d in c(i):
ans[d[0]] = [ans[d[0]][0] and d[1], ans[d[0]][1] + i * d[2]]
i *= 2
ans2 = []
for i in ans:
if ans[i][0]:
if i != 1:
ans2.append((i, ans[i][1]))
else:
for j in range(i, n, i):
ans2.append((j, ans[i][1]))
ans2 = list(set(ans2))
ans2.sort()
for i in ans2:
print(i[0], i[1])
| Statement
Given are two sequences a=\\{a_0,\ldots,a_{N-1}\\} and
b=\\{b_0,\ldots,b_{N-1}\\} of N non-negative integers each.
Snuke will choose an integer k such that 0 \leq k < N and an integer x not
less than 0, to make a new sequence of length N,
a'=\\{a_0',\ldots,a_{N-1}'\\}, as follows:
* a_i'= a_{i+k \mod N}\ XOR \ x
Find all pairs (k,x) such that a' will be equal to b.
What is \mbox{ XOR }?
The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:
* When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.
For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.) | [{"input": "3\n 0 2 1\n 1 2 3", "output": "1 3\n \n\nIf (k,x)=(1,3),\n\n * a_0'=(a_1\\ XOR \\ 3)=1\n\n * a_1'=(a_2\\ XOR \\ 3)=2\n\n * a_2'=(a_0\\ XOR \\ 3)=3\n\nand we have a' = b.\n\n* * *"}, {"input": "5\n 0 0 0 0 0\n 2 2 2 2 2", "output": "0 2\n 1 2\n 2 2\n 3 2\n 4 2\n \n\n* * *"}, {"input": "6\n 0 1 3 7 6 4\n 1 5 4 6 2 3", "output": "2 2\n 5 5\n \n\n* * *"}, {"input": "2\n 1 2\n 0 0", "output": "No pairs may satisfy the condition."}] |
Print the number of the positive integers N such that rev(N) = N + D.
* * * | s876963237 | Wrong Answer | p03704 | Input is given from Standard Input in the following format:
D | D = int(input())
def table(i, k):
if i == k:
return list(range(9, -1, -1)) + [0] * 9
else:
return list(range(10, 0, -1)) + list(range(1, 10))
def nine(i):
return 10**i - 1
def rec(d, i, k):
res = 0
num = table(i, k)
if i == 1:
for j in range(-9, 10):
if 9 * j == d:
return num[j]
return 0
if i == 2:
for j in range(-9, 10):
if d == 99 * j:
return 10 * num[j]
if not -10 * nine(i) <= d <= 10 * nine(i):
return 0
for j in range(-9, 10):
if d % 10 == j * nine(i) % 10:
res += num[j] * rec((d - j * nine(i)) // 10, i - 2, k)
return res
l = 0
while D % 10 == 0:
D //= 10
l += 1
if l == 0:
a = 1
else:
a = 9 * 10 ** (l - 1)
ans = 0
for i in range(1, 17):
if not l:
ans += rec(D, i, i)
else:
ans += rec(D, i, 100)
if ans % 9 != 0:
ans = 0
print(a * ans)
| Statement
For a positive integer n, we denote the integer obtained by reversing the
decimal notation of n (without leading zeroes) by rev(n). For example,
rev(123) = 321 and rev(4000) = 4.
You are given a positive integer D. How many positive integers N satisfy
rev(N) = N + D? | [{"input": "63", "output": "2\n \n\nThere are two positive integers N such that rev(N) = N + 63: N = 18 and 29.\n\n* * *"}, {"input": "75", "output": "0\n \n\nThere are no positive integers N such that rev(N) = N + 75.\n\n* * *"}, {"input": "864197532", "output": "1920"}] |
Print the number of the positive integers N such that rev(N) = N + D.
* * * | s577820391 | Accepted | p03704 | Input is given from Standard Input in the following format:
D | D = int(input())
count = 0
while D % 10 == 0:
count += 1
D //= 10
if not count:
ans = 0
for i in range(1, 1000):
val = str(i)
val = val[::-1]
rev = int(val)
if rev - i == D:
ans += 1
for d in range(4, 18):
dic1 = {}
dic2 = {}
if d % 2 == 0:
k = d // 2
l = k // 2
def dfs(n, a):
if n == l:
val = 0
res = 1
for i in range(len(a)):
val += a[i] * (10 ** (d - 1 - i) - 10**i)
if i != 0:
res *= 10 - abs(a[i])
else:
res *= 9 - abs(a[i])
if val not in dic1:
dic1[val] = 0
dic1[val] += res
return 0
for i in range(-9, 10):
dfs(n + 1, a + [i])
dfs(0, [])
def dfs2(n, a):
if n == k:
val = 0
res = 1
for i in range(len(a)):
val += a[i] * (10 ** (d - 1 - l - i) - 10 ** (i + l))
if i != 0:
res *= 10 - abs(a[i])
else:
res *= 10 - abs(a[i])
if val not in dic2:
dic2[val] = 0
dic2[val] += res
return 0
for i in range(-9, 10):
dfs2(n + 1, a + [i])
dfs2(l, [])
for i in dic1:
if D - i in dic2:
ans += dic1[i] * dic2[D - i]
else:
k = d // 2
l = k // 2
def dfs(n, a):
if n == l:
val = 0
res = 1
for i in range(len(a)):
val += a[i] * (10 ** (d - 1 - i) - 10**i)
if i != 0:
res *= 10 - abs(a[i])
else:
res *= 9 - abs(a[i])
if val not in dic1:
dic1[val] = 0
dic1[val] += res
return 0
for i in range(-9, 10):
dfs(n + 1, a + [i])
dfs(0, [])
def dfs2(n, a):
if n == k:
val = 0
res = 1
for i in range(len(a)):
val += a[i] * (10 ** (d - 1 - l - i) - 10 ** (i + l))
if i != 0:
res *= 10 - abs(a[i])
else:
res *= 10 - abs(a[i])
if val not in dic2:
dic2[val] = 0
dic2[val] += res
return 0
for i in range(-9, 10):
dfs2(n + 1, a + [i])
dfs2(l, [])
for i in dic1:
if D - i in dic2:
ans += dic1[i] * dic2[D - i] * 10
print(ans)
else:
ans = 0
for d in range(1, 18):
dic1 = {}
dic2 = {}
if d % 2 == 0:
k = d // 2
l = k // 2
def dfs(n, a):
if n == l:
val = 0
res = 1
for i in range(len(a)):
val += a[i] * (10 ** (d - 1 - i) - 10**i)
if i != 0:
res *= 10 - abs(a[i])
else:
res *= 10 - abs(a[i])
if val not in dic1:
dic1[val] = 0
dic1[val] += res
return 0
for i in range(-9, 10):
dfs(n + 1, a + [i])
dfs(0, [])
def dfs2(n, a):
if n == k:
val = 0
res = 1
for i in range(len(a)):
val += a[i] * (10 ** (d - 1 - l - i) - 10 ** (i + l))
if i != 0:
res *= 10 - abs(a[i])
else:
res *= 10 - abs(a[i])
if val not in dic2:
dic2[val] = 0
dic2[val] += res
return 0
for i in range(-9, 10):
dfs2(n + 1, a + [i])
dfs2(l, [])
for i in dic1:
if D - i in dic2:
ans += dic1[i] * dic2[D - i]
else:
k = d // 2
l = k // 2
def dfs(n, a):
if n == l:
val = 0
res = 1
for i in range(len(a)):
val += a[i] * (10 ** (d - 1 - i) - 10**i)
if i != 0:
res *= 10 - abs(a[i])
else:
res *= 10 - abs(a[i])
if val not in dic1:
dic1[val] = 0
dic1[val] += res
return 0
for i in range(-9, 10):
dfs(n + 1, a + [i])
dfs(0, [])
def dfs2(n, a):
if n == k:
val = 0
res = 1
for i in range(len(a)):
val += a[i] * (10 ** (d - 1 - l - i) - 10 ** (i + l))
if i != 0:
res *= 10 - abs(a[i])
else:
res *= 10 - abs(a[i])
if val not in dic2:
dic2[val] = 0
dic2[val] += res
return 0
for i in range(-9, 10):
dfs2(n + 1, a + [i])
dfs2(l, [])
for i in dic1:
if D - i in dic2:
ans += dic1[i] * dic2[D - i] * 10
print(ans * 9 * 10 ** (count - 1))
| Statement
For a positive integer n, we denote the integer obtained by reversing the
decimal notation of n (without leading zeroes) by rev(n). For example,
rev(123) = 321 and rev(4000) = 4.
You are given a positive integer D. How many positive integers N satisfy
rev(N) = N + D? | [{"input": "63", "output": "2\n \n\nThere are two positive integers N such that rev(N) = N + 63: N = 18 and 29.\n\n* * *"}, {"input": "75", "output": "0\n \n\nThere are no positive integers N such that rev(N) = N + 75.\n\n* * *"}, {"input": "864197532", "output": "1920"}] |
Print the number of the positive integers N such that rev(N) = N + D.
* * * | s976143388 | Wrong Answer | p03704 | Input is given from Standard Input in the following format:
D | D = int(input())
ans = 0
for i in range(1000000):
if int(str(i)[::-1]) == i + D:
ans += 1
print(ans)
| Statement
For a positive integer n, we denote the integer obtained by reversing the
decimal notation of n (without leading zeroes) by rev(n). For example,
rev(123) = 321 and rev(4000) = 4.
You are given a positive integer D. How many positive integers N satisfy
rev(N) = N + D? | [{"input": "63", "output": "2\n \n\nThere are two positive integers N such that rev(N) = N + 63: N = 18 and 29.\n\n* * *"}, {"input": "75", "output": "0\n \n\nThere are no positive integers N such that rev(N) = N + 75.\n\n* * *"}, {"input": "864197532", "output": "1920"}] |
Print the maximum possible number of i such that p_i = i after operations.
* * * | s148898063 | Wrong Answer | p03354 | Input is given from Standard Input in the following format:
N M
p_1 p_2 .. p_N
x_1 y_1
x_2 y_2
:
x_M y_M | line = input().split(" ")
n, m = int(line[0]), int(line[1])
line = input().split(" ")
operations = []
for i in range(m):
test = input().split(" ")
operations.append((int(test[0]), int(test[1])))
correct = []
line2 = []
for i in range(len(line)):
line2.append(int(line[i]))
correct.append(i + 1)
count = 0
for l, c in zip(line2, correct):
if l == c:
count += 1
if count == n:
print(count)
else:
for i in range(len(operations)):
if (
line2[operations[i][0] - 1] == operations[i][1]
or line2[operations[i][1] - 1] == operations[i][0]
):
temp = line2[operations[i][0] - 1]
line2[operations[i][0] - 1] = line2[operations[i][1] - 1]
line2[operations[i][1] - 1] = temp
count = 0
for l, c in zip(line2, correct):
if l == c:
count += 1
print(count)
| Statement
We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We
also have M pairs of two integers between 1 and N (inclusive), represented as
(x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the
following operation on p as many times as desired so that the number of i (1 ≤
i ≤ N) such that p_i = i is maximized:
* Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}.
Find the maximum possible number of i such that p_i = i after operations. | [{"input": "5 2\n 5 3 1 4 2\n 1 3\n 5 4", "output": "2\n \n\nIf we perform the operation by choosing j=1, p becomes `1 3 5 4 2`, which is\noptimal, so the answer is 2.\n\n* * *"}, {"input": "3 2\n 3 2 1\n 1 2\n 2 3", "output": "3\n \n\nIf we perform the operation by, for example, choosing j=1, j=2, j=1 in this\norder, p becomes `1 2 3`, which is obviously optimal. Note that we may choose\nthe same j any number of times.\n\n* * *"}, {"input": "10 8\n 5 3 6 8 7 10 9 1 2 4\n 3 1\n 4 1\n 5 9\n 2 5\n 6 5\n 3 5\n 8 9\n 7 9", "output": "8\n \n\n* * *"}, {"input": "5 1\n 1 2 3 4 5\n 1 5", "output": "5\n \n\nWe do not have to perform the operation."}] |
Print the maximum possible number of i such that p_i = i after operations.
* * * | s059626227 | Accepted | p03354 | Input is given from Standard Input in the following format:
N M
p_1 p_2 .. p_N
x_1 y_1
x_2 y_2
:
x_M y_M | # -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
# from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9 + 7
INF = float("inf")
AZ = "abcdefghijklmnopqrstuvwxyz"
#############
# 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))))
def base_10_to_n_without_0(X, n):
X -= 1
if X // n:
return base_10_to_n_without_0(X // n, n) + [X % n]
return [X % n]
#####IntLog#####
def int_log(n, a):
count = 0
while n >= a:
n //= a
count += 1
return count
#############
# Main Code #
#############
N, M = IL()
N = N + 1
L = [0] + IL()
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())
U = UnionFind(N)
for _ in range(M):
u, v = IL()
U.union(u, v)
DICMEM = DD(list)
DICNUM = DD(list)
for i in range(U.n):
DICMEM[U.find(i)].append(i)
DICNUM[U.find(i)].append(L[i])
count = 0
for r in U.roots():
DICMEM[r].sort()
DICNUM[r].sort()
while DICMEM[r] and DICNUM[r]:
if DICMEM[r][-1] == DICNUM[r][-1]:
count += 1
DICMEM[r].pop()
DICNUM[r].pop()
elif DICMEM[r][-1] > DICNUM[r][-1]:
DICMEM[r].pop()
else:
DICNUM[r].pop()
print(count - 1)
| Statement
We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We
also have M pairs of two integers between 1 and N (inclusive), represented as
(x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the
following operation on p as many times as desired so that the number of i (1 ≤
i ≤ N) such that p_i = i is maximized:
* Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}.
Find the maximum possible number of i such that p_i = i after operations. | [{"input": "5 2\n 5 3 1 4 2\n 1 3\n 5 4", "output": "2\n \n\nIf we perform the operation by choosing j=1, p becomes `1 3 5 4 2`, which is\noptimal, so the answer is 2.\n\n* * *"}, {"input": "3 2\n 3 2 1\n 1 2\n 2 3", "output": "3\n \n\nIf we perform the operation by, for example, choosing j=1, j=2, j=1 in this\norder, p becomes `1 2 3`, which is obviously optimal. Note that we may choose\nthe same j any number of times.\n\n* * *"}, {"input": "10 8\n 5 3 6 8 7 10 9 1 2 4\n 3 1\n 4 1\n 5 9\n 2 5\n 6 5\n 3 5\n 8 9\n 7 9", "output": "8\n \n\n* * *"}, {"input": "5 1\n 1 2 3 4 5\n 1 5", "output": "5\n \n\nWe do not have to perform the operation."}] |
Print the maximum possible number of i such that p_i = i after operations.
* * * | s968074720 | Runtime Error | p03354 | Input is given from Standard Input in the following format:
N M
p_1 p_2 .. p_N
x_1 y_1
x_2 y_2
:
x_M y_M | def main():
n, m = map(int, input().split())
p = [0] + list(map(int, input().split()))
cnt = 0
global parent
parent = list(range(n+1))
for _ in range(m):
x, y = map(int, input().split())
unite(x, y)
for i in range(1, n+1):
if root(i) == root(p[i]):
cnt += 1
print(cnt)
def root(x):
if parent[x] == x:
return x
parent[x] = root(parent[x])
return parent[x]
def unite(x, y):
root_x = root(x)
if root_x != root(y):
parent[root_x] = y
if __name__ == "__main__":
main() | Statement
We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We
also have M pairs of two integers between 1 and N (inclusive), represented as
(x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the
following operation on p as many times as desired so that the number of i (1 ≤
i ≤ N) such that p_i = i is maximized:
* Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}.
Find the maximum possible number of i such that p_i = i after operations. | [{"input": "5 2\n 5 3 1 4 2\n 1 3\n 5 4", "output": "2\n \n\nIf we perform the operation by choosing j=1, p becomes `1 3 5 4 2`, which is\noptimal, so the answer is 2.\n\n* * *"}, {"input": "3 2\n 3 2 1\n 1 2\n 2 3", "output": "3\n \n\nIf we perform the operation by, for example, choosing j=1, j=2, j=1 in this\norder, p becomes `1 2 3`, which is obviously optimal. Note that we may choose\nthe same j any number of times.\n\n* * *"}, {"input": "10 8\n 5 3 6 8 7 10 9 1 2 4\n 3 1\n 4 1\n 5 9\n 2 5\n 6 5\n 3 5\n 8 9\n 7 9", "output": "8\n \n\n* * *"}, {"input": "5 1\n 1 2 3 4 5\n 1 5", "output": "5\n \n\nWe do not have to perform the operation."}] |
Print the maximum possible number of i such that p_i = i after operations.
* * * | s905111259 | Runtime Error | p03354 | Input is given from Standard Input in the following format:
N M
p_1 p_2 .. p_N
x_1 y_1
x_2 y_2
:
x_M y_M | n,m = list(map(int,input().split()))
p = list(map(int,input().split()))
a = []
for i in range(m):
a.append(list(map(int,input().split())))
for i in range(m):
for j in range(1,m-i):
if a[i][0] == a[i+j][0] and [a[i][1],a[i+j][1]] not in a:
a.append([a[i][1],a[i+j][1]])
elif a[i][1] == a[i+j][1] and [a[i][0],a[i+j][0]] not in a:
a.append([a[i][0],a[i+j][0]])
elif a[i][0] == a[i+j][1] and [a[i][1],a[i+j][0]] not in a:
a.append([a[i][1],a[i+j][0]])
elif a[i][1] == a[i+j][0] and [a[i][0],a[i+j][1]] not in a:
a.append([a[i][0],a[i+j][1]])
for i in range(len(a)):
for j in range(1,len(a)-i):
if a[i][0] == a[i+j][0] and [a[i][1],a[i+j][1]] not in a:
a.append([a[i][1],a[i+j][1]])
elif a[i][1] == a[i+j][1] and [a[i][0],a[i+j][0]] not in a:
a.append([a[i][0],a[i+j][0]])
elif a[i][0] == a[i+j][1] and [a[i][1],a[i+j][0]] not in a:
a.append([a[i][1],a[i+j][0]])
elif a[i][1] == a[i+j][0] and [a[i][0],a[i+j][1]] not in a:
for j in range(m):
for i in a:
if p[i[0]-1] != i[0] and p[i[1]-1] != i[1]:
b = p[i[0]-1]
p[i[0]-1] = p[i[1]-1]
p[i[1]-1] = b
print(p) | Statement
We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We
also have M pairs of two integers between 1 and N (inclusive), represented as
(x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the
following operation on p as many times as desired so that the number of i (1 ≤
i ≤ N) such that p_i = i is maximized:
* Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}.
Find the maximum possible number of i such that p_i = i after operations. | [{"input": "5 2\n 5 3 1 4 2\n 1 3\n 5 4", "output": "2\n \n\nIf we perform the operation by choosing j=1, p becomes `1 3 5 4 2`, which is\noptimal, so the answer is 2.\n\n* * *"}, {"input": "3 2\n 3 2 1\n 1 2\n 2 3", "output": "3\n \n\nIf we perform the operation by, for example, choosing j=1, j=2, j=1 in this\norder, p becomes `1 2 3`, which is obviously optimal. Note that we may choose\nthe same j any number of times.\n\n* * *"}, {"input": "10 8\n 5 3 6 8 7 10 9 1 2 4\n 3 1\n 4 1\n 5 9\n 2 5\n 6 5\n 3 5\n 8 9\n 7 9", "output": "8\n \n\n* * *"}, {"input": "5 1\n 1 2 3 4 5\n 1 5", "output": "5\n \n\nWe do not have to perform the operation."}] |
Print the maximum possible number of i such that p_i = i after operations.
* * * | s500671931 | Runtime Error | p03354 | Input is given from Standard Input in the following format:
N M
p_1 p_2 .. p_N
x_1 y_1
x_2 y_2
:
x_M y_M | #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x) cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;
template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) { if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }
const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 }; // 4近傍(右, 下, 左, 上)
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };
using namespace std;
class UnionFind {
public:
vector<int> parent;
vector<int> setSize;
UnionFind(unsigned int size) {
parent.resize(size + 1);
iota(parent.begin(), parent.end(), 0);
setSize.resize(size + 1, 1);
}
// xとyが同じ集合に属するか
bool isSameSet(int x, int y) {
return findRoot(x) == findRoot(y);
}
// xとyの属する集合を併合
void unionSet(int x, int y) {
x = findRoot(x);
y = findRoot(y);
if (x == y) { return; }
parent[x] = y;
setSize[y] += setSize[x];
}
private:
// 木の根を求める
int findRoot(int x) {
if (parent[x] == x) {
return x;
}
else {
return parent[x] = findRoot(parent[x]);
}
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<int> P(N);
vector<int> num_idx(N);
FOR(i, 0, N) {
cin >> P[i];
P[i]--;
num_idx[P[i]] = i;
}
UnionFind uf(N);
FOR(i, 0, M) {
int x, y;
cin >> x >> y;
uf.unionSet(x - 1, y - 1);
}
int ans = 0;
FOR(i, 0, N) {
if (P[i] == i) {
ans++;
}
else {
int idx = num_idx[i];
ans += uf.isSameSet(i, idx);
}
}
print(ans);
return 0;
} | Statement
We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We
also have M pairs of two integers between 1 and N (inclusive), represented as
(x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the
following operation on p as many times as desired so that the number of i (1 ≤
i ≤ N) such that p_i = i is maximized:
* Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}.
Find the maximum possible number of i such that p_i = i after operations. | [{"input": "5 2\n 5 3 1 4 2\n 1 3\n 5 4", "output": "2\n \n\nIf we perform the operation by choosing j=1, p becomes `1 3 5 4 2`, which is\noptimal, so the answer is 2.\n\n* * *"}, {"input": "3 2\n 3 2 1\n 1 2\n 2 3", "output": "3\n \n\nIf we perform the operation by, for example, choosing j=1, j=2, j=1 in this\norder, p becomes `1 2 3`, which is obviously optimal. Note that we may choose\nthe same j any number of times.\n\n* * *"}, {"input": "10 8\n 5 3 6 8 7 10 9 1 2 4\n 3 1\n 4 1\n 5 9\n 2 5\n 6 5\n 3 5\n 8 9\n 7 9", "output": "8\n \n\n* * *"}, {"input": "5 1\n 1 2 3 4 5\n 1 5", "output": "5\n \n\nWe do not have to perform the operation."}] |
Print the maximum possible number of i such that p_i = i after operations.
* * * | s033944653 | Runtime Error | p03354 | Input is given from Standard Input in the following format:
N M
p_1 p_2 .. p_N
x_1 y_1
x_2 y_2
:
x_M y_M | class unionFind():
def __init__(self,n):
self.tree=[-1]*n
def find(self, x):
if self.tree[x] < 0:
return x
else:
#self.tree[x] = self.find(self.id[x])
return self.find(self.id[x])
def union(self,x,y):
xr=self.find(x)
yr=self.find(y)
if xr!=yr:
if self.tree[xr]<self.tree[yr]:
self.tree[yr]=xr
elif self.tree[xr]>self.tree[yr]:
self.tree[xr]=yr
else:
self.tree[xr]-=1
self.tree[yr]=xr
return True
return False
def main():
ans=0
n,m=map(int,input().split())
a=unionFind(n)
li=[x-1 for x in list(map(int,input().split()))]
for _ in range(m):
x,y=map(int,input().split())
a.union(x-1,y-1)
for x in range(n):
ans += a.find(x)==a.find(li[x])
return ans
print(main())
| Statement
We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We
also have M pairs of two integers between 1 and N (inclusive), represented as
(x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the
following operation on p as many times as desired so that the number of i (1 ≤
i ≤ N) such that p_i = i is maximized:
* Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}.
Find the maximum possible number of i such that p_i = i after operations. | [{"input": "5 2\n 5 3 1 4 2\n 1 3\n 5 4", "output": "2\n \n\nIf we perform the operation by choosing j=1, p becomes `1 3 5 4 2`, which is\noptimal, so the answer is 2.\n\n* * *"}, {"input": "3 2\n 3 2 1\n 1 2\n 2 3", "output": "3\n \n\nIf we perform the operation by, for example, choosing j=1, j=2, j=1 in this\norder, p becomes `1 2 3`, which is obviously optimal. Note that we may choose\nthe same j any number of times.\n\n* * *"}, {"input": "10 8\n 5 3 6 8 7 10 9 1 2 4\n 3 1\n 4 1\n 5 9\n 2 5\n 6 5\n 3 5\n 8 9\n 7 9", "output": "8\n \n\n* * *"}, {"input": "5 1\n 1 2 3 4 5\n 1 5", "output": "5\n \n\nWe do not have to perform the operation."}] |
Print the maximum possible number of i such that p_i = i after operations.
* * * | s808135316 | Runtime Error | p03354 | Input is given from Standard Input in the following format:
N M
p_1 p_2 .. p_N
x_1 y_1
x_2 y_2
:
x_M y_M | class unionFind():
def __init__(self,n):
self.tree=[-1]*n
def find(self,x):
if self.tree[x]<0:
return x
else:
self.tree[x]=self.find(self.tree[x])
return self.tree[x]
def union(self,x,y):
xr=self.find(x)
yr=self.find(y)
if xr!=yr:
if self.tree[xr]<self.tree[yr]:
self.tree[yr]=xr
elif self.tree[xr]>self.tree[yr]:
self.tree[xr]=yr
else:
self.tree[xr]-=1
self.tree[yr]=xr
return True
return False
def main():
ans=0
n,m=map(int,input().split())
a=unionFind(n)
li=[x-1 for x in list(map(int,input().split()))]
for _ in range(m):
x,y=map(int,input().split())
a.union(x-1,y-1)
for x in range(n):
ans += a.find(x)==a.find(li[x])
return ans
print(main())
| Statement
We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We
also have M pairs of two integers between 1 and N (inclusive), represented as
(x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the
following operation on p as many times as desired so that the number of i (1 ≤
i ≤ N) such that p_i = i is maximized:
* Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}.
Find the maximum possible number of i such that p_i = i after operations. | [{"input": "5 2\n 5 3 1 4 2\n 1 3\n 5 4", "output": "2\n \n\nIf we perform the operation by choosing j=1, p becomes `1 3 5 4 2`, which is\noptimal, so the answer is 2.\n\n* * *"}, {"input": "3 2\n 3 2 1\n 1 2\n 2 3", "output": "3\n \n\nIf we perform the operation by, for example, choosing j=1, j=2, j=1 in this\norder, p becomes `1 2 3`, which is obviously optimal. Note that we may choose\nthe same j any number of times.\n\n* * *"}, {"input": "10 8\n 5 3 6 8 7 10 9 1 2 4\n 3 1\n 4 1\n 5 9\n 2 5\n 6 5\n 3 5\n 8 9\n 7 9", "output": "8\n \n\n* * *"}, {"input": "5 1\n 1 2 3 4 5\n 1 5", "output": "5\n \n\nWe do not have to perform the operation."}] |
Print the maximum possible number of i such that p_i = i after operations.
* * * | s417466882 | Runtime Error | p03354 | Input is given from Standard Input in the following format:
N M
p_1 p_2 .. p_N
x_1 y_1
x_2 y_2
:
x_M y_M | class UnionFind:
def __init__(self,node):
self.par=[x for x in range(node)]
self.rank=[1]*(node)
def find(self,x):
if self.par[x]==x:
return x
else:
self.par[x]==self.find(self.par[x])
return self.par[x]
def unite(self,x,y):
rx=self.find(x)
ry=self.find(y)
if rx==ry:
return False
else:
if self.rank[rx]<self.rank[ry]:
self.par[rx]==ry
else:
self.par[ry]==rx
if self.rank[rx]==self.rank[ry]:
self.rank[rx]+=1
return True
def main(self):
n,q=map(int,input().split())
li=[]
sol=self.UnionFind(n)
for _ in [0]*q:
j,a,b=map(int input().split())
if t==0:
sol.unite(a,b)
else:
li.append("Yes" if sol.find(a)==sol.find(b) else "No")
return "\n".join(li)
print(main())
| Statement
We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We
also have M pairs of two integers between 1 and N (inclusive), represented as
(x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the
following operation on p as many times as desired so that the number of i (1 ≤
i ≤ N) such that p_i = i is maximized:
* Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}.
Find the maximum possible number of i such that p_i = i after operations. | [{"input": "5 2\n 5 3 1 4 2\n 1 3\n 5 4", "output": "2\n \n\nIf we perform the operation by choosing j=1, p becomes `1 3 5 4 2`, which is\noptimal, so the answer is 2.\n\n* * *"}, {"input": "3 2\n 3 2 1\n 1 2\n 2 3", "output": "3\n \n\nIf we perform the operation by, for example, choosing j=1, j=2, j=1 in this\norder, p becomes `1 2 3`, which is obviously optimal. Note that we may choose\nthe same j any number of times.\n\n* * *"}, {"input": "10 8\n 5 3 6 8 7 10 9 1 2 4\n 3 1\n 4 1\n 5 9\n 2 5\n 6 5\n 3 5\n 8 9\n 7 9", "output": "8\n \n\n* * *"}, {"input": "5 1\n 1 2 3 4 5\n 1 5", "output": "5\n \n\nWe do not have to perform the operation."}] |
Print the maximum possible number of i such that p_i = i after operations.
* * * | s488225688 | Runtime Error | p03354 | Input is given from Standard Input in the following format:
N M
p_1 p_2 .. p_N
x_1 y_1
x_2 y_2
:
x_M y_M | class unionFind():
def __init__(self,n):
self.tree=[-1]*n
def find(self, x):
if self.tree[x] < 0:
return x
else:
self.tree[x] = self.find(self.id[x])
return self.tree[x]
def union(self,x,y):
xr=self.find(x)
yr=self.find(y)
if xr!=yr:
if self.tree[xr]<self.tree[yr]:
self.tree[yr]=xr
elif self.tree[xr]>self.tree[yr]:
self.tree[xr]=yr
else:
self.tree[xr]-=1
self.tree[yr]=xr
return True
return False
def main():
ans=0
n,m=map(int,input().split())
a=unionFind(n)
li=[x-1 for x in list(map(int,input().split()))]
for _ in range(m):
x,y=map(int,input().split())
a.union(x-1,y-1)
for x in range(n):
ans += a.find(x)==a.find(li[x])
return ans
print(main())
| Statement
We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We
also have M pairs of two integers between 1 and N (inclusive), represented as
(x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the
following operation on p as many times as desired so that the number of i (1 ≤
i ≤ N) such that p_i = i is maximized:
* Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}.
Find the maximum possible number of i such that p_i = i after operations. | [{"input": "5 2\n 5 3 1 4 2\n 1 3\n 5 4", "output": "2\n \n\nIf we perform the operation by choosing j=1, p becomes `1 3 5 4 2`, which is\noptimal, so the answer is 2.\n\n* * *"}, {"input": "3 2\n 3 2 1\n 1 2\n 2 3", "output": "3\n \n\nIf we perform the operation by, for example, choosing j=1, j=2, j=1 in this\norder, p becomes `1 2 3`, which is obviously optimal. Note that we may choose\nthe same j any number of times.\n\n* * *"}, {"input": "10 8\n 5 3 6 8 7 10 9 1 2 4\n 3 1\n 4 1\n 5 9\n 2 5\n 6 5\n 3 5\n 8 9\n 7 9", "output": "8\n \n\n* * *"}, {"input": "5 1\n 1 2 3 4 5\n 1 5", "output": "5\n \n\nWe do not have to perform the operation."}] |
Print the maximum possible number of i such that p_i = i after operations.
* * * | s447560115 | Runtime Error | p03354 | Input is given from Standard Input in the following format:
N M
p_1 p_2 .. p_N
x_1 y_1
x_2 y_2
:
x_M y_M | class unionFind():
def __init__(self,n):
self.tree=[-1]*n
def find(self,x):
if self.tree[x]<0:
return x
else:
self.tree[x]=self.find(self.tree[x])
return self.tree[x]
def union(self,x,y):
xr=self.find(x)
yr=self.find(y)
if xr!=yr:
if self.tree[xr]==self.tree[yr]:
self.tree[xr]-=1
self.tree[yr]=xr
else:
if self.tree[xr]>self.tree[yr]:
self.tree[xr]=yr
else:
self.tree[yr]=xr
return True
return False
def main():
ans=0
n,m=map(int,input().split())
a=unionFind(n)
li=[x-1 for x in list(map(int,input().split()))]
for _ in range(m):
x,y=map(int,input().split())
a.union(x-1,y-1)
for x in range(n):
ans += a.find(x)==a.find(li[x])
return ans
print(main())
| Statement
We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We
also have M pairs of two integers between 1 and N (inclusive), represented as
(x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the
following operation on p as many times as desired so that the number of i (1 ≤
i ≤ N) such that p_i = i is maximized:
* Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}.
Find the maximum possible number of i such that p_i = i after operations. | [{"input": "5 2\n 5 3 1 4 2\n 1 3\n 5 4", "output": "2\n \n\nIf we perform the operation by choosing j=1, p becomes `1 3 5 4 2`, which is\noptimal, so the answer is 2.\n\n* * *"}, {"input": "3 2\n 3 2 1\n 1 2\n 2 3", "output": "3\n \n\nIf we perform the operation by, for example, choosing j=1, j=2, j=1 in this\norder, p becomes `1 2 3`, which is obviously optimal. Note that we may choose\nthe same j any number of times.\n\n* * *"}, {"input": "10 8\n 5 3 6 8 7 10 9 1 2 4\n 3 1\n 4 1\n 5 9\n 2 5\n 6 5\n 3 5\n 8 9\n 7 9", "output": "8\n \n\n* * *"}, {"input": "5 1\n 1 2 3 4 5\n 1 5", "output": "5\n \n\nWe do not have to perform the operation."}] |
Print the maximum possible number of i such that p_i = i after operations.
* * * | s398743064 | Runtime Error | p03354 | Input is given from Standard Input in the following format:
N M
p_1 p_2 .. p_N
x_1 y_1
x_2 y_2
:
x_M y_M | class unionFind():
def __init__(self,n):
self.tree=[-1]*n
def find(self, x):
if self.tree[x] < 0:
return x
else:
self.tree[x] = self.find(self.id[x])
return self.tree[x]
def union(self,x,y):
xr=self.find(x)
yr=self.find(y)
if xr!=yr:
if self.tree[xr]<self.tree[yr]:
self.tree[yr]=xr
elif self.tree[xr]>self.tree[yr]:
self.tree[xr]=yr
else:
self.tree[xr]-=1
self.tree[yr]=xr
return True
return False
def main():
ans=0
n,m=map(int,input().split())
a=unionFind(n)
li=[x-1 for x in list(map(int,input().split()))]
for _ in range(m):
x,y=map(int,input().split())
a.union(x-1,y-1)
for x in range(n):
ans += a.find(x)==a.find(li[x])
return ans
print(main())
| Statement
We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We
also have M pairs of two integers between 1 and N (inclusive), represented as
(x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the
following operation on p as many times as desired so that the number of i (1 ≤
i ≤ N) such that p_i = i is maximized:
* Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}.
Find the maximum possible number of i such that p_i = i after operations. | [{"input": "5 2\n 5 3 1 4 2\n 1 3\n 5 4", "output": "2\n \n\nIf we perform the operation by choosing j=1, p becomes `1 3 5 4 2`, which is\noptimal, so the answer is 2.\n\n* * *"}, {"input": "3 2\n 3 2 1\n 1 2\n 2 3", "output": "3\n \n\nIf we perform the operation by, for example, choosing j=1, j=2, j=1 in this\norder, p becomes `1 2 3`, which is obviously optimal. Note that we may choose\nthe same j any number of times.\n\n* * *"}, {"input": "10 8\n 5 3 6 8 7 10 9 1 2 4\n 3 1\n 4 1\n 5 9\n 2 5\n 6 5\n 3 5\n 8 9\n 7 9", "output": "8\n \n\n* * *"}, {"input": "5 1\n 1 2 3 4 5\n 1 5", "output": "5\n \n\nWe do not have to perform the operation."}] |
Print the maximum possible number of i such that p_i = i after operations.
* * * | s200832275 | Wrong Answer | p03354 | Input is given from Standard Input in the following format:
N M
p_1 p_2 .. p_N
x_1 y_1
x_2 y_2
:
x_M y_M | N, M = (int(i) for i in input().split())
print(1)
| Statement
We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We
also have M pairs of two integers between 1 and N (inclusive), represented as
(x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the
following operation on p as many times as desired so that the number of i (1 ≤
i ≤ N) such that p_i = i is maximized:
* Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}.
Find the maximum possible number of i such that p_i = i after operations. | [{"input": "5 2\n 5 3 1 4 2\n 1 3\n 5 4", "output": "2\n \n\nIf we perform the operation by choosing j=1, p becomes `1 3 5 4 2`, which is\noptimal, so the answer is 2.\n\n* * *"}, {"input": "3 2\n 3 2 1\n 1 2\n 2 3", "output": "3\n \n\nIf we perform the operation by, for example, choosing j=1, j=2, j=1 in this\norder, p becomes `1 2 3`, which is obviously optimal. Note that we may choose\nthe same j any number of times.\n\n* * *"}, {"input": "10 8\n 5 3 6 8 7 10 9 1 2 4\n 3 1\n 4 1\n 5 9\n 2 5\n 6 5\n 3 5\n 8 9\n 7 9", "output": "8\n \n\n* * *"}, {"input": "5 1\n 1 2 3 4 5\n 1 5", "output": "5\n \n\nWe do not have to perform the operation."}] |
Print the maximum possible number of i such that p_i = i after operations.
* * * | s276319662 | Runtime Error | p03354 | Input is given from Standard Input in the following format:
N M
p_1 p_2 .. p_N
x_1 y_1
x_2 y_2
:
x_M y_M | H, W, D = map(int, input().split())
# a = [0] * (H*W+1)
a = {}
for i in range(H):
A = list(map(int, input().split()))
for j, _ in enumerate(A):
a[_] = (i + 1, j + 1)
# table = [0] * (H*W+1)
table = {i: 0 for i in range(H * W + 1)}
for i in range(D + 1, H * W):
x, y = a[i]
x_, y_ = a[i - D]
table[i] = table[i - D] + abs(x - x_) + abs(y - y_)
for i in range(int(input())):
L, R = map(int, input().split())
print(table[R] - table[L])
| Statement
We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We
also have M pairs of two integers between 1 and N (inclusive), represented as
(x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the
following operation on p as many times as desired so that the number of i (1 ≤
i ≤ N) such that p_i = i is maximized:
* Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}.
Find the maximum possible number of i such that p_i = i after operations. | [{"input": "5 2\n 5 3 1 4 2\n 1 3\n 5 4", "output": "2\n \n\nIf we perform the operation by choosing j=1, p becomes `1 3 5 4 2`, which is\noptimal, so the answer is 2.\n\n* * *"}, {"input": "3 2\n 3 2 1\n 1 2\n 2 3", "output": "3\n \n\nIf we perform the operation by, for example, choosing j=1, j=2, j=1 in this\norder, p becomes `1 2 3`, which is obviously optimal. Note that we may choose\nthe same j any number of times.\n\n* * *"}, {"input": "10 8\n 5 3 6 8 7 10 9 1 2 4\n 3 1\n 4 1\n 5 9\n 2 5\n 6 5\n 3 5\n 8 9\n 7 9", "output": "8\n \n\n* * *"}, {"input": "5 1\n 1 2 3 4 5\n 1 5", "output": "5\n \n\nWe do not have to perform the operation."}] |
Print the maximum possible number of i such that p_i = i after operations.
* * * | s822137281 | Accepted | p03354 | Input is given from Standard Input in the following format:
N M
p_1 p_2 .. p_N
x_1 y_1
x_2 y_2
:
x_M y_M | import collections
n, m = map(int, input().split())
p = list(map(int, input().split()))
base = 0
basemap = []
for i in range(n):
if (i + 1) == p[i]:
base += 1
basemap.append(i + 1)
branch = dict()
for i in range(1, n + 1):
branch[i] = []
for i in range(m):
x, y = map(int, input().split())
branch[x].append(y)
branch[y].append(x)
compare = [0 for i in range(n + 1)]
for i in range(1, n + 1):
if branch[i] != []:
compare[i] = 1
arrival = [0 for i in range(n + 1)]
ans = []
q = []
ind = 1
while arrival != compare:
counter = base
while not (arrival[ind] == 0 and compare[ind] == 1):
ind += 1
q.append(ind)
arrival[ind] = 1
section = [q[0]]
while len(q) > 0:
next = branch[q[0]]
for i in range(len(next)):
if arrival[next[i]] == 0:
section.append(next[i])
arrival[next[i]] = 1
q.append(next[i])
q.pop(0)
psec = []
for i in range(len(section)):
psec.append(p[section[i] - 1])
t = section + psec + basemap
search = collections.Counter(t)
for i in search:
if search[i] == 2:
counter += 1
ans.append(counter)
print(max(ans))
| Statement
We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We
also have M pairs of two integers between 1 and N (inclusive), represented as
(x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the
following operation on p as many times as desired so that the number of i (1 ≤
i ≤ N) such that p_i = i is maximized:
* Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}.
Find the maximum possible number of i such that p_i = i after operations. | [{"input": "5 2\n 5 3 1 4 2\n 1 3\n 5 4", "output": "2\n \n\nIf we perform the operation by choosing j=1, p becomes `1 3 5 4 2`, which is\noptimal, so the answer is 2.\n\n* * *"}, {"input": "3 2\n 3 2 1\n 1 2\n 2 3", "output": "3\n \n\nIf we perform the operation by, for example, choosing j=1, j=2, j=1 in this\norder, p becomes `1 2 3`, which is obviously optimal. Note that we may choose\nthe same j any number of times.\n\n* * *"}, {"input": "10 8\n 5 3 6 8 7 10 9 1 2 4\n 3 1\n 4 1\n 5 9\n 2 5\n 6 5\n 3 5\n 8 9\n 7 9", "output": "8\n \n\n* * *"}, {"input": "5 1\n 1 2 3 4 5\n 1 5", "output": "5\n \n\nWe do not have to perform the operation."}] |
Print the maximum possible number of i such that p_i = i after operations.
* * * | s492774178 | Accepted | p03354 | Input is given from Standard Input in the following format:
N M
p_1 p_2 .. p_N
x_1 y_1
x_2 y_2
:
x_M y_M | ###############################################################################
from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict
mod = 1
def intin():
input_tuple = input().split()
if len(input_tuple) <= 1:
return int(input_tuple[0])
return tuple(map(int, input_tuple))
def intina():
return [int(i) for i in input().split()]
def intinl(count):
return [intin() for _ in range(count)]
def modadd(x, y):
global mod
return (x + y) % mod
def modmlt(x, y):
global mod
return (x * y) % mod
def lcm(x, y):
while y != 0:
z = x % y
x = y
y = z
return x
def combination(x, y):
assert x >= y
if y > x // 2:
y = x - y
ret = 1
for i in range(0, y):
j = x - i
i = i + 1
ret = ret * j
ret = ret // i
return ret
def get_divisors(x):
retlist = []
for i in range(1, int(x**0.5) + 3):
if x % i == 0:
retlist.append(i)
retlist.append(x // i)
return retlist
def get_factors(x):
retlist = []
for i in range(2, int(x**0.5) + 3):
while x % i == 0:
retlist.append(i)
x = x // i
retlist.append(x)
return retlist
def make_linklist(xylist):
linklist = {}
for a, b in xylist:
linklist.setdefault(a, [])
linklist.setdefault(b, [])
linklist[a].append(b)
linklist[b].append(a)
return linklist
def calc_longest_distance(linklist, v=1):
distance_list = {}
distance_count = 0
distance = 0
vlist_previous = []
vlist = [v]
nodecount = len(linklist)
while distance_count < nodecount:
vlist_next = []
for v in vlist:
distance_list[v] = distance
distance_count += 1
vlist_next.extend(linklist[v])
distance += 1
vlist_to_del = vlist_previous
vlist_previous = vlist
vlist = list(set(vlist_next) - set(vlist_to_del))
max_distance = -1
max_v = None
for v, distance in distance_list.items():
if distance > max_distance:
max_distance = distance
max_v = v
return (max_distance, max_v)
def calc_tree_diameter(linklist, v=1):
_, u = calc_longest_distance(linklist, v)
distance, _ = calc_longest_distance(linklist, u)
return distance
class UnionFind:
def __init__(self, n):
self.parent = [i for i in range(n)]
def root(self, i):
if self.parent[i] == i:
return i
self.parent[i] = self.root(self.parent[i])
return self.parent[i]
def unite(self, i, j):
rooti = self.root(i)
rootj = self.root(j)
if rooti == rootj:
return
if i < j:
self.parent[rootj] = rooti
else:
self.parent[rooti] = rootj
def same(self, i, j):
return self.root(i) == self.root(j)
###############################################################################
def main():
n, m = intin()
plist = intina()
xylist = intinl(m)
new_xylist = []
for x, y in xylist:
if x < y:
new_xylist.append((x, y))
continue
new_xylist.append((y, x))
new_xylist.sort()
xylist = new_xylist
u = UnionFind(n)
for x, y in xylist:
u.unite(x - 1, y - 1)
ans = 0
for i, p in enumerate(plist):
if u.same(i, p - 1):
ans += 1
print(ans)
if __name__ == "__main__":
main()
| Statement
We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We
also have M pairs of two integers between 1 and N (inclusive), represented as
(x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the
following operation on p as many times as desired so that the number of i (1 ≤
i ≤ N) such that p_i = i is maximized:
* Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}.
Find the maximum possible number of i such that p_i = i after operations. | [{"input": "5 2\n 5 3 1 4 2\n 1 3\n 5 4", "output": "2\n \n\nIf we perform the operation by choosing j=1, p becomes `1 3 5 4 2`, which is\noptimal, so the answer is 2.\n\n* * *"}, {"input": "3 2\n 3 2 1\n 1 2\n 2 3", "output": "3\n \n\nIf we perform the operation by, for example, choosing j=1, j=2, j=1 in this\norder, p becomes `1 2 3`, which is obviously optimal. Note that we may choose\nthe same j any number of times.\n\n* * *"}, {"input": "10 8\n 5 3 6 8 7 10 9 1 2 4\n 3 1\n 4 1\n 5 9\n 2 5\n 6 5\n 3 5\n 8 9\n 7 9", "output": "8\n \n\n* * *"}, {"input": "5 1\n 1 2 3 4 5\n 1 5", "output": "5\n \n\nWe do not have to perform the operation."}] |
For each dataset, print x in the following format:
Case i: x
where i is the case number which starts with 1. Put a single space between
"Case" and i. Also, put a single space between ':' and x. | s527663453 | Accepted | p02396 | The input consists of multiple datasets. Each dataset consists of an integer x
in a line.
The input ends with an integer 0. You program should not process (print) for
this terminal symbol. | a = []
b = input()
while b != "0":
a.append(b)
b = input()
for c in range(len(a)):
print("Case " + str(c + 1) + ": " + a[c])
| Print Test Cases
In the online judge system, a judge file may include multiple datasets to
check whether the submitted program outputs a correct answer for each test
case. This task is to practice solving a problem with multiple datasets.
Write a program which reads an integer x and print it as is. Note that
multiple datasets are given for this problem. | [{"input": "5\n 11\n 7\n 8\n 19\n 0", "output": "Case 1: 3\n Case 2: 5\n Case 3: 11\n Case 4: 7\n Case 5: 8\n Case 6: 19"}] |
For each dataset, print x in the following format:
Case i: x
where i is the case number which starts with 1. Put a single space between
"Case" and i. Also, put a single space between ':' and x. | s132448781 | Accepted | p02396 | The input consists of multiple datasets. Each dataset consists of an integer x
in a line.
The input ends with an integer 0. You program should not process (print) for
this terminal symbol. | (lambda *_: None)(
*map(print, map("Case {0[0]}: {0[1]}".format, enumerate(iter(input, "0"), 1)))
)
| Print Test Cases
In the online judge system, a judge file may include multiple datasets to
check whether the submitted program outputs a correct answer for each test
case. This task is to practice solving a problem with multiple datasets.
Write a program which reads an integer x and print it as is. Note that
multiple datasets are given for this problem. | [{"input": "5\n 11\n 7\n 8\n 19\n 0", "output": "Case 1: 3\n Case 2: 5\n Case 3: 11\n Case 4: 7\n Case 5: 8\n Case 6: 19"}] |
For each dataset, print x in the following format:
Case i: x
where i is the case number which starts with 1. Put a single space between
"Case" and i. Also, put a single space between ':' and x. | s685062147 | Accepted | p02396 | The input consists of multiple datasets. Each dataset consists of an integer x
in a line.
The input ends with an integer 0. You program should not process (print) for
this terminal symbol. | for i, x in enumerate(iter(lambda: input(), "0"), 1):
print("Case {}: {}".format(i, x))
| Print Test Cases
In the online judge system, a judge file may include multiple datasets to
check whether the submitted program outputs a correct answer for each test
case. This task is to practice solving a problem with multiple datasets.
Write a program which reads an integer x and print it as is. Note that
multiple datasets are given for this problem. | [{"input": "5\n 11\n 7\n 8\n 19\n 0", "output": "Case 1: 3\n Case 2: 5\n Case 3: 11\n Case 4: 7\n Case 5: 8\n Case 6: 19"}] |
For each dataset, print x in the following format:
Case i: x
where i is the case number which starts with 1. Put a single space between
"Case" and i. Also, put a single space between ':' and x. | s359904804 | Wrong Answer | p02396 | The input consists of multiple datasets. Each dataset consists of an integer x
in a line.
The input ends with an integer 0. You program should not process (print) for
this terminal symbol. | inpu_list = list(map(int, input().split()))
for i in range(len(inpu_list) - 1):
print("Case %d: %d" % (i + 1, inpu_list[i]))
| Print Test Cases
In the online judge system, a judge file may include multiple datasets to
check whether the submitted program outputs a correct answer for each test
case. This task is to practice solving a problem with multiple datasets.
Write a program which reads an integer x and print it as is. Note that
multiple datasets are given for this problem. | [{"input": "5\n 11\n 7\n 8\n 19\n 0", "output": "Case 1: 3\n Case 2: 5\n Case 3: 11\n Case 4: 7\n Case 5: 8\n Case 6: 19"}] |
For each dataset, print x in the following format:
Case i: x
where i is the case number which starts with 1. Put a single space between
"Case" and i. Also, put a single space between ':' and x. | s850321341 | Runtime Error | p02396 | The input consists of multiple datasets. Each dataset consists of an integer x
in a line.
The input ends with an integer 0. You program should not process (print) for
this terminal symbol. | set = list(map(int, input().split()))
index = 0
next = set[index]
while next:
print("Case " + str(index) + ": " + str(set[index]))
index += 1
next = set[index]
| Print Test Cases
In the online judge system, a judge file may include multiple datasets to
check whether the submitted program outputs a correct answer for each test
case. This task is to practice solving a problem with multiple datasets.
Write a program which reads an integer x and print it as is. Note that
multiple datasets are given for this problem. | [{"input": "5\n 11\n 7\n 8\n 19\n 0", "output": "Case 1: 3\n Case 2: 5\n Case 3: 11\n Case 4: 7\n Case 5: 8\n Case 6: 19"}] |
For each dataset, print x in the following format:
Case i: x
where i is the case number which starts with 1. Put a single space between
"Case" and i. Also, put a single space between ':' and x. | s437466471 | Runtime Error | p02396 | The input consists of multiple datasets. Each dataset consists of an integer x
in a line.
The input ends with an integer 0. You program should not process (print) for
this terminal symbol. | for i, e in enumerate(eval(input().replace('\n', ','))):
print("Case {}: {}".format(i+1, e)) | Print Test Cases
In the online judge system, a judge file may include multiple datasets to
check whether the submitted program outputs a correct answer for each test
case. This task is to practice solving a problem with multiple datasets.
Write a program which reads an integer x and print it as is. Note that
multiple datasets are given for this problem. | [{"input": "5\n 11\n 7\n 8\n 19\n 0", "output": "Case 1: 3\n Case 2: 5\n Case 3: 11\n Case 4: 7\n Case 5: 8\n Case 6: 19"}] |
For each dataset, print x in the following format:
Case i: x
where i is the case number which starts with 1. Put a single space between
"Case" and i. Also, put a single space between ':' and x. | s970482025 | Accepted | p02396 | The input consists of multiple datasets. Each dataset consists of an integer x
in a line.
The input ends with an integer 0. You program should not process (print) for
this terminal symbol. | X = list(map(int, open(0).read().split()))
for id, x in enumerate(X[:-1], start=1):
print(f"Case {id}: {x}")
| Print Test Cases
In the online judge system, a judge file may include multiple datasets to
check whether the submitted program outputs a correct answer for each test
case. This task is to practice solving a problem with multiple datasets.
Write a program which reads an integer x and print it as is. Note that
multiple datasets are given for this problem. | [{"input": "5\n 11\n 7\n 8\n 19\n 0", "output": "Case 1: 3\n Case 2: 5\n Case 3: 11\n Case 4: 7\n Case 5: 8\n Case 6: 19"}] |
For each dataset, print x in the following format:
Case i: x
where i is the case number which starts with 1. Put a single space between
"Case" and i. Also, put a single space between ':' and x. | s433753081 | Wrong Answer | p02396 | The input consists of multiple datasets. Each dataset consists of an integer x
in a line.
The input ends with an integer 0. You program should not process (print) for
this terminal symbol. | in_str = input()
for var in range(1, 3):
print("Case" + str(var) + ": " + in_str)
| Print Test Cases
In the online judge system, a judge file may include multiple datasets to
check whether the submitted program outputs a correct answer for each test
case. This task is to practice solving a problem with multiple datasets.
Write a program which reads an integer x and print it as is. Note that
multiple datasets are given for this problem. | [{"input": "5\n 11\n 7\n 8\n 19\n 0", "output": "Case 1: 3\n Case 2: 5\n Case 3: 11\n Case 4: 7\n Case 5: 8\n Case 6: 19"}] |
For each dataset, print x in the following format:
Case i: x
where i is the case number which starts with 1. Put a single space between
"Case" and i. Also, put a single space between ':' and x. | s306488137 | Wrong Answer | p02396 | The input consists of multiple datasets. Each dataset consists of an integer x
in a line.
The input ends with an integer 0. You program should not process (print) for
this terminal symbol. | i = input()
print(i)
| Print Test Cases
In the online judge system, a judge file may include multiple datasets to
check whether the submitted program outputs a correct answer for each test
case. This task is to practice solving a problem with multiple datasets.
Write a program which reads an integer x and print it as is. Note that
multiple datasets are given for this problem. | [{"input": "5\n 11\n 7\n 8\n 19\n 0", "output": "Case 1: 3\n Case 2: 5\n Case 3: 11\n Case 4: 7\n Case 5: 8\n Case 6: 19"}] |
For each dataset, print x in the following format:
Case i: x
where i is the case number which starts with 1. Put a single space between
"Case" and i. Also, put a single space between ':' and x. | s779730332 | Wrong Answer | p02396 | The input consists of multiple datasets. Each dataset consists of an integer x
in a line.
The input ends with an integer 0. You program should not process (print) for
this terminal symbol. | print("Hello")
| Print Test Cases
In the online judge system, a judge file may include multiple datasets to
check whether the submitted program outputs a correct answer for each test
case. This task is to practice solving a problem with multiple datasets.
Write a program which reads an integer x and print it as is. Note that
multiple datasets are given for this problem. | [{"input": "5\n 11\n 7\n 8\n 19\n 0", "output": "Case 1: 3\n Case 2: 5\n Case 3: 11\n Case 4: 7\n Case 5: 8\n Case 6: 19"}] |
Print the answer.
* * * | s297160003 | Accepted | p02729 | Input is given from Standard Input in the following format:
N M | a = input("")
lista = a.split()
lista2 = []
par = 0
impar = -1
contador = 0
for i in range(int(lista[0])):
par += 2
lista2.append(par)
for i in range(int(lista[1])):
impar += 2
lista2.append(impar)
longitud = len(lista2) - 1
for i in range(0, len(lista2)):
b = i
while True:
if b + 1 > longitud:
break
else:
suma = lista2[i] + lista2[b + 1]
b = b + 1
if suma % 2 == 0:
contador += 1
print(contador)
| Statement
We have N+M balls, each of which has an integer written on it.
It is known that:
* The numbers written on N of the balls are even.
* The numbers written on M of the balls are odd.
Find the number of ways to choose two of the N+M balls (disregarding order) so
that the sum of the numbers written on them is even.
It can be shown that this count does not depend on the actual values written
on the balls. | [{"input": "2 1", "output": "1\n \n\nFor example, let us assume that the numbers written on the three balls are\n1,2,4.\n\n * If we choose the two balls with 1 and 2, the sum is odd;\n * If we choose the two balls with 1 and 4, the sum is odd;\n * If we choose the two balls with 2 and 4, the sum is even.\n\nThus, the answer is 1.\n\n* * *"}, {"input": "4 3", "output": "9\n \n\n* * *"}, {"input": "1 1", "output": "0\n \n\n* * *"}, {"input": "13 3", "output": "81\n \n\n* * *"}, {"input": "0 3", "output": "3"}] |
Print the answer.
* * * | s884145962 | Runtime Error | p02729 | Input is given from Standard Input in the following format:
N M | import sys
input = sys.stdin.readline
H, W, K = map(int, input().split())
choco = [input() for _ in range(H)]
num = 2 ** (H - 1)
white_count = list()
min_div_count = 10**6
for i in range(num):
bin_str = format(i, "b")
zero = str()
if H != len(bin_str):
for i in range(H - len(bin_str)):
zero += "0"
bin_str = zero + bin_str
white_count = [0 for s in bin_str if s == "1"]
white_count.append(0)
div_count = len(white_count) - 1
j = 0
while j < W:
block_count = 0
for k in range(len(bin_str)):
if bin_str[k] == "1":
block_count += 1
white_count[block_count] += int(choco[k][j])
if white_count[block_count] > K:
div_count += 1
white_count = [0 for s in bin_str if s == "1"]
white_count.append(0)
break
else:
j += 1
if min_div_count > div_count:
min_div_count = div_count
print(min_div_count)
| Statement
We have N+M balls, each of which has an integer written on it.
It is known that:
* The numbers written on N of the balls are even.
* The numbers written on M of the balls are odd.
Find the number of ways to choose two of the N+M balls (disregarding order) so
that the sum of the numbers written on them is even.
It can be shown that this count does not depend on the actual values written
on the balls. | [{"input": "2 1", "output": "1\n \n\nFor example, let us assume that the numbers written on the three balls are\n1,2,4.\n\n * If we choose the two balls with 1 and 2, the sum is odd;\n * If we choose the two balls with 1 and 4, the sum is odd;\n * If we choose the two balls with 2 and 4, the sum is even.\n\nThus, the answer is 1.\n\n* * *"}, {"input": "4 3", "output": "9\n \n\n* * *"}, {"input": "1 1", "output": "0\n \n\n* * *"}, {"input": "13 3", "output": "81\n \n\n* * *"}, {"input": "0 3", "output": "3"}] |
Print the answer.
* * * | s223129117 | Wrong Answer | p02729 | Input is given from Standard Input in the following format:
N M | a, b = input().split()
a = int(a)
b = int(b)
print(a * (a - 1) / 2 + (b * (b - 1) / 2))
| Statement
We have N+M balls, each of which has an integer written on it.
It is known that:
* The numbers written on N of the balls are even.
* The numbers written on M of the balls are odd.
Find the number of ways to choose two of the N+M balls (disregarding order) so
that the sum of the numbers written on them is even.
It can be shown that this count does not depend on the actual values written
on the balls. | [{"input": "2 1", "output": "1\n \n\nFor example, let us assume that the numbers written on the three balls are\n1,2,4.\n\n * If we choose the two balls with 1 and 2, the sum is odd;\n * If we choose the two balls with 1 and 4, the sum is odd;\n * If we choose the two balls with 2 and 4, the sum is even.\n\nThus, the answer is 1.\n\n* * *"}, {"input": "4 3", "output": "9\n \n\n* * *"}, {"input": "1 1", "output": "0\n \n\n* * *"}, {"input": "13 3", "output": "81\n \n\n* * *"}, {"input": "0 3", "output": "3"}] |
Print the answer.
* * * | s199018769 | Runtime Error | p02729 | Input is given from Standard Input in the following format:
N M | print((int(input())) ** 3 / 27)
| Statement
We have N+M balls, each of which has an integer written on it.
It is known that:
* The numbers written on N of the balls are even.
* The numbers written on M of the balls are odd.
Find the number of ways to choose two of the N+M balls (disregarding order) so
that the sum of the numbers written on them is even.
It can be shown that this count does not depend on the actual values written
on the balls. | [{"input": "2 1", "output": "1\n \n\nFor example, let us assume that the numbers written on the three balls are\n1,2,4.\n\n * If we choose the two balls with 1 and 2, the sum is odd;\n * If we choose the two balls with 1 and 4, the sum is odd;\n * If we choose the two balls with 2 and 4, the sum is even.\n\nThus, the answer is 1.\n\n* * *"}, {"input": "4 3", "output": "9\n \n\n* * *"}, {"input": "1 1", "output": "0\n \n\n* * *"}, {"input": "13 3", "output": "81\n \n\n* * *"}, {"input": "0 3", "output": "3"}] |
Print the answer.
* * * | s981902987 | Runtime Error | p02729 | Input is given from Standard Input in the following format:
N M | S = input()
N = len(str(S))
temp = S[0 : (N - 1) / 2]
temp2 = S[(N + 2) / 2 : N]
print("Yes") if temp == temp[::-1] and temp2 == temp2[::-1] else "No"
| Statement
We have N+M balls, each of which has an integer written on it.
It is known that:
* The numbers written on N of the balls are even.
* The numbers written on M of the balls are odd.
Find the number of ways to choose two of the N+M balls (disregarding order) so
that the sum of the numbers written on them is even.
It can be shown that this count does not depend on the actual values written
on the balls. | [{"input": "2 1", "output": "1\n \n\nFor example, let us assume that the numbers written on the three balls are\n1,2,4.\n\n * If we choose the two balls with 1 and 2, the sum is odd;\n * If we choose the two balls with 1 and 4, the sum is odd;\n * If we choose the two balls with 2 and 4, the sum is even.\n\nThus, the answer is 1.\n\n* * *"}, {"input": "4 3", "output": "9\n \n\n* * *"}, {"input": "1 1", "output": "0\n \n\n* * *"}, {"input": "13 3", "output": "81\n \n\n* * *"}, {"input": "0 3", "output": "3"}] |
Print the answer.
* * * | s695972173 | Wrong Answer | p02729 | Input is given from Standard Input in the following format:
N M | a, b = list(map(int, input().strip().split())) # 2整数を受け取った
s1 = a * (a - 1) / 2 # 偶どうし
s2 = b * (b - 1) / 2 # 奇どうし
# 出力
print(s1 + s2)
| Statement
We have N+M balls, each of which has an integer written on it.
It is known that:
* The numbers written on N of the balls are even.
* The numbers written on M of the balls are odd.
Find the number of ways to choose two of the N+M balls (disregarding order) so
that the sum of the numbers written on them is even.
It can be shown that this count does not depend on the actual values written
on the balls. | [{"input": "2 1", "output": "1\n \n\nFor example, let us assume that the numbers written on the three balls are\n1,2,4.\n\n * If we choose the two balls with 1 and 2, the sum is odd;\n * If we choose the two balls with 1 and 4, the sum is odd;\n * If we choose the two balls with 2 and 4, the sum is even.\n\nThus, the answer is 1.\n\n* * *"}, {"input": "4 3", "output": "9\n \n\n* * *"}, {"input": "1 1", "output": "0\n \n\n* * *"}, {"input": "13 3", "output": "81\n \n\n* * *"}, {"input": "0 3", "output": "3"}] |
Print the answer.
* * * | s164214433 | Runtime Error | p02729 | Input is given from Standard Input in the following format:
N M | while True:
m, n = list(map(int, input().split()))
print(m * (m - 1) / 2 + n * (n - 1) / 2)
| Statement
We have N+M balls, each of which has an integer written on it.
It is known that:
* The numbers written on N of the balls are even.
* The numbers written on M of the balls are odd.
Find the number of ways to choose two of the N+M balls (disregarding order) so
that the sum of the numbers written on them is even.
It can be shown that this count does not depend on the actual values written
on the balls. | [{"input": "2 1", "output": "1\n \n\nFor example, let us assume that the numbers written on the three balls are\n1,2,4.\n\n * If we choose the two balls with 1 and 2, the sum is odd;\n * If we choose the two balls with 1 and 4, the sum is odd;\n * If we choose the two balls with 2 and 4, the sum is even.\n\nThus, the answer is 1.\n\n* * *"}, {"input": "4 3", "output": "9\n \n\n* * *"}, {"input": "1 1", "output": "0\n \n\n* * *"}, {"input": "13 3", "output": "81\n \n\n* * *"}, {"input": "0 3", "output": "3"}] |
Print the answer.
* * * | s891050277 | Wrong Answer | p02729 | Input is given from Standard Input in the following format:
N M | a, b = list(map(int, input().split()))
ct = (a * (a - 1)) // 2
ct += b
print(ct)
| Statement
We have N+M balls, each of which has an integer written on it.
It is known that:
* The numbers written on N of the balls are even.
* The numbers written on M of the balls are odd.
Find the number of ways to choose two of the N+M balls (disregarding order) so
that the sum of the numbers written on them is even.
It can be shown that this count does not depend on the actual values written
on the balls. | [{"input": "2 1", "output": "1\n \n\nFor example, let us assume that the numbers written on the three balls are\n1,2,4.\n\n * If we choose the two balls with 1 and 2, the sum is odd;\n * If we choose the two balls with 1 and 4, the sum is odd;\n * If we choose the two balls with 2 and 4, the sum is even.\n\nThus, the answer is 1.\n\n* * *"}, {"input": "4 3", "output": "9\n \n\n* * *"}, {"input": "1 1", "output": "0\n \n\n* * *"}, {"input": "13 3", "output": "81\n \n\n* * *"}, {"input": "0 3", "output": "3"}] |
Print the answer.
* * * | s070246510 | Runtime Error | p02729 | Input is given from Standard Input in the following format:
N M | print(int((input())) ** 3 / 27)
| Statement
We have N+M balls, each of which has an integer written on it.
It is known that:
* The numbers written on N of the balls are even.
* The numbers written on M of the balls are odd.
Find the number of ways to choose two of the N+M balls (disregarding order) so
that the sum of the numbers written on them is even.
It can be shown that this count does not depend on the actual values written
on the balls. | [{"input": "2 1", "output": "1\n \n\nFor example, let us assume that the numbers written on the three balls are\n1,2,4.\n\n * If we choose the two balls with 1 and 2, the sum is odd;\n * If we choose the two balls with 1 and 4, the sum is odd;\n * If we choose the two balls with 2 and 4, the sum is even.\n\nThus, the answer is 1.\n\n* * *"}, {"input": "4 3", "output": "9\n \n\n* * *"}, {"input": "1 1", "output": "0\n \n\n* * *"}, {"input": "13 3", "output": "81\n \n\n* * *"}, {"input": "0 3", "output": "3"}] |
Print the answer.
* * * | s526551527 | Accepted | p02729 | Input is given from Standard Input in the following format:
N M | n, m = map(int, input().split())
rs = 0
if n > 2:
for i in range(1, n + 1):
for e in range(i + 1, n + 1):
rs += 1
if n == 2:
rs += 1
if m > 2:
for i in range(1, m + 1):
for e in range(i + 1, m + 1):
rs += 1
if m == 2:
rs += 1
print(rs)
| Statement
We have N+M balls, each of which has an integer written on it.
It is known that:
* The numbers written on N of the balls are even.
* The numbers written on M of the balls are odd.
Find the number of ways to choose two of the N+M balls (disregarding order) so
that the sum of the numbers written on them is even.
It can be shown that this count does not depend on the actual values written
on the balls. | [{"input": "2 1", "output": "1\n \n\nFor example, let us assume that the numbers written on the three balls are\n1,2,4.\n\n * If we choose the two balls with 1 and 2, the sum is odd;\n * If we choose the two balls with 1 and 4, the sum is odd;\n * If we choose the two balls with 2 and 4, the sum is even.\n\nThus, the answer is 1.\n\n* * *"}, {"input": "4 3", "output": "9\n \n\n* * *"}, {"input": "1 1", "output": "0\n \n\n* * *"}, {"input": "13 3", "output": "81\n \n\n* * *"}, {"input": "0 3", "output": "3"}] |
Print the answer.
* * * | s811963081 | Runtime Error | p02729 | Input is given from Standard Input in the following format:
N M | N = int(input())
a = input().split()
a_str = "".join(a)
a_str2 = a_str
sum = 0
l_dict = {}
while len(a_str) > 0:
n = a.count(a_str[0])
sum += int(n * (n - 1) / 2)
l_dict[a_str[0]] = n
a_str = a_str.replace(a_str[0], "")
for k in range(N):
print(sum - l_dict[a_str2[k]] + 1)
| Statement
We have N+M balls, each of which has an integer written on it.
It is known that:
* The numbers written on N of the balls are even.
* The numbers written on M of the balls are odd.
Find the number of ways to choose two of the N+M balls (disregarding order) so
that the sum of the numbers written on them is even.
It can be shown that this count does not depend on the actual values written
on the balls. | [{"input": "2 1", "output": "1\n \n\nFor example, let us assume that the numbers written on the three balls are\n1,2,4.\n\n * If we choose the two balls with 1 and 2, the sum is odd;\n * If we choose the two balls with 1 and 4, the sum is odd;\n * If we choose the two balls with 2 and 4, the sum is even.\n\nThus, the answer is 1.\n\n* * *"}, {"input": "4 3", "output": "9\n \n\n* * *"}, {"input": "1 1", "output": "0\n \n\n* * *"}, {"input": "13 3", "output": "81\n \n\n* * *"}, {"input": "0 3", "output": "3"}] |
Print the answer.
* * * | s812592473 | Accepted | p02729 | Input is given from Standard Input in the following format:
N M | n, m = map(int, input().split(" "))
a = 0
a += (n * (n - 1)) // 2
a += (m * (m - 1)) // 2
print(a)
| Statement
We have N+M balls, each of which has an integer written on it.
It is known that:
* The numbers written on N of the balls are even.
* The numbers written on M of the balls are odd.
Find the number of ways to choose two of the N+M balls (disregarding order) so
that the sum of the numbers written on them is even.
It can be shown that this count does not depend on the actual values written
on the balls. | [{"input": "2 1", "output": "1\n \n\nFor example, let us assume that the numbers written on the three balls are\n1,2,4.\n\n * If we choose the two balls with 1 and 2, the sum is odd;\n * If we choose the two balls with 1 and 4, the sum is odd;\n * If we choose the two balls with 2 and 4, the sum is even.\n\nThus, the answer is 1.\n\n* * *"}, {"input": "4 3", "output": "9\n \n\n* * *"}, {"input": "1 1", "output": "0\n \n\n* * *"}, {"input": "13 3", "output": "81\n \n\n* * *"}, {"input": "0 3", "output": "3"}] |
Print the answer.
* * * | s096224626 | Accepted | p02729 | Input is given from Standard Input in the following format:
N M | m, n = map(int, input().split(" "))
res = m * (m - 1) // 2 + n * (n - 1) // 2
print(res)
| Statement
We have N+M balls, each of which has an integer written on it.
It is known that:
* The numbers written on N of the balls are even.
* The numbers written on M of the balls are odd.
Find the number of ways to choose two of the N+M balls (disregarding order) so
that the sum of the numbers written on them is even.
It can be shown that this count does not depend on the actual values written
on the balls. | [{"input": "2 1", "output": "1\n \n\nFor example, let us assume that the numbers written on the three balls are\n1,2,4.\n\n * If we choose the two balls with 1 and 2, the sum is odd;\n * If we choose the two balls with 1 and 4, the sum is odd;\n * If we choose the two balls with 2 and 4, the sum is even.\n\nThus, the answer is 1.\n\n* * *"}, {"input": "4 3", "output": "9\n \n\n* * *"}, {"input": "1 1", "output": "0\n \n\n* * *"}, {"input": "13 3", "output": "81\n \n\n* * *"}, {"input": "0 3", "output": "3"}] |
Print the answer.
* * * | s078974829 | Accepted | p02729 | Input is given from Standard Input in the following format:
N M | print(sum(map(lambda x: int(x) * (int(x) - 1) // 2, input().split())))
| Statement
We have N+M balls, each of which has an integer written on it.
It is known that:
* The numbers written on N of the balls are even.
* The numbers written on M of the balls are odd.
Find the number of ways to choose two of the N+M balls (disregarding order) so
that the sum of the numbers written on them is even.
It can be shown that this count does not depend on the actual values written
on the balls. | [{"input": "2 1", "output": "1\n \n\nFor example, let us assume that the numbers written on the three balls are\n1,2,4.\n\n * If we choose the two balls with 1 and 2, the sum is odd;\n * If we choose the two balls with 1 and 4, the sum is odd;\n * If we choose the two balls with 2 and 4, the sum is even.\n\nThus, the answer is 1.\n\n* * *"}, {"input": "4 3", "output": "9\n \n\n* * *"}, {"input": "1 1", "output": "0\n \n\n* * *"}, {"input": "13 3", "output": "81\n \n\n* * *"}, {"input": "0 3", "output": "3"}] |
Print the answer.
* * * | s883356899 | Runtime Error | p02729 | Input is given from Standard Input in the following format:
N M | print(int(input()) // 3**3)
| Statement
We have N+M balls, each of which has an integer written on it.
It is known that:
* The numbers written on N of the balls are even.
* The numbers written on M of the balls are odd.
Find the number of ways to choose two of the N+M balls (disregarding order) so
that the sum of the numbers written on them is even.
It can be shown that this count does not depend on the actual values written
on the balls. | [{"input": "2 1", "output": "1\n \n\nFor example, let us assume that the numbers written on the three balls are\n1,2,4.\n\n * If we choose the two balls with 1 and 2, the sum is odd;\n * If we choose the two balls with 1 and 4, the sum is odd;\n * If we choose the two balls with 2 and 4, the sum is even.\n\nThus, the answer is 1.\n\n* * *"}, {"input": "4 3", "output": "9\n \n\n* * *"}, {"input": "1 1", "output": "0\n \n\n* * *"}, {"input": "13 3", "output": "81\n \n\n* * *"}, {"input": "0 3", "output": "3"}] |
Print the answer.
* * * | s535395146 | Runtime Error | p02729 | Input is given from Standard Input in the following format:
N M | (a,) = b = map(int, input().split())
print(a * (a - 1) / 2 + b * (b - 1) / 2)
| Statement
We have N+M balls, each of which has an integer written on it.
It is known that:
* The numbers written on N of the balls are even.
* The numbers written on M of the balls are odd.
Find the number of ways to choose two of the N+M balls (disregarding order) so
that the sum of the numbers written on them is even.
It can be shown that this count does not depend on the actual values written
on the balls. | [{"input": "2 1", "output": "1\n \n\nFor example, let us assume that the numbers written on the three balls are\n1,2,4.\n\n * If we choose the two balls with 1 and 2, the sum is odd;\n * If we choose the two balls with 1 and 4, the sum is odd;\n * If we choose the two balls with 2 and 4, the sum is even.\n\nThus, the answer is 1.\n\n* * *"}, {"input": "4 3", "output": "9\n \n\n* * *"}, {"input": "1 1", "output": "0\n \n\n* * *"}, {"input": "13 3", "output": "81\n \n\n* * *"}, {"input": "0 3", "output": "3"}] |
Print the answer.
* * * | s733203620 | Wrong Answer | p02729 | Input is given from Standard Input in the following format:
N M | s, t = (int(x) for x in input().split())
print(s * (s - 1) / 2 + t * (t - 1) / 2)
| Statement
We have N+M balls, each of which has an integer written on it.
It is known that:
* The numbers written on N of the balls are even.
* The numbers written on M of the balls are odd.
Find the number of ways to choose two of the N+M balls (disregarding order) so
that the sum of the numbers written on them is even.
It can be shown that this count does not depend on the actual values written
on the balls. | [{"input": "2 1", "output": "1\n \n\nFor example, let us assume that the numbers written on the three balls are\n1,2,4.\n\n * If we choose the two balls with 1 and 2, the sum is odd;\n * If we choose the two balls with 1 and 4, the sum is odd;\n * If we choose the two balls with 2 and 4, the sum is even.\n\nThus, the answer is 1.\n\n* * *"}, {"input": "4 3", "output": "9\n \n\n* * *"}, {"input": "1 1", "output": "0\n \n\n* * *"}, {"input": "13 3", "output": "81\n \n\n* * *"}, {"input": "0 3", "output": "3"}] |
Print the answer.
* * * | s618288870 | Accepted | p02729 | Input is given from Standard Input in the following format:
N M | firstInput = list(map(int, input().split()))
even = firstInput[0]
odd = firstInput[1]
evenSum = 0
oddSum = 0
if even >= 2:
nFactorial = 1
nMinusKFactorial = 1
for i in range(1, even + 1):
nFactorial *= i
for i in range(1, even - 1):
nMinusKFactorial *= i
evenSum = nFactorial / (2 * nMinusKFactorial)
if odd >= 2:
nFactorial = 1
nMinusKFactorial = 1
for i in range(1, odd + 1):
nFactorial *= i
for i in range(1, odd - 1):
nMinusKFactorial *= i
oddSum = nFactorial / (2 * nMinusKFactorial)
print(int(evenSum + oddSum))
| Statement
We have N+M balls, each of which has an integer written on it.
It is known that:
* The numbers written on N of the balls are even.
* The numbers written on M of the balls are odd.
Find the number of ways to choose two of the N+M balls (disregarding order) so
that the sum of the numbers written on them is even.
It can be shown that this count does not depend on the actual values written
on the balls. | [{"input": "2 1", "output": "1\n \n\nFor example, let us assume that the numbers written on the three balls are\n1,2,4.\n\n * If we choose the two balls with 1 and 2, the sum is odd;\n * If we choose the two balls with 1 and 4, the sum is odd;\n * If we choose the two balls with 2 and 4, the sum is even.\n\nThus, the answer is 1.\n\n* * *"}, {"input": "4 3", "output": "9\n \n\n* * *"}, {"input": "1 1", "output": "0\n \n\n* * *"}, {"input": "13 3", "output": "81\n \n\n* * *"}, {"input": "0 3", "output": "3"}] |
Print the answer.
* * * | s849806801 | Wrong Answer | p02729 | Input is given from Standard Input in the following format:
N M | A = input()
L = A.split()
N = int(L[0])
M = int(L[1])
x = 1
for n in range(1, N + 1):
x *= n
x /= 2
y = 1
for m in range(1, M + 1):
y *= m
y /= 2
print(int(x + y))
| Statement
We have N+M balls, each of which has an integer written on it.
It is known that:
* The numbers written on N of the balls are even.
* The numbers written on M of the balls are odd.
Find the number of ways to choose two of the N+M balls (disregarding order) so
that the sum of the numbers written on them is even.
It can be shown that this count does not depend on the actual values written
on the balls. | [{"input": "2 1", "output": "1\n \n\nFor example, let us assume that the numbers written on the three balls are\n1,2,4.\n\n * If we choose the two balls with 1 and 2, the sum is odd;\n * If we choose the two balls with 1 and 4, the sum is odd;\n * If we choose the two balls with 2 and 4, the sum is even.\n\nThus, the answer is 1.\n\n* * *"}, {"input": "4 3", "output": "9\n \n\n* * *"}, {"input": "1 1", "output": "0\n \n\n* * *"}, {"input": "13 3", "output": "81\n \n\n* * *"}, {"input": "0 3", "output": "3"}] |
If the objective is not achievable, print `-1`; otherwise, print the minimum
amount of money needed to achieve it.
* * * | s231085569 | Runtime Error | p02683 | Input is given from Standard Input in the following format:
N M X
C_1 A_{1,1} A_{1,2} \cdots A_{1,M}
C_2 A_{2,1} A_{2,2} \cdots A_{2,M}
\vdots
C_N A_{N,1} A_{N,2} \cdots A_{N,M} | N, M, X = map(int, input().split(" "))
A = [[0] * (M + 1)] * N
for i in range(0, N):
A[i] = input().split(" ")
C = [int(x[0]) for x in A]
Ac = [x[1:] for x in A]
su = 0
acd = 0
sumup = 0
for i in range(0, M):
temp = [int(x[i]) for x in Ac]
print(temp)
for j in range(0, len(temp)):
su = su + temp[j]
if su < X:
can = 1
if can == 1:
print("-1")
| Takahashi, who is a novice in competitive programming, wants to learn M
algorithms. Initially, his _understanding level_ of each of the M algorithms
is 0.
Takahashi is visiting a bookstore, where he finds N books on algorithms. The
i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he
buys and reads it, his understanding level of the j-th algorithm will increase
by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the
understanding levels of the algorithms.
Takahashi's objective is to make his understanding levels of all the M
algorithms X or higher. Determine whether this objective is achievable. If it
is achievable, find the minimum amount of money needed to achieve it. | [{"input": "3 3 10\n 60 2 2 4\n 70 8 7 9\n 50 2 3 9", "output": "120\n \n\nBuying the second and third books makes his understanding levels of all the\nalgorithms 10 or higher, at the minimum cost possible.\n\n* * *"}, {"input": "3 3 10\n 100 3 1 4\n 100 1 5 9\n 100 2 6 5", "output": "-1\n \n\nBuying all the books is still not enough to make his understanding levels of\nall the algorithms 10 or higher.\n\n* * *"}, {"input": "8 5 22\n 100 3 7 5 3 1\n 164 4 5 2 7 8\n 334 7 2 7 2 9\n 234 4 7 2 8 2\n 541 5 4 3 3 6\n 235 4 8 6 9 7\n 394 3 6 1 6 2\n 872 8 4 3 7 2", "output": "1067"}] |
If the objective is not achievable, print `-1`; otherwise, print the minimum
amount of money needed to achieve it.
* * * | s883217260 | Accepted | p02683 | Input is given from Standard Input in the following format:
N M X
C_1 A_{1,1} A_{1,2} \cdots A_{1,M}
C_2 A_{2,1} A_{2,2} \cdots A_{2,M}
\vdots
C_N A_{N,1} A_{N,2} \cdots A_{N,M} | n, m, x = [int(elem) for elem in input().split()]
cs = []
a_lsts = []
for i in range(n):
elems = [int(elem) for elem in input().split()]
c, a_lst = elems[0], elems[1:]
cs.append(c)
a_lsts.append(a_lst)
min_ = -1
for i in range(2**n):
s = "0" * n + bin(i)[2:]
s = s[-n:]
res = 0
costs = [0] * m
for j in range(n):
if s[j] == "0":
pass
else:
res += cs[j]
costs = [costs[k] + a_lsts[j][k] for k in range(m)]
if all(elem >= x for elem in costs):
if min_ == -1:
min_ = res
elif min_ > res:
min_ = res
print(min_)
| Takahashi, who is a novice in competitive programming, wants to learn M
algorithms. Initially, his _understanding level_ of each of the M algorithms
is 0.
Takahashi is visiting a bookstore, where he finds N books on algorithms. The
i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he
buys and reads it, his understanding level of the j-th algorithm will increase
by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the
understanding levels of the algorithms.
Takahashi's objective is to make his understanding levels of all the M
algorithms X or higher. Determine whether this objective is achievable. If it
is achievable, find the minimum amount of money needed to achieve it. | [{"input": "3 3 10\n 60 2 2 4\n 70 8 7 9\n 50 2 3 9", "output": "120\n \n\nBuying the second and third books makes his understanding levels of all the\nalgorithms 10 or higher, at the minimum cost possible.\n\n* * *"}, {"input": "3 3 10\n 100 3 1 4\n 100 1 5 9\n 100 2 6 5", "output": "-1\n \n\nBuying all the books is still not enough to make his understanding levels of\nall the algorithms 10 or higher.\n\n* * *"}, {"input": "8 5 22\n 100 3 7 5 3 1\n 164 4 5 2 7 8\n 334 7 2 7 2 9\n 234 4 7 2 8 2\n 541 5 4 3 3 6\n 235 4 8 6 9 7\n 394 3 6 1 6 2\n 872 8 4 3 7 2", "output": "1067"}] |
If the objective is not achievable, print `-1`; otherwise, print the minimum
amount of money needed to achieve it.
* * * | s784051514 | Wrong Answer | p02683 | Input is given from Standard Input in the following format:
N M X
C_1 A_{1,1} A_{1,2} \cdots A_{1,M}
C_2 A_{2,1} A_{2,2} \cdots A_{2,M}
\vdots
C_N A_{N,1} A_{N,2} \cdots A_{N,M} | def Skill_Up():
condition = input()
condition_list = condition.split()
N = int(condition_list[0])
M = int(condition_list[1])
X = int(condition_list[2])
text_info = []
for i in range(0, N):
text_book = input()
text_info_str = text_book.split()
text_book_int = []
for j in text_info_str:
text_book_int.append(int(j))
text_info.append(text_book_int)
text_effective = []
for i in text_info:
effective = 0
for j in range(1, M + 1):
effective += i[j]
effective /= i[0]
text_effective.append(effective)
for i in range(0, N):
for j in range(0, N - i - 1):
if text_effective[j] < text_effective[j + 1]:
text_effective[j], text_effective[j + 1] = (
text_effective[j + 1],
text_effective[j],
)
text_info[j], text_info[j + 1] = text_info[j + 1], text_info[j]
skill_level = []
skill_check = []
for j in range(0, M + 1):
skill_level.append(0)
skill_check.append(False)
is_clear = False
for i in range(0, N):
for j in range(0, M + 1):
skill_level[j] += text_info[i][j]
if skill_level[j] >= X:
skill_check[j] = True
for j in range(0, M + 1):
if skill_check[j] is False:
is_clear = False
break
is_clear = True
if is_clear:
print(skill_level[0])
return
if is_clear is False:
print(-1)
return
Skill_Up()
| Takahashi, who is a novice in competitive programming, wants to learn M
algorithms. Initially, his _understanding level_ of each of the M algorithms
is 0.
Takahashi is visiting a bookstore, where he finds N books on algorithms. The
i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he
buys and reads it, his understanding level of the j-th algorithm will increase
by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the
understanding levels of the algorithms.
Takahashi's objective is to make his understanding levels of all the M
algorithms X or higher. Determine whether this objective is achievable. If it
is achievable, find the minimum amount of money needed to achieve it. | [{"input": "3 3 10\n 60 2 2 4\n 70 8 7 9\n 50 2 3 9", "output": "120\n \n\nBuying the second and third books makes his understanding levels of all the\nalgorithms 10 or higher, at the minimum cost possible.\n\n* * *"}, {"input": "3 3 10\n 100 3 1 4\n 100 1 5 9\n 100 2 6 5", "output": "-1\n \n\nBuying all the books is still not enough to make his understanding levels of\nall the algorithms 10 or higher.\n\n* * *"}, {"input": "8 5 22\n 100 3 7 5 3 1\n 164 4 5 2 7 8\n 334 7 2 7 2 9\n 234 4 7 2 8 2\n 541 5 4 3 3 6\n 235 4 8 6 9 7\n 394 3 6 1 6 2\n 872 8 4 3 7 2", "output": "1067"}] |
If the objective is not achievable, print `-1`; otherwise, print the minimum
amount of money needed to achieve it.
* * * | s566649192 | Wrong Answer | p02683 | Input is given from Standard Input in the following format:
N M X
C_1 A_{1,1} A_{1,2} \cdots A_{1,M}
C_2 A_{2,1} A_{2,2} \cdots A_{2,M}
\vdots
C_N A_{N,1} A_{N,2} \cdots A_{N,M} | N, M, X = input().split()
i = 0
while i < int(N):
A = input().split()
C = A[0]
Am = A[1:]
i = i + 1
| Takahashi, who is a novice in competitive programming, wants to learn M
algorithms. Initially, his _understanding level_ of each of the M algorithms
is 0.
Takahashi is visiting a bookstore, where he finds N books on algorithms. The
i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he
buys and reads it, his understanding level of the j-th algorithm will increase
by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the
understanding levels of the algorithms.
Takahashi's objective is to make his understanding levels of all the M
algorithms X or higher. Determine whether this objective is achievable. If it
is achievable, find the minimum amount of money needed to achieve it. | [{"input": "3 3 10\n 60 2 2 4\n 70 8 7 9\n 50 2 3 9", "output": "120\n \n\nBuying the second and third books makes his understanding levels of all the\nalgorithms 10 or higher, at the minimum cost possible.\n\n* * *"}, {"input": "3 3 10\n 100 3 1 4\n 100 1 5 9\n 100 2 6 5", "output": "-1\n \n\nBuying all the books is still not enough to make his understanding levels of\nall the algorithms 10 or higher.\n\n* * *"}, {"input": "8 5 22\n 100 3 7 5 3 1\n 164 4 5 2 7 8\n 334 7 2 7 2 9\n 234 4 7 2 8 2\n 541 5 4 3 3 6\n 235 4 8 6 9 7\n 394 3 6 1 6 2\n 872 8 4 3 7 2", "output": "1067"}] |
If the objective is not achievable, print `-1`; otherwise, print the minimum
amount of money needed to achieve it.
* * * | s438429683 | Wrong Answer | p02683 | Input is given from Standard Input in the following format:
N M X
C_1 A_{1,1} A_{1,2} \cdots A_{1,M}
C_2 A_{2,1} A_{2,2} \cdots A_{2,M}
\vdots
C_N A_{N,1} A_{N,2} \cdots A_{N,M} | print(-1)
| Takahashi, who is a novice in competitive programming, wants to learn M
algorithms. Initially, his _understanding level_ of each of the M algorithms
is 0.
Takahashi is visiting a bookstore, where he finds N books on algorithms. The
i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he
buys and reads it, his understanding level of the j-th algorithm will increase
by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the
understanding levels of the algorithms.
Takahashi's objective is to make his understanding levels of all the M
algorithms X or higher. Determine whether this objective is achievable. If it
is achievable, find the minimum amount of money needed to achieve it. | [{"input": "3 3 10\n 60 2 2 4\n 70 8 7 9\n 50 2 3 9", "output": "120\n \n\nBuying the second and third books makes his understanding levels of all the\nalgorithms 10 or higher, at the minimum cost possible.\n\n* * *"}, {"input": "3 3 10\n 100 3 1 4\n 100 1 5 9\n 100 2 6 5", "output": "-1\n \n\nBuying all the books is still not enough to make his understanding levels of\nall the algorithms 10 or higher.\n\n* * *"}, {"input": "8 5 22\n 100 3 7 5 3 1\n 164 4 5 2 7 8\n 334 7 2 7 2 9\n 234 4 7 2 8 2\n 541 5 4 3 3 6\n 235 4 8 6 9 7\n 394 3 6 1 6 2\n 872 8 4 3 7 2", "output": "1067"}] |
If the objective is not achievable, print `-1`; otherwise, print the minimum
amount of money needed to achieve it.
* * * | s501791229 | Runtime Error | p02683 | Input is given from Standard Input in the following format:
N M X
C_1 A_{1,1} A_{1,2} \cdots A_{1,M}
C_2 A_{2,1} A_{2,2} \cdots A_{2,M}
\vdots
C_N A_{N,1} A_{N,2} \cdots A_{N,M} | DEBUG = True
import time
N, K = map(int, input().split())
A = [int(i) - 1 for i in input().split()]
visited = [False] * N
next = A[0]
visited[0] = True
K -= 1
while not visited[next]:
if DEBUG:
print("K: {}, next: {}".format(K, next))
print("visited: {}".format(visited))
time.sleep(0.1)
if K == 0:
print(next + 1)
exit()
visited[next] = True
next = A[next]
K -= 1
K -= 1
now = next
count = 1
next = A[next]
while now != next:
next = A[next]
count += 1
if DEBUG:
print("count: {}".format(count))
K %= count
if DEBUG:
print("now: {}, count: {}, K: {}".format(now, count, K))
while K > 0:
if DEBUG:
print("now: {}".format(now))
now = A[now]
K -= 1
print(A[now] + 1)
| Takahashi, who is a novice in competitive programming, wants to learn M
algorithms. Initially, his _understanding level_ of each of the M algorithms
is 0.
Takahashi is visiting a bookstore, where he finds N books on algorithms. The
i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he
buys and reads it, his understanding level of the j-th algorithm will increase
by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the
understanding levels of the algorithms.
Takahashi's objective is to make his understanding levels of all the M
algorithms X or higher. Determine whether this objective is achievable. If it
is achievable, find the minimum amount of money needed to achieve it. | [{"input": "3 3 10\n 60 2 2 4\n 70 8 7 9\n 50 2 3 9", "output": "120\n \n\nBuying the second and third books makes his understanding levels of all the\nalgorithms 10 or higher, at the minimum cost possible.\n\n* * *"}, {"input": "3 3 10\n 100 3 1 4\n 100 1 5 9\n 100 2 6 5", "output": "-1\n \n\nBuying all the books is still not enough to make his understanding levels of\nall the algorithms 10 or higher.\n\n* * *"}, {"input": "8 5 22\n 100 3 7 5 3 1\n 164 4 5 2 7 8\n 334 7 2 7 2 9\n 234 4 7 2 8 2\n 541 5 4 3 3 6\n 235 4 8 6 9 7\n 394 3 6 1 6 2\n 872 8 4 3 7 2", "output": "1067"}] |
If the objective is not achievable, print `-1`; otherwise, print the minimum
amount of money needed to achieve it.
* * * | s754217373 | Wrong Answer | p02683 | Input is given from Standard Input in the following format:
N M X
C_1 A_{1,1} A_{1,2} \cdots A_{1,M}
C_2 A_{2,1} A_{2,2} \cdots A_{2,M}
\vdots
C_N A_{N,1} A_{N,2} \cdots A_{N,M} | n, m, x = map(int, input().split())
ca = [(list(map(int, input().split())))]
print(-1)
| Takahashi, who is a novice in competitive programming, wants to learn M
algorithms. Initially, his _understanding level_ of each of the M algorithms
is 0.
Takahashi is visiting a bookstore, where he finds N books on algorithms. The
i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he
buys and reads it, his understanding level of the j-th algorithm will increase
by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the
understanding levels of the algorithms.
Takahashi's objective is to make his understanding levels of all the M
algorithms X or higher. Determine whether this objective is achievable. If it
is achievable, find the minimum amount of money needed to achieve it. | [{"input": "3 3 10\n 60 2 2 4\n 70 8 7 9\n 50 2 3 9", "output": "120\n \n\nBuying the second and third books makes his understanding levels of all the\nalgorithms 10 or higher, at the minimum cost possible.\n\n* * *"}, {"input": "3 3 10\n 100 3 1 4\n 100 1 5 9\n 100 2 6 5", "output": "-1\n \n\nBuying all the books is still not enough to make his understanding levels of\nall the algorithms 10 or higher.\n\n* * *"}, {"input": "8 5 22\n 100 3 7 5 3 1\n 164 4 5 2 7 8\n 334 7 2 7 2 9\n 234 4 7 2 8 2\n 541 5 4 3 3 6\n 235 4 8 6 9 7\n 394 3 6 1 6 2\n 872 8 4 3 7 2", "output": "1067"}] |
If the objective is not achievable, print `-1`; otherwise, print the minimum
amount of money needed to achieve it.
* * * | s166730493 | Accepted | p02683 | Input is given from Standard Input in the following format:
N M X
C_1 A_{1,1} A_{1,2} \cdots A_{1,M}
C_2 A_{2,1} A_{2,2} \cdots A_{2,M}
\vdots
C_N A_{N,1} A_{N,2} \cdots A_{N,M} | import itertools as itt
n, m, x = map(int, input().split())
lsts = []
cbs = []
minp = -1
for i in range(n):
lsts.append(input().split())
for j in range(m + 1):
lsts[i][j] = int(lsts[i][j])
#
for i in range(1, n + 1):
cbs += list(itt.combinations(lsts, i))
# print(cbs)
for i in range(len(cbs)):
p = 0
algs = [0] * m
flg = True
for j in range(len(cbs[i])):
p += cbs[i][j][0]
for k in range(m):
algs[k] += cbs[i][j][k + 1]
for alg in algs:
if alg < x:
flg = False
if flg and (minp == -1 or p < minp):
minp = p
#
print(minp)
| Takahashi, who is a novice in competitive programming, wants to learn M
algorithms. Initially, his _understanding level_ of each of the M algorithms
is 0.
Takahashi is visiting a bookstore, where he finds N books on algorithms. The
i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he
buys and reads it, his understanding level of the j-th algorithm will increase
by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the
understanding levels of the algorithms.
Takahashi's objective is to make his understanding levels of all the M
algorithms X or higher. Determine whether this objective is achievable. If it
is achievable, find the minimum amount of money needed to achieve it. | [{"input": "3 3 10\n 60 2 2 4\n 70 8 7 9\n 50 2 3 9", "output": "120\n \n\nBuying the second and third books makes his understanding levels of all the\nalgorithms 10 or higher, at the minimum cost possible.\n\n* * *"}, {"input": "3 3 10\n 100 3 1 4\n 100 1 5 9\n 100 2 6 5", "output": "-1\n \n\nBuying all the books is still not enough to make his understanding levels of\nall the algorithms 10 or higher.\n\n* * *"}, {"input": "8 5 22\n 100 3 7 5 3 1\n 164 4 5 2 7 8\n 334 7 2 7 2 9\n 234 4 7 2 8 2\n 541 5 4 3 3 6\n 235 4 8 6 9 7\n 394 3 6 1 6 2\n 872 8 4 3 7 2", "output": "1067"}] |
If the objective is not achievable, print `-1`; otherwise, print the minimum
amount of money needed to achieve it.
* * * | s784437113 | Accepted | p02683 | Input is given from Standard Input in the following format:
N M X
C_1 A_{1,1} A_{1,2} \cdots A_{1,M}
C_2 A_{2,1} A_{2,2} \cdots A_{2,M}
\vdots
C_N A_{N,1} A_{N,2} \cdots A_{N,M} | from itertools import combinations as co
n, m, x = map(int, input().split())
A = []
ansl = []
for i in range(n):
A.append(list(map(int, input().split())))
for i in range(n):
for j in range(1, m + 1):
if A[i][j] < x:
break
if j == m:
ansl.append(A[i][0])
if n == 1:
print(min(ansl) if len(ansl) > 0 else "-1")
quit()
for i, j in co(range(n), 2):
for k in range(1, m + 1):
if A[i][k] + A[j][k] < x:
break
if k == m:
ansl.append(A[i][0] + A[j][0])
if n == 2:
print(min(ansl) if len(ansl) > 0 else "-1")
quit()
for i, j, k in co(range(n), 3):
for l in range(1, m + 1):
if A[i][l] + A[j][l] + A[k][l] < x:
break
if l == m:
ansl.append(A[i][0] + A[j][0] + A[k][0])
if n == 3:
print(min(ansl) if len(ansl) > 0 else "-1")
quit()
for h, i, j, k in co(range(n), 4):
for l in range(1, m + 1):
if A[h][l] + A[i][l] + A[j][l] + A[k][l] < x:
break
if l == m:
ansl.append(A[h][0] + A[i][0] + A[j][0] + A[k][0])
if n == 4:
print(min(ansl) if len(ansl) > 0 else "-1")
quit()
for g, h, i, j, k in co(range(n), 5):
for l in range(1, m + 1):
if sum([A[alp][l] for alp in [g, h, i, j, k]]) < x:
break
if l == m:
ansl.append(sum([A[alp][0] for alp in [g, h, i, j, k]]))
if n == 5:
print(min(ansl) if len(ansl) > 0 else "-1")
quit()
for f, g, h, i, j, k in co(range(n), 6):
for l in range(1, m + 1):
if sum([A[alp][l] for alp in [f, g, h, i, j, k]]) < x:
break
if l == m:
ansl.append(sum([A[alp][0] for alp in [f, g, h, i, j, k]]))
if n == 6:
print(min(ansl) if len(ansl) > 0 else "-1")
quit()
for e, f, g, h, i, j, k in co(range(n), 7):
for l in range(1, m + 1):
if sum([A[alp][l] for alp in [e, f, g, h, i, j, k]]) < x:
break
if l == m:
ansl.append(sum([A[alp][0] for alp in [e, f, g, h, i, j, k]]))
if n == 7:
print(min(ansl) if len(ansl) > 0 else "-1")
quit()
for d, e, f, g, h, i, j, k in co(range(n), 8):
for l in range(1, m + 1):
if sum([A[alp][l] for alp in [d, e, f, g, h, i, j, k]]) < x:
break
if l == m:
ansl.append(sum([A[alp][0] for alp in [d, e, f, g, h, i, j, k]]))
if n == 8:
print(min(ansl) if len(ansl) > 0 else "-1")
quit()
for c, d, e, f, g, h, i, j, k in co(range(n), 9):
for l in range(1, m + 1):
if sum([A[alp][l] for alp in [c, d, e, f, g, h, i, j, k]]) < x:
break
if l == m:
ansl.append(sum([A[alp][0] for alp in [c, d, e, f, g, h, i, j, k]]))
if n == 9:
print(min(ansl) if len(ansl) > 0 else "-1")
quit()
for b, c, d, e, f, g, h, i, j, k in co(range(n), 10):
for l in range(1, m + 1):
if sum([A[alp][l] for alp in [b, c, d, e, f, g, h, i, j, k]]) < x:
break
if l == m:
ansl.append(sum([A[alp][0] for alp in [b, c, d, e, f, g, h, i, j, k]]))
if n == 10:
print(min(ansl) if len(ansl) > 0 else "-1")
quit()
for a, b, c, d, e, f, g, h, i, j, k in co(range(n), 11):
for l in range(1, m + 1):
if sum([A[alp][l] for alp in [a, b, c, d, e, f, g, h, i, j, k]]) < x:
break
if l == m:
ansl.append(sum([A[alp][0] for alp in [a, b, c, d, e, f, g, h, i, j, k]]))
if n == 11:
print(min(ansl) if len(ansl) > 0 else "-1")
quit()
for a0, a, b, c, d, e, f, g, h, i, j, k in co(range(n), 12):
for l in range(1, m + 1):
if sum([A[alp][l] for alp in [a0, a, b, c, d, e, f, g, h, i, j, k]]) < x:
break
if l == m:
ansl.append(
sum([A[alp][0] for alp in [a0, a, b, c, d, e, f, g, h, i, j, k]])
)
if n == 12:
print(min(ansl) if len(ansl) > 0 else "-1")
quit()
| Takahashi, who is a novice in competitive programming, wants to learn M
algorithms. Initially, his _understanding level_ of each of the M algorithms
is 0.
Takahashi is visiting a bookstore, where he finds N books on algorithms. The
i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he
buys and reads it, his understanding level of the j-th algorithm will increase
by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the
understanding levels of the algorithms.
Takahashi's objective is to make his understanding levels of all the M
algorithms X or higher. Determine whether this objective is achievable. If it
is achievable, find the minimum amount of money needed to achieve it. | [{"input": "3 3 10\n 60 2 2 4\n 70 8 7 9\n 50 2 3 9", "output": "120\n \n\nBuying the second and third books makes his understanding levels of all the\nalgorithms 10 or higher, at the minimum cost possible.\n\n* * *"}, {"input": "3 3 10\n 100 3 1 4\n 100 1 5 9\n 100 2 6 5", "output": "-1\n \n\nBuying all the books is still not enough to make his understanding levels of\nall the algorithms 10 or higher.\n\n* * *"}, {"input": "8 5 22\n 100 3 7 5 3 1\n 164 4 5 2 7 8\n 334 7 2 7 2 9\n 234 4 7 2 8 2\n 541 5 4 3 3 6\n 235 4 8 6 9 7\n 394 3 6 1 6 2\n 872 8 4 3 7 2", "output": "1067"}] |
If the objective is not achievable, print `-1`; otherwise, print the minimum
amount of money needed to achieve it.
* * * | s069457875 | Accepted | p02683 | Input is given from Standard Input in the following format:
N M X
C_1 A_{1,1} A_{1,2} \cdots A_{1,M}
C_2 A_{2,1} A_{2,2} \cdots A_{2,M}
\vdots
C_N A_{N,1} A_{N,2} \cdots A_{N,M} | n, m, x = map(int, input().split())
lst = []
for i in range(n):
lst.append(list(map(int, input().split())))
pmin = 10 ** 10
for i in range(1, 2 ** n): # 選び方
sbin = format(i, 'b')
sbin = '0' * (n - len(sbin)) + sbin
temp = [0] * m
p = 0
for j in range(n): # 選ぶ行
if sbin[j] == '1':
for k in range(m): # 足す
temp[k] += lst[j][k + 1]
p += lst[j][0]
if min(temp) >= x:
pmin = min(pmin, p)
if pmin == 10 ** 10:
print(-1)
else:
print(pmin) | Takahashi, who is a novice in competitive programming, wants to learn M
algorithms. Initially, his _understanding level_ of each of the M algorithms
is 0.
Takahashi is visiting a bookstore, where he finds N books on algorithms. The
i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he
buys and reads it, his understanding level of the j-th algorithm will increase
by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the
understanding levels of the algorithms.
Takahashi's objective is to make his understanding levels of all the M
algorithms X or higher. Determine whether this objective is achievable. If it
is achievable, find the minimum amount of money needed to achieve it. | [{"input": "3 3 10\n 60 2 2 4\n 70 8 7 9\n 50 2 3 9", "output": "120\n \n\nBuying the second and third books makes his understanding levels of all the\nalgorithms 10 or higher, at the minimum cost possible.\n\n* * *"}, {"input": "3 3 10\n 100 3 1 4\n 100 1 5 9\n 100 2 6 5", "output": "-1\n \n\nBuying all the books is still not enough to make his understanding levels of\nall the algorithms 10 or higher.\n\n* * *"}, {"input": "8 5 22\n 100 3 7 5 3 1\n 164 4 5 2 7 8\n 334 7 2 7 2 9\n 234 4 7 2 8 2\n 541 5 4 3 3 6\n 235 4 8 6 9 7\n 394 3 6 1 6 2\n 872 8 4 3 7 2", "output": "1067"}] |
If the objective is not achievable, print `-1`; otherwise, print the minimum
amount of money needed to achieve it.
* * * | s723334408 | Accepted | p02683 | Input is given from Standard Input in the following format:
N M X
C_1 A_{1,1} A_{1,2} \cdots A_{1,M}
C_2 A_{2,1} A_{2,2} \cdots A_{2,M}
\vdots
C_N A_{N,1} A_{N,2} \cdots A_{N,M} | (n, m, x), *t = [[*map(int, t.split())] for t in open(0)]
m = 9**9
for i in range(1, 2**n):
c, *a = map(sum, zip(*[t[j] for j in range(n) if 1 << j & i]))
if min(a) >= x:
m = min(m, c + 1)
print(m % 9**9 - 1)
| Takahashi, who is a novice in competitive programming, wants to learn M
algorithms. Initially, his _understanding level_ of each of the M algorithms
is 0.
Takahashi is visiting a bookstore, where he finds N books on algorithms. The
i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he
buys and reads it, his understanding level of the j-th algorithm will increase
by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the
understanding levels of the algorithms.
Takahashi's objective is to make his understanding levels of all the M
algorithms X or higher. Determine whether this objective is achievable. If it
is achievable, find the minimum amount of money needed to achieve it. | [{"input": "3 3 10\n 60 2 2 4\n 70 8 7 9\n 50 2 3 9", "output": "120\n \n\nBuying the second and third books makes his understanding levels of all the\nalgorithms 10 or higher, at the minimum cost possible.\n\n* * *"}, {"input": "3 3 10\n 100 3 1 4\n 100 1 5 9\n 100 2 6 5", "output": "-1\n \n\nBuying all the books is still not enough to make his understanding levels of\nall the algorithms 10 or higher.\n\n* * *"}, {"input": "8 5 22\n 100 3 7 5 3 1\n 164 4 5 2 7 8\n 334 7 2 7 2 9\n 234 4 7 2 8 2\n 541 5 4 3 3 6\n 235 4 8 6 9 7\n 394 3 6 1 6 2\n 872 8 4 3 7 2", "output": "1067"}] |
If the objective is not achievable, print `-1`; otherwise, print the minimum
amount of money needed to achieve it.
* * * | s097143157 | Wrong Answer | p02683 | Input is given from Standard Input in the following format:
N M X
C_1 A_{1,1} A_{1,2} \cdots A_{1,M}
C_2 A_{2,1} A_{2,2} \cdots A_{2,M}
\vdots
C_N A_{N,1} A_{N,2} \cdots A_{N,M} | N, M, X = map(int, input().strip().split())
book_list = [tuple(map(int, input().strip().split())) for _ in range(N)]
most_cheep = 10**5 * 12
for pattern in range(1 << N):
understanding_list = [0] * M
cost_list = []
for n_bit in range(N):
if (pattern >> n_bit) & 1:
for m in range(M):
understanding_list[m] += book_list[n_bit][m + 1]
cost_list.append(book_list[n_bit][0])
for understanding in understanding_list:
if understanding < X:
break
else:
most_cheep = min(most_cheep, sum(cost_list))
if most_cheep == 10**5 * 12:
most_cheep = -1
print(most_cheep)
| Takahashi, who is a novice in competitive programming, wants to learn M
algorithms. Initially, his _understanding level_ of each of the M algorithms
is 0.
Takahashi is visiting a bookstore, where he finds N books on algorithms. The
i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he
buys and reads it, his understanding level of the j-th algorithm will increase
by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the
understanding levels of the algorithms.
Takahashi's objective is to make his understanding levels of all the M
algorithms X or higher. Determine whether this objective is achievable. If it
is achievable, find the minimum amount of money needed to achieve it. | [{"input": "3 3 10\n 60 2 2 4\n 70 8 7 9\n 50 2 3 9", "output": "120\n \n\nBuying the second and third books makes his understanding levels of all the\nalgorithms 10 or higher, at the minimum cost possible.\n\n* * *"}, {"input": "3 3 10\n 100 3 1 4\n 100 1 5 9\n 100 2 6 5", "output": "-1\n \n\nBuying all the books is still not enough to make his understanding levels of\nall the algorithms 10 or higher.\n\n* * *"}, {"input": "8 5 22\n 100 3 7 5 3 1\n 164 4 5 2 7 8\n 334 7 2 7 2 9\n 234 4 7 2 8 2\n 541 5 4 3 3 6\n 235 4 8 6 9 7\n 394 3 6 1 6 2\n 872 8 4 3 7 2", "output": "1067"}] |
If the objective is not achievable, print `-1`; otherwise, print the minimum
amount of money needed to achieve it.
* * * | s995383447 | Wrong Answer | p02683 | Input is given from Standard Input in the following format:
N M X
C_1 A_{1,1} A_{1,2} \cdots A_{1,M}
C_2 A_{2,1} A_{2,2} \cdots A_{2,M}
\vdots
C_N A_{N,1} A_{N,2} \cdots A_{N,M} | n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]
pair = []
for c1 in range(2):
for c2 in range(2):
for c3 in range(2):
for c4 in range(2):
for c5 in range(2):
for c6 in range(2):
for c7 in range(2):
for c8 in range(2):
for c9 in range(2):
for c10 in range(2):
for c11 in range(2):
for c12 in range(2):
pair.append(
[
c1,
c2,
c3,
c4,
c5,
c6,
c7,
c8,
c9,
c10,
c11,
c12,
]
)
zenkingaku = []
for pattern in pair:
rikaido = [0 for _ in range(m)]
kingaku = 0
_pattern = pattern[:n]
for ca_i, p in enumerate(_pattern):
if p == 1:
kingaku += ca[ca_i][0]
for ca_j in range(1, m):
rikaido[ca_j] += ca[ca_i][ca_j]
for ca_j in range(1, m):
if rikaido[ca_j] < x:
kingaku = -1
if kingaku == -1:
continue
zenkingaku.append(kingaku)
if not zenkingaku:
zenkingaku = [-1]
print(min(zenkingaku))
| Takahashi, who is a novice in competitive programming, wants to learn M
algorithms. Initially, his _understanding level_ of each of the M algorithms
is 0.
Takahashi is visiting a bookstore, where he finds N books on algorithms. The
i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he
buys and reads it, his understanding level of the j-th algorithm will increase
by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the
understanding levels of the algorithms.
Takahashi's objective is to make his understanding levels of all the M
algorithms X or higher. Determine whether this objective is achievable. If it
is achievable, find the minimum amount of money needed to achieve it. | [{"input": "3 3 10\n 60 2 2 4\n 70 8 7 9\n 50 2 3 9", "output": "120\n \n\nBuying the second and third books makes his understanding levels of all the\nalgorithms 10 or higher, at the minimum cost possible.\n\n* * *"}, {"input": "3 3 10\n 100 3 1 4\n 100 1 5 9\n 100 2 6 5", "output": "-1\n \n\nBuying all the books is still not enough to make his understanding levels of\nall the algorithms 10 or higher.\n\n* * *"}, {"input": "8 5 22\n 100 3 7 5 3 1\n 164 4 5 2 7 8\n 334 7 2 7 2 9\n 234 4 7 2 8 2\n 541 5 4 3 3 6\n 235 4 8 6 9 7\n 394 3 6 1 6 2\n 872 8 4 3 7 2", "output": "1067"}] |
If the objective is not achievable, print `-1`; otherwise, print the minimum
amount of money needed to achieve it.
* * * | s355735192 | Wrong Answer | p02683 | Input is given from Standard Input in the following format:
N M X
C_1 A_{1,1} A_{1,2} \cdots A_{1,M}
C_2 A_{2,1} A_{2,2} \cdots A_{2,M}
\vdots
C_N A_{N,1} A_{N,2} \cdots A_{N,M} | kati_ok = list()
def katihantei(kati, ind, M, X, i):
global kati_ok
# print(ind)
f = 0
if ind == M:
return i
if kati[ind] < X:
f = 1
if f == 1:
return
ind += 1
return katihantei(kati, ind, M, X, i)
def main():
N, M, X = map(int, input().split())
diction = list()
for i in range(N):
list_i = [i]
list_i.extend(list(map(int, input().split())))
diction.append(list_i)
# print(diction)
n = len(diction)
bit_list = list()
for i in range(2**n):
bit = []
for j in range(n): # このループが一番のポイント
if (i >> j) & 1: # 順に右にシフトさせ最下位bitのチェックを行う
bit.append(diction[j][0]) # フラグが立っていたら bag に果物を詰める
# print(bit)
bit_list.append(bit)
# print(bit_list)
katiari = list()
sum_kingaku = list()
for i in range(len(bit_list)):
kingaku = 0
kati = [0] * M
for j in range(len(bit_list[i])):
kingaku += diction[bit_list[i][j]][1]
for k in range(M):
kati[k] += diction[bit_list[i][j]][2 + k]
sum_kingaku.append(kingaku)
sorenokati = katihantei(kati, 0, M, X, i)
if sorenokati != None:
katiari.append(sorenokati)
# print(katiari,sum_kingaku)
if len(katiari) == 0:
print(-1)
else:
min_kingaku = 10**5
for i in range(len(katiari)):
if min_kingaku > sum_kingaku[katiari[i]]:
min_kingaku = sum_kingaku[katiari[i]]
print(min_kingaku)
if __name__ == "__main__":
main()
| Takahashi, who is a novice in competitive programming, wants to learn M
algorithms. Initially, his _understanding level_ of each of the M algorithms
is 0.
Takahashi is visiting a bookstore, where he finds N books on algorithms. The
i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he
buys and reads it, his understanding level of the j-th algorithm will increase
by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the
understanding levels of the algorithms.
Takahashi's objective is to make his understanding levels of all the M
algorithms X or higher. Determine whether this objective is achievable. If it
is achievable, find the minimum amount of money needed to achieve it. | [{"input": "3 3 10\n 60 2 2 4\n 70 8 7 9\n 50 2 3 9", "output": "120\n \n\nBuying the second and third books makes his understanding levels of all the\nalgorithms 10 or higher, at the minimum cost possible.\n\n* * *"}, {"input": "3 3 10\n 100 3 1 4\n 100 1 5 9\n 100 2 6 5", "output": "-1\n \n\nBuying all the books is still not enough to make his understanding levels of\nall the algorithms 10 or higher.\n\n* * *"}, {"input": "8 5 22\n 100 3 7 5 3 1\n 164 4 5 2 7 8\n 334 7 2 7 2 9\n 234 4 7 2 8 2\n 541 5 4 3 3 6\n 235 4 8 6 9 7\n 394 3 6 1 6 2\n 872 8 4 3 7 2", "output": "1067"}] |
If the objective is not achievable, print `-1`; otherwise, print the minimum
amount of money needed to achieve it.
* * * | s143187707 | Wrong Answer | p02683 | Input is given from Standard Input in the following format:
N M X
C_1 A_{1,1} A_{1,2} \cdots A_{1,M}
C_2 A_{2,1} A_{2,2} \cdots A_{2,M}
\vdots
C_N A_{N,1} A_{N,2} \cdots A_{N,M} | N, M, X = input().split()
N, M, X = int(N), int(M), int(X)
C = []
A = []
for i in range(N):
a = [int(x) for x in input().split()]
C.append(a[0])
A.append(a[1:])
#
def combination(list_, length):
# print(list_, length)
if length == 2:
list_com = [[list_[0], list_[1]], [list_[1], list_[0]]]
return list_com
else:
list_com = []
for i in range(length):
out_i = [list_[j] for j in range(length) if i != j]
list_com_i = combination(out_i, len(out_i))
for j in range(len(list_com_i)):
list_c = [list_[i]]
list_c.extend(list_com_i[j])
list_com.append(list_c)
return list_com
num = [i for i in range(N)]
all_com = combination(num, N)
# print(N,num,all_com)
cost_min = 10000000
for combi in all_com:
# print(combi)
cost = 0
skil = [0 for j in range(M)]
clear = M
for j in range(N): # len(combi)=N
if clear != 0:
cost += C[combi[j]]
clear = M
for k in range(M):
skil[k] += A[combi[j]][k]
# check
if skil[k] >= X:
clear = clear - 1
# print(cost)
if clear == 0:
if cost < cost_min:
cost_min = cost
if cost_min == 10000000:
cost_min = -1
# for i in range(N):
# print(C[i], A[i])
print(cost_min)
| Takahashi, who is a novice in competitive programming, wants to learn M
algorithms. Initially, his _understanding level_ of each of the M algorithms
is 0.
Takahashi is visiting a bookstore, where he finds N books on algorithms. The
i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he
buys and reads it, his understanding level of the j-th algorithm will increase
by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the
understanding levels of the algorithms.
Takahashi's objective is to make his understanding levels of all the M
algorithms X or higher. Determine whether this objective is achievable. If it
is achievable, find the minimum amount of money needed to achieve it. | [{"input": "3 3 10\n 60 2 2 4\n 70 8 7 9\n 50 2 3 9", "output": "120\n \n\nBuying the second and third books makes his understanding levels of all the\nalgorithms 10 or higher, at the minimum cost possible.\n\n* * *"}, {"input": "3 3 10\n 100 3 1 4\n 100 1 5 9\n 100 2 6 5", "output": "-1\n \n\nBuying all the books is still not enough to make his understanding levels of\nall the algorithms 10 or higher.\n\n* * *"}, {"input": "8 5 22\n 100 3 7 5 3 1\n 164 4 5 2 7 8\n 334 7 2 7 2 9\n 234 4 7 2 8 2\n 541 5 4 3 3 6\n 235 4 8 6 9 7\n 394 3 6 1 6 2\n 872 8 4 3 7 2", "output": "1067"}] |
If the objective is not achievable, print `-1`; otherwise, print the minimum
amount of money needed to achieve it.
* * * | s843193248 | Wrong Answer | p02683 | Input is given from Standard Input in the following format:
N M X
C_1 A_{1,1} A_{1,2} \cdots A_{1,M}
C_2 A_{2,1} A_{2,2} \cdots A_{2,M}
\vdots
C_N A_{N,1} A_{N,2} \cdots A_{N,M} | import numpy as np
n, m, x = map(int, input().split())
all = []
cost = []
result = []
for i in range(n):
tmp = list(map(int, input().split()))
all.append(tmp[1:])
cost.append(tmp[0])
# print(cost)
# print(all)
for i1 in range(m):
for i2 in range(i1 + 1, n):
sum = np.array(all[i1]) + np.array(all[i2])
flag = True
for i in sum:
if i < x:
flag = False
if flag:
result.append(cost[i1] + cost[i2])
# 3
for i1 in range(n):
for i2 in range(i1 + 1, n):
for i3 in range(i2 + 1, n):
sum = np.array(all[i1]) + np.array(all[i2]) + np.array(all[i3])
flag = True
for i in sum:
if i < x:
flag = False
if flag:
result.append(cost[i1] + cost[i2] + cost[i3])
# 4
for i1 in range(m):
for i2 in range(i1 + 1, n):
for i3 in range(i2 + 1, n):
for i4 in range(i3 + 1, n):
sum = (
np.array(all[i1])
+ np.array(all[i2])
+ np.array(all[i3])
+ np.array(all[i4])
)
flag = True
for i in sum:
if i < x:
flag = False
if flag:
result.append(cost[i1] + cost[i2] + cost[i3] + cost[i4])
for i1 in range(m):
for i2 in range(i1 + 1, n):
for i3 in range(i2 + 1, n):
for i4 in range(i3 + 1, n):
for i5 in range(i4 + 1, n):
sum = (
np.array(all[i1])
+ np.array(all[i2])
+ np.array(all[i3])
+ np.array(all[i4])
+ np.array(all[i5])
)
flag = True
for i in sum:
if i < x:
flag = False
if flag:
result.append(
cost[i1] + cost[i2] + cost[i3] + cost[i4] + cost[i5]
)
for i1 in range(m):
for i2 in range(i1 + 1, n):
for i3 in range(i2 + 1, n):
for i4 in range(i3 + 1, n):
for i5 in range(i4 + 1, n):
for i6 in range(i5 + 1, n):
sum = (
np.array(all[i1])
+ np.array(all[i2])
+ np.array(all[i3])
+ np.array(all[i4])
+ np.array(all[i5])
+ np.array(all[i6])
)
flag = True
for i in sum:
if i < x:
flag = False
if flag:
result.append(
cost[i1]
+ cost[i2]
+ cost[i3]
+ cost[i4]
+ cost[i5]
+ cost[i6]
)
for i1 in range(m):
for i2 in range(i1 + 1, n):
for i3 in range(i2 + 1, n):
for i4 in range(i3 + 1, n):
for i5 in range(i4 + 1, n):
for i6 in range(i5 + 1, n):
for i7 in range(i6 + 1, n):
sum = (
np.array(all[i1])
+ np.array(all[i2])
+ np.array(all[i3])
+ np.array(all[i4])
+ np.array(all[i5])
+ np.array(all[i6])
+ np.array(all[i7])
)
flag = True
for i in sum:
if i < x:
flag = False
if flag:
result.append(
cost[i1]
+ cost[i2]
+ cost[i3]
+ cost[i4]
+ cost[i5]
+ cost[i6]
+ cost[i7]
)
for i1 in range(m):
for i2 in range(i1 + 1, n):
for i3 in range(i2 + 1, n):
for i4 in range(i3 + 1, n):
for i5 in range(i4 + 1, n):
for i6 in range(i5 + 1, n):
for i7 in range(i6 + 1, n):
sum = (
np.array(all[i1])
+ np.array(all[i2])
+ np.array(all[i3])
+ np.array(all[i4])
+ np.array(all[i5])
+ np.array(all[i6])
+ np.array(all[i7])
)
# print(i1,i2,i3,i4,i5,i6,i7,sum)
flag = True
for i in sum:
if i < x:
flag = False
if flag:
result.append(
cost[i1]
+ cost[i2]
+ cost[i3]
+ cost[i4]
+ cost[i5]
+ cost[i6]
+ cost[i7]
)
if result == []:
print(-1)
else:
print(min(result))
| Takahashi, who is a novice in competitive programming, wants to learn M
algorithms. Initially, his _understanding level_ of each of the M algorithms
is 0.
Takahashi is visiting a bookstore, where he finds N books on algorithms. The
i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he
buys and reads it, his understanding level of the j-th algorithm will increase
by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the
understanding levels of the algorithms.
Takahashi's objective is to make his understanding levels of all the M
algorithms X or higher. Determine whether this objective is achievable. If it
is achievable, find the minimum amount of money needed to achieve it. | [{"input": "3 3 10\n 60 2 2 4\n 70 8 7 9\n 50 2 3 9", "output": "120\n \n\nBuying the second and third books makes his understanding levels of all the\nalgorithms 10 or higher, at the minimum cost possible.\n\n* * *"}, {"input": "3 3 10\n 100 3 1 4\n 100 1 5 9\n 100 2 6 5", "output": "-1\n \n\nBuying all the books is still not enough to make his understanding levels of\nall the algorithms 10 or higher.\n\n* * *"}, {"input": "8 5 22\n 100 3 7 5 3 1\n 164 4 5 2 7 8\n 334 7 2 7 2 9\n 234 4 7 2 8 2\n 541 5 4 3 3 6\n 235 4 8 6 9 7\n 394 3 6 1 6 2\n 872 8 4 3 7 2", "output": "1067"}] |
Print N lines. The i-th line should contain the answer to the problem where
K=i, modulo 924844033.
* * * | s244056761 | Wrong Answer | p03991 | The input is given from Standard Input in the following format:
N
a_1 b_1
a_2 b_2
:
a_{N-1} b_{N-1} | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N = int(readline())
m = map(int, read().split())
AB = zip(m, m)
MOD = 998244353
graph = [[] for _ in range(N + 1)]
for a, b in AB:
graph[a].append(b)
graph[b].append(a)
root = 1
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
x = stack.pop()
order.append(x)
for y in graph[x]:
if y == parent[x]:
continue
parent[y] = x
stack.append(y)
size = [1] * (N + 1) # size of subtree
for v in order[::-1]:
size[parent[v]] += size[v]
P = [0] * N
for s in size[2:]:
P[s] += 1
P[N - s] += 1
class ModArray(np.ndarray):
def __new__(cls, input_array, info=None):
obj = np.asarray(input_array, dtype=np.int64).view(cls)
return obj
@classmethod
def zeros(cls, *args):
obj = np.zeros(*args, dtype=np.int64)
return obj.view(cls)
@classmethod
def ones(cls, *args):
obj = np.ones(*args, dtype=np.int64)
return obj.view(cls)
@classmethod
def arange(cls, *args):
obj = np.arange(*args, dtype=np.int64) % MOD
return obj.view(cls)
@classmethod
def powers(cls, a, N):
B = N.bit_length()
x = cls.ones(1 << B)
for n in range(B):
x[1 << n : 1 << (n + 1)] = x[: 1 << n] * a
a *= a
a %= MOD
return x[:N]
@classmethod
def _set_constant_array(cls, N):
x = cls.arange(N)
x[0] = 1
fact = x.cumprod()
x = cls.arange(N, 0, -1)
x[0] = pow(int(fact[-1]), MOD - 2, MOD)
fact_inv = x.cumprod()[::-1]
inv = cls.zeros(N)
inv[1:N] = fact_inv[1:N] * fact[0 : N - 1]
fact.flags.writeable = False
fact_inv.flags.writeable = False
inv.flags.writeable = False
cls._fact = fact
cls._fact_inv = fact_inv
cls._inverse = inv
@classmethod
def fact(cls, N):
if (getattr(cls, "_fact", None) is None) or len(cls._fact) < N:
cls._set_constant_array(max(N, 10**6))
return cls._fact[:N]
@classmethod
def fact_inv(cls, N):
if (getattr(cls, "_fact", None) is None) or len(cls._fact) < N:
cls._set_constant_array(max(N, 10**6))
return cls._fact_inv[:N]
@classmethod
def inverse(cls, N):
if (getattr(cls, "_fact", None) is None) or len(cls._fact) < N:
cls._set_constant_array(max(N, 10**6))
return cls._inverse[:N]
@classmethod
def convolve_small(cls, f, g):
Lf = len(f)
Lg = len(g)
L = Lf + Lg - 1
if min(Lf, Lg) < 100 or Lf + Lg < 300:
return (np.convolve(f, g) % MOD).view(cls)
else:
fft = np.fft.rfft
ifft = np.fft.irfft
n = 1 << L.bit_length()
return (
np.rint(ifft(fft(f, n) * fft(g, n))[:L]).astype(np.int64) % MOD
).view(cls)
@classmethod
def convolve(cls, f, g, fft_killer=False):
Lf = len(f)
Lg = len(g)
if Lf < Lg:
f, g = g, f
Lf, Lg = Lg, Lf
if Lg <= (1 << 17) or (not fft_killer):
fl = f & (1 << 15) - 1
fh = f >> 15
gl = g & (1 << 15) - 1
gh = g >> 15
x = cls.convolve_small(fl, gl)
z = cls.convolve_small(fh, gh)
y = cls.convolve_small(fl + fh, gl + gh) - x - z
return x + (y << 15) + (z << 30)
g = g.resize(Lf)
n = Lf // 2
fl = f[:n]
fh = f[n:].copy()
gl = g[:n]
gh = g[n:].copy()
x = ModArray.convolve(fl, gl)
z = ModArray.convolve(fh, gh)
fh[: len(fl)] += fl
gh[: len(gl)] += gl
y = ModArray.convolve(fh, gh)
P = x.resize(Lf + Lf)
P[n : n + len(x)] -= x
P[n : n + len(y)] += y
P[n : n + len(z)] -= z
P[n + n : n + n + len(z)] += z
return P[: Lf + Lg - 1]
def print(self, sep=" "):
print(sep.join(self.astype(str)))
def resize(self, N):
L = len(self)
if L >= N:
return self[:N]
A = np.resize(self, N).view(self.__class__)
A[L:] = 0
return A
def diff(self):
return np.diff(self) % MOD
def cumprod(self):
L = len(self)
Lsq = int(L**0.5 + 1)
A = self.resize(Lsq**2).reshape(Lsq, Lsq)
for n in range(1, Lsq):
A[:, n] *= A[:, n - 1]
for n in range(1, Lsq):
A[n] *= A[n - 1, -1]
return A.ravel()[:L]
def __array_wrap__(self, out_arr, context=None):
if out_arr.dtype == np.int64:
if context and context[0] == np.mod:
return out_arr
np.mod(out_arr, MOD, out=out_arr)
return out_arr
else:
return np.asarray(out_arr)
P = ModArray(P)
fact = ModArray.fact(N + 10)
fact_inv = ModArray.fact_inv(N + 10)
Q = ModArray.convolve(P * fact[:N], fact_inv[:N][::-1])[N - 1 :]
Q *= fact_inv[:N]
x = fact[N] * fact_inv[: N + 1] * fact_inv[: N + 1][::-1] * N
x[:-1] -= Q
print("\n".join(x[1:].astype(str)))
| Statement
One day, Takahashi was given the following problem from Aoki:
* You are given a tree with N vertices and an integer K. The vertices are numbered 1 through N. The edges are represented by pairs of integers (a_i, b_i).
* For a set S of vertices in the tree, let f(S) be the minimum number of the vertices in a subtree of the given tree that contains all vertices in S.
* There are  ways to choose K vertices from the trees. For each of them, let S be the set of the chosen vertices, and find the sum of f(S) over all  ways.
* Since the answer may be extremely large, print it modulo 924844033(prime).
Since it was too easy for him, he decided to solve this problem for all K =
1,2,...,N. | [{"input": "3\n 1 2\n 2 3", "output": "3\n 7\n 3\n \n\n\n\nThe diagram above illustrates the case where K=2. The chosen vertices are\ncolored pink, and the subtrees with the minimum number of vertices are\nenclosed by red lines.\n\n* * *"}, {"input": "4\n 1 2\n 1 3\n 1 4", "output": "4\n 15\n 13\n 4\n \n\n* * *"}, {"input": "7\n 1 2\n 2 3\n 2 4\n 4 5\n 4 6\n 6 7", "output": "7\n 67\n 150\n 179\n 122\n 45\n 7"}] |
Print the distance in real number. The output should not contain an absolute
error greater than 10-4. | s544104400 | Accepted | p02379 | Four real numbers x1, y1, x2 and y2 are given in a line. | x, y, p, q = map(float, input().split())
print(((x - p) ** 2 + (y - q) ** 2) ** (1 / 2))
| Distance
Write a program which calculates the distance between two points P1(x1, y1)
and P2(x2, y2). | [{"input": "0 1 1", "output": ".41421356"}] |
Print the distance in real number. The output should not contain an absolute
error greater than 10-4. | s601181762 | Runtime Error | p02379 | Four real numbers x1, y1, x2 and y2 are given in a line. | a, b, c, d = list(map(int, input().split()))
print(((b - a) ** 2 + (c - d) ** 2) ** 0.5)
| Distance
Write a program which calculates the distance between two points P1(x1, y1)
and P2(x2, y2). | [{"input": "0 1 1", "output": ".41421356"}] |
Print the distance in real number. The output should not contain an absolute
error greater than 10-4. | s476832653 | Wrong Answer | p02379 | Four real numbers x1, y1, x2 and y2 are given in a line. | lst = input().split()
x = float(lst[0])
| Distance
Write a program which calculates the distance between two points P1(x1, y1)
and P2(x2, y2). | [{"input": "0 1 1", "output": ".41421356"}] |
Print the distance in real number. The output should not contain an absolute
error greater than 10-4. | s608333011 | Accepted | p02379 | Four real numbers x1, y1, x2 and y2 are given in a line. | a = list(map(float, input().split()))
print((abs(a[0] - a[2]) ** 2 + abs(a[1] - a[3]) ** 2) ** (1 / 2))
| Distance
Write a program which calculates the distance between two points P1(x1, y1)
and P2(x2, y2). | [{"input": "0 1 1", "output": ".41421356"}] |
Print the distance in real number. The output should not contain an absolute
error greater than 10-4. | s166762256 | Accepted | p02379 | Four real numbers x1, y1, x2 and y2 are given in a line. | x, y, x_, y_ = map(float, input().split())
X = abs(x - x_) ** 2
Y = abs(y - y_) ** 2
print("{:.4f}".format((X + Y) ** (1 / 2)))
| Distance
Write a program which calculates the distance between two points P1(x1, y1)
and P2(x2, y2). | [{"input": "0 1 1", "output": ".41421356"}] |
Print the distance in real number. The output should not contain an absolute
error greater than 10-4. | s971753973 | Accepted | p02379 | Four real numbers x1, y1, x2 and y2 are given in a line. | a, b, c, d = list(map(float, input().split()))
print("%.5f" % (((c - a) ** 2 + (b - d) ** 2) ** 0.5))
| Distance
Write a program which calculates the distance between two points P1(x1, y1)
and P2(x2, y2). | [{"input": "0 1 1", "output": ".41421356"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.