結果

問題 No.326 あみだますたー
ユーザー 14番14番
提出日時 2016-05-22 13:34:42
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,193 bytes
コンパイル時間 3,080 ms
コンパイル使用メモリ 108,928 KB
実行使用メモリ 21,120 KB
最終ジャッジ日時 2024-04-16 06:20:17
合計ジャッジ時間 6,005 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
19,200 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 33 ms
19,200 KB
testcase_06 AC 39 ms
20,352 KB
testcase_07 AC 36 ms
19,712 KB
testcase_08 AC 49 ms
19,836 KB
testcase_09 AC 52 ms
21,120 KB
testcase_10 AC 55 ms
21,120 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Collections.Generic;
using System.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int tatebouCount = int.Parse(Reader.ReadLine());
        
        int yokobobuCount = int.Parse(Reader.ReadLine());
        
        Dictionary<int, int> swapDic = new Dictionary<int, int>();
        
        for(int i=1; i<= tatebouCount; i++) {
            swapDic.Add(i, i);
        }
        
        for(int i=0; i<yokobobuCount; i++) {
            int[] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
            int tmp = swapDic[inpt[0]];
            swapDic[inpt[0]] = swapDic[inpt[1]];
            swapDic[inpt[1]] = tmp;
        }
        
        List<int[]> ans = new List<int[]>();
        
        int[] goal = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
        
        for(int i=0; i<goal.Length - 1; i++) {
            int targetIdx = swapDic.Where(a=>a.Value == goal[i]).Select(a=>a.Key).First();
            if(targetIdx - 1 == i) {
                continue;
            }
            for (int j = targetIdx - 1; j > i; j--)
            {
                ans.Add(new int[]{j, j+1});
                int tmp = swapDic[j+1];
                swapDic[j+1] = swapDic[j];
                swapDic[j] = tmp;
            }
        }
        
        Console.WriteLine(ans.Count);
        ans.ForEach(a=>Console.WriteLine(a[0] + " " + a[1]));

    }
    




    

    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


5
6
1 2
3 4
2 3
3 4
1 2
4 5
5 1 4 3 2


 
";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0