結果
問題 | No.918 LISGRID |
ユーザー | EmKjp |
提出日時 | 2019-10-26 10:48:36 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 204 ms / 2,000 ms |
コード長 | 6,273 bytes |
コンパイル時間 | 3,966 ms |
コンパイル使用メモリ | 118,016 KB |
実行使用メモリ | 50,048 KB |
最終ジャッジ日時 | 2024-09-14 02:58:16 |
合計ジャッジ時間 | 8,636 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
25,316 KB |
testcase_01 | AC | 129 ms
34,688 KB |
testcase_02 | AC | 63 ms
23,680 KB |
testcase_03 | AC | 79 ms
29,056 KB |
testcase_04 | AC | 64 ms
24,064 KB |
testcase_05 | AC | 149 ms
36,860 KB |
testcase_06 | AC | 136 ms
35,968 KB |
testcase_07 | AC | 195 ms
43,128 KB |
testcase_08 | AC | 122 ms
34,292 KB |
testcase_09 | AC | 154 ms
37,112 KB |
testcase_10 | AC | 151 ms
37,244 KB |
testcase_11 | AC | 151 ms
37,248 KB |
testcase_12 | AC | 162 ms
38,144 KB |
testcase_13 | AC | 138 ms
35,832 KB |
testcase_14 | AC | 185 ms
49,984 KB |
testcase_15 | AC | 204 ms
50,048 KB |
testcase_16 | AC | 91 ms
29,308 KB |
testcase_17 | AC | 95 ms
29,428 KB |
testcase_18 | AC | 94 ms
29,568 KB |
testcase_19 | AC | 54 ms
21,908 KB |
testcase_20 | AC | 115 ms
33,396 KB |
testcase_21 | AC | 57 ms
22,528 KB |
testcase_22 | AC | 50 ms
21,660 KB |
testcase_23 | AC | 85 ms
29,440 KB |
testcase_24 | AC | 37 ms
19,580 KB |
testcase_25 | AC | 36 ms
19,712 KB |
testcase_26 | AC | 35 ms
19,456 KB |
testcase_27 | AC | 35 ms
19,456 KB |
testcase_28 | AC | 35 ms
19,456 KB |
testcase_29 | AC | 35 ms
19,328 KB |
testcase_30 | AC | 35 ms
19,456 KB |
testcase_31 | AC | 36 ms
19,456 KB |
testcase_32 | AC | 35 ms
19,456 KB |
testcase_33 | AC | 36 ms
19,456 KB |
testcase_34 | AC | 39 ms
19,712 KB |
testcase_35 | AC | 42 ms
20,428 KB |
testcase_36 | AC | 37 ms
19,584 KB |
testcase_37 | AC | 115 ms
33,144 KB |
testcase_38 | AC | 89 ms
29,308 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 E = System.Linq.Enumerable; internal partial class Solver { public void Run() { var h = ni(); var w = ni(); var a = ni(h); var b = ni(w); Array.Sort(a); Array.Sort(b); var adj = E.Range(0, w * h).Select(_ => new List<int>()).ToArray(); for (int i = 0; i < h; i++) { for (int j = 0; j + 1 < w; j++) { var p = i * w + j; var q = i * w + (j + 1); if (j < a[i] - 1) { // increase adj[p].Add(q); } else { adj[q].Add(p); } } } for (int j = 0; j < w; j++) { for (int i = 0; i + 1 < h; i++) { var p = i * w + j; var q = (i + 1) * w + j; if (i < b[j] - 1) { // increase adj[p].Add(q); } else { adj[q].Add(p); } } } var order = GetTopologicalOrder(adj); var ans = new int[h, w]; int index = 1; foreach (var x in order) { ans[x / w, x % w] = index++; } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (j > 0) cout.Write(" "); cout.Write(ans[i, j]); } cout.WriteLine(); } } static public List<int> GetTopologicalOrder(List<int>[] adj) { var n = adj.Length; var inDegree = new int[n]; for (int i = 0; i < n; i++) { foreach (var p in adj[i]) { inDegree[p]++; } } var qu = new Queue<int>(); for (int i = 0; i < n; i++) { if (inDegree[i] == 0) { qu.Enqueue(i); qu.Enqueue(1); } } int maxDay = 0; var order = new List<int>(); while (qu.Count > 0) { var current = qu.Dequeue(); var day = qu.Dequeue(); order.Add(current); maxDay = Math.Max(day, maxDay); foreach (var next in adj[current]) { inDegree[next]--; if (inDegree[next] == 0) { qu.Enqueue(next); qu.Enqueue(day + 1); } } } if (inDegree.Any(d => d > 0)) return null; return order; } } // PREWRITEN CODE BEGINS FROM HERE internal partial class Solver : Scanner { public static void Main(string[] args) { #if LOCAL 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 { public static T Dump<T>(this T obj) { #if LOCAL return LINQPad.Extensions.Dump(obj); #else return obj; #endif } } public class Scanner { private readonly TextReader Reader; private readonly Queue<string> TokenQueue = new Queue<string>(); private readonly CultureInfo ci = CultureInfo.InvariantCulture; public Scanner() : this(Console.In) { } public Scanner(TextReader reader) { Reader = reader; } public int NextInt() { return int.Parse(Next(), ci); } public long NextLong() { return long.Parse(Next(), ci); } 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 (TokenQueue.Count == 0) { if (!StockTokens()) { throw new InvalidOperationException(); } } return TokenQueue.Dequeue(); } public bool HasNext() { if (TokenQueue.Count > 0) { return true; } return StockTokens(); } private static readonly char[] _separator = new[] { ' ', '\t' }; private bool StockTokens() { while (true) { string line = Reader.ReadLine(); if (line == null) { return false; } string[] tokens = line.Split(_separator, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 0) { continue; } foreach (string token in tokens) { TokenQueue.Enqueue(token); } return true; } } }