結果
問題 | No.1017 Reiwa Sequence |
ユーザー | EmKjp |
提出日時 | 2020-05-19 09:29:35 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 107 ms / 2,000 ms |
コード長 | 6,935 bytes |
コンパイル時間 | 1,077 ms |
コンパイル使用メモリ | 121,752 KB |
実行使用メモリ | 75,560 KB |
最終ジャッジ日時 | 2024-07-03 10:07:47 |
合計ジャッジ時間 | 35,128 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
27,004 KB |
testcase_01 | AC | 29 ms
24,748 KB |
testcase_02 | AC | 32 ms
27,368 KB |
testcase_03 | AC | 32 ms
25,196 KB |
testcase_04 | AC | 32 ms
24,956 KB |
testcase_05 | AC | 32 ms
28,224 KB |
testcase_06 | AC | 32 ms
28,348 KB |
testcase_07 | AC | 32 ms
25,068 KB |
testcase_08 | AC | 32 ms
25,072 KB |
testcase_09 | AC | 35 ms
37,448 KB |
testcase_10 | AC | 40 ms
48,060 KB |
testcase_11 | AC | 36 ms
41,160 KB |
testcase_12 | AC | 50 ms
56,384 KB |
testcase_13 | AC | 49 ms
54,684 KB |
testcase_14 | AC | 34 ms
34,760 KB |
testcase_15 | AC | 37 ms
37,620 KB |
testcase_16 | AC | 36 ms
41,212 KB |
testcase_17 | AC | 39 ms
48,396 KB |
testcase_18 | AC | 35 ms
38,848 KB |
testcase_19 | AC | 45 ms
64,052 KB |
testcase_20 | AC | 45 ms
62,744 KB |
testcase_21 | AC | 46 ms
63,024 KB |
testcase_22 | AC | 46 ms
64,700 KB |
testcase_23 | AC | 45 ms
64,092 KB |
testcase_24 | AC | 44 ms
63,556 KB |
testcase_25 | AC | 44 ms
61,968 KB |
testcase_26 | AC | 45 ms
65,460 KB |
testcase_27 | AC | 43 ms
60,776 KB |
testcase_28 | AC | 42 ms
60,504 KB |
testcase_29 | AC | 43 ms
64,876 KB |
testcase_30 | AC | 42 ms
63,848 KB |
testcase_31 | AC | 42 ms
60,112 KB |
testcase_32 | AC | 42 ms
56,360 KB |
testcase_33 | AC | 38 ms
45,264 KB |
testcase_34 | AC | 44 ms
65,948 KB |
testcase_35 | AC | 43 ms
66,596 KB |
testcase_36 | AC | 44 ms
67,932 KB |
testcase_37 | AC | 42 ms
61,808 KB |
testcase_38 | AC | 41 ms
60,076 KB |
testcase_39 | AC | 43 ms
62,328 KB |
testcase_40 | AC | 83 ms
66,612 KB |
testcase_41 | AC | 82 ms
65,952 KB |
testcase_42 | AC | 83 ms
69,584 KB |
testcase_43 | AC | 83 ms
66,836 KB |
testcase_44 | AC | 81 ms
74,792 KB |
testcase_45 | AC | 83 ms
68,936 KB |
testcase_46 | AC | 83 ms
71,300 KB |
testcase_47 | AC | 81 ms
71,012 KB |
testcase_48 | AC | 102 ms
54,340 KB |
testcase_49 | AC | 93 ms
32,292 KB |
testcase_50 | AC | 107 ms
75,560 KB |
testcase_51 | AC | 28 ms
24,812 KB |
testcase_52 | AC | 48 ms
68,572 KB |
testcase_53 | AC | 48 ms
68,368 KB |
コンパイルメッセージ
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; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Text; using System.Linq; using E = System.Linq.Enumerable; using System.Text.RegularExpressions; internal partial class Solver { public void Run() { var n = ni(); var a = ni(n).Take(22).ToArray(); Action<int[], long?[], int, int, long> dfs = null; dfs = (v, array, pos, sum, used) => { if (pos == v.Length) { if (sum >= 0) { array[sum] = used; } } else { dfs(v, array, pos + 1, sum, used); dfs(v, array, pos + 1, sum + v[pos], used | ((1L << (pos * 2)))); dfs(v, array, pos + 1, sum - v[pos], used | ((2L << (pos * 2)))); } }; var a1 = a.Take(a.Length / 2).ToArray(); var a2 = a.Skip(a.Length / 2).ToArray(); var h1 = new long?[a1.Length * 150000 + 1]; var h2 = new long?[a2.Length * 150000 + 1]; dfs(a1, h1, 0, 0, 0); dfs(a2, h2, 0, 0, 0); for (int i = 0; i < h1.Length && i < h2.Length; i++) { if (h1[i].HasValue && h2[i].HasValue) { if (i == 0 && h1[i] == 0 && h2[i] == 0) continue; var ans = new List<int>(); for (int j = 0; j < a1.Length; j++) { if (((h1[i].Value & (1L << (j * 2))) != 0)) { ans.Add(a1[j]); } else if (((h1[i].Value & (2L << (j * 2))) != 0)) { ans.Add(-a1[j]); } else { ans.Add(0); } } for (int j = 0; j < a2.Length; j++) { if (((h2[i].Value & (1L << (j * 2))) != 0)) { ans.Add(-a2[j]); } else if (((h2[i].Value & (2L << (j * 2))) != 0)) { ans.Add(a2[j]); } else { ans.Add(0); } } cout.WriteLine("Yes"); cout.WriteLine(string.Join(" ", ans.Concat(new int[n - ans.Count]))); return; } } cout.WriteLine("No"); } } // PREWRITEN CODE BEGINS FROM HERE internal partial class Solver : Scanner { public static void Main() { #if LOCAL byte[] inputBuffer = new byte[1000000]; var inputStream = Console.OpenStandardInput(inputBuffer.Length); using (var reader = new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)) { Console.SetIn(reader); new Solver(Console.In, Console.Out).Run(); } #else Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver(Console.In, Console.Out).Run(); Console.Out.Flush(); #endif } #pragma warning disable IDE0052 private readonly TextReader cin; private readonly TextWriter cout; #pragma warning restore IDE0052 public Solver(TextReader reader, TextWriter writer) : base(reader) { cin = reader; cout = writer; } public Solver(string input, TextWriter writer) : this(new StringReader(input), writer) { } #pragma warning disable IDE1006 #pragma warning disable IDE0051 private int ni() { return NextInt(); } private int[] ni(int n) { return NextIntArray(n); } private long nl() { return NextLong(); } private long[] nl(int n) { return NextLongArray(n); } private double nd() { return NextDouble(); } private double[] nd(int n) { return NextDoubleArray(n); } private string ns() { return Next(); } private string[] ns(int n) { return NextArray(n); } #pragma warning restore IDE1006 #pragma warning restore IDE0051 } internal static class LinqPadExtension { [Conditional("DEBUG")] public static void Dump<T>(this T obj) { #if DEBUG LINQPad.Extensions.Dump(obj); #endif } } public class Scanner { private readonly TextReader Reader; private readonly CultureInfo ci = CultureInfo.InvariantCulture; private readonly char[] buffer = new char[2 * 1024]; private int cursor = 0, length = 0; private string Token; private readonly StringBuilder sb = new StringBuilder(1024); public Scanner() : this(Console.In) { } public Scanner(TextReader reader) { Reader = reader; } public int NextInt() { return checked((int)NextLong()); } public long NextLong() { var s = Next(); long r = 0; int i = 0; bool negative = false; if (s[i] == '-') { negative = true; i++; } for (; i < s.Length; i++) { r = r * 10 + (s[i] - '0'); #if DEBUG if (!char.IsDigit(s[i])) throw new FormatException(); #endif } return negative ? -r : r; } public double NextDouble() { return double.Parse(Next(), ci); } public string[] NextArray(int size) { string[] array = new string[size]; for (int i = 0; i < size; i++) { array[i] = Next(); } return array; } public int[] NextIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = NextInt(); } return array; } public long[] NextLongArray(int size) { long[] array = new long[size]; for (int i = 0; i < size; i++) { array[i] = NextLong(); } return array; } public double[] NextDoubleArray(int size) { double[] array = new double[size]; for (int i = 0; i < size; i++) { array[i] = NextDouble(); } return array; } public string Next() { if (Token == null) { if (!StockToken()) { throw new Exception(); } } var token = Token; Token = null; return token; } public bool HasNext() { if (Token != null) { return true; } return StockToken(); } private bool StockToken() { while (true) { sb.Clear(); while (true) { if (cursor >= length) { cursor = 0; if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) { break; } } var c = buffer[cursor++]; if (33 <= c && c <= 126) { sb.Append(c); } else { if (sb.Length > 0) break; } } if (sb.Length > 0) { Token = sb.ToString(); return true; } return false; } } }