結果
問題 | No.1251 絶対に間違ってはいけない最小化問題 |
ユーザー | azukun |
提出日時 | 2020-10-09 22:31:56 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 216 ms / 2,000 ms |
コード長 | 4,435 bytes |
コンパイル時間 | 2,413 ms |
コンパイル使用メモリ | 117,440 KB |
実行使用メモリ | 43,136 KB |
最終ジャッジ日時 | 2024-07-20 12:53:49 |
合計ジャッジ時間 | 16,882 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 24 ms
19,200 KB |
testcase_01 | AC | 26 ms
19,072 KB |
testcase_02 | AC | 27 ms
19,072 KB |
testcase_03 | AC | 27 ms
19,328 KB |
testcase_04 | AC | 27 ms
19,456 KB |
testcase_05 | AC | 27 ms
19,328 KB |
testcase_06 | AC | 26 ms
19,200 KB |
testcase_07 | AC | 26 ms
19,456 KB |
testcase_08 | AC | 27 ms
19,200 KB |
testcase_09 | AC | 25 ms
19,328 KB |
testcase_10 | AC | 26 ms
18,944 KB |
testcase_11 | AC | 26 ms
19,200 KB |
testcase_12 | AC | 26 ms
19,456 KB |
testcase_13 | AC | 25 ms
19,328 KB |
testcase_14 | AC | 30 ms
19,072 KB |
testcase_15 | AC | 27 ms
19,328 KB |
testcase_16 | AC | 25 ms
19,328 KB |
testcase_17 | AC | 26 ms
19,328 KB |
testcase_18 | AC | 186 ms
42,368 KB |
testcase_19 | AC | 182 ms
41,728 KB |
testcase_20 | AC | 123 ms
41,472 KB |
testcase_21 | AC | 43 ms
21,764 KB |
testcase_22 | AC | 130 ms
43,136 KB |
testcase_23 | AC | 40 ms
21,504 KB |
testcase_24 | AC | 156 ms
41,088 KB |
testcase_25 | AC | 135 ms
42,368 KB |
testcase_26 | AC | 60 ms
25,856 KB |
testcase_27 | AC | 38 ms
21,504 KB |
testcase_28 | AC | 211 ms
42,752 KB |
testcase_29 | AC | 193 ms
42,624 KB |
testcase_30 | AC | 193 ms
42,752 KB |
testcase_31 | AC | 202 ms
42,752 KB |
testcase_32 | AC | 198 ms
42,752 KB |
testcase_33 | AC | 196 ms
42,624 KB |
testcase_34 | AC | 200 ms
42,624 KB |
testcase_35 | AC | 203 ms
42,496 KB |
testcase_36 | AC | 197 ms
42,624 KB |
testcase_37 | AC | 202 ms
42,496 KB |
testcase_38 | AC | 205 ms
42,752 KB |
testcase_39 | AC | 212 ms
42,752 KB |
testcase_40 | AC | 216 ms
42,752 KB |
testcase_41 | AC | 207 ms
42,880 KB |
testcase_42 | AC | 200 ms
42,752 KB |
testcase_43 | AC | 27 ms
19,456 KB |
testcase_44 | AC | 28 ms
19,200 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.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Threading; // (づ°ω°)づミe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜ public class Solver { public void Solve() { int n = ReadInt(); var a = ReadIntArray(); var b = ReadIntArray(); Array.Sort(a, b); long rsum = 0, rb = 0; for (int i = 1; i < n; i++) { rsum += 1L * b[i] * (a[i] - a[0]); rb += b[i]; } int best = 0; long ans = rsum; long lsum = 0, lb = 0; for (int i = 1; i < n; i++) { rsum -= rb * (a[i] - a[i - 1]); rb -= b[i]; lb += b[i - 1]; lsum += lb * (a[i] - a[i - 1]); if (lsum + rsum < ans) { ans = lsum + rsum; best = i; } } Write(a[best], ans); } #region Main protected static TextReader reader; protected static TextWriter writer; static void Main() { #if DEBUG reader = new StreamReader("..\\..\\input.txt"); //reader = new StreamReader(Console.OpenStandardInput()); writer = Console.Out; //writer = new StreamWriter("..\\..\\output.txt"); #else reader = new StreamReader(Console.OpenStandardInput()); writer = new StreamWriter(Console.OpenStandardOutput()); //reader = new StreamReader("input.txt"); //writer = new StreamWriter("output.txt"); #endif try { new Solver().Solve(); //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128); //thread.Start(); //thread.Join(); } catch (Exception ex) { #if DEBUG Console.WriteLine(ex); #else throw; #endif } reader.Close(); writer.Close(); } #endregion #region Read / Write private static Queue<string> currentLineTokens = new Queue<string>(); private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); } public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); } public static int ReadInt() { return int.Parse(ReadToken()); } public static long ReadLong() { return long.Parse(ReadToken()); } public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); } public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); } public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); } public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); } public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; } public static int[][] ReadAndTransposeIntMatrix(int numberOfRows) { int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][]; for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; } return ret; } public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; } public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); } public static void Write(params object[] array) { WriteArray(array); } public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); } private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue> { public new TValue this[TKey key] { get { return ContainsKey(key) ? base[key] : default(TValue); } set { base[key] = value; } } } private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; } #endregion }