結果
問題 | No.2053 12345... |
ユーザー | Shirotsume |
提出日時 | 2022-08-28 02:15:34 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 159 ms / 2,000 ms |
コード長 | 2,163 bytes |
コンパイル時間 | 140 ms |
コンパイル使用メモリ | 82,428 KB |
実行使用メモリ | 119,236 KB |
最終ジャッジ日時 | 2024-10-15 03:15:49 |
合計ジャッジ時間 | 4,735 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
52,224 KB |
testcase_01 | AC | 37 ms
52,608 KB |
testcase_02 | AC | 56 ms
66,816 KB |
testcase_03 | AC | 70 ms
82,012 KB |
testcase_04 | AC | 97 ms
99,072 KB |
testcase_05 | AC | 64 ms
76,800 KB |
testcase_06 | AC | 93 ms
97,728 KB |
testcase_07 | AC | 90 ms
92,288 KB |
testcase_08 | AC | 84 ms
91,008 KB |
testcase_09 | AC | 100 ms
98,688 KB |
testcase_10 | AC | 112 ms
104,192 KB |
testcase_11 | AC | 63 ms
76,060 KB |
testcase_12 | AC | 67 ms
73,984 KB |
testcase_13 | AC | 150 ms
105,088 KB |
testcase_14 | AC | 87 ms
86,272 KB |
testcase_15 | AC | 91 ms
83,840 KB |
testcase_16 | AC | 89 ms
83,840 KB |
testcase_17 | AC | 79 ms
82,316 KB |
testcase_18 | AC | 159 ms
117,512 KB |
testcase_19 | AC | 111 ms
99,072 KB |
testcase_20 | AC | 77 ms
78,116 KB |
testcase_21 | AC | 98 ms
90,112 KB |
testcase_22 | AC | 55 ms
66,688 KB |
testcase_23 | AC | 61 ms
74,112 KB |
testcase_24 | AC | 70 ms
84,224 KB |
testcase_25 | AC | 114 ms
105,444 KB |
testcase_26 | AC | 86 ms
93,056 KB |
testcase_27 | AC | 70 ms
84,592 KB |
testcase_28 | AC | 67 ms
80,800 KB |
testcase_29 | AC | 97 ms
95,488 KB |
testcase_30 | AC | 72 ms
82,432 KB |
testcase_31 | AC | 93 ms
95,864 KB |
testcase_32 | AC | 131 ms
119,236 KB |
ソースコード
import sys input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 class dsu(): n=1 parent_or_size=[-1 for i in range(n)] def __init__(self,N): self.n=N self.num = N self.parent_or_size=[-1 for i in range(N)] def merge(self,a,b): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) assert 0<=b<self.n, "0<=b<n,b={0},n={1}".format(b,self.n) x=self.leader(a) y=self.leader(b) if x==y: return x self.num -= 1 if (-self.parent_or_size[x]<-self.parent_or_size[y]): x,y=y,x self.parent_or_size[x]+=self.parent_or_size[y] self.parent_or_size[y]=x return x def same(self,a,b): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) assert 0<=b<self.n, "0<=b<n,b={0},n={1}".format(b,self.n) return self.leader(a)==self.leader(b) def leader(self,a): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) if (self.parent_or_size[a]<0): return a self.parent_or_size[a]=self.leader(self.parent_or_size[a]) return self.parent_or_size[a] def size(self,a): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) return -self.parent_or_size[self.leader(a)] def groups(self): leader_buf=[0 for i in range(self.n)] group_size=[0 for i in range(self.n)] for i in range(self.n): leader_buf[i]=self.leader(i) group_size[leader_buf[i]]+=1 result=[[] for i in range(self.n)] for i in range(self.n): result[leader_buf[i]].append(i) result2=[] for i in range(self.n): if len(result[i])>0: result2.append(result[i]) return result2 def count(self): return self.num n = ii() a = li() U = dsu(n) for i in range(n - 1): if a[i + 1] - a[i] == 1: U.merge(i + 1, i) ans = 0 for v in U.groups(): if len(v) > 1: ans += len(v) * (len(v) - 1) // 2 print(ans)