結果
| 問題 | No.365 ジェンガソート | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2016-07-30 13:02:11 | 
| 言語 | C#(csc) (csc 3.9.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 61 ms / 2,000 ms | 
| コード長 | 1,290 bytes | 
| コンパイル時間 | 2,657 ms | 
| コンパイル使用メモリ | 107,360 KB | 
| 実行使用メモリ | 32,896 KB | 
| 最終ジャッジ日時 | 2024-11-06 21:14:34 | 
| 合計ジャッジ時間 | 5,358 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 41 | 
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
namespace JengaSort
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] a = new int[N];
            int[] ai = new int[N+1];
            bool[] moved = new bool[N+1];
            int[] max = new int[N];
            string[] vals = Console.ReadLine().Split(' ');
            for(int i=0; i < N; i++)
            {
                a[i] = int.Parse(vals[i]);
                ai[a[i]] = i;
            }
            int m = 0;
            for (int i = 0; i < N; i++)
            {
                if (m < a[i])
                    m = a[i];
                max[i] = m;
            }
            int count = 0;
            for(int n= N-1; n >= 1; n--)
            {
                if(moved[n+1])
                {
                    moved[n] = true;
                    count++;
                }
                else
                {
                    if(ai[n] > 0)
                    {
                        if(max[ai[n] - 1] > n)
                        {
                            moved[n] = true;
                            count++;
                        }
                    }
                }
            }
            Console.WriteLine(count);
        }
    }
}
            
            
            
        