結果
| 問題 |
No.3018 目隠し宝探し
|
| コンテスト | |
| ユーザー |
navel_tos
|
| 提出日時 | 2025-01-25 14:08:37 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 6,248 bytes |
| コンパイル時間 | 951 ms |
| コンパイル使用メモリ | 81,664 KB |
| 実行使用メモリ | 83,960 KB |
| 平均クエリ数 | 2.68 |
| 最終ジャッジ日時 | 2025-01-25 23:08:44 |
| 合計ジャッジ時間 | 4,534 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge7 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 17 WA * 1 RE * 3 |
ソースコード
#岩井PC全問
def solve_A():
N, M = map(int, input().split())
ans = 0
for _ in range(N):
Si, Ri = input().split()
if ( Ri := int(Ri) ) >= 1200 and any( Si[p] == 'x' for p in range(4) ):
ans += 1
print(ans)
def solve_B():
M = 30
x = 5 * 10 ** 8
for _ in range(M):
print(x)
if ( r := int(input()) ) == 1:
return
else:
x = - ( - x // 2 )
def solve_C():
X, Y = map(int, input().split())
P = [i + 1 for i in range(X * Y)]
print(X * Y, X * Y)
for i in range(X - 1, X * Y, X):
P[i] = (i + X) % (X * Y)
for i in range(X * Y):
print(i + 1, P[i] + 1)
def solve_D():
N, M, P, Y = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
Ai, Bi, Ci = map(int, input().split())
G[Ai - 1].append((Bi - 1, Ci))
G[Bi - 1].append((Ai - 1, Ci))
S = [Y + 1] * N
for _ in range(P):
Di, Ei = map(int, input().split())
assert S[Di - 1] == Y + 1
S[Di - 1] = Ei
#街0から各街に最短で移動したときのコストを計算
import heapq
Q = [(0, 0)]
D = [Y + 1] * N
D[0] = 0
while Q:
cost, now = heapq.heappop(Q)
if D[now] < cost:
continue
D[now] = cost
for nxt, d in G[now]:
if D[nxt] > D[now] + d:
D[nxt] = D[now] + d
heapq.heappush(Q, (D[nxt], nxt))
#各街に最短で着いたら買い占め
ans = 0
for now in range(N):
left = Y - D[now]
price = S[now]
if left >= price:
ans = max(ans, left // price)
print(ans)
def solve_E():
N, D, K = map(int, input().split())
A = list(map(int, input().split()))
C = list(map(int, input().split()))
#DP[i := 考慮した問題数][c := 美しさ][d := 採用数] = 最大の満足度 の遷移をひとつのDPで
DP = [[- 10 ** 18] * (D + 1) for _ in range(K + 1)]
DP[0][0] = 0
for Ai, Ci in zip(A, C): #採用の遷移を逆順ループで
for d in range(D - 1, -1, -1):
for c in range(K, -1, -1):
if DP[c][d] == - 10 ** 18:
continue
nd = d + 1
nc = min(c + Ci, K)
DP[nc][nd] = max(DP[nc][nd], DP[c][d] + Ai)
print( DP[c][d] if DP[c := K][d := D] != - 10 ** 18 else 'No')
def solve_F():
S = input()
N = len(S)
#0を2個飛ばしで左に寄せられる。ただし1が奇数の場合、操作不可能
#1110 → 1011 ・・・ ■ となる ので、飛ばせる1の個数を持ってシミュレートすればよさそう
RLE = []
Lt = 0
for i in range(N):
if i == N - 1 or S[i] != S[i + 1]:
RLE.append((S[i], i - Lt + 1))
Lt = i + 1
n = len(RLE)
ans = 0
cont_1 = 0
for Si, c in RLE:
if Si == '0':
cont_1 >>= 1
cont_1 <<= 1
ans += c * ( cont_1 >> 1 )
if Si == '1':
cont_1 += c
print(ans)
def solve_G():
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
#自信はないがソート順マッチでいいんじゃないか?
A.sort()
B.sort()
#C[i]: 左詰マッチしたときの累積不満度
#D[i]: 右詰マッチしたときの累積不満度
C = [0] * (N + 1)
for i in range(N - 1):
C[i + 1] = C[i] + abs(A[i] - B[i])
C[N] = C[N - 1]
D = [0] * (N + 1)
for i in range(N - 1, 0, -1):
D[i] = D[i + 1] - abs(A[i] - B[i - 1])
D[0] = D[1]
min_comp = 10 ** 18
ans = []
for i in range(N):
cnt = ( C[i] - C[0] ) + ( D[N] - D[i + 1] )
if min_comp > cnt:
min_comp = cnt
ans = []
if min_comp == cnt: #種類数なので重複を許さない
if len(ans) > 0 and ans[-1] == A[i]:
continue
ans.append( A[i] )
print( len(ans) )
print( *ans )
def solve_H():
N = int(input())
H = list(map(int, input().split()))
#stackでシミュレート
Q = [(0, 10 ** 9 + 2)]
ans = 0 #現在の水色の量
for i, Hi in enumerate(H):
c = (i + 1) & 1
d = 0 #今回染めた量
while d < Hi:
color, dist = Q.pop() #足から取り出す
if d + dist > Hi: #全部やると塗りすぎになる場合
diff = (d + dist) - Hi
Q.append((color, diff))
Q.append((color, dist - diff))
continue #一旦仕切り直し
assert d + dist <= Hi
#一旦水色を削除
if color == 1:
ans -= dist
d += dist
#色cに染めて戻す
if c == 1:
ans += d
Q.append((c, d))
print(ans)
def solve_I():
#昔自分でも作ったことあるかも
H, W = map(int, input().split())
print('?', 1, 1)
c1 = int(input())
if c1 == 0:
print('!', 1, 1)
return
if H > 1: #場合分け
if H == 2 and W == 1:
print('!', 2, 1)
return
print('?', 2, 1)
c2 = int(input())
if c2 == 0:
print('!', 2, 1)
return
if c1 < c2:
assert c1 + 1 == c2
h = 1
else:
assert c1 > c2
diff = c1 - c2
h = 1 + (diff + 1) // 2
b = (h - 1) ** 2
d = c1 - b
c = max(0, int(d ** 0.5) - 2)
while c ** 2 < d: c += 1
w = 1 + c
print('!', h, w)
return
else:
assert H == 1 and W > 1
if H == 1 and W == 2:
print('!', 1, 2)
return
print('?', 1, 2)
c2 = int(input())
if c2 == 0:
print('!', 1, 2)
return
if c1 < c2:
assert c1 + 1 == c2
w = 1
else:
assert c1 > c2
diff = c1 - c2
w = 1 + (diff + 1) // 2
print('!', 1, w)
return
#片っ端から提出
solve_I()
navel_tos