static object Solve() { var n = int.Parse(Console.ReadLine()); var s0 = Console.ReadLine().Select(c => c == 'B').ToArray(); var t = Console.ReadLine().Select(c => c == 'B').ToArray(); var s = new IndexedList <bool>(); foreach (var v in s0) { s.Add(v); } var r = 0L; // 先行インデックス var q = 0; for (int i = 0; i < n; i++) { var v = s[i]; if (v == t[i]) { continue; } if (i == n - 1) { return(-1); } q = Math.Max(q, i); while (q + 1 < n && s[q] != s[q + 1]) { q++; } if (q == n - 1) { return(-1); } r += q - i + 1; s.RemoveAt(q); s.RemoveAt(q); s.Insert(i, !v); s.Insert(i, !v); } if (!s.SequenceEqual(t)) { throw new InvalidOperationException(); } return(r); }
public void TestAddRemoveAndClearMethods() { var sut = new IndexedList <ItemMetadata>(); sut.AddIndex("Idx", metadata => metadata.BlobRef); var item1 = new ItemMetadata { BlobRef = Guid.NewGuid().ToString(), Name = "Tag", Value = "Cuba" }; var item2 = new ItemMetadata { BlobRef = Guid.NewGuid().ToString(), Name = "Tag", Value = "beach" }; var item3 = new ItemMetadata { BlobRef = Guid.NewGuid().ToString(), Name = "Tag", Value = "pooltable" }; Assert.That(sut.Count, Is.EqualTo(0)); sut.Add(item1); Assert.That(sut.Count, Is.EqualTo(1)); sut.Add(item2); Assert.That(sut.Count, Is.EqualTo(2)); sut.Insert(1, item3); Assert.That(sut.Count, Is.EqualTo(3)); sut.RemoveAt(2); Assert.That(sut.Count, Is.EqualTo(2)); Assert.That(sut[0].Value, Is.EqualTo("Cuba")); sut.Clear(); Assert.That(sut.Count, Is.EqualTo(0)); }
//we should check entire collection at least in 5 seconds, calculate trackCount for that purpose private static void Update() { #if UNITY_EDITOR if (UseAssetDatabase) { return; //don't need to run this on assetdatabase mode } #endif //first, owner { int trackCount = Mathf.CeilToInt(Time.unscaledDeltaTime * 0.2f * s_TrackingOwners.Count); for (int i = 0; i < trackCount; i++) { if (s_TrackingOwners.TryGetNext(out var kv) && kv.Value.Owner == null) { s_TrackingOwners.Remove(kv.Key); UntrackObjectInternal(kv.Value.Child); } } } //second, objects(so owner can release ref) { int trackCount = Mathf.CeilToInt(Time.unscaledDeltaTime * 0.2f * s_TrackingObjects.Count); for (int i = 0; i < trackCount; i++) { if (s_TrackingObjects.TryGetNext(out var kv) && !kv.Value.WeakRef.IsAlive) { s_TrackingObjects.Remove(kv.Key); ReleaseBundleInternal(kv.Value.Bundle, 1); s_WeakRefPool.Push(kv.Value.WeakRef); } } } //next, sole object { int trackCount = Mathf.CeilToInt(Time.unscaledDeltaTime * 0.2f * s_TrackingGameObjects.Count); for (int i = 0; i < trackCount; i++) { if (s_TrackingGameObjects.TryGetNext(out var trackInfo) && trackInfo.GameObject == null) { s_TrackingGameObjects.RemoveAt(s_TrackingGameObjects.CurrentIndex); ReleaseBundleInternal(trackInfo.Bundle, 1); } } } }
public void MaintainCache() { var worldId = Core.Player.WorldSnoId; Cache.RemoveAll(p => p.WorldId != worldId); while (RecentPositions.Count > RecentPositionsLimit) { RecentPositions.RemoveAt(0); } while (Cache.Count > CacheLimit) { Cache.RemoveAt(0); } }