結果
| 問題 | No.1373 Directed Operations |
| コンテスト | |
| ユーザー |
brthyyjp
|
| 提出日時 | 2021-02-24 21:12:48 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 375 ms / 2,000 ms |
| コード長 | 1,188 bytes |
| 記録 | |
| コンパイル時間 | 200 ms |
| コンパイル使用メモリ | 82,004 KB |
| 実行使用メモリ | 98,116 KB |
| 最終ジャッジ日時 | 2024-09-24 21:01:23 |
| 合計ジャッジ時間 | 5,905 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 19 |
ソースコード
class UnionFind:
def __init__(self, n):
self.par = [-1]*n
self.rank = [0]*n
def Find(self, x):
if self.par[x] < 0:
return x
else:
self.par[x] = self.Find(self.par[x])
return self.par[x]
def Unite(self, x, y):
x = self.Find(x)
y = self.Find(y)
if x != y:
if self.rank[x] < self.rank[y]:
self.par[y] += self.par[x]
self.par[x] = y
else:
self.par[x] += self.par[y]
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def Same(self, x, y):
return self.Find(x) == self.Find(y)
def Size(self, x):
return -self.par[self.Find(x)]
n = int(input())
A = list(map(int, input().split()))
B = []
for i, a in enumerate(A):
B.append((a, i))
B.sort(reverse=True)
uf = UnionFind(n)
ans = [0]*(n-1)
for i in reversed(range(1, n)):
a, j = B[n-1-i]
if i-a >= 0:
uf.Unite(i-a, i)
ans[j] = i-a+1
else:
continue
if uf.Size(0) == n:
print('YES')
print(*ans, sep='\n')
else:
print('NO')
brthyyjp