結果
問題 | No.871 かえるのうた |
ユーザー |
![]() |
提出日時 | 2019-10-12 22:14:09 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 132 ms / 2,000 ms |
コード長 | 1,467 bytes |
コンパイル時間 | 2,292 ms |
コンパイル使用メモリ | 114,404 KB |
実行使用メモリ | 55,596 KB |
最終ジャッジ日時 | 2024-11-30 10:57:25 |
合計ジャッジ時間 | 6,337 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 49 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace FreeWorks { class Program { static void Main(string[] args) { string[] line = Console.ReadLine().Split(' '); int n = int.Parse(line[0]); int k = int.Parse(line[1]); long[] X = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); long[] A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); bool[] check = new bool[n]; Queue<int> q = new Queue<int>(); q.Enqueue(k - 1); int cnt = 0; int max_i = k - 1; int min_i = k - 1; while (q.Count > 0) { int i = q.Dequeue(); if (check[i]) continue; check[i] = true; cnt++; long rightRange = X[i] + A[i]; long leftRange = X[i] - A[i]; for (int x = max_i + 1; x < n && X[x] <= rightRange; x++) { q.Enqueue(x); max_i = Math.Max(max_i, x); } for (int x = min_i - 1; x >= 0 && leftRange <= X[x]; x--) { q.Enqueue(x); min_i = Math.Min(min_i, x); } } Console.WriteLine(cnt); } } }