結果

問題 No.326 あみだますたー
コンテスト
ユーザー 14番
提出日時 2016-05-22 13:33:38
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,155 bytes
コンパイル時間 2,148 ms
コンパイル使用メモリ 108,544 KB
実行使用メモリ 20,992 KB
最終ジャッジ日時 2024-10-06 19:31:44
合計ジャッジ時間 8,225 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 2
other WA * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
            }
        }
        
        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