結果

問題 No.1619 Coccinellidae
ユーザー merlinmerlin
提出日時 2021-07-22 22:52:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 211 ms / 2,000 ms
コード長 1,140 bytes
コンパイル時間 2,347 ms
コンパイル使用メモリ 77,724 KB
実行使用メモリ 62,300 KB
最終ジャッジ日時 2023-09-24 18:32:47
合計ジャッジ時間 6,311 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
50,000 KB
testcase_01 AC 192 ms
61,980 KB
testcase_02 AC 211 ms
61,648 KB
testcase_03 AC 54 ms
50,040 KB
testcase_04 AC 201 ms
61,864 KB
testcase_05 AC 150 ms
58,148 KB
testcase_06 AC 55 ms
50,216 KB
testcase_07 AC 207 ms
59,828 KB
testcase_08 AC 152 ms
60,032 KB
testcase_09 AC 54 ms
50,512 KB
testcase_10 AC 152 ms
57,896 KB
testcase_11 AC 181 ms
61,604 KB
testcase_12 AC 56 ms
50,288 KB
testcase_13 AC 187 ms
62,300 KB
testcase_14 AC 208 ms
61,996 KB
testcase_15 AC 53 ms
50,000 KB
testcase_16 AC 53 ms
49,956 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));
        StringBuilder sb=new StringBuilder();
        String s[]=bu.readLine().split(" ");
        int n=Integer.parseInt(s[0]),i;
        long m=Long.parseLong(s[1]),k=Long.parseLong(s[2]),sum=0;
        Deque<Long> dq=new LinkedList<>();
        for(i=0;i<n;i++)
        {
            dq.addLast((long)i);
            sum+=i;
        }
        long v=dq.pollLast();
        v+=m-sum;
        dq.addLast(v);

        int cur=n-1;
        Queue<Long> q=new LinkedList<>();
        while(cur>=0 && k-cur>=0)    //one by one take largest and place it after the last appended value
        {
            q.add(dq.pollLast());
            k-=cur;
            cur--;
        }

        while(!q.isEmpty()) sb.append(q.poll()+"\n");
        while(dq.size()>k+1) sb.append(dq.pollFirst()+"\n");
        if(!dq.isEmpty()) sb.append(dq.pollLast()+"\n");
        while(!dq.isEmpty()) sb.append(dq.pollFirst()+"\n");
        System.out.print(sb);
    }
}
0