結果

問題 No.1505 Zero-Product Ranges
ユーザー fairy_lettucefairy_lettuce
提出日時 2021-05-22 08:23:36
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 6,177 bytes
コンパイル時間 2,075 ms
コンパイル使用メモリ 117,940 KB
実行使用メモリ 43,292 KB
最終ジャッジ日時 2024-10-10 10:48:20
合計ジャッジ時間 7,008 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
26,184 KB
testcase_01 AC 28 ms
27,412 KB
testcase_02 AC 27 ms
24,264 KB
testcase_03 AC 104 ms
43,292 KB
testcase_04 AC 103 ms
43,156 KB
testcase_05 AC 58 ms
30,936 KB
testcase_06 AC 57 ms
30,192 KB
testcase_07 AC 52 ms
30,948 KB
testcase_08 AC 54 ms
30,284 KB
testcase_09 AC 53 ms
29,528 KB
testcase_10 AC 54 ms
29,212 KB
testcase_11 AC 61 ms
30,884 KB
testcase_12 AC 50 ms
28,980 KB
testcase_13 AC 73 ms
38,928 KB
testcase_14 AC 66 ms
34,048 KB
testcase_15 AC 96 ms
40,956 KB
testcase_16 AC 106 ms
41,124 KB
testcase_17 AC 107 ms
41,240 KB
testcase_18 AC 103 ms
43,276 KB
testcase_19 AC 27 ms
26,292 KB
testcase_20 AC 28 ms
26,432 KB
testcase_21 AC 33 ms
26,852 KB
testcase_22 AC 105 ms
42,856 KB
testcase_23 AC 103 ms
41,028 KB
testcase_24 AC 103 ms
42,464 KB
testcase_25 AC 96 ms
40,404 KB
testcase_26 AC 101 ms
40,792 KB
testcase_27 AC 101 ms
42,132 KB
testcase_28 AC 98 ms
40,524 KB
testcase_29 AC 100 ms
41,292 KB
testcase_30 AC 103 ms
40,964 KB
testcase_31 AC 103 ms
42,736 KB
testcase_32 AC 72 ms
38,252 KB
testcase_33 AC 69 ms
36,068 KB
testcase_34 AC 71 ms
38,252 KB
testcase_35 AC 60 ms
32,852 KB
testcase_36 AC 63 ms
30,980 KB
testcase_37 AC 67 ms
35,772 KB
testcase_38 AC 72 ms
38,048 KB
testcase_39 AC 69 ms
35,676 KB
testcase_40 AC 71 ms
36,152 KB
testcase_41 AC 72 ms
36,824 KB
testcase_42 AC 36 ms
27,456 KB
testcase_43 AC 37 ms
25,960 KB
testcase_44 AC 35 ms
25,364 KB
testcase_45 AC 37 ms
26,088 KB
testcase_46 AC 36 ms
26,016 KB
testcase_47 AC 39 ms
26,544 KB
testcase_48 AC 36 ms
27,096 KB
testcase_49 AC 33 ms
27,024 KB
testcase_50 AC 37 ms
27,256 KB
testcase_51 AC 38 ms
26,012 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Diagnostics;
using System.IO;
using System.Numerics;
using System.Threading;
namespace CpLibrary.Contest
{
	public class SolverA : SolverBase
	{
		Scanner sr;
		bool HasMultipleTestcases { get; }

		public override void Solve()
		{
			var n = sr.ReadInt();
			var a = sr.ReadIntArray(n);
			var last = 0;
			long ans = 0;
			for (int i = 0; i < n; i++)
			{
				if (a[i] == 0)
				{
					ans += (long)(i - last + 1) * (n - i);
					last = i + 1;
				}
			}
			Console.WriteLine(ans);
		}

		public SolverA(Scanner sr) => this.sr = sr;

		public override void Run()
		{
			var _t = 1;
			if (HasMultipleTestcases) _t = sr.ReadInt();
			while (_t-- > 0) Solve();
		}
	}

