結果
| 問題 |
No.1266 7 Colors
|
| ユーザー |
|
| 提出日時 | 2021-06-04 12:51:09 |
| 言語 | Nim (2.2.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 3,101 bytes |
| コンパイル時間 | 4,286 ms |
| コンパイル使用メモリ | 87,552 KB |
| 実行使用メモリ | 33,408 KB |
| 最終ジャッジ日時 | 2024-11-18 20:15:51 |
| 合計ジャッジ時間 | 8,992 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 3 |
| other | RE * 19 |
コンパイルメッセージ
/home/judge/data/code/Main.nim(2, 18) Warning: Use the new 'sugar' module instead; future is deprecated [Deprecated] /home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'times' [UnusedImport] /home/judge/data/code/Main.nim(2, 26) Warning: imported and not used: 'strformat' [UnusedImport] /home/judge/data/code/Main.nim(2, 18) Warning: imported and not used: 'future' [UnusedImport] /home/judge/data/code/Main.nim(2, 37) Warning: imported and not used: 'deques' [UnusedImport] /home/judge/data/code/Main.nim(1, 41) Warning: imported and not used: 'algorithm' [UnusedImport] /home/judge/data/code/Main.nim(1, 52) Warning: imported and not used: 'tables' [UnusedImport] /home/judge/data/code/Main.nim(1, 60) Warning: imported and not used: 'sets' [UnusedImport] /home/judge/data/code/Main.nim(1, 66) Warning: imported and not used: 'lists' [UnusedImport] /home/judge/data/code/Main.nim(1, 73) Warning: imported and not used: 'intsets' [UnusedImport] /home/judge/data/code/Main.nim(2, 8) Warning: imported and not used: 'critbits' [UnusedImport]
ソースコード
import times, strutils, sequtils, math, algorithm, tables, sets, lists, intsets
import critbits, future, strformat, deques
template `max=`(x,y) = x = max(x,y)
template `min=`(x,y) = x = min(x,y)
template `mod=`(x,y) = x = x mod y
template scan2 = (scan(), scan())
template scan3 = (scan(), scan())
let read* = iterator: string {.closure.} =
while true: (for s in stdin.readLine.split: yield s)
proc scan(): int = read().parseInt
proc scanf(): float = read().parseFloat
proc toInt(c:char): int =
return int(c) - int('0')
proc solve()=
var
n = scan()
m = scan()
query = scan()
s = newseqwith(n,read().parseBinInt)
nodeNum = n*7
baseEs = newseqwith(n,newseq[int]())
es = newseqwith(nodeNum,newseq[int]())
roots = newseqwith(nodeNum,0)
size = newseqwith(nodeNum,1)
for i in 0..<m:
var
(u,v) = (scan()-1,scan()-1)
baseEs[u].add(v)
baseEs[v].add(u)
# 都市u,vが同じ色jを持っていたらu*7+j,v*7+j間でunite
var
queries = newseqwith(query,(scan(),scan()-1,scan()-1))
# i番目の都市の色jの仮想都市のインデックス:i*7+j
for i in 0..<nodeNum:
roots[i] = i
proc find(x:int):int=
if roots[x] == x:
return x
else:
result = find(roots[x])
roots[x] = result
proc unite(x,y:int)=
#echo "unite ", x, ", ", y
var
rx = find(x)
ry = find(y)
if rx == ry:
return
elif rx<ry:
(size[rx],size[ry]) = (size[rx]+size[ry],0)
roots[ry]=rx
return
else:
(size[rx],size[ry]) = (0,size[rx]+size[ry])
roots[rx]=ry
return
# もともとの辺を張っていく
# 1. 同一都市内での辺
for idx,colors in s:
for j in 0..<7:
var
left = 7-j-1
right = ((7-j-2).mod(7)+7).mod(7)
# 色j,j+1の間に辺が張れる
if ((colors and (1 shl left)) > 0) and ((colors and (1 shl right)) > 0):
unite(idx*7+j,idx*7+(j+1).mod(7))
# 2. 隣接都市が同じ色を持っていたら辺を張る
for town in 0..n:
for nxt in baseEs[town]:
var
townC = s[town]
nxtC = s[nxt]
for j in 0..<6:
if (townC and (1 shl (6-j)))>0 and (nxtC and (1 shl (6-j)))>0:
unite(town*7+j,nxt*7+j)
#echo roots
for (q,x,y) in queries:
if q == 1:
# 1.自分自身の上下の色とのunite
var
p = (7-y-1)
upper = ((7-(y-1)-1).mod(7)+7).mod(7)
lower = ((7-(y+1)-1).mod(7)+7).mod(7)
#echo s[x].toBin(7)
#echo p, ", ", lower, ", ", upper
s[x] += (1 shl p)
if ((s[x] and (1 shl upper)) > 0) and ((s[x] and (1 shl p)) > 0):
unite(x*7+y,x*7+((y-1).mod(7)+7).mod(7))
if ((s[x] and (1 shl lower)) > 0) and ((s[x] and (1 shl p)) > 0):
unite(x*7+y,x*7+((y+1).mod(7)+7).mod(7))
# 2. 隣接する都市の同一の色とのunite
for nxt in baseEs[x]:
if (s[nxt] and (1 shl p)) > 0:
unite(x*7+y,nxt*7+y)
elif q == 2:
#echo "x: ",x
#echo roots
echo size[find(x*7)]
#echo roots
#echo size
solve()