結果

問題 No.1650 Moving Coins
ユーザー bluemegane
提出日時 2021-08-21 07:13:19
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 667 ms / 2,000 ms
コード長 1,567 bytes
コンパイル時間 1,831 ms
コンパイル使用メモリ 106,240 KB
実行使用メモリ 56,436 KB
最終ジャッジ日時 2024-10-14 15:50:20
合計ジャッジ時間 18,790 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using static System.Math;
using System.Linq;
using System.Collections.Generic;
using System;

public class P
{
    public int id { get; set; }
    public int a { get; set; }
    public int b { get; set; }
}

public class Hello
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        line = Console.ReadLine().Trim().Split(' ');
        var b = Array.ConvertAll(line, int.Parse);
        getAns(n, a, b);
    }
    static void printAsb(List<P> asb)
    {
        var c = asb.Count();
        for (int i = c - 1; i >= 0; i--)
        {
            var jmax = asb[i].b - asb[i].a;
            for (int j = 0; j < jmax; j++) Console.WriteLine("{0} R", asb[i].id);
        }
    }
    static void printAgb(List<P> agb)
    {
        var c = agb.Count();
        for (int i = 0; i < c; i++)
        {
            var jmax = agb[i].a - agb[i].b;
            for (int j = 0; j < jmax; j++) Console.WriteLine("{0} L", agb[i].id);
        }
    }
    static void getAns(int n, int[] a, int[] b)
    {
        var asb = new List<P>();
        var agb = new List<P>();
        var s = 0L;
        for (int i = 0; i < n; i++)
        {
            s += Abs(a[i] - b[i]);
            if (a[i] < b[i]) asb.Add(new P { id = i + 1, a = a[i], b = b[i] });
            else if (a[i] > b[i]) agb.Add(new P { id = i + 1, a = a[i], b = b[i] });
        }
        Console.WriteLine(s);
        printAgb(agb);
        printAsb(asb);
    }
}
0