結果
問題 |
No.365 ジェンガソート
|
ユーザー |
![]() |
提出日時 | 2023-05-17 15:12:34 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 959 bytes |
コンパイル時間 | 980 ms |
コンパイル使用メモリ | 112,028 KB |
実行使用メモリ | 59,112 KB |
最終ジャッジ日時 | 2024-12-15 09:11:36 |
合計ジャッジ時間 | 73,199 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 11 WA * 7 TLE * 23 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Linq; using System.Collections.Generic; namespace yukicoder { class PG { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var blocks = Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToList(); var compBlocks = new List<int>(blocks); compBlocks = compBlocks.OrderBy(c => c).ToList(); int ans = 0; int i = N - 1; while(i >= 0) { if(compBlocks[i] == blocks[i]) { i--; continue; } int max = -1; int maxIndex = -1; for(int p = i ;p >= 0;p--)//入れ替え元探索 { if(blocks[p] == compBlocks[i]) { break; }else if(max < blocks[p]) { max = blocks[p]; maxIndex = p; } } for(int q = maxIndex;q > 0;q--)//入れ替え { blocks[q] = blocks[q - 1]; } blocks[0] = max; ans++; } Console.WriteLine(ans); } } }