コード
using System; using System.Linq; using System.IO; using System.Text; using System.Collections; using System.Collections.Generic; /** * Auto-generated code below aims at helping you parse * the standard input according to the problem statement. **/ class Solution { const int Width = 10002; static int[] silhouette = new int[Width]; static int MinX1 = Width; static int MaxX2 = 0; static int Answer; static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); for (var i = 0; i < n; i++) { string[] inputs = Console.ReadLine().Split(' '); var h = int.Parse(inputs[0]); var x1 = int.Parse(inputs[1]); var x2 = int.Parse(inputs[2]); Console.Error.WriteLine($"{h},{x1},{x2}"); AddBuilding(h, x1*2, x2*2); } CountLines(); // Write an answer using Console.WriteLine() // To debug: Console.Error.WriteLine("Debug messages..."); Console.WriteLine($"{Answer}"); } static void AddBuilding(int h, int x1, int x2) { if(x2 < x1) (x1, x2) = (x2, x1); if(x1 < MinX1) MinX1 = x1; if(MaxX2 < x2) MaxX2 = x2; for(var p = x1; p <= x2; p++) if(silhouette[p] < h) silhouette[p] = h; } static void CountLines() { Console.Error.WriteLine($"**Data**"); Console.Error.WriteLine($"MinX1:{MinX1}, MaxX2:{MaxX2}"); for(var p = MinX1; p <= MaxX2; p++) { if(silhouette[p] != silhouette[p+1]) Answer+=2; } Answer++; } }
だいぶ力技になってる。
*1:Copilot GPT Designer で作成