output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
Print the score. * * *
s634279439
Accepted
p03552
Input is given from Standard Input in the following format: N Z W a_1 a_2 ... a_N
n, z, w = map(int, input().split()) (*a,) = map(int, input().split()) # 添え字間違えたのでa逆 a.reverse() ans1 = 0 if len(a) > 1: ans1 = abs(a[1] - a[0]) ans2 = abs(a[0] - w) print(max(ans1, ans2))
Statement We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i. Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action: * Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn. The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand. X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?
[{"input": "3 100 100\n 10 1000 100", "output": "900\n \n\nIf X draws two cards first, Y will draw the last card, and the score will be\n|1000 - 100| = 900.\n\n* * *"}, {"input": "3 100 1000\n 10 100 100", "output": "900\n \n\nIf X draws all the cards first, the score will be |1000 - 100| = 900.\n\n* * *"}, {"input": "5 1 1\n 1 1 1 1 1", "output": "0\n \n\n* * *"}, {"input": "1 1 1\n 1000000000", "output": "999999999"}]
Print the score. * * *
s780202103
Accepted
p03552
Input is given from Standard Input in the following format: N Z W a_1 a_2 ... a_N
c = input() b = c.split() N = int(b[0]) Z = int(b[1]) W = int(b[2]) A = input().split() ans1 = abs(int(A[N - 1]) - W) ans2 = abs(int(A[N - 1]) - int(A[N - 2])) print(max(ans1, ans2))
Statement We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i. Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action: * Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn. The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand. X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?
[{"input": "3 100 100\n 10 1000 100", "output": "900\n \n\nIf X draws two cards first, Y will draw the last card, and the score will be\n|1000 - 100| = 900.\n\n* * *"}, {"input": "3 100 1000\n 10 100 100", "output": "900\n \n\nIf X draws all the cards first, the score will be |1000 - 100| = 900.\n\n* * *"}, {"input": "5 1 1\n 1 1 1 1 1", "output": "0\n \n\n* * *"}, {"input": "1 1 1\n 1000000000", "output": "999999999"}]
Print the answer. * * *
s429393398
Runtime Error
p03047
Input is given from Standard Input in the following format: N K
print(int(input()) + 1)
Statement Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
[{"input": "3 2", "output": "2\n \n\nThere are two ways to choose two consecutive integers: (1,2) and (2,3).\n\n* * *"}, {"input": "13 3", "output": "11"}]
Print the answer. * * *
s301876936
Runtime Error
p03047
Input is given from Standard Input in the following format: N K
import sys fin = sys.stdin.readline N = int(fin()) s_list = [fin().rstrip("\n") for _ in range(N)] num_AB_in_between = 0 s_Bhoge = 0 s_hogeA = 0 s_BA = 0 for s in s_list: if s[0] == "B" and s[-1] == "A": s_BA += 1 elif s[0] == "B": s_Bhoge += 1 elif s[-1] == "A": s_hogeA += 1 for i, char in enumerate(s[:-1]): next_char = s[i + 1] if char == "A" and next_char == "B": num_AB_in_between += 1 # print(s_Bhoge, s_hogeA, s_BA) if s_BA: num_AB_bound = 2 * s_BA - 2 + int(s_Bhoge > 0) + int(s_hogeA > 0) num_AB_bound += max(0, min(s_Bhoge - 1, s_hogeA - 1)) # num_AB_bound += min(s_Bhoge - 1, s_hogeA - 1) else: num_AB_bound = min(s_Bhoge, s_hogeA) print(num_AB_in_between + num_AB_bound)
Statement Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
[{"input": "3 2", "output": "2\n \n\nThere are two ways to choose two consecutive integers: (1,2) and (2,3).\n\n* * *"}, {"input": "13 3", "output": "11"}]
Print the answer. * * *
s104306224
Runtime Error
p03047
Input is given from Standard Input in the following format: N K
N = int(input()) s = "" point = 0 q1, q2, q3 = 0, 0, 0 # q1はBA q2はAの末尾のみ q3はBの最初のみ for j in range(N): n = str(input()) point += n.count("AB") if n[0] == "B" and n[len(n) - 1] == "A": q1 += 1 elif n[0] == "B": q2 += 1 elif n[len(n) - 1] == "A": q3 += 1 else: pass q1 -= 1 q2 -= 1 print(q1 - 1 + 2 + min(q3, q2) + point)
Statement Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
[{"input": "3 2", "output": "2\n \n\nThere are two ways to choose two consecutive integers: (1,2) and (2,3).\n\n* * *"}, {"input": "13 3", "output": "11"}]
Print the answer. * * *
s011316360
Runtime Error
p03047
Input is given from Standard Input in the following format: N K
n = int(input()) s = ["" for i in range(n)] for i in range(n): s[i] = input() # print(n,s) cnt = 0 cnta = 0 cntb = 0 cntab = 0 ans = 0 for i in range(n): cnt += s[i].count("AB") if s[i][-1] == "A" and s[i][0] == "B": cntab += 1 elif s[i][-1] == "A": cnta += 1 elif s[i][0] == "B": cntb += 1 if cntab == 0: ans = cnt + min(cnta, cntb) else: ans = cnt + cntab + min(cnta, cntb) if cnta == 0 and cntb == 0: if cntab > 0: ans = cnt + cntab - 1 else: ans = cnt print(ans)
Statement Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
[{"input": "3 2", "output": "2\n \n\nThere are two ways to choose two consecutive integers: (1,2) and (2,3).\n\n* * *"}, {"input": "13 3", "output": "11"}]
Print the answer. * * *
s265708357
Accepted
p03047
Input is given from Standard Input in the following format: N K
N, X = map(int, input().split()) print(N - X + 1)
Statement Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
[{"input": "3 2", "output": "2\n \n\nThere are two ways to choose two consecutive integers: (1,2) and (2,3).\n\n* * *"}, {"input": "13 3", "output": "11"}]
Print the answer. * * *
s369579265
Wrong Answer
p03047
Input is given from Standard Input in the following format: N K
print(1)
Statement Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
[{"input": "3 2", "output": "2\n \n\nThere are two ways to choose two consecutive integers: (1,2) and (2,3).\n\n* * *"}, {"input": "13 3", "output": "11"}]
Print the answer. * * *
s354927270
Runtime Error
p03047
Input is given from Standard Input in the following format: N K
print(int(input()) - int(input()) + 1)
Statement Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
[{"input": "3 2", "output": "2\n \n\nThere are two ways to choose two consecutive integers: (1,2) and (2,3).\n\n* * *"}, {"input": "13 3", "output": "11"}]
Print the answer. * * *
s175813273
Wrong Answer
p03047
Input is given from Standard Input in the following format: N K
print(2)
Statement Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
[{"input": "3 2", "output": "2\n \n\nThere are two ways to choose two consecutive integers: (1,2) and (2,3).\n\n* * *"}, {"input": "13 3", "output": "11"}]
Print the answer. * * *
s458385956
Wrong Answer
p03047
Input is given from Standard Input in the following format: N K
print(4)
Statement Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
[{"input": "3 2", "output": "2\n \n\nThere are two ways to choose two consecutive integers: (1,2) and (2,3).\n\n* * *"}, {"input": "13 3", "output": "11"}]
Print the answer. * * *
s889656155
Accepted
p03047
Input is given from Standard Input in the following format: N K
# coding: utf-8 # Your code here! num = input().split() num1 = int(num[0]) retu = int(num[1]) kazu = 0 hint = [] for i in range(num1): hint.append(i) while len(hint) >= retu: kazu += 1 hint.pop(0) print(kazu)
Statement Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
[{"input": "3 2", "output": "2\n \n\nThere are two ways to choose two consecutive integers: (1,2) and (2,3).\n\n* * *"}, {"input": "13 3", "output": "11"}]
Print the answer. * * *
s787233620
Accepted
p03047
Input is given from Standard Input in the following format: N K
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = float("inf") MOD = 10**9 + 7 N, K = MAP() print(N - K + 1)
Statement Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
[{"input": "3 2", "output": "2\n \n\nThere are two ways to choose two consecutive integers: (1,2) and (2,3).\n\n* * *"}, {"input": "13 3", "output": "11"}]
Print the answer. * * *
s758491404
Runtime Error
p03047
Input is given from Standard Input in the following format: N K
if __name__ == "__main__": s = input().split(" ") R = int(s[0]) G = int(s[1]) B = int(s[2]) N = int(s[3]) count = 0 for i in range(N / R + 1): sumR = R * i if sumR == N: count += 1 break elif sumR > N: break else: for j in range(N / G + 1): sumG = G * j if sumR + sumG == N: count += 1 break elif sumR + sumG > N: break else: for k in range(N / B + 1): sumB = B * k if sumR + sumG + sumB == N: count += 1 break elif sumR + sumG + sumB > N: break print(count)
Statement Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
[{"input": "3 2", "output": "2\n \n\nThere are two ways to choose two consecutive integers: (1,2) and (2,3).\n\n* * *"}, {"input": "13 3", "output": "11"}]
Print the answer. * * *
s795944042
Runtime Error
p03047
Input is given from Standard Input in the following format: N K
# -*- coding: utf-8 -*- # input a = int(input()) s = 0 bc = 0 ac = 0 tc = 0 for i in range(a): t = input() s += t.count("AB") if t[:1] == "B": bc += 1 if t[-1:] == "A": ac += 1 if t[:1] == "B" or t[-1:] == "A": tc += 1 if min(bc, ac) == tc and tc > 0: o = s + min(bc, ac) - 1 else: o = s + min(bc, ac) print(o)
Statement Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
[{"input": "3 2", "output": "2\n \n\nThere are two ways to choose two consecutive integers: (1,2) and (2,3).\n\n* * *"}, {"input": "13 3", "output": "11"}]
Print the answer. * * *
s600933165
Wrong Answer
p03047
Input is given from Standard Input in the following format: N K
n, k = map(int, input().split()) n1 = 1 while n > 0: n1 *= n n -= 1 r = n - k r1 = 1 while r > 0: r1 *= r r -= 1 k1 = 1 while k > 0: k1 *= k k -= 1 a = r1 * k1 print(n1 // a)
Statement Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
[{"input": "3 2", "output": "2\n \n\nThere are two ways to choose two consecutive integers: (1,2) and (2,3).\n\n* * *"}, {"input": "13 3", "output": "11"}]
Print the answer. * * *
s997638076
Runtime Error
p03047
Input is given from Standard Input in the following format: N K
def combinations(R, G, B, N): R, G, B, N = int(R), int(G), int(B), int(N) sorted_tuple = sorted((R, G, B), reverse=True) R = sorted_tuple[0] G = sorted_tuple[1] B = sorted_tuple[2] number_combos = 0 print(R) print(G) print(B) for x in range(N + 1): N_modified_x = N - R * x for y in range(N_modified_x + 1): N_modified_y = N_modified_x - G * y for z in range(N_modified_y + 1): if B * z == N_modified_y: number_combos += 1 return number_combos R, G, B, N = input().split(" ") print(combinations(R, G, B, N))
Statement Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
[{"input": "3 2", "output": "2\n \n\nThere are two ways to choose two consecutive integers: (1,2) and (2,3).\n\n* * *"}, {"input": "13 3", "output": "11"}]
Print the answer. * * *
s649363745
Accepted
p03047
Input is given from Standard Input in the following format: N K
s = input().split() print(int(s[0]) - int(s[1]) + 1)
Statement Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
[{"input": "3 2", "output": "2\n \n\nThere are two ways to choose two consecutive integers: (1,2) and (2,3).\n\n* * *"}, {"input": "13 3", "output": "11"}]
Print the answer. * * *
s975566911
Accepted
p03047
Input is given from Standard Input in the following format: N K
n, k = input().split() print(int(n) - int(k) + 1)
Statement Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
[{"input": "3 2", "output": "2\n \n\nThere are two ways to choose two consecutive integers: (1,2) and (2,3).\n\n* * *"}, {"input": "13 3", "output": "11"}]
Print the answer. * * *
s272343783
Accepted
p03047
Input is given from Standard Input in the following format: N K
i = list(map(int, input().split())) print(i[0] - i[1] + 1)
Statement Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
[{"input": "3 2", "output": "2\n \n\nThere are two ways to choose two consecutive integers: (1,2) and (2,3).\n\n* * *"}, {"input": "13 3", "output": "11"}]
Print the answer. * * *
s255898773
Accepted
p03047
Input is given from Standard Input in the following format: N K
list = [int(i) for i in input().split()] print(list[0] - list[1] + 1)
Statement Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
[{"input": "3 2", "output": "2\n \n\nThere are two ways to choose two consecutive integers: (1,2) and (2,3).\n\n* * *"}, {"input": "13 3", "output": "11"}]
Print the answer. * * *
s572884371
Accepted
p03047
Input is given from Standard Input in the following format: N K
list = list(map(int, input().split())) row = list[0] col = list[1] print((row - col) + 1)
Statement Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
[{"input": "3 2", "output": "2\n \n\nThere are two ways to choose two consecutive integers: (1,2) and (2,3).\n\n* * *"}, {"input": "13 3", "output": "11"}]
Print the answer. * * *
s855246508
Accepted
p03047
Input is given from Standard Input in the following format: N K
A = list(map(int, input().split())) print(A[0] - A[1] + 1)
Statement Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
[{"input": "3 2", "output": "2\n \n\nThere are two ways to choose two consecutive integers: (1,2) and (2,3).\n\n* * *"}, {"input": "13 3", "output": "11"}]
Print the number of cards that face down after all the operations. * * *
s882916894
Runtime Error
p03417
Input is given from Standard Input in the following format: N M
N,M = map(int,input().split()) #N>=Mとして一般性を失わない if N==M==1: print(1) if N==1 and M>=2: print(M-2) if N==2 and M>=2: print(0) if N>=3 and M>=3: print((N-2)*(M-2)
Statement There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
[{"input": "2 2", "output": "0\n \n\nWe will flip every card in any of the four operations. Thus, after all the\noperations, all cards face up.\n\n* * *"}, {"input": "1 7", "output": "5\n \n\nAfter all the operations, all cards except at both ends face down.\n\n* * *"}, {"input": "314 1592", "output": "496080"}]
Print the number of cards that face down after all the operations. * * *
s888936382
Runtime Error
p03417
Input is given from Standard Input in the following format: N M
n, m = get(int, input().split()) print(n * m - min(2, n) * min(2, m))
Statement There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
[{"input": "2 2", "output": "0\n \n\nWe will flip every card in any of the four operations. Thus, after all the\noperations, all cards face up.\n\n* * *"}, {"input": "1 7", "output": "5\n \n\nAfter all the operations, all cards except at both ends face down.\n\n* * *"}, {"input": "314 1592", "output": "496080"}]
Print the number of cards that face down after all the operations. * * *
s091065651
Wrong Answer
p03417
Input is given from Standard Input in the following format: N M
n, m = map(int, input().split()) n -= 2 m -= 2 if n < 0 and m < 0: n, m = 0, 0 elif n <= 0: n = 1 elif m <= 0: m = 1 print(n * m)
Statement There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
[{"input": "2 2", "output": "0\n \n\nWe will flip every card in any of the four operations. Thus, after all the\noperations, all cards face up.\n\n* * *"}, {"input": "1 7", "output": "5\n \n\nAfter all the operations, all cards except at both ends face down.\n\n* * *"}, {"input": "314 1592", "output": "496080"}]
Print the number of cards that face down after all the operations. * * *
s430888848
Wrong Answer
p03417
Input is given from Standard Input in the following format: N M
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math # from math import gcd import bisect from collections import defaultdict from collections import deque from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int, input().split())) def SL(): return list(map(str, input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg) return def Y(): print("Yes") return def N(): print("No") return def E(): exit() def PE(arg): print(arg) exit() def YE(): print("Yes") exit() def NE(): print("No") exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors #####GCD##### def gcd(a, b): while b: a, b = b, a % b return a #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X // n: return base_10_to_n(X // n, n) + [X % n] return [X % n] def base_n_to_10(X, n): return sum(int(str(X)[-i]) * n**i for i in range(len(str(X)))) #####IntLog##### def int_log(n, a): count = 0 while n >= a: n = n // a count += 1 if a**count == n: return count else: return count + 1 ############# # Main Code # ############# N, M = IL() P(max(1, (N - 2)) * max(1, (M - 2)))
Statement There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
[{"input": "2 2", "output": "0\n \n\nWe will flip every card in any of the four operations. Thus, after all the\noperations, all cards face up.\n\n* * *"}, {"input": "1 7", "output": "5\n \n\nAfter all the operations, all cards except at both ends face down.\n\n* * *"}, {"input": "314 1592", "output": "496080"}]
Print the number of cards that face down after all the operations. * * *
s056059201
Wrong Answer
p03417
Input is given from Standard Input in the following format: N M
N, M = (int(i) for i in input().split()) tiles = [[True for i in range(M + 2)] for j in range(N + 2)] print(tiles) for i in range(1, N + 1): for j in range(1, M + 1): tiles[i - 1][j - 1] = not (tiles[i - 1][j - 1]) tiles[i - 1][j] = not (tiles[i - 1][j]) tiles[i - 1][j + 1] = not (tiles[i - 1][j + 1]) tiles[i][j - 1] = not (tiles[i][j - 1]) tiles[i][j] = not (tiles[i][j]) tiles[i][j + 1] = not (tiles[i][j + 1]) tiles[i + 1][j - 1] = not (tiles[i + 1][j - 1]) tiles[i + 1][j] = not (tiles[i + 1][j]) tiles[i + 1][j + 1] = not (tiles[i + 1][j + 1]) count = 0 for i in range(1, N + 1): for j in range(1, M + 1): if not tiles[i][j]: count = count + 1 print(count)
Statement There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
[{"input": "2 2", "output": "0\n \n\nWe will flip every card in any of the four operations. Thus, after all the\noperations, all cards face up.\n\n* * *"}, {"input": "1 7", "output": "5\n \n\nAfter all the operations, all cards except at both ends face down.\n\n* * *"}, {"input": "314 1592", "output": "496080"}]
Print the number of cards that face down after all the operations. * * *
s505442231
Wrong Answer
p03417
Input is given from Standard Input in the following format: N M
# coding: utf-8 import re import math from collections import defaultdict from collections import deque 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 is_pow(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 get_facs(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 next_comb(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 get_primes(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 is_prime(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())) ###################################################################################################### H, W = map(int, input().split()) ans = (H - 2) * (W - 2) print(ans)
Statement There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
[{"input": "2 2", "output": "0\n \n\nWe will flip every card in any of the four operations. Thus, after all the\noperations, all cards face up.\n\n* * *"}, {"input": "1 7", "output": "5\n \n\nAfter all the operations, all cards except at both ends face down.\n\n* * *"}, {"input": "314 1592", "output": "496080"}]
Print the number of cards that face down after all the operations. * * *
s559175722
Runtime Error
p03417
Input is given from Standard Input in the following format: N M
def f(x): if x == 0: return 1 elif x == 1: return 0 N, M = map(int, input().split()) a = [[0] * (M + 2) for _ in range(N + 2)] for i in range(N): for j in range(M): a[i][j] = f(a[i][j]) a[i][j + 1] = f(a[i][j + 1]) a[i][j + 2] = f(a[i][j + 2]) a[i + 1][j] = f(a[i + 1][j]) a[i + 1][j + 1] = f(a[i + 1][j + 1]) a[i + 1][j + 2] = f(a[i + 1][j + 2]) a[i + 2][j] = f(a[i + 2][j]) a[i + 2][j + 1] = f(a[i + 2][j + 1]) a[i + 2][j + 2] = f(a[i + 2][j + 2]) print(sum(a[1 : N + 1, 1 : M + 1]))
Statement There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
[{"input": "2 2", "output": "0\n \n\nWe will flip every card in any of the four operations. Thus, after all the\noperations, all cards face up.\n\n* * *"}, {"input": "1 7", "output": "5\n \n\nAfter all the operations, all cards except at both ends face down.\n\n* * *"}, {"input": "314 1592", "output": "496080"}]
Print the number of cards that face down after all the operations. * * *
s709571230
Wrong Answer
p03417
Input is given from Standard Input in the following format: N M
# -*- coding: utf-8 -*- import sys from collections import deque from collections import defaultdict import heapq import collections import itertools import bisect import copy import math from itertools import accumulate sys.setrecursionlimit(10**6) # lis_of_lis = [[] for _ in range(N)] def floor(a, b): return -(-a // b) def zz(): return list(map(int, sys.stdin.readline().split())) def z(): return int(sys.stdin.readline()) def S(): return sys.stdin.readline()[:-1] def C(line): return [sys.stdin.readline() for _ in range(line)] def is_kaibun(kaibun): for i in range(len(kaibun) // 2): if kaibun[i] != kaibun[-i - 1]: return False return True N, M = zz() next1, next2, next3, next4, next5, next6, next7, next8 = 0, 0, 0, 0, 0, 0, 0, 0 if N == 1 and M == 1: print(1) exit() elif N == 1 or M == 1: next1 = 2 next2 = (N * M) - 2 elif M == 2 or N == 2: next3 = 4 next5 = (N * M) - 4 else: next1 = 0 next2 = 0 next3 = 4 next4 = 0 next5 = (M - 2) * 2 + (N - 2) * 2 next6 = 0 next8 = (N - 1) * (M - 1) print(next2 + next4 + next6 + next8)
Statement There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
[{"input": "2 2", "output": "0\n \n\nWe will flip every card in any of the four operations. Thus, after all the\noperations, all cards face up.\n\n* * *"}, {"input": "1 7", "output": "5\n \n\nAfter all the operations, all cards except at both ends face down.\n\n* * *"}, {"input": "314 1592", "output": "496080"}]
Print the number of cards that face down after all the operations. * * *
s240677471
Wrong Answer
p03417
Input is given from Standard Input in the following format: N M
rows, columns = map(int, input().split(" ")) result = 0 if rows == 1: print(columns - 2) exit() if columns == 1: print(rows - 2) exit() for row in range(int(rows / 2)): for column in range(int(columns / 2)): target_time = 0 inc_column = column + 1 < columns dec_column = 0 <= column - 1 inc_row = row + 1 < rows dec_row = 0 <= row - 1 if inc_column: if inc_row: target_time += 1 if dec_row: target_time += 1 if dec_column: if inc_row: target_time += 1 if dec_row: target_time += 1 if dec_column: target_time += 1 if inc_column: target_time += 1 if inc_row: target_time += 1 if dec_row: target_time += 1 if target_time % 2 == 0: result += 1 if columns - 1 != 2 * column: if rows - 1 != 2 * row: result += 1 if columns - 1 != 2 * column: result += 1 if rows - 1 != 2 * row: result += 1 print(result)
Statement There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
[{"input": "2 2", "output": "0\n \n\nWe will flip every card in any of the four operations. Thus, after all the\noperations, all cards face up.\n\n* * *"}, {"input": "1 7", "output": "5\n \n\nAfter all the operations, all cards except at both ends face down.\n\n* * *"}, {"input": "314 1592", "output": "496080"}]
Print the number of cards that face down after all the operations. * * *
s588511769
Wrong Answer
p03417
Input is given from Standard Input in the following format: N M
S = input().split(" ") A = int(S[0]) * int(S[1]) - int(S[0]) * 2 - (int(S[1]) * 2 - 4) if int(S[0]) == 1 or int(S[1]) == 1 and int(S[0]) * int(S[1]) != 1: A = int(S[0]) * int(S[1]) - 2 A = max(0, A) print(A)
Statement There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
[{"input": "2 2", "output": "0\n \n\nWe will flip every card in any of the four operations. Thus, after all the\noperations, all cards face up.\n\n* * *"}, {"input": "1 7", "output": "5\n \n\nAfter all the operations, all cards except at both ends face down.\n\n* * *"}, {"input": "314 1592", "output": "496080"}]
Print the number of cards that face down after all the operations. * * *
s345650754
Wrong Answer
p03417
Input is given from Standard Input in the following format: N M
data = [int(n) for n in input().split()] print(max((data[0] - 2) * (data[1] - 2), 0))
Statement There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
[{"input": "2 2", "output": "0\n \n\nWe will flip every card in any of the four operations. Thus, after all the\noperations, all cards face up.\n\n* * *"}, {"input": "1 7", "output": "5\n \n\nAfter all the operations, all cards except at both ends face down.\n\n* * *"}, {"input": "314 1592", "output": "496080"}]
Print the number of cards that face down after all the operations. * * *
s770532980
Wrong Answer
p03417
Input is given from Standard Input in the following format: N M
print(2) exit() print(3)
Statement There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
[{"input": "2 2", "output": "0\n \n\nWe will flip every card in any of the four operations. Thus, after all the\noperations, all cards face up.\n\n* * *"}, {"input": "1 7", "output": "5\n \n\nAfter all the operations, all cards except at both ends face down.\n\n* * *"}, {"input": "314 1592", "output": "496080"}]
Print the number of cards that face down after all the operations. * * *
s965952125
Runtime Error
p03417
Input is given from Standard Input in the following format: N M
N,M = map(int,input().split()) if(N==1): if M==1: print(1) elif M==2: print(0) else: print(M-2) elif(N==2): print(0) else if M==1: print(1) elif M==2: print(0) else: print((N-2)*(M-2))
Statement There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
[{"input": "2 2", "output": "0\n \n\nWe will flip every card in any of the four operations. Thus, after all the\noperations, all cards face up.\n\n* * *"}, {"input": "1 7", "output": "5\n \n\nAfter all the operations, all cards except at both ends face down.\n\n* * *"}, {"input": "314 1592", "output": "496080"}]
Print the number of cards that face down after all the operations. * * *
s851242915
Runtime Error
p03417
Input is given from Standard Input in the following format: N M
(n, m) = map(int, input().split()) if n == 1: if m == 1: print(1): else: print(m - 2) else: print((n-2)*(m-2))
Statement There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
[{"input": "2 2", "output": "0\n \n\nWe will flip every card in any of the four operations. Thus, after all the\noperations, all cards face up.\n\n* * *"}, {"input": "1 7", "output": "5\n \n\nAfter all the operations, all cards except at both ends face down.\n\n* * *"}, {"input": "314 1592", "output": "496080"}]
Print the number of cards that face down after all the operations. * * *
s924297995
Accepted
p03417
Input is given from Standard Input in the following format: N M
a = list(map(int, input().split())) if a[0] == 1 and a[1] == 1: b = 1 elif a[0] == 1: b = a[1] - 2 elif a[1] == 1: b = a[0] - 2 else: b = (a[0] - 2) * (a[1] - 2) print(b)
Statement There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
[{"input": "2 2", "output": "0\n \n\nWe will flip every card in any of the four operations. Thus, after all the\noperations, all cards face up.\n\n* * *"}, {"input": "1 7", "output": "5\n \n\nAfter all the operations, all cards except at both ends face down.\n\n* * *"}, {"input": "314 1592", "output": "496080"}]
Print the number of cards that face down after all the operations. * * *
s823374006
Accepted
p03417
Input is given from Standard Input in the following format: N M
A, B = map(int, input().split()) print(abs((A - 2) * (B - 2)))
Statement There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
[{"input": "2 2", "output": "0\n \n\nWe will flip every card in any of the four operations. Thus, after all the\noperations, all cards face up.\n\n* * *"}, {"input": "1 7", "output": "5\n \n\nAfter all the operations, all cards except at both ends face down.\n\n* * *"}, {"input": "314 1592", "output": "496080"}]
Print the number of cards that face down after all the operations. * * *
s756990757
Runtime Error
p03417
Input is given from Standard Input in the following format: N M
print(abs((int(input()) - 2) * (int(input()) - 2)))
Statement There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
[{"input": "2 2", "output": "0\n \n\nWe will flip every card in any of the four operations. Thus, after all the\noperations, all cards face up.\n\n* * *"}, {"input": "1 7", "output": "5\n \n\nAfter all the operations, all cards except at both ends face down.\n\n* * *"}, {"input": "314 1592", "output": "496080"}]
Print the number of cards that face down after all the operations. * * *
s873245086
Accepted
p03417
Input is given from Standard Input in the following format: N M
from sys import stdin def main(): N, M = [int(x) for x in stdin.readline().rstrip().split()] # mtx = [[True for x in range(M)] for y in range(N)] # for x in range(M): # for y in range(N): # ps = [(x - 1, y - 1), (x, y - 1), (x + 1, y - 1), # (x - 1, y), (x, y), (x + 1, y), # (x - 1, y + 1), (x, y + 1), (x + 1, y + 1)] # for px, py in ps: # if px < 0 or py < 0 or M - 1 < px or N - 1 < py: # continue # mtx[py][px] = not mtx[py][px] # for m in mtx: # print(m) MIN = min(N, M) MAX = max(N, M) if MIN == 1 and MAX == 1: result = 1 elif MIN == 1: result = MAX - 2 elif MIN == 2: result = 0 else: result = (MIN - 2) * (MAX - 2) print(result) if __name__ == "__main__": main()
Statement There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following operation once for each square contains a card: * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square. It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.
[{"input": "2 2", "output": "0\n \n\nWe will flip every card in any of the four operations. Thus, after all the\noperations, all cards face up.\n\n* * *"}, {"input": "1 7", "output": "5\n \n\nAfter all the operations, all cards except at both ends face down.\n\n* * *"}, {"input": "314 1592", "output": "496080"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s021852709
Accepted
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
s = input().split() w = int(s[0]) h = int(s[1]) n = int(s[2]) max_x = w max_y = h min_x = 0 min_y = 0 x = [] y = [] a = [] for num in range(n): v = input().split() x.append(int(v[0])) y.append(int(v[1])) a.append(int(v[2])) for num in range(n): if a[num] == 1: if x[num] > min_x: min_x = x[num] elif a[num] == 2: if x[num] < max_x: max_x = x[num] elif a[num] == 3: if y[num] > min_y: min_y = y[num] else: if y[num] < max_y: max_y = y[num] y_length = max_y - min_y if y_length < 0: y_length = 0 x_length = max_x - min_x if x_length < 0: x_length = 0 answer = x_length * y_length print(answer)
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s227292639
Runtime Error
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
import sys def nextrec(coor,pt): if pt[2]==1: coor[0]=min(max(coor[0],pt[0]),coor[2]) elif pt[2]==2: coor[2]=max(min(coor[2],pt[0]),coor[0]) elif pt[2]==3: coor[1]=min(max(coor[1],pt[1]),coor[3]) elif pt[2]==4: coor[3]=max(min(coor[3],pt[1]),coor[1]) def main(w,h,n,pts): rec=[0,0,w,h] for x in range(n): nextrec(rec,pt[x]): return (rec[0]-rec[2])*(rec[1]-rec[3]) w,h,n=map(int,sys.stdin.readline().strip().split()) pts=[list(map(int,sys.stdin.readline().strip().split())) \ for x in range(n)] print(main(w,h,n,pts))
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s388588969
Wrong Answer
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
W, H, N = map(int, input().split()) input_li = [list(map(int, input().split())) for i in range(N)] dic = {"1": 0, "2": W, "3": 0, "4": H} for l in input_li: if l[2] == 1 and dic[str(l[2])] < l[0]: dic[str(l[2])] = l[0] if l[2] == 2 and dic[str(l[2])] > l[0]: dic[str(l[2])] = l[0] if l[2] == 3 and dic[str(l[2])] < l[1]: dic[str(l[2])] = l[1] if l[2] == 4 and dic[str(l[2])] > l[1]: dic[str(l[2])] = l[1] print(max(0, (dic["2"] - dic["1"]) * (dic["4"] - dic["3"])))
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s418535752
Accepted
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
r, t, n, *k = map(int, open(0).read().split()) l = b = 0 M = max for x, y, a in zip(*[iter(k)] * 3): exec(("l=M(l,x)", "r=min(r,x)", "b=M(b,y)", "t=min(t,y)")[a - 1]) print(M(0, r - l) * M(0, t - b))
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s787516825
Accepted
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
INT = lambda: int(input()) INTM = lambda: map(int, input().split()) STRM = lambda: map(str, input().split()) STR = lambda: str(input()) LIST = lambda: list(map(int, input().split())) LISTS = lambda: list(map(str, input().split())) def do(): w, h, n = INTM() X, Y, A = [], [], [] for i in range(n): x, y, a = INTM() X.append(x) Y.append(y) A.append(a) wh = [[0] * w] * h for i in range(n): if A[i] == 1: for j in range(h): wh[j][0 : X[i]] = [1] * X[i] elif A[i] == 2: for j in range(h): wh[j][X[i] : w] = [1] * (w - X[i]) elif A[i] == 3: wh[0 : Y[i]] = [[1] * w] * Y[i] else: wh[Y[i] : h] = [[1] * w] * (h - Y[i]) # print(wh) ct = 0 for i in range(h): ct += sum(wh[i]) print(h * w - ct) if __name__ == "__main__": do()
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s618236519
Wrong Answer
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
w, h, n = [int(i) for i in input().split()] width = w height = h flag = flag1 = True xmax1 = xmax2 = ymax1 = ymax2 = 0 while n: x, y, a = [int(i) for i in input().split()] if a == 1: if x > xmax1: if flag: w = width - x xmax1 = x else: if x < xmax2: w = width - x xmax1 = x else: n = 1 w = 0 elif a == 2: if flag and x > xmax1: xmax2 = x w = x - xmax1 flag = False else: n = 1 w = 0 if x < xmax2: if x > xmax1: w = x - xmax1 xmax2 = x else: n = 1 w = 0 elif a == 3: if y > ymax1: if flag1: h = height - y ymax1 = y else: if y < ymax2: h = height - y ymax1 = y else: n = 1 h = 0 elif a == 4: if flag1 and y > ymax1: ymax2 = y h = y - ymax1 flag1 = False else: n = 1 h = 0 if y < ymax2: if y > ymax1: h = y - ymax1 ymax2 = y else: n = 1 h = 0 n -= 1 print(w * h)
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s237320497
Runtime Error
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
import sys inputdata = sys.stdin.readlines() whn = int(inputdata[0].split()) W = whn[0] H = whn[1] N = whn[2] data1 = [] data2 = [] data3 = [] data4 = [] for i in inputdata: if i[-1] == "1": data1.append(int(i.split())) elif i[-1] == "2": data2.append(int(i.split())) elif i[-1] == "3": data3.append(int(i.split())) elif i[-1] == "4": data4.append(int(i.split())) a = 0 for i in data1: if a < i: a = i b = W for i in data2: if b > i: b = i c = 0 for i in data3: if c < i: c = i d = H for i in data4: if d > i: d = i if c >= d: print("0") elif b <= a: print("0") else: print(str((d - c) * (b - a)))
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s789033688
Wrong Answer
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
W, H, N = list(map(int, input().split())) ten = [list(map(int, input().split())) for _ in range(N)] base = [[0, 0, 1], [0, 0, 3], [W, H, 2], [W, H, 4]] ten.extend(base) onemax = max(i[0] for i in ten if i[2] == 1) twomin = min(i[0] for i in ten if i[2] == 2) thrmax = max(i[1] for i in ten if i[2] == 3) foumin = min(i[1] for i in ten if i[2] == 4) if (twomin - onemax) > 0 and (foumin - thrmax) > 0: print((twomin - onemax) * (foumin - thrmax)) else: print()
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s104584255
Accepted
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
W, H, N = input().split() a = [] for i in range(int(N)): a.append(list(map(int, input().split()))) W = int(W) H = int(H) N = int(N) wl = [0, W] hl = [0, H] for x in a: if x[2] == 1: wl[0] = max(wl[0], x[0]) elif x[2] == 2: wl[1] = min(wl[1], x[0]) elif x[2] == 3: hl[0] = max(hl[0], x[1]) elif x[2] == 4: hl[1] = min(hl[1], x[1]) high = 0 width = 0 if wl[1] - wl[0] > 0: width = wl[1] - wl[0] if hl[1] - hl[0] > 0: high = hl[1] - hl[0] print(high * width)
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s248318947
Accepted
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
W, H, N = map(int, input().split()) R = [0, 0, W, 0, H] for _ in [0] * N: *wh, a = map(int, input().split()) R[a] = eval(["min", "max"][a % 2] + "(R[a],wh[a//3])") _, w, W, h, H = R print((W - w) * (H - h) * (W > w) * (H > h))
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s654712263
Runtime Error
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
a
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s736715746
Wrong Answer
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
import sys lines = sys.stdin.readlines() sizes = lines[0].split(" ") W = int(sizes[0]) H = int(sizes[1]) N = int(sizes[2]) # print (W,H,N) calW = W calH = H maxX = 0 minX = W maxY = 0 minY = H for line in lines[1:]: inp = [] for i in line.split(" "): inp.append(int(i)) # print (inp) if inp[2] == 1 and inp[0] > maxX: calW -= inp[0] maxX = inp[0] elif inp[2] == 2 and inp[0] < minX: calW -= W - inp[0] minX = inp[0] elif inp[2] == 3 and inp[1] > maxY: calH -= inp[1] maxY = inp[1] elif inp[2] == 4 and inp[1] < minY: calH -= H - inp[1] minY = inp[1] # print (calW,calH) if calW < 0 or calH < 0: print(0) else: print(calW * calH)
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s349530337
Accepted
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
from subprocess import * call( ( "python3", "-c", """ import numpy I=lambda:map(int,input().split()) W,H,N=I() m=numpy.zeros((H,W),int) while N:x,y,a=I();m[y*(a>3):H*(a^3)or y,x*(a==2):W*~-a or x]=1;N-=1 print(W*H-m.sum()) """, ) )
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s821652797
Runtime Error
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
w,h,n=map(int,input().split()) x1=0 x2=w y1=0 y2=h for i in range(n): x,y,a=map(int,input().split()) if a==1: x1=max(x1,x) if a==2: x2=min(x2,x) if a==3: y1=max(y1,y) if a==4: y2=min(y2,y) if x2<x1 or y2<y1 print(0) else: print((x2-x1)*(y2-y1))
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s017359449
Accepted
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
import numpy as np W, H, N = [int(i) for i in input().split()] x = np.ones(N) y = np.ones(N) a = np.ones(N) for i in range(N): x[i], y[i], a[i] = [int(i) for i in input().split()] init_s = np.zeros([H + 1, W + 1]) ind_a_1 = [ind for ind, v in enumerate(a) if v == 1] ind_a_2 = [ind for ind, v in enumerate(a) if v == 2] ind_a_3 = [ind for ind, v in enumerate(a) if v == 3] ind_a_4 = [ind for ind, v in enumerate(a) if v == 4] if len(ind_a_1) == 0: x_1 = 0 else: x_1 = x[int(ind_a_1[0])] for i in ind_a_1: int_ind = int(i) if x_1 < x[int_ind]: x_1 = x[int_ind] if len(ind_a_3) == 0: y_3 = 0 else: y_3 = y[int(ind_a_3[0])] for i in ind_a_3: int_ind = int(i) if y_3 < y[int_ind]: y_3 = y[int_ind] if len(ind_a_2) == 0: x_2 = W else: x_2 = x[int(ind_a_2[0])] for i in ind_a_2: int_ind = int(i) if x_2 > x[int_ind]: x_2 = x[int_ind] if len(ind_a_4) == 0: y_4 = H else: y_4 = y[int(ind_a_4[0])] for i in ind_a_4: int_ind = int(i) if y_4 > y[int_ind]: y_4 = y[int_ind] if (x_2 - x_1 > 0) & (y_4 - y_3 > 0): ans = int((x_2 - x_1) * (y_4 - y_3)) else: ans = int(0) print(ans)
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s640332974
Wrong Answer
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math # from math import gcd import bisect from collections import defaultdict from collections import deque from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int, input().split())) def SL(): return list(map(str, input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg) return def Y(): print("Yes") return def N(): print("No") return def E(): exit() def PE(arg): print(arg) exit() def YE(): print("Yes") exit() def NE(): print("No") exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X // n: return base_10_to_n(X // n, n) + [X % n] return [X % n] def base_n_to_10(X, n): return sum(int(str(X)[-i]) * n**i for i in range(len(str(X)))) #####IntLog##### def int_log(n, a): count = 0 while n >= a: n //= a count += 1 return count ############# # Main Code # ############# W, H, N = IL() l = [[1] * W for i in range(H)] for _ in range(N): x, y, t = IL() if t == 1: for i in range(H): l[i][:x] = [0 for j in range(x)] if t == 2: for i in range(H): l[i][-x:] = [0 for j in range(W - x)] if t == 4: for i in range(y, H): l[i] = [0 for i in range(W)] if t == 3: for i in range(y): l[i] = [0 for i in range(W)] P(sum(sum(l[i]) for i in range(H)))
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s190369735
Runtime Error
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
W, H, N = map(int, input().split()) xya = [list(map(int, input().split())) for _ in range(N)] S = [[1] * W for _ in range(H)] for x, y, a in xya: if a == 1: for i in range(H): for j in range(x): S[i][j] = 0 elif a == 2: for i in range(x, W): for j in range(x, W) S[i][j] = 0 elif a == 3: for i in range(y): for j in range(W): S[i][j] = 0 else: for i in range(y, H): for j in range(W): S[i][j] = 0 print(sum(S))
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s778652457
Accepted
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
[w, h, n] = [int(i) for i in input().split()] a = [] for i in range(n): a.append([int(j) for j in input().split()]) # それぞれのマスを左下の座標で管理 # (0,0)から(w-1,h-1)まで # print(a) b = [] for i in range(w): for j in range(h): b.append([i, j]) # print(b) # 全ての入力について、大小で外していく for i in range(n): if a[i][2] == 1: for j in range(w * h): if b[j][0] < a[i][0]: b[j] = [-10, -10] elif a[i][2] == 2: for j in range(w * h): if b[j][0] >= a[i][0]: b[j] = [-10, -10] elif a[i][2] == 3: for j in range(w * h): if b[j][1] < a[i][1]: b[j] = [-10, -10] elif a[i][2] == 4: for j in range(w * h): if b[j][1] >= a[i][1]: b[j] = [-10, -10] # print(b) c = [i for i in b if i != [-10, -10]] # print(c) print(len(c))
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s484856656
Accepted
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 def LI(): return list(map(int, input().split())) def II(): return int(input()) def S(): return input() def main(): w, h, n = LI() a = [[1] * w for _ in range(h)] for _ in range(n): x, y, t = LI() if t == 1: for _x in range(x): for _y in range(h): a[_y][_x] = 0 elif t == 2: for _x in range(x, w): for _y in range(h): a[_y][_x] = 0 elif t == 3: for _x in range(w): for _y in range(y): a[_y][_x] = 0 else: for _x in range(w): for _y in range(y, h): a[_y][_x] = 0 return sum(sum(_) for _ in a) print(main())
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s608855405
Accepted
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
def execute(w, h, n, xya): s = [[1 for _ in range(w)] for _ in range(h)] for x, y, a in xya: for xi in range(w): for yi in range(h): if a == 1: if xi < x: s[yi][xi] = 0 if a == 2: if xi >= x: s[yi][xi] = 0 if a == 3: if yi < y: s[yi][xi] = 0 if a == 4: if yi >= y: s[yi][xi] = 0 return sum(map(sum, s)) if __name__ == "__main__": w, h, n = map(int, input().split()) xya = [] for _ in range(n): xya.append(list(map(int, input().split()))) print(execute(w, h, n, xya))
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s006645456
Runtime Error
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
import sys W, H, N = map(int, input().split()) l = d = 0 u = H r = W for i in range(N): x, y, a = list(map(int, input().split())) if a == 1: l = max(x, l) if a == 2: r = min(x, r) if a == 3: d = max(y, d) if a == 4: u = min(y, u) ans = (r - l) * (u - d) if r - l < 0 or u - d < 0 ans = 0 print(max(ans, 0))
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s291715304
Runtime Error
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
w,h,n=map(int,input().split()) s=w*h while n>0: x,y,a=map(int,input().split()) if 
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s709780163
Runtime Error
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
import numpy as np W,H,N = map(int, input().split()) x_s,y_s,a_s = [],[],[] for i in range(N): x,y,a = map(int, input().split()) x_s.append(x) y_s.append(y) a_s.append(a) x_s = np.array(x_s) y_s = np.array(y_s) a_s = np.array(a_s) if (a_s==1).sum()>=1: x_min = x_s[a_s==1].max() else: x_min = 0 if (a_s==2).sum()>=1: x_max = x_s[a_s==2].min() else: x_max = W if (a_s==3).sum()>=1: y_min = y_s[a_s==3].max() else: y_min = 0 if (a_s==4).sum()>=1: y_max = y_s[a_s==4].min() else: y_max = H if (x_min>=x_max)|(y_min>=y_max): ans = 0 else: ans = (x_max-x_min)*(y_max-y_min) print(int(ans))
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s088696456
Runtime Error
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
W, H, N = [int(i) for i in input().split(" ")] a1 = [0,0] a2 = [W,0] a3 = [0,0] a4 = [0,H] for i in range(0,N): lst = [int(i) for i in input().split(" ")] if lst[2] == 1: a1[0] = max(a1[0],lst[0]) elif lst[2] == 2: a2[0] = max(a2[0],lst[0]) elif lst[2] == 3: a3[1] = max(a3[1],lst[1]) elif lst[2] == 4: a4[1] = max(a4[1],lst[1]) print(max(0,a2[0]-a1[0])*max(0,(a4[1]-a3[1]))
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s453650159
Accepted
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
w, h, n = (int(i) for i in input().split()) a = [[int(i) for i in input().split()] for i in range(n)] x = [0, w, 0, h] for i in a: if i[2] == 1 and i[0] > x[0]: x[0] = i[0] elif i[2] == 2 and i[0] < x[1]: x[1] = i[0] elif i[2] == 3 and i[1] > x[2]: x[2] = i[1] elif i[2] == 4 and i[1] < x[3]: x[3] = i[1] print(max(x[1] - x[0], 0) * max(x[3] - x[2], 0))
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s593467991
Runtime Error
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
W, H, N = map(int,input().split()) #白い領域の端 l = 0 r = W u = H d = 0 for i in range(N): x, y, a = map(int,input().split()) if a == 1: l = max(x,l) elif a == 2: r = min(x,r) elif a == 3: d = max(y,d) else: u = min(y,u) print(max((r-l),0)*max((u-d),0)
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the area of the white region within the rectangle after Snuke finished painting. * * *
s345327747
Runtime Error
p03944
The input is given from Standard Input in the following format: W H N x_1 y_1 a_1 x_2 y_2 a_2 : x_N y_N a_N
w,h,n=[int(i) for i in input().split(' ')] x1,x2,y1,y2=0,w,0,h for i in range(n): x,y,a=[int(i) for i in input().split(' ')] if a==1: x1=max(x1,x) if a==2: x2=min(x2,x) if a==3: y1=max(y1,y) if a==4: y2=min(y2,y) print(max(0,(y2-y1)*(x2-x1))
Statement There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
[{"input": "5 4 2\n 2 1 1\n 3 3 4", "output": "9\n \n\nThe figure below shows the rectangle before Snuke starts painting.\n\n![e19e673abcd0882783f635cce9d2f94d.png](https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png)\n\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x <\n2 within the rectangle:\n\n![f25cd04bbac23c4e5426d70511a9762f.png](https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png)\n\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y >\n3 within the rectangle:\n\n![46b0c06fd9eee4f148e1f441f7abca53.png](https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png)\n\nNow, the area of the white region within the rectangle is 9.\n\n* * *"}, {"input": "5 4 3\n 2 1 1\n 3 3 4\n 1 4 2", "output": "0\n \n\nIt is possible that the whole region within the rectangle is painted black.\n\n* * *"}, {"input": "10 10 5\n 1 6 1\n 4 1 3\n 6 9 4\n 9 4 2\n 3 1 3", "output": "64"}]
Print the maximum possible total score for Takahashi's throws. * * *
s383310873
Wrong Answer
p03899
The input is given from Standard Input in the following format: N M K A_1 A_2 … A_N
from collections import deque import sys def solve(): readline = sys.stdin.readline N, M, K = map(int, readline().split()) (*A,) = map(int, readline().split()) S = A[:] T = [0] * N for k in range(K - 1): que = deque() for i, a in enumerate(S[:-1]): while que and que[-1][1] <= a: que.pop() que.append((i, a)) T[i + 1] = que[0][1] + A[i + 1] * (k + 2) if que and que[0][0] <= i + 1 - M: que.popleft() S, T = T, S print(max(S)) solve()
Statement There are N panels arranged in a row in Takahashi's house, numbered 1 through N. The i-th panel has a number A_i written on it. Takahashi is playing by throwing balls at these panels. Takahashi threw a ball K times. Let the panel hit by a boll in the i-th throw be panel p_i. He set the score for the i-th throw as i \times A_{p_i}. He was about to calculate the total score for his throws, when he realized that he forgot the panels hit by balls, p_1,p_2,...,p_K. The only fact he remembers is that for every i (1 ≦ i ≦ K-1), 1 ≦ p_{i+1}-p_i ≦ M holds. Based on this fact, find the maximum possible total score for his throws.
[{"input": "5 2 3\n 10 2 8 10 2", "output": "56\n \n\nThe total score is maximized when panels 1,3 and 4 are hit, in this order.\n\n* * *"}, {"input": "5 5 2\n 5 2 10 5 9", "output": "28\n \n\nThis case satisfies the additional constraint M = N for a partial score.\n\n* * *"}, {"input": "10 3 5\n 3 7 2 6 9 4 8 5 1 1000000000", "output": "5000000078"}]
For each question _M i_, print yes or no.
s028905636
Accepted
p02271
In the first line _n_ is given. In the second line, _n_ integers are given. In the third line _q_ is given. Then, in the fourth line, _q_ integers (_M i_) are given.
n = int(input()) li_in = list(map(int, input().split())) q = int(input()) li_check = list(map(int, input().split())) ubd = 2000 table = [False] * (ubd + 5) S = [0] * n def enum(i): global table if i == n: sum = 0 for j in range(n): sum += li_in[j] * S[j] if sum <= 2000: table[sum] = True else: enum(i + 1) S[i] = 1 enum(i + 1) S[i] = 0 enum(0) for val in li_check: if table[val]: print("yes") else: print("no") # 失敗作: 毎回再帰で計算 # 各回,数が一つくるごとに全探索している. # 時間がかかりすぎる.最初に可能な数を全て計算した上でストックし,それを各数に対して用いれば良い. # S = [0] * n # flag = False # def enum(i, val): # global flag # if i == n: # sum = 0 # for j in range(n): # sum += li_in[j] * S[j] # if sum == val: # flag = True # else: # enum(i + 1, val) # S[i] = 1 # enum(i + 1, val) # S[i] = 0 # for val in li_check: # flag = 0 # enum(0, val) # if flag: # print('yes') # else: # print('no')
Exhaustive Search Write a program which reads a sequence _A_ of _n_ elements and an integer _M_ , and outputs "yes" if you can make _M_ by adding elements in _A_ , otherwise "no". You can use an element only once. You are given the sequence _A_ and _q_ questions where each question contains _M i_.
[{"input": "5\n 1 5 7 10 21\n 8\n 2 4 17 8 22 21 100 35", "output": "no\n no\n yes\n yes\n yes\n yes\n no\n no"}]
For each question _M i_, print yes or no.
s813219297
Accepted
p02271
In the first line _n_ is given. In the second line, _n_ integers are given. In the third line _q_ is given. Then, in the fourth line, _q_ integers (_M i_) are given.
import sys #fin = open("test.txt", "r") fin = sys.stdin n = int(fin.readline()) A = list(map(int, fin.readline().split())) q = int(fin.readline()) m_list = list(map(int, fin.readline().split())) for m in m_list: can_compose = False s = [[] for i in range(n)] #s[i][m]??§???A[i]?????§???????´???§m???????????????????????????????????? for i in range(n): s[i] = [False for i in range(m + 1)] for j in range(m + 1): if j == A[0]: s[0][j] = True else: s[0][j] = False if s[0][m]: can_compose = True if not can_compose: for i in range(1, n): for j in range(m + 1): if j == A[i]: s[i][j] = True elif s[i - 1][j]: s[i][j] = True else: if j - A[i] >= 0: s[i][j] = s[i - 1][j - A[i]] if s[i][m]: can_compose = True break if can_compose: print("yes") else: print("no")
Exhaustive Search Write a program which reads a sequence _A_ of _n_ elements and an integer _M_ , and outputs "yes" if you can make _M_ by adding elements in _A_ , otherwise "no". You can use an element only once. You are given the sequence _A_ and _q_ questions where each question contains _M i_.
[{"input": "5\n 1 5 7 10 21\n 8\n 2 4 17 8 22 21 100 35", "output": "no\n no\n yes\n yes\n yes\n yes\n no\n no"}]
Print the value a + a^2 + a^3 as an integer. * * *
s169320474
Accepted
p02621
Input is given from Standard Input in the following format: a
def main(): a=int(input()) print(a*(1+a+a*a)) main()
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s806035608
Runtime Error
p02621
Input is given from Standard Input in the following format: a
firstString = input() secondString = input() diff = 0 for i in range(len(firstString)): if firstString[i] != secondString[i]: diff += 1 print(diff)
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s154486972
Accepted
p02621
Input is given from Standard Input in the following format: a
s = int(input()) print(s + s**2 + s**3)
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s973830275
Runtime Error
p02621
Input is given from Standard Input in the following format: a
i = input() print(i + (i * i) + (i * i * i))
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s233734195
Accepted
p02621
Input is given from Standard Input in the following format: a
import sys #import string #from collections import defaultdict, deque, Counter #import bisect #import heapq #import math #from itertools import accumulate #from itertools import permutations as perm #from itertools import combinations as comb #from itertools import combinations_with_replacement as combr #from fractions import gcd #import numpy as np stdin = sys.stdin sys.setrecursionlimit(10 ** 7) MIN = -10 ** 9 MOD = 10 ** 9 + 7 INF = float("inf") IINF = 10 ** 18 def solve(): a = int(stdin.readline().rstrip()) #A, B, C = map(int, stdin.readline().rstrip().split()) #l = list(map(int, stdin.readline().rstrip().split())) #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin] #word = [stdin.readline().rstrip() for _ in range(n)] #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)] #zeros = [[0] * w for i in range(h)] print(a + a**2 + a**3) if __name__ == '__main__': solve()
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s319104632
Wrong Answer
p02621
Input is given from Standard Input in the following format: a
a = int(input("整数を入力してください")) answer = a + a * a + a * a * a print("答えは", answer)
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s221812535
Wrong Answer
p02621
Input is given from Standard Input in the following format: a
a = int(input()) if a == 1: print(3) elif a == 2: print(14) elif a == 3: print(39) elif a == 4: print(84) elif a == 5: print(155) elif a == 6: print(238) elif a == 7: print(399) elif a == 8: print(584) elif a == 9: print(819) elif a == 10: print(1110)
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s077990649
Wrong Answer
p02621
Input is given from Standard Input in the following format: a
N = int(input()) # ここで標準入力 print(type(N), N + N * N + N * N * N)
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s453704230
Wrong Answer
p02621
Input is given from Standard Input in the following format: a
n = int(input()) % 1000 print(1000 - n if n else 0)
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s973152486
Accepted
p02621
Input is given from Standard Input in the following format: a
inp1 = int(input()) a = inp1**2 b = inp1**3 print(inp1 + a + b)
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s485554585
Runtime Error
p02621
Input is given from Standard Input in the following format: a
S = str(input()) T = str(input()) length = len(S) listS = list(S) listT = list(T) num = len(T) res = 0 for i in range(length): if listS[num - 1] != listT[num - 1]: res += 1 num -= 1 print(res)
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s095275076
Wrong Answer
p02621
Input is given from Standard Input in the following format: a
a = input("aの値を入力してください:") print(int(a) + (int(a)) ^ 2 + (int(a)) ^ 3)
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s079134080
Accepted
p02621
Input is given from Standard Input in the following format: a
x = input() X = int(x) y = X + X**2 + X**3 print(y)
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s336832397
Wrong Answer
p02621
Input is given from Standard Input in the following format: a
a =int(input()) ans = a+a**2+2**3 print(ans)
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s539046122
Wrong Answer
p02621
Input is given from Standard Input in the following format: a
A = int(input("Input a value for 'a': ")) FINAL = A + (A * A) + (A * A * A) print(FINAL)
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s413753255
Accepted
p02621
Input is given from Standard Input in the following format: a
ii = lambda:int(input()) mi = lambda:list(map(int,input().split())) ix = lambda x:list(input() for _ in range(x)) mix = lambda x:list(mi() for _ in range(x)) iix = lambda x:list(int(input()) for _ in range(x)) ########## def resolve(): a = ii() print(a+a**2+a**3) if __name__ == "__main__": resolve()
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s788205435
Accepted
p02621
Input is given from Standard Input in the following format: a
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**19 MOD = 10**9 + 7 EPS = 10**-10 a = INT() ans = a + a**2 + a**3 print(ans)
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s078412479
Runtime Error
p02621
Input is given from Standard Input in the following format: a
from collections import deque N, M, K = map(int, input().split()) A = deque(map(int, input().split())) B = deque(map(int, input().split())) A.append(float("inf")) B.append(float("inf")) time = K count = 0 sum_A = sum(list(A)[:-1]) sum_B = sum(list(A)[:-1]) for _ in range(len(A) + len(B)): if A[0] > B[0]: target = B.popleft() if (target > (sum_A - A[0])) and len(A) != 1: sum_A -= A[0] B.appendleft(target) target = A.popleft() time -= target count += 1 else: target = A.popleft() if (target > (sum_B - B[0])) and len(B) != 1: sum_B -= B[0] A.appendleft(target) target = B.popleft() time -= target count += 1 if len(A) == len(B) == 1: break if time < 0: count -= 1 break elif time == 0: break print(count)
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s196627169
Runtime Error
p02621
Input is given from Standard Input in the following format: a
for i in range(int(input())): n=int(input()) s=n+n**2+n**3 print(s)
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s808197277
Runtime Error
p02621
Input is given from Standard Input in the following format: a
# -*- coding: utf-8 -*- # def main(): # n, m, k = map(int, input().split()) # A = list(map(int, input().split())) # B = list(map(int, input().split())) # a = A[0] # A2 = [a] # b = B[0] # B2 = [b] # for i in range(1, n): # a += A[i] # A2.append(a) # # for i in range(1, m): # b += B[i] # B2.append(b) # max = -2 # for ia, aa in enumerate(A2): # for ib, bb in enumerate(B2): # if aa + bb > k: # break # if ia + ib > max: # # max = ia + ib # print(max + 2) # def answer(): N, M, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) a, b = [0], [0] for i in range(N): a.append(a[i] + A[i]) for i in range(M): b.append(b[i] + B[i]) ans, j = 0, M for i in range(N + 1): if a[i] > K: break while b[j] > K - a[i]: j -= 1 ans = max(ans, i + j) print(ans) if __name__ == "__main__": answer()
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s293722954
Wrong Answer
p02621
Input is given from Standard Input in the following format: a
# Write your code in below N = int(input().rstrip()) print(N * (1 + N + N ^ 2))
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s004810122
Accepted
p02621
Input is given from Standard Input in the following format: a
print((a := int(input())) * (1 + a + a * a))
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s872402910
Wrong Answer
p02621
Input is given from Standard Input in the following format: a
def cal(): a = str(input()) n = a + a**2 + a**3 print(n)
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s553197888
Accepted
p02621
Input is given from Standard Input in the following format: a
S = int(input()) print(S + (S**2) + (S**3))
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s255093332
Accepted
p02621
Input is given from Standard Input in the following format: a
s = input().split() intA = int(s[0]) # print(intA) intR = intA intR2 = intA * intA intR3 = intA * intA * intA # print(intR) # print(intR2) # print(intR3) print(intR + intR2 + intR3)
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the value a + a^2 + a^3 as an integer. * * *
s869036476
Runtime Error
p02621
Input is given from Standard Input in the following format: a
n, m, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) now = b[0] ans = 0 for i in range(len(a) + len(b)): if now >= k: break else: if len(a) == 0: ans += 1 now += b[0] b.remove(b[0]) elif len(b) == 0: ans += 1 now += a[0] a.remove(a[0]) else: if a[0] < now: ans += 1 now += a[0] a.remove(a[0]) else: now = b[1] ans += 1 now += b[0] b.remove(b[0]) print(ans)
Statement Given an integer a as input, print the value a + a^2 + a^3.
[{"input": "2", "output": "14\n \n\nWhen a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.\n\nPrint the answer as an input. Outputs such as `14.0` will be judged as\nincorrect.\n\n* * *"}, {"input": "10", "output": "1110"}]
Print the maximum number of desires that can be satisfied at the same time. * * *
s726098141
Runtime Error
p03460
Input is given from Standard Input in the following format: N K x_1 y_1 c_1 x_2 y_2 c_2 : x_N y_N c_N
#include <bits/stdc++.h> //#include <math.h> using namespace std; #define INF 1.1e9 #define LINF 1.1e18 #define FOR(i,a,b) for (int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() #define pb push_back #define pf push_front #define fi first #define se second #define BIT(x,n) bitset<n>(x) #define PI 3.14159265358979323846 typedef long long ll; typedef pair<int,int> P; typedef pair<int,P> PP; //----------------------------------------------------------------------------- int n,k,x,y; char c; int imos[5010][5010]; int calc(int y,int x) { int res=0; if(y>=0&&x>=0) res=imos[min(k*2-1,y)][min(k*2-1,x)]; return res; } int sum(int y,int x) { return calc(y,x)-calc(y-k,x)-calc(y,x-k)+calc(y-k,x-k); } int main() { cin.tie(0); ios::sync_with_stdio(false); cin>>n>>k; REP(i,n) { cin>>x>>y>>c; if(c=='W') x+=k; int nx=x%(2*k),ny=y%(2*k); imos[ny][nx]++; } REP(i,k*2) REP(j,k*2) imos[i][j]+=calc(i-1,j); REP(i,k*2) REP(j,k*2) imos[i][j]+=calc(i,j-1); /*cout<<endl; REP(i,k*2) { REP(j,k*2) cout<<imos[i][j]<<' '; cout<<endl; }*/ int ans=0; REP(i,k*2) { REP(j,k*2) { ans=max(ans,sum(i,j)+sum(i-k,j-k)+sum(i-k,j+k)+sum(i+k,j-k)+sum(i+k,j+k)+sum(i+2*k,j)+sum(i,j+k*2)); } } cout<<ans<<endl; return 0; }
Statement AtCoDeer is thinking of painting an infinite two-dimensional grid in a _checked pattern of side K_. Here, a checked pattern of side K is a pattern where each square is painted black or white so that each connected component of each color is a K × K square. Below is an example of a checked pattern of side 3: ![cba927b2484fad94fb5ff7473e9aadef.png](https://img.atcoder.jp/arc089/cba927b2484fad94fb5ff7473e9aadef.png) AtCoDeer has N desires. The i-th desire is represented by x_i, y_i and c_i. If c_i is `B`, it means that he wants to paint the square (x_i,y_i) black; if c_i is `W`, he wants to paint the square (x_i,y_i) white. At most how many desires can he satisfy at the same time?
[{"input": "4 3\n 0 1 W\n 1 2 W\n 5 3 B\n 5 4 B", "output": "4\n \n\nHe can satisfy all his desires by painting as shown in the example above.\n\n* * *"}, {"input": "2 1000\n 0 0 B\n 0 1 W", "output": "2\n \n\n* * *"}, {"input": "6 2\n 1 2 B\n 2 1 W\n 2 2 B\n 1 0 B\n 0 6 W\n 4 5 W", "output": "4"}]
Print the maximum number of desires that can be satisfied at the same time. * * *
s689004327
Wrong Answer
p03460
Input is given from Standard Input in the following format: N K x_1 y_1 c_1 x_2 y_2 c_2 : x_N y_N c_N
# 入力 N, K = map(int, input().split()) x, y, c = zip( *(((int(x), int(y), c) for x, y, c in (input().split() for _ in range(N)))) ) K2 = 2 * K # 各クエリを(0, 0)から(K -1, K - 1) の矩形にマッピングし、各マスの個数をカウント cs = [[0 for _ in range(K2)] for _ in range(K2)] for i, j, k in zip(x, y, c): cs[(i + K * (k == "W")) % K2][j % K2] += 1 # dp[i][j] はマス(i, j) から K*K のマスを黒で塗るときに叶えられる要望の数 dp = [[0 for _ in range(K2)] for _ in range(K2)] # 累積和を用いて解を求める dp[0][0] = sum(cs[i][j] for i in range(K) for j in range(K)) for i in range(1, K + 1): dp[i][0] = ( dp[i - 1][0] + sum(cs[i + K - 1][j] for j in range(K)) - sum(cs[i - 1][j] for j in range(K)) ) dp[0][i] = ( dp[0][i - 1] + sum(cs[j][i + K - 1] for j in range(K)) - sum(cs[j][i - 1] for j in range(K)) ) for i in range(K + 1, K2): dp[i][0] = ( dp[i - 1][0] + sum(cs[i - (K + 1)][j] for j in range(K)) - sum(cs[i - 1][j] for j in range(K)) ) dp[0][i] = ( dp[0][i - 1] + sum(cs[j][i - (K + 1)] for j in range(K)) - sum(cs[j][i - 1] for j in range(K)) ) for i in range(1, K + 1): for j in range(1, K + 1): dp[i][j] = ( dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + cs[i + K - 1][j + K - 1] + cs[i - 1][j - 1] - cs[i - 1][j + K - 1] - cs[i + K - 1][j - 1] ) for j in range(K + 1, K2): dp[i][j] = ( dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + cs[i + K - 1][j - (K + 1)] + cs[i - 1][j - 1] - cs[i - 1][j - (K + 1)] - cs[i + K - 1][j - 1] ) for i in range(K + 1, 2 * K): for j in range(1, K + 1): dp[i][j] = ( dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + cs[i - (K + 1)][j + K - 1] + cs[i - 1][j - 1] - cs[i - 1][j + K - 1] - cs[i - (K + 1)][j - 1] ) for j in range(K + 1, K2): dp[i][j] = ( dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + cs[i - (K + 1)][j - (K + 1)] + cs[i - 1][j - 1] - cs[i - 1][j - (K + 1)] - cs[i - (K + 1)][j - 1] ) # 全通りの塗り方を試し、解を求める ans = max( max(dp[i][j] + dp[i + K][j + K] for i in range(K) for j in range(K)), max(dp[i][j] + dp[i - K][j - K] for i in range(K, K2) for j in range(K, K2)), ) # 出力 print(ans)
Statement AtCoDeer is thinking of painting an infinite two-dimensional grid in a _checked pattern of side K_. Here, a checked pattern of side K is a pattern where each square is painted black or white so that each connected component of each color is a K × K square. Below is an example of a checked pattern of side 3: ![cba927b2484fad94fb5ff7473e9aadef.png](https://img.atcoder.jp/arc089/cba927b2484fad94fb5ff7473e9aadef.png) AtCoDeer has N desires. The i-th desire is represented by x_i, y_i and c_i. If c_i is `B`, it means that he wants to paint the square (x_i,y_i) black; if c_i is `W`, he wants to paint the square (x_i,y_i) white. At most how many desires can he satisfy at the same time?
[{"input": "4 3\n 0 1 W\n 1 2 W\n 5 3 B\n 5 4 B", "output": "4\n \n\nHe can satisfy all his desires by painting as shown in the example above.\n\n* * *"}, {"input": "2 1000\n 0 0 B\n 0 1 W", "output": "2\n \n\n* * *"}, {"input": "6 2\n 1 2 B\n 2 1 W\n 2 2 B\n 1 0 B\n 0 6 W\n 4 5 W", "output": "4"}]
Print the maximum number of desires that can be satisfied at the same time. * * *
s727361558
Wrong Answer
p03460
Input is given from Standard Input in the following format: N K x_1 y_1 c_1 x_2 y_2 c_2 : x_N y_N c_N
# -*- coding: utf-8 -*- from collections import Counter import numpy as np n, k = list(map(int, input().split())) table = np.zeros((2 * k, 2 * k), dtype="int32") for i in range(n): t = input().split() if t[2] == "B": table[int(t[0]) % (2 * k)][int(t[1]) % (2 * k)] += 1 else: table[(int(t[0]) + k) % (2 * k)][int(t[1]) % (2 * k)] += 1 # print(table) n_table = np.zeros((3 * k, 3 * k), dtype="int32") n_table[0 : 2 * k, 0 : 2 * k] = table n_table[2 * k : 3 * k, 0 : 2 * k] = table[0:k, 0 : 2 * k] n_table[0 : 2 * k, 2 * k : 3 * k] = table[0 : 2 * k, 0:k] n_table[2 * k : 3 * k, 2 * k : 3 * k] = table[0:k, 0:k] # print(n_table) i_table = np.zeros((3 * k, 3 * k), dtype="int32") for i in range(0, 3 * k): i_table[i][0] = n_table[i][0] for j in range(1, 3 * k): i_table[i][j] += i_table[i][j - 1] + n_table[i][j] for i in range(1, 3 * k): for j in range(0, 3 * k): i_table[i][j] += i_table[i - 1][j] # print(i_table) ans = 0 hope1 = i_table[k - 1][k - 1] hope2 = ( i_table[2 * k - 1][2 * k - 1] - i_table[2 * k - 1][k - 1] - i_table[k - 1][2 * k - 1] + i_table[k - 1][k - 1] ) ans = max(ans, hope1 + hope2) for i in range(1, k): hope1 = i_table[k - 1][i + k - 1] - i_table[k - 1][i - 1] hope2 = ( i_table[2 * k - 1][i + 2 * k - 1] - i_table[2 * k - 1][i + k - 1] - i_table[k - 1][i + 2 * k - 1] + i_table[k - 1][i + k - 1] ) ans = max(ans, hope1 + hope2) for i in range(1, k): hope1 = i_table[i + k - 1][k - 1] - i_table[i - 1][k - 1] hope2 = ( i_table[i + 2 * k - 1][2 * k - 1] - i_table[i + 2 * k - 1][k - 1] - i_table[i + k - 1][2 * k - 1] + i_table[i + k - 1][k - 1] ) ans = max(ans, hope1 + hope2) for i in range(1, k): for j in range(1, k): hope1 = ( i_table[i + k - 1][j + k - 1] - i_table[i + k - 1][j - 1] - i_table[i - 1][j + k - 1] + i_table[i - 1][j - 1] ) hope2 = ( i_table[i + 2 * k - 1][j + 2 * k - 1] - i_table[i + 2 * k - 1][j + k - 1] - i_table[i + k - 1][j + 2 * k - 1] + i_table[i + k - 1][j + k - 1] ) ans = max(ans, hope1 + hope2) print(ans)
Statement AtCoDeer is thinking of painting an infinite two-dimensional grid in a _checked pattern of side K_. Here, a checked pattern of side K is a pattern where each square is painted black or white so that each connected component of each color is a K × K square. Below is an example of a checked pattern of side 3: ![cba927b2484fad94fb5ff7473e9aadef.png](https://img.atcoder.jp/arc089/cba927b2484fad94fb5ff7473e9aadef.png) AtCoDeer has N desires. The i-th desire is represented by x_i, y_i and c_i. If c_i is `B`, it means that he wants to paint the square (x_i,y_i) black; if c_i is `W`, he wants to paint the square (x_i,y_i) white. At most how many desires can he satisfy at the same time?
[{"input": "4 3\n 0 1 W\n 1 2 W\n 5 3 B\n 5 4 B", "output": "4\n \n\nHe can satisfy all his desires by painting as shown in the example above.\n\n* * *"}, {"input": "2 1000\n 0 0 B\n 0 1 W", "output": "2\n \n\n* * *"}, {"input": "6 2\n 1 2 B\n 2 1 W\n 2 2 B\n 1 0 B\n 0 6 W\n 4 5 W", "output": "4"}]