結果

問題 No.1650 Moving Coins
ユーザー merlinmerlin
提出日時 2021-08-20 22:01:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 971 ms / 2,000 ms
コード長 1,396 bytes
コンパイル時間 2,542 ms
コンパイル使用メモリ 80,344 KB
実行使用メモリ 74,312 KB
最終ジャッジ日時 2024-04-22 04:36:15
合計ジャッジ時間 20,715 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
40,184 KB
testcase_01 AC 70 ms
38,176 KB
testcase_02 AC 103 ms
40,488 KB
testcase_03 AC 308 ms
45,908 KB
testcase_04 AC 272 ms
45,552 KB
testcase_05 AC 294 ms
45,932 KB
testcase_06 AC 316 ms
46,060 KB
testcase_07 AC 299 ms
46,040 KB
testcase_08 AC 660 ms
66,408 KB
testcase_09 AC 648 ms
58,216 KB
testcase_10 AC 736 ms
60,244 KB
testcase_11 AC 707 ms
58,672 KB
testcase_12 AC 501 ms
53,020 KB
testcase_13 AC 488 ms
55,704 KB
testcase_14 AC 773 ms
61,992 KB
testcase_15 AC 447 ms
53,360 KB
testcase_16 AC 638 ms
59,484 KB
testcase_17 AC 666 ms
61,332 KB
testcase_18 AC 728 ms
58,868 KB
testcase_19 AC 914 ms
74,124 KB
testcase_20 AC 808 ms
69,464 KB
testcase_21 AC 971 ms
74,312 KB
testcase_22 AC 778 ms
73,480 KB
testcase_23 AC 828 ms
73,152 KB
testcase_24 AC 302 ms
49,476 KB
testcase_25 AC 298 ms
48,076 KB
testcase_26 AC 582 ms
65,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        int n=Integer.parseInt(bu.readLine());
        String s[]=bu.readLine().split(" ");
        int a[]=new int[n],b[]=new int[n],i;
        for(i=0;i<n;i++) a[i]=Integer.parseInt(s[i]);
        s=bu.readLine().split(" ");
        for(i=0;i<n;i++) b[i]=Integer.parseInt(s[i]);

        ArrayList<Integer> fin=new ArrayList<>();
        Deque<Integer> q=new LinkedList<>();
        int ans=0;
        for(i=0;i<n;i++) ans+=Math.abs(b[i]-a[i]);

        for(i=0;i<n;i++)
        {
            int j=i+1;
            q.add(i);
            while(j<n && ((a[i]<b[i] && a[j]<b[j] && a[j]<=b[j-1]) || (a[i]>b[i] && a[j]>b[j] && b[j]<=a[j-1])))
            q.addLast(j++);

            if(a[i]<=b[i])
            while(!q.isEmpty()) fin.add(q.removeLast());
            else while(!q.isEmpty()) fin.add(q.removeFirst());
            i=j-1;
        }

        pw.append(ans+"\n");
        for(int x:fin)
        {
            int l=a[x],r=b[x]; char c='R';
            if(l>r)
            {
                l=b[x]; r=a[x];
                c='L';
            }

            while(l++<r) pw.append((x+1)+" "+c+"\n");
        }
        pw.close();
    }
}
0