結果
問題 | No.1505 Zero-Product Ranges |
ユーザー |
![]() |
提出日時 | 2021-05-15 07:29:54 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 94 ms / 2,000 ms |
コード長 | 1,100 bytes |
コンパイル時間 | 2,045 ms |
コンパイル使用メモリ | 114,464 KB |
実行使用メモリ | 32,256 KB |
最終ジャッジ日時 | 2024-10-02 14:20:15 |
合計ジャッジ時間 | 6,096 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
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.Collections.Generic; using System; public class Hello { static void Main() { var n = int.Parse(Console.ReadLine().Trim()); string[] line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, int.Parse); getAns(n, a); } static void getAns ( int n, int[] a) { if (n == 1) { Console.WriteLine(a[0] == 0? 1:0); return; } var pre = a[0] == 0 ? 0 : -1; var d = new Dictionary<long, long>(); for (int i = 1; i < n; i++) { if (a[i] == 0) { var t = pre == -1 ? i : i - pre - 1; if (d.ContainsKey(t)) d[t]++; else d[t] = 1; pre = i; } } var e = n - pre - 1; if (e > 0) { if (d.ContainsKey(e)) d[e]++; else d[e] = 1; } var sum = 0L; foreach (var x in d) sum += (x.Key + (x.Key) * (x.Key - 1) / 2L) * x.Value; var ans = n + n * (n - 1L) / 2L - sum; Console.WriteLine(ans); } }