結果

問題 No.1439 Let's Compare!!!!
ユーザー 小野寺健小野寺健
提出日時 2021-05-14 21:34:13
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,173 bytes
コンパイル時間 3,992 ms
コンパイル使用メモリ 88,996 KB
実行使用メモリ 77,964 KB
最終ジャッジ日時 2024-04-09 23:50:43
合計ジャッジ時間 10,097 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
60,840 KB
testcase_01 AC 141 ms
54,260 KB
testcase_02 AC 133 ms
54,340 KB
testcase_03 AC 146 ms
54,168 KB
testcase_04 AC 159 ms
54,344 KB
testcase_05 AC 147 ms
53,968 KB
testcase_06 AC 139 ms
54,484 KB
testcase_07 AC 380 ms
59,300 KB
testcase_08 AC 484 ms
59,752 KB
testcase_09 AC 297 ms
58,140 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class No1439 {
	
	private static int[] S, T;
	private static int N, D;
	private static List<Integer> Diff; 

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		N = scan.nextInt();
		String s = scan.next();
		String t = scan.next();
		int Q = scan.nextInt();
		S = new int[N];
		T = new int[N];
		D = 0;
		Diff = new ArrayList<Integer>();
		for (int i=0; i < N; i++) {
			int cs = s.charAt(i) - '0';
			int ct = t.charAt(i) - '0';
			S[i] = cs;
			T[i] = ct;
			if (cs != ct) {
				if (D == 0) {
					D = cs > ct ? i+1 : -i-1;
				} else {
					Diff.add(cs > ct ? i+1 : -i-1);
				}
			}
		}
		for (int i=0; i < Q; i++) {
			String c = scan.next();
			int x = scan.nextInt();
			int y = scan.nextInt();
			review(c.charAt(0), x, y);
			if (D > 0) {
				System.out.println('>');
//				System.out.println(D);
//				System.out.println(Diff);
//				print(S);
//				print(T);
			} else if (D < 0) {
				System.out.println('<');
//				System.out.println(D);
//				System.out.println(Diff);
//				print(S);
//				print(T);
			} else {
				System.out.println('=');
//				System.out.println(D);
//				System.out.println(Diff);
//				print(S);
//				print(T);
			}
		}
		scan.close();
	}
	private static void print(int[] a) {
		for(int i : a) {
			System.out.print(i);
		}
		System.out.println();
	}
	private static void review(char c, int x, int y) {
		if (c == 'S') {
			if (S[x-1] == y) {
				return;
			}
			S[x-1] = y;
		} else {
			if (T[x-1] == y) {
				return;
			}
			T[x-1] = y;
		}
		if (D == 0 || x < Math.abs(D)) {
			if (D != 0) {
				Diff.add(0, D);
			}
			D = S[x-1] > T[x-1] ? x : -x;
		} else if (x == Math.abs(D)) {
			if (S[x-1] != T[x-1]) {
				D = S[x-1] > T[x-1] ? x : -x;
			} else if (Diff.size() > 0) {
				D = Diff.remove(0);
			} else {
				D = 0;
			}
		} else {
			int v = S[x-1] > T[x-1] ? x : -x;
			int i = Diff.indexOf(v);
			if (i < 0) {
				i = Diff.indexOf(-v);
				if (i >= 0) {
					Diff.set(i, v);
				} else {
					Diff.add(S[x-1] > T[x-1] ? x : -x);
					Diff.sort((a, b) -> Math.abs(a) - Math.abs(b));
				}
			}
		}
	}
}
0