	public static class ProgramA
	{
		private static bool StartsOnThread = true;

		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);
			var sr = new Scanner(new StreamReader(Console.OpenStandardInput()));
			var solver = new SolverA(sr);
			if (StartsOnThread)
			{
				var thread = new Thread(new ThreadStart(() => solver.Run()), 1 << 27);
				thread.Start();
				thread.Join();
			}
			else solver.Run();
			Console.Out.Flush();
		}

		public static void Expand() => SourceExpander.Expander.Expand();
	}
}
#region Expanded by https://github.com/naminodarie/SourceExpander
namespace CpLibrary { public class Scanner { public StreamReader sr { get; private set; }  string[] str; int index; char[] separators; public Scanner(StreamReader sr, char[] separators) { this.sr = sr; this.separators = separators; str = new string[0]; index = 0; }  public Scanner(StreamReader sr): this(sr, new char[]{' '}) { }  public Scanner(): this(new StreamReader(Console.OpenStandardInput()), new char[]{' '}) { }  public string Read() { if (index < str.Length) return str[index++]; string s; do s = sr.ReadLine(); while (s == ""); str = s.Split(separators, StringSplitOptions.RemoveEmptyEntries); index = 0; return str[index++]; }  public string ReadString() => Read(); public string[] ReadStringArray(int n) { var arr = new string[n]; for (int i = 0; i < n; i++) { arr[i] = ReadString(); }  return arr; }  public int ReadInt() => int.Parse(ReadString()); public int[] ReadIntArray(int n) => ReadValueArray<int>(n); public long ReadLong() => long.Parse(ReadString()); public long[] ReadLongArray(int n) => ReadValueArray<long>(n); public double ReadDouble() => double.Parse(ReadString()); public double[] ReadDoubleArray(int n) => ReadValueArray<double>(n); public BigInteger ReadBigInteger() => BigInteger.Parse(ReadString()); public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public T1[] ReadValueArray<T1>(int n) { var arr = new T1[n]; for (int i = 0; i < n; i++) { arr[i] = ReadValue<T1>(); }  return arr; }  public (T1, T2) ReadValue<T1, T2>() => (ReadValue<T1>(), ReadValue<T2>()); public (T1, T2, T3) ReadValue<T1, T2, T3>() => (ReadValue<T1>(), ReadValue<T2>(), ReadValue<T3>()); public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() => (ReadValue<T1>(), ReadValue<T2>(), ReadValue<T3>(), ReadValue<T4>()); public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() => (ReadValue<T1>(), ReadValue<T2>(), ReadValue<T3>(), ReadValue<T4>(), ReadValue<T5>()); public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() => (ReadValue<T1>(), ReadValue<T2>(), ReadValue<T3>(), ReadValue<T4>(), ReadValue<T5>(), ReadValue<T6>()); public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() => (ReadValue<T1>(), ReadValue<T2>(), ReadValue<T3>(), ReadValue<T4>(), ReadValue<T5>(), ReadValue<T6>(), ReadValue<T7>()); public (T1[], T2[]) ReadValueArray<T1, T2>(int n) { var(v1, v2) = (new T1[n], new T2[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i]) = ReadValue<T1, T2>(); }  return (v1, v2); }  public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int n) { var(v1, v2, v3) = (new T1[n], new T2[n], new T3[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i], v3[i]) = ReadValue<T1, T2, T3>(); }  return (v1, v2, v3); }  public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int n) { var(v1, v2, v3, v4) = (new T1[n], new T2[n], new T3[n], new T4[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i], v3[i], v4[i]) = ReadValue<T1, T2, T3, T4>(); }  return (v1, v2, v3, v4); }  public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int n) { var(v1, v2, v3, v4, v5) = (new T1[n], new T2[n], new T3[n], new T4[n], new T5[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i], v3[i], v4[i], v5[i]) = ReadValue<T1, T2, T3, T4, T5>(); }  return (v1, v2, v3, v4, v5); }  public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int n) { var(v1, v2, v3, v4, v5, v6) = (new T1[n], new T2[n], new T3[n], new T4[n], new T5[n], new T6[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i], v3[i], v4[i], v5[i], v6[i]) = ReadValue<T1, T2, T3, T4, T5, T6>(); }  return (v1, v2, v3, v4, v5, v6); }  public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int n) { var(v1, v2, v3, v4, v5, v6, v7) = (new T1[n], new T2[n], new T3[n], new T4[n], new T5[n], new T6[n], new T7[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i], v3[i], v4[i], v5[i], v6[i], v7[i]) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); }  return (v1, v2, v3, v4, v5, v6, v7); } } }
namespace CpLibrary { public interface ISolver { public void Solve(); public void Run(); }  public abstract class SolverBase : ISolver { public abstract void Solve(); public abstract void Run(); public bool YesNo(bool condition) { Console.WriteLine(condition ? "Yes" : "No"); return condition; }  public bool YESNO(bool condition) { Console.WriteLine(condition ? "YES" : "NO"); return condition; }  public bool yesno(bool condition) { Console.WriteLine(condition ? "yes" : "no"); return condition; } } }
namespace SourceExpander{public class Expander{[Conditional("EXP")]public static void Expand(string inputFilePath=null,string outputFilePath=null,bool ignoreAnyError=true){}public static string ExpandString(string inputFilePath=null,bool ignoreAnyError=true){return "";}}}
#endregion Expanded by https://github.com/naminodarie/SourceExpander
0