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 a positive integer not greater than 10^{18} that is a multiple of X but
not a multiple of Y, or print -1 if it does not exist.
* * * | s064261392 | Runtime Error | p03437 | Input is given from Standard Input in the following format:
X Y | N = int(input())
A, B = [sorted(map(int, input().split())) for _ in range(2)]
print("Yes" if all([a <= b for a, b in zip(A, B)]) else "No")
| Statement
You are given positive integers X and Y. If there exists a positive integer
not greater than 10^{18} that is a multiple of X but not a multiple of Y,
choose one such integer and print it. If it does not exist, print -1. | [{"input": "8 6", "output": "16\n \n\nFor example, 16 is a multiple of 8 but not a multiple of 6.\n\n* * *"}, {"input": "3 3", "output": "-1\n \n\nA multiple of 3 is a multiple of 3."}] |
Print a positive integer not greater than 10^{18} that is a multiple of X but
not a multiple of Y, or print -1 if it does not exist.
* * * | s966358423 | Runtime Error | p03437 | Input is given from Standard Input in the following format:
X Y | x,y = map(int,input().split())
if x%y == 0
print(-1)
else:
print(x)
| Statement
You are given positive integers X and Y. If there exists a positive integer
not greater than 10^{18} that is a multiple of X but not a multiple of Y,
choose one such integer and print it. If it does not exist, print -1. | [{"input": "8 6", "output": "16\n \n\nFor example, 16 is a multiple of 8 but not a multiple of 6.\n\n* * *"}, {"input": "3 3", "output": "-1\n \n\nA multiple of 3 is a multiple of 3."}] |
Print a positive integer not greater than 10^{18} that is a multiple of X but
not a multiple of Y, or print -1 if it does not exist.
* * * | s422404950 | Runtime Error | p03437 | Input is given from Standard Input in the following format:
X Y | #!/usr/bin/env python3
#APC1 A
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
a,b = LI()
if a % b == 0:
print(-1)
tmp = 1
while 1:
if tmp % a == 0 and tmp % != 0:
print(tmp)
quit()
tmp += 1
| Statement
You are given positive integers X and Y. If there exists a positive integer
not greater than 10^{18} that is a multiple of X but not a multiple of Y,
choose one such integer and print it. If it does not exist, print -1. | [{"input": "8 6", "output": "16\n \n\nFor example, 16 is a multiple of 8 but not a multiple of 6.\n\n* * *"}, {"input": "3 3", "output": "-1\n \n\nA multiple of 3 is a multiple of 3."}] |
Print a positive integer not greater than 10^{18} that is a multiple of X but
not a multiple of Y, or print -1 if it does not exist.
* * * | s950577946 | Runtime Error | p03437 | Input is given from Standard Input in the following format:
X Y | import sys
x,y=map(int,input().split())
ans=1
i=1
while ans<=10**18:
ans=i*x
if ans%y!=0
print(ans)
sys.exit()
i+=1
print(-1) | Statement
You are given positive integers X and Y. If there exists a positive integer
not greater than 10^{18} that is a multiple of X but not a multiple of Y,
choose one such integer and print it. If it does not exist, print -1. | [{"input": "8 6", "output": "16\n \n\nFor example, 16 is a multiple of 8 but not a multiple of 6.\n\n* * *"}, {"input": "3 3", "output": "-1\n \n\nA multiple of 3 is a multiple of 3."}] |
Print a positive integer not greater than 10^{18} that is a multiple of X but
not a multiple of Y, or print -1 if it does not exist.
* * * | s585386664 | Runtime Error | p03437 | Input is given from Standard Input in the following format:
X Y | import sys
x,y=map(int,input().split())
ans=1
i=1
while ans<=10**18:
ans=i*x
if ans%y=!0
print(ans)
sys.exit()
i+=1
print(-1)
| Statement
You are given positive integers X and Y. If there exists a positive integer
not greater than 10^{18} that is a multiple of X but not a multiple of Y,
choose one such integer and print it. If it does not exist, print -1. | [{"input": "8 6", "output": "16\n \n\nFor example, 16 is a multiple of 8 but not a multiple of 6.\n\n* * *"}, {"input": "3 3", "output": "-1\n \n\nA multiple of 3 is a multiple of 3."}] |
Print a positive integer not greater than 10^{18} that is a multiple of X but
not a multiple of Y, or print -1 if it does not exist.
* * * | s625522218 | Runtime Error | p03437 | Input is given from Standard Input in the following format:
X Y | a, b = map(int, input().split())
if a%b==0:
print(-1)
else
print(a) | Statement
You are given positive integers X and Y. If there exists a positive integer
not greater than 10^{18} that is a multiple of X but not a multiple of Y,
choose one such integer and print it. If it does not exist, print -1. | [{"input": "8 6", "output": "16\n \n\nFor example, 16 is a multiple of 8 but not a multiple of 6.\n\n* * *"}, {"input": "3 3", "output": "-1\n \n\nA multiple of 3 is a multiple of 3."}] |
Print a positive integer not greater than 10^{18} that is a multiple of X but
not a multiple of Y, or print -1 if it does not exist.
* * * | s245638640 | Runtime Error | p03437 | Input is given from Standard Input in the following format:
X Y | x,y=map(int,input()..split())
if x%y==0:
print(-1)
else:
print(x) | Statement
You are given positive integers X and Y. If there exists a positive integer
not greater than 10^{18} that is a multiple of X but not a multiple of Y,
choose one such integer and print it. If it does not exist, print -1. | [{"input": "8 6", "output": "16\n \n\nFor example, 16 is a multiple of 8 but not a multiple of 6.\n\n* * *"}, {"input": "3 3", "output": "-1\n \n\nA multiple of 3 is a multiple of 3."}] |
Print a positive integer not greater than 10^{18} that is a multiple of X but
not a multiple of Y, or print -1 if it does not exist.
* * * | s423184484 | Runtime Error | p03437 | Input is given from Standard Input in the following format:
X Y | num = input().split(" ")
[i = int(i) for i in num]
if num[0]%num[1]==0:
print("-1")
else:
print(num[0]) | Statement
You are given positive integers X and Y. If there exists a positive integer
not greater than 10^{18} that is a multiple of X but not a multiple of Y,
choose one such integer and print it. If it does not exist, print -1. | [{"input": "8 6", "output": "16\n \n\nFor example, 16 is a multiple of 8 but not a multiple of 6.\n\n* * *"}, {"input": "3 3", "output": "-1\n \n\nA multiple of 3 is a multiple of 3."}] |
Print a positive integer not greater than 10^{18} that is a multiple of X but
not a multiple of Y, or print -1 if it does not exist.
* * * | s120079257 | Runtime Error | p03437 | Input is given from Standard Input in the following format:
X Y | [print(x*(y-1) if y%=x else -1) for x,y in [[int(i) for i in input().split()]]] | Statement
You are given positive integers X and Y. If there exists a positive integer
not greater than 10^{18} that is a multiple of X but not a multiple of Y,
choose one such integer and print it. If it does not exist, print -1. | [{"input": "8 6", "output": "16\n \n\nFor example, 16 is a multiple of 8 but not a multiple of 6.\n\n* * *"}, {"input": "3 3", "output": "-1\n \n\nA multiple of 3 is a multiple of 3."}] |
Print a positive integer not greater than 10^{18} that is a multiple of X but
not a multiple of Y, or print -1 if it does not exist.
* * * | s344525811 | Runtime Error | p03437 | Input is given from Standard Input in the following format:
X Y | x,y=map(int,input().split()
l=[x,y]
l=sorted(l)
if l[1]%l[0]==0:
print(-1)
else:
print(x) | Statement
You are given positive integers X and Y. If there exists a positive integer
not greater than 10^{18} that is a multiple of X but not a multiple of Y,
choose one such integer and print it. If it does not exist, print -1. | [{"input": "8 6", "output": "16\n \n\nFor example, 16 is a multiple of 8 but not a multiple of 6.\n\n* * *"}, {"input": "3 3", "output": "-1\n \n\nA multiple of 3 is a multiple of 3."}] |
Print a positive integer not greater than 10^{18} that is a multiple of X but
not a multiple of Y, or print -1 if it does not exist.
* * * | s723551720 | Wrong Answer | p03437 | Input is given from Standard Input in the following format:
X Y | [print(-1 if x == y else x * (y - 1)) for x, y in [[int(i) for i in input().split()]]]
| Statement
You are given positive integers X and Y. If there exists a positive integer
not greater than 10^{18} that is a multiple of X but not a multiple of Y,
choose one such integer and print it. If it does not exist, print -1. | [{"input": "8 6", "output": "16\n \n\nFor example, 16 is a multiple of 8 but not a multiple of 6.\n\n* * *"}, {"input": "3 3", "output": "-1\n \n\nA multiple of 3 is a multiple of 3."}] |
Print a positive integer not greater than 10^{18} that is a multiple of X but
not a multiple of Y, or print -1 if it does not exist.
* * * | s584369306 | Runtime Error | p03437 | Input is given from Standard Input in the following format:
X Y | import math
input = str(input()).split(" ")
for index in range(len(input)):
input[index] = int(input[index])
x = input[0]
y = input[1]
def ahaha(x, y):
for index in range(1, min(abs(y), math.floor((10**(18))/x)):
if (x * index % y != 0):
return x * index
return -1
print(ahaha(x,y))
| Statement
You are given positive integers X and Y. If there exists a positive integer
not greater than 10^{18} that is a multiple of X but not a multiple of Y,
choose one such integer and print it. If it does not exist, print -1. | [{"input": "8 6", "output": "16\n \n\nFor example, 16 is a multiple of 8 but not a multiple of 6.\n\n* * *"}, {"input": "3 3", "output": "-1\n \n\nA multiple of 3 is a multiple of 3."}] |
Print a positive integer not greater than 10^{18} that is a multiple of X but
not a multiple of Y, or print -1 if it does not exist.
* * * | s690875354 | Runtime Error | p03437 | Input is given from Standard Input in the following format:
X Y |
x, y = map(int, input().split())
i = 1
if x % y == 0;
print(-1)
else:
for i in range(10 ** 18 + 1):
if (i * x) % y != 0:
print(i * x)
break
else:
continue
| Statement
You are given positive integers X and Y. If there exists a positive integer
not greater than 10^{18} that is a multiple of X but not a multiple of Y,
choose one such integer and print it. If it does not exist, print -1. | [{"input": "8 6", "output": "16\n \n\nFor example, 16 is a multiple of 8 but not a multiple of 6.\n\n* * *"}, {"input": "3 3", "output": "-1\n \n\nA multiple of 3 is a multiple of 3."}] |
Print the minimum possible total number of votes obtained by Takahashi and
Aoki when AtCoDeer checked the report for the N-th time.
* * * | s171197891 | Runtime Error | p03964 | The input is given from Standard Input in the following format:
N
T_1 A_1
T_2 A_2
:
T_N A_N | import math
n = int(input())
i = 0
list = []
while i < n:
list.append(input().split())
i += 1
h = 0
th = 1.0
ah = 1.0
while h < n:
listh = list[h]
x = int(listh[0])
y = int(listh[1])
m = max(math.ceil(th/x)),math.ceil(ah/y)))
th = m*x
ah = m*y
h += 1
print(long(th+ah)) | Statement
AtCoDeer the deer is seeing a quick report of election results on TV. Two
candidates are standing for the election: Takahashi and Aoki. The report shows
the ratio of the current numbers of votes the two candidates have obtained,
but not the actual numbers of votes. AtCoDeer has checked the report N times,
and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is
known that each candidate had at least one vote when he checked the report for
the first time.
Find the minimum possible total number of votes obtained by the two candidates
when he checked the report for the N-th time. It can be assumed that the
number of votes obtained by each candidate never decreases. | [{"input": "3\n 2 3\n 1 1\n 3 2", "output": "10\n \n\nWhen the numbers of votes obtained by the two candidates change as 2,3 \u2192 3,3 \u2192\n6,4, the total number of votes at the end is 10, which is the minimum possible\nnumber.\n\n* * *"}, {"input": "4\n 1 1\n 1 1\n 1 5\n 1 100", "output": "101\n \n\nIt is possible that neither candidate obtained a vote between the moment when\nhe checked the report, and the moment when he checked it for the next time.\n\n* * *"}, {"input": "5\n 3 10\n 48 17\n 31 199\n 231 23\n 3 2", "output": "6930"}] |
Print the minimum possible total number of votes obtained by Takahashi and
Aoki when AtCoDeer checked the report for the N-th time.
* * * | s429436095 | Runtime Error | p03964 | The input is given from Standard Input in the following format:
N
T_1 A_1
T_2 A_2
:
T_N A_N | import math
N = input()
t = []
a = []
for i in range(int(N)):
t_n, a_n = input().split()
t.append(int(t_n))
a.append(int(a_n))
ma = 0
t_prev = 0
a_prev = 0
t_ans = 0
a_ans = 0
for t_n, a_n in zip(t, a):
summ = t_n + a_n
summ_cp = summ
#i = 0
#while 1:
# i += 1
# summ = summ_cp * i
# if summ >= ma and ((t_n*i) >= t_prev) and ((a_n*i) >= a_prev):
# ma = summ
# break
#summ = summ_cp * i
k = max(math.ceil(t_ans/t_n), math.ceil(a_ans/a_n))
if not k:
k = 1
t_ans = k*t_n
a_ans = k*a_n
print(float((t_ans+a_ans))
| Statement
AtCoDeer the deer is seeing a quick report of election results on TV. Two
candidates are standing for the election: Takahashi and Aoki. The report shows
the ratio of the current numbers of votes the two candidates have obtained,
but not the actual numbers of votes. AtCoDeer has checked the report N times,
and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is
known that each candidate had at least one vote when he checked the report for
the first time.
Find the minimum possible total number of votes obtained by the two candidates
when he checked the report for the N-th time. It can be assumed that the
number of votes obtained by each candidate never decreases. | [{"input": "3\n 2 3\n 1 1\n 3 2", "output": "10\n \n\nWhen the numbers of votes obtained by the two candidates change as 2,3 \u2192 3,3 \u2192\n6,4, the total number of votes at the end is 10, which is the minimum possible\nnumber.\n\n* * *"}, {"input": "4\n 1 1\n 1 1\n 1 5\n 1 100", "output": "101\n \n\nIt is possible that neither candidate obtained a vote between the moment when\nhe checked the report, and the moment when he checked it for the next time.\n\n* * *"}, {"input": "5\n 3 10\n 48 17\n 31 199\n 231 23\n 3 2", "output": "6930"}] |
Print the minimum possible total number of votes obtained by Takahashi and
Aoki when AtCoDeer checked the report for the N-th time.
* * * | s205226076 | Accepted | p03964 | The input is given from Standard Input in the following format:
N
T_1 A_1
T_2 A_2
:
T_N A_N | N = int(input())
li = []
for i in range(N):
li.append(list(map(int, input().split())))
HYOU = li[0]
def f(a, b):
syou = b // a
amari = b % a
if amari == 0:
c = syou
else:
c = syou + 1
return c
for i in range(N - 1):
if li[i][0] <= li[i + 1][0] and li[i][1] <= li[i + 1][1]:
HYOU = li[i + 1]
# print(HYOU)
elif li[i][0] <= li[i + 1][0] and li[i][1] > li[i + 1][1]:
c = f(li[i + 1][1], li[i][1])
li[i + 1] = [li[i + 1][0] * c, li[i + 1][1] * c]
HYOU = li[i + 1]
# print("これ")
# print(HYOU)
elif li[i][0] > li[i + 1][0] and li[i][1] <= li[i + 1][1]:
c = f(li[i + 1][0], li[i][0])
li[i + 1] = [li[i + 1][0] * c, li[i + 1][1] * c]
HYOU = li[i + 1]
# print(HYOU)
else:
c1 = f(li[i + 1][1], li[i][1])
# print("c1は" + str(c1))
hyou1 = [li[i + 1][0] * c1, li[i + 1][1] * c1]
# print("hyou1は" + str(hyou1))
c2 = f(li[i + 1][0], li[i][0])
# print("c2は" + str(c2))
hyou2 = [li[i + 1][0] * c2, li[i + 1][1] * c2]
# print("hyou2は" + str(hyou2))
if hyou1[0] <= hyou2[0] and hyou1[0] >= li[i][0] and hyou1[1] >= li[i][1]:
li[i + 1] = hyou1
HYOU = li[i + 1]
# print(HYOU)
elif hyou2[0] <= hyou1[0] and hyou2[0] >= li[i][0] and hyou2[1] >= li[i][1]:
li[i + 1] = hyou2
HYOU = li[i + 1]
# print(HYOU)
elif hyou1[0] > hyou2[0] and hyou1[0] >= li[i][0] and hyou1[1] >= li[i][1]:
li[i + 1] = hyou1
HYOU = li[i + 1]
# print(HYOU)
elif hyou2[0] > hyou1[0] and hyou2[0] >= li[i][0] and hyou2[1] >= li[i][1]:
li[i + 1] = hyou2
HYOU = li[i + 1]
# print(HYOU)
print(sum(HYOU))
| Statement
AtCoDeer the deer is seeing a quick report of election results on TV. Two
candidates are standing for the election: Takahashi and Aoki. The report shows
the ratio of the current numbers of votes the two candidates have obtained,
but not the actual numbers of votes. AtCoDeer has checked the report N times,
and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is
known that each candidate had at least one vote when he checked the report for
the first time.
Find the minimum possible total number of votes obtained by the two candidates
when he checked the report for the N-th time. It can be assumed that the
number of votes obtained by each candidate never decreases. | [{"input": "3\n 2 3\n 1 1\n 3 2", "output": "10\n \n\nWhen the numbers of votes obtained by the two candidates change as 2,3 \u2192 3,3 \u2192\n6,4, the total number of votes at the end is 10, which is the minimum possible\nnumber.\n\n* * *"}, {"input": "4\n 1 1\n 1 1\n 1 5\n 1 100", "output": "101\n \n\nIt is possible that neither candidate obtained a vote between the moment when\nhe checked the report, and the moment when he checked it for the next time.\n\n* * *"}, {"input": "5\n 3 10\n 48 17\n 31 199\n 231 23\n 3 2", "output": "6930"}] |
Print the minimum possible total number of votes obtained by Takahashi and
Aoki when AtCoDeer checked the report for the N-th time.
* * * | s927081377 | Accepted | p03964 | The input is given from Standard Input in the following format:
N
T_1 A_1
T_2 A_2
:
T_N A_N | N = int(input())
vote = [1, 1]
for i in range(N):
ratio = list(map(int, input().split()))
for j in range(2):
while vote[j] % ratio[j] != 0:
vote[j] += 1
if vote[0] * ratio[1] < vote[1] * ratio[0]:
vote[0] = vote[1] // ratio[1] * ratio[0]
if vote[0] * ratio[1] > vote[1] * ratio[0]:
vote[1] = vote[0] // ratio[0] * ratio[1]
print(vote[0] + vote[1])
| Statement
AtCoDeer the deer is seeing a quick report of election results on TV. Two
candidates are standing for the election: Takahashi and Aoki. The report shows
the ratio of the current numbers of votes the two candidates have obtained,
but not the actual numbers of votes. AtCoDeer has checked the report N times,
and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is
known that each candidate had at least one vote when he checked the report for
the first time.
Find the minimum possible total number of votes obtained by the two candidates
when he checked the report for the N-th time. It can be assumed that the
number of votes obtained by each candidate never decreases. | [{"input": "3\n 2 3\n 1 1\n 3 2", "output": "10\n \n\nWhen the numbers of votes obtained by the two candidates change as 2,3 \u2192 3,3 \u2192\n6,4, the total number of votes at the end is 10, which is the minimum possible\nnumber.\n\n* * *"}, {"input": "4\n 1 1\n 1 1\n 1 5\n 1 100", "output": "101\n \n\nIt is possible that neither candidate obtained a vote between the moment when\nhe checked the report, and the moment when he checked it for the next time.\n\n* * *"}, {"input": "5\n 3 10\n 48 17\n 31 199\n 231 23\n 3 2", "output": "6930"}] |
Print the minimum possible total number of votes obtained by Takahashi and
Aoki when AtCoDeer checked the report for the N-th time.
* * * | s463055711 | Runtime Error | p03964 | The input is given from Standard Input in the following format:
N
T_1 A_1
T_2 A_2
:
T_N A_N | n = int(input())
vote = 0
tt = 0
aa = 0
for i in range(n):
t, a = map(int,input().split())
if (tt < t and aa = a) or (tt = t and aa < a) or (tt< t and aa <a):
tt = t
aa = a
vote = t + a
else:
count = 1
s = t + a
while vote > s:
count = count + 1
s = s * count
vote = s
tt = count * t
ss = count * a
print(vote) | Statement
AtCoDeer the deer is seeing a quick report of election results on TV. Two
candidates are standing for the election: Takahashi and Aoki. The report shows
the ratio of the current numbers of votes the two candidates have obtained,
but not the actual numbers of votes. AtCoDeer has checked the report N times,
and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is
known that each candidate had at least one vote when he checked the report for
the first time.
Find the minimum possible total number of votes obtained by the two candidates
when he checked the report for the N-th time. It can be assumed that the
number of votes obtained by each candidate never decreases. | [{"input": "3\n 2 3\n 1 1\n 3 2", "output": "10\n \n\nWhen the numbers of votes obtained by the two candidates change as 2,3 \u2192 3,3 \u2192\n6,4, the total number of votes at the end is 10, which is the minimum possible\nnumber.\n\n* * *"}, {"input": "4\n 1 1\n 1 1\n 1 5\n 1 100", "output": "101\n \n\nIt is possible that neither candidate obtained a vote between the moment when\nhe checked the report, and the moment when he checked it for the next time.\n\n* * *"}, {"input": "5\n 3 10\n 48 17\n 31 199\n 231 23\n 3 2", "output": "6930"}] |
Print the minimum possible total number of votes obtained by Takahashi and
Aoki when AtCoDeer checked the report for the N-th time.
* * * | s385447184 | Runtime Error | p03964 | The input is given from Standard Input in the following format:
N
T_1 A_1
T_2 A_2
:
T_N A_N | #include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
typedef long long ll;
const ll INF = 1e18 + 1;
const ll MOD = 1e9 + 7;
template<typename T> T lminimum(const std::vector< T >& v) {return *std::min_element(v.begin(), v.end());}
template<typename T> T lmaximum(const std::vector< T >& v) {return *std::max_element(v.begin(), v.end());}
template<typename T> void lunique(std::vector< T >& v) {v.erase(std::unique(v.begin(), v.end()), v.end());}
template<typename T> void lsort(std::vector< T >& v) {std::sort(v.begin(), v.end());}
template<typename T> void lgreatersort(std::vector< T >& v) {std::sort(v.begin(), v.end(), std::greater<>());}
template<typename T> bool lnext_permutation(std::vector< T >& v) {return std::next_permutation(v.begin(), v.end());}
int main(int argc, char* argv[])
{
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
ll N;
std::cin >> N;
std::vector< ll > va(N, 0LL);
std::vector< ll > vb(N, 0LL);
for (ll i = 0; i < N; i++) {
std::cin >> va[i] >> vb[i];
}
ll a = 1;
ll b = 1;
for (ll i = 0; i < N; i++) {
ll n = std::max((a + va[i] - 1) / va[i], (b + vb[i] - 1) / vb[i]);
a = n * va[i];
b = n * vb[i];
//std::cout << a << " " << b << std::endl;
}
std::cout << a + b << std::endl;
return 0;
}
| Statement
AtCoDeer the deer is seeing a quick report of election results on TV. Two
candidates are standing for the election: Takahashi and Aoki. The report shows
the ratio of the current numbers of votes the two candidates have obtained,
but not the actual numbers of votes. AtCoDeer has checked the report N times,
and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is
known that each candidate had at least one vote when he checked the report for
the first time.
Find the minimum possible total number of votes obtained by the two candidates
when he checked the report for the N-th time. It can be assumed that the
number of votes obtained by each candidate never decreases. | [{"input": "3\n 2 3\n 1 1\n 3 2", "output": "10\n \n\nWhen the numbers of votes obtained by the two candidates change as 2,3 \u2192 3,3 \u2192\n6,4, the total number of votes at the end is 10, which is the minimum possible\nnumber.\n\n* * *"}, {"input": "4\n 1 1\n 1 1\n 1 5\n 1 100", "output": "101\n \n\nIt is possible that neither candidate obtained a vote between the moment when\nhe checked the report, and the moment when he checked it for the next time.\n\n* * *"}, {"input": "5\n 3 10\n 48 17\n 31 199\n 231 23\n 3 2", "output": "6930"}] |
Print the minimum possible total number of votes obtained by Takahashi and
Aoki when AtCoDeer checked the report for the N-th time.
* * * | s190897837 | Runtime Error | p03964 | The input is given from Standard Input in the following format:
N
T_1 A_1
T_2 A_2
:
T_N A_N | from sys import stdin
import math
N = int(stdin.readline().rstrip())
t, a = [int(x) for x in stdin.readline().rstrip().split()]
for _ in range(N - 1):
T, A = [int(x) for x in stdin.readline().rstrip().split()]
int(n) = max(math.ceil(t / T), math.ceil(a / A))
t = n * T
a = n * A
print(t + a)
| Statement
AtCoDeer the deer is seeing a quick report of election results on TV. Two
candidates are standing for the election: Takahashi and Aoki. The report shows
the ratio of the current numbers of votes the two candidates have obtained,
but not the actual numbers of votes. AtCoDeer has checked the report N times,
and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is
known that each candidate had at least one vote when he checked the report for
the first time.
Find the minimum possible total number of votes obtained by the two candidates
when he checked the report for the N-th time. It can be assumed that the
number of votes obtained by each candidate never decreases. | [{"input": "3\n 2 3\n 1 1\n 3 2", "output": "10\n \n\nWhen the numbers of votes obtained by the two candidates change as 2,3 \u2192 3,3 \u2192\n6,4, the total number of votes at the end is 10, which is the minimum possible\nnumber.\n\n* * *"}, {"input": "4\n 1 1\n 1 1\n 1 5\n 1 100", "output": "101\n \n\nIt is possible that neither candidate obtained a vote between the moment when\nhe checked the report, and the moment when he checked it for the next time.\n\n* * *"}, {"input": "5\n 3 10\n 48 17\n 31 199\n 231 23\n 3 2", "output": "6930"}] |
Print the minimum possible total number of votes obtained by Takahashi and
Aoki when AtCoDeer checked the report for the N-th time.
* * * | s245190940 | Wrong Answer | p03964 | The input is given from Standard Input in the following format:
N
T_1 A_1
T_2 A_2
:
T_N A_N | n = int(input())
l = 0
p = 0
for i in range(1, n + 1):
b, m = map(int, input().split())
l = (l // (b + m) + 1) * (b + m)
print(l)
| Statement
AtCoDeer the deer is seeing a quick report of election results on TV. Two
candidates are standing for the election: Takahashi and Aoki. The report shows
the ratio of the current numbers of votes the two candidates have obtained,
but not the actual numbers of votes. AtCoDeer has checked the report N times,
and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is
known that each candidate had at least one vote when he checked the report for
the first time.
Find the minimum possible total number of votes obtained by the two candidates
when he checked the report for the N-th time. It can be assumed that the
number of votes obtained by each candidate never decreases. | [{"input": "3\n 2 3\n 1 1\n 3 2", "output": "10\n \n\nWhen the numbers of votes obtained by the two candidates change as 2,3 \u2192 3,3 \u2192\n6,4, the total number of votes at the end is 10, which is the minimum possible\nnumber.\n\n* * *"}, {"input": "4\n 1 1\n 1 1\n 1 5\n 1 100", "output": "101\n \n\nIt is possible that neither candidate obtained a vote between the moment when\nhe checked the report, and the moment when he checked it for the next time.\n\n* * *"}, {"input": "5\n 3 10\n 48 17\n 31 199\n 231 23\n 3 2", "output": "6930"}] |
Print the minimum possible total number of votes obtained by Takahashi and
Aoki when AtCoDeer checked the report for the N-th time.
* * * | s842110578 | Wrong Answer | p03964 | The input is given from Standard Input in the following format:
N
T_1 A_1
T_2 A_2
:
T_N A_N | N = int(input())
min = 0
pro = [1, 1]
for i in range(N):
in_list = list(map(int, input().split()))
temp = in_list[0] + in_list[1]
multi = int(max(pro[0] / in_list[0], pro[1] / in_list[1], min / temp))
multi += 1
if (
max(
(pro[0] - in_list[0] * (multi - 1)),
(pro[1] - in_list[1] * (multi - 1)),
(min - temp * (multi - 1)),
)
<= 0
):
multi -= 1
min = (multi) * temp
pro[0] = in_list[0] * (multi)
pro[1] = in_list[1] * (multi)
else:
min = (multi) * temp
pro[0] = in_list[0] * (multi)
pro[1] = in_list[1] * (multi)
print(min)
| Statement
AtCoDeer the deer is seeing a quick report of election results on TV. Two
candidates are standing for the election: Takahashi and Aoki. The report shows
the ratio of the current numbers of votes the two candidates have obtained,
but not the actual numbers of votes. AtCoDeer has checked the report N times,
and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is
known that each candidate had at least one vote when he checked the report for
the first time.
Find the minimum possible total number of votes obtained by the two candidates
when he checked the report for the N-th time. It can be assumed that the
number of votes obtained by each candidate never decreases. | [{"input": "3\n 2 3\n 1 1\n 3 2", "output": "10\n \n\nWhen the numbers of votes obtained by the two candidates change as 2,3 \u2192 3,3 \u2192\n6,4, the total number of votes at the end is 10, which is the minimum possible\nnumber.\n\n* * *"}, {"input": "4\n 1 1\n 1 1\n 1 5\n 1 100", "output": "101\n \n\nIt is possible that neither candidate obtained a vote between the moment when\nhe checked the report, and the moment when he checked it for the next time.\n\n* * *"}, {"input": "5\n 3 10\n 48 17\n 31 199\n 231 23\n 3 2", "output": "6930"}] |
Print the minimum possible total number of votes obtained by Takahashi and
Aoki when AtCoDeer checked the report for the N-th time.
* * * | s223291921 | Runtime Error | p03964 | The input is given from Standard Input in the following format:
N
T_1 A_1
T_2 A_2
:
T_N A_N | import math
from decimal import Decimal
N = int(input())
T, A = [int(x) for x in input().split()]
for i in range(1,N):
T2, A2 = [int(x) for x in input().split()]
n = max(math.ceil(Decimal(T)/Decimal(T2)),math.ceil(Decimal(A)/Decimal(A2))
T = T2*n
A = A2*n
print(T + A) | Statement
AtCoDeer the deer is seeing a quick report of election results on TV. Two
candidates are standing for the election: Takahashi and Aoki. The report shows
the ratio of the current numbers of votes the two candidates have obtained,
but not the actual numbers of votes. AtCoDeer has checked the report N times,
and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is
known that each candidate had at least one vote when he checked the report for
the first time.
Find the minimum possible total number of votes obtained by the two candidates
when he checked the report for the N-th time. It can be assumed that the
number of votes obtained by each candidate never decreases. | [{"input": "3\n 2 3\n 1 1\n 3 2", "output": "10\n \n\nWhen the numbers of votes obtained by the two candidates change as 2,3 \u2192 3,3 \u2192\n6,4, the total number of votes at the end is 10, which is the minimum possible\nnumber.\n\n* * *"}, {"input": "4\n 1 1\n 1 1\n 1 5\n 1 100", "output": "101\n \n\nIt is possible that neither candidate obtained a vote between the moment when\nhe checked the report, and the moment when he checked it for the next time.\n\n* * *"}, {"input": "5\n 3 10\n 48 17\n 31 199\n 231 23\n 3 2", "output": "6930"}] |
Print the minimum possible total number of votes obtained by Takahashi and
Aoki when AtCoDeer checked the report for the N-th time.
* * * | s388317344 | Accepted | p03964 | The input is given from Standard Input in the following format:
N
T_1 A_1
T_2 A_2
:
T_N A_N | N = int(input())
R = [list(map(int, input().split())) for _ in range(N)]
T = R[0][0]
A = R[0][1]
for r in R[1:]:
i = T // r[0]
if T % r[0] != 0:
i += 1
j = A // r[1]
if A % r[1] != 0:
j += 1
T = r[0] * max(i, j)
A = r[1] * max(i, j)
print(T + A)
| Statement
AtCoDeer the deer is seeing a quick report of election results on TV. Two
candidates are standing for the election: Takahashi and Aoki. The report shows
the ratio of the current numbers of votes the two candidates have obtained,
but not the actual numbers of votes. AtCoDeer has checked the report N times,
and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is
known that each candidate had at least one vote when he checked the report for
the first time.
Find the minimum possible total number of votes obtained by the two candidates
when he checked the report for the N-th time. It can be assumed that the
number of votes obtained by each candidate never decreases. | [{"input": "3\n 2 3\n 1 1\n 3 2", "output": "10\n \n\nWhen the numbers of votes obtained by the two candidates change as 2,3 \u2192 3,3 \u2192\n6,4, the total number of votes at the end is 10, which is the minimum possible\nnumber.\n\n* * *"}, {"input": "4\n 1 1\n 1 1\n 1 5\n 1 100", "output": "101\n \n\nIt is possible that neither candidate obtained a vote between the moment when\nhe checked the report, and the moment when he checked it for the next time.\n\n* * *"}, {"input": "5\n 3 10\n 48 17\n 31 199\n 231 23\n 3 2", "output": "6930"}] |
Print the minimum possible total number of votes obtained by Takahashi and
Aoki when AtCoDeer checked the report for the N-th time.
* * * | s695766485 | Accepted | p03964 | The input is given from Standard Input in the following format:
N
T_1 A_1
T_2 A_2
:
T_N A_N | N = int(input())
table = [[int(i) for i in input().split()] for j in range(0, N)]
for i in range(0, N - 1):
a = table[i][0] // table[i + 1][0]
A = table[i][0] % table[i + 1][0]
b = table[i][1] // table[i + 1][1]
B = table[i][1] % table[i + 1][1]
if a > b and A == 0:
table[i + 1][0] = a * table[i + 1][0]
table[i + 1][1] = a * table[i + 1][1]
elif a > b and not A == 0:
table[i + 1][0] = (a + 1) * table[i + 1][0]
table[i + 1][1] = (a + 1) * table[i + 1][1]
elif a < b and B == 0:
table[i + 1][0] = b * table[i + 1][0]
table[i + 1][1] = b * table[i + 1][1]
elif a < b and not B == 0:
table[i + 1][0] = (b + 1) * table[i + 1][0]
table[i + 1][1] = (b + 1) * table[i + 1][1]
elif a == b and A == 0 and B == 0:
table[i + 1][0] = a * table[i + 1][0]
table[i + 1][1] = a * table[i + 1][1]
elif a == b and not A == 0 and B == 0:
table[i + 1][0] = (a + 1) * table[i + 1][0]
table[i + 1][1] = (a + 1) * table[i + 1][1]
elif a == b and not B == 0 and A == 0:
table[i + 1][0] = (a + 1) * table[i + 1][0]
table[i + 1][1] = (a + 1) * table[i + 1][1]
elif a == b and not B == 0 and not A == 0:
table[i + 1][0] = (a + 1) * table[i + 1][0]
table[i + 1][1] = (a + 1) * table[i + 1][1]
print(table[N - 1][0] + table[N - 1][1])
| Statement
AtCoDeer the deer is seeing a quick report of election results on TV. Two
candidates are standing for the election: Takahashi and Aoki. The report shows
the ratio of the current numbers of votes the two candidates have obtained,
but not the actual numbers of votes. AtCoDeer has checked the report N times,
and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is
known that each candidate had at least one vote when he checked the report for
the first time.
Find the minimum possible total number of votes obtained by the two candidates
when he checked the report for the N-th time. It can be assumed that the
number of votes obtained by each candidate never decreases. | [{"input": "3\n 2 3\n 1 1\n 3 2", "output": "10\n \n\nWhen the numbers of votes obtained by the two candidates change as 2,3 \u2192 3,3 \u2192\n6,4, the total number of votes at the end is 10, which is the minimum possible\nnumber.\n\n* * *"}, {"input": "4\n 1 1\n 1 1\n 1 5\n 1 100", "output": "101\n \n\nIt is possible that neither candidate obtained a vote between the moment when\nhe checked the report, and the moment when he checked it for the next time.\n\n* * *"}, {"input": "5\n 3 10\n 48 17\n 31 199\n 231 23\n 3 2", "output": "6930"}] |
Print the minimum possible total number of votes obtained by Takahashi and
Aoki when AtCoDeer checked the report for the N-th time.
* * * | s161241015 | Wrong Answer | p03964 | The input is given from Standard Input in the following format:
N
T_1 A_1
T_2 A_2
:
T_N A_N | def yakusuu(num):
value = 2
_lst = []
print(num)
while 1:
if num == 1:
break
while num % value == 0:
num = int(num / value)
if value not in _lst:
_lst.append(value)
value += 1
return _lst
def subtract_list(lst1, lst2):
lst = lst1.copy()
for element in lst2:
if element in lst:
lst.remove(element)
return lst
def seki_list(lst):
value = 1
for i in lst:
value *= i
return value
N = int(input())
data = [list(map(int, input().split())) for i in range(N)]
hyou = [data[0][0], data[0][1]]
print("======")
for i in range(N - 1):
if hyou[0] <= data[i + 1][0] and hyou[1] <= data[i + 1][1]:
hyou[0] = data[i + 1][0]
hyou[1] = data[i + 1][1]
elif hyou[0] > data[i + 1][0] and hyou[1] > data[i + 1][1]:
div = max(int(hyou[0] / data[i + 1][0]), int(hyou[1] / data[i + 1][1]))
hyou[0] = data[i + 1][0] * div
hyou[1] = data[i + 1][1] * div
elif hyou[0] > data[i + 1][0] and hyou[1] <= data[i + 1][1]:
_subtract_list = subtract_list(yakusuu(data[i + 1][0]), yakusuu(hyou[0]))
_seki = seki_list(_subtract_list)
hyou[0] = _seki * data[i + 1][0]
hyou[1] = _seki * data[i + 1][1]
elif hyou[0] <= data[i + 1][0] and hyou[1] > data[i + 1][1]:
_subtract_list = subtract_list(yakusuu(data[i + 1][1]), yakusuu(hyou[1]))
_seki = seki_list(_subtract_list)
hyou[0] = _seki * data[i + 1][0]
hyou[1] = _seki * data[i + 1][1]
# print(hyou,div)
print(sum(hyou))
| Statement
AtCoDeer the deer is seeing a quick report of election results on TV. Two
candidates are standing for the election: Takahashi and Aoki. The report shows
the ratio of the current numbers of votes the two candidates have obtained,
but not the actual numbers of votes. AtCoDeer has checked the report N times,
and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is
known that each candidate had at least one vote when he checked the report for
the first time.
Find the minimum possible total number of votes obtained by the two candidates
when he checked the report for the N-th time. It can be assumed that the
number of votes obtained by each candidate never decreases. | [{"input": "3\n 2 3\n 1 1\n 3 2", "output": "10\n \n\nWhen the numbers of votes obtained by the two candidates change as 2,3 \u2192 3,3 \u2192\n6,4, the total number of votes at the end is 10, which is the minimum possible\nnumber.\n\n* * *"}, {"input": "4\n 1 1\n 1 1\n 1 5\n 1 100", "output": "101\n \n\nIt is possible that neither candidate obtained a vote between the moment when\nhe checked the report, and the moment when he checked it for the next time.\n\n* * *"}, {"input": "5\n 3 10\n 48 17\n 31 199\n 231 23\n 3 2", "output": "6930"}] |
Print the minimum possible total number of votes obtained by Takahashi and
Aoki when AtCoDeer checked the report for the N-th time.
* * * | s703774145 | Wrong Answer | p03964 | The input is given from Standard Input in the following format:
N
T_1 A_1
T_2 A_2
:
T_N A_N | n = int(input())
votelist = [input().split() for i in range(n)]
for j in range(n):
votelist[j] = [int(k) for k in votelist[j]]
for l in range(n - 1):
if votelist[l][0] > votelist[l + 1][0] or votelist[l][1] > votelist[l + 1][1]:
x = max(
votelist[l][0] // votelist[l + 1][0], votelist[l][1] // votelist[l + 1][1]
)
if x != max(
votelist[l][0] / votelist[l + 1][0], votelist[l][1] / votelist[l + 1][1]
):
x += 1
else:
x = 1
votelist[l + 1] = [m * x for m in votelist[l + 1]]
print(sum(votelist[n - 1]))
| Statement
AtCoDeer the deer is seeing a quick report of election results on TV. Two
candidates are standing for the election: Takahashi and Aoki. The report shows
the ratio of the current numbers of votes the two candidates have obtained,
but not the actual numbers of votes. AtCoDeer has checked the report N times,
and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is
known that each candidate had at least one vote when he checked the report for
the first time.
Find the minimum possible total number of votes obtained by the two candidates
when he checked the report for the N-th time. It can be assumed that the
number of votes obtained by each candidate never decreases. | [{"input": "3\n 2 3\n 1 1\n 3 2", "output": "10\n \n\nWhen the numbers of votes obtained by the two candidates change as 2,3 \u2192 3,3 \u2192\n6,4, the total number of votes at the end is 10, which is the minimum possible\nnumber.\n\n* * *"}, {"input": "4\n 1 1\n 1 1\n 1 5\n 1 100", "output": "101\n \n\nIt is possible that neither candidate obtained a vote between the moment when\nhe checked the report, and the moment when he checked it for the next time.\n\n* * *"}, {"input": "5\n 3 10\n 48 17\n 31 199\n 231 23\n 3 2", "output": "6930"}] |
Print a string as stated in Problem Statement.
* * * | s303471834 | Wrong Answer | p02676 | Input is given from Standard Input in the following format:
K
S | K = int(input())
N = list(input())
# print(K,N)
ans = []
if len(N) > K:
for i in range(len(N) - K):
# print(i,len(N))
N.pop(-1)
print("".join(N))
| Statement
We have a string S consisting of lowercase English letters.
If the length of S is at most K, print S without change.
If the length of S exceeds K, extract the first K characters in S, append
`...` to the end of them, and print the result. | [{"input": "7\n nikoandsolstice", "output": "nikoand...\n \n\n`nikoandsolstice` has a length of 15, which exceeds K=7.\n\nWe should extract the first 7 characters in this string, append `...` to the\nend of them, and print the result `nikoand...`.\n\n* * *"}, {"input": "40\n ferelibenterhominesidquodvoluntcredunt", "output": "ferelibenterhominesidquodvoluntcredunt\n \n\nThe famous quote from Gaius Julius Caesar."}] |
Print a string as stated in Problem Statement.
* * * | s508909793 | Runtime Error | p02676 | Input is given from Standard Input in the following format:
K
S | def convert(S):
str1 = "" # initialization of string to ""
return str1.join(S) # using join function join the list s by
# separating words by str1
K = int(input()) # take K from user
readtext = str(input()) # take the input string
S = list(readtext) # split the string into charactrers and put them to list
list1 = list() # list 1
for i in range(0, K): # for looop to append the charachters to the new list
a = S[i]
list1.append(a) # appending the charachters to the list
if len(list1) > K: # condition when number of charachters is big than K
b = "..."
list1.append(b) # append the 3 dots
print(convert(list1)) # convert the list of characters back to the string format
| Statement
We have a string S consisting of lowercase English letters.
If the length of S is at most K, print S without change.
If the length of S exceeds K, extract the first K characters in S, append
`...` to the end of them, and print the result. | [{"input": "7\n nikoandsolstice", "output": "nikoand...\n \n\n`nikoandsolstice` has a length of 15, which exceeds K=7.\n\nWe should extract the first 7 characters in this string, append `...` to the\nend of them, and print the result `nikoand...`.\n\n* * *"}, {"input": "40\n ferelibenterhominesidquodvoluntcredunt", "output": "ferelibenterhominesidquodvoluntcredunt\n \n\nThe famous quote from Gaius Julius Caesar."}] |
Print a string as stated in Problem Statement.
* * * | s042228984 | Wrong Answer | p02676 | Input is given from Standard Input in the following format:
K
S | value = int(input())
text = input()
if value < len(text):
print(text[0] + "...")
else:
print(text)
| Statement
We have a string S consisting of lowercase English letters.
If the length of S is at most K, print S without change.
If the length of S exceeds K, extract the first K characters in S, append
`...` to the end of them, and print the result. | [{"input": "7\n nikoandsolstice", "output": "nikoand...\n \n\n`nikoandsolstice` has a length of 15, which exceeds K=7.\n\nWe should extract the first 7 characters in this string, append `...` to the\nend of them, and print the result `nikoand...`.\n\n* * *"}, {"input": "40\n ferelibenterhominesidquodvoluntcredunt", "output": "ferelibenterhominesidquodvoluntcredunt\n \n\nThe famous quote from Gaius Julius Caesar."}] |
Print a string as stated in Problem Statement.
* * * | s527084205 | Accepted | p02676 | Input is given from Standard Input in the following format:
K
S | import sys
sys.setrecursionlimit(10**6) # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1 # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(
*x, sep="\n"
) # リストの要素を改行を挟んで表示する関数
# 入力を整数に変換して受け取る
def input_int():
return int(input())
def map_int_input():
return map(int, input())
MII = map_int_input
def MII_split():
return map(int, input().split())
def MII_to_index():
return map(to_index, input())
def MII_split_to_index():
return map(to_index, input().split())
# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
return list(map(int, input()))
LII = list_int_inputs
def LII_split():
return list(map(int, input().split()))
# 2次元リスト化
def LII_2D(rows_number):
return [LII() for _ in range(rows_number)]
def LII_split_2D(rows_number):
return [LII_split() for _ in range(rows_number)]
K = input_int()
S = input()
if len(S) > K:
S = S[:K]
S += "..."
print(S)
| Statement
We have a string S consisting of lowercase English letters.
If the length of S is at most K, print S without change.
If the length of S exceeds K, extract the first K characters in S, append
`...` to the end of them, and print the result. | [{"input": "7\n nikoandsolstice", "output": "nikoand...\n \n\n`nikoandsolstice` has a length of 15, which exceeds K=7.\n\nWe should extract the first 7 characters in this string, append `...` to the\nend of them, and print the result `nikoand...`.\n\n* * *"}, {"input": "40\n ferelibenterhominesidquodvoluntcredunt", "output": "ferelibenterhominesidquodvoluntcredunt\n \n\nThe famous quote from Gaius Julius Caesar."}] |
Print a string as stated in Problem Statement.
* * * | s491136554 | Wrong Answer | p02676 | Input is given from Standard Input in the following format:
K
S | max = int(input())
retsu = input()
l = len(retsu)
if l > max:
retsu = retsu[0 : l - max - 1]
retsu += "..."
print(retsu)
| Statement
We have a string S consisting of lowercase English letters.
If the length of S is at most K, print S without change.
If the length of S exceeds K, extract the first K characters in S, append
`...` to the end of them, and print the result. | [{"input": "7\n nikoandsolstice", "output": "nikoand...\n \n\n`nikoandsolstice` has a length of 15, which exceeds K=7.\n\nWe should extract the first 7 characters in this string, append `...` to the\nend of them, and print the result `nikoand...`.\n\n* * *"}, {"input": "40\n ferelibenterhominesidquodvoluntcredunt", "output": "ferelibenterhominesidquodvoluntcredunt\n \n\nThe famous quote from Gaius Julius Caesar."}] |
Print a string as stated in Problem Statement.
* * * | s554825532 | Wrong Answer | p02676 | Input is given from Standard Input in the following format:
K
S | a = int(input());s = input()
print(s[:a] + "..." * (len(s) - 1 > a)) | Statement
We have a string S consisting of lowercase English letters.
If the length of S is at most K, print S without change.
If the length of S exceeds K, extract the first K characters in S, append
`...` to the end of them, and print the result. | [{"input": "7\n nikoandsolstice", "output": "nikoand...\n \n\n`nikoandsolstice` has a length of 15, which exceeds K=7.\n\nWe should extract the first 7 characters in this string, append `...` to the\nend of them, and print the result `nikoand...`.\n\n* * *"}, {"input": "40\n ferelibenterhominesidquodvoluntcredunt", "output": "ferelibenterhominesidquodvoluntcredunt\n \n\nThe famous quote from Gaius Julius Caesar."}] |
Print a string as stated in Problem Statement.
* * * | s592166401 | Wrong Answer | p02676 | Input is given from Standard Input in the following format:
K
S | k=int(input())
s=str(input())
if len(s)>k:
print(s[0:k]+"...")
| Statement
We have a string S consisting of lowercase English letters.
If the length of S is at most K, print S without change.
If the length of S exceeds K, extract the first K characters in S, append
`...` to the end of them, and print the result. | [{"input": "7\n nikoandsolstice", "output": "nikoand...\n \n\n`nikoandsolstice` has a length of 15, which exceeds K=7.\n\nWe should extract the first 7 characters in this string, append `...` to the\nend of them, and print the result `nikoand...`.\n\n* * *"}, {"input": "40\n ferelibenterhominesidquodvoluntcredunt", "output": "ferelibenterhominesidquodvoluntcredunt\n \n\nThe famous quote from Gaius Julius Caesar."}] |
Print a string as stated in Problem Statement.
* * * | s901636772 | Accepted | p02676 | Input is given from Standard Input in the following format:
K
S | import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10**7)
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()
k = ni()
s = ns()
if len(s) <= k:
print(s)
else:
print(s[:k] + "...")
| Statement
We have a string S consisting of lowercase English letters.
If the length of S is at most K, print S without change.
If the length of S exceeds K, extract the first K characters in S, append
`...` to the end of them, and print the result. | [{"input": "7\n nikoandsolstice", "output": "nikoand...\n \n\n`nikoandsolstice` has a length of 15, which exceeds K=7.\n\nWe should extract the first 7 characters in this string, append `...` to the\nend of them, and print the result `nikoand...`.\n\n* * *"}, {"input": "40\n ferelibenterhominesidquodvoluntcredunt", "output": "ferelibenterhominesidquodvoluntcredunt\n \n\nThe famous quote from Gaius Julius Caesar."}] |
Print a string as stated in Problem Statement.
* * * | s696837824 | Wrong Answer | p02676 | Input is given from Standard Input in the following format:
K
S | n = int(input())
# print('n=',n)
m = input()
# print('m=',m)
o = len(m)
# print('o=',o)
if o <= n:
print(m)
elif o > n:
print(m[0:n], "...")
| Statement
We have a string S consisting of lowercase English letters.
If the length of S is at most K, print S without change.
If the length of S exceeds K, extract the first K characters in S, append
`...` to the end of them, and print the result. | [{"input": "7\n nikoandsolstice", "output": "nikoand...\n \n\n`nikoandsolstice` has a length of 15, which exceeds K=7.\n\nWe should extract the first 7 characters in this string, append `...` to the\nend of them, and print the result `nikoand...`.\n\n* * *"}, {"input": "40\n ferelibenterhominesidquodvoluntcredunt", "output": "ferelibenterhominesidquodvoluntcredunt\n \n\nThe famous quote from Gaius Julius Caesar."}] |
Print an integer representing the minimum number of times Takahashi will press
the buttons.
* * * | s689670853 | Accepted | p03821 | The input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N | n = int(input())
a = [[int(i) for i in input().split()] for _ in range(n)]
u = 0
for x in a[::-1]:
if (x[0] + u) % x[1] != 0:
u += ((x[0] + u) // x[1] + 1) * x[1] - x[0] - u
print(u)
| Statement
There are an integer sequence A_1,...,A_N consisting of N terms, and N
buttons. When the i-th (1 ≦ i ≦ N) button is pressed, the values of the i
terms from the first through the i-th are all incremented by 1.
There is also another integer sequence B_1,...,B_N. Takahashi will push the
buttons some number of times so that for every i, A_i will be a multiple of
B_i.
Find the minimum number of times Takahashi will press the buttons. | [{"input": "3\n 3 5\n 2 7\n 9 4", "output": "7\n \n\nPress the first button twice, the second button twice and the third button\nthree times.\n\n* * *"}, {"input": "7\n 3 1\n 4 1\n 5 9\n 2 6\n 5 3\n 5 8\n 9 7", "output": "22"}] |
Print an integer representing the minimum number of times Takahashi will press
the buttons.
* * * | s420247379 | Accepted | p03821 | The input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N | # https://atcoder.jp/contests/agc009/tasks/agc009_a
# 普通にBの倍数かつAより大きいものの中で最小の数を高速に求めれば良い
# いや[0,i)を+1増やすらしい。めちゃくちゃめんどくさいやつだ
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate
def exit(*argv, **kwarg):
print(*argv, **kwarg)
sys.exit()
def mina(*argv, sub=1):
return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと
def a_int():
return int(read())
def ints():
return list(map(int, read().split()))
def read_col(H):
"""H is number of rows
A列、B列が与えられるようなとき
ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合"""
ret = []
for _ in range(H):
ret.append(list(map(int, read().split())))
return tuple(map(list, zip(*ret)))
from math import floor, ceil
N = a_int()
A, B = read_col(N)
# 後ろから決定していく
n_pushed = 0 # すでに何回押されたか(a+n_pushedがその時点での数字の大きさに成る)
for a, b in zip(reversed(A), reversed(B)):
a += n_pushed
x = (ceil(a / b)) * b
# print(x)
n_pushed += x - a
print(n_pushed)
| Statement
There are an integer sequence A_1,...,A_N consisting of N terms, and N
buttons. When the i-th (1 ≦ i ≦ N) button is pressed, the values of the i
terms from the first through the i-th are all incremented by 1.
There is also another integer sequence B_1,...,B_N. Takahashi will push the
buttons some number of times so that for every i, A_i will be a multiple of
B_i.
Find the minimum number of times Takahashi will press the buttons. | [{"input": "3\n 3 5\n 2 7\n 9 4", "output": "7\n \n\nPress the first button twice, the second button twice and the third button\nthree times.\n\n* * *"}, {"input": "7\n 3 1\n 4 1\n 5 9\n 2 6\n 5 3\n 5 8\n 9 7", "output": "22"}] |
Print an integer representing the minimum number of times Takahashi will press
the buttons.
* * * | s671260720 | Runtime Error | p03821 | The input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N | n = int(input())
c = [list(map(int, unput().split())) for _ in [0] * n].reverse()
t = 0
for i in c:
a = c[0]
b = c[2]
t += b - 1 - (a + t - 1) % b
print(t)
| Statement
There are an integer sequence A_1,...,A_N consisting of N terms, and N
buttons. When the i-th (1 ≦ i ≦ N) button is pressed, the values of the i
terms from the first through the i-th are all incremented by 1.
There is also another integer sequence B_1,...,B_N. Takahashi will push the
buttons some number of times so that for every i, A_i will be a multiple of
B_i.
Find the minimum number of times Takahashi will press the buttons. | [{"input": "3\n 3 5\n 2 7\n 9 4", "output": "7\n \n\nPress the first button twice, the second button twice and the third button\nthree times.\n\n* * *"}, {"input": "7\n 3 1\n 4 1\n 5 9\n 2 6\n 5 3\n 5 8\n 9 7", "output": "22"}] |
Print an integer representing the minimum number of times Takahashi will press
the buttons.
* * * | s066454226 | Runtime Error | p03821 | The input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N | a = []
b = []
n = int(input())
ind = -1
count = 0
for i in range(n):
c,d = int(input().split())
a.append(c)
b.append(d)
for i in range((n-1),0,-1):
if a[i]+count % b[i] != 0:
count+= b[i] - (a[i] + count) % b[i]
print(count)
| Statement
There are an integer sequence A_1,...,A_N consisting of N terms, and N
buttons. When the i-th (1 ≦ i ≦ N) button is pressed, the values of the i
terms from the first through the i-th are all incremented by 1.
There is also another integer sequence B_1,...,B_N. Takahashi will push the
buttons some number of times so that for every i, A_i will be a multiple of
B_i.
Find the minimum number of times Takahashi will press the buttons. | [{"input": "3\n 3 5\n 2 7\n 9 4", "output": "7\n \n\nPress the first button twice, the second button twice and the third button\nthree times.\n\n* * *"}, {"input": "7\n 3 1\n 4 1\n 5 9\n 2 6\n 5 3\n 5 8\n 9 7", "output": "22"}] |
Print an integer representing the minimum number of times Takahashi will press
the buttons.
* * * | s576353698 | Runtime Error | p03821 | The input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N | n = int(input())
a = []
b = []
for j in range(n):
l = list(map(int, input().split()))
a.append(l[0])
b.append(l[1])
c = 0
for i in range(n-1, -1, -1):
if (a[i]+c) % b[i] != 0:
c += (b[i] - (a[i]+c) % b[i])
print(c) | Statement
There are an integer sequence A_1,...,A_N consisting of N terms, and N
buttons. When the i-th (1 ≦ i ≦ N) button is pressed, the values of the i
terms from the first through the i-th are all incremented by 1.
There is also another integer sequence B_1,...,B_N. Takahashi will push the
buttons some number of times so that for every i, A_i will be a multiple of
B_i.
Find the minimum number of times Takahashi will press the buttons. | [{"input": "3\n 3 5\n 2 7\n 9 4", "output": "7\n \n\nPress the first button twice, the second button twice and the third button\nthree times.\n\n* * *"}, {"input": "7\n 3 1\n 4 1\n 5 9\n 2 6\n 5 3\n 5 8\n 9 7", "output": "22"}] |
Print an integer representing the minimum number of times Takahashi will press
the buttons.
* * * | s098881454 | Runtime Error | p03821 | The input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N | import sys
import os
def file_input():
f = open('AGC009/input.txt', 'r')
sys.stdin = f
def main():
#file_input()
N=int(input())
A=[]
B=[]
for i in range(N):
tmp=list(map(int, input().split()))
A.append(tmp[0])
B.append(tmp[1])
cnt=0
for j in range(N):
# while (A[N-1-j]+cnt)%B[N-1-j]!=0:
# cnt+=1
tmp=A[N-1-j]+cnt
if not tmp==0:
# cnt=B[N-1-j]
elif tmp<B[N-1-j]:
cnt+=B[N-1-j]-tmp
elif tmp%B[N-1-j]!=0:
cnt+=B[N-1-j]-tmp%B[N-1-j]
print(cnt)
if __name__ == '__main__':
main()
| Statement
There are an integer sequence A_1,...,A_N consisting of N terms, and N
buttons. When the i-th (1 ≦ i ≦ N) button is pressed, the values of the i
terms from the first through the i-th are all incremented by 1.
There is also another integer sequence B_1,...,B_N. Takahashi will push the
buttons some number of times so that for every i, A_i will be a multiple of
B_i.
Find the minimum number of times Takahashi will press the buttons. | [{"input": "3\n 3 5\n 2 7\n 9 4", "output": "7\n \n\nPress the first button twice, the second button twice and the third button\nthree times.\n\n* * *"}, {"input": "7\n 3 1\n 4 1\n 5 9\n 2 6\n 5 3\n 5 8\n 9 7", "output": "22"}] |
Print an integer representing the minimum number of times Takahashi will press
the buttons.
* * * | s677940065 | Runtime Error | p03821 | The input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N | N = int(input())
A=[]
B=[]
for i in range(N):
a,b=[int(n) for n in input().split()]
A.append(a)
B.append(b)
cnt=0
# print(list(reversed(range(N))))
for i in reversed(range(N)):
if A[i]%B[i]==0:
r=0
else
r=B[i]-A[i]%B[i]
cnt+=r
A=[A[n]+r if n<=i else A[n] for n in range(N)]
print(cnt)
| Statement
There are an integer sequence A_1,...,A_N consisting of N terms, and N
buttons. When the i-th (1 ≦ i ≦ N) button is pressed, the values of the i
terms from the first through the i-th are all incremented by 1.
There is also another integer sequence B_1,...,B_N. Takahashi will push the
buttons some number of times so that for every i, A_i will be a multiple of
B_i.
Find the minimum number of times Takahashi will press the buttons. | [{"input": "3\n 3 5\n 2 7\n 9 4", "output": "7\n \n\nPress the first button twice, the second button twice and the third button\nthree times.\n\n* * *"}, {"input": "7\n 3 1\n 4 1\n 5 9\n 2 6\n 5 3\n 5 8\n 9 7", "output": "22"}] |
Print an integer representing the minimum number of times Takahashi will press
the buttons.
* * * | s439268851 | Runtime Error | p03821 | The input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N | N = int(input())
A = []
B = []
for i in range(N):
a, b = map(int, input().split())
A.append(a)
B.append(b)
A = A[::-1]
B = B[::-1]
ans = 0
for a, b in zip(A, B):
a += ans
m = b - (a % b) if b != 1 else 0
m = b if a == 0
ans += m
print(ans) | Statement
There are an integer sequence A_1,...,A_N consisting of N terms, and N
buttons. When the i-th (1 ≦ i ≦ N) button is pressed, the values of the i
terms from the first through the i-th are all incremented by 1.
There is also another integer sequence B_1,...,B_N. Takahashi will push the
buttons some number of times so that for every i, A_i will be a multiple of
B_i.
Find the minimum number of times Takahashi will press the buttons. | [{"input": "3\n 3 5\n 2 7\n 9 4", "output": "7\n \n\nPress the first button twice, the second button twice and the third button\nthree times.\n\n* * *"}, {"input": "7\n 3 1\n 4 1\n 5 9\n 2 6\n 5 3\n 5 8\n 9 7", "output": "22"}] |
Print an integer representing the minimum number of times Takahashi will press
the buttons.
* * * | s545238072 | Runtime Error | p03821 | The input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N |
N = int(input())
total = 0
A = [None] * N
B = [None] * N
for i in range(N):
A[i], B[i] = map(int, input().split())
for t in range(N):
i = N + 1 - t
a = A[i] % B[i]
if a == 0:
pass
else:
total = B[i]-a:
for j in range (i):
A[i] = A[i] + B[i] - a
print (total)
| Statement
There are an integer sequence A_1,...,A_N consisting of N terms, and N
buttons. When the i-th (1 ≦ i ≦ N) button is pressed, the values of the i
terms from the first through the i-th are all incremented by 1.
There is also another integer sequence B_1,...,B_N. Takahashi will push the
buttons some number of times so that for every i, A_i will be a multiple of
B_i.
Find the minimum number of times Takahashi will press the buttons. | [{"input": "3\n 3 5\n 2 7\n 9 4", "output": "7\n \n\nPress the first button twice, the second button twice and the third button\nthree times.\n\n* * *"}, {"input": "7\n 3 1\n 4 1\n 5 9\n 2 6\n 5 3\n 5 8\n 9 7", "output": "22"}] |
Print an integer representing the minimum number of times Takahashi will press
the buttons.
* * * | s969389449 | Accepted | p03821 | The input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N | N, *AB = [map(int, s.split()) for s in open(0)]
AB = list(AB)[::-1]
bias = 0
for A, B in AB:
bias += (bias + A + B - 1) // B * B - A - bias
print(bias)
| Statement
There are an integer sequence A_1,...,A_N consisting of N terms, and N
buttons. When the i-th (1 ≦ i ≦ N) button is pressed, the values of the i
terms from the first through the i-th are all incremented by 1.
There is also another integer sequence B_1,...,B_N. Takahashi will push the
buttons some number of times so that for every i, A_i will be a multiple of
B_i.
Find the minimum number of times Takahashi will press the buttons. | [{"input": "3\n 3 5\n 2 7\n 9 4", "output": "7\n \n\nPress the first button twice, the second button twice and the third button\nthree times.\n\n* * *"}, {"input": "7\n 3 1\n 4 1\n 5 9\n 2 6\n 5 3\n 5 8\n 9 7", "output": "22"}] |
Print an integer representing the minimum number of times Takahashi will press
the buttons.
* * * | s968804265 | Accepted | p03821 | The input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N | n = int(input())
l = [list(map(int, input().split())) for i in range(n)]
a, b = [list(i) for i in zip(*l)]
x = 0
for i in range(n)[::-1]:
if (a[i] + x) % b[i] != 0:
x += b[i] - ((a[i] + x) % b[i])
print(x)
| Statement
There are an integer sequence A_1,...,A_N consisting of N terms, and N
buttons. When the i-th (1 ≦ i ≦ N) button is pressed, the values of the i
terms from the first through the i-th are all incremented by 1.
There is also another integer sequence B_1,...,B_N. Takahashi will push the
buttons some number of times so that for every i, A_i will be a multiple of
B_i.
Find the minimum number of times Takahashi will press the buttons. | [{"input": "3\n 3 5\n 2 7\n 9 4", "output": "7\n \n\nPress the first button twice, the second button twice and the third button\nthree times.\n\n* * *"}, {"input": "7\n 3 1\n 4 1\n 5 9\n 2 6\n 5 3\n 5 8\n 9 7", "output": "22"}] |
Print an integer representing the minimum number of times Takahashi will press
the buttons.
* * * | s270711550 | Accepted | p03821 | The input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N | # -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
class Scanner:
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [input() for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [int(input()) for i in range(n)]
class Math:
@staticmethod
def gcd(a, b):
if b == 0:
return a
return Math.gcd(b, a % b)
@staticmethod
def lcm(a, b):
return (a * b) // Math.gcd(a, b)
@staticmethod
def roundUp(a, b):
return -(-a // b)
@staticmethod
def toUpperMultiple(a, x):
return Math.roundUp(a, x) * x
@staticmethod
def toLowerMultiple(a, x):
return (a // x) * x
@staticmethod
def nearPow2(n):
if n <= 0:
return 0
if n & (n - 1) == 0:
return n
ret = 1
while n > 0:
ret <<= 1
n >>= 1
return ret
@staticmethod
def sign(n):
if n == 0:
return 0
if n < 0:
return -1
return 1
@staticmethod
def isPrime(n):
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
d = int(n**0.5) + 1
for i in range(3, d + 1, 2):
if n % i == 0:
return False
return True
class PriorityQueue:
def __init__(self, l=[]):
self.__q = l
heapq.heapify(self.__q)
return
def push(self, n):
heapq.heappush(self.__q, n)
return
def pop(self):
return heapq.heappop(self.__q)
MOD = int(1e09) + 7
INF = int(1e15)
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)
divisors.sort()
return divisors
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
def main():
# sys.stdin = open("sample.txt")
N = Scanner.int()
A, B = [0] * N, [0] * N
for i in range(N):
A[i], B[i] = Scanner.map_int()
ans = 0
for i in reversed(range(N)):
A[i] += ans
if A[i] % B[i] != 0:
ans += B[i] - A[i] % B[i]
print(ans)
return
if __name__ == "__main__":
main()
| Statement
There are an integer sequence A_1,...,A_N consisting of N terms, and N
buttons. When the i-th (1 ≦ i ≦ N) button is pressed, the values of the i
terms from the first through the i-th are all incremented by 1.
There is also another integer sequence B_1,...,B_N. Takahashi will push the
buttons some number of times so that for every i, A_i will be a multiple of
B_i.
Find the minimum number of times Takahashi will press the buttons. | [{"input": "3\n 3 5\n 2 7\n 9 4", "output": "7\n \n\nPress the first button twice, the second button twice and the third button\nthree times.\n\n* * *"}, {"input": "7\n 3 1\n 4 1\n 5 9\n 2 6\n 5 3\n 5 8\n 9 7", "output": "22"}] |
Print an integer representing the minimum number of times Takahashi will press
the buttons.
* * * | s667807867 | Runtime Error | p03821 | The input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N | import sys, collections as cl, bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9 + 7
Max = sys.maxsize
def l(): # intのlist
return list(map(int, input().split()))
def m(): # 複数文字
return map(int, input().split())
def onem(): # Nとかの取得
return int(input())
def s(x): # 圧縮
a = []
if len(x) == 0:
return []
aa = x[0]
su = 1
for i in range(len(x) - 1):
if aa != x[i + 1]:
a.append([aa, su])
aa = x[i + 1]
su = 1
else:
su += 1
a.append([aa, su])
return a
def jo(x): # listをスペースごとに分ける
return " ".join(map(str, x))
def max2(x): # 他のときもどうように作成可能
return max(map(max, x))
def In(x, a): # aがリスト(sorted)
k = bs.bisect_left(a, x)
if k != len(a) and a[k] == x:
return True
else:
return False
def pow_k(x, n):
ans = 1
while n:
if n % 2:
ans *= x
x *= x
n >>= 1
return ans
"""
def nibu(x,n,r):
ll = 0
rr = r
while True:
mid = (ll+rr)//2
if rr == mid:
return ll
if (ここに評価入れる):
rr = mid
else:
ll = mid+1
"""
n = onem()
po = []
for i in range(n):
po.append(l())
co = 0
for i in range(n):
on = po[-(i + 1)]
on[0] += co
co += ((on[1] - on[0]) % on[1]) if on[1] % on[0] != 0 else 0
print(co)
| Statement
There are an integer sequence A_1,...,A_N consisting of N terms, and N
buttons. When the i-th (1 ≦ i ≦ N) button is pressed, the values of the i
terms from the first through the i-th are all incremented by 1.
There is also another integer sequence B_1,...,B_N. Takahashi will push the
buttons some number of times so that for every i, A_i will be a multiple of
B_i.
Find the minimum number of times Takahashi will press the buttons. | [{"input": "3\n 3 5\n 2 7\n 9 4", "output": "7\n \n\nPress the first button twice, the second button twice and the third button\nthree times.\n\n* * *"}, {"input": "7\n 3 1\n 4 1\n 5 9\n 2 6\n 5 3\n 5 8\n 9 7", "output": "22"}] |
Print an integer representing the minimum number of times Takahashi will press
the buttons.
* * * | s391994849 | Accepted | p03821 | The input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N | # 1st: ARC007-B
if False:
N, M = map(int, input().split())
case = [i for i in range(N + 1)]
for _ in range(M):
now = int(input())
i = case.index(now)
case[i] = case[0]
case[0] = now
# print(case)
for i in range(1, N + 1):
print(case[i])
# 2nd: ABC004-C (0408)
if False:
N = int(input()) - 1
N = N % 30
ans = list(range(1, 7))
for i in range(N + 1):
ans[i % 5], ans[i % 5 + 1] = ans[i % 5 + 1], ans[i % 5]
# print(ans)
print("".join(map(str, ans)))
# 3rd: AGC011-A (0408)
if False:
N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
T.sort()
cnt = 1
pas = 1 # 乗客数
tim = K + T[0] # departure time
# print(T)
for i in range(1, N):
t = T[i]
if tim < t or pas >= C:
cnt += 1
tim = t + K
pas = 1
else:
pas += 1
# print(tim,pas,cnt)
print(cnt)
# 4th: ABC072-D (0408)
if False:
N = int(input())
P = [int(i) for i in input().split()]
ans = 0
cnt = 0
for i in range(N - 1):
if P[i] == i + 1:
P[i], P[i + 1] = P[i + 1], P[i]
cnt += 1
if P[N - 1] == N:
P[N - 1], P[N - 2] = P[N - 2], P[N - 1]
cnt += 1
print(cnt)
# 5th: AGC009-A (0408)
if True:
N = int(input())
A = []
B = []
for _ in range(N):
a, b = map(int, input().split())
A.append(a)
B.append(b)
cnt = 0
for i in reversed(range(N)):
if (A[i] + cnt) % B[i] != 0:
cnt += B[i] - (A[i] + cnt) % B[i]
# print(cnt)
print(cnt)
| Statement
There are an integer sequence A_1,...,A_N consisting of N terms, and N
buttons. When the i-th (1 ≦ i ≦ N) button is pressed, the values of the i
terms from the first through the i-th are all incremented by 1.
There is also another integer sequence B_1,...,B_N. Takahashi will push the
buttons some number of times so that for every i, A_i will be a multiple of
B_i.
Find the minimum number of times Takahashi will press the buttons. | [{"input": "3\n 3 5\n 2 7\n 9 4", "output": "7\n \n\nPress the first button twice, the second button twice and the third button\nthree times.\n\n* * *"}, {"input": "7\n 3 1\n 4 1\n 5 9\n 2 6\n 5 3\n 5 8\n 9 7", "output": "22"}] |
Print an integer representing the minimum number of times Takahashi will press
the buttons.
* * * | s858035175 | Accepted | p03821 | The input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N | N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
S = 0
for i in range(N, 0, -1):
A[i - 1][0] += S
A[i - 1][0] %= A[i - 1][1]
if A[i - 1][0] != 0:
S += A[i - 1][1] - A[i - 1][0]
print(S)
| Statement
There are an integer sequence A_1,...,A_N consisting of N terms, and N
buttons. When the i-th (1 ≦ i ≦ N) button is pressed, the values of the i
terms from the first through the i-th are all incremented by 1.
There is also another integer sequence B_1,...,B_N. Takahashi will push the
buttons some number of times so that for every i, A_i will be a multiple of
B_i.
Find the minimum number of times Takahashi will press the buttons. | [{"input": "3\n 3 5\n 2 7\n 9 4", "output": "7\n \n\nPress the first button twice, the second button twice and the third button\nthree times.\n\n* * *"}, {"input": "7\n 3 1\n 4 1\n 5 9\n 2 6\n 5 3\n 5 8\n 9 7", "output": "22"}] |
Print an integer representing the minimum number of times Takahashi will press
the buttons.
* * * | s318162353 | Accepted | p03821 | The input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N | # coding: utf-8
import re
import math
from collections import defaultdict
from collections import deque
import collections
from fractions import Fraction
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
# @lru_cache(maxsize=None)
readline = sys.stdin.readline
sys.setrecursionlimit(2000000)
# import numpy as np
alphabet = "abcdefghijklmnopqrstuvwxyz"
mod = int(10**9 + 7)
inf = int(10**20)
def yn(b):
if b:
print("yes")
else:
print("no")
def Yn(b):
if b:
print("Yes")
else:
print("No")
def YN(b):
if b:
print("YES")
else:
print("NO")
class union_find:
def __init__(self, n):
self.n = n
self.P = [a for a in range(n)]
self.rank = [0] * n
def find(self, x):
if x != self.P[x]:
self.P[x] = self.find(self.P[x])
return self.P[x]
def same(self, x, y):
return self.find(x) == self.find(y)
def link(self, x, y):
if self.rank[x] < self.rank[y]:
self.P[x] = y
elif self.rank[y] < self.rank[x]:
self.P[y] = x
else:
self.P[x] = y
self.rank[y] += 1
def unite(self, x, y):
self.link(self.find(x), self.find(y))
def size(self):
S = set()
for a in range(self.n):
S.add(self.find(a))
return len(S)
def ispow(a, b): # aはbの累乗数か
now = b
while now < a:
now *= b
if now == a:
return True
else:
return False
def getbin(num, size):
A = [0] * size
for a in range(size):
if (num >> (size - a - 1)) & 1 == 1:
A[a] = 1
else:
A[a] = 0
return A
def getfacs(n, mod_=0):
A = [1] * (n + 1)
for a in range(2, len(A)):
A[a] = A[a - 1] * a
if mod_ > 0:
A[a] %= mod_
return A
def comb(n, r, mod, fac):
if n - r < 0:
return 0
return (fac[n] * pow(fac[n - r], mod - 2, mod) * pow(fac[r], mod - 2, mod)) % mod
def nextcomb(num, size):
x = num & (-num)
y = num + x
z = num & (~y)
z //= x
z = z >> 1
num = y | z
if num >= (1 << size):
return False
else:
return num
def getprimes(n, type="int"):
if n == 0:
if type == "int":
return []
else:
return [False]
A = [True] * (n + 1)
A[0] = False
A[1] = False
for a in range(2, n + 1):
if A[a]:
for b in range(a * 2, n + 1, a):
A[b] = False
if type == "bool":
return A
B = []
for a in range(n + 1):
if A[a]:
B.append(a)
return B
def isprime(num):
if num <= 1:
return False
i = 2
while i * i <= num:
if num % i == 0:
return False
i += 1
return True
def ifelse(a, b, c):
if a:
return b
else:
return c
def join(A, c=""):
n = len(A)
A = list(map(str, A))
s = ""
for a in range(n):
s += A[a]
if a < n - 1:
s += c
return s
def factorize(n, type_="dict"):
b = 2
list_ = []
while b * b <= n:
while n % b == 0:
n //= b
list_.append(b)
b += 1
if n > 1:
list_.append(n)
if type_ == "dict":
dic = {}
for a in list_:
if a in dic:
dic[a] += 1
else:
dic[a] = 1
return dic
elif type_ == "list":
return list_
else:
return None
def pm(x):
return x // abs(x)
def inputintlist():
return list(map(int, input().split()))
######################################################################################################
n = int(input())
A = [0] * n
B = [0] * n
for a in range(n):
A[a], B[a] = inputintlist()
ans = 0
R = [0] * n
for a in range(n - 1, -1, -1):
r = 0
if a != n - 1:
r = R[a + 1]
num = ((A[a] + r + B[a] - 1) // B[a]) * B[a] - A[a] - r
R[a] = num + r
print(R[0])
| Statement
There are an integer sequence A_1,...,A_N consisting of N terms, and N
buttons. When the i-th (1 ≦ i ≦ N) button is pressed, the values of the i
terms from the first through the i-th are all incremented by 1.
There is also another integer sequence B_1,...,B_N. Takahashi will push the
buttons some number of times so that for every i, A_i will be a multiple of
B_i.
Find the minimum number of times Takahashi will press the buttons. | [{"input": "3\n 3 5\n 2 7\n 9 4", "output": "7\n \n\nPress the first button twice, the second button twice and the third button\nthree times.\n\n* * *"}, {"input": "7\n 3 1\n 4 1\n 5 9\n 2 6\n 5 3\n 5 8\n 9 7", "output": "22"}] |
Print the number of minimum times the bar needs to be cut so that every block
after the cuts has K or less white squares.
* * * | s782959471 | Accepted | p02733 | Input is given from Standard Input in the following format:
H W K
S_{1,1}S_{1,2}...S_{1,W}
:
S_{H,1}S_{H,2}...S_{H,W} | def main():
H, W, K = map(int, input().split())
S = []
for i in range(H):
col = list(map(int, list(input())))
S.append(col)
CumulativeS = [[S[i][0]] for i in range(H)]
for i in range(len(S)):
for j in range(1, len(S[i])):
CumulativeS[i].append(CumulativeS[i][j - 1] + S[i][j])
for i in range(1, len(S)):
for j in range(len(S[i])):
CumulativeS[i][j] += CumulativeS[i - 1][j]
all_bit = 1 << H - 1
res = 10000
for bit in range(all_bit):
wide_bound = []
for i in range(H - 1):
if (bit & (1 << i)) != 0:
wide_bound.append(i)
res_ = len(wide_bound)
high_bound = []
high_flag = 0
for i in range(W):
if len(high_bound) == 0:
for b in range(len(wide_bound)):
if b == 0:
white_chocolate = CumulativeS[wide_bound[b]][i]
else:
white_chocolate = (
CumulativeS[wide_bound[b]][i]
- CumulativeS[wide_bound[b - 1]][i]
)
if white_chocolate > K:
if i - 1 < 0:
high_flag = 1
break
high_bound.append(i - 1)
break
if b == len(wide_bound) - 1:
white_chocolate = (
CumulativeS[H - 1][i] - CumulativeS[wide_bound[b]][i]
)
if white_chocolate > K:
if i - 1 < 0:
high_flag = 1
break
high_bound.append(i - 1)
if high_flag == 1:
break
if len(wide_bound) == 0:
white_chocolate = CumulativeS[H - 1][i]
if white_chocolate > K:
if i - 1 < 0:
high_flag = 1
break
high_bound.append(i - 1)
else:
for b in range(len(wide_bound)):
if b == 0:
white_chocolate = (
CumulativeS[wide_bound[b]][i]
- CumulativeS[wide_bound[b]][
high_bound[len(high_bound) - 1]
]
)
else:
white_chocolate = (
CumulativeS[wide_bound[b]][i]
- CumulativeS[wide_bound[b - 1]][i]
- CumulativeS[wide_bound[b]][
high_bound[len(high_bound) - 1]
]
+ CumulativeS[wide_bound[b - 1]][
high_bound[len(high_bound) - 1]
]
)
if white_chocolate > K:
if i - 1 < 0:
high_flag = 1
break
high_bound.append(i - 1)
break
if b == len(wide_bound) - 1:
white_chocolate = (
CumulativeS[H - 1][i]
- CumulativeS[wide_bound[b]][i]
- CumulativeS[H - 1][high_bound[len(high_bound) - 1]]
+ CumulativeS[wide_bound[b]][
high_bound[len(high_bound) - 1]
]
)
if white_chocolate > K:
if i - 1 < 0:
high_flag = 1
break
high_bound.append(i - 1)
if high_flag == 1:
break
if len(wide_bound) == 0:
white_chocolate = (
CumulativeS[H - 1][W - 1]
- CumulativeS[H - 1][high_bound[len(high_bound) - 1]]
)
if white_chocolate > K:
if i - 1 < 0:
high_flag = 1
break
high_bound.append(i - 1)
res_ += len(high_bound)
if res_ < res and high_flag == 0:
res = res_
print(res)
if __name__ == "__main__":
main()
| Statement
We have a chocolate bar partitioned into H horizontal rows and W vertical
columns of squares.
The square (i, j) at the i-th row from the top and the j-th column from the
left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`.
We will cut the bar some number of times to divide it into some number of
blocks. In each cut, we cut the whole bar by a line running along some
boundaries of squares from end to end of the bar.
How many times do we need to cut the bar so that every block after the cuts
has K or less white squares? | [{"input": "3 5 4\n 11100\n 10001\n 00111", "output": "2\n \n\nFor example, cutting between the 1-st and 2-nd rows and between the 3-rd and\n4-th columns - as shown in the figure to the left - works.\n\nNote that we cannot cut the bar in the ways shown in the two figures to the\nright.\n\n\n\n* * *"}, {"input": "3 5 8\n 11100\n 10001\n 00111", "output": "0\n \n\nNo cut is needed.\n\n* * *"}, {"input": "4 10 4\n 1110010010\n 1000101110\n 0011101001\n 1101000111", "output": "3"}] |
Print the number of minimum times the bar needs to be cut so that every block
after the cuts has K or less white squares.
* * * | s310101394 | Wrong Answer | p02733 | Input is given from Standard Input in the following format:
H W K
S_{1,1}S_{1,2}...S_{1,W}
:
S_{H,1}S_{H,2}...S_{H,W} | # E
H, W, K = map(int, input().split())
S = [list(str(input())) for _ in range(H)]
count = 0
for slist in S:
for s in slist:
if s == "1":
count += 1
ans = 0
n = 1
while True:
if count / n <= K:
break
else:
n *= 2
ans += 1
print(ans)
| Statement
We have a chocolate bar partitioned into H horizontal rows and W vertical
columns of squares.
The square (i, j) at the i-th row from the top and the j-th column from the
left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`.
We will cut the bar some number of times to divide it into some number of
blocks. In each cut, we cut the whole bar by a line running along some
boundaries of squares from end to end of the bar.
How many times do we need to cut the bar so that every block after the cuts
has K or less white squares? | [{"input": "3 5 4\n 11100\n 10001\n 00111", "output": "2\n \n\nFor example, cutting between the 1-st and 2-nd rows and between the 3-rd and\n4-th columns - as shown in the figure to the left - works.\n\nNote that we cannot cut the bar in the ways shown in the two figures to the\nright.\n\n\n\n* * *"}, {"input": "3 5 8\n 11100\n 10001\n 00111", "output": "0\n \n\nNo cut is needed.\n\n* * *"}, {"input": "4 10 4\n 1110010010\n 1000101110\n 0011101001\n 1101000111", "output": "3"}] |
Print the number of minimum times the bar needs to be cut so that every block
after the cuts has K or less white squares.
* * * | s376994946 | Runtime Error | p02733 | Input is given from Standard Input in the following format:
H W K
S_{1,1}S_{1,2}...S_{1,W}
:
S_{H,1}S_{H,2}...S_{H,W} | from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
d = defaultdict(lambda: 0)
for i in range(len(A)):
d[A[i]] += 1
total = 0
for k, v in d.items():
total += v * (v - 1) // 2
for a in A:
print(total - (d[a] - 1))
| Statement
We have a chocolate bar partitioned into H horizontal rows and W vertical
columns of squares.
The square (i, j) at the i-th row from the top and the j-th column from the
left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`.
We will cut the bar some number of times to divide it into some number of
blocks. In each cut, we cut the whole bar by a line running along some
boundaries of squares from end to end of the bar.
How many times do we need to cut the bar so that every block after the cuts
has K or less white squares? | [{"input": "3 5 4\n 11100\n 10001\n 00111", "output": "2\n \n\nFor example, cutting between the 1-st and 2-nd rows and between the 3-rd and\n4-th columns - as shown in the figure to the left - works.\n\nNote that we cannot cut the bar in the ways shown in the two figures to the\nright.\n\n\n\n* * *"}, {"input": "3 5 8\n 11100\n 10001\n 00111", "output": "0\n \n\nNo cut is needed.\n\n* * *"}, {"input": "4 10 4\n 1110010010\n 1000101110\n 0011101001\n 1101000111", "output": "3"}] |
Print the number of minimum times the bar needs to be cut so that every block
after the cuts has K or less white squares.
* * * | s752509915 | Runtime Error | p02733 | Input is given from Standard Input in the following format:
H W K
S_{1,1}S_{1,2}...S_{1,W}
:
S_{H,1}S_{H,2}...S_{H,W} | # -*- coding: utf-8 -*-
"""
Created on Sun Mar 22 20:56:06 2020
@author: naoki
"""
import math
f = open("C:/Users/naoki/Desktop/Atcoder/input.txt")
H, W, K = map(int, input().split())
S = [list(map(int, str(input()).replace("\n", ""))) for _ in range(H)]
t_S = [[S[j][i] for j in range(len(S))] for i in range(len(S[0]))]
sum_gyo = [sum(gyo) for gyo in S]
sum_retu = [sum(retu) for retu in t_S]
katamari = [sum(sum_retu)]
if katamari[0] > K:
print(math.ceil(katamari[0] / K))
else:
print(0)
| Statement
We have a chocolate bar partitioned into H horizontal rows and W vertical
columns of squares.
The square (i, j) at the i-th row from the top and the j-th column from the
left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`.
We will cut the bar some number of times to divide it into some number of
blocks. In each cut, we cut the whole bar by a line running along some
boundaries of squares from end to end of the bar.
How many times do we need to cut the bar so that every block after the cuts
has K or less white squares? | [{"input": "3 5 4\n 11100\n 10001\n 00111", "output": "2\n \n\nFor example, cutting between the 1-st and 2-nd rows and between the 3-rd and\n4-th columns - as shown in the figure to the left - works.\n\nNote that we cannot cut the bar in the ways shown in the two figures to the\nright.\n\n\n\n* * *"}, {"input": "3 5 8\n 11100\n 10001\n 00111", "output": "0\n \n\nNo cut is needed.\n\n* * *"}, {"input": "4 10 4\n 1110010010\n 1000101110\n 0011101001\n 1101000111", "output": "3"}] |
Print the number of minimum times the bar needs to be cut so that every block
after the cuts has K or less white squares.
* * * | s330017118 | Accepted | p02733 | Input is given from Standard Input in the following format:
H W K
S_{1,1}S_{1,2}...S_{1,W}
:
S_{H,1}S_{H,2}...S_{H,W} | import sys
from itertools import combinations as combi
input = sys.stdin.readline
H, W, K = map(int, input().split())
S = [list(input())[:-1] for _ in range(H)]
cs = [[0] * (W + 1) for _ in range(H)]
for i in range(H):
for j in range(W):
cs[i][j + 1] = cs[i][j] + int(S[i][j] == "1")
res = H * W
# print(cs)
for t in range(H):
for c in combi([x for x in range(H - 1)], t):
l = 0
tres = 0
while l < W:
ok = l
ng = W + 1
while ng - ok > 1:
m = (ok + ng) // 2
tt = 0
i = 0
ttt = 0
while i < H:
ttt += cs[i][m] - cs[i][l]
if i in c:
tt = max(tt, ttt)
ttt = 0
i += 1
tt = max(tt, ttt)
if tt <= K:
ok = m
else:
ng = m
if l == ok:
tres = H * W
break
l = ok
tres += int(l < W)
# print(c, tres)
res = min(res, tres + len(c))
print(res)
| Statement
We have a chocolate bar partitioned into H horizontal rows and W vertical
columns of squares.
The square (i, j) at the i-th row from the top and the j-th column from the
left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`.
We will cut the bar some number of times to divide it into some number of
blocks. In each cut, we cut the whole bar by a line running along some
boundaries of squares from end to end of the bar.
How many times do we need to cut the bar so that every block after the cuts
has K or less white squares? | [{"input": "3 5 4\n 11100\n 10001\n 00111", "output": "2\n \n\nFor example, cutting between the 1-st and 2-nd rows and between the 3-rd and\n4-th columns - as shown in the figure to the left - works.\n\nNote that we cannot cut the bar in the ways shown in the two figures to the\nright.\n\n\n\n* * *"}, {"input": "3 5 8\n 11100\n 10001\n 00111", "output": "0\n \n\nNo cut is needed.\n\n* * *"}, {"input": "4 10 4\n 1110010010\n 1000101110\n 0011101001\n 1101000111", "output": "3"}] |
Print the number of minimum times the bar needs to be cut so that every block
after the cuts has K or less white squares.
* * * | s945650860 | Accepted | p02733 | Input is given from Standard Input in the following format:
H W K
S_{1,1}S_{1,2}...S_{1,W}
:
S_{H,1}S_{H,2}...S_{H,W} | # -*- coding: utf-8 -*-
import sys
from itertools import accumulate
from bisect import bisect_right
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(input())
def MAP():
return map(int, input().split())
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
def build_grid(H, W, intv, _type, space=True, padding=False):
# 入力がスペース区切りかどうか
if space:
_input = lambda: input().split()
else:
_input = lambda: input()
_list = lambda: list(map(_type, _input()))
# 余白の有無
if padding:
offset = 1
else:
offset = 0
grid = list2d(H + offset * 2, W + offset * 2, intv)
for i in range(offset, H + offset):
row = _list()
for j in range(offset, W + offset):
grid[i][j] = row[j - offset]
return grid
def popcount(i):
return bin(i).count("1")
H, W, K = MAP()
grid = build_grid(H, W, 0, int, space=0)
ans = INF
for S in range(1 << (H - 1)):
N = popcount(S) + 1
A = list2d(N, W, 0)
for w in range(W):
A[0][w] = grid[0][w]
h = 0
for k in range(H - 1):
if S & 1 << k:
h += 1
for w in range(W):
A[h][w] += grid[k + 1][w]
for i in range(N):
A[i] = [0] + list(accumulate(A[i]))
cnt = 0
idx = 1
while 1:
nxt = INF
for i in range(N):
nxt = min(nxt, bisect_right(A[i], K + A[i][idx - 1], lo=idx))
if idx == nxt:
cnt = INF
break
idx = nxt
if idx == W + 1:
break
cnt += 1
ans = min(ans, N - 1 + cnt)
print(ans)
| Statement
We have a chocolate bar partitioned into H horizontal rows and W vertical
columns of squares.
The square (i, j) at the i-th row from the top and the j-th column from the
left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`.
We will cut the bar some number of times to divide it into some number of
blocks. In each cut, we cut the whole bar by a line running along some
boundaries of squares from end to end of the bar.
How many times do we need to cut the bar so that every block after the cuts
has K or less white squares? | [{"input": "3 5 4\n 11100\n 10001\n 00111", "output": "2\n \n\nFor example, cutting between the 1-st and 2-nd rows and between the 3-rd and\n4-th columns - as shown in the figure to the left - works.\n\nNote that we cannot cut the bar in the ways shown in the two figures to the\nright.\n\n\n\n* * *"}, {"input": "3 5 8\n 11100\n 10001\n 00111", "output": "0\n \n\nNo cut is needed.\n\n* * *"}, {"input": "4 10 4\n 1110010010\n 1000101110\n 0011101001\n 1101000111", "output": "3"}] |
Print the number of minimum times the bar needs to be cut so that every block
after the cuts has K or less white squares.
* * * | s479056522 | Wrong Answer | p02733 | Input is given from Standard Input in the following format:
H W K
S_{1,1}S_{1,2}...S_{1,W}
:
S_{H,1}S_{H,2}...S_{H,W} | #####
import numpy as np
from numpy import int32
# from collections import Counter
#####
def getIntList(inp):
return [int(_) for _ in inp]
from sys import stdin
import sys
sys.setrecursionlimit(10**8)
def getInputs():
inputs = []
for line in stdin:
line = line.split()
inputs.append(line)
return inputs
def main(inputs):
h, w, k = getIntList(inputs[0])
grid = np.empty((h, w), np.bool)
for hi in range(h):
grid[hi] = np.array([c == "1" for c in inputs[1 + hi][0]])
# h=10
# w=1000
# k=10
# grid=np.random.randint(0,2,(h,w))
# print(grid.astype(int32))
# print()
# from matplotlib import pyplot as plt
# plt.imshow(grid)
# plt.show()
divideHNum = 0
mi = None
for divideHNum in range(2 ** (h - 1)):
divideH = np.empty(h + 1, np.bool)
for hi in range(h):
divideH[hi + 1] = divideHNum & (2**hi)
divideH[0] = True
divideH[-1] = True
# print("divideH", divideHNum, divideH)
indexH = np.where(divideH)[0]
nums = np.empty((len(indexH) - 1, w), int32)
for i, ih in enumerate(indexH[:-1]):
nums[i] = grid[indexH[i] : indexH[i + 1]].sum(axis=0)
# print(indexH)
# print(nums)
# print()
cum = np.cumsum(nums, axis=1)
# print(cum)
divideW = 0
divideWSize = 0
prevNext = 0
while divideW < w:
next = np.where((cum[:, prevNext:] > k).any(axis=0))[0]
# print("next",next)
if len(next) == 0:
break
next = next[0]
if next == 0:
divideWSize = None
break
next += prevNext
divideWSize += 1
cum -= cum[:, next - 1, None]
prevNext = next
# print("next",next)
# print("cum",cum)
# print("divideWSize",divideWSize)
# print()
if divideWSize is not None:
divideSize = divideWSize + (len(indexH) - 2)
if mi is None or divideSize < mi:
mi = divideSize
divideHNum += 1
print(mi)
if __name__ == "__main__":
inputs = getInputs()
# inputs=simInputs()
main(inputs)
| Statement
We have a chocolate bar partitioned into H horizontal rows and W vertical
columns of squares.
The square (i, j) at the i-th row from the top and the j-th column from the
left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`.
We will cut the bar some number of times to divide it into some number of
blocks. In each cut, we cut the whole bar by a line running along some
boundaries of squares from end to end of the bar.
How many times do we need to cut the bar so that every block after the cuts
has K or less white squares? | [{"input": "3 5 4\n 11100\n 10001\n 00111", "output": "2\n \n\nFor example, cutting between the 1-st and 2-nd rows and between the 3-rd and\n4-th columns - as shown in the figure to the left - works.\n\nNote that we cannot cut the bar in the ways shown in the two figures to the\nright.\n\n\n\n* * *"}, {"input": "3 5 8\n 11100\n 10001\n 00111", "output": "0\n \n\nNo cut is needed.\n\n* * *"}, {"input": "4 10 4\n 1110010010\n 1000101110\n 0011101001\n 1101000111", "output": "3"}] |
Print the number of minimum times the bar needs to be cut so that every block
after the cuts has K or less white squares.
* * * | s127653743 | Wrong Answer | p02733 | Input is given from Standard Input in the following format:
H W K
S_{1,1}S_{1,2}...S_{1,W}
:
S_{H,1}S_{H,2}...S_{H,W} | H, W, K = map(int, input().split())
fields = []
for i in range(H):
rows = list(map(int, list(input())))
fields.append(rows)
Acum = [[0] * (W + 1) for i in range(H + 1)]
for i in range(H):
for j in range(W):
Acum[i + 1][j + 1] = Acum[i][j + 1] + Acum[i + 1][j] - Acum[i][j] + fields[i][j]
"""
# 実験
h1,h2,w1,w2 = 1,3,1,5 #(1,1)->(2,3)までの累積和
ans = Acum[h2][w2] - Acum[h1][w2] - Acum[h2][w1] + Acum[h1][w1]
print("aaa",ans)
for i in range(H+1):
print(Acum[i])
"""
# 縦方向は区切り方が2**(H-1)通りを全探索
# 横方向に区切りながらすすめていく(なるべく大きくとっていく)
ans = 10**10
for i in range(2 ** (H - 1)):
s = bin(i)[2:]
s_zero = s.zfill(H - 1)
# print(s_zero)
# 横区切り線の位置
a = [0] + [i + 1 for i, s in enumerate(s_zero) if int(s) == 1]
a += [H]
# 縦区切り線の位置
w_cnt = 0
w1 = 0
w = 0
m = 0
while w <= W:
m = 0
for j in range(1, len(a)):
h1 = a[j - 1]
h2 = a[j]
cnt = Acum[h2][w] - Acum[h1][w] - Acum[h2][w1] + Acum[h1][w1]
m = max(m, cnt)
if m > K:
w_cnt += 1
w1 = w - 1
w += 1
ans = min(ans, sum(map(int, list(s))) + w_cnt)
print(ans)
| Statement
We have a chocolate bar partitioned into H horizontal rows and W vertical
columns of squares.
The square (i, j) at the i-th row from the top and the j-th column from the
left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`.
We will cut the bar some number of times to divide it into some number of
blocks. In each cut, we cut the whole bar by a line running along some
boundaries of squares from end to end of the bar.
How many times do we need to cut the bar so that every block after the cuts
has K or less white squares? | [{"input": "3 5 4\n 11100\n 10001\n 00111", "output": "2\n \n\nFor example, cutting between the 1-st and 2-nd rows and between the 3-rd and\n4-th columns - as shown in the figure to the left - works.\n\nNote that we cannot cut the bar in the ways shown in the two figures to the\nright.\n\n\n\n* * *"}, {"input": "3 5 8\n 11100\n 10001\n 00111", "output": "0\n \n\nNo cut is needed.\n\n* * *"}, {"input": "4 10 4\n 1110010010\n 1000101110\n 0011101001\n 1101000111", "output": "3"}] |
Print the number of minimum times the bar needs to be cut so that every block
after the cuts has K or less white squares.
* * * | s083350936 | Accepted | p02733 | Input is given from Standard Input in the following format:
H W K
S_{1,1}S_{1,2}...S_{1,W}
:
S_{H,1}S_{H,2}...S_{H,W} | def e_dividing_chocolate():
# 参考: https://note.com/tanon_cp/n/ne70a87d249ed
H, W, K = [int(i) for i in input().split()]
Choco = [list(input()) for _ in range(H)]
# 左上のマスを (0, 0)、右下のマスを (col, row) としたとき、2 点で張られる
# 長方形区間の内部に含まれる 1 (ホワイトチョコレートのマス) の数を累積和で管理
cumsum = [[0] * W for _ in range(H)]
for row in range(H):
for col in range(W):
if Choco[row][col] == "1":
cumsum[row][col] += 1
if row != 0:
cumsum[row][col] += cumsum[row - 1][col]
if col != 0:
cumsum[row][col] += cumsum[row][col - 1]
if row != 0 and col != 0:
cumsum[row][col] -= cumsum[row - 1][col - 1]
def count_white_chocolate(x1, y1, x2, y2):
"""左上のマスを (x1, y1)、右下のマスを (x2, y2) としたとき、2 点で張られる
長方形区間の内部に含まれる 1 (ホワイトチョコレートのマス) の数"""
ret = cumsum[y2][x2]
if x1 != 0:
ret -= cumsum[y2][x1 - 1]
if y1 != 0:
ret -= cumsum[y1 - 1][x2]
if x1 != 0 and y1 != 0:
ret += cumsum[y1 - 1][x1 - 1]
return ret
ans = (H - 1) + (W - 1) # 1 マスに分けてしまえば要求を満たすことは保証されている
# 横の切り方は全探索する
for bits in range(1 << (H - 1)):
count = 0 # 何回チョコに切り込みを入れたか?
# 横の切り込みをどこに入れるかを決める
cut_row = []
cut_flag = format(bits, "b")[::-1]
for k, flag in enumerate(cut_flag):
if flag == "1":
count += 1
# k 行目と (k+1) 行目の間を切るとき、長方形区間の最下段は k 行目
cut_row.append(k)
cut_row.append(H - 1) # チョコ全体での最下段も加えておく
# col1-col2 の間は切り込みを入れないでもホワイトチョコが K 個以下である
col1 = 0
for col2 in range(W - 1):
row1 = 0
for row2 in cut_row:
if count_white_chocolate(col1, row1, col2, row2) > K:
count = float(
"inf"
) # 現在の横の切り込みの入れ方では要求を満たせない
# col2 列目と col2+1 列目の間に縦に切り込みを入れなければならない
if (
count_white_chocolate(col1, row1, col2, row2) <= K
and count_white_chocolate(col1, row1, col2 + 1, row2) > K
):
# ここで縦に切り込みを入れ、右の区画へ移動
count += 1
col1 = col2 + 1
break
row1 = row2 + 1 # 下の区画へ移動
# 最後に縦に切り込みを入れた区画の右の区画はまだ調べていないので、調べる
row1 = 0
for row2 in cut_row:
if count_white_chocolate(col1, row1, W - 1, row2) > K:
count = float("inf")
row1 = row2 + 1
ans = min(ans, count)
return ans
print(e_dividing_chocolate())
| Statement
We have a chocolate bar partitioned into H horizontal rows and W vertical
columns of squares.
The square (i, j) at the i-th row from the top and the j-th column from the
left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`.
We will cut the bar some number of times to divide it into some number of
blocks. In each cut, we cut the whole bar by a line running along some
boundaries of squares from end to end of the bar.
How many times do we need to cut the bar so that every block after the cuts
has K or less white squares? | [{"input": "3 5 4\n 11100\n 10001\n 00111", "output": "2\n \n\nFor example, cutting between the 1-st and 2-nd rows and between the 3-rd and\n4-th columns - as shown in the figure to the left - works.\n\nNote that we cannot cut the bar in the ways shown in the two figures to the\nright.\n\n\n\n* * *"}, {"input": "3 5 8\n 11100\n 10001\n 00111", "output": "0\n \n\nNo cut is needed.\n\n* * *"}, {"input": "4 10 4\n 1110010010\n 1000101110\n 0011101001\n 1101000111", "output": "3"}] |
Print the number of minimum times the bar needs to be cut so that every block
after the cuts has K or less white squares.
* * * | s774048607 | Accepted | p02733 | Input is given from Standard Input in the following format:
H W K
S_{1,1}S_{1,2}...S_{1,W}
:
S_{H,1}S_{H,2}...S_{H,W} | def read():
H, W, K = list(map(int, input().strip().split()))
S = list()
for i in range(H):
s = list(map(int, input()))
S.append(s)
return H, W, K, S
def init_n_splits(H, ptn):
n_splits = 0
for h in range(1, H):
if ptn & 1 == 1:
n_splits += 1
ptn >>= 1
return n_splits
def check_first_column(w, H, K, ptn, S):
k = [0 for h in range(H)]
k[0] = S[0][w]
if k[0] > K:
return [-1 for h in range(H)]
for h in range(1, H):
if ptn & 1 == 1:
k[h] = S[h][w]
else:
k[h] = S[h][w] + k[h - 1]
if k[h] > K:
return [-1 for h in range(H)]
ptn >>= 1
return k
def check_next_column(w, H, K, ptn, S, prev):
k = [0 for h in range(H)]
k[0] = S[0][w]
if k[0] + prev[0] > K:
return [-1 for h in range(H)]
for h in range(1, H):
if ptn & 1 == 1:
k[h] = S[h][w]
else:
k[h] = S[h][w] + k[h - 1]
if k[h] + prev[h] > K:
return [-1 for h in range(H)]
ptn >>= 1
return [i + j for i, j in zip(k, prev)]
def solve(H, W, K, S, INF=10000000):
ptns = 2 ** (H - 1)
min_n_splits = W * H
for ptn in range(ptns):
update = True
n_splits = init_n_splits(H, ptn)
ret = check_first_column(0, H, K, ptn, S)
if ret[0] == -1:
update = False
else:
for w in range(1, W):
prev = ret
ret = check_next_column(w, H, K, ptn, S, prev)
if ret[0] == -1:
n_splits += 1
ret = check_first_column(w, H, K, ptn, S)
if ret[0] == -1:
update = False
break
if update:
min_n_splits = min(n_splits, min_n_splits)
return min_n_splits
if __name__ == "__main__":
inputs = read()
print("{}".format(solve(*inputs)))
| Statement
We have a chocolate bar partitioned into H horizontal rows and W vertical
columns of squares.
The square (i, j) at the i-th row from the top and the j-th column from the
left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`.
We will cut the bar some number of times to divide it into some number of
blocks. In each cut, we cut the whole bar by a line running along some
boundaries of squares from end to end of the bar.
How many times do we need to cut the bar so that every block after the cuts
has K or less white squares? | [{"input": "3 5 4\n 11100\n 10001\n 00111", "output": "2\n \n\nFor example, cutting between the 1-st and 2-nd rows and between the 3-rd and\n4-th columns - as shown in the figure to the left - works.\n\nNote that we cannot cut the bar in the ways shown in the two figures to the\nright.\n\n\n\n* * *"}, {"input": "3 5 8\n 11100\n 10001\n 00111", "output": "0\n \n\nNo cut is needed.\n\n* * *"}, {"input": "4 10 4\n 1110010010\n 1000101110\n 0011101001\n 1101000111", "output": "3"}] |
Print the number of minimum times the bar needs to be cut so that every block
after the cuts has K or less white squares.
* * * | s057904155 | Accepted | p02733 | Input is given from Standard Input in the following format:
H W K
S_{1,1}S_{1,2}...S_{1,W}
:
S_{H,1}S_{H,2}...S_{H,W} | import itertools
H, W, K = map(int, input().split())
A = [[int(x) for x in input()] for _ in range(H)]
def solve(blocks):
n_block = len(blocks)
n_cut = n_block - 1
sums = [0 for _ in range(n_block)]
for c in range(W):
adds = [block[c] for block in blocks]
if any(a > K for a in adds):
return H * W
sums = [s + a for s, a in zip(sums, adds)]
if any(s > K for s in sums):
n_cut += 1
sums = adds
return n_cut
ans = H * W
for mask in itertools.product([0, 1], repeat=H - 1):
mask = [1] + list(mask) + [1]
pivots = [r for r in range(H + 1) if mask[r]]
blocks = [A[p1:p2] for p1, p2 in zip(pivots[:-1], pivots[1:])]
blocks = [[sum(row[c] for row in block) for c in range(W)] for block in blocks]
ans = min(ans, solve(blocks))
print(ans)
| Statement
We have a chocolate bar partitioned into H horizontal rows and W vertical
columns of squares.
The square (i, j) at the i-th row from the top and the j-th column from the
left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`.
We will cut the bar some number of times to divide it into some number of
blocks. In each cut, we cut the whole bar by a line running along some
boundaries of squares from end to end of the bar.
How many times do we need to cut the bar so that every block after the cuts
has K or less white squares? | [{"input": "3 5 4\n 11100\n 10001\n 00111", "output": "2\n \n\nFor example, cutting between the 1-st and 2-nd rows and between the 3-rd and\n4-th columns - as shown in the figure to the left - works.\n\nNote that we cannot cut the bar in the ways shown in the two figures to the\nright.\n\n\n\n* * *"}, {"input": "3 5 8\n 11100\n 10001\n 00111", "output": "0\n \n\nNo cut is needed.\n\n* * *"}, {"input": "4 10 4\n 1110010010\n 1000101110\n 0011101001\n 1101000111", "output": "3"}] |
Print the number of minimum times the bar needs to be cut so that every block
after the cuts has K or less white squares.
* * * | s293777923 | Accepted | p02733 | Input is given from Standard Input in the following format:
H W K
S_{1,1}S_{1,2}...S_{1,W}
:
S_{H,1}S_{H,2}...S_{H,W} | from collections import Counter
H, W, K = [int(x) for x in input().split()]
grid = [[int(x) for x in input()] for r in range(H)]
best = float("inf")
for cuts in range(2**H):
# Initialize numCuts to the number of horizontal cuts
hCutIndices = [r for r in range(H) if (1 << r) & cuts]
numCuts = len(hCutIndices)
# The count for each horizontal cut since last cut
cumulativeCount = Counter()
for c in range(W):
# The count for each horizontal cut for this column
columnCount = {}
curr = 0
for r in range(H):
curr += grid[r][c]
if (1 << r) & cuts or r == H - 1: # Note: last row is always a cut
columnCount[r] = curr
curr = 0
# Add column count to cumulative count if possible
if all(cumulativeCount[r] + columnCount[r] <= K for r in columnCount):
for r in columnCount:
cumulativeCount[r] += columnCount[r]
else:
# Cut and reset cumulative count to this column
numCuts += 1
cumulativeCount = columnCount
# If counts within just the column is no good, the current set of horizontal cuts is impossible
if any(counts > K for r, counts in columnCount.items()):
numCuts = float("inf")
break
best = min(best, numCuts)
print(best)
| Statement
We have a chocolate bar partitioned into H horizontal rows and W vertical
columns of squares.
The square (i, j) at the i-th row from the top and the j-th column from the
left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`.
We will cut the bar some number of times to divide it into some number of
blocks. In each cut, we cut the whole bar by a line running along some
boundaries of squares from end to end of the bar.
How many times do we need to cut the bar so that every block after the cuts
has K or less white squares? | [{"input": "3 5 4\n 11100\n 10001\n 00111", "output": "2\n \n\nFor example, cutting between the 1-st and 2-nd rows and between the 3-rd and\n4-th columns - as shown in the figure to the left - works.\n\nNote that we cannot cut the bar in the ways shown in the two figures to the\nright.\n\n\n\n* * *"}, {"input": "3 5 8\n 11100\n 10001\n 00111", "output": "0\n \n\nNo cut is needed.\n\n* * *"}, {"input": "4 10 4\n 1110010010\n 1000101110\n 0011101001\n 1101000111", "output": "3"}] |
Print the number of minimum times the bar needs to be cut so that every block
after the cuts has K or less white squares.
* * * | s921023542 | Wrong Answer | p02733 | Input is given from Standard Input in the following format:
H W K
S_{1,1}S_{1,2}...S_{1,W}
:
S_{H,1}S_{H,2}...S_{H,W} | def bit(n, k):
return (n >> k) & 1
n, m, k = (int(i) for i in input().split())
f = [input() for i in range(n)]
# print(len(f[0]));
res = n * m
for mask in range(2 ** (n - 1)):
cnt = [0 for i in range(n)]
curr = 0
for i in range(n):
curr += bit(mask, i)
for i in range(m):
add = [0 for t in range(n)]
ind = 0
for j in range(n):
if bit(mask, j) == 1:
ind += 1
# print(i, j);
add[ind] += int(f[j][i])
# add[ind] = 1;
correct = True
for j in range(n):
if add[j] + cnt[j] > k:
correct = False
if correct == True:
for j in range(n):
cnt[j] += add[j]
continue
curr += 1
for j in range(n):
cnt[j] = add[j]
res = min(res, curr)
print(res)
| Statement
We have a chocolate bar partitioned into H horizontal rows and W vertical
columns of squares.
The square (i, j) at the i-th row from the top and the j-th column from the
left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`.
We will cut the bar some number of times to divide it into some number of
blocks. In each cut, we cut the whole bar by a line running along some
boundaries of squares from end to end of the bar.
How many times do we need to cut the bar so that every block after the cuts
has K or less white squares? | [{"input": "3 5 4\n 11100\n 10001\n 00111", "output": "2\n \n\nFor example, cutting between the 1-st and 2-nd rows and between the 3-rd and\n4-th columns - as shown in the figure to the left - works.\n\nNote that we cannot cut the bar in the ways shown in the two figures to the\nright.\n\n\n\n* * *"}, {"input": "3 5 8\n 11100\n 10001\n 00111", "output": "0\n \n\nNo cut is needed.\n\n* * *"}, {"input": "4 10 4\n 1110010010\n 1000101110\n 0011101001\n 1101000111", "output": "3"}] |
Print the number of minimum times the bar needs to be cut so that every block
after the cuts has K or less white squares.
* * * | s771452168 | Accepted | p02733 | Input is given from Standard Input in the following format:
H W K
S_{1,1}S_{1,2}...S_{1,W}
:
S_{H,1}S_{H,2}...S_{H,W} | def create_groups(H):
F = "{:0" + str(H) + "b}"
ret = set()
for n in range(2**H):
g = create_group(F.format(n))
ret.add(tuple(g))
return list(sorted(ret))
def create_group(s):
ret = []
n = 0
for i in range(len(s)):
if i == 0:
ret.append(0)
else:
if s[i - 1] == s[i]:
ret.append(n)
else:
n += 1
ret.append(n)
return ret
# assert(create_group("0000") == [0,0,0,0])
# assert(create_group("0011") == [0,0,1,1])
# assert(create_group("0010") == [0,0,1,2])
# print(len(create_groups(10)))
def solve(H, W, K, fields):
ans = H * W + 1
for g in create_groups(H):
M = len(set(g))
s = [0 for _ in range(M)]
tans = M - 1
for w in range(W):
for h in range(H):
if fields[h][w] == "1":
s[g[h]] += 1
if any([a > K for a in s]):
s = [0 for _ in range(M)]
tans += 1
for h in range(H):
if fields[h][w] == "1":
s[g[h]] += 1
if any([a > K for a in s]):
tans = H * W + 1
break
ans = min(ans, tans)
return ans
#
# assert(solve(3, 3, 1, ["111", "111", "111"]) == 4)
# assert(solve(1, 1, 1, ["1"]) == 0)
# assert(solve(2, 1, 1, ["1", "1"]) == 1)
# assert(solve(1, 2, 1, ["11"]) == 1)
# assert(solve(1, 2, 1, ["11"]) == 1)
# assert(solve(3, 5, 4, ["11100", "10001", "00111"]) == 2)
# assert(solve(3, 5, 8, ["11100", "10001", "00111"]) == 0)
# assert(solve(4, 10, 4, ["1110010010", "1000101110", "0011101001", "1101000111"]) == 3)
# print(slowsolve(5, 11, "33883"))
# print(solve(5, 11, "33883"))
if __name__ == "__main__":
H, W, K = tuple(map(int, input().split(" ")))
fields = []
for _ in range(H):
fields.append(input())
print(solve(H, W, K, fields))
| Statement
We have a chocolate bar partitioned into H horizontal rows and W vertical
columns of squares.
The square (i, j) at the i-th row from the top and the j-th column from the
left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`.
We will cut the bar some number of times to divide it into some number of
blocks. In each cut, we cut the whole bar by a line running along some
boundaries of squares from end to end of the bar.
How many times do we need to cut the bar so that every block after the cuts
has K or less white squares? | [{"input": "3 5 4\n 11100\n 10001\n 00111", "output": "2\n \n\nFor example, cutting between the 1-st and 2-nd rows and between the 3-rd and\n4-th columns - as shown in the figure to the left - works.\n\nNote that we cannot cut the bar in the ways shown in the two figures to the\nright.\n\n\n\n* * *"}, {"input": "3 5 8\n 11100\n 10001\n 00111", "output": "0\n \n\nNo cut is needed.\n\n* * *"}, {"input": "4 10 4\n 1110010010\n 1000101110\n 0011101001\n 1101000111", "output": "3"}] |
Print the number of minimum times the bar needs to be cut so that every block
after the cuts has K or less white squares.
* * * | s302042135 | Wrong Answer | p02733 | Input is given from Standard Input in the following format:
H W K
S_{1,1}S_{1,2}...S_{1,W}
:
S_{H,1}S_{H,2}...S_{H,W} | H, W, K = map(int, input().split())
mat = []
for i in range(H):
array = [int(x) for x in input()]
mat.append(array)
# print(mat)
answer = 10**9
for i in range(2 ** (H - 1)):
bitarray = []
ii = i
for j in range(H - 1):
bitarray.append(ii & 1)
ii >>= 1
# print(bitarray)
segment_list = []
segment = [0]
for k in range(len(bitarray)):
if bitarray[k] == 0:
segment.append(k + 1)
else:
segment_list.append(segment)
segment = [k + 1]
segment_list.append(segment)
divide_yoko = len(segment_list) - 1
# print(segment_list,divide_yoko)
white_list_segment = [0] * len(segment_list)
sep_list = []
for j in range(W):
white_list_segment_line = [0] * len(segment_list)
for k in range(len(segment_list)):
seg = segment_list[k]
for s in seg:
white_list_segment_line[k] += mat[s][j]
isLineOver = False
if max(white_list_segment_line) > K:
isLineOver = True
break
isOver = False
for k in range(len(segment_list)):
if white_list_segment[k] + white_list_segment_line[k] > K:
isOver = True
break
if isOver:
sep_list.append(j - 1)
for k in range(len(segment_list)):
white_list_segment[k] = white_list_segment_line[k]
else:
for k in range(len(segment_list)):
white_list_segment[k] += white_list_segment_line[k]
answer = min(answer, len(segment_list) - 1 + len(sep_list))
# print(len(segment_list)-1+len(sep_list),segment_list,sep_list)
print(answer)
| Statement
We have a chocolate bar partitioned into H horizontal rows and W vertical
columns of squares.
The square (i, j) at the i-th row from the top and the j-th column from the
left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`.
We will cut the bar some number of times to divide it into some number of
blocks. In each cut, we cut the whole bar by a line running along some
boundaries of squares from end to end of the bar.
How many times do we need to cut the bar so that every block after the cuts
has K or less white squares? | [{"input": "3 5 4\n 11100\n 10001\n 00111", "output": "2\n \n\nFor example, cutting between the 1-st and 2-nd rows and between the 3-rd and\n4-th columns - as shown in the figure to the left - works.\n\nNote that we cannot cut the bar in the ways shown in the two figures to the\nright.\n\n\n\n* * *"}, {"input": "3 5 8\n 11100\n 10001\n 00111", "output": "0\n \n\nNo cut is needed.\n\n* * *"}, {"input": "4 10 4\n 1110010010\n 1000101110\n 0011101001\n 1101000111", "output": "3"}] |
Print the number of minimum times the bar needs to be cut so that every block
after the cuts has K or less white squares.
* * * | s831965725 | Wrong Answer | p02733 | Input is given from Standard Input in the following format:
H W K
S_{1,1}S_{1,2}...S_{1,W}
:
S_{H,1}S_{H,2}...S_{H,W} | h, w, k = map(int, input().split())
li_hw = []
for l in range(h):
a = map(str, input().split())
li = []
for i in a:
li_hw.append(list(i))
all_h = []
score = []
for l in range(2 ** (h - 1)):
ind = []
pre = 0
cut_list = []
hline_num = 0
for n, yn in enumerate(reversed(list(bin(l))[2:])):
if yn == "1":
cut_list.append(li_hw[pre : n + 1])
pre = n + 1
cut_list.append(li_hw[pre:h])
hline_num = list(bin(l)).count("1")
# print(bin(l))
pred = 0
wline_num = 0
# print("list is {}".format(cut_list))
for y in range(w):
wcounter_list = []
for c in cut_list:
wcounter = 0
for c2 in c:
wcounter += c2[pred : y + 1].count("1")
wcounter_list.append(wcounter)
# print("wcounter{}".format(wcounter_list))
if max(wcounter_list) > k:
pred = y
wline_num += 1
# print("line between{}and{}".format(y-1, y))
print("wline{}, hline{}".format(wline_num, hline_num))
score.append(wline_num + hline_num)
print(min(score))
| Statement
We have a chocolate bar partitioned into H horizontal rows and W vertical
columns of squares.
The square (i, j) at the i-th row from the top and the j-th column from the
left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`.
We will cut the bar some number of times to divide it into some number of
blocks. In each cut, we cut the whole bar by a line running along some
boundaries of squares from end to end of the bar.
How many times do we need to cut the bar so that every block after the cuts
has K or less white squares? | [{"input": "3 5 4\n 11100\n 10001\n 00111", "output": "2\n \n\nFor example, cutting between the 1-st and 2-nd rows and between the 3-rd and\n4-th columns - as shown in the figure to the left - works.\n\nNote that we cannot cut the bar in the ways shown in the two figures to the\nright.\n\n\n\n* * *"}, {"input": "3 5 8\n 11100\n 10001\n 00111", "output": "0\n \n\nNo cut is needed.\n\n* * *"}, {"input": "4 10 4\n 1110010010\n 1000101110\n 0011101001\n 1101000111", "output": "3"}] |
Print the number of minimum times the bar needs to be cut so that every block
after the cuts has K or less white squares.
* * * | s398049192 | Runtime Error | p02733 | Input is given from Standard Input in the following format:
H W K
S_{1,1}S_{1,2}...S_{1,W}
:
S_{H,1}S_{H,2}...S_{H,W} | import numpy as np
def str_to_array(rows):
array = []
for row in rows:
col_array = []
array.append(col_array)
for column in row:
col_array.append(int(column))
return np.array(array)
H, W, K = (int(n) for n in input().split(" "))
rows = []
for i in range(H):
rows.append(input())
choco = str_to_array(rows)
cuts = 0
while np.sum(choco) > K:
cuts += 1
min_diff = H * W
choco_left = None
for i in range(1, H - 1):
top = choco[:i]
bot = choco[i:]
top_sum = np.sum(top)
bot_sum = np.sum(bot)
diff = np.abs(top_sum - bot_sum)
if diff < min_diff:
if top_sum <= K:
choco_left = bot
min_diff = diff
elif bot_sum <= K:
choco_left = top
min_diff = diff
for i in range(1, W - 1):
left = choco[:, :i]
right = choco[:, i:]
left_sum = np.sum(left)
right_sum = np.sum(right)
diff = np.abs(left_sum - right_sum)
if diff < min_diff:
if left_sum <= K:
choco_left = right
min_diff = diff
elif right_sum <= K:
choco_left = left
min_diff = diff
choco = choco_left
print(cuts)
| Statement
We have a chocolate bar partitioned into H horizontal rows and W vertical
columns of squares.
The square (i, j) at the i-th row from the top and the j-th column from the
left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`.
We will cut the bar some number of times to divide it into some number of
blocks. In each cut, we cut the whole bar by a line running along some
boundaries of squares from end to end of the bar.
How many times do we need to cut the bar so that every block after the cuts
has K or less white squares? | [{"input": "3 5 4\n 11100\n 10001\n 00111", "output": "2\n \n\nFor example, cutting between the 1-st and 2-nd rows and between the 3-rd and\n4-th columns - as shown in the figure to the left - works.\n\nNote that we cannot cut the bar in the ways shown in the two figures to the\nright.\n\n\n\n* * *"}, {"input": "3 5 8\n 11100\n 10001\n 00111", "output": "0\n \n\nNo cut is needed.\n\n* * *"}, {"input": "4 10 4\n 1110010010\n 1000101110\n 0011101001\n 1101000111", "output": "3"}] |
Print the number of minimum times the bar needs to be cut so that every block
after the cuts has K or less white squares.
* * * | s788734133 | Runtime Error | p02733 | Input is given from Standard Input in the following format:
H W K
S_{1,1}S_{1,2}...S_{1,W}
:
S_{H,1}S_{H,2}...S_{H,W} | import numpy as np
h, w, k = (int(x) for x in input().split())
s_list = np.array([[x for x in input()] for _ in range(h)])
cut_num = h + w - 2
def clear(c_list):
c_w = [0]
c_h = [0]
for c in c_list:
if c < w:
c_w.append(c)
else:
c_h.append(c - w + 1)
c_w.append(w)
c_h.append(h)
flg = True
for i in range(1, len(c_w)):
for j in range(1, len(c_h)):
field = s_list[c_h[j - 1] : c_h[j], c_w[i - 1] : c_w[i]]
if np.count_nonzero(field == "1") > k:
flg = False
break
return flg
def cut(c_list, k):
if k > cut_num:
if clear(c_list):
return len(c_list)
else:
return cut_num + 1
c_list.append(k)
x = cut(c_list, k + 1)
c_list.remove(k)
x = min(x, cut(c_list, k + 1))
return x
x = cut([], 1)
print(x)
| Statement
We have a chocolate bar partitioned into H horizontal rows and W vertical
columns of squares.
The square (i, j) at the i-th row from the top and the j-th column from the
left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`.
We will cut the bar some number of times to divide it into some number of
blocks. In each cut, we cut the whole bar by a line running along some
boundaries of squares from end to end of the bar.
How many times do we need to cut the bar so that every block after the cuts
has K or less white squares? | [{"input": "3 5 4\n 11100\n 10001\n 00111", "output": "2\n \n\nFor example, cutting between the 1-st and 2-nd rows and between the 3-rd and\n4-th columns - as shown in the figure to the left - works.\n\nNote that we cannot cut the bar in the ways shown in the two figures to the\nright.\n\n\n\n* * *"}, {"input": "3 5 8\n 11100\n 10001\n 00111", "output": "0\n \n\nNo cut is needed.\n\n* * *"}, {"input": "4 10 4\n 1110010010\n 1000101110\n 0011101001\n 1101000111", "output": "3"}] |
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`.
* * * | s588132781 | Wrong Answer | p02699 | Input is given from Standard Input in the following format:
S W | func = lambda N=input(): "Yes" if "7" in N else "No"
print(func())
| Statement
There are S sheep and W wolves.
If the number of wolves is greater than or equal to that of sheep, the wolves
will attack the sheep.
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`. | [{"input": "4 5", "output": "unsafe\n \n\nThere are four sheep and five wolves. The number of wolves is not less than\nthat of sheep, so they will attack them.\n\n* * *"}, {"input": "100 2", "output": "safe\n \n\nMany a sheep drive away two wolves.\n\n* * *"}, {"input": "10 10", "output": "unsafe"}] |
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`.
* * * | s731698900 | Wrong Answer | p02699 | Input is given from Standard Input in the following format:
S W | print("Yes") if "7" in input() else print("No")
| Statement
There are S sheep and W wolves.
If the number of wolves is greater than or equal to that of sheep, the wolves
will attack the sheep.
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`. | [{"input": "4 5", "output": "unsafe\n \n\nThere are four sheep and five wolves. The number of wolves is not less than\nthat of sheep, so they will attack them.\n\n* * *"}, {"input": "100 2", "output": "safe\n \n\nMany a sheep drive away two wolves.\n\n* * *"}, {"input": "10 10", "output": "unsafe"}] |
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`.
* * * | s662554397 | Wrong Answer | p02699 | Input is given from Standard Input in the following format:
S W | {
"kernelspecs": {
"python3": {
"resource_dir": "C:\\Users\\Xergalese\\anaconda3\\share\\jupyter\\kernels\\python3",
"spec": {
"argv": [
"C:/Users/Xergalese/anaconda3\\python.exe",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}",
],
"env": {},
"display_name": "Python 3",
"language": "python",
"interrupt_mode": "signal",
"metadata": {},
},
}
}
}
| Statement
There are S sheep and W wolves.
If the number of wolves is greater than or equal to that of sheep, the wolves
will attack the sheep.
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`. | [{"input": "4 5", "output": "unsafe\n \n\nThere are four sheep and five wolves. The number of wolves is not less than\nthat of sheep, so they will attack them.\n\n* * *"}, {"input": "100 2", "output": "safe\n \n\nMany a sheep drive away two wolves.\n\n* * *"}, {"input": "10 10", "output": "unsafe"}] |
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`.
* * * | s643966022 | Wrong Answer | p02699 | Input is given from Standard Input in the following format:
S W | print("safe")
| Statement
There are S sheep and W wolves.
If the number of wolves is greater than or equal to that of sheep, the wolves
will attack the sheep.
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`. | [{"input": "4 5", "output": "unsafe\n \n\nThere are four sheep and five wolves. The number of wolves is not less than\nthat of sheep, so they will attack them.\n\n* * *"}, {"input": "100 2", "output": "safe\n \n\nMany a sheep drive away two wolves.\n\n* * *"}, {"input": "10 10", "output": "unsafe"}] |
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`.
* * * | s869954540 | Runtime Error | p02699 | Input is given from Standard Input in the following format:
S W | import sys
input = lambda: sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
c, d = map(int, input().split())
XX = [int(i) for i in input().split()]
Y = []
YY = []
X = [0] * c
for i, x in enumerate(XX):
if x > 0:
Y.append(x)
X[i + 1] = x
else:
YY.append((-x, i + 1))
Y.sort()
Y = [0] + Y
YY.sort()
for x, i in YY:
X[i] = Y[x - 1] + 1
Y = Y[:x] + [Y[x - 1] + 1] + Y[x:]
edge = [[] for i in range(c)]
E = [0] * d
for i in range(d):
u, v = map(int, input().split())
edge[u - 1].append([v - 1, i])
edge[v - 1].append([u - 1, i])
D = [[] for i in range(1000)]
for i in range(1, c):
D[X[i]].append(i)
for i in range(1, 1000):
if not D[i]:
continue
else:
for goal in D[i]:
t_root = 0
dist = float("inf")
t_ind = 0
for root, ind in edge[goal]:
if X[root] < dist:
t_root = root
dist = X[root]
t_ind = ind
E[t_ind] = i - dist
for i in range(d):
if E[i] == 0:
E[i] = str(10**6)
else:
E[i] = str(E[i])
ans = " ".join(E)
print("Case #" + str(_ + 1) + ": " + ans)
| Statement
There are S sheep and W wolves.
If the number of wolves is greater than or equal to that of sheep, the wolves
will attack the sheep.
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`. | [{"input": "4 5", "output": "unsafe\n \n\nThere are four sheep and five wolves. The number of wolves is not less than\nthat of sheep, so they will attack them.\n\n* * *"}, {"input": "100 2", "output": "safe\n \n\nMany a sheep drive away two wolves.\n\n* * *"}, {"input": "10 10", "output": "unsafe"}] |
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`.
* * * | s619747880 | Runtime Error | p02699 | Input is given from Standard Input in the following format:
S W | A, B, C, D = map(int, input().split())
ans = "Yes"
curA = A
curC = C
for i in range(max(A, C)):
curC = curC - B
if curC <= 0:
ans = "Yes"
break
curA = curA - D
if curA <= 0:
ans = "No"
break
print(ans)
| Statement
There are S sheep and W wolves.
If the number of wolves is greater than or equal to that of sheep, the wolves
will attack the sheep.
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`. | [{"input": "4 5", "output": "unsafe\n \n\nThere are four sheep and five wolves. The number of wolves is not less than\nthat of sheep, so they will attack them.\n\n* * *"}, {"input": "100 2", "output": "safe\n \n\nMany a sheep drive away two wolves.\n\n* * *"}, {"input": "10 10", "output": "unsafe"}] |
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`.
* * * | s066839080 | Runtime Error | p02699 | Input is given from Standard Input in the following format:
S W | # Aです
import sys
input = lambda: sys.stdin.readline().rstrip()
def f(x, y):
left, right = 0, 10**9
while right - left > 1:
mid = (left + right) // 2
if x * mid + mid * (mid - 1) // 2 <= y:
left = mid
else:
right = mid
return left
def f1(x, y):
left, right = 0, 10**9
while right - left > 1:
mid = (left + right) // 2
if x * mid + mid**2 <= y:
left = mid
else:
right = mid
return left
def f2(x, y):
left, right = 0, 10**9
while right - left > 1:
mid = (left + right) // 2
if x * mid + mid * (mid + 1) <= y:
left = mid
else:
right = mid
return left
t = int(input())
for _ in range(t):
l, r = map(int, input().split())
if l >= r:
d = l - r
ct = f(1, d)
l -= ct * (ct + 1) // 2
ct1 = f1(ct, l)
ct2 = f2(ct, r)
if ct1 <= ct2:
ans1 = ct + 2 * ct1
ans2 = l - ct * ct1 - ct1**2
ans3 = r - ct * ct1 - ct1 * (ct1 + 1)
else:
ans1 = ct + 2 * ct2 + 1
ans2 = l - ct * (ct2 + 1) - (ct2 + 1) ** 2
ans3 = r - ct * ct2 - ct2 * (ct2 + 1)
print(
"Case #" + str(_ + 1) + ": " + str(ans1) + " " + str(ans2) + " " + str(ans3)
)
else:
d = r - l
ct = f(1, d)
r -= ct * (ct + 1) // 2
if l == r:
ct1 = f1(ct, l)
ct2 = f2(ct, r)
if ct1 <= ct2:
ans1 = ct + 2 * ct1
ans2 = l - ct * ct1 - ct1**2
ans3 = r - ct * ct1 - ct1 * (ct1 + 1)
else:
ans1 = ct + 2 * ct2 + 1
ans2 = l - ct * (ct2 + 1) - (ct2 + 1) ** 2
ans3 = r - ct * ct2 - ct2 * (ct2 + 1)
print(
"Case #"
+ str(_ + 1)
+ ": "
+ str(ans1)
+ " "
+ str(ans2)
+ " "
+ str(ans3)
)
else:
ct1 = f1(ct, r)
ct2 = f2(ct, l)
if ct1 <= ct2:
ans1 = ct + 2 * ct1
ans3 = r - ct * ct1 - ct1**2
ans2 = l - ct * ct1 - ct1 * (ct1 + 1)
else:
ans1 = ct + 2 * ct2 + 1
ans3 = r - ct * (ct2 + 1) - (ct2 + 1) ** 2
ans2 = l - ct * ct2 - ct2 * (ct2 + 1)
print(
"Case #"
+ str(_ + 1)
+ ": "
+ str(ans1)
+ " "
+ str(ans2)
+ " "
+ str(ans3)
)
| Statement
There are S sheep and W wolves.
If the number of wolves is greater than or equal to that of sheep, the wolves
will attack the sheep.
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`. | [{"input": "4 5", "output": "unsafe\n \n\nThere are four sheep and five wolves. The number of wolves is not less than\nthat of sheep, so they will attack them.\n\n* * *"}, {"input": "100 2", "output": "safe\n \n\nMany a sheep drive away two wolves.\n\n* * *"}, {"input": "10 10", "output": "unsafe"}] |
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`.
* * * | s343753022 | Wrong Answer | p02699 | Input is given from Standard Input in the following format:
S W | n, s = map(int, input().split())
print("sefe") if n > s else print("unsafe")
| Statement
There are S sheep and W wolves.
If the number of wolves is greater than or equal to that of sheep, the wolves
will attack the sheep.
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`. | [{"input": "4 5", "output": "unsafe\n \n\nThere are four sheep and five wolves. The number of wolves is not less than\nthat of sheep, so they will attack them.\n\n* * *"}, {"input": "100 2", "output": "safe\n \n\nMany a sheep drive away two wolves.\n\n* * *"}, {"input": "10 10", "output": "unsafe"}] |
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`.
* * * | s724842228 | Wrong Answer | p02699 | Input is given from Standard Input in the following format:
S W | input(int())
| Statement
There are S sheep and W wolves.
If the number of wolves is greater than or equal to that of sheep, the wolves
will attack the sheep.
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`. | [{"input": "4 5", "output": "unsafe\n \n\nThere are four sheep and five wolves. The number of wolves is not less than\nthat of sheep, so they will attack them.\n\n* * *"}, {"input": "100 2", "output": "safe\n \n\nMany a sheep drive away two wolves.\n\n* * *"}, {"input": "10 10", "output": "unsafe"}] |
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`.
* * * | s711131053 | Runtime Error | p02699 | Input is given from Standard Input in the following format:
S W | s = input()
n = len(s)
if n < 4:
quit()
l, r = 0, 4
ans = [[[], []] for _ in range(n + 3)]
for i in range(4, 8):
l = 0
while l + i <= n:
if int(s[l : (l + i)]) % 2019 == 0:
ans[l + 1][0].append(l + i)
ans[l + i + 1][1].append(l + 1)
l += 1
final = 0
cnt = 1
for i in range(n + 1):
if ans[i][0] and ans[i][1]:
cnt += 1
final += cnt
elif ans[i][0]:
final += 1
cnt = 1
print(final)
| Statement
There are S sheep and W wolves.
If the number of wolves is greater than or equal to that of sheep, the wolves
will attack the sheep.
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`. | [{"input": "4 5", "output": "unsafe\n \n\nThere are four sheep and five wolves. The number of wolves is not less than\nthat of sheep, so they will attack them.\n\n* * *"}, {"input": "100 2", "output": "safe\n \n\nMany a sheep drive away two wolves.\n\n* * *"}, {"input": "10 10", "output": "unsafe"}] |
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`.
* * * | s465850970 | Accepted | p02699 | Input is given from Standard Input in the following format:
S W | # a = int(input())
b, c = list(map(int, input().split()))
# text = input()
print("safe") if b > c else print("unsafe")
| Statement
There are S sheep and W wolves.
If the number of wolves is greater than or equal to that of sheep, the wolves
will attack the sheep.
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`. | [{"input": "4 5", "output": "unsafe\n \n\nThere are four sheep and five wolves. The number of wolves is not less than\nthat of sheep, so they will attack them.\n\n* * *"}, {"input": "100 2", "output": "safe\n \n\nMany a sheep drive away two wolves.\n\n* * *"}, {"input": "10 10", "output": "unsafe"}] |
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`.
* * * | s351160795 | Accepted | p02699 | Input is given from Standard Input in the following format:
S W | sheep, wolf = list(map(int, input().split()))
result = "unsafe" if sheep <= wolf else "safe"
print(result)
| Statement
There are S sheep and W wolves.
If the number of wolves is greater than or equal to that of sheep, the wolves
will attack the sheep.
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`. | [{"input": "4 5", "output": "unsafe\n \n\nThere are four sheep and five wolves. The number of wolves is not less than\nthat of sheep, so they will attack them.\n\n* * *"}, {"input": "100 2", "output": "safe\n \n\nMany a sheep drive away two wolves.\n\n* * *"}, {"input": "10 10", "output": "unsafe"}] |
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`.
* * * | s541797869 | Runtime Error | p02699 | Input is given from Standard Input in the following format:
S W | n = int(input())
y = []
for x in range(n):
y.append(input())
print(len(set(y)))
| Statement
There are S sheep and W wolves.
If the number of wolves is greater than or equal to that of sheep, the wolves
will attack the sheep.
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`. | [{"input": "4 5", "output": "unsafe\n \n\nThere are four sheep and five wolves. The number of wolves is not less than\nthat of sheep, so they will attack them.\n\n* * *"}, {"input": "100 2", "output": "safe\n \n\nMany a sheep drive away two wolves.\n\n* * *"}, {"input": "10 10", "output": "unsafe"}] |
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`.
* * * | s850981231 | Runtime Error | p02699 | Input is given from Standard Input in the following format:
S W | s = input()
b = len(s)
c = 0
f = 0
while True:
if f == b:
break
elif b - f <= 2:
f = 0
b -= 1
else:
if int(s[f:b]) % 2019 == 0:
c += 1
f += 1
else:
f += 1
print(c)
| Statement
There are S sheep and W wolves.
If the number of wolves is greater than or equal to that of sheep, the wolves
will attack the sheep.
If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`. | [{"input": "4 5", "output": "unsafe\n \n\nThere are four sheep and five wolves. The number of wolves is not less than\nthat of sheep, so they will attack them.\n\n* * *"}, {"input": "100 2", "output": "safe\n \n\nMany a sheep drive away two wolves.\n\n* * *"}, {"input": "10 10", "output": "unsafe"}] |
If the graph contains a negative cycle (a cycle whose sum of edge costs is a
negative value), print
NEGATIVE CYCLE
in a line.
Otherwise, print
D0,0 D0,1 ... D0,|V|-1
D1,0 D1,1 ... D1,|V|-1
:
D|V|-1,0 D1,1 ... D|V|-1,|V|-1
The output consists of |V| lines. For each ith line, print the cost of the
shortest path from vertex i to each vertex j (j = 0, 1, ... |V|-1)
respectively. If there is no path from vertex i to vertex j, print "INF".
Print a space between the costs. | s486670269 | Accepted | p02363 | An edge-weighted graph G (V, E).
|V| |E|
s0 t0 d0
s1 t1 d1
:
s|E|-1 t|E|-1 d|E|-1
|V| is the number of vertices and |E| is the number of edges in G. The graph
vertices are named with the numbers 0, 1,..., |V|-1 respectively.
si and ti represent source and target vertices of i-th edge (directed) and di
represents the cost of the i-th edge. | # http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_C&lang=ja
# Johnsonのアルゴリズム
# Bellman-Ford法で負辺を消去した後、
# 各頂点からダイクストラを行う
from heapq import heappop, heappush
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
class BellmanFord:
"""
shortest_distance(): startノードから各ノードまでの最短距離
include_negative_cycle(): 負閉路の存在確認
"""
def __init__(self, V, edges, start):
"""
V : 頂点数
edges: (辺の始点,辺の終点,辺のコスト)を要素とする辺のリスト
start: 始点のノード番号
"""
self.V = V
self.edges = edges
self.start = start
def include_negative_cycle(self):
"""
負閉路の存在確認
Returns: True or False
"""
d = [0] * self.V
for i in range(self.V):
# start, end, cost
for s, e, c in self.edges:
if d[e] > d[s] + c:
d[e] = d[s] + c
# V回目にも更新があるなら負の閉路が存在する
if i == self.V - 1:
return True
return False
def shortest_distance(self):
"""
始点から各頂点までの最短距離をを返す
負閉路に到達可能ならば d[start] = INF
"""
d = [float("inf")] * self.V
d[self.start] = 0
loop_counter = 0
while True:
update = False
# start, end, cost
for s, e, c in self.edges:
if d[s] != float("inf") and d[e] > d[s] + c:
d[e] = d[s] + c
update = True
# 負閉路の到達しないならばループは高々V-1回
# ループ回数がV回の時点で更新があるならば負閉路に到達してしまう
loop_counter += 1
if loop_counter == self.V and update:
d[self.start] = float("inf")
break
if not update:
break
return d
class Dijkstra:
"""
shortest_distance(): startノードから各ノードまでの最短距離
"""
def __init__(self, graph, start):
"""
graph: 隣接リストによるグラフ
start: 始点のノード番号
"""
self.g = graph
self.V = len(graph)
# startノードからの最短距離
# startノードは0, それ以外は無限大で初期化
self.dist = [float("inf")] * self.V
self.dist[start] = 0
# startノードをキューに入れる
self.Q = []
heappush(self.Q, (0, start))
while self.Q:
# 優先度(距離)が最小であるキューを取り出す
dist_u, u = heappop(self.Q)
if dist_u > self.dist[u]:
continue
for v, weight in self.g[u]:
alt = self.dist[u] + weight
if alt < self.dist[v]:
self.dist[v] = alt
heappush(self.Q, (alt, v))
def shortest_distance(self):
return self.dist
def main():
V, E, *std = map(int, read().split())
Edges = []
for i in range(V):
Edges.append((V, i, 0))
for s, t, d in zip(*[iter(std)] * 3):
Edges.append((s, t, d))
# 超頂点からBellman-Ford O(VE)
bf = BellmanFord(V + 1, Edges, V)
h = bf.shortest_distance()
if float("inf") in h:
print("NEGATIVE CYCLE")
else:
Graph = [[] * V for _ in range(V)]
for s, t, d in Edges:
if s == V:
continue
else:
Graph[s].append((t, d + h[s] - h[t]))
ans = []
# 各頂点からDijkstra O(VElogV)
for i in range(V):
d = Dijkstra(Graph, i)
ans.append(d.shortest_distance())
# 重みを元に戻す O(V^2)
for i, line in enumerate(ans):
h_i = h[i]
for j, n in enumerate(line):
if n == float("inf"):
line[j] = "INF"
else:
line[j] -= h_i - h[j]
tmp = " ".join(map(str, line))
print(tmp)
if __name__ == "__main__":
main()
| All Pairs Shortest Path | [{"input": "4 6\n 0 1 1\n 0 2 5\n 1 2 2\n 1 3 4\n 2 3 1\n 3 2 7", "output": "0 1 3 4\n INF 0 2 3\n INF INF 0 1\n INF INF 7 0"}, {"input": "4 6\n 0 1 1\n 0 2 -5\n 1 2 2\n 1 3 4\n 2 3 1\n 3 2 7", "output": "0 1 -5 -4\n INF 0 2 3\n INF INF 0 1\n INF INF 7 0"}, {"input": "4 6\n 0 1 1\n 0 2 5\n 1 2 2\n 1 3 4\n 2 3 1\n 3 2 -7", "output": "NEGATIVE CYCLE"}] |
If the graph contains a negative cycle (a cycle whose sum of edge costs is a
negative value), print
NEGATIVE CYCLE
in a line.
Otherwise, print
D0,0 D0,1 ... D0,|V|-1
D1,0 D1,1 ... D1,|V|-1
:
D|V|-1,0 D1,1 ... D|V|-1,|V|-1
The output consists of |V| lines. For each ith line, print the cost of the
shortest path from vertex i to each vertex j (j = 0, 1, ... |V|-1)
respectively. If there is no path from vertex i to vertex j, print "INF".
Print a space between the costs. | s282868040 | Accepted | p02363 | An edge-weighted graph G (V, E).
|V| |E|
s0 t0 d0
s1 t1 d1
:
s|E|-1 t|E|-1 d|E|-1
|V| is the number of vertices and |E| is the number of edges in G. The graph
vertices are named with the numbers 0, 1,..., |V|-1 respectively.
si and ti represent source and target vertices of i-th edge (directed) and di
represents the cost of the i-th edge. | V, E = map(int, input().split())
cost_matrix = [[float("inf")] * V for _ in range(V)]
for i in range(V):
cost_matrix[i][i] = 0
for i in range(E):
start, end, cost = map(int, input().split())
cost_matrix[start][end] = cost
for stop in range(V):
for start in range(V):
for end in range(V):
cost_matrix[start][end] = min(
cost_matrix[start][end],
cost_matrix[start][stop] + cost_matrix[stop][end],
)
is_negative = False
for start in range(V):
for end in range(V):
if cost_matrix[start][end] < 0 and start == end:
is_negative = True
elif cost_matrix[start][end] == float("inf"):
cost_matrix[start][end] = "INF"
if is_negative:
print("NEGATIVE CYCLE")
else:
for start in range(V):
res = list(map(str, cost_matrix[start]))
print(" ".join(res))
| All Pairs Shortest Path | [{"input": "4 6\n 0 1 1\n 0 2 5\n 1 2 2\n 1 3 4\n 2 3 1\n 3 2 7", "output": "0 1 3 4\n INF 0 2 3\n INF INF 0 1\n INF INF 7 0"}, {"input": "4 6\n 0 1 1\n 0 2 -5\n 1 2 2\n 1 3 4\n 2 3 1\n 3 2 7", "output": "0 1 -5 -4\n INF 0 2 3\n INF INF 0 1\n INF INF 7 0"}, {"input": "4 6\n 0 1 1\n 0 2 5\n 1 2 2\n 1 3 4\n 2 3 1\n 3 2 -7", "output": "NEGATIVE CYCLE"}] |
Print the number of strings of length N that satisfy the following conditions,
modulo 10^9+7.
* * * | s572446879 | Wrong Answer | p03088 | Input is given from Standard Input in the following format:
N | # 記念提出
N = int(input())
AA = [0] * (N + 1)
AG = [0] * (N + 1)
AC = [0] * (N + 1)
GG = [0] * (N + 1)
GA = [0] * (N + 1)
GC = [0] * (N + 1)
CC = [0] * (N + 1)
CA = [0] * (N + 1)
CG = [0] * (N + 1)
T_ = [0] * (N + 1)
_T = [0] * (N + 1)
TT = [0] * (N + 1)
AA[2], AG[2], AC[2], GG[2], GA[2], GC[2], CC[2], CA[2], CG[2], T_[2], _T[2], TT[2] = (
1,
1,
1,
1,
1,
1,
1,
1,
1,
3,
3,
1,
)
for i in range(3, N + 1):
AA[i] = AA[i - 1] + GA[i - 1] + CA[i - 1] + T_[i - 1] // 3
AG[i] = AA[i - 1] + GA[i - 1] + CA[i - 1] + T_[i - 1] // 3
AC[i] = AA[i - 1] + CA[i - 1] + T_[i - 1] // 3
GG[i] = AG[i - 1] + GG[i - 1] + CG[i - 1] + T_[i - 1] // 3
GA[i] = AG[i - 1] + GG[i - 1] + CG[i - 1] + T_[i - 1] // 3
GC[i] = GG[i - 1] + CG[i - 1] + T_[i - 1] // 3 - AG[i - 2] - _T[i - 2] // 3
CC[i] = AC[i - 1] + GC[i - 1] + CC[i - 1] + T_[i - 1] // 3
CA[i] = AC[i - 1] + GC[i - 1] + CC[i - 1] + T_[i - 1] // 3
CG[i] = GC[i - 1] + CC[i - 1] + T_[i - 1] // 3
T_[i] = _T[i - 1] * 3 + TT[i - 1] * 3 - AG[i - 2]
_T[i] = (
AA[i - 1]
+ AG[i - 1]
+ AC[i - 1]
+ GG[i - 1]
+ GA[i - 1]
+ GC[i - 1]
+ CC[i - 1]
+ CA[i - 1]
+ CG[i - 1]
+ T_[i - 1]
)
TT[i] = _T[i - 1] + TT[i - 1]
ans = (
AA[N]
+ AG[N]
+ AC[N]
+ GG[N]
+ GA[N]
+ GC[N]
+ CC[N]
+ CA[N]
+ CG[N]
+ T_[N]
+ _T[N]
+ TT[N]
)
print(ans % (10**9 + 7))
print(
AA[N], AG[N], AC[N], GG[N], GA[N], GC[N], CC[N], CA[N], CG[N], T_[N], _T[N], TT[N]
)
| Statement
You are given an integer N. Find the number of strings of length N that
satisfy the following conditions, modulo 10^9+7:
* The string does not contain characters other than `A`, `C`, `G` and `T`.
* The string does not contain `AGC` as a substring.
* The condition above cannot be violated by swapping two adjacent characters once. | [{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}] |
Print the number of strings of length N that satisfy the following conditions,
modulo 10^9+7.
* * * | s028870340 | Accepted | p03088 | Input is given from Standard Input in the following format:
N | N = int(input())
N += 1
dp = []
for l in range(N):
L = []
for i in range(4):
I = []
for j in range(4):
J = [0, 0, 0, 0]
I.append(J)
L.append(I)
dp.append(L)
dp[0][0][0][0] = 1
NGLIST_JKL = [
[1, 0, 2],
[1, 1, 2],
[1, 2, 2],
[1, 3, 2],
[1, 2, 0],
[1, 2, 1],
[1, 2, 2],
[1, 2, 3],
]
NGLIST_KLM = [[1, 2, 3], [2, 1, 3], [1, 3, 2]]
for i in range(N - 1):
for j in range(4):
for k in range(4):
for l in range(4):
if not [j, k, l] in NGLIST_JKL:
for m in range(4):
if not [k, l, m] in NGLIST_KLM:
dp[i + 1][k][l][m] += dp[i][j][k][l]
dp[i + 1][k][l][m] = dp[i + 1][k][l][m] % (10**9 + 7)
else:
if j == 1 and l == 2:
for m in range(4):
if m != 3:
dp[i + 1][k][l][m] += dp[i][j][k][l]
dp[i + 1][k][l][m] = dp[i + 1][k][l][m] % (10**9 + 7)
elif j == 1 and k == 2:
for m in range(4):
if m != 3:
dp[i + 1][k][l][m] += dp[i][j][k][l]
dp[i + 1][k][l][m] = dp[i + 1][k][l][m] % (10**9 + 7)
ans = 0
for i in range(4):
for j in range(4):
for k in range(4):
ans += dp[N - 1][i][j][k] % (10**9 + 7)
print(ans % (10**9 + 7))
| Statement
You are given an integer N. Find the number of strings of length N that
satisfy the following conditions, modulo 10^9+7:
* The string does not contain characters other than `A`, `C`, `G` and `T`.
* The string does not contain `AGC` as a substring.
* The condition above cannot be violated by swapping two adjacent characters once. | [{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}] |
Print the number of strings of length N that satisfy the following conditions,
modulo 10^9+7.
* * * | s321034559 | Accepted | p03088 | Input is given from Standard Input in the following format:
N | MOD = 10**9 + 7
aa = ["A", "C", "G", "T"]
dic = {}
invdic = {}
n = int(input())
for i in range(4):
for j in range(4):
for k in range(4):
dic[16 * i + 4 * j + k] = aa[i] + aa[j] + aa[k]
invdic[aa[i] + aa[j] + aa[k]] = 16 * i + 4 * j + k
dp = [[0 for j in range(64)] for i in range(101)]
for i in range(64):
dp[3][i] = 1
dp[3][invdic["AGC"]] = 0
dp[3][invdic["GAC"]] = 0
dp[3][invdic["ACG"]] = 0
for i in range(3, 100):
for j in range(64):
moji = dic[j]
if (
(moji[0] == "A" and moji[2] == "G")
or (moji[0] == "A" and moji[1] == "G")
or (moji[1] == "A" and moji[2] == "G")
or (moji[1] == "G" and moji[2] == "A")
):
dp[i + 1][invdic[moji[1] + moji[2] + "A"]] = (
dp[i + 1][invdic[moji[1] + moji[2] + "A"]] + dp[i][j]
) % MOD
dp[i + 1][invdic[moji[1] + moji[2] + "G"]] = (
dp[i + 1][invdic[moji[1] + moji[2] + "G"]] + dp[i][j]
) % MOD
dp[i + 1][invdic[moji[1] + moji[2] + "T"]] = (
dp[i + 1][invdic[moji[1] + moji[2] + "T"]] + dp[i][j]
) % MOD
elif moji[1] == "A" and moji[2] == "C":
dp[i + 1][invdic[moji[1] + moji[2] + "A"]] = (
dp[i + 1][invdic[moji[1] + moji[2] + "A"]] + dp[i][j]
) % MOD
dp[i + 1][invdic[moji[1] + moji[2] + "C"]] = (
dp[i + 1][invdic[moji[1] + moji[2] + "C"]] + dp[i][j]
) % MOD
dp[i + 1][invdic[moji[1] + moji[2] + "T"]] = (
dp[i + 1][invdic[moji[1] + moji[2] + "T"]] + dp[i][j]
) % MOD
else:
dp[i + 1][invdic[moji[1] + moji[2] + "A"]] = (
dp[i + 1][invdic[moji[1] + moji[2] + "A"]] + dp[i][j]
) % MOD
dp[i + 1][invdic[moji[1] + moji[2] + "C"]] = (
dp[i + 1][invdic[moji[1] + moji[2] + "C"]] + dp[i][j]
) % MOD
dp[i + 1][invdic[moji[1] + moji[2] + "T"]] = (
dp[i + 1][invdic[moji[1] + moji[2] + "T"]] + dp[i][j]
) % MOD
dp[i + 1][invdic[moji[1] + moji[2] + "G"]] = (
dp[i + 1][invdic[moji[1] + moji[2] + "G"]] + dp[i][j]
) % MOD
ans = 0
for i in range(64):
ans = (ans + dp[n][i]) % MOD
print(ans)
| Statement
You are given an integer N. Find the number of strings of length N that
satisfy the following conditions, modulo 10^9+7:
* The string does not contain characters other than `A`, `C`, `G` and `T`.
* The string does not contain `AGC` as a substring.
* The condition above cannot be violated by swapping two adjacent characters once. | [{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}] |
Print the number of strings of length N that satisfy the following conditions,
modulo 10^9+7.
* * * | s374768681 | Accepted | p03088 | Input is given from Standard Input in the following format:
N | # D - We Like AGC
import itertools, copy
N = int(input())
MOD = 10**9 + 7
if N == 3:
print(4**3 - 3)
exit()
# AGCそれ自体を含むか、1箇所入れ替えてAGCができてしまうような4文字
out_letters_4 = set()
for x in ["A", "C", "G", "T"]:
out_letters_4.add("A" + x + "GC")
out_letters_4.add("AG" + x + "C")
for y in ["AGC", "GAC", "ACG"]:
out_letters_4.add(x + y)
out_letters_4.add(y + x)
# 全4文字辞書
tmp = list(itertools.product(["A", "C", "G", "T"], repeat=4))
all_letters_4 = set()
for x in tmp:
tmp2 = ""
for y in x:
tmp2 += y
all_letters_4.add(tmp2)
possible_letters_4 = all_letters_4 - out_letters_4
# 文字を末尾に追加する前の末尾の4文字(key)、文字追加後の末尾の4文字(value)の辞書
trans_letters_4_dict = dict.fromkeys(possible_letters_4, -1)
for key in trans_letters_4_dict.keys():
for x in ["A", "C", "G", "T"]:
tmp = (key + x)[1:]
if tmp in trans_letters_4_dict.keys():
if trans_letters_4_dict[key] == -1:
trans_letters_4_dict[key] = [tmp]
else:
trans_letters_4_dict[key].append(tmp)
n_pattern = dict.fromkeys(possible_letters_4, 1)
for _ in range(N - 4):
next_n_pattern = dict.fromkeys(possible_letters_4, 0)
for former_key in possible_letters_4:
for to_key in trans_letters_4_dict[former_key]:
next_n_pattern[to_key] += n_pattern[former_key]
n_pattern = copy.deepcopy(next_n_pattern)
print(sum(n_pattern.values()) % MOD)
| Statement
You are given an integer N. Find the number of strings of length N that
satisfy the following conditions, modulo 10^9+7:
* The string does not contain characters other than `A`, `C`, `G` and `T`.
* The string does not contain `AGC` as a substring.
* The condition above cannot be violated by swapping two adjacent characters once. | [{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}] |
Print the number of strings of length N that satisfy the following conditions,
modulo 10^9+7.
* * * | s603421072 | Wrong Answer | p03088 | Input is given from Standard Input in the following format:
N | from collections import defaultdict
n = int(input())
MOD = 10**9 + 7
s = "ATGC"
t = ["AGC", "ACG", "GAC"]
# d = [defaultdict(int), {x+y+z: 1 for x in s for y in s for z in s if x+y+z not in t}]
d = [{"": 1}, defaultdict(int)]
# print(d[0])
for i in range(1, n + 1):
a = i % 2
b = (i - 1) % 2
d[a] = defaultdict(int)
for k in d[b]:
for c in s:
if len(k) < 2:
d[a][k + c] += d[b][k]
d[a][k + c] %= MOD
elif len(k) == 2:
if "AGC" not in [k + c, k[1] + k[0] + c, k[0] + c + k[1]]:
d[a][k + c] += d[b][k]
d[a][k + c] %= MOD
elif "AGC" not in [
k[1:] + c,
k[0] + k[2] + c,
k[2] + k[1] + c,
k[1] + c + k[2],
k[0] + k[1] + c,
]:
# if len(set(k+c)) >= 3:
# print(k+c)
d[a][k[1:] + c] += d[b][k]
d[a][k[1:] + c] %= MOD
# print(len(d[a]), sum(d[a].values()))
# print(d[a])
print(sum(d[n % 2].values()))
| Statement
You are given an integer N. Find the number of strings of length N that
satisfy the following conditions, modulo 10^9+7:
* The string does not contain characters other than `A`, `C`, `G` and `T`.
* The string does not contain `AGC` as a substring.
* The condition above cannot be violated by swapping two adjacent characters once. | [{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}] |
Print the number of strings of length N that satisfy the following conditions,
modulo 10^9+7.
* * * | s323662736 | Accepted | p03088 | Input is given from Standard Input in the following format:
N | # 18:29
n = int(input())
mod = 10**9 + 7
now = [[[0 for _ in range(4)] for _ in range(4)] for _ in range(4)]
now[3][3][3] = 1
# print(part)
boo = [
[0, 0, 1, 2],
[1, 0, 1, 2],
[2, 0, 1, 2],
[3, 0, 1, 2],
[0, 0, 1, 2],
[0, 1, 1, 2],
[0, 2, 1, 2],
[0, 3, 1, 2],
[0, 1, 0, 2],
[0, 1, 1, 2],
[0, 1, 2, 2],
[0, 1, 3, 2],
[0, 1, 0, 2],
[1, 1, 0, 2],
[2, 1, 0, 2],
[3, 1, 0, 2],
[0, 0, 2, 1],
[1, 0, 2, 1],
[2, 0, 2, 1],
[3, 0, 2, 1],
]
# print(now)
for i in range(n):
last = now
now = [[[0 for _ in range(4)] for _ in range(4)] for _ in range(4)]
# print(i,'l',last)
# print(i,'n',now)
for i in range(4):
for j in range(4):
for k in range(4):
for l in range(4):
if [i, j, k, l] not in boo:
now[j][k][l] += last[i][j][k]
now[j][k][l] %= mod
ans = 0
for i in range(4):
for j in range(4):
for k in range(4):
ans += now[i][j][k]
ans %= mod
# print(last)
# print(now)
print(ans)
| Statement
You are given an integer N. Find the number of strings of length N that
satisfy the following conditions, modulo 10^9+7:
* The string does not contain characters other than `A`, `C`, `G` and `T`.
* The string does not contain `AGC` as a substring.
* The condition above cannot be violated by swapping two adjacent characters once. | [{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}] |
Print the number of strings of length N that satisfy the following conditions,
modulo 10^9+7.
* * * | s888365030 | Wrong Answer | p03088 | Input is given from Standard Input in the following format:
N | n = int(input())
mod = 10**9 + 7
agc = [[1, 1, 1, 1], [4, 4, 4, 4], [16, 15, 14, 16]]
for i in range(n - 3):
sm = sum(agc[-1])
s = sm % mod
c = agc[-2][0] + agc[-3][0] * 2
g = agc[-2][0] + agc[-2][2]
cc, gg = sm, sm
while cc < c:
cc += sm
while gg < g:
gg += sm
# if c > sm:
# c -= c // sm * sm
# if g > sm:
# g -= g // sm * sm
a = [s, (cc - c) % mod, (gg - g) % mod, s]
# while a[1] < 0:
# a[1] += sm
# while a[2] < 0:
# a[2] += sm
agc.append(a)
# print(agc)
print(sum(agc[-1]))
# [61, 51, 57, 61]
| Statement
You are given an integer N. Find the number of strings of length N that
satisfy the following conditions, modulo 10^9+7:
* The string does not contain characters other than `A`, `C`, `G` and `T`.
* The string does not contain `AGC` as a substring.
* The condition above cannot be violated by swapping two adjacent characters once. | [{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}] |
Print the number of strings of length N that satisfy the following conditions,
modulo 10^9+7.
* * * | s875746583 | Accepted | p03088 | Input is given from Standard Input in the following format:
N | A = [0, 1, 4]
G = [0, 1, 4]
C = [0, 1, 4]
T = [0, 1, 4]
AG = [0, 0, 1]
GA = [0, 0, 1]
AC = [0, 0, 1]
AT = [0, 0, 1]
AGG = [0, 0, 0]
ATG = [0, 0, 0]
AGT = [0, 0, 0]
for i in range(2, 100):
A.append(A[i] + G[i] + C[i] + T[i])
G.append(A[i] + G[i] + C[i] + T[i] - AC[i])
C.append(A[i] + G[i] + C[i] + T[i] - AG[i] - GA[i] - AGG[i] - ATG[i] - AGT[i])
T.append(A[i] + G[i] + C[i] + T[i])
AG.append(A[i])
GA.append(G[i])
AC.append(A[i] - GA[i])
AT.append(A[i])
AGG.append(AG[i])
ATG.append(AT[i])
AGT.append(AG[i])
N = int(input())
print((A[N] + G[N] + C[N] + T[N]) % (10**9 + 7))
| Statement
You are given an integer N. Find the number of strings of length N that
satisfy the following conditions, modulo 10^9+7:
* The string does not contain characters other than `A`, `C`, `G` and `T`.
* The string does not contain `AGC` as a substring.
* The condition above cannot be violated by swapping two adjacent characters once. | [{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}] |
Print the number of strings of length N that satisfy the following conditions,
modulo 10^9+7.
* * * | s320421736 | Runtime Error | p03088 | Input is given from Standard Input in the following format:
N | ANS = [0, 0, 0, 61, 230, 865, 3247, 12185, 45719, 171531]
print(ANS[int(input())])
| Statement
You are given an integer N. Find the number of strings of length N that
satisfy the following conditions, modulo 10^9+7:
* The string does not contain characters other than `A`, `C`, `G` and `T`.
* The string does not contain `AGC` as a substring.
* The condition above cannot be violated by swapping two adjacent characters once. | [{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}] |
Print the number of strings of length N that satisfy the following conditions,
modulo 10^9+7.
* * * | s207176438 | Accepted | p03088 | Input is given from Standard Input in the following format:
N | from functools import lru_cache
def check(s):
bads = (
["AGC", "ACG", "GAC"]
+ ["AG{}C".format(_s) for _s in "ACGT"]
+ ["A{}GC".format(_s) for _s in "ACGT"]
)
return not any(map(lambda x: x in s, bads))
def solve(string):
n = int(string)
@lru_cache(n * 4**3)
def dfs(pos, last3):
if pos == n:
return 1
ans = 0
for _s in "ACGT":
ans += dfs(pos + 1, last3[1:] + _s) if check(last3 + _s) else 0
return ans % (10**9 + 7)
return str(dfs(0, "TTT"))
if __name__ == "__main__":
print(solve(input()))
| Statement
You are given an integer N. Find the number of strings of length N that
satisfy the following conditions, modulo 10^9+7:
* The string does not contain characters other than `A`, `C`, `G` and `T`.
* The string does not contain `AGC` as a substring.
* The condition above cannot be violated by swapping two adjacent characters once. | [{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}] |
Print the number of strings of length N that satisfy the following conditions,
modulo 10^9+7.
* * * | s494610475 | Accepted | p03088 | Input is given from Standard Input in the following format:
N | # ACGT
# 0123
# exclude the cases AGC, AXGC, GAC, ACG, AGXC
# AGGC TGAC GAGC AAGC AGTC GGAC AGAC CAGC GACG AGCC CACG CGAC AACG ACGC TAGC ATGC TACG
#
MOD = 10**9 + 7
n = int(input())
dp = [
[[[0 for _ in range(4)] for _ in range(4)] for _ in range(4)] for _ in range(n + 1)
]
for s in range(4):
for t in range(4):
for u in range(4):
dp[3][s][t][u] = 1
dp[3][0][2][1] = 0
dp[3][0][1][2] = 0
dp[3][2][0][1] = 0
for i in range(3, n):
for s in range(4):
for t in range(4):
for u in range(4):
for v in range(4):
dp[i + 1][t][u][v] = (dp[i + 1][t][u][v] + dp[i][s][t][u]) % MOD
dp[i + 1][2][2][1] -= dp[i][0][2][2]
dp[i + 1][2][0][1] -= dp[i][3][2][0]
dp[i + 1][0][2][1] -= dp[i][2][0][2]
dp[i + 1][0][2][1] -= dp[i][0][0][2]
dp[i + 1][2][3][1] -= dp[i][0][2][3]
dp[i + 1][2][0][1] -= dp[i][2][2][0]
dp[i + 1][2][0][1] -= dp[i][0][2][0]
dp[i + 1][0][2][1] -= dp[i][1][0][2]
dp[i + 1][0][1][2] -= dp[i][2][0][1]
dp[i + 1][2][1][1] -= dp[i][0][2][1]
dp[i + 1][0][1][2] -= dp[i][1][0][1]
dp[i + 1][2][0][1] -= dp[i][1][2][0]
dp[i + 1][0][1][2] -= dp[i][0][0][1]
dp[i + 1][1][2][1] -= dp[i][0][1][2]
dp[i + 1][0][2][1] -= dp[i][3][0][2]
dp[i + 1][3][2][1] -= dp[i][0][3][2]
dp[i + 1][0][1][2] -= dp[i][3][0][1]
print(sum(dp[n][s][t][u] for s in range(4) for t in range(4) for u in range(4)) % MOD)
| Statement
You are given an integer N. Find the number of strings of length N that
satisfy the following conditions, modulo 10^9+7:
* The string does not contain characters other than `A`, `C`, `G` and `T`.
* The string does not contain `AGC` as a substring.
* The condition above cannot be violated by swapping two adjacent characters once. | [{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}] |
Print the number of strings of length N that satisfy the following conditions,
modulo 10^9+7.
* * * | s847352406 | Accepted | p03088 | Input is given from Standard Input in the following format:
N | #!/usr/bin/env python
# coding: utf-8
# In[1]:
N = int(input())
# In[14]:
# N = 4
MOD = 10**9 + 7
# In[15]:
char = ["A", "C", "G", "T"]
S = [c1 + c2 + c3 for c1 in char for c2 in char for c3 in char]
S
# In[16]:
ng3 = ["AGC", "GAC", "ACG"]
ng4 = (
[c + ng for c in char for ng in ng3]
+ [ng + c for c in char for ng in ng3]
+ ["A" + c + "GC" for c in char]
+ ["AG" + c + "C" for c in char]
)
ng4 = set(ng4)
ng4
# In[17]:
dict1 = {s: 1 if s not in ng3 else 0 for s in S}
# In[18]:
for _ in range(N - 3):
dict2 = {}
for s in S:
val = 0
for c in char:
if c + s not in ng4:
val = (val + dict1[c + s[:2]]) % MOD
dict2[s] = val
dict1 = dict2
# In[19]:
ans = 0
for s in dict1.keys():
ans = (ans + dict1[s]) % MOD
print(ans)
# In[ ]:
| Statement
You are given an integer N. Find the number of strings of length N that
satisfy the following conditions, modulo 10^9+7:
* The string does not contain characters other than `A`, `C`, `G` and `T`.
* The string does not contain `AGC` as a substring.
* The condition above cannot be violated by swapping two adjacent characters once. | [{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}] |
Print the number of strings of length N that satisfy the following conditions,
modulo 10^9+7.
* * * | s439255559 | Wrong Answer | p03088 | Input is given from Standard Input in the following format:
N | n = int(input())
s = ["A", "C", "G", "T"]
list = []
cnt = 0
for h in range(10**4):
for i in range(3):
for j in range(3):
for k in range(3):
for l in range(3):
l = s[i] + s[j] + s[k] + s[l]
list.append(l)
for i in range(n):
if "AGC" in list[i]:
cnt += 1
print((4**3 - cnt) / (10**9 + 7))
| Statement
You are given an integer N. Find the number of strings of length N that
satisfy the following conditions, modulo 10^9+7:
* The string does not contain characters other than `A`, `C`, `G` and `T`.
* The string does not contain `AGC` as a substring.
* The condition above cannot be violated by swapping two adjacent characters once. | [{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}] |
Print the number of strings of length N that satisfy the following conditions,
modulo 10^9+7.
* * * | s988225989 | Accepted | p03088 | Input is given from Standard Input in the following format:
N | n = int(input())
mod = 10**9 + 7
A = [1] + [0] * (n - 1)
G = [1] + [0] * (n - 1)
T = [1] + [0] * (n - 1)
C = [1] + [0] * (n - 1)
##NG:: AGC,GAC,ACG
AG = [0] * n
GA = [0] * n
AC = [0] * n
##NG:: AGGC,AGTC,ATGC
AGG = [0] * n
AGT = [0] * n
ATG = [0] * n
for i in range(1, n):
tmp = A[i - 1] + G[i - 1] + C[i - 1] + T[i - 1]
A[i] = tmp % mod
T[i] = tmp % mod
G[i] = (tmp - AC[i - 1]) % mod
C[i] = (tmp - AG[i - 1] - GA[i - 1] - AGG[i - 1] - AGT[i - 1] - ATG[i - 1]) % mod
AG[i] = A[i - 1]
GA[i] = G[i - 1]
AC[i] = (A[i - 1] - GA[i - 1]) % mod
AGG[i] = AG[i - 1]
AGT[i] = AG[i - 1]
ATG[i] = A[i - 2] # == AT[i-1]
print((A[-1] + G[-1] + C[-1] + T[-1]) % mod)
# print(A,G,C,T)
# print(AG,GA,AC)
# print(AGG,AGT,ATG)
| Statement
You are given an integer N. Find the number of strings of length N that
satisfy the following conditions, modulo 10^9+7:
* The string does not contain characters other than `A`, `C`, `G` and `T`.
* The string does not contain `AGC` as a substring.
* The condition above cannot be violated by swapping two adjacent characters once. | [{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.