結果

問題 No.365 ジェンガソート
ユーザー suzusuzu
提出日時 2023-05-17 15:12:34
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 959 bytes
コンパイル時間 2,111 ms
コンパイル使用メモリ 102,336 KB
実行使用メモリ 32,652 KB
最終ジャッジ日時 2023-08-21 19:09:44
合計ジャッジ時間 7,814 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
26,240 KB
testcase_01 AC 63 ms
21,700 KB
testcase_02 AC 64 ms
21,784 KB
testcase_03 AC 62 ms
21,784 KB
testcase_04 WA -
testcase_05 AC 65 ms
21,760 KB
testcase_06 AC 64 ms
21,728 KB
testcase_07 AC 64 ms
23,640 KB
testcase_08 WA -
testcase_09 AC 63 ms
21,700 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 64 ms
21,824 KB
testcase_15 AC 65 ms
21,864 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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);
			
			
		}
		
		
	}
}
0