結果
| 問題 | No.3448 ABBBBBBBBC |
| コンテスト | |
| ユーザー |
37zigen
|
| 提出日時 | 2026-02-20 22:09:53 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
AC
|
| 実行時間 | 481 ms / 2,000 ms |
| コード長 | 15,153 bytes |
| 記録 | |
| コンパイル時間 | 3,769 ms |
| コンパイル使用メモリ | 102,152 KB |
| 実行使用メモリ | 60,732 KB |
| 最終ジャッジ日時 | 2026-02-20 22:10:00 |
| 合計ジャッジ時間 | 6,847 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 4 |
ソースコード
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.math.BigInteger;
import java.nio.file.Files;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.DoubleUnaryOperator;
import java.util.function.IntPredicate;
import java.util.function.LongToDoubleFunction;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.random.RandomGenerator;
import java.util.stream.IntStream;
import java.util.stream.Stream;
class FastScanner {
private static FastScanner instance = null;
private final InputStream in = System.in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int buflen = 0;
private FastScanner() {
}
public static FastScanner getInstance() {
if (instance == null) {
instance = new FastScanner();
}
return instance;
}
private boolean hasNextByte() {
if (ptr < buflen) {
return true;
}
ptr = 0;
try {
buflen = in.read(buffer);
} catch (IOException e) {
e.printStackTrace();
}
return buflen > 0;
}
private int readByte() {
if (hasNextByte()) {
return buffer[ptr++];
} else {
return -1;
}
}
private boolean isPrintableChar(int c) {
return (33 <= c) && (c <= 126);
}
public boolean hasNext() {
while (hasNextByte() && (!isPrintableChar(buffer[ptr]))) {
ptr++;
}
return hasNextByte();
}
public long nextLong() {
if (!hasNext()) {
throw new NoSuchElementException();
}
long n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
while ((b >= '0') && (b <= '9')) {
// n = n * 10 + (b - '0');
n = ((n << 1) + (n << 3)) + (b - '0');
b = readByte();
}
return minus ? -n : n;
}
public int nextInt() {
return ((int) (nextLong()));
}
}
class MergeFiles {}
class MyPrintWriter extends PrintWriter {
private static MyPrintWriter instance = null;
private MyPrintWriter() {
super(System.out);
}
public static MyPrintWriter getInstance() {
if (instance == null) {
instance = new MyPrintWriter();
}
return instance;
}
public void println(boolean[][] a) {
for (int i = 0; i < a.length; i++) {
println(a[i], " ");
}
}
public void println(boolean[] a, String separator) {
for (int i = 0; i < a.length; ++i) {
super.print((a[i] ? 1 : 0) + (i == (a.length - 1) ? "\n" : separator));
}
}
}
/* Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* Factory for {@link IntStream}.
* <p>
* <small> Only a factory for now but could hold other functionality.</small>
* </p>
*
* @since 3.13.0
*/
class IntStreams {
/**
* Shorthand for {@code IntStream.range(0, i)}.
*
* @param endExclusive
* the exclusive upper bound.
* @return a sequential {@link IntStream} for the range of {@code int} elements.
*/
public static IntStream range(final int endExclusive) {
return IntStream.range(0, endExclusive);
}
}
class MathUtils {
/**
* C(n,i)=C(n,i-1)(n-i+1)/iで計算
*
* @param n
* @param k
* @return */
public static long comb(int n, int k) {
if ((k < 0) || ((n - k) < 0)) {
return 0;
}
if (k > (n / 2)) {
return MathUtils.comb(n, n - k);
}
if (k == 0) {
return 1;
}
if (k == 1) {
return n;
}
if (k == 2) {
return ((1L * n) * (n - 1)) / 2;
}
if (k > (n - k)) {
return MathUtils.comb(n, n - k);
}
long ans = 1;
for (int i = 1; i <= k; i++) {
// C(n,i)=C(n,i-1)(n-i+1)/i
ans = (ans * ((n - i) + 1)) / i;
}
return ans;
}
}
public class Main implements Runnable {
public static void main(String[] args) throws IOException {
Thread.setDefaultUncaughtExceptionHandler((t, e) -> System.exit(1));
// Runtime runtime = Runtime.getRuntime();
// new Thread(null, new Main(), "MainThreadWithLargeStack", (1024 * 1024) * 1024).start();
// new Main().test();
// new Main().gen();
new Main().run();
// long usedMemory = runtime.totalMemory() - runtime.freeMemory();
// System.err.printf("使用メモリ: %.2f MB%n", usedMemory / 1024.0 / 1024.0);
MyPrintWriter.getInstance().flush();
}
@Override
public void run() {
Random rnd = new Random();
FastScanner sc = FastScanner.getInstance();
MyPrintWriter pw = MyPrintWriter.getInstance();
// String f="c";
// ArrayList<String> list=new ArrayList<>();
// for (int len = 1; len <= 5; len++) {
// for (int i = 0; i < 5; i++) {
// if(i==2)continue;
// String s=String.valueOf((char)(i+'a'));
// list.add(f.repeat(len)+s);
// }
// }
/* ca
cb
cca
ccb
ccca
cccb
cccca
ccccb
ccccca
cccccb
cccccd
ccccce
ccccd
cccce
cccd
ccce
ccd
cce
cd
ce
*/
// Collections.sort(list);
// for (int i = 0; i < list.size(); i++) {
// pw.println(list.get(i));
// }
int T = sc.nextInt();
long A = 2 * MathUtils.comb(9, 2);
out : for (int TEST = 0; TEST < T; TEST++) {
int N = sc.nextInt();
long K = sc.nextLong();
int first = 1;
while (K > (A * N)) {
K -= A * N;
first++;
}
int second = 0;
if (second == first) {
++second;
}
while (K > (8L * N)) {
K -= 8L * N;
second++;
if (second == first) {
++second;
}
}
int countLes = second;
int countGrt = 9 - second;
if (first < second) {
countLes--;
}
if (first > second) {
countGrt--;
}
// 最後がsecond未満の場合
if (((1L * countLes) * N) >= K) {
long midLen = Math.ceilDiv(K, countLes);
K -= countLes * (midLen - 1);
int f = first;
int s = second;
int[] a = IntStreams.range(10).filter(v -> (v != f) && (v != s)).toArray();
pw.println(((((((midLen + 2) + " ") + first) + " ") + second) + " ") + a[((int) ((K - 1) % 10))]);
continue out;
}
K -= (1L * countLes) * N;
// 最後がsecond以上
long midLen = (N + 1) - Math.ceilDiv(K, countGrt);
K -= countGrt * (Math.ceilDiv(K, countGrt) - 1);
int f = first;
int s = second;
int[] a = IntStreams.range(10).filter(v -> ((v != f) && (v != s)) && (v > s)).toArray();
pw.println(((((((midLen + 2) + " ") + first) + " ") + second) + " ") + a[((int) ((K - 1) % 10))]);
}
}
}
// --- Original Code ---
// package template;
//
// import java.io.IOException;
// import java.util.Arrays;
// import java.util.Random;
// import java.util.stream.IntStream;
//
// import lib.tools.FastScanner;
// import lib.tools.MergeFiles;
// import lib.tools.MyPrintWriter;
// import lib.util.MathUtils;
//
// public class Main implements Runnable {
//
// public static void main(String[] args) throws IOException {
// // Runtime runtime = Runtime.getRuntime();
// // new Thread(null, new Main(), "MainThreadWithLargeStack", (1024 * 1024) * 1024).start();
// // new Main().test();
// // new Main().gen();
// new Main().run();
// // long usedMemory = runtime.totalMemory() - runtime.freeMemory();
// // System.err.printf("使用メモリ: %.2f MB%n", usedMemory / 1024.0 / 1024.0);
// MyPrintWriter.getInstance().flush();
// MergeFiles.export();
// }
//
// @Override
// public void run() {
// Random rnd = new Random();
// FastScanner sc = FastScanner.getInstance();
// MyPrintWriter pw = MyPrintWriter.getInstance();
// // String f="c";
// // ArrayList<String> list=new ArrayList<>();
// // for (int len = 1; len <= 5; len++) {
// // for (int i = 0; i < 5; i++) {
// // if(i==2)continue;
// // String s=String.valueOf((char)(i+'a'));
// // list.add(f.repeat(len)+s);
// // }
// // }
// /*
// ca
// cb
// cca
// ccb
// ccca
// cccb
// cccca
// ccccb
// ccccca
// cccccb
//
//
//
//
// cccccd
// ccccce
// ccccd
// cccce
// cccd
// ccce
// ccd
// cce
// cd
// ce
// */
//
//
// // Collections.sort(list);
// // for (int i = 0; i < list.size(); i++) {
// // pw.println(list.get(i));
// // }
//
//
// int T=sc.nextInt();
// long A=2*MathUtils.comb(9, 2);
// out : for (int TEST = 0; TEST < T; TEST++) {
// int N=sc.nextInt();
// long K=sc.nextLong();
//
// int first = 1;
// while (K > A * N) {
// K -= A * N;
// first++;
// }
// int second = 0;
// if (second == first) ++second;
// while (K > 8L * N) {
// K -= 8L * N;
// second++;
// if (second == first) ++second;
// }
// int countLes = second;
// int countGrt = 9 - second;
// if (first < second) countLes--;
// if (first > second) countGrt--;
// //最後がsecond未満の場合
// if (1L * countLes * N >= K) {
// long midLen = Math.ceilDiv(K, countLes);
// K -= countLes * (midLen - 1);
// int f = first;
// int s = second;
// int[] a=IntStreams.range(10).filter(v -> v != f && v != s).toArray();
// pw.println((midLen + 2) + " " + first + " " + second + " " + a[(int)((K - 1) % 10)]);
// continue out;
// }
// K -= 1L * countLes * N;
// //最後がsecond以上
// long midLen = N + 1 - Math.ceilDiv(K, countGrt);
// K -= countGrt * (Math.ceilDiv(K, countGrt) - 1);
// int f = first;
// int s = second;
// int[] a=IntStreams.range(10).filter(v -> v != f && v != s && v > s).toArray();
// pw.println((midLen + 2) + " " + first + " " + second + " " + a[(int)((K - 1) % 10)]);
//
// }
//
//
// }
//
//
// void gen() {
// Random rnd = new Random();
// MyPrintWriter pw = MyPrintWriter.getInstance();
// }
//
// void test() {
// Random rnd = new Random();
// for (int TEST = 0; TEST < 10000; TEST++) {
// }
// }
//
// void abc() {
// Random rnd = new Random();
// int a = rnd.nextInt(212, 445);
// System.out.println(a);
// }
//
// void tr(Object... objects) {
// System.out.println(Arrays.deepToString(objects));
// }
//
//
//
//
// }
//
//
//
// /*
// * Licensed to the Apache Software Foundation (ASF) under one or more
// * contributor license agreements. See the NOTICE file distributed with
// * this work for additional information regarding copyright ownership.
// * The ASF licenses this file to You under the Apache License, Version 2.0
// * (the "License"); you may not use this file except in compliance with
// * the License. You may obtain a copy of the License at
// *
// * https://www.apache.org/licenses/LICENSE-2.0
// *
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// * See the License for the specific language governing permissions and
// * limitations under the License.
// */
//
//
// /**
// * Factory for {@link IntStream}.
// * <p>
// * <small> Only a factory for now but could hold other functionality.</small>
// * </p>
// *
// * @since 3.13.0
// */
// class IntStreams {
//
// /**
// * Null-safe version of {@link IntStream#of(int[])}.
// *
// * @param values the elements of the new stream, may be {@code null}.
// * @return the new stream on {@code values} or {@link IntStream#empty()}.
// * @since 3.18.0
// */
// @SafeVarargs // Creating a stream from an array is safe
// public static IntStream of(final int... values) {
// return values == null ? IntStream.empty() : IntStream.of(values);
// }
//
// /**
// * Shorthand for {@code IntStream.range(0, i)}.
// *
// * @param endExclusive the exclusive upper bound.
// * @return a sequential {@link IntStream} for the range of {@code int} elements.
// */
// public static IntStream range(final int endExclusive) {
// return IntStream.range(0, endExclusive);
// }
//
// /**
// * Shorthand for {@code IntStream.rangeClosed(0, i)}.
// *
// * @param endInclusive the inclusive upper bound.
// * @return a sequential {@link IntStream} for the range of {@code int} elements.
// */
// public static IntStream rangeClosed(final int endInclusive) {
// return IntStream.rangeClosed(0, endInclusive);
// }
//
// /**
// * Make private in 4.0.
// *
// * @deprecated TODO Make private in 4.0.
// */
// @Deprecated
// public IntStreams() {
// // empty
// }
// }
//
37zigen