Submission #29890592


Source Code Expand

Copy
import java.util.Scanner;
import java.util.stream.IntStream;
public class Main {
private static final int[][] MAP = { { 1, 2 }, { 2, 0 }, { 0, 1 } };
private static final int[][] MAP2 = { { 0, 1, 2 }, { 1, 2, 0 }, { 2, 0, 1 } };
private static final char A = 'A';
public static void main(String[] args) {
try (Scanner scanner = new Scanner(System.in)) {
char[] s = scanner.next().toCharArray();
int[] sn = new int[s.length];
IntStream.range(0, s.length).forEach(i -> sn[i] = s[i] - A);
int q = scanner.nextInt();
// TLEStringBuilder
StringBuilder sb = new StringBuilder();
IntStream.range(0, q).forEach(i -> {
long t = scanner.nextLong(), k = scanner.nextLong() - 1;
sb.append((char) (calc(sn, t, k) + 'A')).append(System.lineSeparator());
});
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	private static final int[][] MAP = { { 1, 2 }, { 2, 0 }, { 0, 1 } };
	private static final int[][] MAP2 = { { 0, 1, 2 }, { 1, 2, 0 }, { 2, 0, 1 } };
	private static final char A = 'A';

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			char[] s = scanner.next().toCharArray();
			int[] sn = new int[s.length];
			IntStream.range(0, s.length).forEach(i -> sn[i] = s[i] - A);
			int q = scanner.nextInt();
			// TLE対策のため、結果をStringBuilderにまとめる
			StringBuilder sb = new StringBuilder();
			IntStream.range(0, q).forEach(i -> {
				long t = scanner.nextLong(), k = scanner.nextLong() - 1;
				sb.append((char) (calc(sn, t, k) + 'A')).append(System.lineSeparator());
			});
			System.out.print(sb.toString());
			System.out.flush();
		}
	}

	private static int calc(int[] sn, long t, long k) {
		if (0 == t) {
			return sn[(int) k];
		}
		if (0 == k) {
			return MAP2[sn[0]][(int) (t % 3)];
		}
		return MAP[calc(sn, t - 1, k / 2)][(int) (1 & k)];
	}
}

Submission Info

Submission Time
Task D - ABC Transform
User danielsun3164
Language Java (OpenJDK 11.0.6)
Score 400
Code Size 1142 Byte
Status AC
Exec Time 727 ms
Memory 64612 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 24
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 151 ms 35736 KB
001.txt AC 167 ms 39768 KB
002.txt AC 632 ms 58660 KB
003.txt AC 727 ms 62452 KB
004.txt AC 549 ms 61200 KB
005.txt AC 715 ms 61648 KB
006.txt AC 715 ms 61628 KB
007.txt AC 677 ms 61632 KB
008.txt AC 583 ms 59920 KB
009.txt AC 583 ms 58700 KB
010.txt AC 703 ms 64612 KB
011.txt AC 606 ms 59984 KB
012.txt AC 675 ms 61848 KB
013.txt AC 512 ms 58616 KB
014.txt AC 581 ms 62168 KB
015.txt AC 544 ms 59968 KB
016.txt AC 520 ms 59784 KB
017.txt AC 605 ms 64036 KB
018.txt AC 626 ms 61888 KB
019.txt AC 530 ms 58648 KB
020.txt AC 549 ms 60040 KB
021.txt AC 611 ms 61088 KB
example0.txt AC 106 ms 35768 KB
example1.txt AC 107 ms 35756 KB


2025-02-28 (Fri)
05:14:02 +00:00