結果
問題 | No.2030 Googol Strings |
ユーザー | 👑 kakel-san |
提出日時 | 2022-08-05 22:35:07 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 111 ms / 2,000 ms |
コード長 | 1,687 bytes |
コンパイル時間 | 1,326 ms |
コンパイル使用メモリ | 63,932 KB |
実行使用メモリ | 32,908 KB |
最終ジャッジ日時 | 2023-10-13 23:58:28 |
合計ジャッジ時間 | 4,009 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 73 ms
23,620 KB |
testcase_01 | AC | 71 ms
23,852 KB |
testcase_02 | AC | 64 ms
20,920 KB |
testcase_03 | AC | 62 ms
21,596 KB |
testcase_04 | AC | 79 ms
25,680 KB |
testcase_05 | AC | 72 ms
24,820 KB |
testcase_06 | AC | 91 ms
26,972 KB |
testcase_07 | AC | 110 ms
32,908 KB |
testcase_08 | AC | 111 ms
32,780 KB |
testcase_09 | AC | 79 ms
26,348 KB |
testcase_10 | AC | 79 ms
26,576 KB |
testcase_11 | AC | 80 ms
28,440 KB |
testcase_12 | AC | 84 ms
23,760 KB |
testcase_13 | AC | 90 ms
27,800 KB |
testcase_14 | AC | 77 ms
24,268 KB |
testcase_15 | AC | 94 ms
30,348 KB |
testcase_16 | AC | 90 ms
28,948 KB |
ソースコード
using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static void Main() { var t = NN; var res = new char[t]; for (var u = 0; u < t; ++u) { var x = ReadLine(); var y = ReadLine(); res[u] = Compare(x, y); } WriteLine(string.Join("\n", res)); } static char Compare(string x, string y) { if (x[0] > y[0]) return 'X'; if (x[0] < y[0]) return 'Y'; if (IsRepeat(x, y)) { if (x.Length > y.Length) return 'X'; else return 'Y'; } var pos = 1; while (true) { var xi = pos % x.Length; var yi = pos % y.Length; if (xi == 0 && yi == 0) break; if (x[xi] > y[yi]) return 'X'; if (x[xi] < y[yi]) return 'Y'; ++pos; } return ' '; } static bool IsRepeat(string x, string y) { var gcd = GCD(x.Length, y.Length); var glist = x.Take(gcd).ToArray(); for (var i = gcd; i < x.Length; ++i) { if (x[i] != glist[i % gcd]) return false; } for (var i = 0; i < y.Length; ++i) { if (y[i] != glist[i % gcd]) return false; } return true; } static int GCD(int a, int b) { if (a < b) return GCD(b, a); if (a % b == 0) return b; return GCD(b, a % b); } }